×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

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!

*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

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! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close