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
<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).
Well thanks to Vladimir suggestion here what i did to solve my problem!
program test_ec
implicit none
integer :: mi,di,iiii,fff
character(len=1024) :: filename
character(len=1024) :: format_string
logical exist
mi=1
CALL chdir('/media/Hello/ncfiles/GFS' )
!do di=1,10
do iiii=0,18,6
do fff=0,18,6
format_string = "(A17,i2.2,i2.2,A1,i4.4,A1,i3.3,A8)"
write (filename,format_string) "sub_gfsanl_4_2011",mi,di,"_",iiii,"_",fff,".grb2.nc"
inquire(file=trim(filename), exist=exist)
if (exist) then
write(*,*) 'file exists i can do do whatever i want with this file'
else
write(*,*) 'I did not find that file.'
end if
enddo
enddo
enddo
end program test_ec