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_hist_mod
00025
00026
00027
00028 use shr_kind_mod, only: R8 => SHR_KIND_R8, IN => SHR_KIND_IN
00029 use shr_kind_mod, only: CL => SHR_KIND_CL, CS => SHR_KIND_CS
00030 use shr_sys_mod, only: shr_sys_abort, shr_sys_flush
00031 use shr_cal_mod, only: shr_cal_date2ymd
00032 use mct_mod
00033 use ESMF_Mod
00034
00035 use seq_avdata_mod
00036 use seq_comm_mct
00037 use seq_cdata_mod
00038 use seq_infodata_mod
00039 use seq_timemgr_mod
00040 use seq_io_mod
00041
00042 implicit none
00043
00044 private
00045
00046
00047
00048
00049
00050
00051
00052 public :: seq_hist_write
00053 public :: seq_hist_writeavg
00054 public :: seq_hist_writeaux
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 logical :: iamin_CPLID
00067 integer(IN) :: mpicom_GLOID
00068 integer(IN) :: mpicom_CPLID
00069
00070 integer(IN) :: nthreads_GLOID
00071 integer(IN) :: nthreads_CPLID
00072 logical :: drv_threading
00073
00074 logical :: atm_present
00075 logical :: lnd_present
00076 logical :: ice_present
00077 logical :: ocn_present
00078 logical :: rof_present
00079 logical :: glc_present
00080 logical :: sno_present
00081
00082 logical :: atm_prognostic
00083 logical :: lnd_prognostic
00084 logical :: ice_prognostic
00085 logical :: ocn_prognostic
00086 logical :: ocnrof_prognostic
00087 logical :: glc_prognostic
00088 logical :: sno_prognostic
00089
00090 logical :: cdf64
00091
00092
00093 integer(IN) :: atm_nx, atm_ny
00094 integer(IN) :: lnd_nx, lnd_ny
00095 integer(IN) :: ice_nx, ice_ny
00096 integer(IN) :: ocn_nx, ocn_ny
00097 integer(IN) :: rof_nx, rof_ny
00098 integer(IN) :: glc_nx, glc_ny
00099 integer(IN) :: sno_nx, sno_ny
00100
00101 integer(IN) :: info_debug = 0
00102
00103
00104 contains
00105
00106
00107 subroutine seq_hist_write(EClock_d)
00108
00109 implicit none
00110
00111 type (ESMF_Clock),intent(in) :: EClock_d
00112
00113 integer(IN) :: curr_ymd
00114 integer(IN) :: curr_tod
00115 integer(IN) :: start_ymd
00116 integer(IN) :: start_tod
00117 real(r8) :: curr_time
00118 integer(IN) :: yy,mm,dd
00119 integer(IN) :: fk
00120 character(CL) :: time_units
00121 character(CL) :: calendar
00122 character(CL) :: case_name
00123 character(CL) :: hist_file
00124 integer(IN) :: lsize
00125 logical :: whead,wdata
00126
00127
00128
00129
00130
00131
00132
00133
00134 iamin_CPLID = seq_comm_iamin(CPLID)
00135 call seq_comm_setptrs(GLOID,mpicom=mpicom_GLOID,nthreads=nthreads_GLOID)
00136 call seq_comm_setptrs(CPLID,mpicom=mpicom_CPLID,nthreads=nthreads_CPLID)
00137 call seq_infodata_getData(infodata,drv_threading=drv_threading)
00138 call seq_infodata_getData(infodata, &
00139 atm_present=atm_present, &
00140 lnd_present=lnd_present, &
00141 rof_present=rof_present, &
00142 ice_present=ice_present, &
00143 ocn_present=ocn_present, &
00144 glc_present=glc_present, &
00145 sno_present=sno_present )
00146 call seq_infodata_getData(infodata, &
00147 atm_prognostic=atm_prognostic, &
00148 lnd_prognostic=lnd_prognostic, &
00149 ice_prognostic=ice_prognostic, &
00150 ocn_prognostic=ocn_prognostic, &
00151 ocnrof_prognostic=ocnrof_prognostic, &
00152 glc_prognostic=glc_prognostic, &
00153 sno_prognostic=sno_prognostic )
00154 call seq_infodata_getData(infodata, &
00155 atm_nx=atm_nx, atm_ny=atm_ny, &
00156 lnd_nx=lnd_nx, lnd_ny=lnd_ny, &
00157 rof_nx=rof_nx, rof_ny=rof_ny, &
00158 ice_nx=ice_nx, ice_ny=ice_ny, &
00159 glc_nx=glc_nx, glc_ny=glc_ny, &
00160 sno_nx=sno_nx, sno_ny=sno_ny, &
00161 ocn_nx=ocn_nx, ocn_ny=ocn_ny )
00162 call seq_infodata_getData(infodata, cpl_cdf64=cdf64 )
00163
00164
00165
00166
00167 call seq_infodata_GetData( infodata, case_name=case_name)
00168 call seq_timemgr_EClockGetData( EClock_d, curr_ymd=curr_ymd, curr_tod=curr_tod, &
00169 start_ymd=start_ymd, start_tod=start_tod, curr_time=curr_time, &
00170 calendar=calendar)
00171 call shr_cal_date2ymd(curr_ymd,yy,mm,dd)
00172 write(hist_file,"(2a,i4.4,a,i2.2,a,i2.2,a,i5.5,a)") &
00173 trim(case_name), '.cpl.hi.', yy,'-',mm,'-',dd,'-',curr_tod,'.nc'
00174
00175 time_units = 'days since ' &
00176 // seq_io_date2yyyymmdd(start_ymd) // ' ' // seq_io_sec2hms(start_tod)
00177
00178 if (iamin_CPLID) then
00179
00180 if (drv_threading) call seq_comm_setnthreads(nthreads_CPLID)
00181 call seq_io_wopen(hist_file,cdata_ax,clobber=.true.,cdf64=cdf64)
00182
00183
00184
00185 do fk = 1,2
00186 if (fk == 1) then
00187 whead = .true.
00188 wdata = .false.
00189 elseif (fk == 2) then
00190 whead = .false.
00191 wdata = .true.
00192 call seq_io_enddef(hist_file)
00193 else
00194 call shr_sys_abort('seq_hist_write fk illegal')
00195 end if
00196
00197 call seq_io_write(hist_file,&
00198 time_units=time_units,time_cal=calendar,time_val=curr_time,&
00199 whead=whead,wdata=wdata)
00200 if (atm_present) then
00201 call seq_io_write(hist_file,cdata_ax,dom_ax%data,'dom_ax', &
00202 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='doma')
00203 call seq_io_write(hist_file,cdata_ax,fractions_ax,'fractions_ax', &
00204 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='fraca')
00205 call seq_io_write(hist_file,cdata_ax,x2a_ax,'x2a_ax', &
00206 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='x2a')
00207 call seq_io_write(hist_file,cdata_ax,a2x_ax,'a2x_ax', &
00208 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='a2x')
00209
00210
00211
00212
00213
00214
00215 endif
00216 if (lnd_present) then
00217 call seq_io_write(hist_file,cdata_lx,dom_lx%data,'dom_lx', &
00218 nx=lnd_nx,ny=lnd_ny,whead=whead,wdata=wdata,pre='doml')
00219 call seq_io_write(hist_file,cdata_lx,fractions_lx,'fractions_lx', &
00220 nx=lnd_nx,ny=lnd_ny,whead=whead,wdata=wdata,pre='fracl')
00221 call seq_io_write(hist_file,cdata_lx,l2x_lx,'l2x_lx', &
00222 nx=lnd_nx,ny=lnd_ny,whead=whead,wdata=wdata,pre='l2x')
00223 call seq_io_write(hist_file,cdata_lx,x2l_lx,'x2l_lx', &
00224 nx=lnd_nx,ny=lnd_ny,whead=whead,wdata=wdata,pre='x2l')
00225 endif
00226
00227 if (rof_present) then
00228 call seq_io_write(hist_file,cdata_rx,dom_rx%data,'dom_rx', &
00229 nx=rof_nx,ny=rof_ny,whead=whead,wdata=wdata,pre='domr')
00230 call seq_io_write(hist_file,cdata_rx,r2x_rx,'r2x_rx', &
00231 nx=rof_nx,ny=rof_ny,whead=whead,wdata=wdata,pre='r2x')
00232 endif
00233 if (rof_present .and. ocnrof_prognostic) then
00234 call seq_io_write(hist_file,cdata_rx,r2xacc_rx%data,'r2xacc_rx', &
00235 nx=rof_nx,ny=rof_ny,whead=whead,wdata=wdata,pre='r2xacc')
00236 call seq_io_write(hist_file,cdata_ox,r2x_ox,'r2x_ox', &
00237 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='r2xo')
00238 endif
00239 if (ocn_present) then
00240 call seq_io_write(hist_file,cdata_ox,dom_ox%data,'dom_ox', &
00241 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='domo')
00242 call seq_io_write(hist_file,cdata_ox,fractions_ox,'fractions_ox', &
00243 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='fraco')
00244 call seq_io_write(hist_file,cdata_ox,o2x_ox,'o2x_ox', &
00245 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='o2x')
00246 call seq_io_write(hist_file,cdata_ax,o2x_ax,'o2x_ax', &
00247 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='o2xa')
00248
00249
00250 call seq_io_write(hist_file,cdata_ox,x2oacc_ox%data,'x2oacc_ox', &
00251 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='x2oacc')
00252
00253
00254 call seq_io_write(hist_file,cdata_ox,x2oacc_ox_cnt,'x2oacc_ox_cnt', &
00255 whead=whead,wdata=wdata)
00256 call seq_io_write(hist_file,cdata_ox,xao_ox,'xao_ox', &
00257 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='xaoo')
00258 call seq_io_write(hist_file,cdata_ax,xao_ax,'xao_ax', &
00259 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='xaoa')
00260 endif
00261 if (ice_present) then
00262 call seq_io_write(hist_file,cdata_ix,dom_ix%data,'dom_ix', &
00263 nx=ice_nx,ny=ice_ny,whead=whead,wdata=wdata,pre='domi')
00264 call seq_io_write(hist_file,cdata_ix,fractions_ix,'fractions_ix', &
00265 nx=ice_nx,ny=ice_ny,whead=whead,wdata=wdata,pre='fraci')
00266 call seq_io_write(hist_file,cdata_ix,i2x_ix,'i2x_ix', &
00267 nx=ice_nx,ny=ice_ny,whead=whead,wdata=wdata,pre='i2x')
00268 call seq_io_write(hist_file,cdata_ix,x2i_ix,'x2i_ix', &
00269 nx=ice_nx,ny=ice_ny,whead=whead,wdata=wdata,pre='x2i')
00270 endif
00271 if (glc_present) then
00272 call seq_io_write(hist_file,cdata_gx,dom_gx%data,'dom_gx', &
00273 nx=glc_nx,ny=glc_ny,whead=whead,wdata=wdata,pre='domg')
00274 call seq_io_write(hist_file,cdata_gx,fractions_gx,'fractions_gx', &
00275 nx=glc_nx,ny=glc_ny,whead=whead,wdata=wdata,pre='fracg')
00276 call seq_io_write(hist_file,cdata_gx,g2x_gx,'g2x_gx', &
00277 nx=glc_nx,ny=glc_ny,whead=whead,wdata=wdata,pre='g2x')
00278 call seq_io_write(hist_file,cdata_gx,x2g_gx,'x2g_gx', &
00279 nx=glc_nx,ny=glc_ny,whead=whead,wdata=wdata,pre='x2g')
00280 endif
00281 if (sno_present) then
00282 call seq_io_write(hist_file,cdata_sx,dom_sx%data,'dom_sx', &
00283 nx=sno_nx,ny=sno_ny,whead=whead,wdata=wdata,pre='doms')
00284 call seq_io_write(hist_file,cdata_sx,s2x_sx,'s2x_sx', &
00285 nx=sno_nx,ny=sno_ny,whead=whead,wdata=wdata,pre='s2x')
00286 call seq_io_write(hist_file,cdata_sx,x2s_sx,'x2s_sx', &
00287 nx=sno_nx,ny=sno_ny,whead=whead,wdata=wdata,pre='x2s')
00288 endif
00289 enddo
00290
00291 call seq_io_close(hist_file,cdata_ax)
00292 if (drv_threading) call seq_comm_setnthreads(nthreads_GLOID)
00293 endif
00294
00295 end subroutine seq_hist_write
00296
00297
00298
00299 subroutine seq_hist_writeavg(EClock_d,write_now)
00300
00301 implicit none
00302
00303 type (ESMF_Clock),intent(in) :: EClock_d
00304 logical ,intent(in) :: write_now
00305
00306 integer(IN) :: curr_ymd
00307 integer(IN) :: curr_tod
00308 integer(IN) :: prev_ymd
00309 integer(IN) :: prev_tod
00310 integer(IN) :: start_ymd
00311 integer(IN) :: start_tod
00312 real(r8) :: curr_time
00313 real(r8) :: prev_time
00314 integer(IN) :: yy,mm,dd
00315 integer(IN) :: fk
00316 character(CL) :: time_units
00317 character(CL) :: calendar
00318 integer(IN) :: lsize
00319 character(CL) :: case_name
00320 character(CL) :: hist_file
00321 logical :: whead,wdata
00322
00323 type(mct_aVect),save :: a2x_ax_avg
00324 type(mct_aVect),save :: x2a_ax_avg
00325 type(mct_aVect),save :: l2x_lx_avg
00326 type(mct_aVect),save :: x2l_lx_avg
00327 type(mct_aVect),save :: r2x_rx_avg
00328 type(mct_aVect),save :: o2x_ox_avg
00329 type(mct_aVect),save :: x2o_ox_avg
00330 type(mct_aVect),save :: i2x_ix_avg
00331 type(mct_aVect),save :: x2i_ix_avg
00332 type(mct_aVect),save :: g2x_gx_avg
00333 type(mct_aVect),save :: x2g_gx_avg
00334 type(mct_aVect),save :: s2x_sx_avg
00335 type(mct_aVect),save :: x2s_sx_avg
00336
00337 integer(IN) ,save :: cnt
00338 real(r8) ,save :: tbnds(2)
00339
00340 logical ,save :: first_call = .true.
00341
00342
00343
00344
00345
00346
00347
00348
00349 iamin_CPLID = seq_comm_iamin(CPLID)
00350 call seq_comm_setptrs(GLOID,mpicom=mpicom_GLOID,nthreads=nthreads_GLOID)
00351 call seq_comm_setptrs(CPLID,mpicom=mpicom_CPLID,nthreads=nthreads_CPLID)
00352 call seq_infodata_getData(infodata,drv_threading=drv_threading)
00353 call seq_infodata_getData(infodata, &
00354 atm_present=atm_present, &
00355 lnd_present=lnd_present, &
00356 rof_present=rof_present, &
00357 ice_present=ice_present, &
00358 ocn_present=ocn_present, &
00359 glc_present=glc_present, &
00360 sno_present=sno_present )
00361 call seq_infodata_getData(infodata, &
00362 atm_prognostic=atm_prognostic, &
00363 lnd_prognostic=lnd_prognostic, &
00364 ice_prognostic=ice_prognostic, &
00365 ocn_prognostic=ocn_prognostic, &
00366 ocnrof_prognostic=ocnrof_prognostic, &
00367 glc_prognostic=glc_prognostic, &
00368 sno_prognostic=sno_prognostic )
00369 call seq_infodata_getData(infodata, &
00370 atm_nx=atm_nx, atm_ny=atm_ny, &
00371 lnd_nx=lnd_nx, lnd_ny=lnd_ny, &
00372 rof_nx=rof_nx, rof_ny=rof_ny, &
00373 ice_nx=ice_nx, ice_ny=ice_ny, &
00374 glc_nx=glc_nx, glc_ny=glc_ny, &
00375 sno_nx=sno_nx, sno_ny=sno_ny, &
00376 ocn_nx=ocn_nx, ocn_ny=ocn_ny )
00377 call seq_infodata_getData(infodata, cpl_cdf64=cdf64 )
00378
00379
00380
00381 call seq_timemgr_EClockGetData( EClock_d, curr_ymd=curr_ymd, curr_tod=curr_tod, &
00382 start_ymd=start_ymd, start_tod=start_tod, curr_time=curr_time, prev_time=prev_time, &
00383 calendar=calendar)
00384
00385 if (first_call) then
00386 if (atm_present) then
00387 lsize = mct_aVect_lsize(a2x_ax)
00388 call mct_aVect_init(a2x_ax_avg,a2x_ax,lsize)
00389 call mct_aVect_zero(a2x_ax_avg)
00390 lsize = mct_aVect_lsize(x2a_ax)
00391 call mct_aVect_init(x2a_ax_avg,x2a_ax,lsize)
00392 call mct_aVect_zero(x2a_ax_avg)
00393 endif
00394 if (lnd_present) then
00395 lsize = mct_aVect_lsize(l2x_lx)
00396 call mct_aVect_init(l2x_lx_avg,l2x_lx,lsize)
00397 call mct_aVect_zero(l2x_lx_avg)
00398 lsize = mct_aVect_lsize(x2l_lx)
00399 call mct_aVect_init(x2l_lx_avg,x2l_lx,lsize)
00400 call mct_aVect_zero(x2l_lx_avg)
00401 endif
00402 if (rof_present .and. ocnrof_prognostic) then
00403 lsize = mct_aVect_lsize(r2x_rx)
00404 call mct_aVect_init(r2x_rx_avg,r2x_rx,lsize)
00405 call mct_aVect_zero(r2x_rx_avg)
00406 endif
00407 if (ocn_present) then
00408 lsize = mct_aVect_lsize(o2x_ox)
00409 call mct_aVect_init(o2x_ox_avg,o2x_ox,lsize)
00410 call mct_aVect_zero(o2x_ox_avg)
00411 lsize = mct_aVect_lsize(x2o_ox)
00412 call mct_aVect_init(x2o_ox_avg,x2o_ox,lsize)
00413 call mct_aVect_zero(x2o_ox_avg)
00414 endif
00415 if (ice_present) then
00416 lsize = mct_aVect_lsize(i2x_ix)
00417 call mct_aVect_init(i2x_ix_avg,i2x_ix,lsize)
00418 call mct_aVect_zero(i2x_ix_avg)
00419 lsize = mct_aVect_lsize(x2i_ix)
00420 call mct_aVect_init(x2i_ix_avg,x2i_ix,lsize)
00421 call mct_aVect_zero(x2i_ix_avg)
00422 endif
00423 if (glc_present) then
00424 lsize = mct_aVect_lsize(g2x_gx)
00425 call mct_aVect_init(g2x_gx_avg,g2x_gx,lsize)
00426 call mct_aVect_zero(g2x_gx_avg)
00427 lsize = mct_aVect_lsize(x2g_gx)
00428 call mct_aVect_init(x2g_gx_avg,x2g_gx,lsize)
00429 call mct_aVect_zero(x2g_gx_avg)
00430 endif
00431 if (sno_present) then
00432 lsize = mct_aVect_lsize(s2x_sx)
00433 call mct_aVect_init(s2x_sx_avg,s2x_sx,lsize)
00434 call mct_aVect_zero(s2x_sx_avg)
00435 lsize = mct_aVect_lsize(x2s_sx)
00436 call mct_aVect_init(x2s_sx_avg,x2s_sx,lsize)
00437 call mct_aVect_zero(x2s_sx_avg)
00438 endif
00439 cnt = 0
00440 tbnds(1) = prev_time
00441 first_call = .false.
00442 endif
00443
00444 if (.not.write_now) then
00445 cnt = cnt + 1
00446 if (atm_present) then
00447 a2x_ax_avg%rAttr = a2x_ax_avg%rAttr + a2x_ax%rAttr
00448 x2a_ax_avg%rAttr = x2a_ax_avg%rAttr + x2a_ax%rAttr
00449 endif
00450 if (lnd_present) then
00451 l2x_lx_avg%rAttr = l2x_lx_avg%rAttr + l2x_lx%rAttr
00452 x2l_lx_avg%rAttr = x2l_lx_avg%rAttr + x2l_lx%rAttr
00453 endif
00454 if (rof_present .and. ocnrof_prognostic) then
00455 r2x_rx_avg%rAttr = r2x_rx_avg%rAttr + r2x_rx%rAttr
00456 endif
00457 if (ocn_present) then
00458 o2x_ox_avg%rAttr = o2x_ox_avg%rAttr + o2x_ox%rAttr
00459 x2o_ox_avg%rAttr = x2o_ox_avg%rAttr + x2o_ox%rAttr
00460 endif
00461 if (ice_present) then
00462 i2x_ix_avg%rAttr = i2x_ix_avg%rAttr + i2x_ix%rAttr
00463 x2i_ix_avg%rAttr = x2i_ix_avg%rAttr + x2i_ix%rAttr
00464 endif
00465 if (glc_present) then
00466 g2x_gx_avg%rAttr = g2x_gx_avg%rAttr + g2x_gx%rAttr
00467 x2g_gx_avg%rAttr = x2g_gx_avg%rAttr + x2g_gx%rAttr
00468 endif
00469 if (sno_present) then
00470 s2x_sx_avg%rAttr = s2x_sx_avg%rAttr + s2x_sx%rAttr
00471 x2s_sx_avg%rAttr = x2s_sx_avg%rAttr + x2s_sx%rAttr
00472 endif
00473
00474 else
00475 cnt = cnt + 1
00476 tbnds(2) = curr_time
00477 if (atm_present) then
00478 a2x_ax_avg%rAttr = (a2x_ax_avg%rAttr + a2x_ax%rAttr) / (cnt * 1.0_r8)
00479 x2a_ax_avg%rAttr = (x2a_ax_avg%rAttr + x2a_ax%rAttr) / (cnt * 1.0_r8)
00480 endif
00481 if (lnd_present) then
00482 l2x_lx_avg%rAttr = (l2x_lx_avg%rAttr + l2x_lx%rAttr) / (cnt * 1.0_r8)
00483 x2l_lx_avg%rAttr = (x2l_lx_avg%rAttr + x2l_lx%rAttr) / (cnt * 1.0_r8)
00484 endif
00485 if (rof_present .and. ocnrof_prognostic) then
00486 r2x_rx_avg%rAttr = (r2x_rx_avg%rAttr + r2x_rx%rAttr) / (cnt * 1.0_r8)
00487 endif
00488 if (ocn_present) then
00489 o2x_ox_avg%rAttr = (o2x_ox_avg%rAttr + o2x_ox%rAttr) / (cnt * 1.0_r8)
00490 x2o_ox_avg%rAttr = (x2o_ox_avg%rAttr + x2o_ox%rAttr) / (cnt * 1.0_r8)
00491 endif
00492 if (ice_present) then
00493 i2x_ix_avg%rAttr = (i2x_ix_avg%rAttr + i2x_ix%rAttr) / (cnt * 1.0_r8)
00494 x2i_ix_avg%rAttr = (x2i_ix_avg%rAttr + x2i_ix%rAttr) / (cnt * 1.0_r8)
00495 endif
00496 if (glc_present) then
00497 g2x_gx_avg%rAttr = (g2x_gx_avg%rAttr + g2x_gx%rAttr) / (cnt * 1.0_r8)
00498 x2g_gx_avg%rAttr = (x2g_gx_avg%rAttr + x2g_gx%rAttr) / (cnt * 1.0_r8)
00499 endif
00500 if (sno_present) then
00501 s2x_sx_avg%rAttr = (s2x_sx_avg%rAttr + s2x_sx%rAttr) / (cnt * 1.0_r8)
00502 x2s_sx_avg%rAttr = (x2s_sx_avg%rAttr + x2s_sx%rAttr) / (cnt * 1.0_r8)
00503 endif
00504
00505 call seq_infodata_GetData( infodata, case_name=case_name)
00506 call seq_timemgr_EClockGetData( EClock_d, prev_ymd=prev_ymd, prev_tod=prev_tod)
00507 if (seq_timemgr_histavg_type == seq_timemgr_type_nyear) then
00508 call shr_cal_date2ymd(prev_ymd,yy,mm,dd)
00509 write(hist_file,"(2a,i4.4,a)") &
00510 trim(case_name), '.cpl.ha.', yy,'.nc'
00511 elseif (seq_timemgr_histavg_type == seq_timemgr_type_nmonth) then
00512 call shr_cal_date2ymd(prev_ymd,yy,mm,dd)
00513 write(hist_file,"(2a,i4.4,a,i2.2,a)") &
00514 trim(case_name), '.cpl.ha.', yy,'-',mm,'.nc'
00515 elseif (seq_timemgr_histavg_type == seq_timemgr_type_nday) then
00516 call shr_cal_date2ymd(prev_ymd,yy,mm,dd)
00517 write(hist_file,"(2a,i4.4,a,i2.2,a,i2.2,a)") &
00518 trim(case_name), '.cpl.ha.', yy,'-',mm,'-',dd,'.nc'
00519 else
00520 call shr_cal_date2ymd(curr_ymd,yy,mm,dd)
00521 write(hist_file,"(2a,i4.4,a,i2.2,a,i2.2,a,i5.5,a)") &
00522 trim(case_name), '.cpl.ha.', yy,'-',mm,'-',dd,'-',curr_tod,'.nc'
00523 endif
00524
00525 time_units = 'days since ' &
00526 // seq_io_date2yyyymmdd(start_ymd) // ' ' // seq_io_sec2hms(start_tod)
00527
00528 if (iamin_CPLID) then
00529
00530 if (drv_threading) call seq_comm_setnthreads(nthreads_CPLID)
00531 call seq_io_wopen(hist_file,cdata_ax,clobber=.true.,cdf64=cdf64)
00532
00533
00534
00535 do fk = 1,2
00536 if (fk == 1) then
00537 whead = .true.
00538 wdata = .false.
00539 elseif (fk == 2) then
00540 whead = .false.
00541 wdata = .true.
00542 call seq_io_enddef(hist_file)
00543 else
00544 call shr_sys_abort('seq_hist_writeavg fk illegal')
00545 end if
00546
00547 call seq_io_write(hist_file,&
00548 time_units=time_units,time_cal=calendar,time_val=curr_time,&
00549 whead=whead,wdata=wdata,tbnds=tbnds)
00550 if (atm_present) then
00551 call seq_io_write(hist_file,cdata_ax,dom_ax%data,'dom_ax', &
00552 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='doma')
00553 call seq_io_write(hist_file,cdata_ax,x2a_ax_avg,'x2a_ax', &
00554 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='x2aavg',tavg=.true.)
00555 call seq_io_write(hist_file,cdata_ax,a2x_ax_avg,'a2x_ax', &
00556 nx=atm_nx,ny=atm_ny,whead=whead,wdata=wdata,pre='a2xavg',tavg=.true.)
00557 endif
00558 if (lnd_present) then
00559 call seq_io_write(hist_file,cdata_lx,dom_lx%data,'dom_lx', &
00560 nx=lnd_nx,ny=lnd_ny,whead=whead,wdata=wdata,pre='doml')
00561 call seq_io_write(hist_file,cdata_lx,l2x_lx_avg,'l2x_lx', &
00562 nx=lnd_nx,ny=lnd_ny,whead=whead,wdata=wdata,pre='l2xavg',tavg=.true.)
00563 call seq_io_write(hist_file,cdata_lx,x2l_lx_avg,'x2l_lx', &
00564 nx=lnd_nx,ny=lnd_ny,whead=whead,wdata=wdata,pre='x2lavg',tavg=.true.)
00565 endif
00566
00567 if (rof_present .and. ocnrof_prognostic) then
00568 call seq_io_write(hist_file,cdata_rx,dom_rx%data,'dom_rx', &
00569 nx=rof_nx,ny=rof_ny,whead=whead,wdata=wdata,pre='domr')
00570 call seq_io_write(hist_file,cdata_rx,r2x_rx_avg,'r2x_rx', &
00571 nx=rof_nx,ny=rof_ny,whead=whead,wdata=wdata,pre='r2xavg',tavg=.true.)
00572 endif
00573 if (ocn_present) then
00574 call seq_io_write(hist_file,cdata_ox,dom_ox%data,'dom_ox', &
00575 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='domo')
00576 call seq_io_write(hist_file,cdata_ox,o2x_ox_avg,'o2x_ox', &
00577 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='o2xavg',tavg=.true.)
00578 call seq_io_write(hist_file,cdata_ox,x2o_ox_avg,'x2o_ox', &
00579 nx=ocn_nx,ny=ocn_ny,whead=whead,wdata=wdata,pre='x2oavg',tavg=.true.)
00580 endif
00581 if (ice_present) then
00582 call seq_io_write(hist_file,cdata_ix,dom_ix%data,'dom_ix', &
00583 nx=ice_nx,ny=ice_ny,whead=whead,wdata=wdata,pre='domi')
00584 call seq_io_write(hist_file,cdata_ix,i2x_ix_avg,'i2x_ix', &
00585 nx=ice_nx,ny=ice_ny,whead=whead,wdata=wdata,pre='i2xavg',tavg=.true.)
00586 call seq_io_write(hist_file,cdata_ix,x2i_ix_avg,'x2i_ix', &
00587 nx=ice_nx,ny=ice_ny,whead=whead,wdata=wdata,pre='x2iavg',tavg=.true.)
00588 endif
00589 if (glc_present) then
00590 call seq_io_write(hist_file,cdata_gx,dom_gx%data,'dom_gx', &
00591 nx=glc_nx,ny=glc_ny,whead=whead,wdata=wdata,pre='domg')
00592 call seq_io_write(hist_file,cdata_gx,g2x_gx_avg,'g2x_gx', &
00593 nx=glc_nx,ny=glc_ny,whead=whead,wdata=wdata,pre='g2xavg',tavg=.true.)
00594 call seq_io_write(hist_file,cdata_gx,x2g_gx_avg,'x2g_gx', &
00595 nx=glc_nx,ny=glc_ny,whead=whead,wdata=wdata,pre='x2gavg',tavg=.true.)
00596 endif
00597 if (sno_present) then
00598 call seq_io_write(hist_file,cdata_sx,dom_sx%data,'dom_sx', &
00599 nx=sno_nx,ny=sno_ny,whead=whead,wdata=wdata,pre='doms')
00600 call seq_io_write(hist_file,cdata_sx,s2x_sx_avg,'s2x_sx', &
00601 nx=sno_nx,ny=sno_ny,whead=whead,wdata=wdata,pre='s2xavg',tavg=.true.)
00602 call seq_io_write(hist_file,cdata_sx,x2s_sx_avg,'x2s_sx', &
00603 nx=sno_nx,ny=sno_ny,whead=whead,wdata=wdata,pre='x2savg',tavg=.true.)
00604 endif
00605 enddo
00606
00607 call seq_io_close(hist_file,cdata_ax)
00608 if (drv_threading) call seq_comm_setnthreads(nthreads_GLOID)
00609
00610 if (atm_present) then
00611 call mct_aVect_zero(a2x_ax_avg)
00612 call mct_aVect_zero(x2a_ax_avg)
00613 endif
00614 if (lnd_present) then
00615 call mct_aVect_zero(l2x_lx_avg)
00616 call mct_aVect_zero(x2l_lx_avg)
00617 endif
00618 if (rof_present .and. ocnrof_prognostic) then
00619 call mct_aVect_zero(r2x_rx_avg)
00620 endif
00621 if (ocn_present) then
00622 call mct_aVect_zero(o2x_ox_avg)
00623 call mct_aVect_zero(x2o_ox_avg)
00624 endif
00625 if (ice_present) then
00626 call mct_aVect_zero(i2x_ix_avg)
00627 call mct_aVect_zero(x2i_ix_avg)
00628 endif
00629 if (glc_present) then
00630 call mct_aVect_zero(g2x_gx_avg)
00631 call mct_aVect_zero(x2g_gx_avg)
00632 endif
00633 if (sno_present) then
00634 call mct_aVect_zero(s2x_sx_avg)
00635 call mct_aVect_zero(x2s_sx_avg)
00636 endif
00637 cnt = 0
00638 tbnds(1) = curr_time
00639
00640 endif
00641 endif
00642
00643 end subroutine seq_hist_writeavg
00644
00645
00646
00647 subroutine seq_hist_writeaux(EClock_d,aname,dname,cdata_av,av,nx,ny,nt,write_now,flds)
00648
00649 implicit none
00650
00651 type(ESMF_Clock), intent(in) :: EClock_d
00652 character(*) , intent(in) :: aname
00653 character(*) , intent(in) :: dname
00654 type(seq_cdata) , intent(in) :: cdata_av
00655 type(mct_aVect) , intent(in) :: av
00656 integer(IN) , intent(in) :: nx
00657 integer(IN) , intent(in) :: ny
00658 integer(IN) , intent(in) :: nt
00659 logical,optional, intent(in) :: write_now
00660 character(*),intent(in),optional :: flds
00661
00662
00663 character(CL) :: case_name
00664 type(mct_gGrid),pointer :: dom
00665 integer(IN) :: curr_ymd
00666 integer(IN) :: curr_tod
00667 integer(IN) :: start_ymd
00668 integer(IN) :: start_tod
00669 real(r8) :: curr_time
00670 real(r8) :: prev_time
00671 integer(IN) :: yy,mm,dd
00672 integer(IN) :: n,fk,fk1
00673 character(CL) :: time_units
00674 character(CL) :: calendar
00675 integer(IN) :: samples_per_file
00676 integer(IN) :: lsize
00677 logical :: first_call
00678 integer(IN) :: found = -10
00679 logical :: useavg
00680 logical :: lwrite_now
00681 logical :: whead,wdata
00682 real(r8) :: tbnds(2)
00683
00684 integer(IN),parameter :: maxout = 20
00685 integer(IN) ,save :: ntout = 0
00686 character(CS) ,save :: tname(maxout) = 'x1y2z3'
00687 integer(IN) ,save :: ncnt(maxout) = -10
00688 character(CL) ,save :: hist_file(maxout)
00689 type(mct_aVect) ,save :: avavg(maxout)
00690 integer(IN) ,save :: avcnt(maxout) = 0
00691 logical ,save :: fwrite(maxout) = .true.
00692 real(r8) ,save :: tbnds1(maxout)
00693 real(r8) ,save :: tbnds2(maxout)
00694
00695 type(mct_aVect) :: avflds
00696
00697 real(r8),parameter :: c0 = 0.0_r8
00698
00699
00700
00701
00702
00703
00704
00705
00706 iamin_CPLID = seq_comm_iamin(CPLID)
00707 call seq_comm_setptrs(GLOID,mpicom=mpicom_GLOID,nthreads=nthreads_GLOID)
00708 call seq_comm_setptrs(CPLID,mpicom=mpicom_CPLID,nthreads=nthreads_CPLID)
00709 call seq_infodata_getData(infodata,drv_threading=drv_threading)
00710 call seq_infodata_getData(infodata, &
00711 atm_present=atm_present, &
00712 lnd_present=lnd_present, &
00713 rof_present=rof_present, &
00714 ice_present=ice_present, &
00715 ocn_present=ocn_present, &
00716 glc_present=glc_present, &
00717 sno_present=sno_present )
00718 call seq_infodata_getData(infodata, cpl_cdf64=cdf64 )
00719
00720
00721 lwrite_now = .true.
00722 useavg = .false.
00723 if (present(write_now)) then
00724 useavg = .true.
00725 lwrite_now = write_now
00726 endif
00727
00728 call seq_timemgr_EClockGetData( EClock_d, curr_ymd=curr_ymd, curr_tod=curr_tod, &
00729 start_ymd=start_ymd, start_tod=start_tod, curr_time=curr_time, prev_time=prev_time, &
00730 calendar=calendar)
00731
00732 first_call = .true.
00733 do n = 1,ntout
00734 if (trim(tname(n)) == trim(aname)) then
00735 first_call = .false.
00736 found = n
00737 endif
00738 enddo
00739
00740 if (first_call) then
00741 ntout = ntout + 1
00742 if (ntout > maxout) then
00743 write(logunit,*) 'write_history_spewAV maxout exceeded',ntout,maxout
00744 call shr_sys_abort()
00745 endif
00746 tname(ntout) = trim(aname)
00747 ncnt(ntout) = -10
00748 if (iamin_CPLID .and. useavg) then
00749 lsize = mct_aVect_lsize(av)
00750 call mct_aVect_init(avavg(ntout),av,lsize)
00751 call mct_aVect_zero(avavg(ntout))
00752 avcnt(ntout) = 0
00753 endif
00754 tbnds1(ntout) = prev_time
00755 found = ntout
00756 endif
00757
00758
00759 if (iamin_CPLID) then
00760
00761 samples_per_file = nt
00762
00763 if (useavg) then
00764 if (lwrite_now) then
00765 avcnt(found) = avcnt(found) + 1
00766 avavg(found)%rAttr = (avavg(found)%rAttr + av%rAttr) / (avcnt(found) * 1.0_r8)
00767 else
00768 avcnt(found) = avcnt(found) + 1
00769 avavg(found)%rAttr = avavg(found)%rAttr + av%rAttr
00770 endif
00771 endif
00772
00773 if (lwrite_now) then
00774
00775 ncnt(found) = ncnt(found) + 1
00776 if (ncnt(found) < 1 .or. ncnt(found) > samples_per_file) ncnt(found) = 1
00777
00778 time_units = 'days since ' &
00779 // seq_io_date2yyyymmdd(start_ymd) // ' ' // seq_io_sec2hms(start_tod)
00780 tbnds2(found) = curr_time
00781
00782 if (ncnt(found) == 1) then
00783 fk1 = 1
00784 call seq_infodata_GetData( infodata, case_name=case_name)
00785 call shr_cal_date2ymd(curr_ymd,yy,mm,dd)
00786 write(hist_file(found),"(a,i4.4,a,i2.2,a,i2.2,a)") &
00787 trim(case_name)//'.cpl.h'//trim(aname)//'.', yy,'-',mm,'-',dd,'.nc'
00788 else
00789 fk1 = 2
00790 endif
00791
00792 call seq_cdata_setptrs(cdata_av, dom=dom)
00793
00794 if (drv_threading) call seq_comm_setnthreads(nthreads_CPLID)
00795 if (fk1 == 1) then
00796 call seq_io_wopen(hist_file(found),cdata_av,clobber=.true.,cdf64=cdf64)
00797 else
00798 call seq_io_wopen(hist_file(found),cdata_av,clobber=.false.,cdf64=cdf64)
00799 endif
00800
00801
00802
00803 tbnds(1) = tbnds1(found)
00804 tbnds(2) = tbnds2(found)
00805
00806 do fk = fk1,2
00807 if (fk == 1) then
00808 whead = .true.
00809 wdata = .false.
00810 elseif (fk == 2) then
00811 whead = .false.
00812 wdata = .true.
00813 else
00814 call shr_sys_abort('seq_hist_writeaux fk illegal')
00815 end if
00816
00817 if (present(flds)) then
00818 if (fk == fk1) then
00819 lsize = mct_aVect_lsize(av)
00820 call mct_aVect_init(avflds, rList=flds, lsize=lsize)
00821 call mct_aVect_zero(avflds)
00822 end if
00823 end if
00824
00825 call seq_io_write(hist_file(found),&
00826 time_units=time_units,time_cal=calendar,time_val=curr_time,&
00827 nt=ncnt(found),whead=whead,wdata=wdata,tbnds=tbnds)
00828
00829 if (fwrite(found)) then
00830 call seq_io_write(hist_file(found),cdata_av,dom%data,trim(dname), &
00831 nx=nx,ny=ny,whead=whead,wdata=wdata,fillval=c0,pre=trim(dname))
00832 endif
00833
00834 if (useavg) then
00835 if (present(flds)) then
00836 call mct_aVect_copy(aVin=avavg(found), aVout=avflds)
00837 call seq_io_write(hist_file(found), cdata_av, avflds, trim(aname), &
00838 nx=nx, ny=ny, nt=ncnt(found), whead=whead, wdata=wdata, &
00839 pre=trim(aname),tavg=.true.,use_float=.true.)
00840 else
00841 call seq_io_write(hist_file(found), cdata_av, avavg(found), trim(aname), &
00842 nx=nx, ny=ny, nt=ncnt(found), whead=whead, wdata=wdata, &
00843 pre=trim(aname),tavg=.true., use_float=.true.)
00844 end if
00845 else if (present(flds)) then
00846 call mct_aVect_copy(aVin=av, aVout=avflds)
00847 call seq_io_write(hist_file(found), cdata_av, avflds, trim(aname), &
00848 nx=nx,ny=ny,nt=ncnt(found),whead=whead,wdata=wdata,pre=trim(aname),&
00849 use_float=.true.)
00850 else
00851 call seq_io_write(hist_file(found), cdata_av, av, trim(aname), &
00852 nx=nx,ny=ny,nt=ncnt(found),whead=whead,wdata=wdata,pre=trim(aname),&
00853 use_float=.true.)
00854 endif
00855
00856 if (present(flds)) then
00857 if (fk == 2) then
00858 call mct_aVect_clean(avflds)
00859 end if
00860 end if
00861
00862 if (fk == 1) call seq_io_enddef(hist_file(found))
00863 if (fk == 2) then
00864 fwrite(found) = .false.
00865 if (useavg) then
00866 call mct_aVect_zero(avavg(found))
00867 avcnt(found) = 0
00868 endif
00869 tbnds1(found) = curr_time
00870 endif
00871 enddo
00872
00873 call seq_io_close(hist_file(found),cdata_av)
00874 if (drv_threading) call seq_comm_setnthreads(nthreads_GLOID)
00875
00876 endif
00877
00878 endif
00879
00880 end subroutine seq_hist_writeaux
00881
00882
00883
00884 end module seq_hist_mod