Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for a File and get the name

Status
Not open for further replies.

ehsansharei

Civil/Environmental
Joined
Jan 11, 2013
Messages
6
Location
DE
Hi everybody,
I am new Fortran user. I have written a Subroutine which opens an Input file in the current work directory and reads some data from this file. The Problem is that the Name of the input file changes each time but the extension is always .inp. Is is possible in Fortran 77 to get the file name automatically and open the file without changing the name each time in READ statement?
Any answer is really appreciated.
Regards
Ehsan
 
You'll need something like this so start.
Code:
      program main
      character(len=32):: arg
      integer:: numarg
! print arguments from the command line
      numarg = command_argument_count()
      print *, 'Num arg ', numarg
      do nn = 1, numarg
         call get_command_argument(nn, arg)
         print*, 'arg ', nn, ' = ', arg
      end do
      end
Next, it depends on which OS you are using. All This does is print the command line arguments. This can be used as the filename. To run it from windows, you will need a script that looks something like this
Code:
for %%i in (*.inp) do processdata %%i
 
Forgot to add that you use the argument in the first program as the file to be opened.
 
Thank you so much for your replay. But you have written the code in Fortran 90 I think (?). By the way I could solve the problem, acquiring the name of the job directly from the software which the subroutine s written for. Thanks a lot again.
Ehsan
 
It is F77: just a cut and paste problem that put the program bit in column 1. This one works on GNU and Silverfrost. Other manufacturers may have their own version of it for F77.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top