Can't Skip missing files in loop

  • Thread starter Thread starter Jahir
  • Start date Start date
  • Tags Tags
    files Loop
AI Thread Summary
The discussion centers on troubleshooting a Fortran program that processes input files named with specific numerical values. The user is encountering issues when a file is missing; the program halts instead of skipping to the next iteration. The suggested solution involves using error handling with the `open` statement, specifically utilizing the `iostat` and `err` parameters to capture file open errors. By checking the error number, the program can print a message indicating the missing file and continue to the next iteration without terminating. This approach allows for smoother execution of the program even when some input files are absent. The user confirmed that this solution resolved their issue.
Jahir
Messages
2
Reaction score
0
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

"Input_A=0.00_B=0.00"
"Input_A=0.10_B=0.01"
"Input_A=0.20_B=0.02"
"Input_A=0.30_B=0.03"
"Input_A=0.40_B=0.04"
...
..
"Input_A=..._B=..."

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 anyone 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.
 
Technology news on Phys.org
You can trap the errors when you open the file. Start by doing simething ike

Code:
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.
 
Dear AlephZero,
Thanks a lot. It's working!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
8
Views
1K
Replies
12
Views
10K
Replies
12
Views
3K
Replies
5
Views
5K
Replies
6
Views
3K
Replies
5
Views
2K
Replies
1
Views
3K
Replies
3
Views
2K
Replies
41
Views
5K
Back
Top