Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Can't Skip missing files in loop

  1. May 6, 2014 #1
    Hi all,

    Thanks in advance!
    I'm almost new in Fortran, and I'm having some troubles with a Fortran program. I've some input data files named with numerical values like


    I've to read this within a do loop and have some calculations and make similar output files. I can read and write the files if and only the sequence has no break. If any one file is missing in between, the do loop terminates rather to proceed to take the next as input.

    The program is somewhat like this:

    do A=0.0,1.0,0.1
    do B=0.00,0.5,0.01

    open (1, file =...........)
    do i=1,n
    read(1,*) x(i), y(i)
    end do
    end do
    end do

    I want to make the program to proceed to the next iterations, skipping the missing files and to the end of the steps. Can you guys please help me out? Thanks again.
  2. jcsd
  3. May 6, 2014 #2


    User Avatar
    Science Advisor
    Homework Helper

    You can trap the errors when you open the file. Start by doing simething ike

    Code (Text):

    integer errornumber

    open(1, file=... , err = 99, iostat = errornumber)
    99 if (errornumber .ne. 0) then
       print *, 'a = ', a, ' b = ', b, ' File open error number ', errornumber
       go to .....
    end if
    When you know what errornumber you get for a missing file, you can test for it and do what you want.
  4. May 6, 2014 #3
    Dear AlephZero,
    Thanks a lot. It's working!!!!!!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook