00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 module seq_rest_mod
00025
00026 #define NEW_BUDGET
00027
00028
00029
00030 use shr_kind_mod, only: R8 => SHR_KIND_R8, IN => SHR_KIND_IN
00031 use shr_kind_mod, only: CL => SHR_KIND_CL, CS => SHR_KIND_CS
00032 use shr_sys_mod, only: shr_sys_abort, shr_sys_flush
00033 use shr_mpi_mod, only : shr_mpi_bcast
00034 use shr_cal_mod, only: shr_cal_date2ymd
00035 use mct_mod
00036 use ESMF_Mod
00037
00038 use seq_avdata_mod
00039 use seq_diag_mct
00040 use seq_comm_mct
00041 use seq_cdata_mod
00042 use seq_infodata_mod
00043 use seq_timemgr_mod
00044 use seq_io_mod
00045
00046 implicit none
00047
00048 private
00049
00050
00051
00052
00053
00054
00055
00056 public :: seq_rest_read
00057 public :: seq_rest_write
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 logical :: iamin_CPLID
00070 integer(IN) :: mpicom_GLOID
00071 integer(IN) :: mpicom_CPLID
00072
00073 integer(IN) :: nthreads_GLOID
00074 integer(IN) :: nthreads_CPLID
00075 logical :: drv_threading
00076
00077 logical :: atm_present
00078 logical :: lnd_present
00079 logical :: ice_present
00080 logical :: ocn_present
00081 logical :: rof_present
00082 logical :: glc_present
00083 logical :: sno_present
00084
00085 logical :: atm_prognostic
00086 logical :: lnd_prognostic
00087 logical :: ice_prognostic
00088 logical :: ocn_prognostic
00089 logical :: ocnrof_prognostic
00090 logical :: glc_prognostic
00091 logical :: sno_prognostic
00092
00093 integer(IN) :: info_debug = 0
00094
00095
00096 contains
00097
00098
00099 subroutine seq_rest_read(rest_file)
00100
00101 implicit none
00102
00103 character(*),intent(in) :: rest_file
00104
00105 integer(IN) :: n,n1,n2,n3
00106 real(r8),allocatable :: ds(:)
00107 real(r8),allocatable :: ns(:)
00108 character(CS) :: string
00109 integer(IN) :: ierr
00110
00111
00112
00113
00114
00115
00116
00117
00118 iamin_CPLID = seq_comm_iamin(CPLID)
00119 call seq_comm_setptrs(GLOID,mpicom=mpicom_GLOID,nthreads=nthreads_GLOID)
00120 call seq_comm_setptrs(CPLID,mpicom=mpicom_CPLID,nthreads=nthreads_CPLID)
00121 call seq_infodata_getData(infodata,drv_threading=drv_threading)
00122 call seq_infodata_getData(infodata, &
00123 atm_present=atm_present, &
00124 lnd_present=lnd_present, &
00125 rof_present=rof_present, &
00126 ice_present=ice_present, &
00127 ocn_present=ocn_present, &
00128 glc_present=glc_present, &
00129 sno_present=sno_present )
00130 call seq_infodata_getData(infodata, &
00131 atm_prognostic=atm_prognostic, &
00132 lnd_prognostic=lnd_prognostic, &
00133 ice_prognostic=ice_prognostic, &
00134 ocn_prognostic=ocn_prognostic, &
00135 ocnrof_prognostic=ocnrof_prognostic, &
00136 glc_prognostic=glc_prognostic, &
00137 sno_prognostic=sno_prognostic )
00138
00139 if (iamin_CPLID) then
00140 if (drv_threading) call seq_comm_setnthreads(nthreads_CPLID)
00141 if (atm_present) then
00142 call seq_io_read(rest_file,cdata_ax,fractions_ax,'fractions_ax')
00143 call seq_io_read(rest_file,cdata_ax,a2x_ax,'a2x_ax')
00144 endif
00145 if (lnd_present) then
00146 call seq_io_read(rest_file,cdata_lx,fractions_lx,'fractions_lx')
00147 call seq_io_read(rest_file,cdata_lx,l2x_lx,'l2x_lx')
00148 endif
00149 if (ocn_present) then
00150 call seq_io_read(rest_file,cdata_ox,fractions_ox,'fractions_ox')
00151 call seq_io_read(rest_file,cdata_ox,o2x_ox,'o2x_ox')
00152 call seq_io_read(rest_file,cdata_ox,x2oacc_ox%data,'x2oacc_ox')
00153
00154 call seq_io_read(rest_file,cdata_ox,x2oacc_ox_cnt,'x2oacc_ox_cnt')
00155 call seq_io_read(rest_file,cdata_ox,xao_ox,'xao_ox')
00156 call seq_io_read(rest_file,cdata_ax,xao_ax,'xao_ax')
00157 endif
00158 if (ice_present) then
00159 call seq_io_read(rest_file,cdata_ix,fractions_ix,'fractions_ix')
00160 call seq_io_read(rest_file,cdata_ix,i2x_ix,'i2x_ix')
00161 endif
00162 if (rof_present .and. ocnrof_prognostic) then
00163 call seq_io_read(rest_file,cdata_rx,r2xacc_rx%data,'r2xacc_rx')
00164 call seq_io_read(rest_file,cdata_rx,r2xacc_rx_cnt,'r2xacc_rx_cnt')
00165 endif
00166 if (glc_present) then
00167 call seq_io_read(rest_file,cdata_gx,fractions_gx,'fractions_gx')
00168 endif
00169 if (sno_present) then
00170 call seq_io_read(rest_file,cdata_sx,x2s_sx,'x2s_sx')
00171 endif
00172
00173 #if (defined NEW_BUDGET)
00174 n = size(budg_dataG)
00175 allocate(ds(n),ns(n))
00176 call seq_io_read(rest_file,cdata_ax,ds,'budg_dataG')
00177 call seq_io_read(rest_file,cdata_ax,ns,'budg_ns')
00178
00179 n = 0
00180 do n1 = 1,size(budg_dataG,dim=1)
00181 do n2 = 1,size(budg_dataG,dim=2)
00182 do n3 = 1,size(budg_dataG,dim=3)
00183 n = n + 1
00184 budg_dataG(n1,n2,n3) = ds(n)
00185 budg_ns (n1,n2,n3) = ns(n)
00186 enddo
00187 enddo
00188 enddo
00189
00190
00191 deallocate(ds,ns)
00192 #endif
00193
00194 if (drv_threading) call seq_comm_setnthreads(nthreads_GLOID)
00195
00196 endif
00197
00198 end subroutine seq_rest_read
00199
00200
00201
00202 subroutine seq_rest_write(EClock_d,seq_SyncClock)
00203
00204 implicit none
00205
00206 type(ESMF_Clock) ,intent(in) :: EClock_d
00207 type(seq_timemgr_type),intent(inout) :: seq_SyncClock
00208
00209 integer(IN) :: n,n1,n2,n3,fk
00210 integer(IN) :: curr_ymd
00211 integer(IN) :: curr_tod
00212 integer(IN) :: yy,mm,dd
00213 character(CL) :: case_name
00214 logical :: whead,wdata
00215 logical :: cdf64
00216 character(CL) :: rest_file
00217 integer(IN) :: ierr
00218
00219 real(r8),allocatable :: ds(:)
00220 real(r8),allocatable :: ns(:)
00221
00222
00223
00224
00225
00226
00227
00228
00229 iamin_CPLID = seq_comm_iamin(CPLID)
00230 call seq_comm_setptrs(GLOID,mpicom=mpicom_GLOID,nthreads=nthreads_GLOID)
00231 call seq_comm_setptrs(CPLID,mpicom=mpicom_CPLID,nthreads=nthreads_CPLID)
00232 call seq_infodata_getData(infodata,drv_threading=drv_threading)
00233 call seq_infodata_getData(infodata, &
00234 atm_present=atm_present, &
00235 lnd_present=lnd_present, &
00236 rof_present=rof_present, &
00237 ice_present=ice_present, &
00238 ocn_present=ocn_present, &
00239 glc_present=glc_present, &
00240 sno_present=sno_present )
00241 call seq_infodata_getData(infodata, &
00242 atm_prognostic=atm_prognostic, &
00243 lnd_prognostic=lnd_prognostic, &
00244 ice_prognostic=ice_prognostic, &
00245 ocn_prognostic=ocn_prognostic, &
00246 ocnrof_prognostic=ocnrof_prognostic, &
00247 glc_prognostic=glc_prognostic, &
00248 sno_prognostic=sno_prognostic )
00249 call seq_infodata_getData(infodata, cpl_cdf64=cdf64 )
00250
00251
00252
00253 call seq_infodata_GetData( infodata, case_name=case_name)
00254 call seq_timemgr_EClockGetData( EClock_d, curr_ymd=curr_ymd, curr_tod=curr_tod)
00255 call shr_cal_date2ymd(curr_ymd,yy,mm,dd)
00256 write(rest_file,"(2a,i4.4,a,i2.2,a,i2.2,a,i5.5,a)") &
00257 trim(case_name), '.cpl.r.', yy,'-',mm,'-',dd,'-',curr_tod,'.nc'
00258
00259 call seq_infodata_Restart ('write',infodata ,rest_file,mpicom_cplid)
00260 call mpi_barrier(mpicom_CPLID,ierr)
00261 call seq_timemgr_clockRestart('write',seq_SyncClock,rest_file,mpicom_cplid)
00262 call mpi_barrier(mpicom_CPLID,ierr)
00263
00264
00265
00266 if (iamin_CPLID) then
00267
00268 if (drv_threading) call seq_comm_setnthreads(nthreads_CPLID)
00269
00270 #if (defined NEW_BUDGET)
00271
00272 n = size(budg_dataG)
00273 allocate(ds(n),ns(n))
00274 call shr_mpi_bcast(budg_dataG,mpicom_CPLID)
00275
00276 n = 0
00277 do n1 = 1,size(budg_dataG,dim=1)
00278 do n2 = 1,size(budg_dataG,dim=2)
00279 do n3 = 1,size(budg_dataG,dim=3)
00280 n = n + 1
00281 ds(n) = budg_dataG(n1,n2,n3)
00282 ns(n) = budg_ns(n1,n2,n3)
00283 enddo
00284 enddo
00285 enddo
00286 #endif
00287
00288 call seq_io_wopen(rest_file,cdata_ax,clobber=.false.,cdf64=cdf64)
00289
00290
00291 do fk = 1,2
00292 if (fk == 1) then
00293 whead = .true.
00294 wdata = .false.
00295 call seq_io_redef(rest_file)
00296 elseif (fk == 2) then
00297 whead = .false.
00298 wdata = .true.
00299 call seq_io_enddef(rest_file)
00300 else
00301 call shr_sys_abort('driver_write_rstart fk illegal')
00302 end if
00303 #if (defined NEW_BUDGET)
00304 call seq_io_write(rest_file,cdata_ax,ds,'budg_dataG',whead=whead,wdata=wdata)
00305 call seq_io_write(rest_file,cdata_ax,ns,'budg_ns',whead=whead,wdata=wdata)
00306 #endif
00307
00308 if (atm_present) then
00309 call seq_io_write(rest_file,cdata_ax,fractions_ax,'fractions_ax',whead=whead,wdata=wdata)
00310 call seq_io_write(rest_file,cdata_ax,a2x_ax,'a2x_ax',whead=whead,wdata=wdata)
00311 endif
00312 if (lnd_present) then
00313 call seq_io_write(rest_file,cdata_lx,fractions_lx,'fractions_lx',whead=whead,wdata=wdata)
00314 call seq_io_write(rest_file,cdata_lx,l2x_lx,'l2x_lx',whead=whead,wdata=wdata)
00315 endif
00316 if (ocn_present) then
00317 call seq_io_write(rest_file,cdata_ox,fractions_ox,'fractions_ox',whead=whead,wdata=wdata)
00318 call seq_io_write(rest_file,cdata_ox,o2x_ox,'o2x_ox',whead=whead,wdata=wdata)
00319 call seq_io_write(rest_file,cdata_ox,x2oacc_ox%data,'x2oacc_ox',whead=whead,wdata=wdata)
00320
00321 call seq_io_write(rest_file,cdata_ox,x2oacc_ox_cnt,'x2oacc_ox_cnt',whead=whead,wdata=wdata)
00322 call seq_io_write(rest_file,cdata_ox,xao_ox,'xao_ox',whead=whead,wdata=wdata)
00323 call seq_io_write(rest_file,cdata_ax,xao_ax,'xao_ax',whead=whead,wdata=wdata)
00324 endif
00325 if (ice_present) then
00326 call seq_io_write(rest_file,cdata_ix,fractions_ix,'fractions_ix',whead=whead,wdata=wdata)
00327 call seq_io_write(rest_file,cdata_ix,i2x_ix,'i2x_ix',whead=whead,wdata=wdata)
00328 endif
00329 if (rof_present .and. ocnrof_prognostic) then
00330 call seq_io_write(rest_file,cdata_rx,r2xacc_rx%data,'r2xacc_rx',whead=whead,wdata=wdata)
00331 call seq_io_write(rest_file,cdata_rx,r2xacc_rx_cnt,'r2xacc_rx_cnt',whead=whead,wdata=wdata)
00332 endif
00333 if (glc_present) then
00334 call seq_io_write(rest_file,cdata_gx,fractions_gx,'fractions_gx',whead=whead,wdata=wdata)
00335 endif
00336 if (sno_present) then
00337 call seq_io_write(rest_file,cdata_sx,x2s_sx,'x2s_sx',whead=whead,wdata=wdata)
00338 endif
00339
00340 enddo
00341
00342 call seq_io_close(rest_file,cdata_ax)
00343 #if (defined NEW_BUDGET)
00344 deallocate(ds,ns)
00345 #endif
00346
00347 if (drv_threading) call seq_comm_setnthreads(nthreads_GLOID)
00348 endif
00349
00350 end subroutine seq_rest_write
00351
00352
00353
00354 end module seq_rest_mod