主题:linux系统下fortran 调用shell出错,大家帮着看下!
program main
character(len=50):: filename
integer :: time_u
filename = '08092320.000'
call write_time_data(trim(filename),time_u)
open (12,file='./pp2.txt')
write(12,*)filename
write(12,*)time_u
close(12)
end
subroutine write_time_data(filename_data,dset_t_int)
implicit none
character(len=50):: filename_data
integer :: len_datafile,yr_data,mn_data,dd_data,hr_data,postfix_data,dset_t_int
! dset_t_int====the time of the dataset in character format
character :: str_temp3
character(len=10) :: dset_t_cha ! the time of the dataset in character format
character(len=256) :: shellcmd1,shellcmd2,shellcmd3,shellcmd4
character(len=50) :: cst_date,cst_sec,utc_sec
len_datafile=len(trim(filename_data))
read(filename_data(1:len_datafile),'(4i2.2,a1,i3.3)')yr_data,mn_data,dd_data,hr_data,str_temp3,postfix_data
if (yr_data/10.GT. 1 ) then
dset_t_cha(1:2)='19'
else
dset_t_cha(1:2)='20'
endif
! if((hr_data.le.7).and.(hr_data.ge.0))then
! hr_data=hr_data+16
! dd_data=dd_data-1
! else
! hr_data=hr_data-8
! endif
write(dset_t_cha(3:4),'(i2.2)')yr_data
write(dset_t_cha(5:6),'(i2.2)')mn_data
write(dset_t_cha(7:8),'(i2.2)')dd_data
write(dset_t_cha(9:10),'(i2.2)')hr_data
shellcmd1 = " date -d "//trim(dset_t_cha(1:8))//" +%s"
shellcmd1 = "cst_date=`"//trim(shellcmd1)//"`"
call system(shellcmd1)
shellcmd2 = "echo "//trim(cst_date)//" + "//dset_t_cha(9:10)// " *3600 | bc"
shellcmd2 = "cst_sec=` "//trim(shellcmd2)//" ` "
call system(shellcmd2)
shellcmd3 = "echo "//trim(cst_sec)// " -8*3600 | bc "
shellcmd3 = "utc_sec=` "//trim(shellcmd3)//" ` "
call system(shellcmd3)
shellcmd4 = "date --date="//"""1970-01-01 UTC "//trim(utc_sec)//" seconds"" +%Y%m%d%H "
shellcmd4 = "dset_t_int=` "//trim(shellcmd4)//" ` "
call system(shellcmd4)
! read(dset_t_cha(1:10),'(i10)')dset_t_int
end subroutine write_time_data
character(len=50):: filename
integer :: time_u
filename = '08092320.000'
call write_time_data(trim(filename),time_u)
open (12,file='./pp2.txt')
write(12,*)filename
write(12,*)time_u
close(12)
end
subroutine write_time_data(filename_data,dset_t_int)
implicit none
character(len=50):: filename_data
integer :: len_datafile,yr_data,mn_data,dd_data,hr_data,postfix_data,dset_t_int
! dset_t_int====the time of the dataset in character format
character :: str_temp3
character(len=10) :: dset_t_cha ! the time of the dataset in character format
character(len=256) :: shellcmd1,shellcmd2,shellcmd3,shellcmd4
character(len=50) :: cst_date,cst_sec,utc_sec
len_datafile=len(trim(filename_data))
read(filename_data(1:len_datafile),'(4i2.2,a1,i3.3)')yr_data,mn_data,dd_data,hr_data,str_temp3,postfix_data
if (yr_data/10.GT. 1 ) then
dset_t_cha(1:2)='19'
else
dset_t_cha(1:2)='20'
endif
! if((hr_data.le.7).and.(hr_data.ge.0))then
! hr_data=hr_data+16
! dd_data=dd_data-1
! else
! hr_data=hr_data-8
! endif
write(dset_t_cha(3:4),'(i2.2)')yr_data
write(dset_t_cha(5:6),'(i2.2)')mn_data
write(dset_t_cha(7:8),'(i2.2)')dd_data
write(dset_t_cha(9:10),'(i2.2)')hr_data
shellcmd1 = " date -d "//trim(dset_t_cha(1:8))//" +%s"
shellcmd1 = "cst_date=`"//trim(shellcmd1)//"`"
call system(shellcmd1)
shellcmd2 = "echo "//trim(cst_date)//" + "//dset_t_cha(9:10)// " *3600 | bc"
shellcmd2 = "cst_sec=` "//trim(shellcmd2)//" ` "
call system(shellcmd2)
shellcmd3 = "echo "//trim(cst_sec)// " -8*3600 | bc "
shellcmd3 = "utc_sec=` "//trim(shellcmd3)//" ` "
call system(shellcmd3)
shellcmd4 = "date --date="//"""1970-01-01 UTC "//trim(utc_sec)//" seconds"" +%Y%m%d%H "
shellcmd4 = "dset_t_int=` "//trim(shellcmd4)//" ` "
call system(shellcmd4)
! read(dset_t_cha(1:10),'(i10)')dset_t_int
end subroutine write_time_data