2013-05-14 47 views
0

我正在使用valgrind在我的代碼中查找錯誤。我使用的命令是valgrind在將第二行打印到文件時給出錯誤

,我編譯代碼單獨-g代碼。我得到了很多指向單個寫入行的錯誤(三個打印值被初始化並定義完好)。

write (22,*) avlength, stdlength, avenergy 

全部與Conditional jump or move depends on uninitialised value(s)錯誤。所述行是從一堆行打印到單個文件的第二行。在錯誤的結束,我得到兩個,一個指向行打開文件

resStep = int(conf*100/iterate) 
       if (resStep.lt.10) then 
        write (resFile, "(A5,I1)") "res00",resStep 
       elseif (ResStep.lt.100) then 
        write (resFile, "(A4,I2)") "res0",resStep 
       else 
        write (resFile, "(A3,I1)") "res",resStep 
       endif 
       open (unit=22,file=trim(resFile),status='replace', 
    c     action='write') 

resStep是整數。錯誤是Syscall param write(buf) points to uninitialised byte(s)。最後,當我清除文件時(在關閉文件之前)出現錯誤Address 0x52d83f4 is 212 bytes inside a block of size 8,344 alloc'd

我在這裏找不到任何邏輯。如果問題是以錯誤的方式打開文件,是不是會在第一行顯示錯誤?

我用f95編譯這個,我的gcc版本是4.1.2。我無法升級任何它。

回答

0

大膽猜測:檢查resFile的數據類型。它是一個字符串還是一個單元號?

我的Fortran 95超出生鏽,但嘗試呼叫轉移到的open()調用之前寫()和整數關口resUnit,而不是resFile作爲第一個參數寫( )

CHARACTER(LEN=20):: resFile 
INTEGER(KIND=2) :: resUnit, resStep 

resStep = 1 
resFile = 'MY-results' 
resUnit = 22 
open (unit=resUnit, file=trim(resFile), status='replace', action='write') 
write(resUnit, "(A5,I1)") "res00", resStep 

END 
+0

character(len = 20):: resFile。我的fortran Foo真的很差。我正在更新我的教授代碼以滿足我的需求。 – Yotam 2013-05-14 14:05:40

+0

@Yotam,嘗試在write()之前移動open()並將一個單位而不是一個字符(len = 20)傳遞給open()。我用一個簡短的獨立程序更新了我的答案。 – scottt 2013-05-14 14:45:40