107  CHARACTER(LEN=3) :: donst
   108  INTEGER :: idim, jdim, lsoil, lugb, iy, im, id, ih, ialb
   109  INTEGER :: isot, ivegsrc, lensfc, zsea1_mm, zsea2_mm, ierr
   110  INTEGER :: nprocs, myrank, num_threads, 
num_parthds, max_tasks
   111  REAL    :: fh, deltsfc, zsea1, zsea2
   112  LOGICAL :: use_ufo, do_nsst, do_lndinc, do_sfccycle, frac_grid
   114  NAMELIST/namcyc/ idim,jdim,lsoil,lugb,iy,im,id,ih,fh,&
   115                   deltsfc,ialb,use_ufo,donst,             &
   116                   do_sfccycle,isot,ivegsrc,zsea1_mm,      &
   117                   zsea2_mm, max_tasks, do_lndinc, frac_grid
   119  DATA idim,jdim,lsoil/96,96,4/
   120  DATA iy,im,id,ih,fh/1997,8,2,0,0./
   121  DATA lugb/51/, deltsfc/0.0/, ialb/1/, max_tasks/99999/
   122  DATA isot/1/, ivegsrc/2/, zsea1_mm/0/, zsea2_mm/0/
   125  CALL mpi_comm_size(mpi_comm_world, nprocs, ierr)
   126  CALL mpi_comm_rank(mpi_comm_world, myrank, ierr)
   128  if (myrank==0) 
call w3tagb(
'GLOBAL_CYCLE',2018,0179,0055,
'NP20')
   133  print*,
"STARTING CYCLE PROGRAM ON RANK ", myrank
   134  print*,
"RUNNING WITH ", nprocs, 
"TASKS"   135  print*,
"AND WITH ", num_threads, 
" THREADS."   144  print*,
"READ NAMCYC NAMELIST."   146  CALL baopenr(36, 
"fort.36", ierr)
   150  IF (max_tasks < 99999 .AND. myrank > (max_tasks - 1)) 
THEN   151    print*,
"USER SPECIFIED MAX NUMBER OF TASKS: ", max_tasks
   152    print*,
"WILL NOT RUN CYCLE PROGRAM ON RANK: ", myrank
   158  zsea1 = float(zsea1_mm) / 1000.0  
   159  zsea2 = float(zsea2_mm) / 1000.0
   161  IF (donst == 
"YES") 
THEN   168  IF (myrank==0) print*,
"LUGB,IDIM,JDIM,ISOT,IVEGSRC,LSOIL,DELTSFC,IY,IM,ID,IH,FH: ", &
   169               lugb,idim,jdim,isot,ivegsrc,lsoil,deltsfc,iy,im,id,ih,fh
   171  CALL sfcdrv(lugb,idim,jdim,lensfc,lsoil,deltsfc,  &
   172              iy,im,id,ih,fh,ialb,                  &
   173              use_ufo,do_nsst,do_sfccycle,do_lndinc, &
   174              frac_grid,zsea1,zsea2,isot,ivegsrc,myrank)
   177  print*,
'CYCLE PROGRAM COMPLETED NORMALLY ON RANK: ', myrank
   181  CALL mpi_barrier(mpi_comm_world, ierr)
   183  if (myrank==0) 
call w3tage(
'GLOBAL_CYCLE')
   185  CALL mpi_finalize(ierr)
   299  SUBROUTINE sfcdrv(LUGB, IDIM,JDIM,LENSFC,LSOIL,DELTSFC,  &
   300                    IY,IM,ID,IH,FH,IALB,                  &
   301                    USE_UFO,DO_NSST,DO_SFCCYCLE,DO_LNDINC,&
   302                    FRAC_GRID,ZSEA1,ZSEA2,ISOT,IVEGSRC,MYRANK)
   307  USE land_increments, 
ONLY: add_increment_soil,     &
   308                             add_increment_snow,     &
   309                             calculate_landinc_mask, &
   310                             apply_land_da_adjustments_soil, &
   311                             apply_land_da_adjustments_snd, &
   316  INTEGER, 
INTENT(IN) :: IDIM, JDIM, LENSFC, LSOIL, IALB
   317  INTEGER, 
INTENT(IN) :: LUGB, IY, IM, ID, IH
   318  INTEGER, 
INTENT(IN) :: ISOT, IVEGSRC, MYRANK
   320  LOGICAL, 
INTENT(IN) :: USE_UFO, DO_NSST,DO_SFCCYCLE
   321  LOGICAL, 
INTENT(IN) :: DO_LNDINC, FRAC_GRID
   323  REAL, 
INTENT(IN)    :: FH, DELTSFC, ZSEA1, ZSEA2
   325  INTEGER, 
PARAMETER  :: NLUNIT=35
   326  INTEGER, 
PARAMETER  :: SZ_NML=1
   328  CHARACTER(LEN=5)    :: TILE_NUM
   329  CHARACTER(LEN=500)  :: NST_FILE
   330  CHARACTER(LEN=500)  :: LND_SOI_FILE
   331  CHARACTER(LEN=4)    :: INPUT_NML_FILE(SZ_NML)
   334  INTEGER             :: I_INDEX(LENSFC), J_INDEX(LENSFC)
   335  INTEGER             :: IDUM(IDIM,JDIM)
   336  integer             :: num_parthds, num_threads
   341  real(kind=kind_io8) :: min_ice(lensfc)
   343  REAL                :: SLMASK(LENSFC), OROG(LENSFC)
   344  REAL                :: SIHFCS(LENSFC), SICFCS(LENSFC)
   345  REAL                :: SITFCS(LENSFC), TSFFCS(LENSFC)
   346  REAL                :: SWEFCS(LENSFC), ZORFCS(LENSFC)
   347  REAL                :: ALBFCS(LENSFC,4), TG3FCS(LENSFC)
   348  REAL                :: CNPFCS(LENSFC), SMCFCS(LENSFC,LSOIL)
   349  REAL                :: STCFCS(LENSFC,LSOIL), SLIFCS(LENSFC)
   350  REAL                :: AISFCS(LENSFC), F10M(LENSFC)
   351  REAL                :: VEGFCS(LENSFC), VETFCS(LENSFC)
   352  REAL                :: SOTFCS(LENSFC), ALFFCS(LENSFC,2)
   353  REAL                :: CVFCS(LENSFC), CVTFCS(LENSFC)
   354  REAL                :: CVBFCS(LENSFC), TPRCP(LENSFC)
   355  REAL                :: SRFLAG(LENSFC), SNDFCS(LENSFC)
   356  REAL                :: SLCFCS(LENSFC,LSOIL), VMXFCS(LENSFC)
   357  REAL                :: VMNFCS(LENSFC), T2M(LENSFC)
   358  REAL                :: Q2M(LENSFC), SLPFCS(LENSFC)
   359  REAL                :: ABSFCS(LENSFC), OROG_UF(LENSFC)
   360  REAL                :: USTAR(LENSFC)
   361  REAL                :: FMM(LENSFC), FHH(LENSFC)
   362  REAL                :: RLA(LENSFC), RLO(LENSFC)
   363  REAL(KIND=4)        :: ZSOIL(LSOIL)
   364  REAL                :: SIG1T(LENSFC)
   367  REAL, 
ALLOCATABLE   :: STC_BCK(:,:), SMC_BCK(:,:), SLC_BCK(:,:)
   368  REAL, 
ALLOCATABLE   :: SLIFCS_FG(:), SICFCS_FG(:)
   369  INTEGER, 
ALLOCATABLE :: LANDINC_MASK_FG(:), LANDINC_MASK(:)
   370  REAL, 
ALLOCATABLE   :: SND_BCK(:), SND_INC(:), SWE_BCK(:)
   371  REAL(KIND=KIND_IO8), 
