home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4384 < prev    next >
Encoding:
Text File  |  1992-11-20  |  2.0 KB  |  49 lines

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