Novo no Fortran, perguntas sobre como escrever no arquivo

Eu sou completamente novo no Fortran e bastante novo na programação em geral. Eu estou tentando compilar um script que alguém escreveu. Isso está me dando alguns problemas. A metade superior do código é:

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 

Então, quando eu imprimir "Out" e "Out2" para a tela eu acho que Out = 0 e Out2 = 110. Como não é mais igual a zero, o programa me dá um erro. Portanto, estou basicamente me perguntando sobre o que está acontecendo aqui:

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

Eu suponho que 12 se refere ao arquivo que abri (e criei), e quero escrever para. O que o resto dos primeiros colchetes faz? E qual é o objetivo do segundo? Isso me dá as informações que eu quero colocar no meu arquivo? No caso, onde DB fica preenchido com isso?

Geralmente eu estou querendo saber o que está errado? Por que o valor de mudança OUT? (Eu preciso

NCOEFF é definido como um Integer no começo do programa e DB: como DOUBLE PRECISION DB (3000), DB2Z / 0.d0 /, então eu assumo que DB é um array de algum tipo.

questionAnswers(4)

yourAnswerToTheQuestion