Can't Skip missing files in loop

In summary, the conversation discusses a problem with a Fortran program that reads and writes input data files with numerical values. The program uses a do loop, but terminates if any file is missing. The solution is to trap errors when opening the file and proceed to the next iteration.
  • #1
Jahir
2
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
  • #2
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.
 
  • #3
Dear AlephZero,
Thanks a lot. It's working!
 

Related to Can't Skip missing files in loop

1. What does it mean when I encounter "Can't Skip missing files in loop"?

When you encounter "Can't Skip missing files in loop", it means that there are missing files or data that are needed for the loop to continue running. This can happen if a file or data is accidentally deleted, moved, or renamed.

2. Why is it important to address "Can't Skip missing files in loop"?

It is important to address "Can't Skip missing files in loop" because it can cause errors in your code and prevent it from running properly. It can also lead to incorrect or incomplete results if essential files or data are missing.

3. How can I troubleshoot "Can't Skip missing files in loop"?

To troubleshoot "Can't Skip missing files in loop", you can start by checking if the missing files or data are located in the correct directory. You can also try to manually input the missing data or files if they are available. If the issue persists, you may need to review your code and look for any errors that may be causing the files to be skipped.

4. Is there a way to prevent "Can't Skip missing files in loop" from happening?

Yes, there are ways to prevent "Can't Skip missing files in loop" from happening. One way is to always double-check the file paths and names before running your code. You can also include error-handling in your code to handle missing files or data.

5. Can "Can't Skip missing files in loop" be caused by other factors aside from missing files?

Yes, "Can't Skip missing files in loop" can also be caused by other factors such as incorrect file permissions, corrupted files, or issues with the software or programming language being used. It is important to thoroughly troubleshoot and identify the root cause of the issue to effectively address it.

Similar threads

  • Programming and Computer Science
Replies
12
Views
8K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
2
Replies
41
Views
4K
  • Programming and Computer Science
Replies
4
Views
761
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
18
Views
1K
Back
Top