作者bestman8556 (廷廷)
看板Fortran
標題[問題] 讀檔特定區域一問
時間Mon Nov 19 17:24:13 2012
這是我的data長樣:
2012/xx/xx abcdefgxxxxxxxxxxx(表示有問字敘述)
abcdefgxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
12 1234 4567
55 4321 7654
.. .... ....
.. .... ....
.. .... ....
^^^ ^^ ^^
檔案中"^"表示有空白的存在
目前已經試過下列方法:
open(unit=10, file='filename.txt')
100 format(
2/,5X,I6)
200 format(I6)
read(10,100) a
write(*,200) a
程式碼中黃色的2字可以成功跳過2012/xx/xx以及文字敘述那兩列
但因為某些需求黃色文字的部分想要用一個變數取代
就像是
E=12
100 format(
E/,5X,I6)
但執行結果他都要求我必須以一個constant or general expreesion
來表示我大寫
E的部分
請求解...............QQ
PS:我有試過另一個方法用open(access='direct',recl=
?)
問號的部分我不知道到底要用甚麼長度分才正確..........
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.120.35
1F:推 hiyiyi:1.write(fmtstr,*) E,'/,5X,I6' & read(10,fmtstr) a 11/19 17:52
2F:→ hiyiyi:或2.迴圈跳行 do i=1,E & read(10,"(A)") linestr & end do 11/19 17:55
3F:→ bestman8556:h大的第一種方法是說 11/19 18:44
4F:→ bestman8556:用write(字串格式,*) E,'/,5X,I6' 來拼湊出一個字串 11/19 18:46
5F:→ bestman8556:然後寫入100 format() 裡面嗎? 我一值嘗試不成功 11/19 18:46
6F:→ bestman8556:在寫出write(字串格式,*) E,'/,5X,I6' 這部分出問題. 11/19 18:50
7F:→ bestman8556:解決了~~~ 謝謝~~~~ 11/19 23:17