爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11779|回复: 28

[源代码] 循环读n年常规报文或ncep资料的程序!

[复制链接]

新浪微博达人勋

发表于 2011-10-22 10:09:18 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 youwei 于 2011-10-22 10:12 编辑

!---------------将某一固定位置、层次的变量找出来,建立时间序列文件
!本程序是对日平均的数据进行提取
program main
implicit none
integer,parameter :: x=79,y=89,z=12
real,parameter :: T0=273.16
integer i,j,k
real:: h(x,y,z),u(x,y,z),v(x,y,z),vor(x,y,z),div(x,y,z),w(x,y,z)   
real:: serial_u(x,y,z),serial_v(x,y,z),serial_vor(x,y,z),serial_div(x,y,z),serial_w(x,y,z),serial_tk(x,y,z),serial_cape2(x,y),serial_ssi1(x,y),serial_cin2(x,y),serial_k1(x,y)  
real:: citase(x,y,z),q(x,y,z),tk(x,y,z),k1(x,y),cape2(x,y),cin2(x,y)      
real:: ssi1(x,y)
real p(z),t(z),td(z)
real:: te(120),ta(120)
real CAPE,PLFC,PE,CIN,LI,PC,TC,BCAPE,BIC,DCAPEX,TCON,CCL,H0,shr,SSI
integer l,m,n,o,riqi,degree
integer n_time
integer start_time,end_time,n_hour,n_rec
integer flag_x,flag_y,flag_z,name_var
real read_d
integer,parameter :: length=100
character(len=80)::a,b,c,d,e,g,path_input,path_output
character(len=80)::filename
character(len=8):: c_start,c_end
open(1,file='parameter_time.txt')
read (1,*) start_time  ! 开始时间
read (1,*) end_time    ! 结束时间
read (1,*) name_var    ! 变量名称
read (1,*) flag_x      ! x方向位置
read (1,*) flag_y      ! y方向位置
read (1,*) flag_z      ! z方向位置
close(1)
open(2,file='parameter_path.txt')
read(2,*) path_input         ! 日平均资料所放的路径
read(2,*) path_output        ! 日平均资料所放的路径
close(2)
open(3,file=trim(adjustl(path_output))//'serial_output.dat')  ! 提取出来的时间序列数据
open(11,file=trim(adjustl(path_output))//'serial_time.dat')  !写入的时间序列数据(上一行每个数据对应的时间)
n_time=start_time !n_time是中间加上头尾的所有时间
!-----------------------------------------------------------------------------------------------------------------
!-------------------------------------下面开始循环时间,然后读入变量并提取出来写入新的文件中----------------------
!-----------------------------------------------------------------------------------------------------------------

c1: do while (n_time<=end_time)
  write(b,"(i8)") n_time
            write(11,*)  trim(adjustl(b))
            open(4,file=trim(adjustl(path_input))//trim(adjustl(b))//'.dat',status='old',form='unformatted',access='direct',recl=1)
            if (name_var<=8) then  !提取单层变量
               n_rec=(name_var-1)*x*y+(flag_y-1)*x+flag_x
               read(4,rec=n_rec) read_d
        write(3,*) read_d
   else                   !提取多层变量
            n_rec=8*x*y+(name_var-9)*x*y*z+(flag_z-1)*x*y+(flag_y-1)*x+flag_x  
               read(4,rec=n_rec) read_d
        write(3,*) read_d
      endif  
   close(4)      
!--------------------------------------第一天数据读入和提取结束,进行时间循环
if(mod(n_time/100,100)==1.or.mod(n_time/100,100)==3.or.mod(n_time/100,100)==5.or.mod(n_time/100,100)==7.or.mod(n_time/100,100)==8.or.mod(n_time/100,100)==10) then
  if(mod(n_time,100)==31) then
      n_time=n_time+100-30
  else
      n_time=n_time+1
  endif
elseif(mod(n_time/100,100)==4.or.mod(n_time/100,100)==6.or.mod(n_time/100,100)==9.or.mod(n_time/100,100)==11) then
  if(mod(n_time,100)==30) then
      n_time=n_time+100-29
  else
      n_time=n_time+1
  endif
elseif(mod(n_time/100,100)==2) then
  if(mod(n_time/10000,4)==0) then   !如果年是4的倍数,则为润年,2月有29天
    if(mod(n_time,100)==29) then
        n_time=n_time+100-28
    else
        n_time=n_time+1
    endif
  else                             !否则2月为28天
    if(mod(n_time,100)==28) then
        n_time=n_time+100-27
    else
        n_time=n_time+1
    endif
  endif
elseif(mod(n_time/100,100)==12) then  !12月
  if(mod(n_time,100)==31) then
      n_time=n_time-1130+10000        !12月要加上1年
  else
      n_time=n_time+1
  endif
endif
enddo c1
close(3)
close(11)
end

评分

参与人数 6金钱 +65 贡献 +14 收起 理由
evereen + 10 + 2
zlyjs + 10 + 2 很实用
天目神眉 + 10 + 2 赞一个!
mofangbao + 10 + 3 给力,有空的话可以稍加程序功能的说明
尽头的尽头 + 10 + 2
topmad + 15 + 3 很给力! 感谢分享

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 10:22:54 | 显示全部楼层
这是好东西啊,估计好多朋友都会喜欢的
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 10:52:27 | 显示全部楼层
感谢分享~~~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

0
早起挑战累计收入
发表于 2011-10-22 11:13:01 | 显示全部楼层
好东西一起分享,楼主加油~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 12:21:18 | 显示全部楼层
好东西哇
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 12:24:01 | 显示全部楼层
哈哈,好东东啊 很给力
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 12:24:31 | 显示全部楼层
都是很实际的问题啊,论坛,加油!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 12:26:25 | 显示全部楼层
加油加油~~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-10-22 13:01:40 | 显示全部楼层
哈哈,好东西,正找着呢
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 成长值: 19710
发表于 2011-10-22 13:08:56 | 显示全部楼层
要是能给出读取的数据就好了,不然看得一头雾水。。。
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表