13 subroutine interp(localpet, method, input_file)
 
   25 character(len=*), 
intent(in)       :: input_file
 
   27 integer                            :: rc, localpet
 
   28 integer                            :: i, j, ij, tile, n, ncid, status
 
   29 integer                            :: l(1), u(1), t
 
   30 integer                            :: clb_mdl(2), cub_mdl(2)
 
   31 integer                            :: varid, record
 
   32 integer                            :: tile_num, pt_loc_this_tile
 
   33 integer                            :: isrctermprocessing
 
   35 integer(esmf_kind_i4), 
allocatable :: mask_mdl_one_tile(:,:)
 
   36 integer(esmf_kind_i4), 
pointer     :: unmapped_ptr(:)
 
   38 real(esmf_kind_r4), 
pointer        :: data_mdl_ptr(:,:)
 
   39 real(esmf_kind_r4), 
pointer        :: data_src_ptr(:,:)
 
   40 real(esmf_kind_r4), 
allocatable    :: data_src_global(:,:)
 
   41 real(esmf_kind_r4), 
allocatable    :: data_mdl_one_tile(:,:)
 
   42 real(esmf_kind_r4), 
allocatable    :: vegt_mdl_one_tile(:,:)
 
   43 real(esmf_kind_r4), 
allocatable    :: lat_mdl_one_tile(:,:)
 
   44 real(esmf_kind_r4), 
allocatable    :: lon_mdl_one_tile(:,:)
 
   46 type(esmf_regridmethod_flag),
intent(in) :: method
 
   47 type(esmf_field)                        :: data_field_src
 
   48 type(esmf_routehandle)                  :: regrid_data
 
   49 type(esmf_polemethod_flag)              :: pole
 
   51 print*,
