×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Search for a File and get the name

Search for a File and get the name

Search for a File and get the name

(OP)
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

RE: Search for a File and get the name

You'll need something like this so start.

CODE --> processdata.f

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 --> run.bat

for %%i in (*.inp) do processdata %%i 

RE: Search for a File and get the name

Forgot to add that you use the argument in the first program as the file to be opened.

RE: Search for a File and get the name

(OP)
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

RE: Search for a File and get the name

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources