Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Error in the open statement

Amlesh_K_
Beginner
585 Views

        do m = 0,15,1
                write(fn,*) m,'.txt'
                print *,fn
                open(unit=m,status='unknown',action='read',file=fn)
                print *,'opened file ',fn
                do k = 1,6
                        read(m,*),array(k,m,:)
                        print *,array(k,m,:)
                enddo
        enddo

 

I have the above code to read in an array from multiple files. It successfully reads from the first file but after that it shows error. I am posting the output.

 

           0.txt    
 opened file            0.txt    
   1437989539.58974        1437989540.91451        1437989540.28583     
   1437989540.40498     
   1437989547.74656        1437989547.79766        1437989547.31648     
   1437989547.31722     
   1437989551.27468        1437989551.35893        1437989550.87781     
   1437989550.87831     
   1437989557.64002        1437989557.66885        1437989557.18768     
   1437989557.18810     
   1437989561.10420        1437989561.17505        1437989560.69326     
   1437989560.69363     
   1437989567.37678        1437989567.46258        1437989566.98124     
   1437989566.98164     
            1.txt      
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              00000000004785B1  Unknown               Unknown  Unknown
a.out              0000000000476D07  Unknown               Unknown  Unknown
a.out              0000000000434114  Unknown               Unknown  Unknown
a.out              0000000000433F26  Unknown               Unknown  Unknown
a.out              0000000000406C1F  Unknown               Unknown  Unknown
a.out              000000000040A63D  Unknown               Unknown  Unknown
libpthread.so.0    000000328AC0F500  Unknown               Unknown  Unknown
libc.so.6          000000328A46E940  Unknown               Unknown  Unknown
a.out              000000000043C988  Unknown               Unknown  Unknown
a.out              0000000000412052  Unknown               Unknown  Unknown
a.out              0000000000402FAF  Unknown               Unknown  Unknown
a.out              0000000000402C7E  Unknown               Unknown  Unknown
libc.so.6          000000328A41ECDD  Unknown               Unknown  Unknown
a.out              0000000000402B89  Unknown               Unknown  Unknown

 

0 Kudos
2 Replies
Lorri_M_Intel
Employee
585 Views

You're using "m" both as an index to name your input files, *and* as a unit number.

There are pre-connected unit numbers in Fortran, generally in the lower ranges, and so, you are trying to incorrectly use one of these.

Try something like this instead:

        do m = 0,15,1
                 write(fn,*) m,'.txt'
                 print *,fn
                 open(newunit=u,status='unknown',action='read',file=fn)
                 print *,'opened file ',fn
                 do k = 1,6
                         read(u,*),array(k,m,:)
                         print *,array(k,m,:)
                 enddo
                 close (u)
         enddo

Also, please note that the variable named "array" must have been declared with lowerbound of 0 for its second dimension, as:

real array(6,0:15,100)  (I'm not sure what number the final dimension should be ..)

 

 

 

0 Kudos
Amlesh_K_
Beginner
585 Views

Thanks Lorri.

The problem was related to the array(6,0:15,4)

It works now.

0 Kudos
Reply