0

I have 256 files to be opened and read. And I have to write the result in another separate 256 files with similar names but in different folders. The files should be called in a form of loop (do i = 1,16; do j = 1,16) where the filename is phi=i_theta=j. Thus, it needs to open, read and write the 256 files. I did a code but it is unable to run.

program test1
implicit none
integer:: lskip,lread , count
real ReThe, ImThe, RePhi, ImPhi
integer i,j
real v1,v2,v3,v4,v5



    count = 100
    do i = 1,16
       do j = 1,16
    open(count, file ='phi=',i,'_theta=',j,'.efe')

    !skip first 17 line
    do lskip = 1,17
    read(count,*)
    End do
    ! First 17 lines skiped
    do lread = 1,1


    read(count,*) v1,v2,v3,v4,v5,ReThe, ImThe, RePhi, ImPhi
    End do
  open(count,file ='C:\Users\user\Desktop\test\output_test\
 &phi=',i,'_theta=',j,'.efe', status = 'replace')
   write(count,*)ReThe, ImThe, RePhi, ImPhi
   count = count +1
   end do
   end do
   stop

  end program test1

There are quite many errors when I compile and run the program. The errors are: In file C:\Users\user\Desktop\rtpact1\0_polarization\many_inc\Near_field\TESTSOURCE.f:14

    open(count, file ='phi=',i,'_theta=',j,'.efe')
                             1

Error: Syntax error in OPEN statement at (1) In file C:\Users\user\Desktop\rtpact1\0_polarization\many_inc\Near_field\TESTSOURCE.f:28

 &phi=',i,'_theta=',j,'.efe', status = 'replace')
        1

Error: Syntax error in OPEN statement at (1) In file C:\Users\user\Desktop\rtpact1\0_polarization\many_inc\Near_field\TESTSOURCE.f:28

 &phi=',i,'_theta=',j,'.efe', status = 'replace')
  1

Error: Bad continuation line at (1) In file C:\Users\user\Desktop\rtpact1\0_polarization\many_inc\Near_field\TESTSOURCE.f:28

 &phi=',i,'_theta=',j,'.efe', status = 'replace')
  1

Error: Unclassifiable statement at (1)

Please help to make adjustment in the code. Your help is really appreciated. Thank you

  • As well as the changes to how the file name is constructed, you'll need to pay careful attention to the _fixed form_ nature of your source. – francescalus Apr 17 '20 at 16:38
  • Thank you for your reply. However, I can't understand your point. Can you explain a bit further? Thank you – Hamsa Lekha Apr 17 '20 at 16:43
  • The question is relating two sets of loops and this question is not same as the rest of the questions in the forum as they relate to only one loop. I suggest that this is not a duplicate question. Thank you. – Hamsa Lekha Apr 17 '20 at 16:52
  • 1
    You want to convert an integer to a character. The linked question explains how to do it. The number of loops is at best barely relevant - you just use the same method for each of the integers you need to convert. – Ian Bush Apr 17 '20 at 17:25
  • Noted with thanks. Will look through the link and follow the method – Hamsa Lekha Apr 18 '20 at 02:43

0 Answers0