18 character(len=5),
allocatable,
public :: tiles_target_grid(:)
20 character(len=10),
public :: inv_file =
"chgres.inv"
22 character(len=50),
public :: input_grid_type =
"latlon"
26 integer,
public :: lsoil_target = 4
28 integer,
public :: i_input
31 integer,
public :: j_input
34 integer,
public :: ip1_input
36 integer,
public :: jp1_input
38 integer,
public :: i_target
41 integer,
public :: j_target
44 integer,
public :: ip1_target
46 integer,
public :: jp1_target
48 integer,
public :: num_tiles_input_grid
50 integer,
public :: num_tiles_target_grid
53 type(esmf_grid
),
public :: input_grid
55 type(esmf_grid
),
public :: target_grid
58 type(esmf_field
),
public :: latitude_input_grid
60 type(esmf_field
),
public :: longitude_input_grid
62 type(esmf_field
),
public :: latitude_s_input_grid
65 type(esmf_field
),
public :: longitude_s_input_grid
68 type(esmf_field
),
public :: latitude_w_input_grid
71 type(esmf_field
),
public :: longitude_w_input_grid
75 type(esmf_field
),
public :: landmask_target_grid
78 type(esmf_field
),
public :: latitude_target_grid
80 type(esmf_field
),
public :: latitude_s_target_grid
83 type(esmf_field
),
public :: latitude_w_target_grid
86 type(esmf_field
),
public :: longitude_target_grid
88 type(esmf_field
),
public :: longitude_s_target_grid
91 type(esmf_field
),
public :: longitude_w_target_grid
94 type(esmf_field
),
public :: seamask_target_grid
97 type(esmf_field
),
public :: terrain_target_grid
123 integer,
intent(in) :: localpet, npets
125 if (trim(input_type) ==
"gaussian_nemsio" .or. &
126 trim(input_type) ==
"gfs_gaussian_nemsio" .or. &
127 trim(input_type) ==
"gfs_sigio" .or. &
128 trim(input_type) ==
"gaussian_netcdf")
then
130 elseif (trim(external_model) ==
"GFS" .and. trim(input_type) ==
"grib2")
then
132 elseif (trim(input_type) ==
"grib2")
then
156 atm_files_input_grid, &
157 sfc_files_input_grid, &
159 convert_atm, convert_sfc
167 integer,
intent(in) :: localpet, npets
169 character(len=250) :: the_file
171 integer :: i, j, rc, clb(2), cub(2), ncid, id_grid
172 integer(sfcio_intkind) :: rc2
173 integer(sigio_intkind) :: rc3
175 real(esmf_kind_r8),
allocatable :: latitude(:,:)
176 real(esmf_kind_r8),
allocatable :: longitude(:,:)
177 real(esmf_kind_r8),
pointer :: lat_src_ptr(:,:)
178 real(esmf_kind_r8),
pointer :: lon_src_ptr(:,:)
179 real(esmf_kind_r8),
pointer :: lat_corner_src_ptr(:,:)
180 real(esmf_kind_r8),
pointer :: lon_corner_src_ptr(:,:)
181 real(esmf_kind_r8) :: deltalon
182 real(esmf_kind_r8),
allocatable :: slat(:), wlat(:)
184 type(nemsio_gfile
) :: gfile
185 type(esmf_polekind_flag
) :: polekindflag(2)
186 type(sfcio_head
) :: sfchead
187 type(sigio_head
) :: sighead
189 print*,
"- DEFINE INPUT GRID OBJECT FOR GAUSSIAN DATA."
191 num_tiles_input_grid = 1
193 if (convert_sfc)
then
194 the_file=trim(data_dir_input_grid) //
"/" // trim(sfc_files_input_grid(1))
195 elseif (convert_atm)
then
196 the_file=trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(1))
199 if (trim(input_type) ==
"gfs_sigio")
then
202 if (convert_sfc)
then
203 print*,
"- OPEN AND READ ", trim(the_file)
204 call sfcio_sropen(21, trim(the_file), rc2)
206 call sfcio_srhead(21, sfchead, rc2)
208 call sfcio_sclose(21, rc2)
209 i_input = sfchead%lonb
210 j_input = sfchead%latb
211 elseif (convert_atm)
then
212 print*,
"- OPEN AND READ ", trim(the_file)
213 call sigio_sropen(21, trim(the_file), rc3)
215 call sigio_srhead(21, sighead, rc3)
217 call sigio_sclose(21, rc3)
218 i_input = sighead%lonb
219 j_input = sighead%latb
222 elseif (trim(input_type) ==
"gaussian_netcdf")
then
224 print*,
'- OPEN AND READ: ',trim(the_file)
225 rc=nf90_open(trim(the_file),nf90_nowrite,ncid)
228 print*,
"- READ grid_xt"
229 rc=nf90_inq_dimid(ncid,
'grid_xt', id_grid)
231 rc=nf90_inquire_dimension(ncid,id_grid,len=i_input)
234 print*,
"- READ grid_yt"
235 rc=nf90_inq_dimid(ncid,
'grid_yt', id_grid)
237 rc=nf90_inquire_dimension(ncid,id_grid,len=j_input)
240 rc = nf90_close(ncid)
244 call nemsio_init(iret=rc)
246 print*,
"- OPEN AND READ ", trim(the_file)
247 call nemsio_open(gfile, the_file,
"read", iret=rc)
250 call nemsio_getfilehead(gfile, iret=rc, dimx=i_input, dimy=j_input)
253 call nemsio_close(gfile)
257 ip1_input = i_input + 1
258 jp1_input = j_input + 1
260 polekindflag(1:2) = esmf_polekind_monopole
262 print*,
"- CALL GridCreate1PeriDim FOR INPUT GRID."
263 input_grid = esmf_gridcreate1peridim(minindex=(/1,1/), &
264 maxindex=(/i_input,j_input/), &
265 polekindflag=polekindflag, &
268 coordsys=esmf_coordsys_sph_deg, &
269 regdecomp=(/1,npets/), &
270 indexflag=esmf_index_global, rc=rc)
271 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
274 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE."
275 latitude_input_grid = esmf_fieldcreate(input_grid, &
276 typekind=esmf_typekind_r8, &
277 staggerloc=esmf_staggerloc_center, &
278 name=
"input_grid_latitude", rc=rc)
279 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
282 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE."
283 longitude_input_grid = esmf_fieldcreate(input_grid, &
284 typekind=esmf_typekind_r8, &
285 staggerloc=esmf_staggerloc_center, &
286 name=
"input_grid_longitude", rc=rc)
287 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
290 allocate(longitude(i_input,j_input))
291 allocate(latitude(i_input,j_input))
293 deltalon = 360.0_esmf_kind_r8 /
real(i_input,kind=esmf_kind_r8)
295 longitude(i,:) =
real((i-1),kind=esmf_kind_r8) * deltalon
298 allocate(slat(j_input))
299 allocate(wlat(j_input))
300 call splat(4, j_input, slat, wlat)
303 latitude(:,i) = 90.0_esmf_kind_r8 - (acos(slat(i))* 180.0_esmf_kind_r8 / &
304 (4.0_esmf_kind_r8*atan(1.0_esmf_kind_r8)))
307 deallocate(slat, wlat)
309 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE."
310 call esmf_fieldscatter(longitude_input_grid, longitude, rootpet=0, rc=rc)
311 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
314 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE."
315 call esmf_fieldscatter(latitude_input_grid, latitude, rootpet=0, rc=rc)
316 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
319 print*,
"- CALL GridAddCoord FOR INPUT GRID."
320 call esmf_gridaddcoord(input_grid, &
321 staggerloc=esmf_staggerloc_center, rc=rc)
322 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
325 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
327 call esmf_gridgetcoord(input_grid, &
328 staggerloc=esmf_staggerloc_center, &
330 farrayptr=lon_src_ptr, rc=rc)
331 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
334 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
336 call esmf_gridgetcoord(input_grid, &
337 staggerloc=esmf_staggerloc_center, &
339 computationallbound=clb, &
340 computationalubound=cub, &
341 farrayptr=lat_src_ptr, rc=rc)
342 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
345 do j = clb(2), cub(2)
346 do i = clb(1), cub(1)
347 lon_src_ptr(i,j) = longitude(i,j)
348 if (lon_src_ptr(i,j) > 360.0_esmf_kind_r8) lon_src_ptr(i,j) = lon_src_ptr(i,j) - 360.0_esmf_kind_r8
349 lat_src_ptr(i,j) = latitude(i,j)
353 print*,
"- CALL GridAddCoord FOR INPUT GRID."
354 call esmf_gridaddcoord(input_grid, &
355 staggerloc=esmf_staggerloc_corner, rc=rc)
356 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
359 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
360 nullify(lon_corner_src_ptr)
361 call esmf_gridgetcoord(input_grid, &
362 staggerloc=esmf_staggerloc_corner, &
364 farrayptr=lon_corner_src_ptr, rc=rc)
365 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
368 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
369 nullify(lat_corner_src_ptr)
370 call esmf_gridgetcoord(input_grid, &
371 staggerloc=esmf_staggerloc_corner, &
373 computationallbound=clb, &
374 computationalubound=cub, &
375 farrayptr=lat_corner_src_ptr, rc=rc)
376 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
379 do j = clb(2), cub(2)
380 do i = clb(1), cub(1)
381 lon_corner_src_ptr(i,j) = longitude(i,1) - (0.5_esmf_kind_r8*deltalon)
382 if (lon_corner_src_ptr(i,j) > 360.0_esmf_kind_r8) lon_corner_src_ptr(i,j) = lon_corner_src_ptr(i,j) - 360.0_esmf_kind_r8
384 lat_corner_src_ptr(i,j) = 90.0_esmf_kind_r8
387 if (j == jp1_input)
then
388 lat_corner_src_ptr(i,j) = -90.0_esmf_kind_r8
391 lat_corner_src_ptr(i,j) = 0.5_esmf_kind_r8 * (latitude(i,j-1)+ latitude(i,j))
395 deallocate(latitude,longitude)
409 orog_dir_input_grid, &
410 orog_files_input_grid
414 character(len=500) :: the_file
416 integer,
intent(in) :: localpet, npets
418 integer :: id_tiles, id_dim, tile
419 integer :: extra, error, ncid
420 integer,
allocatable :: decomptile(:,:)
422 integer(esmf_kind_i8),
allocatable :: landmask_one_tile(:,:)
424 real(esmf_kind_r8),
allocatable :: latitude_one_tile(:,:)
425 real(esmf_kind_r8),
allocatable :: latitude_s_one_tile(:,:)
426 real(esmf_kind_r8),
allocatable :: latitude_w_one_tile(:,:)
427 real(esmf_kind_r8),
allocatable :: longitude_one_tile(:,:)
428 real(esmf_kind_r8),
allocatable :: longitude_s_one_tile(:,:)
429 real(esmf_kind_r8),
allocatable :: longitude_w_one_tile(:,:)
431 print*,
'- OPEN INPUT GRID MOSAIC FILE: ',trim(mosaic_file_input_grid)
432 error=nf90_open(trim(mosaic_file_input_grid),nf90_nowrite,ncid)
433 call
netcdf_err(error,
'opening grid mosaic file')
435 print*,
"- READ NUMBER OF TILES"
436 error=nf90_inq_dimid(ncid,
'ntiles', id_tiles)
438 error=nf90_inquire_dimension(ncid,id_tiles,len=num_tiles_input_grid)
441 error = nf90_close(ncid)
443 print*,
'- NUMBER OF TILES, INPUT MODEL GRID IS ', num_tiles_input_grid
445 if (mod(npets,num_tiles_input_grid) /= 0)
then
446 call
error_handler(
"MUST RUN WITH A TASK COUNT THAT IS A MULTIPLE OF 6.", 1)
453 extra = npets / num_tiles_input_grid
455 allocate(decomptile(2,num_tiles_input_grid))
457 do tile = 1, num_tiles_input_grid
458 decomptile(:,tile)=(/1,extra/)
461 print*,
"- CALL GridCreateMosaic FOR INPUT MODEL GRID"
462 input_grid = esmf_gridcreatemosaic(filename=trim(mosaic_file_input_grid), &
463 regdecompptile=decomptile, &
464 staggerloclist=(/esmf_staggerloc_center, esmf_staggerloc_corner, &
465 esmf_staggerloc_edge1, esmf_staggerloc_edge2/), &
466 indexflag=esmf_index_global, &
467 tilefilepath=trim(orog_dir_input_grid), &
469 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
476 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE."
477 latitude_input_grid = esmf_fieldcreate(input_grid, &
478 typekind=esmf_typekind_r8, &
479 staggerloc=esmf_staggerloc_center, &
480 name=
"input_grid_latitude", &
482 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
485 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE."
486 longitude_input_grid = esmf_fieldcreate(input_grid, &
487 typekind=esmf_typekind_r8, &
488 staggerloc=esmf_staggerloc_center, &
489 name=
"input_grid_longitude", &
491 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
494 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE_S."
495 latitude_s_input_grid = esmf_fieldcreate(input_grid, &
496 typekind=esmf_typekind_r8, &
497 staggerloc=esmf_staggerloc_edge2, &
498 name=
"input_grid_latitude_s", &
500 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
503 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE_S."
504 longitude_s_input_grid = esmf_fieldcreate(input_grid, &
505 typekind=esmf_typekind_r8, &
506 staggerloc=esmf_staggerloc_edge2, &
507 name=
"input_grid_longitude_s", &
509 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
512 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE_W."
513 latitude_w_input_grid = esmf_fieldcreate(input_grid, &
514 typekind=esmf_typekind_r8, &
515 staggerloc=esmf_staggerloc_edge1, &
516 name=
"input_grid_latitude_w", &
518 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
521 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE_W."
522 longitude_w_input_grid = esmf_fieldcreate(input_grid, &
523 typekind=esmf_typekind_r8, &
524 staggerloc=esmf_staggerloc_edge1, &
525 name=
"input_grid_longitude_w", &
527 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
530 the_file = trim(orog_dir_input_grid) // trim(orog_files_input_grid(1))
532 print*,
'- OPEN FIRST INPUT GRID OROGRAPHY FILE: ',trim(the_file)
533 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
534 call
netcdf_err(error,
'opening ororgraphy file')
535 print*,
"- READ GRID DIMENSIONS"
536 error=nf90_inq_dimid(ncid,
'lon', id_dim)
538 error=nf90_inquire_dimension(ncid,id_dim,len=i_input)
540 error=nf90_inq_dimid(ncid,
'lat', id_dim)
542 error=nf90_inquire_dimension(ncid,id_dim,len=j_input)
544 error = nf90_close(ncid)
546 print*,
"- I/J DIMENSIONS OF THE INPUT GRID TILES ", i_input, j_input
548 ip1_input = i_input + 1
549 jp1_input = j_input + 1
551 if (localpet == 0)
then
552 allocate(longitude_one_tile(i_input,j_input))
553 allocate(longitude_s_one_tile(i_input,jp1_input))
554 allocate(longitude_w_one_tile(ip1_input,j_input))
555 allocate(latitude_one_tile(i_input,j_input))
556 allocate(latitude_s_one_tile(i_input,jp1_input))
557 allocate(latitude_w_one_tile(ip1_input,j_input))
558 allocate(landmask_one_tile(i_input,j_input))
560 allocate(longitude_one_tile(0,0))
561 allocate(longitude_s_one_tile(0,0))
562 allocate(longitude_w_one_tile(0,0))
563 allocate(latitude_one_tile(0,0))
564 allocate(latitude_s_one_tile(0,0))
565 allocate(latitude_w_one_tile(0,0))
566 allocate(landmask_one_tile(0,0))
569 do tile = 1, num_tiles_input_grid
570 if (localpet == 0)
then
571 call
get_model_latlons(mosaic_file_input_grid, orog_dir_input_grid, num_tiles_input_grid, tile, &
572 i_input, j_input, ip1_input, jp1_input, latitude_one_tile, &
573 latitude_s_one_tile, latitude_w_one_tile, longitude_one_tile, &
574 longitude_s_one_tile, longitude_w_one_tile)
576 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE. TILE IS: ", tile
577 call esmf_fieldscatter(latitude_input_grid, latitude_one_tile, rootpet=0, tile=tile, rc=error)
578 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
580 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE. TILE IS: ", tile
581 call esmf_fieldscatter(longitude_input_grid, longitude_one_tile, rootpet=0, tile=tile, rc=error)
582 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
584 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE_S. TILE IS: ", tile
585 call esmf_fieldscatter(latitude_s_input_grid, latitude_s_one_tile, rootpet=0, tile=tile, rc=error)
586 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
588 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE_S. TILE IS: ", tile
589 call esmf_fieldscatter(longitude_s_input_grid, longitude_s_one_tile, rootpet=0, tile=tile, rc=error)
590 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
592 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE_W. TILE IS: ", tile
593 call esmf_fieldscatter(latitude_w_input_grid, latitude_w_one_tile, rootpet=0, tile=tile, rc=error)
594 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
596 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE_W. TILE IS: ", tile
597 call esmf_fieldscatter(longitude_w_input_grid, longitude_w_one_tile, rootpet=0, tile=tile, rc=error)
598 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
602 deallocate(longitude_one_tile)
603 deallocate(longitude_s_one_tile)
604 deallocate(longitude_w_one_tile)
605 deallocate(latitude_one_tile)
606 deallocate(latitude_s_one_tile)
607 deallocate(latitude_w_one_tile)
608 deallocate(landmask_one_tile)
623 grib2_file_input_grid
627 integer,
intent(in) :: localpet, npets
629 character(len=250) :: the_file
631 integer :: i, j, rc, clb(2), cub(2)
634 real(esmf_kind_r8),
allocatable :: latitude(:,:)
635 real(esmf_kind_r8),
allocatable :: longitude(:,:)
636 real(esmf_kind_r4),
allocatable :: lat4(:,:), lon4(:,:)
637 real(esmf_kind_r8),
pointer :: lat_src_ptr(:,:)
638 real(esmf_kind_r8),
pointer :: lon_src_ptr(:,:)
639 real(esmf_kind_r8),
pointer :: lat_corner_src_ptr(:,:)
640 real(esmf_kind_r8),
pointer :: lon_corner_src_ptr(:,:)
641 real(esmf_kind_r8) :: deltalon
643 type(esmf_polekind_flag
) :: polekindflag(2)
645 print*,
"- DEFINE INPUT GRID OBJECT FOR INPUT GRIB2 DATA."
647 num_tiles_input_grid = 1
649 the_file = trim(data_dir_input_grid) //
"/" // grib2_file_input_grid
650 if (localpet == 0)
then
651 print*,
'- OPEN AND INVENTORY GRIB2 FILE: ',trim(the_file)
652 rc=grb2_mk_inv(the_file,inv_file)
657 call mpi_barrier(mpi_comm_world, ierr)
659 rc = grb2_inq(the_file,inv_file,
':PRES:',
':surface:',nx=i_input, ny=j_input, &
663 ip1_input = i_input + 1
664 jp1_input = j_input + 1
666 polekindflag(1:2) = esmf_polekind_monopole
668 print*,
"- CALL GridCreate1PeriDim FOR INPUT GRID."
669 input_grid = esmf_gridcreate1peridim(minindex=(/1,1/), &
670 maxindex=(/i_input,j_input/), &
671 polekindflag=polekindflag, &
674 coordsys=esmf_coordsys_sph_deg, &
675 regdecomp=(/1,npets/), &
676 indexflag=esmf_index_global, rc=rc)
677 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
680 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE."
681 latitude_input_grid = esmf_fieldcreate(input_grid, &
682 typekind=esmf_typekind_r8, &
683 staggerloc=esmf_staggerloc_center, &
684 name=
"input_grid_latitude", rc=rc)
685 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
688 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE."
689 longitude_input_grid = esmf_fieldcreate(input_grid, &
690 typekind=esmf_typekind_r8, &
691 staggerloc=esmf_staggerloc_center, &
692 name=
"input_grid_longitude", rc=rc)
693 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
696 allocate(longitude(i_input,j_input))
697 allocate(latitude(i_input,j_input))
700 longitude(i,:) =
real(lon4(i,:),kind=esmf_kind_r8)
704 latitude(:,i) =
real(lat4(:,i),kind=esmf_kind_r8)
707 deallocate(lat4, lon4)
709 deltalon = abs(longitude(2,1)-longitude(1,1))
711 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE."
712 call esmf_fieldscatter(longitude_input_grid, longitude, rootpet=0, rc=rc)
713 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
716 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE."
717 call esmf_fieldscatter(latitude_input_grid, latitude, rootpet=0, rc=rc)
718 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
721 print*,
"- CALL GridAddCoord FOR INPUT GRID."
722 call esmf_gridaddcoord(input_grid, &
723 staggerloc=esmf_staggerloc_center, rc=rc)
724 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
727 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
729 call esmf_gridgetcoord(input_grid, &
730 staggerloc=esmf_staggerloc_center, &
732 farrayptr=lon_src_ptr, rc=rc)
733 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
736 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
738 call esmf_gridgetcoord(input_grid, &
739 staggerloc=esmf_staggerloc_center, &
741 computationallbound=clb, &
742 computationalubound=cub, &
743 farrayptr=lat_src_ptr, rc=rc)
744 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
747 do j = clb(2), cub(2)
748 do i = clb(1), cub(1)
749 lon_src_ptr(i,j) = longitude(i,j)
750 if (lon_src_ptr(i,j) > 360.0_esmf_kind_r8) lon_src_ptr(i,j) = lon_src_ptr(i,j) - 360.0_esmf_kind_r8
751 lat_src_ptr(i,j) = latitude(i,j)
755 print*,
"- CALL GridAddCoord FOR INPUT GRID."
756 call esmf_gridaddcoord(input_grid, &
757 staggerloc=esmf_staggerloc_corner, rc=rc)
758 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
761 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
762 nullify(lon_corner_src_ptr)
763 call esmf_gridgetcoord(input_grid, &
764 staggerloc=esmf_staggerloc_corner, &
766 farrayptr=lon_corner_src_ptr, rc=rc)
767 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
770 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
771 nullify(lat_corner_src_ptr)
772 call esmf_gridgetcoord(input_grid, &
773 staggerloc=esmf_staggerloc_corner, &
775 computationallbound=clb, &
776 computationalubound=cub, &
777 farrayptr=lat_corner_src_ptr, rc=rc)
778 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
781 do j = clb(2), cub(2)
782 do i = clb(1), cub(1)
783 lon_corner_src_ptr(i,j) = longitude(i,1) - (0.5_esmf_kind_r8*deltalon)
784 if (lon_corner_src_ptr(i,j) > 360.0_esmf_kind_r8) lon_corner_src_ptr(i,j) = lon_corner_src_ptr(i,j) - 360.0_esmf_kind_r8
786 lat_corner_src_ptr(i,j) = -90.0_esmf_kind_r8
789 if (j == jp1_input)
then
790 lat_corner_src_ptr(i,j) = +90.0_esmf_kind_r8
793 lat_corner_src_ptr(i,j) = 0.5_esmf_kind_r8 * (latitude(i,j-1)+ latitude(i,j))
797 deallocate(latitude,longitude)
812 use program_setup, only : grib2_file_input_grid, data_dir_input_grid, &
816 character(len=500) :: the_file, temp_file
818 integer,
intent(in) :: localpet, npets
820 integer :: error, extra, i, j, clb(2), cub(2)
822 real(esmf_kind_r4),
allocatable :: latitude_one_tile(:,:), lat_corners(:,:)
823 real(esmf_kind_r4),
allocatable :: longitude_one_tile(:,:), lon_corners(:,:)
824 real(esmf_kind_r8) :: lat_target(i_target,j_target), &
825 lon_target(i_target,j_target)
826 real(esmf_kind_r8) :: deltalon, dx
827 integer :: ncid,id_var, id_dim
828 real(esmf_kind_r8),
pointer :: lat_src_ptr(:,:), lon_src_ptr(:,:)
829 character(len=10000) :: temp_msg
830 character(len=10) :: temp_num =
'NA'
832 num_tiles_input_grid = 1
835 the_file = trim(data_dir_input_grid) //
"/" // grib2_file_input_grid
836 temp_file = trim(fix_dir_input_grid)//
"/latlon_grid3.32769.nc"
838 call esmf_fieldgather(latitude_target_grid, lat_target, rootpet=0, tile=1, rc=error)
839 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
841 call esmf_fieldgather(longitude_target_grid, lon_target, rootpet=0, tile=1, rc=error)
842 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
845 if (localpet==0)
then
846 print*,
'- OPEN AND INVENTORY GRIB2 FILE: ',trim(the_file)
847 error=grb2_mk_inv(the_file,inv_file)
848 if (error /=0) call
error_handler(
"OPENING GRIB2 FILE",error)
849 error = grb2_inq(the_file, inv_file,grid_desc=temp_msg)
850 i = index(temp_msg,
"grid_template=") + len(
"grid_template=")
851 j = index(temp_msg,
":winds(")
852 temp_num=temp_msg(i:j-1)
854 call mpi_barrier(mpi_comm_world, error)
855 call mpi_bcast(temp_num,10,mpi_char,0,mpi_comm_world,error)
859 if (trim(temp_num)==
"3.32769" .or. trim(temp_num)==
"32769")
then
861 input_grid_type =
"rotated_latlon"
863 error=nf90_open(trim(temp_file),nf90_nowrite,ncid)
864 call
netcdf_err(error,
'opening: '//trim(temp_file))
866 error=nf90_inq_dimid(ncid,
'nx', id_dim)
868 error=nf90_inquire_dimension(ncid,id_dim,len=i_input)
871 error=nf90_inq_dimid(ncid,
'ny', id_dim)
873 error=nf90_inquire_dimension(ncid,id_dim,len=j_input)
876 allocate(longitude_one_tile(i_input,j_input))
877 allocate(latitude_one_tile(i_input,j_input))
879 error=nf90_inq_varid(ncid,
'gridlat', id_var)
881 error=nf90_get_var(ncid, id_var, latitude_one_tile)
884 error=nf90_inq_varid(ncid,
'gridlon', id_var)
886 error=nf90_get_var(ncid, id_var, longitude_one_tile)
889 elseif (temp_num ==
"3.0" .or. temp_num ==
"3.30" .or. temp_num==
"30" .or. temp_num ==
"0")
then
891 if (temp_num ==
"3.0" .or. temp_num ==
"0") input_grid_type =
"latlon"
892 if (temp_num ==
"3.30" .or. temp_num==
'30') input_grid_type =
"lambert"
894 error = grb2_inq(the_file,inv_file,
':PRES:',
':surface:',nx=i_input, ny=j_input, &
895 lat=latitude_one_tile, lon=longitude_one_tile)
899 if (localpet==0) print*,
"from file lon(1:10,1) = ", longitude_one_tile(1:10,1)
900 if (localpet==0) print*,
"from file lat(1,1:10) = ", latitude_one_tile(1,1:10)
901 elseif (temp_num==
"NA")
then
903 call
error_handler(
"Grid template number cannot be read from the input file. Please " //&
904 "check that the wgrib2 executable is in your path.", error)
907 call
error_handler(
"Unknown input file grid template number. Must be one of: " //&
908 "3, 3.30, 3.32769", error)
911 print*,
"- I/J DIMENSIONS OF THE INPUT GRID TILES ", i_input, j_input
913 ip1_input = i_input + 1
914 jp1_input = j_input + 1
920 extra = npets / num_tiles_input_grid
922 print*,
"- CALL GridCreateNoPeriDim FOR INPUT MODEL GRID"
923 input_grid = esmf_gridcreatenoperidim(maxindex=(/i_input,j_input/), &
924 indexflag=esmf_index_global, &
926 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
934 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE."
935 latitude_input_grid = esmf_fieldcreate(input_grid, &
936 typekind=esmf_typekind_r8, &
937 staggerloc=esmf_staggerloc_center, &
938 name=
"input_grid_latitude", &
940 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
943 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE."
944 longitude_input_grid = esmf_fieldcreate(input_grid, &
945 typekind=esmf_typekind_r8, &
946 staggerloc=esmf_staggerloc_center, &
947 name=
"input_grid_longitude", &
949 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
952 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE. "
953 call esmf_fieldscatter(latitude_input_grid,
real(latitude_one_tile,esmf_kind_r8), rootpet=0, rc=error)
954 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
957 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE."
958 call esmf_fieldscatter(longitude_input_grid,
real(longitude_one_tile,esmf_kind_r8), rootpet=0, rc=error)
959 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
963 print*,
"- CALL GridAddCoord FOR INPUT GRID."
964 call esmf_gridaddcoord(input_grid, &
965 staggerloc=esmf_staggerloc_center, rc=error)
966 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
970 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
972 call esmf_gridgetcoord(input_grid, &
973 staggerloc=esmf_staggerloc_center, &
975 farrayptr=lon_src_ptr, rc=error)
976 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
979 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
981 call esmf_gridgetcoord(input_grid, &
982 staggerloc=esmf_staggerloc_center, &
984 computationallbound=clb, &
985 computationalubound=cub, &
986 farrayptr=lat_src_ptr, rc=error)
987 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
991 do i = clb(1), cub(1)
992 lon_src_ptr(i,j)=
real(longitude_one_tile(i,j),esmf_kind_r8)
993 lat_src_ptr(i,j)=
real(latitude_one_tile(i,j),esmf_kind_r8)
997 print*,
"- CALL GridAddCoord FOR INPUT GRID."
998 call esmf_gridaddcoord(input_grid, &
999 staggerloc=esmf_staggerloc_corner, rc=error)
1000 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1003 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
1004 nullify(lon_src_ptr)
1005 call esmf_gridgetcoord(input_grid, &
1006 staggerloc=esmf_staggerloc_corner, &
1008 farrayptr=lon_src_ptr, rc=error)
1009 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1012 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
1013 nullify(lat_src_ptr)
1014 call esmf_gridgetcoord(input_grid, &
1015 staggerloc=esmf_staggerloc_corner, &
1017 computationallbound=clb, &
1018 computationalubound=cub, &
1019 farrayptr=lat_src_ptr, rc=error)
1020 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1025 if(trim(input_grid_type)==
"latlon" .or. trim(input_grid_type) ==
"lambert")
then
1026 if (trim(input_grid_type) ==
"latlon")
then
1028 deltalon = abs(longitude_one_tile(2,1)-longitude_one_tile(1,1))
1029 do j = clb(2), cub(2)
1030 do i = clb(1), cub(1)
1032 if (i == ip1_input)
then
1033 lon_src_ptr(i,j) = longitude_one_tile(i_input,1) + (0.5_esmf_kind_r8*deltalon)
1035 lon_src_ptr(i,j) = longitude_one_tile(i,1) - (0.5_esmf_kind_r8*deltalon)
1038 if (j == jp1_input)
then
1039 lat_src_ptr(i,j) = latitude_one_tile(1,j_input) + (0.5_esmf_kind_r8*deltalon)
1041 lat_src_ptr(i,j) = latitude_one_tile(1,j) - (0.5_esmf_kind_r8*deltalon)
1047 if (localpet==0)
then
1055 print*, trim(temp_msg)
1056 i = index(temp_msg,
"Dx ") + len(
"Dx ")
1057 j = index(temp_msg,
" m Dy")
1058 read(temp_msg(i:j-1),
"(F9.6)") dx
1060 call mpi_barrier(mpi_comm_world,error)
1061 call mpi_bcast(dx,1,mpi_real8,0,mpi_comm_world,error)
1064 real(longitude_one_tile, esmf_kind_r8), &
1065 lat_src_ptr, lon_src_ptr, dx, clb, cub)
1067 elseif (trim(input_grid_type) ==
"rotated_latlon")
then
1069 allocate(lon_corners(ip1_input,jp1_input))
1070 allocate(lat_corners(ip1_input,jp1_input))
1072 error=nf90_inq_varid(ncid,
'gridlon_corners', id_var)
1074 error=nf90_get_var(ncid, id_var, lon_corners)
1077 error=nf90_inq_varid(ncid,
'gridlat_corners', id_var)
1079 error=nf90_get_var(ncid, id_var, lat_corners)
1082 do j = clb(2),cub(2)
1083 do i = clb(1), cub(1)
1084 lon_src_ptr(i,j)=
real(lon_corners(i,j),esmf_kind_r8)
1085 lat_src_ptr(i,j)=
real(lat_corners(i,j),esmf_kind_r8)
1089 error= nf90_close(ncid)
1092 nullify(lon_src_ptr)
1093 nullify(lat_src_ptr)
1095 deallocate(longitude_one_tile)
1096 deallocate(latitude_one_tile)
1109 orog_dir_target_grid, &
1110 orog_files_target_grid, &
1115 integer,
intent(in) :: localpet, npets
1117 character(len=500) :: the_file
1119 integer :: error, ncid, extra
1121 integer :: id_dim, id_grid_tiles
1123 integer,
allocatable :: decomptile(:,:)
1124 integer(esmf_kind_i8),
allocatable :: landmask_one_tile(:,:)
1125 integer(esmf_kind_i8),
allocatable :: seamask_one_tile(:,:)
1127 real(esmf_kind_r8),
allocatable :: latitude_one_tile(:,:)
1128 real(esmf_kind_r8),
allocatable :: latitude_s_one_tile(:,:)
1129 real(esmf_kind_r8),
allocatable :: latitude_w_one_tile(:,:)
1130 real(esmf_kind_r8),
allocatable :: longitude_one_tile(:,:)
1131 real(esmf_kind_r8),
allocatable :: longitude_s_one_tile(:,:)
1132 real(esmf_kind_r8),
allocatable :: longitude_w_one_tile(:,:)
1133 real(esmf_kind_r8),
allocatable :: terrain_one_tile(:,:)
1135 lsoil_target = nsoill_out
1137 print*,
'- OPEN TARGET GRID MOSAIC FILE: ',trim(mosaic_file_target_grid)
1138 error=nf90_open(trim(mosaic_file_target_grid),nf90_nowrite,ncid)
1139 call
netcdf_err(error,
'opening grid mosaic file')
1141 print*,
"- READ NUMBER OF TILES"
1142 error=nf90_inq_dimid(ncid,
'ntiles', id_tiles)
1144 error=nf90_inquire_dimension(ncid,id_tiles,len=num_tiles_target_grid)
1146 error=nf90_inq_varid(ncid,
'gridtiles', id_grid_tiles)
1147 call
netcdf_err(error,
'reading gridtiles id')
1148 allocate(tiles_target_grid(num_tiles_target_grid))
1149 tiles_target_grid=
"NULL"
1150 print*,
"- READ TILE NAMES"
1151 error=nf90_get_var(ncid, id_grid_tiles, tiles_target_grid)
1154 error = nf90_close(ncid)
1156 print*,
'- NUMBER OF TILES, TARGET MODEL GRID IS ', num_tiles_target_grid
1158 if (mod(npets,num_tiles_target_grid) /= 0)
then
1159 call
error_handler(
"MUST RUN WITH TASK COUNT THAT IS A MULTIPLE OF # OF TILES.", 1)
1166 the_file = trim(orog_dir_target_grid) // trim(orog_files_target_grid(1))
1168 print*,
'- OPEN FIRST TARGET GRID OROGRAPHY FILE: ',trim(the_file)
1169 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
1170 call
netcdf_err(error,
'opening orography file')
1171 print*,
"- READ GRID DIMENSIONS"
1172 error=nf90_inq_dimid(ncid,
'lon', id_dim)
1174 error=nf90_inquire_dimension(ncid,id_dim,len=i_target)
1176 error=nf90_inq_dimid(ncid,
'lat', id_dim)
1178 error=nf90_inquire_dimension(ncid,id_dim,len=j_target)
1180 error = nf90_close(ncid)
1182 print*,
"- I/J DIMENSIONS OF THE TARGET GRID TILES ", i_target, j_target
1184 ip1_target = i_target + 1
1185 jp1_target = j_target + 1
1191 extra = npets / num_tiles_target_grid
1193 allocate(decomptile(2,num_tiles_target_grid))
1195 do tile = 1, num_tiles_target_grid
1196 decomptile(:,tile)=(/1,extra/)
1199 print*,
"- CALL GridCreateMosaic FOR TARGET GRID"
1200 target_grid = esmf_gridcreatemosaic(filename=trim(mosaic_file_target_grid), &
1201 regdecompptile=decomptile, &
1202 staggerloclist=(/esmf_staggerloc_center, esmf_staggerloc_corner, &
1203 esmf_staggerloc_edge1, esmf_staggerloc_edge2/), &
1204 indexflag=esmf_index_global, &
1205 tilefilepath=trim(orog_dir_target_grid), rc=error)
1206 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1214 print*,
"- CALL FieldCreate FOR TARGET GRID LANDMASK."
1215 landmask_target_grid = esmf_fieldcreate(target_grid, &
1216 typekind=esmf_typekind_i8, &
1217 staggerloc=esmf_staggerloc_center, &
1218 name=
"target_grid_landmask", rc=error)
1219 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1222 print*,
"- CALL FieldCreate FOR TARGET GRID SEAMASK."
1223 seamask_target_grid = esmf_fieldcreate(target_grid, &
1224 typekind=esmf_typekind_i8, &
1225 staggerloc=esmf_staggerloc_center, &
1226 name=
"target_grid_seamask", rc=error)
1227 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1230 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE."
1231 latitude_target_grid = esmf_fieldcreate(target_grid, &
1232 typekind=esmf_typekind_r8, &
1233 staggerloc=esmf_staggerloc_center, &
1234 name=
"target_grid_latitude", rc=error)
1235 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1238 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE_S."
1239 latitude_s_target_grid = esmf_fieldcreate(target_grid, &
1240 typekind=esmf_typekind_r8, &
1241 staggerloc=esmf_staggerloc_edge2, &
1242 name=
"target_grid_latitude_s", rc=error)
1243 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1246 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE_W."
1247 latitude_w_target_grid = esmf_fieldcreate(target_grid, &
1248 typekind=esmf_typekind_r8, &
1249 staggerloc=esmf_staggerloc_edge1, &
1250 name=
"target_grid_latitude_w", &
1252 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1255 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE."
1256 longitude_target_grid = esmf_fieldcreate(target_grid, &
1257 typekind=esmf_typekind_r8, &
1258 staggerloc=esmf_staggerloc_center, &
1259 name=
"target_grid_longitude", &
1261 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1264 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE_S."
1265 longitude_s_target_grid = esmf_fieldcreate(target_grid, &
1266 typekind=esmf_typekind_r8, &
1267 staggerloc=esmf_staggerloc_edge2, &
1268 name=
"target_grid_longitude_s", &
1270 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1273 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE_W."
1274 longitude_w_target_grid = esmf_fieldcreate(target_grid, &
1275 typekind=esmf_typekind_r8, &
1276 staggerloc=esmf_staggerloc_edge1, &
1277 name=
"target_grid_longitude_w", &
1279 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1282 print*,
"- CALL FieldCreate FOR TARGET GRID TERRAIN."
1283 terrain_target_grid = esmf_fieldcreate(target_grid, &
1284 typekind=esmf_typekind_r8, &
1285 staggerloc=esmf_staggerloc_center, &
1286 name=
"target_grid_terrain", &
1288 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1291 if (localpet == 0)
then
1292 allocate(landmask_one_tile(i_target,j_target))
1293 allocate(seamask_one_tile(i_target,j_target))
1294 allocate(latitude_one_tile(i_target,j_target))
1295 allocate(latitude_s_one_tile(i_target,jp1_target))
1296 allocate(latitude_w_one_tile(ip1_target,j_target))
1297 allocate(longitude_one_tile(i_target,j_target))
1298 allocate(longitude_s_one_tile(i_target,jp1_target))
1299 allocate(longitude_w_one_tile(ip1_target,j_target))
1300 allocate(terrain_one_tile(i_target,j_target))
1302 allocate(landmask_one_tile(0,0))
1303 allocate(seamask_one_tile(0,0))
1304 allocate(longitude_one_tile(0,0))
1305 allocate(longitude_s_one_tile(0,0))
1306 allocate(longitude_w_one_tile(0,0))
1307 allocate(latitude_one_tile(0,0))
1308 allocate(latitude_s_one_tile(0,0))
1309 allocate(latitude_w_one_tile(0,0))
1310 allocate(terrain_one_tile(0,0))
1313 do tile = 1, num_tiles_target_grid
1314 if (localpet == 0)
then
1315 the_file = trim(orog_dir_target_grid) // trim(orog_files_target_grid(tile))
1318 seamask_one_tile = 0
1319 where(landmask_one_tile == 0) seamask_one_tile = 1
1320 call
get_model_latlons(mosaic_file_target_grid, orog_dir_target_grid, num_tiles_target_grid, tile, &
1321 i_target, j_target, ip1_target, jp1_target, latitude_one_tile, &
1322 latitude_s_one_tile, latitude_w_one_tile, longitude_one_tile, &
1323 longitude_s_one_tile, longitude_w_one_tile)
1325 print*,
"- CALL FieldScatter FOR TARGET GRID LANDMASK. TILE IS: ", tile
1326 call esmf_fieldscatter(landmask_target_grid, landmask_one_tile, rootpet=0, tile=tile, rc=error)
1327 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1329 print*,
"- CALL FieldScatter FOR TARGET GRID SEAMASK. TILE IS: ", tile
1330 call esmf_fieldscatter(seamask_target_grid, seamask_one_tile, rootpet=0, tile=tile, rc=error)
1331 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1333 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE. TILE IS: ", tile
1334 call esmf_fieldscatter(longitude_target_grid, longitude_one_tile, rootpet=0, tile=tile, rc=error)
1335 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1337 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE_S. TILE IS: ", tile
1338 call esmf_fieldscatter(longitude_s_target_grid, longitude_s_one_tile, rootpet=0, tile=tile, rc=error)
1339 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1341 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE_W. TILE IS: ", tile
1342 call esmf_fieldscatter(longitude_w_target_grid, longitude_w_one_tile, rootpet=0, tile=tile, rc=error)
1343 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1345 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE. TILE IS: ", tile
1346 call esmf_fieldscatter(latitude_target_grid, latitude_one_tile, rootpet=0, tile=tile, rc=error)
1347 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1349 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE_S. TILE IS: ", tile
1350 call esmf_fieldscatter(latitude_s_target_grid, latitude_s_one_tile, rootpet=0, tile=tile, rc=error)
1351 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1353 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE_W. TILE IS: ", tile
1354 call esmf_fieldscatter(latitude_w_target_grid, latitude_w_one_tile, rootpet=0, tile=tile, rc=error)
1355 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1357 print*,
"- CALL FieldScatter FOR TARGET GRID TERRAIN. TILE IS: ", tile
1358 call esmf_fieldscatter(terrain_target_grid, terrain_one_tile, rootpet=0, tile=tile, rc=error)
1359 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1363 deallocate(landmask_one_tile)
1364 deallocate(seamask_one_tile)
1365 deallocate(longitude_one_tile)
1366 deallocate(longitude_s_one_tile)
1367 deallocate(longitude_w_one_tile)
1368 deallocate(latitude_one_tile)
1369 deallocate(latitude_s_one_tile)
1370 deallocate(latitude_w_one_tile)
1371 deallocate(terrain_one_tile)
1394 i_tile, j_tile, ip1_tile, jp1_tile, &
1395 latitude, latitude_s, latitude_w, &
1396 longitude, longitude_s, longitude_w)
1402 character(len=*),
intent(in) :: mosaic_file, orog_dir
1404 integer,
intent(in) :: num_tiles, tile
1405 integer,
intent(in) :: i_tile, j_tile
1406 integer,
intent(in) :: ip1_tile, jp1_tile
1408 real(esmf_kind_r8),
intent(out) :: latitude(i_tile, j_tile)
1409 real(esmf_kind_r8),
intent(out) :: latitude_s(i_tile, jp1_tile)
1410 real(esmf_kind_r8),
intent(out) :: latitude_w(ip1_tile, j_tile)
1411 real(esmf_kind_r8),
intent(out) :: longitude(i_tile, j_tile)
1412 real(esmf_kind_r8),
intent(out) :: longitude_s(i_tile, jp1_tile)
1413 real(esmf_kind_r8),
intent(out) :: longitude_w(ip1_tile, j_tile)
1415 character(len=25) :: grid_files(num_tiles)
1416 character(len=255) :: grid_file
1418 integer :: error, id_var, ncid
1419 integer :: id_dim, nxp, nyp, i, j, ii, jj
1421 real(esmf_kind_r8),
allocatable :: tmpvar(:,:)
1423 print*,
"- READ MODEL GRID FILE"
1425 print*,
'- OPEN MOSAIC FILE: ', trim(mosaic_file)
1426 error=nf90_open(trim(mosaic_file), nf90_nowrite, ncid)
1427 call
netcdf_err(error,
'opening mosaic file')
1429 print*,
"- READ GRID FILE NAMES"
1430 error=nf90_inq_varid(ncid,
'gridfiles', id_var)
1431 call
netcdf_err(error,
'reading gridfiles id')
1432 error=nf90_get_var(ncid, id_var, grid_files)
1435 error = nf90_close(ncid)
1437 grid_file = trim(orog_dir) // trim(grid_files(tile))
1439 print*,
'- OPEN GRID FILE: ', trim(grid_file)
1440 error=nf90_open(trim(grid_file), nf90_nowrite, ncid)
1443 print*,
'- READ NXP ID'
1444 error=nf90_inq_dimid(ncid,
'nxp', id_dim)
1448 error=nf90_inquire_dimension(ncid,id_dim,len=nxp)
1451 print*,
'- READ NYP ID'
1452 error=nf90_inq_dimid(ncid,
'nyp', id_dim)
1456 error=nf90_inquire_dimension(ncid,id_dim,len=nyp)
1459 if ((nxp/2 /= i_tile) .or. (nyp/2 /= j_tile))
then
1463 allocate(tmpvar(nxp,nyp))
1465 print*,
'- READ LONGITUDE ID'
1466 error=nf90_inq_varid(ncid,
'x', id_var)
1467 call
netcdf_err(error,
'reading longitude id')
1469 print*,
'- READ LONGITUDE'
1470 error=nf90_get_var(ncid, id_var, tmpvar)
1477 longitude(i,j) = tmpvar(ii,jj)
1485 longitude_s(i,j) = tmpvar(ii,jj)
1493 longitude_w(i,j) = tmpvar(ii,jj)
1497 print*,
'- READ LATITUDE ID'
1498 error=nf90_inq_varid(ncid,
'y', id_var)
1499 call
netcdf_err(error,
'reading latitude id')
1501 print*,
'- READ LATIITUDE'
1502 error=nf90_get_var(ncid, id_var, tmpvar)
1509 latitude(i,j) = tmpvar(ii,jj)
1517 latitude_s(i,j) = tmpvar(ii,jj)
1525 latitude_w(i,j) = tmpvar(ii,jj)
1531 error = nf90_close(ncid)
1550 real(esmf_kind_r8),
intent(in) :: latitude(i_input,j_input)
1551 real(esmf_kind_r8),
intent(inout),
pointer :: latitude_sw(:,:)
1552 real(esmf_kind_r8),
intent(in) :: longitude(i_input, j_input)
1553 real(esmf_kind_r8),
intent(inout),
pointer :: longitude_sw(:,:)
1554 real(esmf_kind_r8),
intent(in) :: dx
1556 integer,
intent(in) :: clb(2), cub(2)
1558 real(esmf_kind_r8) :: lat1, lon1, lat2, lon2, d, brng
1561 real(esmf_kind_r8),
parameter :: pi = 3.14159265359
1562 real(esmf_kind_r8),
parameter :: r = 6370000.0
1563 real(esmf_kind_r8),
parameter :: bearingindegrees = 135.0
1567 d = sqrt((dx**2.0_esmf_kind_r8)/2.0_esmf_kind_r8)
1569 do j = clb(2),cub(2)
1570 do i = clb(1), cub(1)
1572 if (j == jp1_input .and. i == ip1_input)
then
1573 lat1 = latitude(i_input,j_input) * ( pi / 180.0_esmf_kind_r8 )
1574 lon1 = longitude(i_input,j_input) * ( pi / 180.0_esmf_kind_r8 )
1575 brng = 315.0_esmf_kind_r8 * pi / 180.0_esmf_kind_r8
1576 lat2 = asin( sin( lat1 ) * cos( d / r ) + cos( lat1 ) * sin( d / r ) * cos( brng ) );
1577 lon2= lon1 + atan2( sin( brng ) * sin( d / r ) * cos( lat1 ), cos( d / r ) - sin( lat1 ) * sin( lat2 ) );
1578 latitude_sw(ip1_input,jp1_input) = lat2 * 180.0_esmf_kind_r8 / pi
1579 longitude_sw(ip1_input,jp1_input) = lon2 * 180.0_esmf_kind_r8 / pi
1583 if (i == ip1_input)
then
1584 brng = 225.0_esmf_kind_r8 * pi / 180.0_esmf_kind_r8
1585 lat1 = latitude(i_input,j) * ( pi / 180.0_esmf_kind_r8 )
1586 lon1 = longitude(i_input,j) * ( pi / 180.0_esmf_kind_r8 )
1587 lat2 = asin( sin( lat1 ) * cos( d / r ) + cos( lat1 ) * sin( d / r ) * cos( brng ) );
1588 lon2= lon1 + atan2( sin( brng ) * sin( d / r ) * cos( lat1 ), cos( d / r ) - sin( lat1 ) * sin( lat2 ) );
1589 latitude_sw(ip1_input,j) = lat2 * 180.0_esmf_kind_r8 / pi
1590 longitude_sw(ip1_input,j) = lon2 * 180.0_esmf_kind_r8 / pi
1594 if (j == jp1_input)
then
1595 brng = 45.0_esmf_kind_r8 * pi / 180.0_esmf_kind_r8
1596 lat1 = latitude(i,j_input) * ( pi / 180.0_esmf_kind_r8 )
1597 lon1 = longitude(i,j_input) * ( pi / 180.0_esmf_kind_r8 )
1598 lat2 = asin( sin( lat1 ) * cos( d / r ) + cos( lat1 ) * sin( d / r ) * cos( brng ) );
1599 lon2= lon1 + atan2( sin( brng ) * sin( d / r ) * cos( lat1 ), cos( d / r ) - sin( lat1 ) * sin( lat2 ) );
1600 latitude_sw(i,jp1_input) = lat2 * 180.0_esmf_kind_r8 / pi
1601 longitude_sw(i,jp1_input) = lon2 * 180.0_esmf_kind_r8 / pi
1605 lat1 = latitude(i,j) * ( pi / 180.0_esmf_kind_r8 )
1606 lon1 = longitude(i,j) * ( pi / 180.0_esmf_kind_r8 )
1608 brng = bearingindegrees * ( pi / 180.0_esmf_kind_r8 );
1609 lat2 = asin( sin( lat1 ) * cos( d / r ) + cos( lat1 ) * sin( d / r ) * cos( brng ) );
1610 lon2= lon1 + atan2( sin( brng ) * sin( d / r ) * cos( lat1 ), cos( d / r ) - sin( lat1 ) * sin( lat2 ) );
1612 latitude_sw(i,j) = lat2 * 180.0_esmf_kind_r8 / pi
1613 longitude_sw(i,j) = lon2 * 180.0_esmf_kind_r8 / pi
1635 character(len=*),
intent(in) :: orog_file
1637 integer,
intent(in) :: idim, jdim
1638 integer(esmf_kind_i8),
intent(out) :: mask(idim,jdim)
1640 real(esmf_kind_i8),
intent(out) :: terrain(idim,jdim)
1642 integer :: error, lat, lon
1643 integer :: ncid, id_dim, id_var
1645 real(kind=4),
allocatable :: dummy(:,:)
1647 print*,
"- READ MODEL LAND MASK FILE"
1649 print*,
'- OPEN LAND MASK FILE: ', orog_file
1650 error=nf90_open(orog_file,nf90_nowrite,ncid)
1651 call
netcdf_err(error,
'opening land mask file')
1653 print*,
"- READ I-DIMENSION"
1654 error=nf90_inq_dimid(ncid,
'lon', id_dim)
1656 error=nf90_inquire_dimension(ncid,id_dim,len=lon)
1659 print*,
"- READ J-DIMENSION"
1660 error=nf90_inq_dimid(ncid,
'lat', id_dim)
1662 error=nf90_inquire_dimension(ncid,id_dim,len=lat)
1665 print*,
"- I/J DIMENSIONS: ", lon, lat
1667 if ((lon /= idim) .or. (lat /= jdim))
then
1671 allocate(dummy(idim,jdim))
1673 print*,
"- READ LAND MASK"
1674 error=nf90_inq_varid(ncid,
'slmsk', id_var)
1676 error=nf90_get_var(ncid, id_var, dummy)
1680 print*,
"- READ RAW OROGRAPHY."
1681 error=nf90_inq_varid(ncid,
'orog_raw', id_var)
1682 call
netcdf_err(error,
'reading orog_raw id')
1683 error=nf90_get_var(ncid, id_var, dummy)
1687 error = nf90_close(ncid)
1702 print*,
"- DESTROY MODEL DATA."
1704 if (esmf_fieldiscreated(latitude_s_input_grid))
then
1705 call esmf_fielddestroy(latitude_s_input_grid, rc=rc)
1707 if (esmf_fieldiscreated(latitude_w_input_grid))
then
1708 call esmf_fielddestroy(latitude_w_input_grid, rc=rc)
1710 if (esmf_fieldiscreated(longitude_s_input_grid))
then
1711 call esmf_fielddestroy(longitude_s_input_grid, rc=rc)
1713 if (esmf_fieldiscreated(longitude_w_input_grid))
then
1714 call esmf_fielddestroy(longitude_w_input_grid, rc=rc)
1716 call esmf_fielddestroy(landmask_target_grid, rc=rc)
1717 call esmf_fielddestroy(latitude_target_grid, rc=rc)
1718 call esmf_fielddestroy(latitude_s_target_grid, rc=rc)
1719 call esmf_fielddestroy(latitude_w_target_grid, rc=rc)
1720 call esmf_fielddestroy(longitude_target_grid, rc=rc)
1721 call esmf_fielddestroy(longitude_s_target_grid, rc=rc)
1722 call esmf_fielddestroy(longitude_w_target_grid, rc=rc)
1723 call esmf_fielddestroy(seamask_target_grid, rc=rc)
1724 call esmf_fielddestroy(terrain_target_grid, rc=rc)
1725 call esmf_griddestroy(input_grid, rc=rc)
1726 call esmf_griddestroy(target_grid, rc=rc)
subroutine get_model_mask_terrain(orog_file, idim, jdim, mask, terrain)
Read the model land mask and terrain for a single tile from the orography file.
subroutine, public cleanup_input_target_grid_data
Deallocate all esmf grid objects.
subroutine define_input_grid_gfs_grib2(localpet, npets)
Define input grid object for GFS grib2 data.
subroutine get_cell_corners(latitude, longitude, latitude_sw, longitude_sw, dx, clb, cub)
For grids with equal cell sizes (e.g., lambert conformal), get latitude and longitude of the grid cel...
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
subroutine get_model_latlons(mosaic_file, orog_dir, num_tiles, tile, i_tile, j_tile, ip1_tile, jp1_tile, latitude, latitude_s, latitude_w, longitude, longitude_s, longitude_w)
Read model lat/lons for a single tile from the "grid" specificaton file.
subroutine define_input_grid_grib2(localpet, npets)
Define input grid object for non-GFS grib2 data.
subroutine netcdf_err(err, string)
Error handler for netcdf.
subroutine define_input_grid_gaussian(localpet, npets)
Define grid object for input data on global gaussian grids.
subroutine define_input_grid_mosaic(localpet, npets)
Define input grid for tiled data using the 'mosaic', 'grid' and orography files.
subroutine error_handler(string, rc)
General error handler.
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...
subroutine, public define_input_grid(localpet, npets)
Driver routine to setup the esmf grid object for the input grid.
subroutine, public define_target_grid(localpet, npets)
Setup the esmf grid object for the target grid.