[問題] 實數轉字串 卻有錯誤
我想要在路徑下用迴圈開從-3.0, -2.8,...,0,...,2.8,3.0的.txt檔
我已經先建立好所需要用到的資料夾,包括"pk0.03","-3.0","-2.8".....
一開始都正常,但是到abil= -1.2以後,下一次的迴圈
就會變成abil=-0.9999996而不是-1.0,
到abil=0.0時就會出現錯誤,無法繼續跑下去
以下是我的程式碼
program main
implicit none
integer,parameter::ni=20
real::abil
character*7::r_name
character*2:: ni1
call int_to_cht(ni,ni1)
do abil=-3.0,3.0,0.2
call real_to_cht(abil,r_name,888)
open(250+abil,file="D:\pk0.03\"//TRIM(r_name)//"/SH_"&
//TRIM(r_name)//"_"//TRIM(ni1)//".txt",status='replace')
write(250+abil,"(g5.1,4(g10.1))") "迭代","Bias","RMSE","max_expo","not_use"
open(350+abil,file="D:\pk0.03\"//TRIM(r_name)//"/SH_1_"&
//TRIM(r_name)//"_"//TRIM(ni1)//".txt",status='replace')
write(350+abil,"(g5.1,3(g10.1))")"item","P(A)","P(S)","pk"
open(450+abil,file="D:\pk0.03\"//TRIM(r_name)//"/item_"&
//TRIM(r_name)//"_"//TRIM(ni1)//".txt",status='replace')
open(550+abil,file="D:\pk0.03\"//TRIM(r_name)//"/theta_hat_&
"//TRIM(r_name)//"_"//TRIM(ni1)//".txt",status='replace')
open(650+abil,file="D:\pk0.03\"//TRIM(r_name)//"/迭代次數 _&
"//TRIM(r_name)//"_"//TRIM(ni1)//".txt",status='replace')
end do !! abil
stop
end program
!-------------------------------------------
!實數轉字串
!-------------------------------------------
subroutine real_to_cht(abil,r_name,num)
implicit none
integer::num
real::abil
character*7::r_name
open(num,file="temp.txt")
write(num,"(f4.1)") abil
rewind(num)
read(num,"(a4)") r_name
close(num,status="delete")
return
end
!-------------------------------------------
!整數轉字串
!-------------------------------------------
subroutine int_to_cht(ni,ni1)
implicit none
integer::ni
character*7::ni1
open(987,file="temp.txt")
write(987,"(I2)") ni
rewind(987)
read(987,"(a2)") ni1
close(987,status="delete")
return
end
不知道是哪裡出了問題,
想請各位高手幫我看一下@@
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.239.136
→
06/27 00:06, , 1F
06/27 00:06, 1F
→
06/27 00:06, , 2F
06/27 00:06, 2F
→
06/27 10:01, , 3F
06/27 10:01, 3F
→
06/27 11:24, , 4F
06/27 11:24, 4F
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章