作者terrylove12 (空洞)
看板Fortran
标题[问题] 资料整理问题
时间Mon Sep 20 11:15:09 2010
最近在学怎麽整理一些资料
然後有一个问题想问板上各位
假设有一个档案 档案的格式大概是这样
stano time temp
466920 2008010101 12.2
466920 2008010102 11.9
467540 2008073101 24.9
467540 2008073102 24.9
72S200 2008022718 12.6
72S200 2008022719 12.5
C0A870 2008062317 27.5
C0A870 2008062318 26.2
然後我想抓 有温度纪录的stano站名就好
所以我写了下面的程式
program work1
implicit none
!---------------
character(len=6) :: station2
character(len=6) :: station1
integer status
station1="1"
status=0
!---------------
open(11,file="t2008.txt")
!---------------
do while (.true.)
read(11,"(A6)" , iostat=status) station2
if (status/=0) exit
if (station2/=station1) then
write(*,"(A6)") station2
end if
station2=station1
end do
end
我想要输出结果为
466920
467540
72S200
C0A870
但是上面的程式 似乎因为字串无法运算
所以station1=station2 没办法成立
station1 的字串值一直是1
所以重复的站名还是会被写出来
不知道有没有办法可以修改这个状况
因为站名有英文字所以我把他宣告为字串
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.13.115
※ 编辑: terrylove12 来自: 140.112.13.115 (09/20 11:25)
1F:推 Cypresslin:你程式码中是写station2=station1而不是sta..1=sta...2 09/20 11:30
2F:→ Cypresslin:另外缩排一下会比较好阅读,个人感想啦 09/20 11:30
3F:→ suzuke:station2=station1反了吧 station1=station2才对~ 09/20 11:35
4F:→ terrylove12:欸 对耶 我傻了 09/20 11:35