2014年1月19日日曜日

divide_5day.f90

昔作ったプログラム、その参。

! This program divides 5day-mean data
! so that the file size does not exceed the memory size on stokes
! created by Hakase Hayashida on Jan.24.2012

! Replace the ones with "!" symbols to the appropriate ones
program dividenetcdfdata
implicit none
INCLUDE 'netcdf.inc'
integer,parameter::jpi=304,jpj=334,jpk=46,jpt=72
integer::ncid,ncfile,dim1,dim2,dim3,dim4,divider,dimtx(3)!,dimtx(4)
integer::tempid,deftemp1,deftemp2,deftemp3,deftemp4
integer::vartemp
real,dimension(jpi,jpj,jpt)::temp
real,dimension(jpi,jpj,18)::temp1,temp2,temp3,temp4
!real,dimension(jpi,jpj,jpk,jpt)::temp
!real,dimension(jpi,jpj,jpk,18)::temp1,temp2,temp3,temp4

!Opening netcdf data file from grid_t,v,u,w
ncfile=nf_open('grid_t29.nc',nf_nowrite,ncid) !
ncfile=nf_inq_varid(ncid,'sohefldo',tempid) !
ncfile=nf_get_var_real(ncid,tempid,temp)
ncfile=nf_close(ncid)

!Dividing the data
divider=18
temp1=temp(:,:,1:divider)
temp2=temp(:,:,divider+1:divider*2)
temp3=temp(:,:,1+divider*2:divider*3)
temp4=temp(:,:,1+divider*3:divider*4)

!Creating netcdf data file for temperature
ncfile=nf_create('lab29f.nc',nf_share,ncid) !
ncfile=nf_def_dim(ncid,'x',jpi,dim1)
ncfile=nf_def_dim(ncid,'y',jpj,dim2)
!ncfile=nf_def_dim(ncid,'deptht',jpk,dim3)
ncfile=nf_def_dim(ncid,'time_counter',divider,dim4)
dimtx(1)=dim1
dimtx(2)=dim2
!dimtx(3)=dim3
dimtx(3)=dim4
!dimtx(4)=dim4
ncfile=nf_def_var(ncid,'sohefldo1',nf_real,3,dimtx,deftemp1) !
ncfile=nf_def_var(ncid,'sohefldo2',nf_real,3,dimtx,deftemp2) !
ncfile=nf_def_var(ncid,'sohefldo3',nf_real,3,dimtx,deftemp3) !
ncfile=nf_def_var(ncid,'sohefldo4',nf_real,3,dimtx,deftemp4) !
ncfile=nf_enddef(ncid)
ncfile=nf_put_var_real(ncid,deftemp1,temp1)
ncfile=nf_put_var_real(ncid,deftemp2,temp2)
ncfile=nf_put_var_real(ncid,deftemp3,temp3)
ncfile=nf_put_var_real(ncid,deftemp4,temp4)
ncfile=nf_close(ncid)

end program dividenetcdfdata


subroutine handle_err(errcode)
      implicit none
      include 'netcdf.inc'
      integer errcode

      print *, 'Error: ', nf_strerror(errcode)
      stop 2
      end

0 件のコメント:

コメントを投稿