How to read variables of unknown width?

前端 未结 2 502
长发绾君心
长发绾君心 2021-01-26 04:51

I think this is quite a basic question, but I can\'t seem to find the answer. I\'m trying to read a file of the following form:

     1 filedir/i03j12_fort.4
             


        
2条回答
  •  离开以前
    2021-01-26 05:19

    For completeness, here is my chosen solution, which relies on the fact that the string following the integer always starts with '/' (as it's a filepath):

    ! first determine how much whitespace is around the first integer
    ! and store this as string ln
     read(20, '(a)') filestring
     write(ln, "(I1)") INDEX(filestring, ' /')-1
     rewind(20)
    
    ! use ln to as the integer width
     read(filenumber,'(i'//ln//','//ldir//'x,i2,x,i2)') n,pix_i,pix_j
    

提交回复
热议问题