登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
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
|