126 integer,
intent(out) :: rc
128 TYPE (esmf_gridcomp) :: model
132 character (len=*),
parameter :: myfile = &
133 & __FILE__//
", ATM_SetServices"
140 WRITE (
trac,
'(a,a,i0)')
'==> Entering ATM_SetServices', &
150 CALL nuopc_compderive (model, &
151 & nuopc_setservices, &
153 IF (esmf_logfounderror(rctocheck=rc, &
154 & msg=esmf_logerr_passthru, &
166 CALL nuopc_compsetentrypoint (model, &
167 & methodflag=esmf_method_initialize, &
168 & phaselabellist=(/
"IPDv00p1"/), &
171 IF (esmf_logfounderror(rctocheck=rc, &
172 & msg=esmf_logerr_passthru, &
180 CALL nuopc_compsetentrypoint (model, &
181 & methodflag=esmf_method_initialize, &
182 & phaselabellist=(/
"IPDv00p2"/), &
185 IF (esmf_logfounderror(rctocheck=rc, &
186 & msg=esmf_logerr_passthru, &
198 CALL nuopc_compspecialize (model, &
199 & speclabel=nuopc_label_datainitialize, &
202 IF (esmf_logfounderror(rctocheck=rc, &
203 & msg=esmf_logerr_passthru, &
211 CALL nuopc_compspecialize (model, &
212 & speclabel=nuopc_label_setclock, &
215 IF (esmf_logfounderror(rctocheck=rc, &
216 & msg=esmf_logerr_passthru, &
222# ifdef ESM_SETRUNCLOCK
227 CALL esmf_methodremove (model, &
228 & nuopc_label_setrunclock, &
230 IF (esmf_logfounderror(rctocheck=rc, &
231 & msg=esmf_logerr_passthru, &
237 CALL nuopc_compspecialize (model, &
238 & speclabel=nuopc_label_setrunclock, &
241 IF (esmf_logfounderror(rctocheck=rc, &
242 & msg=esmf_logerr_passthru, &
251 CALL nuopc_compspecialize (model, &
252 & speclabel=nuopc_label_checkimport, &
253 & specphaselabel=
"RunPhase1", &
256 IF (esmf_logfounderror(rctocheck=rc, &
257 & msg=esmf_logerr_passthru, &
265 CALL nuopc_compspecialize (model, &
266 & speclabel=nuopc_label_advance, &
269 IF (esmf_logfounderror(rctocheck=rc, &
270 & msg=esmf_logerr_passthru, &
280 CALL esmf_gridcompsetentrypoint (model, &
281 & methodflag=esmf_method_finalize, &
284 IF (esmf_logfounderror(rctocheck=rc, &
285 & msg=esmf_logerr_passthru, &
292 WRITE (
trac,
'(a,a,i0)')
'<== Exiting ATM_SetServices', &
301 & ImportState, ExportState, &
313 integer,
intent(out) :: rc
315 TYPE (esmf_gridcomp) :: model
316 TYPE (esmf_state) :: importstate
317 TYPE (esmf_state) :: exportstate
318 TYPE (esmf_clock) :: clock
324 character (len=100) :: coupledset, statelabel
325 character (len=240) :: standardname, shortname
327 character (len=*),
parameter :: myfile = &
328 & __FILE__//
", COAMPS_SetInitializeP1"
335 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_SetInitializeP1', &
350 CALL nuopc_addnestedstate (importstate, &
351 & cplset=trim(coupledset), &
352 & nestedstatename=trim(statelabel),&
356 IF (esmf_logfounderror(rctocheck=rc, &
357 & msg=esmf_logerr_passthru, &
366 standardname=
models(
iatmos)%ImportField(i)%standard_name
369 & standardname=trim(standardname), &
370 & name=trim(shortname), &
372 IF (esmf_logfounderror(rctocheck=rc, &
373 & msg=esmf_logerr_passthru, &
392 CALL nuopc_addnestedstate (exportstate, &
393 & cplset=trim(coupledset), &
394 & nestedstatename=trim(statelabel),&
398 IF (esmf_logfounderror(rctocheck=rc, &
399 & msg=esmf_logerr_passthru, &
408 standardname=
models(
iatmos)%ExportField(i)%standard_name
411 & standardname=trim(standardname), &
412 & name=trim(shortname), &
414 IF (esmf_logfounderror(rctocheck=rc, &
415 & msg=esmf_logerr_passthru, &
426 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_SetInitializeP1', &
435 & ImportState, ExportState, &
446 USE avg_mod,
ONLY : avg_init, avg_init_fld, avg_set_ptr
447 USE avg_mod,
ONLY : fld_name, navg_fields
448 USE avg_mod,
ONLY : ifld_airrhm, &
459 & ifld_stress_u_true, &
460 & ifld_stress_v_true, &
465 USE coamm_memm,
ONLY : t_nest2d_ptr
466 USE coamnl_mod,
ONLY : locean
467 USE coamps_parms,
ONLY : max_grids
471 integer,
intent(out) :: rc
473 TYPE (esmf_gridcomp) :: model
474 TYPE (esmf_state) :: importstate
475 TYPE (esmf_state) :: exportstate
476 TYPE (esmf_clock) :: clock
480 logical :: got_heaflx, got_lwdown
483 integer :: stepcount, ng
484 integer :: mycomm, localpet, petcount
485 integer :: exportcount, findex, ifld
487 character (len=*),
parameter :: myfile = &
488 & __FILE__//
", COAMPS_SetInitializeP@"
490 character (ESMF_MAXSTR),
allocatable :: exportnamelist(:)
492 TYPE (esmf_time) :: currenttime, starttime
495 TYPE (t_nest2d_ptr) :: exportpointer(
ngridsa,navg_fields)
502 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_SetInitializeP2', &
513 CALL esmf_gridcompget (model, &
516 IF (esmf_logfounderror(rctocheck=rc, &
517 & msg=esmf_logerr_passthru, &
523 CALL esmf_vmget (vm, &
524 & localpet=localpet, &
525 & petcount=petcount, &
526 & mpicommunicator=mycomm, &
528 IF (esmf_logfounderror(rctocheck=rc, &
529 & msg=esmf_logerr_passthru, &
541 CALL coamps_initialize (mycomm, .false., rc)
542 IF (esmf_logfounderror(rctocheck=rc, &
543 & msg=esmf_logerr_passthru, &
561 & itemcount=exportcount, &
563 IF (esmf_logfounderror(rctocheck=rc, &
564 & msg=esmf_logerr_passthru, &
570 IF (.not.
allocated(exportnamelist))
THEN
571 allocate ( exportnamelist(exportcount) )
574 & itemnamelist=exportnamelist, &
576 IF (esmf_logfounderror(rctocheck=rc, &
577 & msg=esmf_logerr_passthru, &
588 DO ifld=1,exportcount
589 SELECT CASE (trim(adjustl(exportnamelist(ifld))))
590 CASE (
'psfc',
'Pair')
592 CASE (
'tsfc',
'Tair')
596 CASE (
'qsfc',
'Qair')
598 CASE (
'nflx',
'shflux')
601 CASE (
'lwrd',
'LWrad')
603 CASE (
'dlwrd',
'dLWrad',
'lwrad_down')
606 CASE (
'swrd',
'SWrad')
608 CASE (
'dswrd',
'dSWrad')
610 CASE (
'lhfx',
'LHfx')
612 CASE (
'shfx',
'SHfx')
614 CASE (
'swflx',
'swflux')
618 CASE (
'taux',
'taux10',
'sustr')
619 findex=ifld_stress_u_true
620 CASE (
'tauy',
'tauy10',
'svstr')
621 findex=ifld_stress_v_true
622 CASE (
'Uwind',
'u10',
'wndu')
624 CASE (
'Vwind',
'v10',
'wndv')
627 IF (localpet.eq.0)
THEN
628 WRITE (
cplout,10) trim(exportnamelist(ifld))
631 IF (esmf_logfounderror(rctocheck=rc, &
632 & msg=esmf_logerr_passthru, &
638 CALL avg_init_fld (ng, findex)
639 CALL avg_set_ptr (ng, findex, exportpointer(ng,findex)%p)
642 IF (
allocated(exportnamelist))
deallocate (exportnamelist)
647 IF (.not.got_lwdown.and.got_heaflx)
THEN
648 CALL avg_init_fld (ng, ifld_lwdown)
649 CALL avg_set_ptr (ng, ifld_lwdown, exportpointer(ng,findex)%p)
659 CALL coamps_run (ltau_0, stepcount)
675 IF (esmf_logfounderror(rctocheck=rc, &
676 & msg=esmf_logerr_passthru, &
691 IF (esmf_logfounderror(rctocheck=rc, &
692 & msg=esmf_logerr_passthru, &
701 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_SetInitializeP2', &
706 10
FORMAT (/,
' COAMPS_SetInitializeP2 - unable to find time-', &
707 &
'averaged index for Export Field: ',a)
812 USE coamnl_mod,
ONLY : ktaust
813 USE coamnl_mod,
ONLY : ktauf
817 integer,
intent(out) :: rc
819 TYPE (esmf_gridcomp) :: model
824 integer :: localpet, petcount
826# ifdef REGRESS_STARTCLOCK
827 integer :: regressstartdate(7)
830 character (len= 22) :: calendar
831# ifdef REGRESS_STARTCLOCK
832 character (len= 22) :: regressstartstring
834 character (len= 22) :: starttimestring, stoptimestring
835 character (len=160) :: message
837 character (len=*),
parameter :: myfile = &
838 & __FILE__//
", COAMPS_SetClock"
840 TYPE (esmf_calkind_flag) :: caltype
841 TYPE (esmf_clock) :: clock
842 TYPE (esmf_time) :: starttime
850 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_SetClock', &
861 CALL esmf_gridcompget (model, &
862 & localpet=localpet, &
863 & petcount=petcount, &
866 IF (esmf_logfounderror(rctocheck=rc, &
867 & msg=esmf_logerr_passthru, &
878 IF (trim(calendar).eq.
'gregorian')
THEN
879 caltype=esmf_calkind_gregorian
881 caltype=esmf_calkind_gregorian
885 & name=trim(calendar), &
887 IF (esmf_logfounderror(rctocheck=rc, &
888 & msg=esmf_logerr_passthru, &
905 IF (esmf_logfounderror(rctocheck=rc, &
906 & msg=esmf_logerr_passthru, &
912# ifdef REGRESS_STARTCLOCK
920 & yy=regressstartdate(1), &
921 & mm=regressstartdate(2), &
922 & dd=regressstartdate(3), &
923 & h= regressstartdate(4), &
924 & m= regressstartdate(5), &
925 & s= regressstartdate(6), &
926 & ms=regressstartdate(7), &
927 & timestring=regressstartstring, &
929 IF (esmf_logfounderror(rctocheck=rc, &
930 & msg=esmf_logerr_passthru, &
948 IF (esmf_logfounderror(rctocheck=rc, &
949 & msg=esmf_logerr_passthru, &
967 IF (esmf_logfounderror(rctocheck=rc, &
968 & msg=esmf_logerr_passthru, &
975 & timestringisofrac=stoptimestring, &
977 IF (esmf_logfounderror(rctocheck=rc, &
978 & msg=esmf_logerr_passthru, &
983 is=index(stoptimestring,
'T')
984 IF (is.gt.0) stoptimestring(is:is)=
' '
994 timefrac=max(timefrac, &
996 & mask=
models(:)%IsActive))
999 IF (timefrac.lt.1)
THEN
1001 IF (esmf_logfounderror(rctocheck=rc, &
1002 & msg=esmf_logerr_passthru, &
1004 & file=myfile))
THEN
1021 IF (esmf_logfounderror(rctocheck=rc, &
1022 & msg=esmf_logerr_passthru, &
1024 & file=myfile))
THEN
1031 CALL esmf_gridcompset (model, &
1034 IF (esmf_logfounderror(rctocheck=rc, &
1035 & msg=esmf_logerr_passthru, &
1037 & file=myfile))
THEN
1046 IF (esmf_logfounderror(rctocheck=rc, &
1047 & msg=esmf_logerr_passthru, &
1049 & file=myfile))
THEN
1065 IF (localpet.eq.0)
THEN
1066 WRITE (
cplout,10)
'COAMPS Calendar: ', &
1068 &
'COAMPS Start Clock: ', &
1070 &
'COAMPS Stop Clock: ', &
1077 & starttimestring)
THEN
1078 IF (localpet.eq.0)
THEN
1079 WRITE (
cplout,20)
'COAMPS Start Time: ', &
1081 &
'Driver Start Time: ', &
1082 & trim(starttimestring), &
1085 message=
'Driver and COAMPS start times do not match: '// &
1086 &
'please check the config files.'
1087 CALL esmf_logseterror (esmf_failure, rctoreturn=rc, &
1088 & msg=trim(message))
1094 IF (localpet.eq.0)
THEN
1095 WRITE (
cplout,20)
'COAMPS Stop Time: ', &
1097 &
'Driver Stop Time: ', &
1101 message=
'Driver and COAMPS stop times do not match: '// &
1102 &
'please check the config files.'
1103 CALL esmf_logseterror (esmf_failure, rctoreturn=rc, &
1104 & msg=trim(message))
1110 IF (localpet.eq.0)
THEN
1111 WRITE (
cplout,20)
'COAMPS Calendar: ', &
1113 &
'Driver Calendar: ', &
1117 message=
'Driver and COAMPS calendars do not match: '// &
1118 &
'please check the config files.'
1119 CALL esmf_logseterror (esmf_failure, rctoreturn=rc, &
1120 & msg=trim(message))
1125 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_SetClock', &
1130 10
FORMAT (2x,a,2x,a/,2x,a,2x,a,/,2x,a,2x,a,/)
1131 20
FORMAT (/,2x,a,a,/,2x,a,a,/,2x,a)
1243 integer,
intent(out) :: rc
1245 TYPE (esmf_gridcomp) :: model
1249 logical :: isvalid, atcorrecttime
1251 integer :: importcount, i, is, localpet, ng
1253 real (dp) :: tcurrentinseconds
1255 character (len=22) :: drivertimestring, fieldtimestring
1257 character (len=*),
parameter :: myfile = &
1258 & __FILE__//
", COAMPS_CheckImport"
1260 character (ESMF_MAXSTR) :: string, fieldname
1261 character (ESMF_MAXSTR),
allocatable :: importnamelist(:)
1263 TYPE (esmf_clock) :: driverclock
1264 TYPE (esmf_field) :: field
1265 TYPE (esmf_time) :: starttime, currenttime
1266 TYPE (esmf_time) :: drivertime, fieldtime
1267 TYPE (esmf_timeinterval) ::
timestep
1268 TYPE (esmf_vm) :: vm
1275 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_CheckImport', &
1285 CALL nuopc_modelget (model, &
1286 & driverclock=driverclock, &
1288 IF (esmf_logfounderror(rctocheck=rc, &
1289 & msg=esmf_logerr_passthru, &
1291 & file=myfile))
THEN
1295 CALL esmf_gridcompget (model, &
1296 & localpet=localpet, &
1299 IF (esmf_logfounderror(rctocheck=rc, &
1300 & msg=esmf_logerr_passthru, &
1302 & file=myfile))
THEN
1310 CALL esmf_clockget (driverclock, &
1312 & starttime=starttime, &
1313 & currtime=drivertime, &
1315 IF (esmf_logfounderror(rctocheck=rc, &
1316 & msg=esmf_logerr_passthru, &
1318 & file=myfile))
THEN
1322 CALL esmf_timeget (drivertime, &
1323 & s_r8=tcurrentinseconds, &
1324 & timestringisofrac=drivertimestring, &
1326 IF (esmf_logfounderror(rctocheck=rc, &
1327 & msg=esmf_logerr_passthru, &
1329 & file=myfile))
THEN
1332 is=index(drivertimestring,
'T')
1333 IF (is.gt.0) drivertimestring(is:is)=
' '
1343 & itemcount=importcount, &
1345 IF (esmf_logfounderror(rctocheck=rc, &
1346 & msg=esmf_logerr_passthru, &
1348 & file=myfile))
THEN
1352 IF (.not.
allocated(importnamelist))
THEN
1353 allocate ( importnamelist(importcount) )
1357 & itemnamelist=importnamelist, &
1359 IF (esmf_logfounderror(rctocheck=rc, &
1360 & msg=esmf_logerr_passthru, &
1362 & file=myfile))
THEN
1370 field_loop :
DO i=1,importcount
1371 fieldname=trim(importnamelist(i))
1373 & itemname=trim(fieldname), &
1376 IF (esmf_logfounderror(rctocheck=rc, &
1377 & msg=esmf_logerr_passthru, &
1379 & file=myfile))
THEN
1386 CALL nuopc_gettimestamp (field, &
1387 & isvalid = isvalid, &
1388 & time = fieldtime, &
1390 IF (esmf_logfounderror(rctocheck=rc, &
1391 & msg=esmf_logerr_passthru, &
1393 & file=myfile))
THEN
1398 CALL esmf_timeget (fieldtime, &
1399 & timestringisofrac = fieldtimestring, &
1401 IF (esmf_logfounderror(rctocheck=rc, &
1402 & msg=esmf_logerr_passthru, &
1404 & file=myfile))
THEN
1407 is=index(fieldtimestring,
'T')
1408 IF (is.gt.0) fieldtimestring(is:is)=
' '
1410 IF (localpet.eq.0)
THEN
1411 WRITE (
cplout,10) trim(fieldname), &
1412 & trim(fieldtimestring), &
1413 & trim(drivertimestring)
1420 string=
'COAMPS_CheckImport - '//trim(fieldname)//
' field'
1421 currenttime=drivertime
1423 atcorrecttime=nuopc_isattime(field, &
1426 IF (esmf_logfounderror(rctocheck=rc, &
1427 & msg=esmf_logerr_passthru, &
1429 & file=myfile))
THEN
1433 IF (.not.atcorrecttime)
THEN
1435 & localpet, trim(string), rc)
1437 string=
'NUOPC INCOMPATIBILITY DETECTED: Import '// &
1438 &
'Fields not at correct time'
1439 CALL esmf_logseterror(esmf_rc_not_valid, &
1440 & msg=trim(string), &
1447 IF (
allocated(importnamelist))
deallocate (importnamelist)
1453 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_CheckImport', &
1458 10
FORMAT (1x,
'COAMPS_CheckImport - ',a,
':',t32,
'TimeStamp = ',a, &
1459 &
', DriverTime = ',a)
1558 USE coamm_memm,
ONLY : adom
1559 USE domdec,
ONLY : iminf, imaxf, jminf, jmaxf, &
1560 & nlimx, nlimy, nprdom, ndx, ndy
1561 USE gridnl_mod,
ONLY : delx, dely, m, n
1565 integer,
intent(in) :: ng, localpet
1566 integer,
intent(out) :: rc
1568 TYPE (esmf_gridcomp),
intent(inout) :: model
1572 integer :: gtype, i, ivar, j, node, tile
1573 integer :: localde, localdecount
1574 integer :: lbi, ubi, lbj, ubj
1575 integer :: clb(2), cub(2), elb(2), eub(2), tlb(2), tub(2)
1577 integer,
allocatable :: deblocklist(:,:,:)
1578 integer (i4b),
pointer :: ptrm(:,:) => null()
1580 real (dp),
pointer :: ptra(:,:) => null()
1581 real (dp),
pointer :: ptrx(:,:) => null()
1582 real (dp),
pointer :: ptry(:,:) => null()
1584 character (len=40) :: name
1586 character (len=*),
parameter :: myfile = &
1587 & __FILE__//
", COAMPS_SetGridArrays"
1589 TYPE (esmf_distgrid) :: distgrid
1590 TYPE (esmf_staggerloc) :: staggerloc
1591 TYPE (esmf_vm) :: vm
1598 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_SetGridArrays', &
1609 CALL esmf_gridcompget (model, &
1612 IF (esmf_logfounderror(rctocheck=rc, &
1613 & msg=esmf_logerr_passthru, &
1615 & file=myfile))
THEN
1625 IF (.not.
allocated(deblocklist))
THEN
1626 allocate ( deblocklist(2,2,nprdom) )
1629 deblocklist(1,1,tile)=nlimx(ng)%bp(tile)
1630 deblocklist(1,2,tile)=nlimx(ng)%ep(tile)
1631 deblocklist(2,1,tile)=nlimy(ng)%bp(tile)
1632 deblocklist(2,2,tile)=nlimy(ng)%ep(tile)
1642 distgrid=esmf_distgridcreate(minindex=(/ 1, 1 /), &
1643 & maxindex=(/ m(ng), n(ng) /), &
1644 & deblocklist=deblocklist, &
1646 IF (esmf_logfounderror(rctocheck=rc, &
1647 & msg=esmf_logerr_passthru, &
1649 & file=myfile))
THEN
1655 IF ((localpet.eq.0).and.(
debuglevel.gt.0))
THEN
1659 WRITE (
cplout,20) node-1, deblocklist(1,1,node), &
1660 & deblocklist(1,2,node), &
1661 & deblocklist(2,1,node), &
1662 & deblocklist(2,2,node)
1665 IF (
allocated(deblocklist))
deallocate (deblocklist)
1667# ifdef DATA_COUPLING
1676 IF (esmf_logfounderror(rctocheck=rc, &
1677 & msg=esmf_logerr_passthru, &
1679 & file=myfile))
THEN
1700 models(
iatmos)%grid(ng)=esmf_gridcreate(distgrid=distgrid, &
1701 & coordsys=esmf_coordsys_sph_deg, &
1702 & coordtypekind=esmf_typekind_r8, &
1703 & gridedgelwidth=(/0,0/), &
1704 & gridedgeuwidth=(/0,0/), &
1705 & indexflag=esmf_index_global, &
1708 IF (esmf_logfounderror(rctocheck=rc, &
1709 & msg=esmf_logerr_passthru, &
1711 & file=myfile))
THEN
1720 & localdecount=localdecount, &
1722 IF (esmf_logfounderror(rctocheck=rc, &
1723 & msg=esmf_logerr_passthru, &
1725 & file=myfile))
THEN
1731 mesh_loop :
DO ivar=1,ubound(
models(
iatmos)%mesh, dim=1)
1737 staggerloc=esmf_staggerloc_center
1744 & staggerloc=staggerloc, &
1746 IF (esmf_logfounderror(rctocheck=rc, &
1747 & msg=esmf_logerr_passthru, &
1749 & file=myfile))
THEN
1756 & staggerloc=staggerloc, &
1757 & itemflag=esmf_griditem_mask, &
1759 IF (esmf_logfounderror(rctocheck=rc, &
1760 & msg=esmf_logerr_passthru, &
1762 & file=myfile))
THEN
1778 & staggerloc=staggerloc, &
1779 & itemflag=esmf_griditem_area, &
1781 IF (esmf_logfounderror(rctocheck=rc, &
1782 & msg=esmf_logerr_passthru, &
1784 & file=myfile))
THEN
1792 de_loop :
DO localde=0,localdecount-1
1795 & staggerloc=staggerloc, &
1796 & localde=localde, &
1798 & exclusivelbound=elb, &
1799 & exclusiveubound=eub, &
1800 & computationallbound=clb, &
1801 & computationalubound=cub, &
1802 & totallbound=tlb, &
1803 & totalubound=tub, &
1805 IF (esmf_logfounderror(rctocheck=rc, &
1806 & msg=esmf_logerr_passthru, &
1808 & file=myfile))
THEN
1814 & staggerloc=staggerloc, &
1815 & localde=localde, &
1817 & exclusivelbound=elb, &
1818 & exclusiveubound=eub, &
1819 & computationallbound=clb, &
1820 & computationalubound=cub, &
1821 & totallbound=tlb, &
1822 & totalubound=tub, &
1824 IF (esmf_logfounderror(rctocheck=rc, &
1825 & msg=esmf_logerr_passthru, &
1827 & file=myfile))
THEN
1832 & itemflag=esmf_griditem_mask, &
1833 & staggerloc=staggerloc, &
1834 & localde=localde, &
1837 IF (esmf_logfounderror(rctocheck=rc, &
1838 & msg=esmf_logerr_passthru, &
1840 & file=myfile))
THEN
1845 & itemflag=esmf_griditem_area, &
1846 & staggerloc=staggerloc, &
1847 & localde=localde, &
1850 IF (esmf_logfounderror(rctocheck=rc, &
1851 & msg=esmf_logerr_passthru, &
1853 & file=myfile))
THEN
1867 ptrx(i,j)=adom(ng)%aln(i,j)
1868 ptry(i,j)=adom(ng)%phi(i,j)
1869 ptrm(i,j)=adom(ng)%xland(i,j)
1870 ptra(i,j)=delx(ng)*dely(ng)
1877 IF (
associated(ptrx) )
nullify (ptrx)
1878 IF (
associated(ptry) )
nullify (ptry)
1879 IF (
associated(ptrm) )
nullify (ptrm)
1880 IF (
associated(ptra) )
nullify (ptra)
1888 & filename=
"coamps_"// &
1891 & staggerloc=staggerloc, &
1893 IF (esmf_logfounderror(rctocheck=rc, &
1894 & msg=esmf_logerr_passthru, &
1896 & file=myfile))
THEN
1904 CALL esmf_gridcompset (model, &
1907 IF (esmf_logfounderror(rctocheck=rc, &
1908 & msg=esmf_logerr_passthru, &
1910 & file=myfile))
THEN
1915 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_SetGridArrays', &
1921 10
FORMAT (
'COAMPS_DistGrid - Grid = ',i2.2,
',',3x,
'Mesh = ',a,
',', &
1922 & 3x,
'Partition = ',i0,
' x ',i0)
1923 20
FORMAT (18x,
'node = ',i0,t32,
'Istr = ',i0,t45,
'Iend = ',i0, &
1924 & t58,
'Jstr = ',i0,t71,
'Jend = ',i0)
1938 USE domdec,
ONLY : iminf, imaxf, jminf, jmaxf, &
1939 & ndom, nlimx, nlimy
1943 integer,
intent(in) :: ng
1944 integer,
intent(out) :: rc
1946 TYPE (esmf_gridcomp) :: model
1951 integer :: localde, localdecount
1952 integer :: localpet, petcount
1953 integer :: exportcount, importcount
1954 integer :: iminp, imaxp, jminp, jmaxp
1955 integer :: halolw(2), halouw(2)
1957 real (dp),
dimension(:,:),
pointer :: ptr2d => null()
1959 character (len=*),
parameter :: myfile = &
1960 & __FILE__//
", COAMPS_SetStates"
1962 character (ESMF_MAXSTR),
allocatable :: exportnamelist(:)
1963 character (ESMF_MAXSTR),
allocatable :: importnamelist(:)
1965 TYPE (esmf_arrayspec) :: arrayspec2d
1966 TYPE (esmf_field) :: field
1967 TYPE (esmf_staggerloc) :: staggerloc
1968 TYPE (esmf_vm) :: vm
1975 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_SetStates', &
1985 iminp=nlimx(ng)%bp(ndom)
1986 imaxp=nlimx(ng)%ep(ndom)
1987 jminp=nlimy(ng)%bp(ndom)
1988 jmaxp=nlimy(ng)%ep(ndom)
1990 halolw(1)=iminp-iminf(ng)
1991 halolw(2)=jminp-jminf(ng)
1992 halouw(1)=imaxf(ng)-imaxp
1993 halouw(2)=jmaxf(ng)-jmaxp
2001 CALL esmf_gridcompget (model, &
2002 & localpet=localpet, &
2003 & petcount=petcount, &
2006 IF (esmf_logfounderror(rctocheck=rc, &
2007 & msg=esmf_logerr_passthru, &
2009 & file=myfile))
THEN
2018 & localdecount=localdecount, &
2020 IF (esmf_logfounderror(rctocheck=rc, &
2021 & msg=esmf_logerr_passthru, &
2023 & file=myfile))
THEN
2031 CALL esmf_arrayspecset (arrayspec2d, &
2032 & typekind=esmf_typekind_r8, &
2035 IF (esmf_logfounderror(rctocheck=rc, &
2036 & msg=esmf_logerr_passthru, &
2038 & file=myfile))
THEN
2051 & itemcount=exportcount, &
2053 IF (esmf_logfounderror(rctocheck=rc, &
2054 & msg=esmf_logerr_passthru, &
2056 & file=myfile))
THEN
2062 IF (.not.
allocated(exportnamelist))
THEN
2063 allocate ( exportnamelist(exportcount) )
2066 & itemnamelist=exportnamelist, &
2068 IF (esmf_logfounderror(rctocheck=rc, &
2069 & msg=esmf_logerr_passthru, &
2071 & file=myfile))
THEN
2080 IF (nuopc_isconnected(
models(
iatmos)%ExportState(ng), &
2081 & fieldname=trim(exportnamelist(i)), &
2088 staggerloc=esmf_staggerloc_center
2090 staggerloc=esmf_staggerloc_corner
2092 staggerloc=esmf_staggerloc_edge1
2094 staggerloc=esmf_staggerloc_edge2
2101 & indexflag=esmf_index_global, &
2102 & staggerloc=staggerloc, &
2103 & totallwidth=halolw, &
2104 & totaluwidth=halouw, &
2105 & name=trim(exportnamelist(i)), &
2107 IF (esmf_logfounderror(rctocheck=rc, &
2108 & msg=esmf_logerr_passthru, &
2110 & file=myfile))
THEN
2117 DO localde=0,localdecount-1
2121 CALL esmf_fieldget (field, &
2122 & localde=localde, &
2123 & farrayptr=ptr2d, &
2125 IF (esmf_logfounderror(rctocheck=rc, &
2126 & msg=esmf_logerr_passthru, &
2128 & file=myfile))
THEN
2139 IF (
associated(ptr2d) )
nullify (ptr2d)
2147 IF (esmf_logfounderror(rctocheck=rc, &
2148 & msg=esmf_logerr_passthru, &
2150 & file=myfile))
THEN
2157 IF (localpet.eq.0)
THEN
2158 WRITE (
cplout,10) trim(exportnamelist(i)), &
2159 &
'Export State: ', &
2162 CALL esmf_stateremove (
models(
iatmos)%ExportState(ng), &
2163 & (/ trim(exportnamelist(i)) /), &
2165 IF (esmf_logfounderror(rctocheck=rc, &
2166 & msg=esmf_logerr_passthru, &
2168 & file=myfile))
THEN
2176 IF (
allocated(exportnamelist) )
deallocate (exportnamelist)
2189 & itemcount=importcount, &
2191 IF (esmf_logfounderror(rctocheck=rc, &
2192 & msg=esmf_logerr_passthru, &
2194 & file=myfile))
THEN
2200 IF (.not.
allocated(importnamelist))
THEN
2201 allocate (importnamelist(importcount))
2204 & itemnamelist=importnamelist, &
2206 IF (esmf_logfounderror(rctocheck=rc, &
2207 & msg=esmf_logerr_passthru, &
2209 & file=myfile))
THEN
2218 IF (nuopc_isconnected(
models(
iatmos)%ImportState(ng), &
2219 & fieldname=trim(importnamelist(i)), &
2226 staggerloc=esmf_staggerloc_center
2228 staggerloc=esmf_staggerloc_corner
2230 staggerloc=esmf_staggerloc_edge1
2232 staggerloc=esmf_staggerloc_edge2
2239 & indexflag=esmf_index_global, &
2240 & staggerloc=staggerloc, &
2241 & totallwidth=halolw, &
2242 & totaluwidth=halouw, &
2243 & name=trim(importnamelist(i)), &
2245 IF (esmf_logfounderror(rctocheck=rc, &
2246 & msg=esmf_logerr_passthru, &
2248 & file=myfile))
THEN
2255 DO localde=0,localdecount-1
2259 CALL esmf_fieldget (field, &
2260 & localde=localde, &
2261 & farrayptr=ptr2d, &
2263 IF (esmf_logfounderror(rctocheck=rc, &
2264 & msg=esmf_logerr_passthru, &
2266 & file=myfile))
THEN
2277 IF (
associated(ptr2d))
nullify (ptr2d)
2285 IF (esmf_logfounderror(rctocheck=rc, &
2286 & msg=esmf_logerr_passthru, &
2288 & file=myfile))
THEN
2295 IF (localpet.eq.0)
THEN
2296 WRITE (
cplout,10) trim(importnamelist(i)), &
2297 &
'Import State: ', &
2300 CALL esmf_stateremove (
models(
iatmos)%ImportState(ng), &
2301 & (/ trim(importnamelist(i)) /), &
2303 IF (esmf_logfounderror(rctocheck=rc, &
2304 & msg=esmf_logerr_passthru, &
2306 & file=myfile))
THEN
2314 IF (
allocated(importnamelist))
deallocate (importnamelist)
2319 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_SetStates', &
2325 10
FORMAT (
'COAMPS_SetStates - Removing field ''',a,
''' from ',a, &
2326 &
'''',a,
'''',/,19x,
'because it is not connected.')
2341 USE coamnl_mod,
ONLY : delta
2345 integer,
intent(out) :: rc
2347 TYPE (esmf_gridcomp) :: model
2351 logical :: ladvance, ltau_0
2354 integer :: localpet, petcount, phase
2355 integer :: nstrstep, nendstep, stepcount
2357 real (dp) :: couplinginterval, secondssincestart
2358 real (dp) :: tcurrentinseconds, tstopinseconds
2360 character (len=22) :: cinterval
2361 character (len=22) :: currtimestring, stoptimestring
2363 character (len=*),
parameter :: myfile = &
2364 & __FILE__//
", COAMPS_SetModelAdvance"
2366 TYPE (esmf_clock) :: clock
2367 TYPE (esmf_state) :: exportstate, importstate
2368 TYPE (esmf_timeinterval) ::
timestep
2369 TYPE (esmf_time) :: referencetime
2370 TYPE (esmf_time) :: currenttime, starttime, stoptime
2371 TYPE (esmf_vm) :: vm
2378 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_ModelAdvance', &
2390 CALL esmf_gridcompget (model, &
2391 & importstate=importstate, &
2392 & exportstate=exportstate, &
2394 & localpet=localpet, &
2395 & petcount=petcount, &
2396 & currentphase=phase, &
2399 IF (esmf_logfounderror(rctocheck=rc, &
2400 & msg=esmf_logerr_passthru, &
2402 & file=myfile))
THEN
2409 CALL esmf_clockget (clock, &
2411 & stoptime=stoptime, &
2412 & reftime=referencetime, &
2415 IF (esmf_logfounderror(rctocheck=rc, &
2416 & msg=esmf_logerr_passthru, &
2418 & file=myfile))
THEN
2425 & s_r8=tcurrentinseconds, &
2426 & timestringisofrac=currtimestring, &
2428 IF (esmf_logfounderror(rctocheck=rc, &
2429 & msg=esmf_logerr_passthru, &
2431 & file=myfile))
THEN
2434 is=index(currtimestring,
'T')
2435 IF (is.gt.0) currtimestring(is:is)=
' '
2440 & s_r8=tstopinseconds, &
2441 & timestringisofrac=stoptimestring, &
2443 IF (esmf_logfounderror(rctocheck=rc, &
2444 & msg=esmf_logerr_passthru, &
2446 & file=myfile))
THEN
2449 is=index(stoptimestring,
'T')
2450 IF (is.gt.0) stoptimestring(is:is)=
' '
2454 CALL esmf_timeintervalget (
timestep, &
2455 & s_r8=couplinginterval, &
2457 IF (esmf_logfounderror(rctocheck=rc, &
2458 & msg=esmf_logerr_passthru, &
2460 & file=myfile))
THEN
2471 secondssincestart=tcurrentinseconds- &
2474 secondssincestart=tcurrentinseconds- &
2480 nstrstep=int((secondssincestart+0.001_dp)/delta)+1
2481 nendstep=int(secondssincestart+couplinginterval+0.001_dp)/delta
2482 stepcount=nendstep-nstrstep+1
2484# ifdef REGRESS_STARTCLOCK
2505 IF (localpet.eq.0)
THEN
2506 WRITE (cinterval,
'(f15.2)') couplinginterval
2507 WRITE (
cplout,10) trim(currtimestring), trim(stoptimestring), &
2508 & trim(adjustl(cinterval)), ladvance
2519 IF (esmf_logfounderror(rctocheck=rc, &
2520 & msg=esmf_logerr_passthru, &
2522 & file=myfile))
THEN
2538 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_Run', &
2542 CALL coamps_run (ltau_0, stepcount)
2544 WRITE (
trac,
'(a,a,i0)')
'==> Exiting COAMPS_Run', &
2558 IF (esmf_logfounderror(rctocheck=rc, &
2559 & msg=esmf_logerr_passthru, &
2561 & file=myfile))
THEN
2569 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_ModelAdvance', &
2574 10
FORMAT (3x,
'ModelAdvance - ESMF, Running COAMPS:',t42,a, &
2575 &
' => ',a,
', [',a,
' s], Advance: ',l1)
2640 USE coamm_memm,
ONLY : adom
2641 USE domdec,
ONLY : iminf, imaxf, jminf, jmaxf, &
2642 & ndom, nlimx, nlimy
2646 integer,
intent(in) :: ng
2647 integer,
intent(out) :: rc
2649 TYPE (esmf_gridcomp) :: model
2653 logical :: got_sst(2)
2655 integer :: id, ifld, i, is, j
2656 integer :: year, month, day, hour, minutes, seconds, sn, sd
2657 integer :: seaice, seawater
2658 integer :: importcount
2659 integer :: localde, localdecount, localpet, petcount
2660 integer :: lbi, ubi, lbj, ubj
2661 integer :: iminp, imaxp, jminp, jmaxp
2662 integer :: ifield(2)
2664 real (dp) :: fseconds, timeindays, time_current
2666 real (dp) :: myfmax(2), myfmin(2), fmin(2), fmax(2), fval
2667 real (dp) :: scale, add_offset
2669 real (dp),
pointer :: ptr2d(:,:)
2671 real (dp),
allocatable :: dat_sst(:,:), ocn_sst(:,:)
2673 character (len=22 ) :: time_currentstring
2675 character (len=*),
parameter :: myfile = &
2676 & __FILE__//
", COAMPS_Import"
2678 character (ESMF_MAXSTR) :: fieldname, fld_name(2)
2679 character (ESMF_MAXSTR) :: cname, ofile
2680 character (ESMF_MAXSTR),
allocatable :: importnamelist(:)
2682 TYPE (esmf_clock) :: clock
2683 TYPE (esmf_field) :: field
2684 TYPE (esmf_state) :: importstate
2685 TYPE (esmf_time) :: currenttime
2686 TYPE (esmf_vm) :: vm
2693 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_Import', &
2704 iminp=nlimx(ng)%bp(ndom)
2705 imaxp=nlimx(ng)%ep(ndom)
2706 jminp=nlimy(ng)%bp(ndom)
2707 jmaxp=nlimy(ng)%ep(ndom)
2713 CALL esmf_gridcompget (model, &
2714 & importstate=importstate, &
2716 & localpet=localpet, &
2717 & petcount=petcount, &
2721 IF (esmf_logfounderror(rctocheck=rc, &
2722 & msg=esmf_logerr_passthru, &
2724 & file=myfile))
THEN
2733 & localdecount=localdecount, &
2735 IF (esmf_logfounderror(rctocheck=rc, &
2736 & msg=esmf_logerr_passthru, &
2738 & file=myfile))
THEN
2746 CALL esmf_clockget (clock, &
2747 & currtime=currenttime, &
2749 IF (esmf_logfounderror(rctocheck=rc, &
2750 & msg=esmf_logerr_passthru, &
2752 & file=myfile))
THEN
2756 CALL esmf_timeget (currenttime, &
2766 IF (esmf_logfounderror(rctocheck=rc, &
2767 & msg=esmf_logerr_passthru, &
2769 & file=myfile))
THEN
2773 CALL esmf_timeget (currenttime, &
2774 & s_r8=time_current, &
2775 & timestring=time_currentstring, &
2777 IF (esmf_logfounderror(rctocheck=rc, &
2778 & msg=esmf_logerr_passthru, &
2780 & file=myfile))
THEN
2783 fseconds=real(seconds,dp)+real(sn,dp)/real(sd,dp)
2784 timeindays=time_current/86400.0_dp
2785 is=index(time_currentstring,
'T')
2786 IF (is.gt.0) time_currentstring(is:is)=
' '
2793 & itemcount=importcount, &
2795 IF (esmf_logfounderror(rctocheck=rc, &
2796 & msg=esmf_logerr_passthru, &
2798 & file=myfile))
THEN
2802 IF (.not.
allocated(importnamelist))
THEN
2803 allocate ( importnamelist(importcount) )
2806 & itemnamelist=importnamelist, &
2808 IF (esmf_logfounderror(rctocheck=rc, &
2809 & msg=esmf_logerr_passthru, &
2811 & file=myfile))
THEN
2831 fld_loop :
DO ifld=1,importcount
2837 & trim(importnamelist(ifld)), &
2840 IF (esmf_logfounderror(rctocheck=rc, &
2841 & msg=esmf_logerr_passthru, &
2843 & file=myfile))
THEN
2850 de_loop :
DO localde=0,localdecount-1
2851 CALL esmf_fieldget (field, &
2852 & localde=localde, &
2853 & farrayptr=ptr2d, &
2855 IF (esmf_logfounderror(rctocheck=rc, &
2856 & msg=esmf_logerr_passthru, &
2858 & file=myfile))
THEN
2877 fieldname=adjustl(importnamelist(ifld))
2879 SELECT CASE (trim(fieldname))
2884 IF (.not.
allocated(ocn_sst))
THEN
2885 allocate ( ocn_sst(lbi:ubi,lbj:ubj) )
2888 IF (.not.
allocated(dat_sst))
THEN
2889 allocate ( dat_sst(lbi:ubi,lbj:ubj) )
2894 fld_name(1)=trim(fieldname)
2897 IF (((nint(adom(ng)%xland(i,j)).eq.seawater).or. &
2898 & (nint(adom(ng)%xland(i,j)).eq.seaice)).and. &
2899 & (abs(ptr2d(i,j)).lt.
tol_dp))
THEN
2900 myfmin(1)=min(myfmin(1),ptr2d(i,j))
2901 myfmax(1)=max(myfmax(1),ptr2d(i,j))
2902 fval=scale*ptr2d(i,j)+add_offset
2903 myfmin(2)=min(myfmin(2),fval)
2904 myfmax(2)=max(myfmax(2),fval)
2913 CASE (
'dsst',
'dSST')
2914 IF (.not.
allocated(ocn_sst))
THEN
2915 allocate ( ocn_sst(lbi:ubi,lbj:ubj) )
2918 IF (.not.
allocated(dat_sst))
THEN
2919 allocate ( dat_sst(lbi:ubi,lbj:ubj) )
2924 fld_name(2)=trim(fieldname)
2927 IF (((nint(adom(ng)%xland(i,j)).eq.seawater).or. &
2928 & (nint(adom(ng)%xland(i,j)).eq.seaice)).and. &
2929 & (abs(ptr2d(i,j)).lt.
tol_dp))
THEN
2930 myfmin(1)=min(myfmin(1),ptr2d(i,j))
2931 myfmax(1)=max(myfmax(1),ptr2d(i,j))
2932 fval=scale*ptr2d(i,j)+add_offset
2933 myfmin(2)=min(myfmin(2),fval)
2934 myfmax(2)=max(myfmax(2),fval)
2942 CASE (
'charno',
'Charnock')
2945 IF (abs(ptr2d(i,j)).lt.
tol_dp)
THEN
2946 fval=scale*ptr2d(i,j)+add_offset
2950 myfmin(1)=min(myfmin(1),ptr2d(i,j))
2951 myfmax(1)=max(myfmax(1),ptr2d(i,j))
2952 myfmin(2)=min(myfmin(2),fval)
2953 myfmax(2)=max(myfmax(2),fval)
2954 adom(ng)%charnock(i,j)=fval
2963 IF (abs(ptr2d(i,j)).lt.
tol_dp)
THEN
2964 fval=scale*ptr2d(i,j)+add_offset
2968 myfmin(1)=min(myfmin(1),ptr2d(i,j))
2969 myfmax(1)=max(myfmax(1),ptr2d(i,j))
2970 myfmin(2)=min(myfmin(2),fval)
2971 myfmax(2)=max(myfmax(2),fval)
2972 adom(ng)%wvsu(i,j)=fval
2981 IF (abs(ptr2d(i,j)).lt.
tol_dp)
THEN
2982 fval=scale*ptr2d(i,j)+add_offset
2986 myfmin(1)=min(myfmin(1),ptr2d(i,j))
2987 myfmax(1)=max(myfmax(1),ptr2d(i,j))
2988 myfmin(2)=min(myfmin(2),fval)
2989 myfmax(2)=max(myfmax(2),fval)
2990 adom(ng)%wvsv(i,j)=fval
2999 IF (abs(ptr2d(i,j)).lt.
tol_dp)
THEN
3000 fval=scale*ptr2d(i,j)+add_offset
3004 myfmin(1)=min(myfmin(1),ptr2d(i,j))
3005 myfmax(1)=max(myfmax(1),ptr2d(i,j))
3006 myfmin(2)=min(myfmin(2),fval)
3007 myfmax(2)=max(myfmax(2),fval)
3008 adom(ng)%wvst(i,j)=fval
3015 IF (localpet.eq.0)
THEN
3016 WRITE (
cplout,10) trim(importnamelist(ifld)), &
3019 rc=esmf_rc_not_found
3020 IF (esmf_logfounderror(rctocheck=rc, &
3021 & msg=esmf_logerr_passthru, &
3023 & file=myfile))
THEN
3031 IF (
associated(ptr2d))
nullify (ptr2d)
3036 CALL esmf_vmallreduce (vm, &
3037 & senddata=myfmin, &
3040 & reduceflag=esmf_reduce_min, &
3042 IF (esmf_logfounderror(rctocheck=rc, &
3043 & msg=esmf_logerr_passthru, &
3045 & file=myfile))
THEN
3049 CALL esmf_vmallreduce (vm, &
3050 & senddata=myfmax, &
3053 & reduceflag=esmf_reduce_max, &
3055 IF (esmf_logfounderror(rctocheck=rc, &
3056 & msg=esmf_logerr_passthru, &
3058 & file=myfile))
THEN
3064 IF ((
debuglevel.ge.0).and.(localpet.eq.0))
THEN
3065 WRITE (
cplout,20) trim(importnamelist(ifld)), &
3066 & trim(time_currentstring), ng, &
3068 IF (scale.ne.1.0_dp)
THEN
3069 WRITE (
cplout,30) fmin(2), fmax(2), &
3070 &
' coampsScale = ', scale
3071 ELSE IF (add_offset.ne.0.0_dp)
THEN
3072 WRITE (
cplout,30) fmin(2), fmax(2), &
3073 &
' AddOffset = ', add_offset
3081 WRITE (ofile,40) ng, trim(importnamelist(ifld)), &
3082 & year, month, day, hour, minutes, seconds
3083 CALL esmf_fieldwrite (field, &
3085 & overwrite=.true., &
3087 IF (esmf_logfounderror(rctocheck=rc, &
3088 & msg=esmf_logerr_passthru, &
3090 & file=myfile))
THEN
3099 IF (any(got_sst))
THEN
3101 & got_sst, ifield, fld_name, &
3102 & lbi, ubi, lbj, ubj, &
3103 & ocn_sst, dat_sst, &
3105 IF (esmf_logfounderror(rctocheck=rc, &
3106 & msg=esmf_logerr_passthru, &
3108 & file=myfile))
THEN
3115 IF (
allocated(importnamelist))
deallocate (importnamelist)
3116 IF (
allocated(ocn_sst))
deallocate (ocn_sst)
3117 IF (
allocated(dat_sst))
deallocate (dat_sst)
3121 IF (importcount.gt.0)
THEN
3126 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_Import', &
3132 10
FORMAT (/,2x,
'COAMPS_Import - unable to find option to import: ', &
3133 & a,/,18x,
'check ''Import(atmos)'' in input script: ', a)
3134 20
FORMAT (2x,
'COAMPS_Import - ESMF: importing field ''',a,
'''', &
3135 & t72,a,2x,
'Grid ',i2.2,/, &
3136 & 19x,
'(InpMin = ', 1p,e15.8,0p,
' InpMax = ',1p,e15.8,0p, &
3138 30
FORMAT (19x,
'(OutMin = ', 1p,e15.8,0p,
' OutMax = ',1p,e15.8,0p, &
3139 & 1x,a,1p,e15.8,0p,
')')
3140 40
FORMAT (
'coamps_',i2.2,
'_import_',a,
'_',i4.4,2(
'-',i2.2),
'_', &
3141 & i2.2,2(
'.',i2.2),
'.nc')
3147 & got, ifield, FieldName, &
3148 & LBi, UBi, LBj, UBj, Focn, Fdat, &
3185 USE coamm_memm,
ONLY : adom
3186 USE domdec,
ONLY : iminf, imaxf, jminf, jmaxf, &
3187 & ndom, nlimx, nlimy
3192 logical,
intent(in) :: got(2)
3194 integer,
intent(in) :: ng, ifield(2)
3195 integer,
intent(in) :: lbi, ubi, lbj, ubj
3196 integer,
intent(out) :: rc
3198 real (dp),
intent(in) :: focn(lbi:ubi,lbj:ubj)
3199 real (dp),
intent(in) :: fdat(lbi:ubi,lbj:ubj)
3201 character (len=*),
intent(in) :: fieldname(:)
3203 TYPE (esmf_gridcomp) :: model
3207 logical :: debugwrite(2) = (/ .false., .false. /)
3209 integer :: i, ic, is, j
3210 integer :: year, month, day, hour, minutes, seconds, sn, sd
3211 integer :: seaice, seawater
3212 integer :: localde, localdecount, localpet, petcount
3213 integer :: iminp, imaxp, jminp, jmaxp
3215 real (dp) :: fseconds, timeindays, time_current
3217 real (dp) :: fval, myfmax(3), myfmin(3), fmin(3), fmax(3)
3219 real (dp),
pointer :: ptr2d(:,:) => null()
3221 real (kind(adom(1)%tsea)),
pointer :: fout(:,:) => null()
3223 character (len=22 ) :: time_currentstring
3225 character (len=*),
parameter :: myfile = &
3226 & __FILE__//
", COAMPS_ProcessImport"
3228 character (ESMF_MAXSTR) :: cname, fld_string, ofile
3230 TYPE (esmf_arrayspec) :: arrayspec2d
3231 TYPE (esmf_clock) :: clock
3232 TYPE (esmf_field) :: fmerge
3233 TYPE (esmf_staggerloc) :: staggerloc
3234 TYPE (esmf_time) :: currenttime
3235 TYPE (esmf_vm) :: vm
3242 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_ProcessImport', &
3252 CALL esmf_gridcompget (model, &
3254 & localpet=localpet, &
3255 & petcount=petcount, &
3259 IF (esmf_logfounderror(rctocheck=rc, &
3260 & msg=esmf_logerr_passthru, &
3262 & file=myfile))
THEN
3271 & localdecount=localdecount, &
3273 IF (esmf_logfounderror(rctocheck=rc, &
3274 & msg=esmf_logerr_passthru, &
3276 & file=myfile))
THEN
3282 CALL esmf_clockget (clock, &
3283 & currtime=currenttime, &
3285 IF (esmf_logfounderror(rctocheck=rc, &
3286 & msg=esmf_logerr_passthru, &
3288 & file=myfile))
THEN
3292 CALL esmf_timeget (currenttime, &
3302 IF (esmf_logfounderror(rctocheck=rc, &
3303 & msg=esmf_logerr_passthru, &
3305 & file=myfile))
THEN
3309 CALL esmf_timeget (currenttime, &
3310 & s_r8=time_current, &
3311 & timestring=time_currentstring, &
3313 IF (esmf_logfounderror(rctocheck=rc, &
3314 & msg=esmf_logerr_passthru, &
3316 & file=myfile))
THEN
3319 fseconds=real(seconds,dp)+real(sn,dp)/real(sd,dp)
3320 timeindays=time_current/86400.0_dp
3321 is=index(time_currentstring,
'T')
3322 IF (is.gt.0) time_currentstring(is:is)=
' '
3330 CALL esmf_arrayspecset (arrayspec2d, &
3331 & typekind=esmf_typekind_r8, &
3334 IF (esmf_logfounderror(rctocheck=rc, &
3335 & msg=esmf_logerr_passthru, &
3337 & file=myfile))
THEN
3343 IF (.not.got(2).and.got(1))
THEN
3344 debugwrite(1)=
models(
iatmos)%ImportField(ifield(1))%debug_write
3345 fld_string=trim(fieldname(1))
3346 ELSE IF (.not.got(1).and.got(2))
THEN
3347 debugwrite(2)=
models(
iatmos)%ImportField(ifield(2))%debug_write
3348 fld_string=trim(fieldname(2))
3349 ELSE IF (got(1).and.got(2))
THEN
3350 debugwrite(1)=
models(
iatmos)%ImportField(ifield(1))%debug_write
3351 debugwrite(2)=
models(
iatmos)%ImportField(ifield(2))%debug_write
3352 fld_string=trim(fieldname(1))//
'-'//trim(fieldname(2))
3354 staggerloc=esmf_staggerloc_center
3358 & staggerloc=staggerloc, &
3359 & name=trim(fld_string), &
3361 IF (esmf_logfounderror(rctocheck=rc, &
3362 & msg=esmf_logerr_passthru, &
3364 & file=myfile))
THEN
3370 CALL esmf_fieldget (fmerge, &
3371 & farrayptr=ptr2d, &
3373 IF (esmf_logfounderror(rctocheck=rc, &
3374 & msg=esmf_logerr_passthru, &
3376 & file=myfile))
THEN
3387 SELECT CASE (
lowercase(trim(fld_string)))
3388 CASE (
'sst',
'dsst',
'sst-dsst',
'dsst-sst')
3389 fout => adom(ng)%tsea
3391 IF (localpet.eq.0)
THEN
3394 rc=esmf_rc_not_found
3395 IF (esmf_logfounderror(rctocheck=rc, &
3396 & msg=esmf_logerr_passthru, &
3398 & file=myfile))
THEN
3406 iminp=nlimx(ng)%bp(ndom)
3407 imaxp=nlimx(ng)%ep(ndom)
3408 jminp=nlimy(ng)%bp(ndom)
3409 jmaxp=nlimy(ng)%ep(ndom)
3426 IF (.not.got(2).and.got(1))
THEN
3431 IF (((nint(adom(ng)%xland(i,j)).eq.seawater).or. &
3432 & (nint(adom(ng)%xland(i,j)).eq.seaice)).and. &
3433 & (abs(focn(i,j)).lt.
tol_dp))
THEN
3434 fout(i,j)=real(focn(i,j), kind(adom(ng)%tsea))
3436 ptr2d(i,j)=real(fout(i,j), dp)
3437 myfmin(1)=min(myfmin(1),fout(i,j))
3438 myfmax(1)=max(myfmax(1),fout(i,j))
3441 ELSE IF (.not.got(1).and.got(2))
THEN
3446 IF (((nint(adom(ng)%xland(i,j)).eq.seawater).or. &
3447 & (nint(adom(ng)%xland(i,j)).eq.seaice)).and. &
3448 & (abs(fdat(i,j)).lt.
tol_dp))
THEN
3449 fout(i,j)=real(fdat(i,j), kind(adom(1)%tsea))
3451 ptr2d(i,j)=real(fout(i,j), dp)
3452 myfmin(1)=min(myfmin(1),fout(i,j))
3453 myfmax(1)=max(myfmax(1),fout(i,j))
3462 IF (got(1).and.got(2))
THEN
3475 IF ((nint(adom(ng)%xland(i,j)).eq.seawater).or. &
3476 & (nint(adom(ng)%xland(i,j)).eq.seaice))
THEN
3477 IF (abs(fdat(i,j)).lt.
tol_dp)
THEN
3478 myfmin(2)=min(myfmin(2),fdat(i,j))
3479 myfmax(2)=max(myfmax(2),fdat(i,j))
3481 IF (abs(focn(i,j)).lt.
tol_dp)
THEN
3482 myfmin(1)=min(myfmin(1),focn(i,j))
3483 myfmax(1)=max(myfmax(1),focn(i,j))
3487 fout(i,j)=real(fval, kind(adom(ng)%tsea))
3488 ptr2d(i,j)=real(fval, dp)
3489 myfmin(3)=min(myfmin(3),fval)
3490 myfmax(3)=max(myfmax(3),fval)
3493 ptr2d(i,j)=real(fout(i,j), dp)
3501 IF (got(1).and.got(2))
THEN
3506 CALL esmf_vmallreduce (vm, &
3507 & senddata=myfmin, &
3510 & reduceflag=esmf_reduce_min, &
3512 IF (esmf_logfounderror(rctocheck=rc, &
3513 & msg=esmf_logerr_passthru, &
3515 & file=myfile))
THEN
3519 CALL esmf_vmallreduce (vm, &
3520 & senddata=myfmax, &
3523 & reduceflag=esmf_reduce_max, &
3525 IF (esmf_logfounderror(rctocheck=rc, &
3526 & msg=esmf_logerr_passthru, &
3528 & file=myfile))
THEN
3534 IF (got(1).and.got(2))
THEN
3535 IF ((
debuglevel.ge.0).and.(localpet.eq.0))
THEN
3536 WRITE (
cplout,20) trim(fld_string), &
3537 & trim(time_currentstring), ng, &
3538 & fmin(1), fmax(1), &
3539 & fmin(2), fmax(2), &
3543 IF ((
debuglevel.ge.0).and.(localpet.eq.0))
THEN
3544 WRITE (
cplout,30) fmin(1), fmax(1)
3550 IF ((
debuglevel.ge.3).and.any(debugwrite))
THEN
3551 WRITE (ofile,40) ng, trim(fld_string), &
3552 & year, month, day, hour, minutes, seconds
3553 CALL esmf_fieldwrite (fmerge, &
3555 & overwrite=.true., &
3557 IF (esmf_logfounderror(rctocheck=rc, &
3558 & msg=esmf_logerr_passthru, &
3560 & file=myfile))
THEN
3568 IF (
associated(ptr2d))
nullify (ptr2d)
3569 IF (
associated(fout ))
nullify (fout)
3573 CALL esmf_fielddestroy (fmerge, &
3574 & nogarbage=.false., &
3576 IF (esmf_logfounderror(rctocheck=rc, &
3577 & msg=esmf_logerr_passthru, &
3579 & file=myfile))
THEN
3584 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_ProcessImport', &
3590 10
FORMAT (/,5x,
'COAMPS_ProcessImport - ', &
3591 &
'unable to find option to import: ',a, &
3592 & /,25x,
'check ''Import(atmos)'' in input script: ',a)
3593 20
FORMAT (1x,
' COAMPS_ProcessImport - ESMF merging field ''', &
3594 & a,
'''',t72,a,2x,
'Grid ',i2.2, &
3595 & /,19x,
'(OcnMin = ', 1p,e15.8,0p, &
3596 &
' OcnMax = ', 1p,e15.8,0p,
')', &
3597 & /,19x,
'(DatMin = ', 1p,e15.8,0p, &
3598 &
' DatMax = ', 1p,e15.8,0p,
')', &
3599 & /,19x,
'(OutMin = ', 1p,e15.8,0p, &
3600 &
' OutMax = ', 1p,e15.8,0p,
')')
3601 30
FORMAT (19x,
'(OutMin = ', 1p,e15.8,0p, &
3602 &
' OutMax = ', 1p,e15.8,0p,
') COAMPS_ProcessImport')
3603 40
FORMAT (
'coamps_',i2.2,
'_merged_',a,
'_',i4.4,2(
'-',i2.2),
'_', &
3604 & i2.2,2(
'.',i2.2),
'.nc')
3621 USE avg_mod,
ONLY : avg
3622 USE avg_mod,
ONLY : ifld_airrhm, &
3633 & ifld_stress_u_true, &
3634 & ifld_stress_v_true, &
3639 USE coamm_memm,
ONLY : adom
3640 USE domdec,
ONLY : iminf, imaxf, jminf, jmaxf
3644 integer,
intent(in) :: ng
3645 integer,
intent(out) :: rc
3647 TYPE (esmf_gridcomp) :: model
3651 integer :: ifld, i, is, j
3652 integer :: istr, iend, jstr, jend
3653 integer :: year, month, day, hour, minutes, seconds, sn, sd
3654 integer :: exportcount
3655 integer :: localde, localdecount, localpet, petcount
3657 real (dp),
parameter :: emiss = 0.97_dp
3658 real (dp),
parameter :: stbolt = 5.67051e-8_dp
3659 real (dp),
parameter :: z1 = 3.0_dp
3661 real (dp) :: fseconds, timeindays, time_current
3662 real (dp) :: cff1, cff2, f1, scale
3664 real (dp) :: myfmax(1), myfmin(1), fmin(1), fmax(1), fval
3666 real (dp),
pointer :: ptr2d(:,:) => null()
3668 character (len=22) :: time_currentstring
3670 character (len=*),
parameter :: myfile = &
3671 & __FILE__//
", COAMPS_Export"
3673 character (ESMF_MAXSTR) :: cname, ofile
3674 character (ESMF_MAXSTR),
allocatable :: exportnamelist(:)
3676 TYPE (esmf_clock) :: clock
3677 TYPE (esmf_field) :: field
3678 TYPE (esmf_state) :: exportstate
3679 TYPE (esmf_time) :: currenttime
3680 TYPE (esmf_vm) :: vm
3687 WRITE (
trac,
'(a,a,i0)')
'==> Entering COAMPS_Export', &
3697 CALL esmf_gridcompget (model, &
3698 & exportstate=exportstate, &
3700 & localpet=localpet, &
3701 & petcount=petcount, &
3705 IF (esmf_logfounderror(rctocheck=rc, &
3706 & msg=esmf_logerr_passthru, &
3708 & file=myfile))
THEN
3717 & localdecount=localdecount, &
3719 IF (esmf_logfounderror(rctocheck=rc, &
3720 & msg=esmf_logerr_passthru, &
3722 & file=myfile))
THEN
3730 CALL esmf_clockget (clock, &
3731 & currtime=currenttime, &
3733 IF (esmf_logfounderror(rctocheck=rc, &
3734 & msg=esmf_logerr_passthru, &
3736 & file=myfile))
THEN
3740 CALL esmf_timeget (currenttime, &
3750 IF (esmf_logfounderror(rctocheck=rc, &
3751 & msg=esmf_logerr_passthru, &
3753 & file=myfile))
THEN
3757 CALL esmf_timeget (currenttime, &
3758 & s_r8=time_current, &
3759 & timestring=time_currentstring, &
3761 IF (esmf_logfounderror(rctocheck=rc, &
3762 & msg=esmf_logerr_passthru, &
3764 & file=myfile))
THEN
3767 fseconds=real(seconds,dp)+real(sn,dp)/real(sd,dp)
3768 timeindays=time_current/86400.0_dp
3769 is=index(time_currentstring,
'T')
3770 IF (is.gt.0) time_currentstring(is:is)=
' '
3777 & itemcount=exportcount, &
3779 IF (esmf_logfounderror(rctocheck=rc, &
3780 & msg=esmf_logerr_passthru, &
3782 & file=myfile))
THEN
3786 IF (.not.
allocated(exportnamelist))
THEN
3787 allocate ( exportnamelist(exportcount) )
3790 & itemnamelist=exportnamelist, &
3792 IF (esmf_logfounderror(rctocheck=rc, &
3793 & msg=esmf_logerr_passthru, &
3795 & file=myfile))
THEN
3803 fld_loop :
DO ifld=1,exportcount
3808 & trim(exportnamelist(ifld)), &
3811 IF (esmf_logfounderror(rctocheck=rc, &
3812 & msg=esmf_logerr_passthru, &
3814 & file=myfile))
THEN
3821 de_loop :
DO localde=0,localdecount-1
3822 CALL esmf_fieldget (field, &
3823 & localde=localde, &
3824 & farrayptr=ptr2d, &
3826 IF (esmf_logfounderror(rctocheck=rc, &
3827 & msg=esmf_logerr_passthru, &
3829 & file=myfile))
THEN
3832 istr=lbound(ptr2d,1)
3833 iend=ubound(ptr2d,1)
3834 jstr=lbound(ptr2d,2)
3835 jend=ubound(ptr2d,2)
3846 SELECT CASE (trim(adjustl(exportnamelist(ifld))))
3850 CASE (
'psfc',
'Pair')
3855 fval=avg(ng)%fld(ifld_slpres)%p(i,j)
3856 myfmin(1)=min(myfmin(1),fval)
3857 myfmax(1)=max(myfmax(1),fval)
3864 CASE (
'tsfc',
'Tair')
3869 fval=avg(ng)%fld(ifld_airtmp)%p(i,j)
3870 myfmin(1)=min(myfmin(1),fval)
3871 myfmax(1)=max(myfmax(1),fval)
3883 fval=avg(ng)%fld(ifld_airshm)%p(i,j)
3884 myfmin(1)=min(myfmin(1),fval)
3885 myfmax(1)=max(myfmax(1),fval)
3892 CASE (
'qsfc',
'Qair')
3897 fval=avg(ng)%fld(ifld_airrhm)%p(i,j)
3898 myfmin(1)=min(myfmin(1),fval)
3899 myfmax(1)=max(myfmax(1),fval)
3918 CASE (
'nflx',
'shflux')
3921 f1=1.0_dp-0.27_dp*exp(-2.80_dp*z1)- &
3922 & 0.45_dp*exp(-0.07_dp*z1)
3925 cff1=adom(ng)%tsea(i,j)*adom(ng)%tsea(i,j)* &
3926 & adom(ng)%tsea(i,j)*adom(ng)%tsea(i,j)
3927 cff2=emiss*stbolt*cff1
3928 fval=avg(ng)%fld(ifld_solflx)%p(i,j)*f1+ &
3929 & avg(ng)%fld(ifld_lwdown)%p(i,j)-cff2- &
3930 & avg(ng)%fld(ifld_lahflx)%p(i,j)- &
3931 & avg(ng)%fld(ifld_sehflx)%p(i,j)
3932 myfmin(1)=min(myfmin(1),fval)
3933 myfmax(1)=max(myfmax(1),fval)
3940 CASE (
'lwrd',
'LWrad')
3945 fval=avg(ng)%fld(ifld_lonflx)%p(i,j)
3946 myfmin(1)=min(myfmin(1),fval)
3947 myfmax(1)=max(myfmax(1),fval)
3954 CASE (
'dlwrd',
'dLWrad',
'lwrad_down')
3959 fval=avg(ng)%fld(ifld_lwdown)%p(i,j)
3960 myfmin(1)=min(myfmin(1),fval)
3961 myfmax(1)=max(myfmax(1),fval)
3968 CASE (
'swrd',
'SWrad')
3973 fval=avg(ng)%fld(ifld_solflx)%p(i,j)
3974 myfmin(1)=min(myfmin(1),fval)
3975 myfmax(1)=max(myfmax(1),fval)
3982 CASE (
'dswrd',
'dSWrad')
3987 fval=avg(ng)%fld(ifld_swdown)%p(i,j)
3988 myfmin(1)=min(myfmin(1),fval)
3989 myfmax(1)=max(myfmax(1),fval)
3999 CASE (
'lhfx',
'LHfx')
4004 fval=-avg(ng)%fld(ifld_lahflx)%p(i,j)
4005 myfmin(1)=min(myfmin(1),fval)
4006 myfmax(1)=max(myfmax(1),fval)
4015 CASE (
'shfx',
'SHfx')
4020 fval=-avg(ng)%fld(ifld_sehflx)%p(i,j)
4021 myfmin(1)=min(myfmin(1),fval)
4022 myfmax(1)=max(myfmax(1),fval)
4036 fval=-avg(ng)%fld(ifld_mstflx)%p(i,j)
4037 myfmin(1)=min(myfmin(1),fval)
4038 myfmax(1)=max(myfmax(1),fval)
4052 fval=avg(ng)%fld(ifld_ttlprr)%p(i,j)*scale
4053 myfmin(1)=min(myfmin(1),fval)
4054 myfmax(1)=max(myfmax(1),fval)
4061 CASE (
'taux',
'taux10',
'sustr')
4066 fval=avg(ng)%fld(ifld_stress_u_true)%p(i,j)
4067 myfmin(1)=min(myfmin(1),fval)
4068 myfmax(1)=max(myfmax(1),fval)
4075 CASE (
'tauy',
'tauy10',
'svstr')
4080 fval=avg(ng)%fld(ifld_stress_v_true)%p(i,j)
4081 myfmin(1)=min(myfmin(1),fval)
4082 myfmax(1)=max(myfmax(1),fval)
4089 CASE (
'Uwind',
'u10',
'wndu')
4094 fval=avg(ng)%fld(ifld_u10_true)%p(i,j)
4095 myfmin(1)=min(myfmin(1),fval)
4096 myfmax(1)=max(myfmax(1),fval)
4103 CASE (
'Vwind',
'v10',
'wndv')
4108 fval=avg(ng)%fld(ifld_v10_true)%p(i,j)
4109 myfmin(1)=min(myfmin(1),fval)
4110 myfmax(1)=max(myfmax(1),fval)
4118 IF (localpet.eq.0)
THEN
4119 WRITE (
cplout,10) trim(adjustl(exportnamelist(ifld))), &
4122 rc=esmf_rc_not_found
4123 IF (esmf_logfounderror(rctocheck=rc, &
4124 & msg=esmf_logerr_passthru, &
4126 & file=myfile))
THEN
4134 IF (
associated(ptr2d))
nullify (ptr2d)
4139 CALL esmf_vmallreduce (vm, &
4140 & senddata=myfmin, &
4143 & reduceflag=esmf_reduce_min, &
4145 IF (esmf_logfounderror(rctocheck=rc, &
4146 & msg=esmf_logerr_passthru, &
4148 & file=myfile))
THEN
4152 CALL esmf_vmallreduce (vm, &
4153 & senddata=myfmax, &
4156 & reduceflag=esmf_reduce_max, &
4158 IF (esmf_logfounderror(rctocheck=rc, &
4159 & msg=esmf_logerr_passthru, &
4161 & file=myfile))
THEN
4167 IF ((
debuglevel.ge.0).and.(localpet.eq.0))
THEN
4168 WRITE (
cplout,20) trim(exportnamelist(ifld)), &
4169 & trim(time_currentstring), ng, &
4177 WRITE (ofile,30) ng, trim(exportnamelist(ifld)), &
4178 & year, month, day, hour, minutes, seconds
4179 CALL esmf_fieldwrite (field, &
4181 & overwrite=.true., &
4183 IF (esmf_logfounderror(rctocheck=rc, &
4184 & msg=esmf_logerr_passthru, &
4186 & file=myfile))
THEN
4194 IF (
allocated(exportnamelist))
deallocate(exportnamelist)
4198 IF (exportcount.gt.0)
THEN
4203 WRITE (
trac,
'(a,a,i0)')
'<== Exiting COAMPS_Export', &
4209 10
FORMAT (/,2x,
'COAMPS_Export - unable to find option to export: ', &
4210 & a,/,18x,
'check ''Export(atmos)'' in input script: ',a)
4211 20
FORMAT (2x,
'COAMPS_Export - ESMF: exporting field ''',a,
'''', &
4212 & t72,a,2x,
'Grid ',i2.2,/, &
4213 & 19x,
'(OutMin = ', 1p,e15.8,0p,
' OutMax = ',1p,e15.8,0p, &
4215 30
FORMAT (
'coamps_',i2.2,
'_export_',a,
'_',i4.4,2(
'-',i2.2),
'_', &
4216 & i2.2,2(
'.',i2.2),
'.nc')