……大家好,编程小白请教一下大家一个问题。本来么,用DMol3算周期性结构的Optics,结果得到了线状的吸收光谱,所以只能找把线状光谱转为带状光谱的软件了……
在网上看到一个代码,然而我死活用不了,看了半天估摸着可能是输入文件的问题,不过我完全不知道该怎么处理,这里就只能向大家请教了。
.f90的代码如下,
!---------------------------
PROGRAM GaussianBroadening
!---------------------------
!
! Purpose : Perform a Gaussian broadening on a set of impulse signal data as input.
! Sigma will be calculated from the hight of the impulses signal.
! You must input the range and the step of the output data in the proper order.
! No ouput file to be written, since it is designed to output to standard screen
! so as to work with gnuplot, as usage shown below.
! if you want to get an output file with final data, uncommnent related 2 lines.
! you would get 'g-broadened.dat'
!
! UsageEx : plot '< gbroad.x input.dat width Xmin Xmax Xstep < ' u 1:2 ...
! in which, width : FWHM, full width at half maximum, e.g., 3.0
! Xmin, Xmax: the range of X in output, e.g., 500 3000
! Xstep : the increment of X in the output, e.g., 2
!
! Note : all unit of X are the same with input, e.g., cm-1
!
! Author : Xijun Wang, 2012.12.26
!
implicit none
integer, parameter :: dp = kind(1.0d0)
character(len=20) :: arg, input
character(len=100) :: temp
real(dp), allocatable :: X0(:), Y0(:) ! 0 - input, no 0 - output
integer,parameter :: inputfile = 10, outputfile = 20
real(dp) :: X, Y, Xmin, Xmax, Ysum, Yavg, sigma, pi ! sigma2 is sigma square
integer :: step, i, j, nline, stat ! nline: number of lines
logical :: alive
CALL getarg(1, arg)
input = trim(arg)
inquire(file=input, exist=alive)
if( .not. alive) then
write(*,*) input, "does not exist! "
stop
end if
call getarg(2, arg)
read(arg, *) Xmin
call getarg(3, arg)
read(arg, *) Xmax
call getarg(4, arg)
read(arg, *) step
call getarg(5, arg)
read(arg, *) sigma
! open and count number of lines in input file
open(unit=inputfile, file=input, access="sequential", status="old")
nline = 0
do
read(unit=inputfile, FMT=*, END=100) temp
nline = nline + 1
end do
100 continue
rewind(inputfile)
! allocate memory for arrays X0, Y0
allocate(X0(1:nline), Y0(1:nline))
! read in data from input file
do i = 1, nline
read(unit=inputfile,FMT=*,iostat=stat) X0(i), Y0(i)
end do
! Uncomment the following line if you want to output to file
! open(unit=outputfile,file="g-broadended.dat", status='replace', action='write')
pi = 2.0 * acos(0.0_dp)
X = Xmin
do while(X .le. Xmax)
Y = 0.0
do i = 1, nline
if( abs(X - X0(i)) .le. 3 * sigma ) then
Y = Y + Y0(i)/(sigma*sqrt(2*pi)) * exp(-1.0*(X - X0(i))**2.0/(2.0*sigma*sigma) )
end if
end do
! uncomment the following line if you want to output to file
! write(unit=outputfile,fmt="(F6.2,1X,F8.6)") X, Y
write(*,fmt="(F9.1,1X,F15.8)") X, Y
X = X + step
end do
! release memory
deallocate(X0, Y0)
stop
END PROGRAM GaussianBroadening
gfortran编译成可执行文件后,使用./command运行的时候显示does not exist,我想它本来的意思是输入一个文件名然后读取(是call getarg命令吧?),问题似乎是无法写入文件名就报错了。(还是说我理解有误?)
所以这里诚恳地求助啊…… |