Software Archive
Read-only legacy content
17060 Discussions

Read Input file from working directorly

Intel_C_Intel
Employee
1,428 Views
I'm working with a program which use Excel spreadsheet to take input data and write to an input file, then use a Fortran Console application to read that input file, perform some calculation and then write to several output files. The question is the location of the input file created by Excel may very. how could the Fortran Consonle application know where to find it. Is there anyway I could pass an argument or commnd line from Excel to Fortran exe.
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
1,428 Views
Sure, see NARGS/GETARG:

 
PROGRAM Foo 
 
USE DFLIB 
 
CHARACTER (MAX_PATH)::     sDir="" 
 
IF (NARGS() .GT. 0) CALL GETARG(1, sDir) 


and change all your open statements so that they look like:

 
OPEN (11, FILE=TRIM(sDir)//"input.txt") 


HTH

Jugoslav
0 Kudos
durisinm
Novice
1,428 Views
You can also consider writing an Excel VBA macro to pass an argument directly to a Fortran DLL. You can probably change your console application to a DLL by changing its main program to a subroutine. If you do, though, the Fortran code shouldn't write any output to the console. The console won't exist unless the DLL explicitly creates it. Writing to and reading from files is OK.

Mike
0 Kudos
Reply