Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!agate!usenet.ins.cwru.edu!eagle!zargon.lerc.nasa.gov!pstowne From: pstowne@zargon.lerc.nasa.gov (Charlie Towne) Newsgroups: comp.lang.fortran Subject: Re: Command line arguements? Message-ID: <1991May30.201909.23372@eagle.lerc.nasa.gov> Date: 30 May 91 20:19:09 GMT References: <1991May30.135749.10529@eagle.lerc.nasa.gov> <1991May30.175533.13315@cs.dal.ca> Sender: news@eagle.lerc.nasa.gov Organization: NASA Lewis Research Center (Cleveland) Lines: 76 In article <1991May30.175533.13315@cs.dal.ca> silvert%biome@cs.dal.ca writes: >In article <1991May30.135749.10529@eagle.lerc.nasa.gov> I wrote: >>In article eesnyder@boulder.Colorado.EDU (Eric E. Snyder) writes: >>>I need to write a program that takes arguements from the >>>command line and passes them to variables with in the program. >>> a.out arg1 arg2 .... >> >>See the getarg(3F) man page in the Iris-4D Fortran 77 Reference Manual >>Pages (Doc. number 007-0621-030). It can be used as follows: >> >> character*1 iargc,jargc ^^^^^ poor name choice >> c >> c-----get arguments from command line >> c >> call getarg(1,iargc) >> call getarg(2,jargc) >> read (iargc,'(i1)') iarg >> read (jargc,'(i1)') jarg >> >>The calls to getarg return the 1st and 2nd arguments in the character >>variables iargc and jargc. The internal reads convert the character >>variables to integers. Note that this example is for single digit >>integer arguments. > >Whoa! My manual says that iargc() returns an integer. The usage is: > CALL GETARG(I, STRING) > and > ICOUNT = IARGC() >Conversion with internal reads is not called for! (I just checked it, >the manual description is correct.) I probably caused some confusion by the very poor choice of iargc as a variable name, when there's also a function by that name. (Which, until about 10 minutes ago I'd never used.) I'll try to clear things up. The function IARGC returns the index of the last argument, as an integer. The subroutine GETARG returns a specified argument itself, as a character string. Unless I'm missing something, an internal write is needed to convert the argument itself from a character string to an integer variable (or floating point, if that's appropriate.) The example I gave _should_ have been written as: character*1 ic,jc c c-----get arguments from command line c n = iargc() call getarg(1,ic) call getarg(2,jc) read (ic,'(i1)') i read (jc,'(i1)') j If this code is part of a.out, then a.out 3 6 yields n=2, i=3, j=6. As another poster noted, all this is system-dependent. It's not standard fortran. I've used getarg (and now iargc) on an SGI Iris 4D. Getarg is also available on the Cray X-MP and Y-MP under UNICOS 5.0, but as a function instead of a subroutine. I don't know about other systems. Sorry about the screw-up. That's what I get for posting code I haven't actually run. -- Charlie Towne Email: pstowne@zargon.lerc.nasa.gov MS 5-11 Phone: (216) 433-5851 NASA Lewis Research Center Cleveland, OH 44135