Please login or register.

Login with username, password and session length
gfx gfx
1619 Posts in 535 Topics by 781 Members - Latest Member: chekyl43 January 27, 2023, 03:42:34 PM
gfx* Home | Help | Search | Login | Register | gfx
Absoft User Forum  |  Support  |  Macintosh  |  command line argument

Author Topic: command line argument  (Read 6580 times)


  • Newbie
  • *
  • Posts: 1
command line argument
« on: November 07, 2007, 01:31:10 PM »
I'm fairly new to fortran so I'm going to give more info than I probably need to.

I need to write a program that takes arguments from the command line at execution. For instance, when I run the program I might type
./a.x myfile.txt

My fortran program would read the argument myfile.txt from the command line and then create a file with that name and write some data to it.

A very simple version of my code is:

implicit none

character(len=20) :: filename

call getarg(1,filename)
write(20,*) "data ..."

end program

to compile it I am typing (using the absoft compiler):
f95 ci1.f90 -o ci1.x

The output from the compiler reads:

/usr/bin/ld: Undefined symbols:
/tmp/RFXbDO/ci1.o reference to undefined _GETARG
collect2: ld returned 1 exit status
link failed.

In doing research I also found reference to a command called GET_COMMAND_ARGUMENT and got an error in compiling that as well.

Any help would be greatly appreciated.



  • Newbie
  • *
  • Posts: 8
Re: command line argument
« Reply #1 on: November 08, 2007, 11:20:14 AM »
Dear ejoswaler: Though I use the windows version of the Absoft fortran compiler and am not familiar with the Macintosh, I think your problem reflects the fact that Absoft Fortran is a standards compliant Fortran 95. The standard does not include a GETARG procedure. Lahey Fortran 77 and 95 does include a procedure GETCL that returns the command string as an argument but I don't think Absoft Fortran does.

However, there are at least two easy solutions: 

(1) The easiest one is to read the information from an input file. Simply prepare an input text file with any input data you would like. This approach is very convenient and easy.

(2) Amost as easy is to link to a "C" main program that gets the command arguments and pass them to your fortran program. This is the approach where you use C for the stuff it does easily and well and use Fortran for the heavy lifting, that is, for the numerical procedures.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: command line argument
« Reply #2 on: December 08, 2007, 02:53:06 AM »
Check whether you are including the Absoft UNIX compatibility library. The "getarg" function is in that library.

Absoft User Forum  |  Support  |  Macintosh  |  command line argument

gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!