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!
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...

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