茜意 发表于 2016-6-17 17:18:34

批量循环读取predict文件

现在我要读取循环predict文件,用时间文件date作为读文件的路径一部分,并用时间文件控制要读哪个文件,我调用下面的程序能输出outputfile1(j),outputfile2(j)实现吗?代码如下:    谢谢老师!


subroutine timefileprepare(Began_time,finish_time,deltminute,outputfile1,outputfile2,sizeoffile,totaltime)
integer Began_time,finish_time,deltminute,totaltime
integer datelength,sizeoffile
integer minutestep,hourstep,tempint
character(90) date1char,date2char,timechar,temp_char!(sizeoffile)
character outputfile1(4300),outputfile2(4300)
integer dateofile(25000)
integer date1,date2,time
integer TIMELENGH
         !________截取时间段_____________________
          open(11,file="date.txt")
      i=0
          do while(.not.eof(11))
            i=i+1            
      read(11,*) dateofile(i)
          enddo
      !do i=1,4246
      !read(11,*) dateofile(i)
      ! enddo
      close(11)      

          TIMELENGH=4246
      minutestep=deltminute

          j=0
      do i=1,TIMELENGH
      if (((dateofile(i)).GE.(Began_time)).and.((dateofile(i)).LE.(finish_time))) then
            j=j+1
          ! k=j
            date1=int(dateofile(i)/10000)+2*10**7            !20150427适用于实际降水文件
          date2=int(dateofile(i)/10000)+2*10**7+2*10**9    !2020150427适用于预报文件
            time=dateofile(i)-int(dateofile(i)/10000)*10000!10000
            if(time.LE.1000) then
            write(temp_char,"(I4)") time
            timechar="0"//trim(temp_char)
            end if
                  write(timechar,"(I4)") time                  ! 0730
          write(date1char,"(I8)") date1                  !20150427
                  write(date2char,"(I10)") date2               !2020150427

                  outputfile1(j)=trim(date1char)//"_"//trim(timechar(2:5))    !20150427_0730
                  outputfile2(j)=trim(date2char)//"_"//trim(timechar(2:5))!2020150427_0730
            end if
      end do


li913 发表于 2016-6-18 10:18:14

本帖最后由 li913 于 2016-6-18 10:19 编辑

Fortran Coder(群号: 2338021)
里面有 批量处理文件 的教程。也可参考
http://fcode.cn/code_gen-97-1.html
http://fcode.cn/code_gen-12-1.html

fcode 发表于 2016-6-18 16:29:21

文件名在语法里,视为字符串,所以你可以用一切支持字符串的用法和函数来处理文件名,实现批量读写。

你可参考楼上给出的页码,也可以观看本站的视频教程应用篇第一期 http://v.fcode.cn
页: [1]
查看完整版本: 批量循环读取predict文件