Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29236 Discussions

Associate a file type to my Fortran program

los
Beginner
726 Views
Hello,
If I select to use my Fortran (QWin) program to open a file I have clicked on, how can I get the file name inside the program for proper actions? I have some different types of files that I would like to associate and must have the file extension to read the filewith differentroutines.
Best Regards
Lars
0 Kudos
2 Replies
anthonyrichards
New Contributor III
726 Views

If you need the filename, use NARGS to get the number of command line arguments and use GETARG to access the filename from the command line. Then you can parse the filename and go on from there. With the use of GETARG programmed in, you will also be able to drag-and -drop a filename onto a shortcut to your application and start it that way. You can also associate your application with several filename extensions in Explorer (see Tools..Folder Options..File Types from the Explorer menu bar),then double-clicking on a filename with one of the extensions will start you application with the filename as the first argument after the application's name. From the FORTRAN Help:

GETARG Run-Time Subroutine: Returns the specified command-line argument (where the command itself is argument number 0).

Module: USE DFLIB

Syntax CALL GETARG (n, buffer [, status])

n (Input) INTEGER(2). Position of the command-line argument to retrieve. The command itself is argument number 0.

buffer (Output) Character*(*). Command-line argument retrieved.

status (Optional; output) INTEGER(2). If specified, returns the c completion status. If there were no errors, status returns the number of characters in the retrieved command-line argument before truncation or blank-padding. (That is, status is the original number of characters in the command-line argument.) Errors return a value of -1. Errors include specifying an argument position less than 0 or greater than the value returned by NARGS. GETARG can be used with two or three arguments. If you use module DFLIB.F90 in the DF98INCLUDE subdirectory (by including the statement USE DFLIB), you can mix calls to GETARG with two or three arguments. If you do not use DFLIB.F90, you can use either two-argument or three-argument calls to GETARG but only one type of call within a subprogram. GETARG returns command-line arguments as they were entered. There is no case conversion.

0 Kudos
los
Beginner
726 Views

Thank you for your help, it works just fine!

Regards,

Lars

0 Kudos
Reply