Fortran runtime error: No such file or directory

3,554 views
Skip to first unread message

Stephen P. Molnar, Ph.D.

unread,
Nov 13, 2005, 10:37:13 AM11/13/05
to gg...@googlegroups.com
I have just installed g95 on my SuSE9.3 linux partition. I only had to correct
two syntax errors in a FORTRAN 77 program in order to get it to compile
without any error or warning messages.

However, when I attempt to run the program I get the error:

Fortran runtime error: No such file or directory

Traceback tells me that the error is in line 37 of the source code:

open (1,file=' ',access='sequential',status='old')

Where do I find the correct syntax for opening named files?

Thanks in advance.
--
Stephen P. Molnar, Ph.D. Life is a fuzzy set
Foundation for Chemistry Stochastic and multivariant
http://www.geocities.com/FoundationForChemistry

Joost

unread,
Nov 13, 2005, 10:55:41 AM11/13/05
to gg95
This runtime error means that the file with name ' ' (i.e. the argument
of 'file') does not exist in the directory where the program is
running. ' ' (that is a single space) is a bit a special name for a
file since trailing spaces are ignored (as required by the standard).
Try something like

open(1,file='data.xyz',status='old')

where data.xyz is present in the directory where you run the program.
If the file is not present and you want your program to create it, use
status='unknown'

Joost

s.mo...@sbcglobal.net

unread,
Nov 13, 2005, 11:59:50 AM11/13/05
to gg95

Thanks for the reply. When I include the name of the data file the
program executes and I get output. Unfortunately, I run batches of
input files and I need an input statement that will look in the
directry in which it is running and find the name of the input file.

I hope my explination isn't too confusing.

Joost

unread,
Nov 13, 2005, 1:33:46 PM11/13/05
to gg95
Well, in that case you'll have to code something to do that, there is
nothing automatic. Three simple ways:

0) in your script that runs your batch of jobs, always copy the
inputfile to a temporary one with the same name...

1) get it from the command line

./a.out filename.dat

you can code that easily like this
character(LEN=200) :: filename
CALL get_command_argument(1,filename)
open(1,file=filename,status='old')

2) read the name of that file that always has the same name
('INPUTFILE')
open(1,file='INPUTFILE')
read(1,*) filename
close(1)
open(1,file=filename, ...)

Cheers,

Joost

Message has been deleted

Natasha Green

unread,
Mar 11, 2014, 10:31:12 AM3/11/14
to gg...@googlegroups.com, jv...@cam.ac.uk
Thanks for this. For some reason I am still getting errors when it comes to the file reading an "stdout" file

Error:
At line 15 of file decmp.f (unit = 6, file = 'stdout')"


Files: 
-- decmp


#!/bin/csh
#
#
# LNUM = N^2 + N + 1
#

 set lnum = 10101

 
 echo $lnum
#
 foreach NUM ( 1 2 3 4 5)
#
   setenv OUT bx1_$NUM
   sed  "s/changeme/ $NUM   $lnum/g" whichtmp > which
   ~/Desktop/right100/decmp.x
#
end



---decmp.f

      program decmp
      implicit double precision(a-h, o-z)
      character*80 junk80
      character*6 nam
c
      iskip = 0
      open (unit=7, file='which')
      read(7,*) iwhch, lnum
      close(unit=7)
      write(0,*) iwhch
c
      open (unit=5, file='wave2d.out')
c
      call getenv('OUT',nam)
      open (unit=6, file=nam)

c
      istart = (iwhch-1)*lnum
      do j=1,istart
         read(5,2004) junk80
      end do
      do i=1,lnum
         read(5,2004) junk80
         write(6,2004) junk80
      end do
c
 2004 format(a80)
      close(unit=6)
      close(unit=5)
c
      stop
      end
Reply all
Reply to author
Forward
0 new messages