ALLOCATABLE :: SLMASKL(:), SLMASKW(:), LANDFRAC(:)
   373  TYPE(NSST_DATA)     :: NSST
   374  real, 
dimension(idim,jdim) :: tf_clm,tf_trd,sal_clm
   375  real, 
dimension(lensfc)    :: tf_clm_tile,tf_trd_tile,sal_clm_tile
   376  INTEGER             :: veg_type_landice
   377  INTEGER, 
DIMENSION(LENSFC) :: STC_UPDATED, SLC_UPDATED
   379  LOGICAL :: FILE_EXISTS, DO_SOI_INC, DO_SNO_INC
   380  CHARACTER(LEN=3)       :: RANKCH
   387  NAMELIST/namsfcd/ nst_file, lnd_soi_file, do_sno_inc
   389  DATA nst_file/
'NULL'/
   390  DATA lnd_soi_file/
'NULL'/
   397  input_nml_file = 
"NULL"   399  CALL baopenr(37, 
"fort.37", ierr)
   400  READ (37, nml=namsfcd)
   403  print*,
'IN ROUTINE SFCDRV,IDIM=',idim,
'JDIM=',jdim,
'FH=',fh
   409  ALLOCATE(landfrac(lensfc))
   411    print*,
'- RUNNING WITH FRACTIONAL GRID.'   412    CALL read_lat_lon_orog(rla,rlo,orog,orog_uf,tile_num,idim,jdim,lensfc,landfrac=landfrac)
   422  i_index = reshape(idum, (/lensfc/))
   428  j_index = reshape(idum, (/lensfc/) )
   432    print*,
"WILL PROCESS NSST RECORDS."   433    ALLOCATE(nsst%C_0(lensfc))
   434    ALLOCATE(nsst%C_D(lensfc))
   435    ALLOCATE(nsst%D_CONV(lensfc))
   436    ALLOCATE(nsst%DT_COOL(lensfc))
   437    ALLOCATE(nsst%IFD(lensfc))
   438    ALLOCATE(nsst%QRAIN(lensfc))
   439    ALLOCATE(nsst%TREF(lensfc))
   440    ALLOCATE(nsst%TFINC(lensfc))
   441    ALLOCATE(nsst%W_0(lensfc))
   442    ALLOCATE(nsst%W_D(lensfc))
   443    ALLOCATE(nsst%XS(lensfc))
   444    ALLOCATE(nsst%XT(lensfc))
   445    ALLOCATE(nsst%XTTS(lensfc))
   446    ALLOCATE(nsst%XU(lensfc))
   447    ALLOCATE(nsst%XV(lensfc))
   448    ALLOCATE(nsst%XZ(lensfc))
   449    ALLOCATE(nsst%XZTS(lensfc))
   450    ALLOCATE(nsst%Z_C(lensfc))
   451    ALLOCATE(nsst%ZM(lensfc))
   452    ALLOCATE(slifcs_fg(lensfc))
   453    ALLOCATE(sicfcs_fg(lensfc))
   458    IF  (trim(lnd_soi_file) .NE. 
"NULL") 
THEN   461        print*,
" APPLYING SOIL INCREMENTS FROM THE GSI"   462        ALLOCATE(stc_bck(lensfc, lsoil), smc_bck(lensfc, lsoil), slc_bck(lensfc,lsoil))
   463        ALLOCATE(landinc_mask_fg(lensfc))
   471        print*,
" APPLYING SNOW INCREMENTS FROM JEDI"   472        ALLOCATE(snd_bck(lensfc), snd_inc(lensfc), swe_bck(lensfc))
   475    ALLOCATE(landinc_mask(lensfc))
   476    if (ivegsrc == 2) 
then      487  CALL read_data(lsoil,lensfc,do_nsst,.false.,is_noahmp=is_noahmp, &
   488                 tsffcs=tsffcs,smcfcs=smcfcs,   &
   489                 swefcs=swefcs,stcfcs=stcfcs,tg3fcs=tg3fcs,zorfcs=zorfcs,  &
   490                 cvfcs=cvfcs,  cvbfcs=cvbfcs,cvtfcs=cvtfcs,albfcs=albfcs,  &
   491                 vegfcs=vegfcs,slifcs=slifcs,cnpfcs=cnpfcs,f10m=f10m    ,  &
   492                 vetfcs=vetfcs,sotfcs=sotfcs,alffcs=alffcs,ustar=ustar  ,  &
   493                 fmm=fmm      ,fhh=fhh      ,sihfcs=sihfcs,sicfcs=sicfcs,  &
   494                 sitfcs=sitfcs,tprcp=tprcp  ,srflag=srflag,sndfcs=sndfcs,  &
   495                 vmnfcs=vmnfcs,vmxfcs=vmxfcs,slcfcs=slcfcs,slpfcs=slpfcs,  &
   496                 absfcs=absfcs,t2m=t2m      ,q2m=q2m      ,slmask=slmask,  &
   497                 zsoil=zsoil,   nsst=nsst)
   499  IF (frac_grid .AND. .NOT. is_noahmp) 
THEN   500    print *, 
'FATAL ERROR: NOAH lsm update does not work with fractional grids.'   501    call mpi_abort(mpi_comm_world, 18, ierr)
   504  IF (is_noahmp .AND. do_sno_inc) 
THEN   505    print *, 
'FATAL ERROR: Snow increment update does not work with NOAH_MP.'   506    call mpi_abort(mpi_comm_world, 29, ierr)
   517    print*,
'USE UNFILTERED OROGRAPHY.'   524    IF(nint(slifcs(i)).EQ.2) aisfcs(i) = 1.
   529    IF (.NOT. do_sfccycle ) 
THEN   531      print*,
"FIRST GUESS MASK ADJUSTED BY IFD RECORD"   533      WHERE(nint(nsst%IFD) == 3) slifcs_fg = 2.0
   536      print*,
"SAVE FIRST GUESS MASK"   543     CALL calculate_landinc_mask(smcfcs(:,1),swefcs, vetfcs,  &
   544                     lensfc,veg_type_landice,  landinc_mask)
   554  IF (do_sfccycle) 
THEN   555    ALLOCATE(slmaskl(lensfc), slmaskw(lensfc))
   557    set_mask : 
IF (frac_grid) 
THEN   560        IF(landfrac(i) > 0.0_kind_io8) 
THEN   561          slmaskl(i) = ceiling(landfrac(i)-1.0e-6_kind_io8)
   562          slmaskw(i) =   floor(landfrac(i)+1.0e-6_kind_io8)
   564          IF(nint(slmask(i)) == 1) 
THEN    566            print*, 
'FATAL ERROR: LAND FRAC AND SLMASK MISMATCH.'   567            CALL mpi_abort(mpi_comm_world, 27, ierr)
   569            slmaskl(i) = 0.0_kind_io8
   570            slmaskw(i) = 0.0_kind_io8
   581        IF(nint(slmask(i)) == 1) 
THEN   582          slmaskl(i) = 1.0_kind_io8
   583          slmaskw(i) = 1.0_kind_io8
   585          slmaskl(i) = 0.0_kind_io8
   586          slmaskw(i) = 0.0_kind_io8
   593      if(nint(slmask(i)) == 0) 
then   594        min_ice(i) = 0.15_kind_io8
   596        min_ice(i) = 0.0_kind_io8
   600    num_threads = num_parthds()
   602    print*,
