List the content of a directory specified by loop indices

前端 未结 2 858
耶瑟儿~
耶瑟儿~ 2021-01-26 11:43

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

<
2条回答
  •  情歌与酒
    2021-01-26 12:30

    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
    

提交回复
热议问题