列出循环索引指定的目录内容 [英] List the content of a directory specified by loop indices
问题描述
-MM代表从01至12月份
- DD表示从01到31的天数
-IIII代表初始化时间,第一个和第二个数字代表第三个数字,最后一个代表分钟数字
-FFFF代表预测小时数,第一位和第二位数字代表第三位,最后一位代表分钟数
在我的目录我有给定几个月的给定日期的几个文件。一天有4个数据,每六个小时一次IIII = 0000,0600,1200,1800。
我要做的是列出所有文件给定日子,这里是我写的f90代码:
program test_ec
隐式无
!==变量声明==
整数:: mi,di,dil,mil
字符* 3 :: temp
!==程序指令==
mil = 1
write(temp,'(i2.2)')mil
read(temp,'(i2.2)')mi
!将该月转换为两位数值mi = 01
!切换到存储数据的目录
CALL chdir('/ media / Hello / ncfiles / GFS')
do dil = 1,31
!loop (temp,'(i2.2)')dil
read(temp,'(i2.2)')di
!将日数转换为两位数字,将此值存储为di。 ex dil = 9 then di = 09
CALL execute_command_line('ls sub_gfsanl_4_2011 $ {mi} $ {di} *。nc> yes.txt')
!列出所有带有正确的月份和日期,并将其存储到yes.txt中
end do
结束程序test_ec
由于某些原因, execute_command_line
似乎不像$ for变量...
您不能在shell中使用
$ {mi} $ {di}
。它们是Fortran变量,而不是shell变量。您必须将这些数字放入Fortran中的字符串中。使用一些已建立的方法。在将整数转换为字符串以在运行时创建输出文件名/ a>及其副本(请参阅右侧的相关内容)。
I'm working with numerical weather forecast named as follow:
sub_gfsanl_4_2011MMDD-IIII-FFFF.grb2
-MM stands for month from 01 to 12
-DD stands for days from 01 to 31
-IIII stands for initialisation time, the first and second digits are for hours the third and last are for minutes
-FFFF stands for forecast hour , the first and second digits are for hours the third and last are for minutes
In my directory I have several files for a given days of a given months. A day has 4 data, one at every six hours IIII=0000 ,0600,1200,1800.
What I'm trying to do is to list all files of a given days, here the f90 code I wrote:
program test_ec
implicit none
!==variable declaration==
integer :: mi,di,dil,mil
character*3 :: temp
!==Program instructions==
mil=1
write(temp,'(i2.2)') mil
read(temp,'(i2.2)') mi
!convert the month into a two digit value mi=01
! change to directory where the data are stored
CALL chdir('/media/Hello/ncfiles/GFS' )
do dil=1,31
!loop over days
write(temp,'(i2.2)') dil
read(temp,'(i2.2)') di
! converting day number into a two digit number, store this value into di. ex dil=9 then di=09
CALL execute_command_line( 'ls sub_gfsanl_4_2011${mi}${di}*.nc > yes.txt' )
!list all files with the correct month and days and store it to yes.txt
end do
end program test_ec
For some reasons the execute_command_line
doesn't seem to like the $ for variable...
You cannot use ${mi}${di}
in shell. They are Fortran variables, not shell variables. You must put the numbers into the string inside Fortran. Use some of the established methods. They were treated here many times in Convert integers to strings to create output filenames at run time and its duplicates (see Related on the right).
这篇关于列出循环索引指定的目录内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!