寫文件
filename="/home/allen/sample"
openw,1,filename,/F77_UNFORMATTED
a=[1L,3L,5L,7L,9L,11L,19L]
writeu,1,a
writeu,1,a
close,1
end
得到的sample文件應該保存了下面這個array:
28 1 3 5 7 9 11 19 28 28 1 3 5 7 11 19 28
, 共72 bytes , 其中4 個28 應該是ULong 的類型, 或者說C語言中的unsigned int 類型, 但是因爲是不大的正數, 編碼和Long型的28是一樣的, 簡單地說就是LonArr(9)+LonArr(9)
當做普通二進制
文件讀
filename="/home/allen/sample"
openr,2,filename
a=lonarr(5)
b=lonarr(5)
readu,2,a
print,a
readu,2,b
print,b
close,2
end
IDL> .go
% Compiled module: $MAIN$.
28 1 3 5 7
9 11 19 28 28;這是我們容易理解的, 就只是把二進制數字羅列下去, 讀到哪裏, 停在哪裏, 下一次讀, 從這裏開始.
;從這裏也容易看到, F77_UNFORMATTED的格式不過是每次讀寫數據都要注意到始末位置都包含了一個表示數據總量的校驗值
以F77_UNFORMATTED
格式打開讀
filename="/home/allen/sample"
openr,2,filename,/F77_UNFORMATTED
a=lonarr(5)
b=lonarr(5)
readu,2,a
print,a
readu,2,b
print,b
close,2
end
IDL> .go
% Compiled module: $MAIN$.
1 3 5 7 9
1 3 5 7 9;第一次讀完停在9後面, 正常講下一次讀應該從11開始讀入, 但這裏不是, 它會從下一個檢查點開始讀, 也就是說, 這次讀完, 不管讀入了幾個(變量的總容量超出實際數據量的話立即報錯, 否則沒關係, 所以是小於等於的關係), IDL會根據第一個檢查點的數值直接調到合適的位置(即下一個初始檢查點的位置)