2017-04-11 91 views
0

我有.dat文件與14000之間2列和行至36000保存在文件象下面這樣:計數梯度

0.00 0.00 
2.00 1.00 
2.03 1.01 
2.05 1.07 
. 
. 
. 
79.03 23.01 

的第一列是分機,第二是緊張。當我想計算梯度來指定圖的鉤子定律時,我使用下面的代碼。

CCCCCC 
     Program gradient 
     REAL S(40000),E(40000),GRAD(40000,1) 
     open(unit=300, file='Probka1A.dat', status='OLD') 
     open(unit=321, file='result.out', status='unknown') 
     write(321,400) 
400 format('alfa') 
260 DO 200 i=1, 40000 
     read(300,30) S(i),E(i) 
30 format(2F7.2) 
     GRAD(i,1)=(S(i)-S(i-1))/(E(i)-E(i-1)) 
     write(321,777) GRAD(i,1) 
777 Format(F7.2) 
200 Continue 
     END 

但是在我執行它,我得到了警告

PGFIO-F-231/formatted read/unit=300/error on data conversion. 
File name = Probka1A.dat formatted, sequential access record = 1 
In source file gradient1.f, at line number 9 

我能做些什麼與Fortran 77的計數通過這種或其他方式梯度?

+0

如果你用'read(300,*)'替換'read(300,30)',或者爲每行預先加一個空格,那很好嗎? – francescalus

+0

使用'read(300,*)'我得到警告: 'PGFIO-F-217/list-directed read/unit = 300 /試圖讀取文件末尾。 文件名= Probka1A.dat格式化,順序訪問記錄= 14398 在源文件gradient1.f,在行號9' – Witchinster

回答

1

您正在從文件中讀取數據,但未檢查文件的結尾。你的代碼應該是這樣的:

260 DO 200 i=1, 40000 
     read(300,*,ERR=400,END=400) S(i),E(i) 
     if (i>1) then 
      GRAD(i-1,1)=(S(i)-S(i-1))/(E(i)-E(i-1)) 
      write(321,777) GRAD(i-1,1) 
     end if 
777 Format(F7.2) 
200 Continue 
400 continue 
+0

執行此操作後,我得到了此警告: '/tmp/pgf77anqawnGT_Gd.o:在函數梯度' : /mnt/auto/people/plgkamilwalus/fortran/Gryn/Do fortranu /./gradient1.f:13:undefined reference to .LB1_351'' – Witchinster

+0

哪一行是數字13? –

+0

'400 exit' - >是第13行 – Witchinster