Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!noao!ncar!bierstat.scd.ucar.edu!morreale From: morreale@bierstadt.scd.ucar.edu (Peter Morreale) Newsgroups: comp.lang.fortran Subject: Re: How to load executables and transfer variable name to FORTRAN Message-ID: <8198@ncar.ucar.edu> Date: 8 Aug 90 18:29:37 GMT References: <8386@ccncsu.ColoState.EDU> Sender: news@ncar.ucar.edu Reply-To: morreale@bierstadt.scd.ucar.edu (Peter Morreale) Organization: Scientific Computing Division / NCAR, Boulder CO Lines: 73 In article <8386@ccncsu.ColoState.EDU>, flatau@handel.CS.ColoState.Edu (flatau) writes: |> Say, I have a file "prog.f" |> |> Compile it as (UNIX): |> |> f77 prog.f -o prog |> |> and execute "prog" with a parameter, e.g. |> |> prog 'file.dat' |> |> Is the above possible (loading step) ? |> Is there a way to assign "name" to 'file.dat' from within |> a fortran code ? How should I modify "prog.f" to make it work ? |> |> flatau@handel.cs.colostate.edu If the UNIX is SunOS (or UNICOS, I suspect some others as well) you can use the routines: call getarg(k,arg) icnt = iarg() GETARG returns the K'th commandline argument to ARG. ARG should be a CHARACTER variable sufficently large enough to hold ARG. IARGC retuns a count of the number of commandline arguments. Example: (not tested) program tst character*80 arg integer ilen c c Get the commandline argument, assume it is a valid filename c call getarg(1,arg) c c Find out where the last non-null character is in ARG... c ilen= index(arg,char(0))-1 open(file=arg(1:ilen),unit=10.....) .............. end Note, GETARG only retuns the blank separated word from the commandline. You are responsible for checking the arguments, parsing, etc.... IARGC is useful to iterate a loop where more than one argument may be encountered.... Other UNIXs may provide a Fortran interface to the C routine: getopt -PWM ------------------------------------------------------------------ Peter W. Morreale email: morreale@ncar.ucar.edu Nat'l Center for Atmos Research voice: (303) 497-1293 Scientific Computing Division Consulting Office ------------------------------------------------------------------