Note that there are some explanatory texts on larger screens.

plurals
  1. PONew to Fortran, questions about writing to file
    text
    copied!<p>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 half of the code is: </p> <pre><code>C C Open direct-access output file ('JPLEPH') C OPEN ( UNIT = 12, . FILE = 'JPLEPH', . ACCESS = 'DIRECT', . FORM = 'UNFORMATTED', . RECL = IRECSZ, . STATUS = 'NEW' ) C C Read and write the ephemeris data records (GROUP 1070). C CALL NXTGRP ( HEADER ) IF ( HEADER .NE. 'GROUP 1070' ) CALL ERRPRT(1070,'NOT HEADER') NROUT = 0 IN = 0 OUT = 0 1 READ(*,'(2i6)')NRW,NCOEFF if(NRW .EQ. 0) GO TO 1 READ (*,'(3D26.18)',IOSTAT =IN) (DB(K),K=1,NCOEFF) DO WHILE ( ( IN .EQ. 0 ) . .AND. ( DB(2) .LT. T2) ) IF ( 2*NCOEFF .NE. KSIZE ) THEN CALL ERRPRT(NCOEFF,' 2*NCOEFF not equal to KSIZE') ENDIF C C Skip this data block if the end of the interval is less C than the specified start time or if the it does not begin C where the previous block ended. C IF ( (DB(2) .GE. T1) .AND. (DB(1) .GE. DB2Z) ) THEN IF ( FIRST ) THEN C C Don't worry about the intervals overlapping C or abutting if this is the first applicable C interval. C DB2Z = DB(1) FIRST = .FALSE. ENDIF IF (DB(1) .NE. DB2Z ) THEN C C Beginning of current interval is past the end C of the previous one. CALL ERRPRT (NRW, 'Records do not overlap or abut') ENDIF DB2Z = DB(2) NROUT = NROUT + 1 print*,'Out =', OUT WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF) print*,'Out2 =', OUT IF ( OUT .NE. 0 ) THEN CALL ERRPRT (NROUT, . 'th record not written because of error') ENDIF </code></pre> <p>So, when I print "Out" and "Out2" to the screen I find that Out=0 and Out2=110. As it is not longer equal to zero, the program gives me an error. Therefore I am basically wondering about what is happening here:</p> <pre><code>WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF) </code></pre> <p>I assume that 12 refers to the file I have opened (and created), and want to write to. What does the rest of the first brackets do? And what is the point of the second? Does that gives me the information I want to put in my file? In case, where does DB get filled with that?</p> <p>Generally I am wondering what is going wrong? Why does OUT change value? (I need t</p> <p>NCOEFF is defined as an Integer in the beginning of the programme, and DB: as DOUBLE PRECISION DB(3000), DB2Z/0.d0/ , so I assume DB is an array of some sort.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload