3 use pio
, only: file_desc_t, io_desc_t, var_desc_t, pio_double, pio_def_dim, &
4 pio_put_att, pio_enddef, pio_initdecomp, pio_read_darray, pio_freedecomp, &
5 pio_closefile, pio_write_darray, pio_def_var, pio_inq_varid, &
6 pio_noerr, pio_bcast_error, pio_internal_error, pio_seterrorhandling
14 use shr_kind_mod
, only: r8 => shr_kind_r8, cl=>shr_kind_cl
15 use shr_file_mod
, only: shr_file_getunit, shr_file_freeunit, &
16 shr_file_setlogunit, shr_file_setloglevel, &
17 shr_file_getlogunit, shr_file_getloglevel, &
19 use shr_sys_mod
, only: shr_sys_flush, shr_sys_abort
23 use cam_instance
, only: cam_instance_init, inst_suffix
24 use cam_control_mod
, only: nsrest, adiabatic, ideal_phys, aqua_planet, eccen, obliqr, lambm0, mvelpp
25 use radiation
, only: radiation_get, radiation_do, radiation_nextsw_cday
26 use phys_grid
, only: get_ncols_p, get_gcol_all_p, &
27 ngcols, get_gcol_p, get_rlat_all_p, &
28 get_rlon_all_p, get_area_all_p
29 use ppgrid
, only: pcols, begchunk, endchunk
30 use dyn_grid
, only: get_horiz_grid_dim_d
32 use cam_restart
, only: get_restcase, get_restartdir
33 use cam_history
, only: outfld, ctitle
34 use abortutils
, only: endrun
35 use filenames
, only: interpret_filename_spec, caseid, brnch_retain_casename
37 use spmd_utils
, only: spmdinit, masterproc, iam
38 use mpishorthand
, only: mpicom
40 use spmd_utils
, only: spmdinit, masterproc, mpicom, iam
42 use time_manager
, only: get_curr_calday, advance_timestep, get_curr_date, get_nstep, &
43 is_first_step, get_step_size, timemgr_init, timemgr_check_restart
46 use cam_logfile
, only: iulog
47 use co2_cycle
, only: c_i, co2_readflux_ocn, co2_readflux_fuel, co2_transport, &
48 co2_time_interp_ocn, co2_time_interp_fuel, data_flux_ocn, data_flux_fuel
49 use physconst
, only: mwco2
50 use runtime_opts
, only: read_namelist
51 use phys_control
, only: cam_chempkg_is
52 use scammod
, only: single_column,scmlat,scmlon
72 private :: atm_setgsmap_mct
73 private :: atm_import_mct
74 private :: atm_export_mct
75 private :: atm_domain_mct
76 private :: atm_read_srfrest_mct
77 private :: atm_write_srfrest_mct
83 type(cam_in_t) ,
pointer :: cam_in(:)
86 type(mct_avect
) :: a2x_a_snap
87 type(mct_avect
) :: a2x_a_sum
89 integer,
parameter :: nlen = 256
90 character(len=nlen) :: fname_srf_cam
91 character(len=nlen) :: pname_srf_cam
94 character(len=cl) :: rsfilename_spec_cam
102 character(*),
parameter :: a2x_avg_flds =
"Faxa_rainc:Faxa_rainl:Faxa_snowc:Faxa_snowl"
106 logical :: lnd_present
107 logical :: ocn_present
120 type(esmf_clock
),
intent(in) :: eclock
121 type(seq_cdata
),
intent(inout) :: cdata_a
122 type(mct_avect
),
intent(inout) :: x2a_a
123 type(mct_avect
),
intent(inout) :: a2x_a
124 character(len=*),
optional,
intent(IN) :: nlfilename
128 type(mct_gsmap
),
pointer :: gsmap_atm
129 type(mct_ggrid
),
pointer :: dom_a
130 type(seq_infodata_type
),
pointer :: infodata
132 integer :: mpicom_atm
136 real(r8):: nextsw_cday
138 integer :: dtime_sync
139 integer :: currentymd
141 integer :: atm_cpl_dt
156 logical :: perpetual_run
157 integer :: perpetual_ymd
158 integer :: shrlogunit,shrloglev
159 logical :: first_time = .true.
160 character(len=SHR_KIND_CS) :: calendar
161 character(len=SHR_KIND_CS) :: starttype
163 integer :: hdim1_d, hdim2_d
166 character(len=64) :: filein
171 #if (defined _MEMTRACE)
174 call memmon_dump_fort(
'memmon.out',
'atm_init_mct:start::',lbnum)
177 call seq_cdata_setptrs(cdata_a, id=atmid, mpicom=mpicom_atm, &
178 gsmap=gsmap_atm, dom=dom_a, infodata=infodata)
182 call cam_instance_init(atmid)
186 rsfilename_spec_cam =
'%c.cam' // trim(inst_suffix) //
'.rs.%y-%m-%d-%s.nc'
190 call cam_cpl_indices_set()
194 call spmdinit(mpicom_atm)
197 inquire(file=
'atm_modelio.nml'//trim(inst_suffix), exist=exists)
199 iulog = shr_file_getunit()
200 call shr_file_setio(
'atm_modelio.nml'//trim(inst_suffix), iulog)
202 write(iulog,*)
"CAM atmosphere model initialization"
205 call shr_file_getlogunit(shrlogunit)
206 call shr_file_getloglevel(shrloglev)
207 call shr_file_setlogunit(iulog)
211 if (co2_readflux_ocn .and. index_x2a_faoo_fco2_ocn /= 0)
then
212 write(iulog,*)
'error co2_readFlux_ocn and index_x2a_Faoo_fco2_ocn cannot both be active'
218 call seq_infodata_getdata( infodata, &
219 case_name=caseid, case_desc=ctitle, &
220 start_type=starttype, &
221 atm_adiabatic=adiabatic, &
222 atm_ideal_phys=ideal_phys, &
223 aqua_planet=aqua_planet, &
224 brnch_retain_casename=brnch_retain_casename, &
225 single_column=single_column, scmlat=scmlat, scmlon=scmlon, &
226 orb_eccen=eccen, orb_mvelpp=mvelpp, orb_lambm0=lambm0, orb_obliqr=obliqr, &
227 lnd_present=lnd_present, ocn_present=ocn_present, &
228 perpetual=perpetual_run, perpetual_ymd=perpetual_ymd)
232 if ( trim(starttype) == trim(seq_infodata_start_type_start))
then
234 else if (trim(starttype) == trim(seq_infodata_start_type_cont) )
then
236 else if (trim(starttype) == trim(seq_infodata_start_type_brnch))
then
239 write(iulog,*)
'atm_comp_mct: ERROR: unknown starttype'
245 call seq_timemgr_eclockgetdata(eclock, &
246 start_ymd=start_ymd, start_tod=start_tod, &
247 ref_ymd=ref_ymd, ref_tod=ref_tod, &
248 stop_ymd=stop_ymd, stop_tod=stop_tod, &
253 filein =
"atm_in" // trim(inst_suffix)
254 call read_namelist(single_column_in=single_column, scmlat_in=scmlat, &
255 scmlon_in=scmlon, nlfilename_in=filein)
259 if ( nsrest == 0 )
then
260 call timemgr_init( calendar_in=calendar, start_ymd=start_ymd, &
261 start_tod=start_tod, ref_ymd=ref_ymd, &
262 ref_tod=ref_tod, stop_ymd=stop_ymd, &
264 perpetual_run=perpetual_run, &
265 perpetual_ymd=perpetual_ymd )
276 call
cam_init( cam_out, cam_in, mpicom_atm, &
277 start_ymd, start_tod, ref_ymd, ref_tod, stop_ymd, stop_tod, &
278 perpetual_run, perpetual_ymd, calendar)
282 if (nsrest /= 0)
then
283 dtime_cam = get_step_size()
284 call timemgr_check_restart( calendar, start_ymd, start_tod, ref_ymd, &
285 ref_tod, dtime_cam, perpetual_run, perpetual_ymd)
290 call atm_setgsmap_mct( mpicom_atm, atmid, gsmap_atm )
291 lsize = mct_gsmap_lsize(gsmap_atm, mpicom_atm)
295 call atm_domain_mct( lsize, gsmap_atm, dom_a )
299 call mct_avect_init(a2x_a, rlist=seq_flds_a2x_fields, lsize=lsize)
300 call mct_avect_zero(a2x_a)
302 call mct_avect_init(x2a_a, rlist=seq_flds_x2a_fields, lsize=lsize)
303 call mct_avect_zero(x2a_a)
305 call mct_avect_init(a2x_a_snap, rlist=a2x_avg_flds, lsize=lsize)
306 call mct_avect_zero(a2x_a_snap)
308 call mct_avect_init(a2x_a_sum , rlist=a2x_avg_flds, lsize=lsize)
309 call mct_avect_zero(a2x_a_sum )
317 call atm_export_mct( cam_out, a2x_a )
321 call seq_infodata_putdata(infodata, atm_prognostic=.true.)
322 call get_horiz_grid_dim_d(hdim1_d, hdim2_d)
323 call seq_infodata_putdata(infodata, atm_nx=hdim1_d, atm_ny=hdim2_d)
328 call seq_infodata_putdata(infodata, atm_aero=.true.)
334 if (nsrest == 0)
then
335 nextsw_cday = get_curr_calday()
336 call seq_infodata_putdata( infodata, nextsw_cday=nextsw_cday )
341 call shr_file_setlogunit(shrlogunit)
342 call shr_file_setloglevel(shrloglev)
357 call shr_file_getlogunit(shrlogunit)
358 call shr_file_getloglevel(shrloglev)
359 call shr_file_setlogunit(iulog)
361 call seq_timemgr_eclockgetdata(eclock,curr_ymd=currentymd, stepno=stepno, dtime=dtime_sync )
362 if (stepno == 0)
then
363 call atm_import_mct( x2a_a, cam_in )
365 call atm_export_mct( cam_out, a2x_a )
367 call atm_read_srfrest_mct( eclock, cdata_a, x2a_a, a2x_a )
368 call atm_import_mct( x2a_a, cam_in )
377 call seq_timemgr_eclockgetdata(eclock,dtime=atm_cpl_dt)
378 dtime = get_step_size()
380 if (nstep < 1 .or. dtime < atm_cpl_dt)
then
381 nextsw_cday = radiation_nextsw_cday()
382 else if (dtime == atm_cpl_dt)
then
383 caldayp1 = get_curr_calday(offset=int(dtime))
384 nextsw_cday = radiation_nextsw_cday()
385 if (caldayp1 /= nextsw_cday) nextsw_cday = -1._r8
387 call shr_sys_abort(
'dtime must be less than or equal to atm_cpl_dt')
389 call seq_infodata_putdata( infodata, nextsw_cday=nextsw_cday )
393 call shr_file_setlogunit(shrlogunit)
394 call shr_file_setloglevel(shrloglev)
398 #if (defined _MEMTRACE )
401 call memmon_dump_fort(
'memmon.out',
'atm_init_mct:end::',lbnum)
402 call memmon_reset_addr()
406 call shr_sys_flush(iulog)
418 use time_manager
, only: advance_timestep, get_curr_date, get_curr_calday, &
419 get_nstep, get_step_size
421 use pmgrid
, only: plev, plevp
422 use constituents
, only: pcnst
423 use shr_sys_mod
, only: shr_sys_flush
424 use chemistry
, only: chem_reset_fluxes
425 use offline_driver
, only: offline_driver_dorun, offline_driver_end_of_data
430 type(esmf_clock
) ,
intent(in) :: eclock
431 type(seq_cdata
) ,
intent(inout) :: cdata_a
432 type(mct_avect
) ,
intent(inout) :: x2a_a
433 type(mct_avect
) ,
intent(inout) :: a2x_a
437 type(seq_infodata_type
),
pointer :: infodata
440 integer :: dtime_sync
441 integer :: currentymd
445 integer :: atm_cpl_dt
457 integer :: shrlogunit,shrloglev
459 real(r8):: nextsw_cday
462 logical :: rstwr_sync
463 logical :: nlend_sync
464 logical :: first_time = .true.
465 character(len=*),
parameter :: subname=
"atm_run_mct"
469 #if (defined _MEMTRACE)
472 call memmon_dump_fort(
'memmon.out',subname //
':start::',lbnum)
478 call shr_file_getlogunit(shrlogunit)
479 call shr_file_getloglevel(shrloglev)
480 call shr_file_setlogunit(iulog)
484 call seq_cdata_setptrs(cdata_a, infodata=infodata)
485 call seq_timemgr_eclockgetdata(eclock,curr_ymd=ymd_sync,curr_tod=tod_sync, &
486 curr_yr=yr_sync,curr_mon=mon_sync,curr_day=day_sync)
489 call seq_infodata_getdata( infodata, &
490 orb_eccen=eccen, orb_mvelpp=mvelpp, orb_lambm0=lambm0, orb_obliqr=obliqr)
492 nlend_sync = seq_timemgr_stopalarmison(eclock)
493 rstwr_sync = seq_timemgr_restartalarmison(eclock)
497 call t_startf(
'CAM_import')
498 call atm_import_mct( x2a_a, cam_in )
499 call t_stopf(
'CAM_import')
504 do while (.not. dosend)
508 call chem_reset_fluxes( x2a_a%rAttr, cam_in )
514 call get_curr_date( yr, mon, day, tod )
515 ymd = yr*10000 + mon*100 + day
517 if( offline_driver_dorun )
then
518 dosend = offline_driver_end_of_data()
520 dosend = (seq_timemgr_eclockdateinsync( eclock, ymd, tod))
526 if (rstwr_sync .and. dosend) rstwr = .true.
528 if (nlend_sync .and. dosend) nlend = .true.
532 if (single_column)
then
533 call scam_use_iop_srf( cam_in )
538 call t_startf(
'CAM_run2')
540 call t_stopf(
'CAM_run2')
542 call t_startf(
'CAM_run3')
544 call t_stopf(
'CAM_run3')
546 call t_startf(
'CAM_run4')
547 call
cam_run4( cam_out, cam_in, rstwr, nlend, &
548 yr_spec=yr_sync, mon_spec=mon_sync, day_spec=day_sync, sec_spec=tod_sync)
549 call t_stopf(
'CAM_run4')
552 if( .not.offline_driver_dorun )
then
553 call t_startf(
'CAM_adv_timestep')
554 call advance_timestep()
555 call t_stopf(
'CAM_adv_timestep')
560 call t_startf(
'CAM_run1')
562 call t_stopf(
'CAM_run1')
566 call t_startf(
'CAM_export')
567 call atm_export_mct( cam_out, a2x_a )
568 call t_stopf(
'CAM_export')
576 call mct_avect_copy( a2x_a, a2x_a_sum )
579 call mct_avect_copy( a2x_a, a2x_a_snap )
580 call mct_avect_accum( avin=a2x_a_snap, avout=a2x_a_sum )
581 avg_count = avg_count + 1
589 call mct_avect_avg( a2x_a_sum, avg_count)
590 call mct_avect_copy( a2x_a_sum, a2x_a )
591 call mct_avect_zero( a2x_a_sum)
597 call seq_timemgr_eclockgetdata(eclock,dtime=atm_cpl_dt)
598 dtime = get_step_size()
599 if (dtime < atm_cpl_dt)
then
600 nextsw_cday = radiation_nextsw_cday()
601 else if (dtime == atm_cpl_dt)
then
602 caldayp1 = get_curr_calday(offset=int(dtime))
603 nextsw_cday = radiation_nextsw_cday()
604 if (caldayp1 /= nextsw_cday) nextsw_cday = -1._r8
606 call shr_sys_abort(
'dtime must be less than or equal to atm_cpl_dt')
608 call seq_infodata_putdata( infodata, nextsw_cday=nextsw_cday )
613 call atm_write_srfrest_mct( cdata_a, x2a_a, a2x_a, &
614 yr_spec=yr_sync, mon_spec=mon_sync, day_spec=day_sync, sec_spec=tod_sync)
619 dtime = get_step_size()
620 call get_curr_date( yr, mon, day, tod, offset=-dtime )
621 ymd = yr*10000 + mon*100 + day
623 if ((.not.seq_timemgr_eclockdateinsync( eclock, ymd, tod )) .and. (.not.offline_driver_dorun))
then
624 call seq_timemgr_eclockgetdata(eclock, curr_ymd=ymd_sync, curr_tod=tod_sync )
625 write(iulog,*)
' cam ymd=',ymd ,
' cam tod= ',tod
626 write(iulog,*)
'sync ymd=',ymd_sync,
' sync tod= ',tod_sync
627 call shr_sys_abort( subname//
': CAM clock is not in sync with master Sync Clock' )
632 call shr_file_setlogunit(shrlogunit)
633 call shr_file_setloglevel(shrloglev)
635 #if (defined _MEMTRACE)
638 call memmon_dump_fort(
'memmon.out',subname //
':end::',lbnum)
639 call memmon_reset_addr()
648 type(esmf_clock
) ,
intent(in) :: eclock
649 type(seq_cdata
) ,
intent(inout) :: cdata_a
650 type(mct_avect
) ,
intent(inout) :: x2a_a
651 type(mct_avect
) ,
intent(inout) :: a2x_a
659 subroutine atm_setgsmap_mct( mpicom_atm, ATMID, GSMap_atm )
660 use phys_grid
, only : get_nlcols_p
665 integer ,
intent(in) :: mpicom_atm
666 integer ,
intent(in) :: atmid
667 type(mct_gsmap
),
intent(out) :: gsmap_atm
671 integer,
allocatable :: gindex(:)
672 integer :: i, n, c, ncols, sizebuf, nlcols
683 do c = begchunk, endchunk
684 ncols = get_ncols_p(c)
690 allocate(gindex(sizebuf))
693 do c = begchunk, endchunk
694 ncols = get_ncols_p(c)
697 gindex(n) = get_gcol_p(c,i)
701 nlcols = get_nlcols_p()
702 call mct_gsmap_init( gsmap_atm, gindex, mpicom_atm, atmid, nlcols, ngcols)
706 end subroutine atm_setgsmap_mct
710 subroutine atm_import_mct( x2a_a, cam_in )
716 use dust_intr
, only: dust_idx1
717 #if (defined MODAL_AERO)
718 use mo_chem_utls
, only: get_spc_ndx
720 use shr_const_mod
, only: shr_const_stebol
721 use seq_drydep_mod
,only: n_drydep
725 type(mct_avect
),
intent(inout) :: x2a_a
726 type(cam_in_t),
intent(inout) :: cam_in(begchunk:endchunk)
730 integer :: i,lat,n,c,ig
733 logical,
save :: first_time = .true.
735 #if (defined MODAL_AERO)
736 integer,
parameter:: ndst =2
737 integer,
target :: spc_ndx(ndst)
738 #if (defined MODAL_AERO_7MODE)
739 integer,
pointer :: dst_a5_ndx, dst_a7_ndx
740 #elif (defined MODAL_AERO_3MODE)
741 integer,
pointer :: dst_a1_ndx, dst_a3_ndx
746 #if (defined MODAL_AERO)
747 #if (defined MODAL_AERO_7MODE)
748 dst_a5_ndx => spc_ndx(1)
749 dst_a7_ndx => spc_ndx(2)
750 dst_a5_ndx = get_spc_ndx(
'dst_a5' )
751 dst_a7_ndx = get_spc_ndx(
'dst_a7' )
752 #elif (defined MODAL_AERO_3MODE)
753 dst_a1_ndx => spc_ndx(1)
754 dst_a3_ndx => spc_ndx(2)
755 dst_a1_ndx = get_spc_ndx(
'dst_a1' )
756 dst_a3_ndx = get_spc_ndx(
'dst_a3' )
763 do c=begchunk,endchunk
764 ncols = get_ncols_p(c)
767 cam_in(c)%cflx(:,:) = 0._r8
770 cam_in(c)%wsx(i) = -x2a_a%rAttr(index_x2a_faxx_taux,ig)
771 cam_in(c)%wsy(i) = -x2a_a%rAttr(index_x2a_faxx_tauy,ig)
772 cam_in(c)%lhf(i) = -x2a_a%rAttr(index_x2a_faxx_lat, ig)
773 cam_in(c)%shf(i) = -x2a_a%rAttr(index_x2a_faxx_sen, ig)
774 cam_in(c)%lwup(i) = -x2a_a%rAttr(index_x2a_faxx_lwup,ig)
775 cam_in(c)%cflx(i,1) = -x2a_a%rAttr(index_x2a_faxx_evap,ig)
776 cam_in(c)%asdir(i) = x2a_a%rAttr(index_x2a_sx_avsdr, ig)
777 cam_in(c)%aldir(i) = x2a_a%rAttr(index_x2a_sx_anidr, ig)
778 cam_in(c)%asdif(i) = x2a_a%rAttr(index_x2a_sx_avsdf, ig)
779 cam_in(c)%aldif(i) = x2a_a%rAttr(index_x2a_sx_anidf, ig)
780 cam_in(c)%ts(i) = x2a_a%rAttr(index_x2a_sx_t, ig)
781 cam_in(c)%sst(i) = x2a_a%rAttr(index_x2a_so_t, ig)
782 cam_in(c)%snowhland(i) = x2a_a%rAttr(index_x2a_sl_snowh, ig)
783 cam_in(c)%snowhice(i) = x2a_a%rAttr(index_x2a_si_snowh, ig)
784 cam_in(c)%tref(i) = x2a_a%rAttr(index_x2a_sx_tref, ig)
785 cam_in(c)%qref(i) = x2a_a%rAttr(index_x2a_sx_qref, ig)
786 cam_in(c)%u10(i) = x2a_a%rAttr(index_x2a_sx_u10, ig)
787 cam_in(c)%icefrac(i) = x2a_a%rAttr(index_x2a_sf_ifrac, ig)
788 cam_in(c)%ocnfrac(i) = x2a_a%rAttr(index_x2a_sf_ofrac, ig)
789 cam_in(c)%landfrac(i) = x2a_a%rAttr(index_x2a_sf_lfrac, ig)
790 if (
associated(cam_in(c)%ram1) ) &
791 cam_in(c)%ram1(i) = x2a_a%rAttr(index_x2a_sl_ram1 , ig)
792 if (
associated(cam_in(c)%fv) ) &
793 cam_in(c)%fv(i) = x2a_a%rAttr(index_x2a_sl_fv , ig)
794 if (
associated(cam_in(c)%soilw) ) &
795 cam_in(c)%soilw(i) = x2a_a%rAttr(index_x2a_sl_soilw, ig)
796 dust_ndx = dust_idx1()
799 #if (defined MODAL_AERO)
800 #if (defined MODAL_AERO_7MODE)
801 cam_in(c)%cflx(i,dust_ndx ) = 0.13_r8 &
802 #elif (defined MODAL_AERO_3MODE)
803 cam_in(c)%cflx(i,dust_ndx ) = 0.032_r8 &
805 * (-x2a_a%rAttr(index_x2a_fall_flxdst1, ig) &
806 -x2a_a%rAttr(index_x2a_fall_flxdst2, ig) &
807 -x2a_a%rAttr(index_x2a_fall_flxdst3, ig) &
808 -x2a_a%rAttr(index_x2a_fall_flxdst4, ig))
809 #if (defined MODAL_AERO_7MODE)
810 cam_in(c)%cflx(i,dust_ndx-spc_ndx(1)+spc_ndx(2)) = 0.87_r8 &
811 #elif (defined MODAL_AERO_3MODE)
812 cam_in(c)%cflx(i,dust_ndx-spc_ndx(1)+spc_ndx(2)) = 0.968_r8 &
814 * (-x2a_a%rAttr(index_x2a_fall_flxdst1, ig) &
815 -x2a_a%rAttr(index_x2a_fall_flxdst2, ig) &
816 -x2a_a%rAttr(index_x2a_fall_flxdst3, ig) &
817 -x2a_a%rAttr(index_x2a_fall_flxdst4, ig))
819 cam_in(c)%cflx(i,dust_ndx ) = -x2a_a%rAttr(index_x2a_fall_flxdst1, ig)
820 cam_in(c)%cflx(i,dust_ndx +1) = -x2a_a%rAttr(index_x2a_fall_flxdst2, ig)
821 cam_in(c)%cflx(i,dust_ndx +2) = -x2a_a%rAttr(index_x2a_fall_flxdst3, ig)
822 cam_in(c)%cflx(i,dust_ndx +3) = -x2a_a%rAttr(index_x2a_fall_flxdst4, ig)
827 if ( index_x2a_sl_ddvel/=0 .and. n_drydep>0 )
then
828 cam_in(c)%depvel(i,:n_drydep) = &
829 x2a_a%rAttr(index_x2a_sl_ddvel:index_x2a_sl_ddvel+n_drydep-1, ig)
834 cam_in(c)%ustar(i) = x2a_a%rAttr(index_x2a_so_ustar,ig)
835 cam_in(c)%re(i) = x2a_a%rAttr(index_x2a_so_re ,ig)
836 cam_in(c)%ssq(i) = x2a_a%rAttr(index_x2a_so_ssq ,ig)
840 if (index_x2a_fall_fco2_lnd /= 0)
then
841 cam_in(c)%fco2_lnd(i) = -x2a_a%rAttr(index_x2a_fall_fco2_lnd,ig)
843 if (index_x2a_faoo_fco2_ocn /= 0)
then
844 cam_in(c)%fco2_ocn(i) = -x2a_a%rAttr(index_x2a_faoo_fco2_ocn,ig)
846 if (index_x2a_faoo_fdms_ocn /= 0)
then
847 cam_in(c)%fdms(i) = -x2a_a%rAttr(index_x2a_faoo_fdms_ocn,ig)
858 if (co2_transport())
then
861 if (co2_readflux_ocn)
then
862 call co2_time_interp_ocn
864 if (co2_readflux_fuel)
then
865 call co2_time_interp_fuel
871 do c=begchunk,endchunk
872 ncols = get_ncols_p(c)
876 if (index_x2a_faoo_fco2_ocn /= 0)
then
877 cam_in(c)%cflx(i,c_i(1)) = cam_in(c)%fco2_ocn(i)
878 else if (co2_readflux_ocn)
then
880 cam_in(c)%cflx(i,c_i(1)) = &
881 -data_flux_ocn%co2flx(i,c)*(1._r8- cam_in(c)%landfrac(i)) &
884 cam_in(c)%cflx(i,c_i(1)) = 0._r8
888 if (co2_readflux_fuel)
then
889 cam_in(c)%cflx(i,c_i(2)) = data_flux_fuel%co2flx(i,c)
891 cam_in(c)%cflx(i,c_i(2)) = 0._r8
895 if (index_x2a_fall_fco2_lnd /= 0)
then
896 cam_in(c)%cflx(i,c_i(3)) = cam_in(c)%fco2_lnd(i)
898 cam_in(c)%cflx(i,c_i(3)) = 0._r8
902 cam_in(c)%cflx(i,c_i(4)) = cam_in(c)%cflx(i,c_i(1)) + &
903 cam_in(c)%cflx(i,c_i(2)) + &
904 cam_in(c)%cflx(i,c_i(3))
912 if (is_first_step())
then
913 do c=begchunk, endchunk
914 ncols = get_ncols_p(c)
916 cam_in(c)%lwup(i) = shr_const_stebol*(cam_in(c)%ts(i)**4)
923 end subroutine atm_import_mct
927 subroutine atm_export_mct( cam_out, a2x_a )
933 type(cam_out_t),
intent(in) :: cam_out(begchunk:endchunk)
934 type(mct_avect
),
intent(inout) :: a2x_a
938 integer :: avsize, avnat
939 integer :: i,m,c,n,ig
948 do c=begchunk, endchunk
949 ncols = get_ncols_p(c)
951 a2x_a%rAttr(index_a2x_sa_pslv ,ig) = cam_out(c)%psl(i)
952 a2x_a%rAttr(index_a2x_sa_z ,ig) = cam_out(c)%zbot(i)
953 a2x_a%rAttr(index_a2x_sa_u ,ig) = cam_out(c)%ubot(i)
954 a2x_a%rAttr(index_a2x_sa_v ,ig) = cam_out(c)%vbot(i)
955 a2x_a%rAttr(index_a2x_sa_tbot ,ig) = cam_out(c)%tbot(i)
956 a2x_a%rAttr(index_a2x_sa_ptem ,ig) = cam_out(c)%thbot(i)
957 a2x_a%rAttr(index_a2x_sa_pbot ,ig) = cam_out(c)%pbot(i)
958 a2x_a%rAttr(index_a2x_sa_shum ,ig) = cam_out(c)%qbot(i,1)
959 a2x_a%rAttr(index_a2x_sa_dens ,ig) = cam_out(c)%rho(i)
960 a2x_a%rAttr(index_a2x_faxa_swnet,ig) = cam_out(c)%netsw(i)
961 a2x_a%rAttr(index_a2x_faxa_lwdn ,ig) = cam_out(c)%flwds(i)
962 a2x_a%rAttr(index_a2x_faxa_rainc,ig) = (cam_out(c)%precc(i)-cam_out(c)%precsc(i))*1000._r8
963 a2x_a%rAttr(index_a2x_faxa_rainl,ig) = (cam_out(c)%precl(i)-cam_out(c)%precsl(i))*1000._r8
964 a2x_a%rAttr(index_a2x_faxa_snowc,ig) = cam_out(c)%precsc(i)*1000._r8
965 a2x_a%rAttr(index_a2x_faxa_snowl,ig) = cam_out(c)%precsl(i)*1000._r8
966 a2x_a%rAttr(index_a2x_faxa_swndr,ig) = cam_out(c)%soll(i)
967 a2x_a%rAttr(index_a2x_faxa_swvdr,ig) = cam_out(c)%sols(i)
968 a2x_a%rAttr(index_a2x_faxa_swndf,ig) = cam_out(c)%solld(i)
969 a2x_a%rAttr(index_a2x_faxa_swvdf,ig) = cam_out(c)%solsd(i)
972 a2x_a%rAttr(index_a2x_faxa_bcphidry,ig) = cam_out(c)%bcphidry(i)
973 a2x_a%rAttr(index_a2x_faxa_bcphodry,ig) = cam_out(c)%bcphodry(i)
974 a2x_a%rAttr(index_a2x_faxa_bcphiwet,ig) = cam_out(c)%bcphiwet(i)
975 a2x_a%rAttr(index_a2x_faxa_ocphidry,ig) = cam_out(c)%ocphidry(i)
976 a2x_a%rAttr(index_a2x_faxa_ocphodry,ig) = cam_out(c)%ocphodry(i)
977 a2x_a%rAttr(index_a2x_faxa_ocphiwet,ig) = cam_out(c)%ocphiwet(i)
978 a2x_a%rAttr(index_a2x_faxa_dstwet1,ig) = cam_out(c)%dstwet1(i)
979 a2x_a%rAttr(index_a2x_faxa_dstdry1,ig) = cam_out(c)%dstdry1(i)
980 a2x_a%rAttr(index_a2x_faxa_dstwet2,ig) = cam_out(c)%dstwet2(i)
981 a2x_a%rAttr(index_a2x_faxa_dstdry2,ig) = cam_out(c)%dstdry2(i)
982 a2x_a%rAttr(index_a2x_faxa_dstwet3,ig) = cam_out(c)%dstwet3(i)
983 a2x_a%rAttr(index_a2x_faxa_dstdry3,ig) = cam_out(c)%dstdry3(i)
984 a2x_a%rAttr(index_a2x_faxa_dstwet4,ig) = cam_out(c)%dstwet4(i)
985 a2x_a%rAttr(index_a2x_faxa_dstdry4,ig) = cam_out(c)%dstdry4(i)
987 if (index_a2x_sa_co2prog /= 0)
then
988 a2x_a%rAttr(index_a2x_sa_co2prog,ig) = cam_out(c)%co2prog(i)
990 if (index_a2x_sa_co2diag /= 0)
then
991 a2x_a%rAttr(index_a2x_sa_co2diag,ig) = cam_out(c)%co2diag(i)
998 end subroutine atm_export_mct
1002 subroutine atm_domain_mct( lsize, gsMap_a, dom_a )
1008 integer ,
intent(in) :: lsize
1009 type(mct_gsmap
),
intent(in) :: gsmap_a
1010 type(mct_ggrid
),
intent(inout):: dom_a
1014 integer :: n,i,c,ncols
1015 real(r8) :: lats(pcols)
1016 real(r8) :: lons(pcols)
1017 real(r8) :: area(pcols)
1018 real(r8),
pointer :: data(:)
1019 integer ,
pointer :: idata(:)
1020 real(r8),
parameter:: radtodeg = 180.0_r8/shr_const_pi
1025 call mct_ggrid_init( ggrid=dom_a, coordchars=trim(seq_flds_dom_coord), otherchars=trim(seq_flds_dom_other), lsize=lsize )
1029 allocate(
data(lsize))
1033 call mct_gsmap_orderedpoints(gsmap_a, iam, idata)
1034 call mct_ggrid_importiattr(dom_a,
'GlobGridNum',idata,lsize)
1039 data(:) = -9999.0_r8
1040 call mct_ggrid_importrattr(dom_a,
"lat" ,
data,lsize)
1041 call mct_ggrid_importrattr(dom_a,
"lon" ,
data,lsize)
1042 call mct_ggrid_importrattr(dom_a,
"area" ,
data,lsize)
1043 call mct_ggrid_importrattr(dom_a,
"aream",
data,lsize)
1045 call mct_ggrid_importrattr(dom_a,
"mask" ,
data,lsize)
1047 call mct_ggrid_importrattr(dom_a,
"frac" ,
data,lsize)
1052 do c = begchunk, endchunk
1053 ncols = get_ncols_p(c)
1054 call get_rlat_all_p(c, ncols, lats)
1057 data(n) = lats(i)*radtodeg
1060 call mct_ggrid_importrattr(dom_a,
"lat",
data,lsize)
1063 do c = begchunk, endchunk
1064 ncols = get_ncols_p(c)
1065 call get_rlon_all_p(c, ncols, lons)
1068 data(n) = lons(i)*radtodeg
1071 call mct_ggrid_importrattr(dom_a,
"lon",
data,lsize)
1074 do c = begchunk, endchunk
1075 ncols = get_ncols_p(c)
1076 call get_area_all_p(c, ncols, area)
1082 call mct_ggrid_importrattr(dom_a,
"area",
data,lsize)
1085 do c = begchunk, endchunk
1086 ncols = get_ncols_p(c)
1092 call mct_ggrid_importrattr(dom_a,
"mask" ,
data,lsize)
1095 end subroutine atm_domain_mct
1099 subroutine atm_read_srfrest_mct( EClock, cdata_a, x2a_a, a2x_a)
1105 type(esmf_clock
),
intent(in) :: eclock
1106 type(seq_cdata
),
intent(inout) :: cdata_a
1107 type(mct_avect
),
intent(inout) :: x2a_a
1108 type(mct_avect
),
intent(inout) :: a2x_a
1114 type(mct_avect
) :: gdata
1123 integer,
pointer :: dof(:)
1124 integer :: lnx, nf_x2a, nf_a2x, k
1125 real(r8),
allocatable :: tmp(:)
1126 type(file_desc_t
) :: file
1127 type(io_desc_t
) :: iodesc
1128 type(var_desc_t
) :: varid
1129 character(CL) :: itemc
1130 type(mct_string
) :: mstring
1134 call seq_timemgr_eclockgetdata( eclock, curr_yr=yr_spec,curr_mon=mon_spec, &
1135 curr_day=day_spec, curr_tod=sec_spec )
1136 fname_srf_cam = interpret_filename_spec( rsfilename_spec_cam, case=get_restcase(), &
1137 yr_spec=yr_spec, mon_spec=mon_spec, day_spec=day_spec, sec_spec= sec_spec )
1138 pname_srf_cam = trim(get_restartdir() )//fname_srf_cam
1139 call getfil(pname_srf_cam, fname_srf_cam)
1141 call cam_pio_openfile(file, fname_srf_cam, 0)
1142 call mct_gsmap_orderedpoints(cdata_a%gsmap, iam, dof)
1143 lnx = mct_gsmap_gsize(cdata_a%gsmap)
1144 call pio_initdecomp(pio_subsystem, pio_double, (/lnx/), dof, iodesc)
1145 allocate(tmp(
size(dof)))
1148 nf_x2a = mct_avect_nrattr(x2a_a)
1151 call mct_avect_getrlist(mstring,k,x2a_a)
1152 itemc = mct_string_tochar(mstring)
1153 call mct_string_clean(mstring)
1155 call pio_seterrorhandling(file, pio_bcast_error)
1156 rcode = pio_inq_varid(file,
'x2a_'//trim(itemc) ,varid)
1157 if (rcode == pio_noerr)
then
1158 call pio_read_darray(file, varid, iodesc, tmp, rcode)
1159 x2a_a%rattr(k,:) = tmp(:)
1161 if (masterproc)
then
1162 write(iulog,*)
'srfrest warning: field ',trim(itemc),
' is not on restart file'
1163 write(iulog,*)
'for backwards compatibility will set it to 0'
1165 x2a_a%rattr(k,:) = 0._r8
1167 call pio_seterrorhandling(file, pio_internal_error)
1170 nf_a2x = mct_avect_nrattr(a2x_a)
1173 call mct_avect_getrlist(mstring,k,a2x_a)
1174 itemc = mct_string_tochar(mstring)
1175 call mct_string_clean(mstring)
1177 rcode = pio_inq_varid(file,
'a2x_'//trim(itemc) ,varid)
1178 call pio_read_darray(file, varid, iodesc, tmp, rcode)
1179 a2x_a%rattr(k,:) = tmp(:)
1182 call pio_freedecomp(file,iodesc)
1183 call pio_closefile(file)
1186 end subroutine atm_read_srfrest_mct
1190 subroutine atm_write_srfrest_mct( cdata_a, x2a_a, a2x_a, &
1191 yr_spec, mon_spec, day_spec, sec_spec)
1197 type(seq_cdata
),
intent(in) :: cdata_a
1198 type(mct_avect
),
intent(in) :: x2a_a
1199 type(mct_avect
),
intent(in) :: a2x_a
1200 integer ,
intent(in) :: yr_spec
1201 integer ,
intent(in) :: mon_spec
1202 integer ,
intent(in) :: day_spec
1203 integer ,
intent(in) :: sec_spec
1208 type(mct_avect
) :: gdata
1214 integer,
pointer :: dof(:)
1215 integer :: nf_x2a, nf_a2x, lnx, dimid(1), k
1216 type(file_desc_t
) :: file
1217 type(var_desc_t
),
pointer :: varid_x2a(:), varid_a2x(:)
1218 type(io_desc_t
) :: iodesc
1219 character(CL) :: itemc
1220 type(mct_string
) :: mstring
1223 fname_srf_cam = interpret_filename_spec( rsfilename_spec_cam, &
1224 yr_spec=yr_spec, mon_spec=mon_spec, day_spec=day_spec, sec_spec= sec_spec )
1225 call cam_pio_createfile(file, fname_srf_cam, 0)
1227 call mct_gsmap_orderedpoints(cdata_a%gsmap, iam, dof)
1228 lnx = mct_gsmap_gsize(cdata_a%gsmap)
1229 call pio_initdecomp(pio_subsystem, pio_double, (/lnx/), dof, iodesc)
1233 nf_x2a = mct_avect_nrattr(x2a_a)
1234 allocate(varid_x2a(nf_x2a))
1236 rcode = pio_def_dim(file,
'x2a_nx',lnx,dimid(1))
1238 call mct_avect_getrlist(mstring,k,x2a_a)
1239 itemc = mct_string_tochar(mstring)
1240 call mct_string_clean(mstring)
1241 rcode = pio_def_var(file,
'x2a_'//trim(itemc),pio_double,dimid,varid_x2a(k))
1242 rcode = pio_put_att(file,varid_x2a(k),
"_fillvalue",fillvalue)
1245 nf_a2x = mct_avect_nrattr(a2x_a)
1246 allocate(varid_a2x(nf_a2x))
1248 rcode = pio_def_dim(file,
'a2x_nx',lnx,dimid(1))
1250 call mct_avect_getrlist(mstring,k,a2x_a)
1251 itemc = mct_string_tochar(mstring)
1252 call mct_string_clean(mstring)
1253 rcode = pio_def_var(file,
'a2x_'//trim(itemc),pio_double,dimid,varid_a2x(k))
1254 rcode = pio_put_att(file,varid_a2x(k),
"_fillvalue",fillvalue)
1257 rcode = pio_enddef(file)
1261 call pio_write_darray(file, varid_x2a(k), iodesc, x2a_a%rattr(k,:), rcode)
1265 call pio_write_darray(file, varid_a2x(k), iodesc, a2x_a%rattr(k,:), rcode)
1268 deallocate(varid_x2a, varid_a2x)
1270 call pio_freedecomp(file,iodesc)
1271 call pio_closefile(file)
1274 end subroutine atm_write_srfrest_mct
subroutine, public atm_final_mct(EClock, cdata_a, x2a_a, a2x_a)
subroutine, public cam_init(cam_out, cam_in, mpicom_atm, start_ymd, start_tod, ref_ymd, ref_tod, stop_ymd, stop_tod, perpetual_run, perpetual_ymd, calendar)
subroutine, public cam_final(cam_out, cam_in)
subroutine, public cam_run2(cam_out, cam_in)
subroutine, public cam_run1(cam_in, cam_out)
subroutine, public atm_run_mct(EClock, cdata_a, x2a_a, a2x_a)
subroutine, public cam_run3(cam_out)
subroutine, public atm_init_mct(EClock, cdata_a, x2a_a, a2x_a, NLFilename)
subroutine, public cam_run4(cam_out, cam_in, rstwr, nlend, yr_spec, mon_spec, day_spec, sec_spec)