"CALL SFCCYCLE TO UPDATE SURFACE FIELDS."   603    CALL sfccycle(lugb,lensfc,lsoil,sig1t,deltsfc,          &
   604                iy,im,id,ih,fh,rla,rlo,                   &
   605                slmaskl,slmaskw, orog, orog_uf, use_ufo, do_nsst,   &
   606                sihfcs,sicfcs,sitfcs,sndfcs,slcfcs,       &
   607                vmnfcs,vmxfcs,slpfcs,absfcs,              &
   608                tsffcs,swefcs,zorfcs,albfcs,tg3fcs,       &
   609                cnpfcs,smcfcs,stcfcs,slifcs,aisfcs,       &
   610                vegfcs,vetfcs,sotfcs,alffcs,              &
   611                cvfcs,cvbfcs,cvtfcs,myrank,num_threads, nlunit,        &
   612                sz_nml, input_nml_file,                   &
   614                ialb,isot,ivegsrc,tile_num,i_index,j_index)
   616    DEALLOCATE(slmaskl, slmaskw)
   626    IF (nst_file == 
"NULL") 
THEN   628      print*,
"NO GSI FILE.  ADJUST IFD FOR FORMER ICE POINTS."   630        IF (sicfcs_fg(i) > 0.0 .AND. sicfcs(i) == 0) 
THEN   637      print*,
"ADJUST TREF FROM GSI INCREMENT"   641      call get_tf_clm(rla,rlo,jdim,idim,iy,im,id,ih,tf_clm,tf_trd)
   642      tf_clm_tile(:) = reshape(tf_clm, (/lensfc/) )
   643      tf_trd_tile(:) = reshape(tf_trd, (/lensfc/) )
   647      call get_sal_clm(rla,rlo,jdim,idim,iy,im,id,ih,sal_clm)
   648      sal_clm_tile(:) = reshape(sal_clm, (/lensfc/) )
   656      CALL adjust_nsst(rla,rlo,slifcs,slifcs_fg,tsffcs,sitfcs,sicfcs,sicfcs_fg,&
   657                     stcfcs,nsst,lensfc,lsoil,idim,jdim,zsea1,zsea2, &
   658                     tf_clm_tile,tf_trd_tile,sal_clm_tile,landfrac,frac_grid)
   680        CALL read_data(lsoil,lensfc,.false.,.true.,sndfcs=snd_inc)
   690        CALL add_increment_snow(snd_inc,landinc_mask,lensfc,sndfcs)
   696        CALL apply_land_da_adjustments_snd(lsm, lensfc, landinc_mask, swe_bck, snd_bck, &
   708         landinc_mask_fg = landinc_mask
   710         IF (do_sfccycle .OR. do_sno_inc)  
THEN   711             CALL calculate_landinc_mask(smcfcs(:,1),swefcs, vetfcs, lensfc, &
   712                                                         veg_type_landice, landinc_mask )
   719         WRITE(rankch, 
'(I3.3)') (myrank+1)
   721         lnd_soi_file = trim(lnd_soi_file) // 
"." //  rankch
   723         INQUIRE(file=trim(lnd_soi_file), exist=file_exists)
   724         IF (.not. file_exists) 
then   725             print *, 
'FATAL ERROR: land increment update requested, but file does not exist: ', &
   727             call mpi_abort(mpi_comm_world, 10, ierr)
   746         CALL add_increment_soil(rla,rlo,stcfcs,smcfcs,slcfcs,stc_updated, slc_updated, &
   747                 landinc_mask,landinc_mask_fg,lensfc,lsoil,idim,jdim,lsm,myrank)
   754         CALL apply_land_da_adjustments_soil(lsm, isot, ivegsrc,lensfc, lsoil, &
   755             sotfcs, landinc_mask_fg, stc_bck, stcfcs, smcfcs, slcfcs, stc_updated, &
   765    IF(
ALLOCATED(landinc_mask_fg)) 
DEALLOCATE(landinc_mask_fg)
   766    IF(
ALLOCATED(landinc_mask)) 
DEALLOCATE(landinc_mask)
   767    IF(
ALLOCATED(stc_bck)) 
DEALLOCATE(stc_bck)
   768    IF(
ALLOCATED(smc_bck)) 
DEALLOCATE(smc_bck)
   769    IF(
ALLOCATED(slc_bck)) 
DEALLOCATE(slc_bck)
   770    IF(
ALLOCATED(snd_bck)) 
DEALLOCATE(snd_bck)
   771    IF(
ALLOCATED(swe_bck)) 
DEALLOCATE(swe_bck)
   772    IF(
ALLOCATED(snd_inc)) 
DEALLOCATE(snd_inc)
   779  IF (lsm==lsm_noahmp) 
THEN   781    CALL write_data(lensfc,idim,jdim,lsoil,do_nsst,nsst,vegfcs=vegfcs, &
   782                    slcfcs=slcfcs,smcfcs=smcfcs,stcfcs=stcfcs,&
   783                    sicfcs=sicfcs,sihfcs=sihfcs)
   785  ELSEIF (lsm==lsm_noah) 
THEN   788                    do_nsst,nsst,slifcs=slifcs,tsffcs=tsffcs,vegfcs=vegfcs, &
   789                    swefcs=swefcs,tg3fcs=tg3fcs,zorfcs=zorfcs, &
   790                    albfcs=albfcs,alffcs=alffcs,cnpfcs=cnpfcs, &
   791                    f10m=f10m,t2m=t2m,q2m=q2m,vetfcs=vetfcs, &
   792                    sotfcs=sotfcs,ustar=ustar,fmm=fmm,fhh=fhh, &
   793                    sicfcs=sicfcs,sihfcs=sihfcs,sitfcs=sitfcs,tprcp=tprcp, &
   794                    srflag=srflag,swdfcs=sndfcs,vmnfcs=vmnfcs, &
   795                    vmxfcs=vmxfcs,slpfcs=slpfcs,absfcs=absfcs, &
   796                    slcfcs=slcfcs,smcfcs=smcfcs,stcfcs=stcfcs)
   803    DEALLOCATE(nsst%D_CONV)
   804    DEALLOCATE(nsst%DT_COOL)
   806    DEALLOCATE(nsst%QRAIN)
   807    DEALLOCATE(nsst%TREF)
   808    DEALLOCATE(nsst%TFINC)
   813    DEALLOCATE(nsst%XTTS)
   817    DEALLOCATE(nsst%XZTS)
   820    DEALLOCATE(slifcs_fg)
   821    DEALLOCATE(sicfcs_fg)
   859  SUBROUTINE adjust_nsst(RLA,RLO,SLMSK_TILE,SLMSK_FG_TILE,SKINT_TILE,&
   860                         SICET_TILE,sice_tile,sice_fg_tile,SOILT_TILE,NSST, &
   861                         LENSFC,LSOIL,IDIM,JDIM,ZSEA1,ZSEA2, &
   862                         tf_clm_tile,tf_trd_tile,sal_clm_tile,LANDFRAC, &
   875  INTEGER, 
INTENT(IN)      :: LENSFC, LSOIL, IDIM, JDIM
   877  LOGICAL, 
INTENT(IN)      :: FRAC_GRID
   879  REAL, 
INTENT(IN)         :: SLMSK_TILE(LENSFC), SLMSK_FG_TILE(LENSFC), LANDFRAC(LENSFC)
   880  real, 
intent(in)         :: tf_clm_tile(lensfc),tf_trd_tile(lensfc),sal_clm_tile(lensfc)
   881  REAL, 
INTENT(IN)         :: ZSEA1, ZSEA2,sice_tile(lensfc),sice_fg_tile(lensfc)
   882  REAL, 
INTENT(IN)         :: RLA(LENSFC), RLO(LENSFC)
   883  REAL, 
INTENT(INOUT)      :: SKINT_TILE(LENSFC)
   884  REAL, 
INTENT(INOUT)      :: SICET_TILE(LENSFC),SOILT_TILE(LENSFC,LSOIL)
   886  TYPE(NSST_DATA)          :: NSST
   888  REAL, 
PARAMETER          :: TMAX=313.0,tzero=273.16
   890  INTEGER                  :: IOPT, NRET, KGDS_GAUS(200)
   891  INTEGER                  :: IGAUS, JGAUS, IJ, II, JJ, III, JJJ, KRAD
   892  INTEGER                  :: ISTART, IEND, JSTART, JEND
   894  INTEGER,
allocatable      :: MASK_TILE(:),MASK_FG_TILE(:)
   895  INTEGER                  :: ITILE, JTILE
   896  INTEGER                  :: MAX_SEARCH, J, IERR
   897  INTEGER                  :: IGAUSP1, JGAUSP1
   898  integer                  :: nintp,nsearched,nice,nland
   899  integer                  :: nfill,nfill_tice,nfill_clm
   900  integer                  :: nset_thaw,nset_thaw_s,nset_thaw_i,nset_thaw_c
   902  INTEGER, 
ALLOCATABLE     :: ID1(:,:), ID2(:,:), JDC(:,:)
   907  REAL                     :: TREF_SAVE,WSUM,tf_ice,tf_thaw
   908  REAL                     :: FILL, DTZM, GAUS_RES_KM, DTREF
   909  REAL, 
ALLOCATABLE        :: XPTS(:), YPTS(:), LATS(:), LONS(:)
   910  REAL, 
ALLOCATABLE        :: DUM2D(:,:), LATS_RAD(:), LONS_RAD(:)
   911  REAL, 
ALLOCATABLE        :: AGRID(:,:,:), S2C(:,:,:)
   920  kgds_gaus(7)  = -90000     
   921  kgds_gaus(8)  = nint(-360000./float(
idim_gaus))  
   922  kgds_gaus(9)  = nint((360.0 / float(
idim_gaus))*1000.0)
   929  print*,
'ADJUST NSST USING GSI INCREMENTS ON GAUSSIAN GRID'   949    print*,
'FATAL ERROR: PROBLEM IN GDSWZD. STOP.'   950    CALL mpi_abort(mpi_comm_world, 12, ierr)
   953  DEALLOCATE (xpts, ypts)
   961    lats_rad(j) = dum2d(1,
jdim_gaus-j+1) * 3.1415926 / 180.0
   967  lons_rad = dum2d(:,1) * 3.1415926 / 180.0
   971  ALLOCATE(agrid(idim,jdim,2))
   972  agrid(:,:,1) = reshape(rlo, (/idim,jdim/) )
   973  agrid(:,:,2) = reshape(rla, (/idim,jdim/) )
   974  agrid        = agrid * 3.1415926 / 180.0
   976  ALLOCATE(id1(idim,jdim))
   977  ALLOCATE(id2(idim,jdim))
   978  ALLOCATE(jdc(idim,jdim))
   979  ALLOCATE(s2c(idim,jdim,4))
   988                   lons_rad, lats_rad, id1, id2, jdc, s2c, agrid )
   990  DEALLOCATE(lons_rad, lats_rad, agrid)
   998  max_search  = ceiling(500.0/gaus_res_km)
  1001  print*,
'MAXIMUM SEARCH IS ',max_search, 
' GAUSSIAN POINTS.'  1024  allocate(mask_tile(lensfc))
  1025  allocate(mask_fg_tile(lensfc))
  1027  IF(.NOT. frac_grid) 
THEN  1028    mask_tile    = nint(slmsk_tile)
  1029    mask_fg_tile = nint(slmsk_fg_tile)
  1032    WHERE(sice_tile > 0.0) mask_tile=2
  1033    WHERE(landfrac == 1.0) mask_tile=1
  1035    WHERE(sice_fg_tile > 0.0) mask_fg_tile=2
  1036    WHERE(landfrac == 1.0) mask_fg_tile=1
  1039  ij_loop : 
DO ij = 1, lensfc
  1044    tf_ice = tfreez(sal_clm_tile(ij)) + tzero
  1049    IF (mask_tile(ij) == 1) 
THEN  1057    if (mask_tile(ij) == 2) 
then  1058      nsst%tref(ij)=tf_ice      
  1059      skint_tile(ij)=(1.0-sice_tile(ij))*nsst%tref(ij)+sice_tile(ij)*sicet_tile(ij)
  1067    jtile = (ij-1) / idim + 1
  1068    itile = mod(ij,idim)
  1069    IF (itile==0) itile = idim
  1077    IF (mask_fg_tile(ij) == 2 .AND. mask_tile(ij) == 0) 
THEN  1081      call tf_thaw_set(nsst%tref,mask_fg_tile,itile,jtile,tf_ice,tf_clm_tile(ij),tf_thaw,idim,jdim, &
  1082                       nset_thaw_s,nset_thaw_i,nset_thaw_c)
  1084      nset_thaw = nset_thaw + 1
  1100    igaus   = id1(itile,jtile)
  1101    jgaus   = jdc(itile,jtile)
  1102    igausp1 = id2(itile,jtile)
  1103    jgausp1 = jdc(itile,jtile)+1
  1114        dtref = dtref + (s2c(itile,jtile,1) * 
dtref_gaus(igaus,jgaus))
  1115        wsum  = wsum + s2c(itile,jtile,1)
  1119        dtref = dtref + (s2c(itile,jtile,2) * 
dtref_gaus(igausp1,jgaus))
  1120        wsum  = wsum + s2c(itile,jtile,2)
  1124        dtref = dtref + (s2c(itile,jtile,3) * 
dtref_gaus(igausp1,jgausp1))
  1125        wsum  = wsum + s2c(itile,jtile,3)
  1129        dtref = dtref + (s2c(itile,jtile,4) * 
dtref_gaus(igaus,jgausp1))
  1130        wsum  = wsum + s2c(itile,jtile,4)
  1134      dtref = dtref / wsum
  1136      tref_save      = nsst%TREF(ij)
  1137      nsst%TREF(ij)  = nsst%TREF(ij) + dtref
  1138      nsst%TREF(ij)  = max(nsst%TREF(ij), tf_ice)
  1139      nsst%TREF(ij)  = min(nsst%TREF(ij), tmax)
  1140      nsst%TFINC(ij) = nsst%TREF(ij) - tref_save
  1142      CALL dtzm_point(nsst%XT(ij),nsst%XZ(ij),nsst%DT_COOL(ij),  &
  1143                      nsst%Z_C(ij),zsea1,zsea2,dtzm)
  1145      skint_tile(ij) = nsst%TREF(ij) + dtzm
  1146      skint_tile(ij) = max(skint_tile(ij), tf_ice)
  1147      skint_tile(ij) = min(skint_tile(ij), tmax)
  1149      sicet_tile(ij)   = skint_tile(ij)
  1152      IF(.NOT. frac_grid) soilt_tile(ij,:) = skint_tile(ij)
  1163      DO krad = 1, max_search
  1165        istart = igaus - krad
  1167        jstart = jgaus - krad
  1170        DO jj = jstart, jend
  1171        DO ii = istart, iend
  1173          IF((jj == jstart) .OR. (jj == jend) .OR.   &
  1174             (ii == istart) .OR. (ii == iend))  
THEN  1176            IF ((jj >= 1) .AND. (jj <= 
jdim_gaus)) 
THEN  1193              IF (krad <= 2 .AND. 
slmsk_gaus(iii,jjj) == 2) is_ice = .true.
  1199                nsearched = nsearched + 1
  1201                tref_save      = nsst%TREF(ij)
  1202                nsst%TREF(ij ) = nsst%TREF(ij) + 
dtref_gaus(iii,jjj)
  1203                nsst%TREF(ij)  = max(nsst%TREF(ij), tf_ice)
  1204                nsst%TREF(ij)  = min(nsst%TREF(ij), tmax)
  1205                nsst%TFINC(ij) = nsst%TREF(ij) - tref_save
  1207                CALL dtzm_point(nsst%XT(ij),nsst%XZ(ij),nsst%DT_COOL(ij),  &
  1208                      nsst%Z_C(ij),zsea1,zsea2,dtzm)
  1210                skint_tile(ij) = nsst%TREF(ij) + dtzm
  1211                skint_tile(ij) = max(skint_tile(ij), tf_ice)
  1212                skint_tile(ij) = min(skint_tile(ij), tmax)
  1214                sicet_tile(ij)   = skint_tile(ij)
  1215                IF(.NOT. frac_grid) soilt_tile(ij,:) = skint_tile(ij)
  1238        nsst%TREF(ij) = tf_ice
  1240        nfill_tice = nfill_tice + 1
  1242        tref_save      = nsst%TREF(ij)
  1243        nsst%TREF(ij)  = nsst%TREF(ij) + tf_trd_tile(ij)
  1244        nsst%TREF(ij)  = max(nsst%TREF(ij), tf_ice)
  1245        nsst%TREF(ij)  = min(nsst%TREF(ij), tmax)
  1246        nsst%TFINC(ij) = nsst%TREF(ij) - tref_save
  1248        nfill_clm = nfill_clm + 1
  1251      CALL dtzm_point(nsst%XT(ij),nsst%XZ(ij),nsst%DT_COOL(ij),  &
  1252                      nsst%Z_C(ij),zsea1,zsea2,dtzm)
  1254      skint_tile(ij) = nsst%TREF(ij) + dtzm
  1255      skint_tile(ij) = max(skint_tile(ij), tf_ice)
  1256      skint_tile(ij) = min(skint_tile(ij), tmax)
  1258      sicet_tile(ij)   = skint_tile(ij)
  1259      IF (.NOT. frac_grid) soilt_tile(ij,:) = skint_tile(ij)
  1265  write(*,
'(a)') 
'statistics of grids number processed for tile : '  1266  write(*,
'(a,I8)') 
' nintp = ',nintp
  1267  write(*,
'(a,4I8)') 
'nset_thaw,nset_thaw_s,nset_thaw_i,nset_thaw_c =',nset_thaw,nset_thaw_s,nset_thaw_i,nset_thaw_c
  1268  write(*,
'(a,I8)') 
' nsearched = ',nsearched
  1269  write(*,
'(a,3I6)') 
' nfill,nfill_tice,nfill_clm = ',nfill,nfill_tice,nfill_clm
  1270  write(*,
'(a,I8)') 
' nice = ',nice
  1271  write(*,
'(a,I8)') 
' nland = ',nland
  1273  DEALLOCATE(id1, id2, jdc, s2c, mask_tile, mask_fg_tile)
  1287  SUBROUTINE climo_trend(LATITUDE, MON, DAY, DELTSFC, DTREF)
  1290  INTEGER, 
INTENT(IN)    :: MON, DAY
  1292  REAL, 
INTENT(IN)       :: LATITUDE, DELTSFC
  1293  REAL, 
INTENT(OUT)      :: DTREF
  1295  INTEGER                :: NUM_DAYS(12), MON2, MON1
  1297  REAL, 
TARGET           :: SST_80_90(12)
  1298  REAL, 
TARGET           :: SST_70_80(12)
  1299  REAL, 
TARGET           :: SST_60_70(12)
  1300  REAL, 
TARGET           :: SST_50_60(12)
  1301  REAL, 
TARGET           :: SST_40_50(12)
  1302  REAL, 
TARGET           :: SST_30_40(12)
  1303  REAL, 
TARGET           :: SST_20_30(12)
  1304  REAL, 
TARGET           :: SST_10_20(12)
  1305  REAL, 
TARGET           :: SST_00_10(12)
  1306  REAL, 
TARGET           :: SST_M10_00(12)
  1307  REAL, 
TARGET           :: SST_M20_M10(12)
  1308  REAL, 
TARGET           :: SST_M30_M20(12)
  1309  REAL, 
TARGET           :: SST_M40_M30(12)
  1310  REAL, 
TARGET           :: SST_M50_M40(12)
  1311  REAL, 
TARGET           :: SST_M60_M50(12)
  1312  REAL, 
TARGET           :: SST_M70_M60(12)
  1313  REAL, 
TARGET           :: SST_M80_M70(12)
  1314  REAL, 
TARGET           :: SST_M90_M80(12)
  1316  REAL, 
POINTER          :: SST(:)
  1318  DATA num_days  /31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/
  1320  DATA sst_80_90 /271.466, 271.458, 271.448, 271.445, 271.519, 271.636, & 
  1321                  272.023, 272.066, 272.001, 271.698, 271.510, 271.472/
  1323  DATA sst_70_80 /272.149, 272.103, 272.095, 272.126, 272.360, 272.988, &
  1324                  274.061, 274.868, 274.415, 273.201, 272.468, 272.268/
  1326  DATA sst_60_70 /274.240, 274.019, 273.988, 274.185, 275.104, 276.875, &
  1327                  279.005, 280.172, 279.396, 277.586, 275.818, 274.803/
  1329  DATA sst_50_60 /277.277, 276.935, 277.021, 277.531, 279.100, 281.357, &
  1330                  283.735, 285.171, 284.399, 282.328, 279.918, 278.199/
  1332  DATA sst_40_50 /281.321, 280.721, 280.850, 281.820, 283.958, 286.588, &
  1333                  289.195, 290.873, 290.014, 287.652, 284.898, 282.735/
  1335  DATA sst_30_40 /289.189, 288.519, 288.687, 289.648, 291.547, 293.904, &
  1336                  296.110, 297.319, 296.816, 295.225, 292.908, 290.743/
  1338  DATA sst_20_30 /294.807, 294.348, 294.710, 295.714, 297.224, 298.703, &
  1339                  299.682, 300.127, 300.099, 299.455, 297.953, 296.177/
  1341  DATA sst_10_20 /298.878, 298.720, 299.033, 299.707, 300.431, 300.709, &
  1342                  300.814, 300.976, 301.174, 301.145, 300.587, 299.694/
  1344  DATA sst_00_10 /300.415, 300.548, 300.939, 301.365, 301.505, 301.141, &
  1345                  300.779, 300.660, 300.818, 300.994, 300.941, 300.675/
  1347  DATA sst_m10_00 /300.226, 300.558, 300.914, 301.047, 300.645, 299.870, &
  1348                   299.114, 298.751, 298.875, 299.294, 299.721, 299.989/
  1350  DATA sst_m20_m10 /299.547, 299.985, 300.056, 299.676, 298.841, 297.788, &
  1351                    296.893, 296.491, 296.687, 297.355, 298.220, 298.964/
  1353  DATA sst_m30_m20 /297.524, 298.073, 297.897, 297.088, 295.846, 294.520, &
  1354                    293.525, 293.087, 293.217, 293.951, 295.047, 296.363/
  1356  DATA sst_m40_m30 /293.054, 293.765, 293.468, 292.447, 291.128, 289.781, &
  1357                    288.773, 288.239, 288.203, 288.794, 289.947, 291.553/
  1359  DATA sst_m50_m40 /285.052, 285.599, 285.426, 284.681, 283.761, 282.826, &
  1360                    282.138, 281.730, 281.659, 281.965, 282.768, 283.961/
  1362  DATA sst_m60_m50 /277.818, 278.174, 277.991, 277.455, 276.824, 276.229, &
  1363                    275.817, 275.585, 275.560, 275.687, 276.142, 276.968/
  1365  DATA sst_m70_m60 /273.436, 273.793, 273.451, 272.813, 272.349, 272.048, &
  1366                    271.901, 271.838, 271.845, 271.889, 272.080, 272.607/
  1368  DATA sst_m80_m70 /271.579, 271.578, 271.471, 271.407, 271.392, 271.391, &
  1369                    271.390, 271.391, 271.394, 271.401, 271.422, 271.486/
  1371  DATA sst_m90_m80 /271.350, 271.350, 271.350, 271.350, 271.350, 271.350, &
  1372                    271.350, 271.350, 271.350, 271.350, 271.350, 271.350/
  1375  IF (latitude > 80.0) 
THEN  1377  ELSEIF (latitude > 70.0) 
THEN  1379  ELSEIF (latitude > 60.0) 
THEN  1381  ELSEIF (latitude > 50.0) 
THEN  1383  ELSEIF (latitude > 40.0) 
THEN  1385  ELSEIF (latitude > 30.0) 
THEN  1387  ELSEIF (latitude > 20.0) 
THEN  1389  ELSEIF (latitude > 10.0) 
THEN  1391  ELSEIF (latitude > 0.0) 
THEN  1393  ELSEIF (latitude > -10.0) 
THEN  1395  ELSEIF (latitude > -20.0) 
THEN  1397  ELSEIF (latitude > -30.0) 
THEN  1399  ELSEIF (latitude > -40.0) 
THEN  1401  ELSEIF (latitude > -50.0) 
THEN  1403  ELSEIF (latitude > -60.0) 
THEN  1405  ELSEIF (latitude > -70.0) 
THEN  1407  ELSEIF (latitude > -80.0) 
THEN  1415    IF(mon2 == 13) mon2 = 1
  1417    dtref = (sst(mon2) - sst(mon1)) / num_days(mon1)
  1420    IF (mon1 == 0) mon1=12
  1422    dtref = (sst(mon2) - sst(mon1)) / num_days(mon1)
  1425  dtref = dtref * (deltsfc / 24.0)
  1440  SUBROUTINE dtzm_point(XT,XZ,DT_COOL,ZC,Z1,Z2,DTZM)
  1443   real, 
intent(in)  :: xt,xz,dt_cool,zc,z1,z2
  1444   real, 
intent(out) :: dtzm
  1446   real, 
parameter   :: zero = 0.0
  1447   real, 
parameter   :: one  = 1.0
  1448   real, 
parameter   :: half = 0.5
  1449   real              :: dt_warm,dtw,dtc
  1454   if ( xt > zero ) 
then  1455     dt_warm = (xt+xt)/xz      
  1458         dtw = dt_warm*(one-(z1+z2)/(xz+xz))
  1459       elseif ( z1 < xz .and. z2 >= xz ) 
then  1460         dtw = half*(one-z1/xz)*dt_warm*(xz-z1)/(z2-z1)
  1462     elseif ( z1 == z2 ) 
then  1464         dtw = dt_warm*(one-z1/xz)
  1472   if ( zc > zero ) 
then  1475         dtc = dt_cool*(one-(z1+z2)/(zc+zc))
  1476       elseif ( z1 < zc .and. z2 >= zc ) 
then  1477         dtc = half*(one-z1/zc)*dt_cool*(zc-z1)/(z2-z1)
  1479     elseif ( z1 == z2 ) 
then  1481         dtc = dt_cool*(one-z1/zc)
  1512  subroutine tf_thaw_set(tf_ij,mask_ij,itile,jtile,tice,tclm,tf_thaw,nx,ny, &
  1513                         nset_thaw_s,nset_thaw_i,nset_thaw_c)
  1515  real,    
dimension(nx*ny), 
intent(in)    :: tf_ij
  1516  integer, 
dimension(nx*ny), 
intent(in)    :: mask_ij
  1517  real,                      
intent(in)    :: tice,tclm
  1518  integer,                   
intent(in)    :: itile,jtile,nx,ny
  1519  real,                      
intent(out)   :: tf_thaw
  1520  integer,                   
intent(inout) :: nset_thaw_s,nset_thaw_i,nset_thaw_c
  1522  real, 
parameter :: bmiss = -999.0
  1523  real,    
dimension(nx,ny) :: tf
  1524  integer, 
dimension(nx,ny) :: mask
  1525  integer :: krad,max_search,istart,iend,jstart,jend
  1526  integer :: ii,jj,iii,jjj
  1531  mask(:,:) = reshape(mask_ij,(/nx,ny/) )
  1532  tf(:,:)   = reshape(tf_ij,(/nx,ny/) )
  1536  do krad = 1, max_search
  1538     istart = itile - krad
  1540     jstart = jtile - krad
  1543     do jj = jstart, jend
  1544        do ii = istart, iend
  1547           if ((jj == jstart) .or. (jj == jend) .or.   &
  1548               (ii == istart) .or. (ii == iend))  
then  1550              if ((jj >= 1) .and. (jj <= ny)) 
then  1554                 else if (ii >= (nx+1)) 
then  1565                 if (krad <= 2 .and. mask(iii,jjj) == 2) is_ice = .true.
  1567                 if (mask(iii,jjj) == 0) 
then  1568                    tf_thaw = tf(iii,jjj)
  1569                    nset_thaw_s = nset_thaw_s + 1
  1570                    write(*,
'(a,I4,2F9.3)') 
'nset_thaw_s,tf(iii,jjj),tclm : ',nset_thaw_s,tf(iii,jjj),tclm
  1582  if ( tf_thaw == bmiss ) 
then  1585        nset_thaw_i = nset_thaw_i + 1
  1586        write(*,
'(a,I4,F9.3)') 
'nset_thaw_i,tf_ice : ',nset_thaw_i,tice
  1588        tf_thaw = 0.8*tice+0.2*tclm
  1589        nset_thaw_c = nset_thaw_c + 1
  1590        write(*,
'(a,I4,2F9.3)') 
'nset_thaw_c,tf_ice,tclm : ',nset_thaw_c,tice,tclm
  1607  integer, 
intent(in)  :: ij
  1609  real, 
intent(in)     :: tf_thaw
  1611  type(nsst_data), 
intent(inout)      :: nsst
  1615  nsst%d_conv(ij)  = 0.0
  1616  nsst%dt_cool(ij) = 0.0
  1618  nsst%qrain(ij)   = 0.0
  1619  nsst%tref(ij)    = tf_thaw
  1649 subroutine get_tf_clm(xlats_ij,xlons_ij,ny,nx,iy,im,id,ih,tf_clm,tf_trd)
  1654  real,    
dimension(nx*ny), 
intent(in)  :: xlats_ij 
  1655  real,    
dimension(nx*ny), 
intent(in)  :: xlons_ij 
  1656  real,    
dimension(nx,ny), 
intent(out) :: tf_clm   
  1657  real,    
dimension(nx,ny), 
intent(out) :: tf_trd   
  1658  integer, 
intent(in) :: iy,im,id,ih,nx,ny
  1660  real,    
allocatable, 
dimension(:,:)   :: tf_clm0    
  1661  real,    
allocatable, 
dimension(:,:)   :: tf_trd0    
  1662  real,    
allocatable, 
dimension(:)     :: cxlats     
  1663  real,    
allocatable, 
dimension(:)     :: cxlons     
  1665  real,    
dimension(nx*ny)  :: tf_clm_ij  
  1666  real,    
dimension(nx*ny)  :: tf_trd_ij  
  1668  integer :: nxc,nyc,mon1,mon2
  1669  character (len=6), 
parameter :: fin_tf_clm=
'sstclm'   1678  allocate( tf_clm0(nxc,nyc),tf_trd0(nxc,nyc),cxlats(nyc),cxlons(nxc) )
  1682  call get_tf_clm_ta(tf_clm0,tf_trd0,cxlats,cxlons,nyc,nxc,mon1,mon2,wei1,wei2)
  1686  if ( nx == nxc .and. ny == nyc ) 
then  1687     tf_clm(:,:) = tf_clm0(:,:)
  1688     tf_trd(:,:) = tf_trd0(:,:)
  1692     call intp_tile(tf_clm0,  cxlats,  cxlons,  nyc, nxc, &
  1693                    tf_clm_ij,xlats_ij,xlons_ij,ny,  nx)
  1694     call intp_tile(tf_trd0,  cxlats,  cxlons,  nyc, nxc, &
  1695                    tf_trd_ij,xlats_ij,xlons_ij,ny,  nx)
  1698     tf_clm(:,:) = reshape(tf_clm_ij, (/nx,ny/) )
  1699     tf_trd(:,:) = reshape(tf_trd_ij, (/nx,ny/) )
  1718 subroutine get_tf_clm_ta(tf_clm_ta,tf_clm_trend,xlats,xlons,nlat,nlon,mon1,mon2,wei1,wei2)
  1723  integer, 
intent(in) :: nlat,nlon,mon1,mon2
  1724  real,    
intent(in) :: wei1,wei2
  1726  real, 
dimension(nlon,nlat), 
intent(out)   :: tf_clm_ta,tf_clm_trend
  1727  real, 
dimension(nlat),      
intent(out)   :: xlats
  1728  real, 
dimension(nlon),      
intent(out)   :: xlons
  1731  character (len=6),  
parameter :: fin_tf_clm=
'sstclm'  1734  real, 
dimension(nlon,nlat) :: tf_clm1,tf_clm2
  1744    tf_clm_ta(:,:) = wei1*tf_clm1(:,:)+wei2*tf_clm2(:,:)
  1748    tf_clm_trend(:,:) = (tf_clm2(:,:)-tf_clm1(:,:))/120.0
  1750    write(*,
'(a,2f9.3)') 
'tf_clm_ta, min, max : ',minval(tf_clm_ta),maxval(tf_clm_ta)
  1751    write(*,
'(a,2f9.3)') 
'tf_clm_trend, min, max : ',minval(tf_clm_trend),maxval(tf_clm_trend)
  1766 subroutine get_sal_clm(xlats_ij,xlons_ij,ny,nx,iy,im,id,ih,sal_clm)
  1770  real,    
dimension(nx*ny), 
intent(in)  :: xlats_ij   
  1771  real,    
dimension(nx*ny), 
intent(in)  :: xlons_ij   
  1772  real,    
dimension(nx,ny), 
intent(out) :: sal_clm    
  1773  integer, 
intent(in) :: iy,im,id,ih,nx,ny
  1775  real,    
allocatable, 
dimension(:,:)   :: sal_clm0   
  1776  real,    
allocatable, 
dimension(:)     :: cxlats     
  1777  real,    
allocatable, 
dimension(:)     :: cxlons     
  1779  real,    
dimension(nx*ny)  :: sal_clm_ij  
  1781  integer :: nxc,nyc,mon1,mon2
  1782  character (len=6), 
parameter :: fin_sal_clm=
'salclm'   1791  allocate( sal_clm0(nxc,nyc),cxlats(nyc),cxlons(nxc) )
  1795  call get_sal_clm_ta(sal_clm0,cxlats,cxlons,nyc,nxc,mon1,mon2,wei1,wei2)
  1799  if ( nx == nxc .and. ny == nyc ) 
then  1800     sal_clm(:,:) = sal_clm0(:,:)
  1804     call intp_tile(sal_clm0,  cxlats,  cxlons,  nyc, nxc, &
  1805                    sal_clm_ij,xlats_ij,xlons_ij,ny,  nx)
  1809     sal_clm(:,:) = reshape(sal_clm_ij, (/nx,ny/) )
  1826 subroutine get_sal_clm_ta(sal_clm_ta,xlats,xlons,nlat,nlon,mon1,mon2,wei1,wei2)
  1832  integer, 
intent(in) :: nlat,nlon,mon1,mon2
  1833  real,    
intent(in) :: wei1,wei2
  1835  real, 
dimension(nlon,nlat), 
intent(out)   :: sal_clm_ta
  1836  real, 
dimension(nlat),      
intent(out)   :: xlats
  1837  real, 
dimension(nlon),      
intent(out)   :: xlons
  1840  character (len=6),  
parameter :: fin_sal_clm=
'salclm'  1843  real, 
dimension(nlon,nlat) :: sal_clm1,sal_clm2
  1853    sal_clm_ta(:,:) = wei1*sal_clm1(:,:)+wei2*sal_clm2(:,:)
  1854    write(*,
'(a,2f9.3)') 
'sal_clm_ta, min, max : ',minval(sal_clm_ta),maxval(sal_clm_ta)
  1871 subroutine intp_tile(tf_lalo,dlats_lalo,dlons_lalo,jdim_lalo,idim_lalo, &
  1872                      tf_tile,xlats_tile,xlons_tile,jdim_tile,idim_tile)
  1879  real,    
dimension(idim_lalo,jdim_lalo), 
intent(in)  :: tf_lalo
  1880  real,    
dimension(jdim_lalo),           
intent(in)  :: dlats_lalo
  1881  real,    
dimension(idim_lalo),           
intent(in)  :: dlons_lalo
  1882  real,    
dimension(jdim_tile*idim_tile), 
intent(in)  :: xlats_tile
  1883  real,    
dimension(jdim_tile*idim_tile), 
intent(in)  :: xlons_tile
  1884  integer,                                 
intent(in)  :: jdim_lalo,idim_lalo,jdim_tile,idim_tile
  1885  real,    
dimension(jdim_tile*idim_tile), 
intent(out) :: tf_tile
  1888  real, 
parameter :: deg2rad=3.1415926/180.0
  1889  real,    
dimension(jdim_lalo) :: xlats_lalo
  1890  real,    
dimension(idim_lalo) :: xlons_lalo
  1892  integer :: itile,jtile
  1894  integer :: ilalo,jlalo,ilalop1,jlalop1
  1896  integer, 
allocatable, 
dimension(:,:)   :: id1,id2,jdc
  1897  real,    
allocatable, 
dimension(:,:,:) :: agrid,s2c
  1900  print*,
'interpolate from lat/lon grids to any one grid with known lat/lon'  1902  xlats_lalo = dlats_lalo*deg2rad
  1903  xlons_lalo = dlons_lalo*deg2rad
  1905  allocate(agrid(idim_tile,jdim_tile,2))
  1906  agrid(:,:,1) = reshape(xlons_tile, (/idim_tile,jdim_tile/) )
  1907  agrid(:,:,2) = reshape(xlats_tile, (/idim_tile,jdim_tile/) )
  1908  agrid        = agrid*deg2rad
  1910  allocate(id1(idim_tile,jdim_tile))
  1911  allocate(id2(idim_tile,jdim_tile))
  1912  allocate(jdc(idim_tile,jdim_tile))
  1913  allocate(s2c(idim_tile,jdim_tile,4))
  1921  call remap_coef( 1, idim_tile, 1, jdim_tile, idim_lalo, jdim_lalo, &
  1922                   xlons_lalo, xlats_lalo, id1, id2, jdc, s2c, agrid )
  1924  do ij = 1, jdim_tile*idim_tile
  1926     jtile = (ij-1)/idim_tile + 1
  1927     itile = mod(ij,idim_tile)
  1928     if (itile==0) itile = idim_tile
  1930     ilalo   = id1(itile,jtile)
  1931     ilalop1 = id2(itile,jtile)
  1932     jlalo   = jdc(itile,jtile)
  1933     jlalop1 = jdc(itile,jtile) + 1
  1935     wsum = s2c(itile,jtile,1) + s2c(itile,jtile,2) + &
  1936            s2c(itile,jtile,3) + s2c(itile,jtile,4)
  1938     tf_tile(ij)  = ( s2c(itile,jtile,1)*tf_lalo(ilalo,jlalo)     + &
  1939                      s2c(itile,jtile,2)*tf_lalo(ilalop1,jlalo)   + &
  1940                      s2c(itile,jtile,3)*tf_lalo(ilalop1,jlalop1) + &
  1941                      s2c(itile,jtile,4)*tf_lalo(ilalo,jlalop1) )/wsum
  1944  deallocate(id1, id2, jdc, s2c)
  1960 subroutine get_tim_wei(iy,im,id,ih,mon1,mon2,wei1,wei2)
  1964  integer, 
intent(in) :: iy,im,id,ih
  1966  integer, 
intent(out) :: mon1,mon2
  1967  real,    
intent(out) :: wei1,wei2
  1971  integer :: mon,monend,monm,monp,jdow,jdoy,jday
  1976  real, 
dimension(13) ::  dayhf
  1977  data dayhf/15.5,45.0,74.5,105.0,135.5,166.0,196.5,227.5,258.0,288.5,319.0,349.5,380.5/
  1990  call w3doxdat(jda,jdow,jdoy,jday)
  1991  rjday=jdoy+jda(5)/24.
  1992  if(rjday.lt.dayhf(1)) rjday=rjday+365.
  1998     if( rjday >= dayhf(monm) .and. rjday < dayhf(monp) ) 
then  2005  print *,
'FATAL ERROR in get_tim_wei, wrong rjday',rjday
  2009  wei1 = (dayhf(mon2)-rjday)/(dayhf(mon2)-dayhf(mon1))
  2010  wei2 = (rjday-dayhf(mon1))/(dayhf(mon2)-dayhf(mon1))
  2012  if( mon2 == 13 ) mon2=1
  2014  write(*,
'(a,2i4,3f9.3)') 
'mon1,mon2,rjday,wei1,wei2=',mon1,mon2,rjday,wei1,wei2
  2027  real function tfreez(salinity)
  2033  parameter(a1 = -0.0575)
  2034  parameter(a2 =  1.710523e-3)
  2035  parameter(a3 = -2.154996e-4)
  2037  IF (salinity .LT. 0.) 
THEN  2042  tfreez = sal*(a1+a2*sqrt(sal)+a3*sal)
 integer function num_parthds()
Return the number of omp threads. 
 
subroutine, public get_tf_clm_dim(file_sst, mlat_sst, mlon_sst)
Get the i/j dimensions of RTG SST climatology file. 
 
subroutine, public read_tf_clim_grb(file_sst, sst, rlats_sst, rlons_sst, mlat_sst, mlon_sst, mon)
Read a GRIB1 sst climatological analysis file. 
 
integer, public idim_gaus
'i' dimension of GSI gaussian grid. 
 
subroutine get_tf_clm(xlats_ij, xlons_ij, ny, nx, iy, im, id, ih, tf_clm, tf_trd)
Get the sst climatology at the valid time and on the target grid. 
 
subroutine, public read_salclm_gfs_nc(filename, sal, xlats, xlons, nlat, nlon, itime)
Read the woa05 salinity monthly climatology file. 
 
subroutine, public write_data(lensfc, idim, jdim, lsoil, do_nsst, nsst, slifcs, tsffcs, vegfcs, swefcs, tg3fcs, zorfcs, albfcs, alffcs, cnpfcs, f10m, t2m, q2m, vetfcs, sotfcs, ustar, fmm, fhh, sicfcs, sihfcs, sitfcs, tprcp, srflag, swdfcs, vmnfcs, vmxfcs, slpfcs, absfcs, slcfcs, smcfcs, stcfcs)
Update surface records - and nsst records if selected - on a single cubed-sphere tile to a pre-existi...
 
subroutine get_tf_clm_ta(tf_clm_ta, tf_clm_trend, xlats, xlons, nlat, nlon, mon1, mon2, wei1, wei2)
Get the reference temperature/sst climatology and its trend at analysis time. 
 
subroutine, public remap_coef(is, ie, js, je, im, jm, lon, lat, id1, id2, jdc, s2c, agrid)
Generate the weights and index of the grids used in the bilinear interpolation. 
 
integer, dimension(:,:), allocatable, public slmsk_gaus
GSI land mask on the gaussian grid. 
 
subroutine dtzm_point(XT, XZ, DT_COOL, ZC, Z1, Z2, DTZM)
Compute the vertical mean of the NSST t-profile. 
 
subroutine get_sal_clm_ta(sal_clm_ta, xlats, xlons, nlat, nlon, mon1, mon2, wei1, wei2)
Get climatological salinity at the analysis time. 
 
Holds machine dependent constants for global_cycle. 
 
subroutine sfcdrv(LUGB, IDIM, JDIM, LENSFC, LSOIL, DELTSFC, IY, IM, ID, IH, FH, IALB, USE_UFO, DO_NSST, DO_SFCCYCLE, DO_LNDINC, FRAC_GRID, ZSEA1, ZSEA2, ISOT, IVEGSRC, MYRANK)
Driver routine for updating the surface fields. 
 
subroutine tf_thaw_set(tf_ij, mask_ij, itile, jtile, tice, tclm, tf_thaw, nx, ny, nset_thaw_s, nset_thaw_i, nset_thaw_c)
Set the background reference temperature (tf) for points where the ice has just melted. 
 
subroutine, public get_dim_nc(filename, nlat, nlon)
Get the i/j dimensions of the data from a NetCDF file. 
 
subroutine, public read_gsi_data(GSI_FILE, FILE_TYPE, LSOIL)
Read increment file from the GSI containing either the foundation temperature increments and mask...
 
subroutine intp_tile(tf_lalo, dlats_lalo, dlons_lalo, jdim_lalo, idim_lalo, tf_tile, xlats_tile, xlons_tile, jdim_tile, idim_tile)
Interpolate lon/lat grid data to the fv3 native grid (tf_lalo => tf_tile). 
 
subroutine climo_trend(LATITUDE, MON, DAY, DELTSFC, DTREF)
If the tile point is an isolated water point that has no corresponding gsi water point, then tref is updated using the rtg sst climo trend. 
 
subroutine, public read_data(LSOIL, LENSFC, DO_NSST, INC_FILE, IS_NOAHMP, TSFFCS, SMCFCS, SWEFCS, STCFCS, TG3FCS, ZORFCS, CVFCS, CVBFCS, CVTFCS, ALBFCS, VEGFCS, SLIFCS, CNPFCS, F10M, VETFCS, SOTFCS, ALFFCS, USTAR, FMM, FHH, SIHFCS, SICFCS, SITFCS, TPRCP, SRFLAG, SNDFCS, VMNFCS, VMXFCS, SLCFCS, SLPFCS, ABSFCS, T2M, Q2M, SLMASK, ZSOIL, NSST)
Read the first guess surface records and nsst records (if selected) for a single cubed-sphere tile...
 
real, dimension(:,:), allocatable, public dtref_gaus
GSI foundation temperature increment on the gaussian grid. 
 
Module containing utility routines. 
 
This module contains routines that read and write data. 
 
program sfc_drv
Stand alone surface/NSST cycle driver for the cubed-sphere grid. 
 
subroutine adjust_nsst(RLA, RLO, SLMSK_TILE, SLMSK_FG_TILE, SKINT_TILE, SICET_TILE, sice_tile, sice_fg_tile, SOILT_TILE, NSST, LENSFC, LSOIL, IDIM, JDIM, ZSEA1, ZSEA2, tf_clm_tile, tf_trd_tile, sal_clm_tile, LANDFRAC, FRAC_GRID)
Read in gsi file with the updated reference temperature increments (on the gaussian grid)...
 
real function tfreez(salinity)
Compute the freezing point of water as a function of salinity. 
 
integer, public jdim_gaus
'j' dimension of GSI gaussian grid. 
 
subroutine get_tim_wei(iy, im, id, ih, mon1, mon2, wei1, wei2)
For a given date, determine the bounding months and the linear time interpolation weights...
 
subroutine get_sal_clm(xlats_ij, xlons_ij, ny, nx, iy, im, id, ih, sal_clm)
Get salinity climatology at the valid time on the target grid. 
 
subroutine nsst_water_reset(nsst, ij, tf_thaw)
If the first guess was sea ice, but the analysis is open water, reset all nsst variables. 
 
subroutine, public read_lat_lon_orog(RLA, RLO, OROG, OROG_UF, TILE_NUM, IDIM, JDIM, IJDIM, LANDFRAC)
Read latitude and longitude for the cubed-sphere tile from the 'grid' file.