2017-03-01 97 views
0

我需要打開一個二進制文件,數據的開發人員提供了一個用Fortran編寫的程序。我是Fortran語言的新手,但我認爲值得嘗試使用ready程序,而不是自己寫一個新的程序。執行隨數據文件提供的Fortran代碼時讀取錯誤

我想打開的文件是this,this是數據手冊,並且可以找到打開數據的代碼行here。數據在開始時包含一個576字節的標題行,可以使用this打開。

我做了什麼: 將二進制文件保存在一個新文件夾中,其中我還保存了打開它的軟件的代碼。設置終端到後者的文件夾(cd /home/urs/../),從經GNU Linux終端後我運行:

# compile the program using gfortran 
    gfortran read_v2.2_month.f -o read_v2.2_month 
# make file executable 
chmod +x read_v2.2_month 
# run the program 
./read_v2.2_month 

然而,我得到以下錯誤:

Error: read error  5016 on file gpcp_v2.2_psg.1987 

編輯: Fortran中的代碼開不包括頭的第一行中的數據如下:

 OPEN (UNIT=10, FILE='gpcp_v2.2_psg.1987', ACCESS='DIRECT', 
    +   FORM='UNFORMATTED', STATUS='OLD', RECL=144, 
    +  IOSTAT=iret) 
     IF (iret .NE. 0) THEN 
      WRITE (*, *) 'Error: open error', iret, 
    +     ' on file gpcp_v2.2_psg.1987' 
      STOP 
     END IF 
C 
C  Compute the number of records to skip, namely 1 for the header 
C  and 72 for each intervening month. 
C 
     nskip = 1 + (month - 1) * 72 
C 
C  Read the 72 rows of data and close the file. 
C 
     DO 10 j = 1, 72 
      READ (UNIT=10, REC=j+nskip, IOSTAT=iret) 
    +   (data (i, j), i = 1, 144) 
      IF (iret .NE. 0) THEN 
       WRITE (*, *) 'Error: read error', iret, 
    +      ' on file gpcp_v2.2_psg.1987' 
       STOP 
      END IF 
    10 END DO 
     CLOSE (UNIT=10) 
C 
C  Now array "data" is ready to be manipulated, printed, etc. 
C  For example, dump the single month as unformatted direct: 
C 
     OPEN (UNIT=10, FILE='junk', ACCESS='DIRECT', 
    +   FORM='UNFORMATTED', RECL=144, IOSTAT=iret) 
     IF (iret .NE. 0) THEN 
      WRITE (*, *) 'Error: open error', iret, 
    +     ' on file junk' 
      STOP 
     END IF 
     DO 20 j = 1, 72 
      WRITE (UNIT=10, REC=j, IOSTAT=iret) 
    +   (data (i, j), i = 1, 144) 
      IF (iret .NE. 0) THEN 
       WRITE (*, *) 'Error: write error', iret, 
    +      ' on file junk' 
       STOP 
      END IF 
    20 END DO 
     CLOSE (UNIT=10) 
     STOP 
     END 
+2

的副本我相信我們需要看代碼。 –

+0

我沒有關注你的鏈接。在這裏發佈一個最小的重現代碼。 – Ross

+0

BTW錯誤5016是'5016 LIBERROR_SHORT_RECORD' –

回答