Reading columns from data file in fortran

前端 未结 1 746
时光说笑
时光说笑 2020-12-20 22:56

I wrote the following block to read from an external data file:

     open(unit=338,file=\'bounnodes.dat\',form=\'formatted\') 
      DO I=1,NQBOUN
         D         


        
相关标签:
1条回答
  • 2020-12-20 23:20

    Every read statement in Fortran advances to the next record. This means a new line in normal text files. Try this:

       DO I=1,NQBOUN
         DO J=1,NUMBOUNNODES(I)
            read(338,2001,advance='no') NODEBOUN(i,j)
            write(*,*) 'BOUNDARY NODES',  NODEBOUN(i,j)
         ENDDO
         read(338,*)
       ENDDO
    

    where NQBOUN is number of rows and NUMBOUNNODES(I) is number of columns in a row. (I have allway problems, what is 32x2 vs. 2x32)

    You can make it even shorter, using the implied do

       DO I=1,NQBOUN
            read(338,2001) ( NODEBOUN(i,j) , j=1,NUMBOUNNODES(I) )
            write(*,*) ( 'BOUNDARY NODES', NODEBOUN(i,j) , j=1,NUMBOUNNODES(I) )
       ENDDO
    

    or even

       DO I=1,NQBOUN
            read(338,2001) NODEBOUN(i,:)
            write(*,*) 'BOUNDARY NODES',  NODEBOUN(i,1:NUMBOUNNODES(I))
       ENDDO
    

    All of these use Fortran 90 features.

    0 讨论(0)
提交回复
热议问题