Reputation: 719
I'm new to Fortran, and trying to repurpose a bit of code that is part of a larger program I've inherited. When the program is run, it prompts for output file names. I would prefer to specify these output file names directly in the code, so I can run the program in parallel/all at once (the run time of the program is about 15 hours, and needs to be run for 66 different files, so I would prefer to run them all at once as opposed to one after another because that would take quite a long time).
The bit of code I'm working with looks like this:
24 print *,'Enter output filename'
25 read(*,*) fout
26 print *,'Enter parameter estimate output filename'
27 read(*,*) foutb
28 print *,'Enter seed for random number generator'
29 read(*,*) idum
30 if(idum.gt.0) idum = -idum
Everything I've tried gives me:
At line 25 of file v1.f95:
Fortran runtime error: End of file
I've checked that I have proper line endings. Any suggestions?
Upvotes: 0
Views: 990
Reputation: 361
I think your error comes from the fact that fout cannot be read without a character string as the format specifier. Try this on line 25 (and in other read's)
read(*,'(a)') fout
You could improve on that if you copy the length from the definition of fout, like so (guessing the size)
CHARACTER fout(25)
.
.
.
read(*,'(a25)') fout
You are reading from the standard input (this is the asterisk in the first argument). I assume your input file is ASCII text. Like you have it now, you could specify the names of the output files on the first two lines of the file, then a third line for idum, then the rest of the input (if you have any).
Say your executable is my_program.exe and your input file (with the three lines mentioned above) is my_input_file.txt, you could redirect the input file to standard input like this
%> my_program.exe < my_input_file.txt
Upvotes: 0
Reputation: 6989
perhaps the simplest possible solution for you, assuming you have only a few simple read(*,*)'s you can leave the code alone and simply pipe the required strings to standard input
echo "file1\nfile2\n3" | executable
(tested under csh.. you might need to tweak a bit for a different shell)
The error message BTW makes me think you were already reading from a stdin pipe rather than a terminal and some prior read exhausted the input.
Upvotes: 0
Reputation: 2953
If I understand the question correctly, you want to pass a number of output filenames/other variables to your program at runtime. This could be handled by using a simple namelist input file, and passing this single file to the program. The code would look like, for example:
character(20) :: file1, file2, file3
integer :: idum
namelist /input/ file1, file2, file3, idum
read(unit = iunit, nml = input)
where iunit
is the I/O unit connected to the previously opened input file. The contents of this file would be like
&input ! Name of corresponding namelist group
file1 = 'file1.out',
file2 = 'file2.out',
file3 = 'file3.out',
idum = 1
/
Namelist files are very easy to handle. They don't care about the order of entries, record length or comments. You can omit any variables in the namelist file (their value will not be modified), or include multiple namelists (even of the same name) in a single file.
Upvotes: 3