"- CALL FieldCreate FOR SOURCE GRID DATA." 
   52 data_field_src = esmf_fieldcreate(
grid_src, &
 
   53                                  typekind=esmf_typekind_r4, &
 
   54                                  indexflag=esmf_index_global, &
 
   55                                  staggerloc=esmf_staggerloc_center, &
 
   58 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
   61 print*,
"- CALL FieldGet FOR SOURCE GRID DATA." 
   63 call esmf_fieldget(data_field_src, &
 
   64                    farrayptr=data_src_ptr,  &
 
   66 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
   69 print*,
"- CALL FieldGet FOR MODEL GRID DATA." 
   72                    farrayptr=data_mdl_ptr,  &
 
   73                    computationallbound=clb_mdl, &
 
   74                    computationalubound=cub_mdl, &
 
   76 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
   79 if (localpet == 0) 
then 
   82   allocate(data_src_global(0,0))
 
   85 print*,
'- OPEN SOURCE FILE ', trim(input_file)
 
   86 status = nf90_open(input_file, nf90_nowrite, ncid)
 
   87 call netcdf_err(status, 
"IN ROUTINE INTERP OPENING SOURCE FILE")
 
   89 if (localpet == 0) 
then 
   95   allocate(data_mdl_one_tile(0,0))
 
   96   allocate(mask_mdl_one_tile(0,0))
 
   97   allocate(lat_mdl_one_tile(0,0))
 
   98   allocate(lon_mdl_one_tile(0,0))
 
  109   if (localpet == 0) 
then 
  110     status = nf90_inq_varid(ncid, 
field_names(n), varid)
 
  111     call netcdf_err(status, 
"IN ROUTINE INTERP READING FIELD ID")
 
  112     status = nf90_get_var(ncid, varid, data_src_global, start=(/1,1,t/), count=(/
i_src,
j_src,1/))
 
  113     call netcdf_err(status, 
"IN ROUTINE INTERP READING FIELD")
 
  116   print*,
"- CALL FieldScatter FOR SOURCE GRID DATA." 
  117   call esmf_fieldscatter(data_field_src, data_src_global, rootpet=0, rc=rc)
 
  118   if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  121   isrctermprocessing = 1
 
  123   if (record == 1) 
then 
  125     if (method == esmf_regridmethod_bilinear) 
then 
  126       pole = esmf_polemethod_allavg
 
  128       pole = esmf_polemethod_none
 
  131     print*,
"- CALL FieldRegridStore." 
  132     nullify(unmapped_ptr)
 
  133     call esmf_fieldregridstore(data_field_src, &
 
  135                            srcmaskvalues=(/0/), &
 
  136                            dstmaskvalues=(/0/), &
 
  138                            unmappedaction=esmf_unmappedaction_ignore, &
 
  139                            normtype=esmf_normtype_fracarea, &
 
  140                            srctermprocessing=isrctermprocessing, &
 
  141                            routehandle=regrid_data, &
 
  142                            regridmethod=method, &
 
  143                            unmappeddstlist=unmapped_ptr,  &
 
  145     if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  150   print*,
"- CALL Field_Regrid." 
  151   call esmf_fieldregrid(data_field_src, &
 
  153                         routehandle=regrid_data, &
 
  154                         termorderflag=esmf_termorder_srcseq, &
 
  156   if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  174   l = lbound(unmapped_ptr)
 
  175   u = ubound(unmapped_ptr)
 
  178     tile_num = ((unmapped_ptr(ij)-1) / (
i_mdl*
j_mdl)) 
 
  179     pt_loc_this_tile = unmapped_ptr(ij) - (tile_num * 
i_mdl * 
j_mdl) 
 
  182     j = (pt_loc_this_tile - 1) / 
i_mdl + 1
 
  183     i = mod(pt_loc_this_tile, 
i_mdl)
 
  185     data_mdl_ptr(i,j) = -9999.9 
 
  197       case (
'substrate_temperature',
'vegetation_greenness',
'leaf_area_index',
'slope_type',
'soil_type',
'soil_color')
 
  198       if (localpet == 0) 
then 
  201         allocate(vegt_mdl_one_tile(0,0))
 
  208     print*,
"- CALL FieldGather FOR MODEL LATITUDE." 
  209     call esmf_fieldgather(
latitude_field_mdl, lat_mdl_one_tile, rootpet=0, tile=tile, rc=rc)
 
  210     if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  213     print*,
"- CALL FieldGather FOR MODEL LONGITUDE." 
  215     if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  218     print*,
"- CALL FieldGather FOR MODEL GRID DATA." 
  219     call esmf_fieldgather(
data_field_mdl, data_mdl_one_tile, rootpet=0, tile=tile, rc=rc)
 
  220     if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  223     print*,
"- CALL FieldGather FOR MODEL GRID LAND MASK." 
  224     call esmf_fieldgather(
mask_field_mdl, mask_mdl_one_tile, rootpet=0, tile=tile, rc=rc)
 
  225     if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  230         case (
'substrate_temperature',
'vegetation_greenness',
'leaf_area_index',
'slope_type',
'soil_type',
'soil_color')
 
  231           print*,
"- CALL FieldGather FOR MODEL GRID VEG TYPE." 
  232           call esmf_fieldgather(
vegt_field_mdl, vegt_mdl_one_tile, rootpet=0, tile=tile, rc=rc)
 
  233           if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  238     if (localpet == 0) 
then 
  239       print*,
'- CALL SEARCH FOR TILE ',tile
 
  243           case (
'substrate_temperature',
'vegetation_greenness',
'leaf_area_index',
'slope_type',
'soil_type',
'soil_color')
 
  247       where(mask_mdl_one_tile == 0) data_mdl_one_tile = 
missing 
  248       call output (data_mdl_one_tile, lat_mdl_one_tile, lon_mdl_one_tile, 
i_mdl, 
j_mdl, tile, record, t, n)
 
  253         print*,
"- CALL FieldScatter FOR MODEL GRID VEGETATION TYPE." 
  254         call esmf_fieldscatter(
vegt_field_mdl, data_mdl_one_tile, rootpet=0, tile=tile, rc=rc)
 
  255         if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
 
  262   if (
allocated(vegt_mdl_one_tile)) 
deallocate(vegt_mdl_one_tile)
 
  267 status=nf90_close(ncid)
 
  269 deallocate(data_mdl_one_tile, mask_mdl_one_tile)
 
  270 deallocate(data_src_global, lat_mdl_one_tile, lon_mdl_one_tile)
 
  272 print*,
"- CALL FieldRegridRelease." 
  273 call esmf_fieldregridrelease(routehandle=regrid_data, rc=rc)
 
  275 print*,
"- CALL FieldDestroy." 
  276 call esmf_fielddestroy(data_field_src, rc=rc)
 
 
  297 character(len=*), 
intent(in)      :: field_ch
 
  299 integer, 
intent(in)               :: idim, jdim
 
  301 real(esmf_kind_i4), 
intent(in)    :: vegt(idim,jdim)
 
  302 real(esmf_kind_r4), 
intent(inout) :: field(idim,jdim)
 
  304 integer, 
parameter                :: landice=15
 
  306 integer                           :: i, j, ierr
 
  308 real                              :: landice_value
 
  310 select case (field_ch)
 
  311   case (
'substrate_temperature') 
 
  312     landice_value = 273.15
 
  315       if (nint(vegt(i,j)) == landice) 
then 
  316         field(i,j) = min(field(i,j), landice_value)
 
  320   case (
'vegetation_greenness') 
 
  324       if (nint(vegt(i,j)) == landice) 
then 
  325         field(i,j) = landice_value
 
  329   case (
'leaf_area_index') 
 
  333       if (nint(vegt(i,j)) == landice) 
then 
  334         field(i,j) = landice_value
 
  342       if (nint(vegt(i,j)) == landice) 
then 
  343         field(i,j) = landice_value
 
  345         if (nint(field(i,j)) == nint(landice_value)) field(i,j) = 2.0
 
  353       if (nint(vegt(i,j)) == landice) 
then 
  354         field(i,j) = landice_value
 
  356         if (nint(field(i,j)) == nint(landice_value)) field(i,j) = 6.0
 
  364       if (nint(vegt(i,j)) == landice) 
then 
  365         field(i,j) = landice_value
 
  370     print*,
'- FATAL ERROR IN ROUTINE ADJUST_FOR_LANDICE.  UNIDENTIFIED FIELD : ', field_ch
 
  371     call mpi_abort(mpi_comm_world, 57, ierr)