New to Fortran, questions about writing to file

后端 未结 4 706
慢半拍i
慢半拍i 2020-12-21 19:35

I am completely new to Fortran and pretty new to programming in general. I am trying to compile a script someone else has written. This is giving me a few problems. The top

4条回答
  •  梦毁少年i
    2020-12-21 20:17

    The statement

    WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)
    

    is, if memory serves me, called an "implied DO-loop". As written, it will write NCOEFF values from array DB, starting at DB(1).

    It is called an implied DO-loop because the explicit form would be (in FORTRAN IV, for the ancients: I know it a lot better than the more modern variations) something along the lines of:

          DO 10 K=1,NCOEFF
          WRITE (12,REC=NROUT+2,IOSTAT=OUT) DB(K)
    10    CONTINUE
    

    (Pretend that the first two lines are indented six columns.) This is a DO-loop. The implied DO-loop form lets you put the "loop" right in the input/output statement.

    What makes it useful is that you can have multiple arrays, and multiple loops. For a simple example:

    WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K), DC(K), K=1,NCOEFF)
    

提交回复
热议问题