home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!unixhub!slacvx.slac.stanford.edu!fairfield
- From: fairfield@slacvx.slac.stanford.edu
- Subject: Re: passing a string constant to a subroutine
- Message-ID: <1992Nov19.192855.1@slacvx.slac.stanford.edu>
- Lines: 37
- Sender: news@unixhub.SLAC.Stanford.EDU
- Organization: Stanford Linear Accelerator Center
- References: <EJH.92Nov19160031@khonshu.colorado.edu>
- Date: Fri, 20 Nov 1992 03:28:55 GMT
-
- In article <EJH.92Nov19160031@khonshu.colorado.edu>, ejh@khonshu.colorado.edu (Edward J. Hartnett) writes:
- > When I want to pass a string constant to a subroutine, what size do I
- > declare the character variable to be in the subprogram. For example
- > I have a subroutine:
- >
- > subroutine ask_data_type(prog, typenum)
- >
- > This is intended to be called from one of several programs, and the
- > program name is to be passed in as the first parameter. Inside the
- > subroutine I have:
- > character*20 prog
-
- [description of incorrect execution, etc., deleted]
-
- Within your subroutine, declare PROG so:
-
- CHARACTER*(*) PROG
-
- This is called a "passed-length character argument". If ASK_DATA_TYPE
- needs to know the length of PROG, use LEN(PROG). This is all standard
- Fortran 77.
-
- > But I'm just wondering if what I did was non-standard or what.
-
- Not non-standard, just a "programming error" ;-) That is, you called
- ASK_DATA_TYPE with an actual argument that didn't match the declaration
- of the dummy argument within ASK_DATA_TYPE. The same kind of thing would
- happen if the subroutine declared one of its dummy arguments to be
- DOUBLE PRECISION but you called it with a REAL...
-
- Cheers, Ken
- --
- Dr. Kenneth H. Fairfield | Internet: Fairfield@Slac.Stanford.Edu
- SLAC, P.O.Box 4349, MS 98 | DECnet: 45537::FAIRFIELD (45537=SLACVX)
- Stanford, CA 94309 | BITNET Fairfield@Slacvx
- ----------------------------------------------------------------------------
- These opinions are mine, not SLAC's, Stanford's, nor the DOE's...
-