I have a Fortran subroutine that is called several times in a main program (which I don't have access to). In my subroutine, I wish to read data from one of several (~10^4) files in every iteration based on an input argument. Each of the files has one line of data; and the format of my data is as follows:
0.97014199999999995 0.24253600000000000 0.0000000000000000
I'm using the following lines of code to open and read the files:
program test_read
implicit none
integer :: i, iopen_status, iread_status
real :: gb
CHARACTER(len=25) :: filename
CHARACTER(*), PARAMETER :: fileplace =
& "/home/ajax/hexmesh_readn/G3/"
dimension gb(3)
i = 5
WRITE(filename,'(a,I0,a)')'GBn_',i,'.txt'
open(unit=15,
& file=fileplace//filename,IOSTAT=iopen_status)
read (15,*,IOSTAT=iread_status) gb
print *,"gb",gb(1),gb(2),gb(3)
close(15)
end program test_read
- In the main program, i is a variable, but I have a file for all possible values of i.
- Now, this code works perfectly well when I run on my local machine. But, when I submit it along with the main program, it behaves somewhat weirdly. Specifically, it reads some of the files, but not others.
- When I print out the IOSTAT for open and read, I see that the IOSTAT for open is 0 for all the files, whereas that for the read command is 0 for some, -1 for some and 29 for others! I looked up what the error code 29 means and I learned that it might indicate that the file is not found in the path. But the file is most definitely there.
- Also, I don't see anything different about the files that it isn't able to read. In fact, I have even seen the same file giving an IOSTAT value of 0 and 29!
- One thing to note is that I'm running the main program on several cores. Could this have anything to do with the error?
iomsg=specifier (and check iostat values when you useiostat=) applies here. - francescalusiomsgis only available in Fortran 2003 onwards, but I'm using Fortran 90. Also, where do you mean I should indent by 4 columns? Before the first column? - Ajaxiomsg=, just try it. It may not work for your compiler, but there are very few Fortran 90 only compilers currently in popular use (and not many more Fortran 2003 compilers). And it's worth noting that your code in the question isn't Fortran 90. - francescalusCHARACTER(*)is an assumed length declaration. That syntax is valid Fortran 90. - IanH