Fortran Coder

标题: 程序输出到文件,求大神看看应该改哪,新手求助 [打印本页]

作者: Sin    时间: 2016-6-11 18:41
标题: 程序输出到文件,求大神看看应该改哪,新手求助
[Fortran] 纯文本查看 复制代码
program gyro
implicit none
!-- ofen used constant
real(8),parameter :: light_speed=2.99792458d8, pi=3.14159265d0, h_pc=6.62620d-34
!-- parameter of the detector
real(8),parameter :: eta=0.9d0, t0=3.6d3
!-- input parameter of the incident ligth
real(8),parameter :: intensity_input=1.0d-6, wavelength=1550d-9, frequency=light_speed/wavelength
!-- structure parameter of the ring
real(8)  :: radius_ring, length_ring
real(8)  :: neff_r, neff_i                                                                               
!-- structure parameter of the waveguide
!     real(8)  :: radius_nanoline
!-- variables
real(8)  :: k, alpha, m, t_max, t_min, snr, df12,domega
!-- common integer variables
integer  :: n
radius_ring = 5.0d-2      
!     unit =   m, correspongding to 2cm
length_ring = 2*pi*radius_ring       
        neff_r = 1.451117
        neff_i = 7.485137d-6
!-- correspongding propagation loss and effective index
        alpha = 2.0*pi*neff_i/wavelength
!-- open(1,file='output.dat')
write(1,*) 'k  m  t_maxt_minsnr  df12  domega'
do n = 1, 99, 1
       k = n*0.01d0
m = exp(-alpha*length_ring)
t_max=( 2*m*dsqrt(1-k) + (1-k) + m**2 ) / ( 1 + 2*m*dsqrt(1-k) +(m**2)*(1-k) )
t_min=(-2*m*dsqrt(1-k) + (1-k) + m**2 ) / ( 1 - 2*m*dsqrt(1-k) +(m**2)*(1-k) )
snr = dsqrt( (eta * t0 * intensity_input) / ( 2 * h_pc * frequency ) )*( (t_max - t_min)/dsqrt(t_max) )
df12 = ( light_speed / (2*neff_r*pi*length_ring) ) * (2*pi - 2*dacos( (2*m*dsqrt(1-k))/( (m**2)*(k-1) -1 ) ) )
domega = 3600*(wavelength / ( 2*radius_ring ) ) * ( ( dsqrt(2.0d0)*df12 )/ snr )
write(1,'(10e20.5e3)') k, m, t_max, t_min, snr, df12, domega
enddo
close(1)
end program gyro


作者: li913    时间: 2016-6-11 21:30
缺少 open 语句,看看书。
作者: Sin    时间: 2016-6-11 21:50
li913 发表于 2016-6-11 21:30
缺少 open 语句,看看书。

能详细说一下应该改哪吗,以前没接触过Fortran,谢谢
作者: fcode    时间: 2016-6-12 15:00
program gyro
implicit none
!-- ofen used constant
real(8),parameter :: light_speed=2.99792458d8, pi=3.14159265d0, h_pc=6.62620d-34
!-- parameter of the detector
real(8),parameter :: eta=0.9d0, t0=3.6d3
!-- input parameter of the incident ligth
real(8),parameter :: intensity_input=1.0d-6, wavelength=1550d-9, frequency=light_speed/wavelength
!-- structure parameter of the ring
real(8)  :: radius_ring, length_ring
real(8)  :: neff_r, neff_i                                                                               
!-- structure parameter of the waveguide
!     real(8)  :: radius_nanoline
!-- variables
real(8)  :: k, alpha, m, t_max, t_min, snr, df12,domega
!-- common integer variables
integer  :: n
Open( 1 , File = "文件名" )
radius_ring = 5.0d-2      
!     unit =   m, correspongding to 2cm
length_ring = 2*pi*radius_ring       
        neff_r = 1.451117
        neff_i = 7.485137d-6
!-- correspongding propagation loss and effective index
        alpha = 2.0*pi*neff_i/wavelength
!-- open(1,file='output.dat')
write(1,*) 'k  m  t_maxt_minsnr  df12  domega'
do n = 1, 99, 1
       k = n*0.01d0
m = exp(-alpha*length_ring)
t_max=( 2*m*dsqrt(1-k) + (1-k) + m**2 ) / ( 1 + 2*m*dsqrt(1-k) +(m**2)*(1-k) )
t_min=(-2*m*dsqrt(1-k) + (1-k) + m**2 ) / ( 1 - 2*m*dsqrt(1-k) +(m**2)*(1-k) )
snr = dsqrt( (eta * t0 * intensity_input) / ( 2 * h_pc * frequency ) )*( (t_max - t_min)/dsqrt(t_max) )
df12 = ( light_speed / (2*neff_r*pi*length_ring) ) * (2*pi - 2*dacos( (2*m*dsqrt(1-k))/( (m**2)*(k-1) -1 ) ) )
domega = 3600*(wavelength / ( 2*radius_ring ) ) * ( ( dsqrt(2.0d0)*df12 )/ snr )
write(1,'(10e20.5e3)') k, m, t_max, t_min, snr, df12, domega
enddo
close(1)
end program gyro

作者: pasuka    时间: 2016-6-12 19:20
fcode 发表于 2016-6-12 15:00
program gyro
implicit none
!-- ofen used constant

直接用通道1好像不妥当吧,还是推荐用newunit参数
其实最理想的是,类似Python的with open(file_name, mode) as fp: ...的模式




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2