19 character(len=5),
allocatable,
public :: tiles_target_grid(:)
21 character(len=50),
public :: input_grid_type =
"latlon"
25 integer,
public :: lsoil_target = 4
27 integer,
public :: i_input
30 integer,
public :: j_input
33 integer,
public :: ip1_input
35 integer,
public :: jp1_input
37 integer,
public :: i_target
40 integer,
public :: j_target
43 integer,
public :: ip1_target
45 integer,
public :: jp1_target
47 integer,
public :: num_tiles_input_grid
49 integer,
public :: num_tiles_target_grid
52 type(esmf_grid
),
public :: input_grid
54 type(esmf_grid
),
public :: target_grid
57 type(esmf_field
),
public :: latitude_input_grid
59 type(esmf_field
),
public :: longitude_input_grid
61 type(esmf_field
),
public :: latitude_s_input_grid
64 type(esmf_field
),
public :: longitude_s_input_grid
67 type(esmf_field
),
public :: latitude_w_input_grid
70 type(esmf_field
),
public :: longitude_w_input_grid
73 type(esmf_field
),
public :: landmask_target_grid
76 type(esmf_field
),
public :: land_frac_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(input_type) ==
"grib2")
then
153 atm_files_input_grid, &
154 sfc_files_input_grid, &
156 convert_atm, convert_sfc
164 integer,
intent(in) :: npets
166 character(len=250) :: the_file
168 integer :: i, j, rc, clb(2), cub(2), ncid, id_grid
169 integer(sfcio_intkind) :: rc2
170 integer(sigio_intkind) :: rc3
172 real(esmf_kind_r8),
allocatable :: latitude(:,:)
173 real(esmf_kind_r8),
allocatable :: longitude(:,:)
174 real(esmf_kind_r8),
pointer :: lat_src_ptr(:,:)
175 real(esmf_kind_r8),
pointer :: lon_src_ptr(:,:)
176 real(esmf_kind_r8),
pointer :: lat_corner_src_ptr(:,:)
177 real(esmf_kind_r8),
pointer :: lon_corner_src_ptr(:,:)
178 real(esmf_kind_r8) :: deltalon
179 real(esmf_kind_r8),
allocatable :: slat(:), wlat(:)
181 type(nemsio_gfile
) :: gfile
182 type(esmf_polekind_flag
) :: polekindflag(2)
183 type(sfcio_head
) :: sfchead
184 type(sigio_head
) :: sighead
186 print*,
"- DEFINE INPUT GRID OBJECT FOR GAUSSIAN DATA."
188 num_tiles_input_grid = 1
190 if (convert_sfc)
then
191 the_file=trim(data_dir_input_grid) //
"/" // trim(sfc_files_input_grid(1))
192 elseif (convert_atm)
then
193 the_file=trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(1))
196 if (trim(input_type) ==
"gfs_sigio")
then
199 if (convert_sfc)
then
200 print*,
"- OPEN AND READ ", trim(the_file)
201 call sfcio_sropen(21, trim(the_file), rc2)
203 call sfcio_srhead(21, sfchead, rc2)
205 call sfcio_sclose(21, rc2)
206 i_input = sfchead%lonb
207 j_input = sfchead%latb
208 elseif (convert_atm)
then
209 print*,
"- OPEN AND READ ", trim(the_file)
210 call sigio_sropen(21, trim(the_file), rc3)
212 call sigio_srhead(21, sighead, rc3)
214 call sigio_sclose(21, rc3)
215 i_input = sighead%lonb
216 j_input = sighead%latb
219 elseif (trim(input_type) ==
"gaussian_netcdf")
then
221 print*,
'- OPEN AND READ: ',trim(the_file)
222 rc=nf90_open(trim(the_file),nf90_nowrite,ncid)
225 print*,
"- READ grid_xt"
226 rc=nf90_inq_dimid(ncid,
'grid_xt', id_grid)
228 rc=nf90_inquire_dimension(ncid,id_grid,len=i_input)
231 print*,
"- READ grid_yt"
232 rc=nf90_inq_dimid(ncid,
'grid_yt', id_grid)
234 rc=nf90_inquire_dimension(ncid,id_grid,len=j_input)
237 rc = nf90_close(ncid)
241 call nemsio_init(iret=rc)
243 print*,
"- OPEN AND READ ", trim(the_file)
244 call nemsio_open(gfile, the_file,
"read", iret=rc)
247 call nemsio_getfilehead(gfile, iret=rc, dimx=i_input, dimy=j_input)
250 call nemsio_close(gfile)
254 ip1_input = i_input + 1
255 jp1_input = j_input + 1
257 polekindflag(1:2) = esmf_polekind_monopole
259 print*,
"- CALL GridCreate1PeriDim FOR INPUT GRID."
260 input_grid = esmf_gridcreate1peridim(minindex=(/1,1/), &
261 maxindex=(/i_input,j_input/), &
262 polekindflag=polekindflag, &
265 coordsys=esmf_coordsys_sph_deg, &
266 regdecomp=(/1,npets/), &
267 indexflag=esmf_index_global, rc=rc)
268 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
271 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE."
272 latitude_input_grid = esmf_fieldcreate(input_grid, &
273 typekind=esmf_typekind_r8, &
274 staggerloc=esmf_staggerloc_center, &
275 name=
"input_grid_latitude", rc=rc)
276 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
279 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE."
280 longitude_input_grid = esmf_fieldcreate(input_grid, &
281 typekind=esmf_typekind_r8, &
282 staggerloc=esmf_staggerloc_center, &
283 name=
"input_grid_longitude", rc=rc)
284 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
287 allocate(longitude(i_input,j_input))
288 allocate(latitude(i_input,j_input))
290 deltalon = 360.0_esmf_kind_r8 /
real(i_input,kind=esmf_kind_r8)
292 longitude(i,:) =
real((i-1),kind=esmf_kind_r8) * deltalon
295 allocate(slat(j_input))
296 allocate(wlat(j_input))
297 call splat(4, j_input, slat, wlat)
300 latitude(:,i) = 90.0_esmf_kind_r8 - (acos(slat(i))* 180.0_esmf_kind_r8 / &
301 (4.0_esmf_kind_r8*atan(1.0_esmf_kind_r8)))
304 deallocate(slat, wlat)
306 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE."
307 call esmf_fieldscatter(longitude_input_grid, longitude, rootpet=0, rc=rc)
308 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
311 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE."
312 call esmf_fieldscatter(latitude_input_grid, latitude, rootpet=0, rc=rc)
313 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
316 print*,
"- CALL GridAddCoord FOR INPUT GRID."
317 call esmf_gridaddcoord(input_grid, &
318 staggerloc=esmf_staggerloc_center, rc=rc)
319 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
322 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
324 call esmf_gridgetcoord(input_grid, &
325 staggerloc=esmf_staggerloc_center, &
327 farrayptr=lon_src_ptr, rc=rc)
328 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
331 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
333 call esmf_gridgetcoord(input_grid, &
334 staggerloc=esmf_staggerloc_center, &
336 computationallbound=clb, &
337 computationalubound=cub, &
338 farrayptr=lat_src_ptr, rc=rc)
339 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
342 do j = clb(2), cub(2)
343 do i = clb(1), cub(1)
344 lon_src_ptr(i,j) = longitude(i,j)
345 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
346 lat_src_ptr(i,j) = latitude(i,j)
350 print*,
"- CALL GridAddCoord FOR INPUT GRID."
351 call esmf_gridaddcoord(input_grid, &
352 staggerloc=esmf_staggerloc_corner, rc=rc)
353 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
356 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
357 nullify(lon_corner_src_ptr)
358 call esmf_gridgetcoord(input_grid, &
359 staggerloc=esmf_staggerloc_corner, &
361 farrayptr=lon_corner_src_ptr, rc=rc)
362 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
365 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
366 nullify(lat_corner_src_ptr)
367 call esmf_gridgetcoord(input_grid, &
368 staggerloc=esmf_staggerloc_corner, &
370 computationallbound=clb, &
371 computationalubound=cub, &
372 farrayptr=lat_corner_src_ptr, rc=rc)
373 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
376 do j = clb(2), cub(2)
377 do i = clb(1), cub(1)
378 lon_corner_src_ptr(i,j) = longitude(i,1) - (0.5_esmf_kind_r8*deltalon)
379 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
381 lat_corner_src_ptr(i,j) = 90.0_esmf_kind_r8
384 if (j == jp1_input)
then
385 lat_corner_src_ptr(i,j) = -90.0_esmf_kind_r8
388 lat_corner_src_ptr(i,j) = 0.5_esmf_kind_r8 * (latitude(i,j-1)+ latitude(i,j))
392 deallocate(latitude,longitude)
406 orog_dir_input_grid, &
407 orog_files_input_grid
411 character(len=500) :: the_file
413 integer,
intent(in) :: localpet, npets
415 integer :: id_tiles, id_dim, tile
416 integer :: extra, error, ncid
417 integer,
allocatable :: decomptile(:,:)
419 real(esmf_kind_r8),
allocatable :: latitude_one_tile(:,:)
420 real(esmf_kind_r8),
allocatable :: latitude_s_one_tile(:,:)
421 real(esmf_kind_r8),
allocatable :: latitude_w_one_tile(:,:)
422 real(esmf_kind_r8),
allocatable :: longitude_one_tile(:,:)
423 real(esmf_kind_r8),
allocatable :: longitude_s_one_tile(:,:)
424 real(esmf_kind_r8),
allocatable :: longitude_w_one_tile(:,:)
426 print*,
'- OPEN INPUT GRID MOSAIC FILE: ',trim(mosaic_file_input_grid)
427 error=nf90_open(trim(mosaic_file_input_grid),nf90_nowrite,ncid)
428 call
netcdf_err(error,
'opening grid mosaic file')
430 print*,
"- READ NUMBER OF TILES"
431 error=nf90_inq_dimid(ncid,
'ntiles', id_tiles)
433 error=nf90_inquire_dimension(ncid,id_tiles,len=num_tiles_input_grid)
436 error = nf90_close(ncid)
438 print*,
'- NUMBER OF TILES, INPUT MODEL GRID IS ', num_tiles_input_grid
440 if (mod(npets,num_tiles_input_grid) /= 0)
then
441 call
error_handler(
"MUST RUN WITH A TASK COUNT THAT IS A MULTIPLE OF 6.", 1)
448 extra = npets / num_tiles_input_grid
450 allocate(decomptile(2,num_tiles_input_grid))
452 do tile = 1, num_tiles_input_grid
453 decomptile(:,tile)=(/1,extra/)
456 print*,
"- CALL GridCreateMosaic FOR INPUT MODEL GRID"
457 input_grid = esmf_gridcreatemosaic(filename=trim(mosaic_file_input_grid), &
458 regdecompptile=decomptile, &
459 staggerloclist=(/esmf_staggerloc_center, esmf_staggerloc_corner, &
460 esmf_staggerloc_edge1, esmf_staggerloc_edge2/), &
461 indexflag=esmf_index_global, &
462 tilefilepath=trim(orog_dir_input_grid), &
464 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
471 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE."
472 latitude_input_grid = esmf_fieldcreate(input_grid, &
473 typekind=esmf_typekind_r8, &
474 staggerloc=esmf_staggerloc_center, &
475 name=
"input_grid_latitude", &
477 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
480 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE."
481 longitude_input_grid = esmf_fieldcreate(input_grid, &
482 typekind=esmf_typekind_r8, &
483 staggerloc=esmf_staggerloc_center, &
484 name=
"input_grid_longitude", &
486 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
489 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE_S."
490 latitude_s_input_grid = esmf_fieldcreate(input_grid, &
491 typekind=esmf_typekind_r8, &
492 staggerloc=esmf_staggerloc_edge2, &
493 name=
"input_grid_latitude_s", &
495 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
498 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE_S."
499 longitude_s_input_grid = esmf_fieldcreate(input_grid, &
500 typekind=esmf_typekind_r8, &
501 staggerloc=esmf_staggerloc_edge2, &
502 name=
"input_grid_longitude_s", &
504 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
507 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE_W."
508 latitude_w_input_grid = esmf_fieldcreate(input_grid, &
509 typekind=esmf_typekind_r8, &
510 staggerloc=esmf_staggerloc_edge1, &
511 name=
"input_grid_latitude_w", &
513 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
516 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE_W."
517 longitude_w_input_grid = esmf_fieldcreate(input_grid, &
518 typekind=esmf_typekind_r8, &
519 staggerloc=esmf_staggerloc_edge1, &
520 name=
"input_grid_longitude_w", &
522 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
525 the_file = trim(orog_dir_input_grid) // trim(orog_files_input_grid(1))
527 print*,
'- OPEN FIRST INPUT GRID OROGRAPHY FILE: ',trim(the_file)
528 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
529 call
netcdf_err(error,
'opening ororgraphy file')
530 print*,
"- READ GRID DIMENSIONS"
531 error=nf90_inq_dimid(ncid,
'lon', id_dim)
533 error=nf90_inquire_dimension(ncid,id_dim,len=i_input)
535 error=nf90_inq_dimid(ncid,
'lat', id_dim)
537 error=nf90_inquire_dimension(ncid,id_dim,len=j_input)
539 error = nf90_close(ncid)
541 print*,
"- I/J DIMENSIONS OF THE INPUT GRID TILES ", i_input, j_input
543 ip1_input = i_input + 1
544 jp1_input = j_input + 1
546 if (localpet == 0)
then
547 allocate(longitude_one_tile(i_input,j_input))
548 allocate(longitude_s_one_tile(i_input,jp1_input))
549 allocate(longitude_w_one_tile(ip1_input,j_input))
550 allocate(latitude_one_tile(i_input,j_input))
551 allocate(latitude_s_one_tile(i_input,jp1_input))
552 allocate(latitude_w_one_tile(ip1_input,j_input))
554 allocate(longitude_one_tile(0,0))
555 allocate(longitude_s_one_tile(0,0))
556 allocate(longitude_w_one_tile(0,0))
557 allocate(latitude_one_tile(0,0))
558 allocate(latitude_s_one_tile(0,0))
559 allocate(latitude_w_one_tile(0,0))
562 do tile = 1, num_tiles_input_grid
563 if (localpet == 0)
then
564 call
get_model_latlons(mosaic_file_input_grid, orog_dir_input_grid, num_tiles_input_grid, tile, &
565 i_input, j_input, ip1_input, jp1_input, latitude_one_tile, &
566 latitude_s_one_tile, latitude_w_one_tile, longitude_one_tile, &
567 longitude_s_one_tile, longitude_w_one_tile)
569 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE. TILE IS: ", tile
570 call esmf_fieldscatter(latitude_input_grid, latitude_one_tile, rootpet=0, tile=tile, rc=error)
571 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
573 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE. TILE IS: ", tile
574 call esmf_fieldscatter(longitude_input_grid, longitude_one_tile, rootpet=0, tile=tile, rc=error)
575 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
577 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE_S. TILE IS: ", tile
578 call esmf_fieldscatter(latitude_s_input_grid, latitude_s_one_tile, rootpet=0, tile=tile, rc=error)
579 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
581 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE_S. TILE IS: ", tile
582 call esmf_fieldscatter(longitude_s_input_grid, longitude_s_one_tile, rootpet=0, tile=tile, rc=error)
583 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
585 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE_W. TILE IS: ", tile
586 call esmf_fieldscatter(latitude_w_input_grid, latitude_w_one_tile, rootpet=0, tile=tile, rc=error)
587 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
589 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE_W. TILE IS: ", tile
590 call esmf_fieldscatter(longitude_w_input_grid, longitude_w_one_tile, rootpet=0, tile=tile, rc=error)
591 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
595 deallocate(longitude_one_tile)
596 deallocate(longitude_s_one_tile)
597 deallocate(longitude_w_one_tile)
598 deallocate(latitude_one_tile)
599 deallocate(latitude_s_one_tile)
600 deallocate(latitude_w_one_tile)
614 use program_setup, only : grib2_file_input_grid, data_dir_input_grid
618 integer,
intent(in) :: npets
620 character(len=500) :: the_file
622 integer :: i, j, k, jdisc, jgdtn, jpdtn, lugb, lugi
623 integer :: jids(200), jgdt(200), jpdt(200), rc
624 integer :: kgds(200), nret, clb(2), cub(2)
629 real,
allocatable :: rlon(:,:),rlat(:,:),xpts(:,:),ypts(:,:)
630 real,
allocatable :: rlon_corner(:,:),rlat_corner(:,:)
631 real,
allocatable :: rlon_diff(:,:),rlat_diff(:,:)
632 real,
allocatable :: xpts_corner(:,:),ypts_corner(:,:)
633 real(esmf_kind_r8),
allocatable :: latitude(:,:)
634 real(esmf_kind_r8),
allocatable :: longitude(:,:)
635 real(esmf_kind_r8),
allocatable :: latitude_corner(:,:)
636 real(esmf_kind_r8),
allocatable :: longitude_corner(:,:)
637 real(esmf_kind_r8),
pointer :: lat_src_ptr(:,:)
638 real(esmf_kind_r8),
pointer :: lat_corner_src_ptr(:,:)
639 real(esmf_kind_r8),
pointer :: lon_src_ptr(:,:)
640 real(esmf_kind_r8),
pointer :: lon_corner_src_ptr(:,:)
642 type(esmf_polekind_flag
) :: polekindflag(2)
644 type(gribfield
) :: gfld
646 the_file = trim(data_dir_input_grid) //
"/" // grib2_file_input_grid
650 print*,
"- OPEN AND READ INPUT DATA GRIB2 FILE: ", trim(the_file)
651 call baopenr(lugb,the_file,rc)
666 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
668 if (rc /= 0) call
error_handler(
"DEGRIBBING INPUT FILE.", rc)
670 call baclose(lugb,rc)
672 if (gfld%igdtnum == 0)
then
673 print*,
"- INPUT DATA ON LAT/LON GRID."
674 input_grid_type =
'latlon'
675 elseif (gfld%igdtnum == 30)
then
676 print*,
"- INPUT DATA ON LAMBERT CONFORMAL GRID."
677 input_grid_type =
'lambert'
678 elseif (gfld%igdtnum == 32769 .or. gfld%igdtnum == 1)
then
679 print*,
"- INPUT DATA ON ROTATED LAT/LON GRID."
680 input_grid_type =
'rotated_latlon'
686 call
gdt_to_gds(gfld%igdtnum, gfld%igdtmpl, gfld%igdtlen, kgds, i_input, j_input, res)
688 ip1_input = i_input + 1
689 jp1_input = j_input + 1
691 allocate(rlat(i_input,j_input))
692 allocate(rlon(i_input,j_input))
693 allocate(rlat_diff(i_input,j_input))
694 allocate(rlon_diff(i_input,j_input))
695 allocate(xpts(i_input,j_input))
696 allocate(ypts(i_input,j_input))
697 allocate(rlat_corner(ip1_input,jp1_input))
698 allocate(rlon_corner(ip1_input,jp1_input))
699 allocate(xpts_corner(ip1_input,jp1_input))
700 allocate(ypts_corner(ip1_input,jp1_input))
709 print*,
"- COMPUTE GRID CELL CENTER COORDINATES."
710 call gdswzd(kgds,1,(i_input*j_input),-9999.,xpts,ypts,rlon,rlat,nret)
712 if (nret /= (i_input*j_input))
then
713 call
error_handler(
"GDSWZD RETURNED WRONG NUMBER OF POINTS.", 2)
716 deallocate(xpts, ypts)
720 xpts_corner(i,j) = float(i) - 0.5
721 ypts_corner(i,j) = float(j) - 0.5
725 print*,
"- COMPUTE GRID CELL CORNER COORDINATES."
726 call gdswzd(kgds,1,(ip1_input*jp1_input),-9999.,xpts_corner,ypts_corner,rlon_corner,rlat_corner,nret)
728 if (nret /= (ip1_input*jp1_input))
then
729 call
error_handler(
"GDSWZD RETURNED WRONG NUMBER OF POINTS.", 2)
732 deallocate(xpts_corner, ypts_corner)
734 if (gfld%igdtnum == 0)
then
736 print*,
"- CALL GridCreate1PeriDim FOR INPUT GRID."
738 polekindflag(1:2) = esmf_polekind_monopole
740 input_grid = esmf_gridcreate1peridim(minindex=(/1,1/), &
741 maxindex=(/i_input,j_input/), &
742 polekindflag=polekindflag, &
745 coordsys=esmf_coordsys_sph_deg, &
746 regdecomp=(/1,npets/), &
747 indexflag=esmf_index_global, rc=rc)
751 print*,
"- CALL GridCreateNoPeriDim FOR INPUT GRID."
753 input_grid = esmf_gridcreatenoperidim(maxindex=(/i_input,j_input/), &
754 indexflag=esmf_index_global, &
759 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
762 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE."
763 latitude_input_grid = esmf_fieldcreate(input_grid, &
764 typekind=esmf_typekind_r8, &
765 staggerloc=esmf_staggerloc_center, &
766 name=
"input_grid_latitude", rc=rc)
767 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
770 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE."
771 longitude_input_grid = esmf_fieldcreate(input_grid, &
772 typekind=esmf_typekind_r8, &
773 staggerloc=esmf_staggerloc_center, &
774 name=
"input_grid_longitude", rc=rc)
775 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
778 allocate(latitude(i_input,j_input))
779 allocate(longitude(i_input,j_input))
784 deallocate (rlat, rlon)
786 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE."
787 call esmf_fieldscatter(longitude_input_grid, longitude, rootpet=0, rc=rc)
788 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
791 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE."
792 call esmf_fieldscatter(latitude_input_grid, latitude, rootpet=0, rc=rc)
793 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
796 print*,
"- CALL GridAddCoord FOR INPUT GRID."
797 call esmf_gridaddcoord(input_grid, &
798 staggerloc=esmf_staggerloc_center, rc=rc)
799 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
802 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
804 call esmf_gridgetcoord(input_grid, &
805 staggerloc=esmf_staggerloc_center, &
807 farrayptr=lon_src_ptr, rc=rc)
808 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
811 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
813 call esmf_gridgetcoord(input_grid, &
814 staggerloc=esmf_staggerloc_center, &
816 computationallbound=clb, &
817 computationalubound=cub, &
818 farrayptr=lat_src_ptr, rc=rc)
819 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
822 do j = clb(2), cub(2)
823 do i = clb(1), cub(1)
824 lon_src_ptr(i,j) = longitude(i,j)
825 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
826 lat_src_ptr(i,j) = latitude(i,j)
830 deallocate(latitude, longitude)
832 allocate(latitude_corner(ip1_input,jp1_input))
833 allocate(longitude_corner(ip1_input,jp1_input))
835 latitude_corner = rlat_corner
836 longitude_corner = rlon_corner
838 deallocate (rlat_corner, rlon_corner)
840 print*,
"- CALL GridAddCoord FOR INPUT GRID."
841 call esmf_gridaddcoord(input_grid, &
842 staggerloc=esmf_staggerloc_corner, rc=rc)
843 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
846 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD."
847 nullify(lon_corner_src_ptr)
848 call esmf_gridgetcoord(input_grid, &
849 staggerloc=esmf_staggerloc_corner, &
851 farrayptr=lon_corner_src_ptr, rc=rc)
852 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
855 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD."
856 nullify(lat_corner_src_ptr)
857 call esmf_gridgetcoord(input_grid, &
858 staggerloc=esmf_staggerloc_corner, &
860 computationallbound=clb, &
861 computationalubound=cub, &
862 farrayptr=lat_corner_src_ptr, rc=rc)
863 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
866 do j = clb(2), cub(2)
867 do i = clb(1), cub(1)
868 lon_corner_src_ptr(i,j) = longitude_corner(i,j)
869 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
870 lat_corner_src_ptr(i,j) = latitude_corner(i,j)
874 deallocate(latitude_corner, longitude_corner)
887 orog_dir_target_grid, &
888 orog_files_target_grid, &
893 integer,
intent(in) :: localpet, npets
895 character(len=500) :: the_file
897 integer :: error, ncid, extra
899 integer :: id_dim, id_grid_tiles
901 integer,
allocatable :: decomptile(:,:)
902 integer(esmf_kind_i8),
allocatable :: landmask_one_tile(:,:)
903 integer(esmf_kind_i8),
allocatable :: seamask_one_tile(:,:)
905 real(esmf_kind_r8),
allocatable :: land_frac_one_tile(:,:)
906 real(esmf_kind_r8),
allocatable :: latitude_one_tile(:,:)
907 real(esmf_kind_r8),
allocatable :: latitude_s_one_tile(:,:)
908 real(esmf_kind_r8),
allocatable :: latitude_w_one_tile(:,:)
909 real(esmf_kind_r8),
allocatable :: longitude_one_tile(:,:)
910 real(esmf_kind_r8),
allocatable :: longitude_s_one_tile(:,:)
911 real(esmf_kind_r8),
allocatable :: longitude_w_one_tile(:,:)
912 real(esmf_kind_r8),
allocatable :: terrain_one_tile(:,:)
914 lsoil_target = nsoill_out
916 print*,
'- OPEN TARGET GRID MOSAIC FILE: ',trim(mosaic_file_target_grid)
917 error=nf90_open(trim(mosaic_file_target_grid),nf90_nowrite,ncid)
918 call
netcdf_err(error,
'opening grid mosaic file')
920 print*,
"- READ NUMBER OF TILES"
921 error=nf90_inq_dimid(ncid,
'ntiles', id_tiles)
923 error=nf90_inquire_dimension(ncid,id_tiles,len=num_tiles_target_grid)
925 error=nf90_inq_varid(ncid,
'gridtiles', id_grid_tiles)
926 call
netcdf_err(error,
'reading gridtiles id')
927 allocate(tiles_target_grid(num_tiles_target_grid))
928 tiles_target_grid=
"NULL"
929 print*,
"- READ TILE NAMES"
930 error=nf90_get_var(ncid, id_grid_tiles, tiles_target_grid)
933 error = nf90_close(ncid)
935 print*,
'- NUMBER OF TILES, TARGET MODEL GRID IS ', num_tiles_target_grid
937 if (mod(npets,num_tiles_target_grid) /= 0)
then
938 call
error_handler(
"MUST RUN WITH TASK COUNT THAT IS A MULTIPLE OF # OF TILES.", 1)
945 the_file = trim(orog_dir_target_grid) // trim(orog_files_target_grid(1))
947 print*,
'- OPEN FIRST TARGET GRID OROGRAPHY FILE: ',trim(the_file)
948 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
949 call
netcdf_err(error,
'opening orography file')
950 print*,
"- READ GRID DIMENSIONS"
951 error=nf90_inq_dimid(ncid,
'lon', id_dim)
953 error=nf90_inquire_dimension(ncid,id_dim,len=i_target)
955 error=nf90_inq_dimid(ncid,
'lat', id_dim)
957 error=nf90_inquire_dimension(ncid,id_dim,len=j_target)
959 error = nf90_close(ncid)
961 print*,
"- I/J DIMENSIONS OF THE TARGET GRID TILES ", i_target, j_target
963 ip1_target = i_target + 1
964 jp1_target = j_target + 1
970 extra = npets / num_tiles_target_grid
972 allocate(decomptile(2,num_tiles_target_grid))
974 do tile = 1, num_tiles_target_grid
975 decomptile(:,tile)=(/1,extra/)
978 print*,
"- CALL GridCreateMosaic FOR TARGET GRID"
979 target_grid = esmf_gridcreatemosaic(filename=trim(mosaic_file_target_grid), &
980 regdecompptile=decomptile, &
981 staggerloclist=(/esmf_staggerloc_center, esmf_staggerloc_corner, &
982 esmf_staggerloc_edge1, esmf_staggerloc_edge2/), &
983 indexflag=esmf_index_global, &
984 tilefilepath=trim(orog_dir_target_grid), rc=error)
985 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
993 print*,
"- CALL FieldCreate FOR TARGET GRID LAND FRACTION."
994 land_frac_target_grid = esmf_fieldcreate(target_grid, &
995 typekind=esmf_typekind_r8, &
996 staggerloc=esmf_staggerloc_center, &
997 name=
"target_grid_landmask", rc=error)
998 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1001 print*,
"- CALL FieldCreate FOR TARGET GRID LANDMASK."
1002 landmask_target_grid = esmf_fieldcreate(target_grid, &
1003 typekind=esmf_typekind_i8, &
1004 staggerloc=esmf_staggerloc_center, &
1005 name=
"target_grid_landmask", rc=error)
1006 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1009 print*,
"- CALL FieldCreate FOR TARGET GRID SEAMASK."
1010 seamask_target_grid = esmf_fieldcreate(target_grid, &
1011 typekind=esmf_typekind_i8, &
1012 staggerloc=esmf_staggerloc_center, &
1013 name=
"target_grid_seamask", rc=error)
1014 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1017 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE."
1018 latitude_target_grid = esmf_fieldcreate(target_grid, &
1019 typekind=esmf_typekind_r8, &
1020 staggerloc=esmf_staggerloc_center, &
1021 name=
"target_grid_latitude", rc=error)
1022 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1025 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE_S."
1026 latitude_s_target_grid = esmf_fieldcreate(target_grid, &
1027 typekind=esmf_typekind_r8, &
1028 staggerloc=esmf_staggerloc_edge2, &
1029 name=
"target_grid_latitude_s", rc=error)
1030 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1033 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE_W."
1034 latitude_w_target_grid = esmf_fieldcreate(target_grid, &
1035 typekind=esmf_typekind_r8, &
1036 staggerloc=esmf_staggerloc_edge1, &
1037 name=
"target_grid_latitude_w", &
1039 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1042 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE."
1043 longitude_target_grid = esmf_fieldcreate(target_grid, &
1044 typekind=esmf_typekind_r8, &
1045 staggerloc=esmf_staggerloc_center, &
1046 name=
"target_grid_longitude", &
1048 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1051 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE_S."
1052 longitude_s_target_grid = esmf_fieldcreate(target_grid, &
1053 typekind=esmf_typekind_r8, &
1054 staggerloc=esmf_staggerloc_edge2, &
1055 name=
"target_grid_longitude_s", &
1057 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1060 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE_W."
1061 longitude_w_target_grid = esmf_fieldcreate(target_grid, &
1062 typekind=esmf_typekind_r8, &
1063 staggerloc=esmf_staggerloc_edge1, &
1064 name=
"target_grid_longitude_w", &
1066 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1069 print*,
"- CALL FieldCreate FOR TARGET GRID TERRAIN."
1070 terrain_target_grid = esmf_fieldcreate(target_grid, &
1071 typekind=esmf_typekind_r8, &
1072 staggerloc=esmf_staggerloc_center, &
1073 name=
"target_grid_terrain", &
1075 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1078 if (localpet == 0)
then
1079 allocate(land_frac_one_tile(i_target,j_target))
1080 allocate(landmask_one_tile(i_target,j_target))
1081 allocate(seamask_one_tile(i_target,j_target))
1082 allocate(latitude_one_tile(i_target,j_target))
1083 allocate(latitude_s_one_tile(i_target,jp1_target))
1084 allocate(latitude_w_one_tile(ip1_target,j_target))
1085 allocate(longitude_one_tile(i_target,j_target))
1086 allocate(longitude_s_one_tile(i_target,jp1_target))
1087 allocate(longitude_w_one_tile(ip1_target,j_target))
1088 allocate(terrain_one_tile(i_target,j_target))
1090 allocate(land_frac_one_tile(0,0))
1091 allocate(landmask_one_tile(0,0))
1092 allocate(seamask_one_tile(0,0))
1093 allocate(longitude_one_tile(0,0))
1094 allocate(longitude_s_one_tile(0,0))
1095 allocate(longitude_w_one_tile(0,0))
1096 allocate(latitude_one_tile(0,0))
1097 allocate(latitude_s_one_tile(0,0))
1098 allocate(latitude_w_one_tile(0,0))
1099 allocate(terrain_one_tile(0,0))
1102 do tile = 1, num_tiles_target_grid
1103 if (localpet == 0)
then
1104 the_file = trim(orog_dir_target_grid) // trim(orog_files_target_grid(tile))
1106 terrain_one_tile, land_frac_one_tile)
1108 seamask_one_tile = 0
1109 where(floor(land_frac_one_tile) == 0) seamask_one_tile = 1
1110 landmask_one_tile = 0
1111 where(ceiling(land_frac_one_tile) == 1) landmask_one_tile = 1
1113 call
get_model_latlons(mosaic_file_target_grid, orog_dir_target_grid, num_tiles_target_grid, tile, &
1114 i_target, j_target, ip1_target, jp1_target, latitude_one_tile, &
1115 latitude_s_one_tile, latitude_w_one_tile, longitude_one_tile, &
1116 longitude_s_one_tile, longitude_w_one_tile)
1118 print*,
"- CALL FieldScatter FOR TARGET GRID LAND FRACTION. TILE IS: ", tile
1119 call esmf_fieldscatter(land_frac_target_grid, land_frac_one_tile, rootpet=0, tile=tile, rc=error)
1120 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1122 print*,
"- CALL FieldScatter FOR TARGET GRID LANDMASK. TILE IS: ", tile
1123 call esmf_fieldscatter(landmask_target_grid, landmask_one_tile, rootpet=0, tile=tile, rc=error)
1124 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1126 print*,
"- CALL FieldScatter FOR TARGET GRID SEAMASK. TILE IS: ", tile
1127 call esmf_fieldscatter(seamask_target_grid, seamask_one_tile, rootpet=0, tile=tile, rc=error)
1128 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1130 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE. TILE IS: ", tile
1131 call esmf_fieldscatter(longitude_target_grid, longitude_one_tile, rootpet=0, tile=tile, rc=error)
1132 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1134 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE_S. TILE IS: ", tile
1135 call esmf_fieldscatter(longitude_s_target_grid, longitude_s_one_tile, rootpet=0, tile=tile, rc=error)
1136 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1138 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE_W. TILE IS: ", tile
1139 call esmf_fieldscatter(longitude_w_target_grid, longitude_w_one_tile, rootpet=0, tile=tile, rc=error)
1140 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1142 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE. TILE IS: ", tile
1143 call esmf_fieldscatter(latitude_target_grid, latitude_one_tile, rootpet=0, tile=tile, rc=error)
1144 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1146 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE_S. TILE IS: ", tile
1147 call esmf_fieldscatter(latitude_s_target_grid, latitude_s_one_tile, rootpet=0, tile=tile, rc=error)
1148 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1150 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE_W. TILE IS: ", tile
1151 call esmf_fieldscatter(latitude_w_target_grid, latitude_w_one_tile, rootpet=0, tile=tile, rc=error)
1152 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1154 print*,
"- CALL FieldScatter FOR TARGET GRID TERRAIN. TILE IS: ", tile
1155 call esmf_fieldscatter(terrain_target_grid, terrain_one_tile, rootpet=0, tile=tile, rc=error)
1156 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1160 deallocate(land_frac_one_tile)
1161 deallocate(landmask_one_tile)
1162 deallocate(seamask_one_tile)
1163 deallocate(longitude_one_tile)
1164 deallocate(longitude_s_one_tile)
1165 deallocate(longitude_w_one_tile)
1166 deallocate(latitude_one_tile)
1167 deallocate(latitude_s_one_tile)
1168 deallocate(latitude_w_one_tile)
1169 deallocate(terrain_one_tile)
1192 i_tile, j_tile, ip1_tile, jp1_tile, &
1193 latitude, latitude_s, latitude_w, &
1194 longitude, longitude_s, longitude_w)
1200 character(len=*),
intent(in) :: mosaic_file, orog_dir
1202 integer,
intent(in) :: num_tiles, tile
1203 integer,
intent(in) :: i_tile, j_tile
1204 integer,
intent(in) :: ip1_tile, jp1_tile
1206 real(esmf_kind_r8),
intent(out) :: latitude(i_tile, j_tile)
1207 real(esmf_kind_r8),
intent(out) :: latitude_s(i_tile, jp1_tile)
1208 real(esmf_kind_r8),
intent(out) :: latitude_w(ip1_tile, j_tile)
1209 real(esmf_kind_r8),
intent(out) :: longitude(i_tile, j_tile)
1210 real(esmf_kind_r8),
intent(out) :: longitude_s(i_tile, jp1_tile)
1211 real(esmf_kind_r8),
intent(out) :: longitude_w(ip1_tile, j_tile)
1213 character(len=50) :: grid_files(num_tiles)
1214 character(len=255) :: grid_file
1216 integer :: error, id_var, ncid
1217 integer :: id_dim, nxp, nyp, i, j, ii, jj
1219 real(esmf_kind_r8),
allocatable :: tmpvar(:,:)
1221 print*,
"- READ MODEL GRID FILE"
1223 print*,
'- OPEN MOSAIC FILE: ', trim(mosaic_file)
1224 error=nf90_open(trim(mosaic_file), nf90_nowrite, ncid)
1225 call
netcdf_err(error,
'opening mosaic file')
1227 print*,
"- READ GRID FILE NAMES"
1228 error=nf90_inq_varid(ncid,
'gridfiles', id_var)
1229 call
netcdf_err(error,
'reading gridfiles id')
1230 error=nf90_get_var(ncid, id_var, grid_files)
1233 error = nf90_close(ncid)
1235 grid_file = trim(orog_dir) // trim(grid_files(tile))
1237 print*,
'- OPEN GRID FILE: ', trim(grid_file)
1238 error=nf90_open(trim(grid_file), nf90_nowrite, ncid)
1241 print*,
'- READ NXP ID'
1242 error=nf90_inq_dimid(ncid,
'nxp', id_dim)
1246 error=nf90_inquire_dimension(ncid,id_dim,len=nxp)
1249 print*,
'- READ NYP ID'
1250 error=nf90_inq_dimid(ncid,
'nyp', id_dim)
1254 error=nf90_inquire_dimension(ncid,id_dim,len=nyp)
1257 if ((nxp/2 /= i_tile) .or. (nyp/2 /= j_tile))
then
1261 allocate(tmpvar(nxp,nyp))
1263 print*,
'- READ LONGITUDE ID'
1264 error=nf90_inq_varid(ncid,
'x', id_var)
1265 call
netcdf_err(error,
'reading longitude id')
1267 print*,
'- READ LONGITUDE'
1268 error=nf90_get_var(ncid, id_var, tmpvar)
1275 longitude(i,j) = tmpvar(ii,jj)
1283 longitude_s(i,j) = tmpvar(ii,jj)
1291 longitude_w(i,j) = tmpvar(ii,jj)
1295 print*,
'- READ LATITUDE ID'
1296 error=nf90_inq_varid(ncid,
'y', id_var)
1297 call
netcdf_err(error,
'reading latitude id')
1299 print*,
'- READ LATIITUDE'
1300 error=nf90_get_var(ncid, id_var, tmpvar)
1307 latitude(i,j) = tmpvar(ii,jj)
1315 latitude_s(i,j) = tmpvar(ii,jj)
1323 latitude_w(i,j) = tmpvar(ii,jj)
1329 error = nf90_close(ncid)
1349 character(len=*),
intent(in) :: orog_file
1351 integer,
intent(in) :: idim, jdim
1352 integer(esmf_kind_i8),
intent(out) :: mask(idim,jdim)
1354 real(esmf_kind_i8),
intent(out) :: terrain(idim,jdim)
1355 real(esmf_kind_i8),
intent(out) :: land_frac(idim,jdim)
1357 integer :: error, lat, lon
1358 integer :: ncid, id_dim, id_var
1360 real(kind=4),
allocatable :: dummy(:,:)
1362 print*,
"- READ MODEL LAND MASK FILE"
1364 print*,
'- OPEN LAND MASK FILE: ', orog_file
1365 error=nf90_open(orog_file,nf90_nowrite,ncid)
1366 call
netcdf_err(error,
'opening land mask file')
1368 print*,
"- READ I-DIMENSION"
1369 error=nf90_inq_dimid(ncid,
'lon', id_dim)
1371 error=nf90_inquire_dimension(ncid,id_dim,len=lon)
1374 print*,
"- READ J-DIMENSION"
1375 error=nf90_inq_dimid(ncid,
'lat', id_dim)
1377 error=nf90_inquire_dimension(ncid,id_dim,len=lat)
1380 print*,
"- I/J DIMENSIONS: ", lon, lat
1382 if ((lon /= idim) .or. (lat /= jdim))
then
1386 allocate(dummy(idim,jdim))
1388 print*,
"- READ LAND MASK"
1389 error=nf90_inq_varid(ncid,
'slmsk', id_var)
1391 error=nf90_get_var(ncid, id_var, dummy)
1395 print*,
"- READ RAW OROGRAPHY."
1396 error=nf90_inq_varid(ncid,
'orog_raw', id_var)
1397 call
netcdf_err(error,
'reading orog_raw id')
1398 error=nf90_get_var(ncid, id_var, dummy)
1402 print*,
"- READ LAND FRACTION."
1403 error=nf90_inq_varid(ncid,
'land_frac', id_var)
1404 call
netcdf_err(error,
'reading land_frac id')
1405 error=nf90_get_var(ncid, id_var, dummy)
1409 error = nf90_close(ncid)
1424 print*,
"- DESTROY MODEL DATA."
1426 call esmf_fielddestroy(latitude_input_grid,rc=rc)
1427 call esmf_fielddestroy(longitude_input_grid,rc=rc)
1428 if (esmf_fieldiscreated(latitude_s_input_grid))
then
1429 call esmf_fielddestroy(latitude_s_input_grid, rc=rc)
1431 if (esmf_fieldiscreated(latitude_w_input_grid))
then
1432 call esmf_fielddestroy(latitude_w_input_grid, rc=rc)
1434 if (esmf_fieldiscreated(longitude_s_input_grid))
then
1435 call esmf_fielddestroy(longitude_s_input_grid, rc=rc)
1437 if (esmf_fieldiscreated(longitude_w_input_grid))
then
1438 call esmf_fielddestroy(longitude_w_input_grid, rc=rc)
1440 call esmf_fielddestroy(land_frac_target_grid, rc=rc)
1441 call esmf_fielddestroy(landmask_target_grid, rc=rc)
1442 call esmf_fielddestroy(latitude_target_grid, rc=rc)
1443 if (esmf_fieldiscreated(latitude_s_target_grid))
then
1444 call esmf_fielddestroy(latitude_s_target_grid, rc=rc)
1446 if (esmf_fieldiscreated(latitude_w_target_grid))
then
1447 call esmf_fielddestroy(latitude_w_target_grid, rc=rc)
1449 call esmf_fielddestroy(longitude_target_grid, rc=rc)
1450 if (esmf_fieldiscreated(longitude_s_target_grid))
then
1451 call esmf_fielddestroy(longitude_s_target_grid, rc=rc)
1453 if (esmf_fieldiscreated(longitude_w_target_grid))
then
1454 call esmf_fielddestroy(longitude_w_target_grid, rc=rc)
1456 call esmf_fielddestroy(seamask_target_grid, rc=rc)
1457 call esmf_fielddestroy(terrain_target_grid, rc=rc)
1458 call esmf_griddestroy(input_grid, rc=rc)
1459 call esmf_griddestroy(target_grid, rc=rc)
1474 subroutine gdt_to_gds(igdtnum, igdstmpl, igdtlen, kgds, ni, nj, res)
1478 integer,
intent(in ) :: igdtnum, igdtlen, igdstmpl(igdtlen)
1479 integer,
intent( out) :: kgds(200), ni, nj
1480 integer :: iscale, i
1482 real,
intent( out) :: res
1484 real :: clatr, slatr, clonr, dpr, slat
1485 real :: slat0, clat0, clat, clon, rlat
1486 real :: rlon0, rlon, hs
1490 if (igdtnum.eq.32769)
then
1492 iscale=igdstmpl(10)*igdstmpl(11)
1493 if (iscale == 0) iscale = 1e6
1500 kgds(4)=nint(float(igdstmpl(12))/float(iscale)*1000.)
1502 kgds(5)=nint(float(igdstmpl(13))/float(iscale)*1000.)
1506 if (igdstmpl(1)==2 ) kgds(6)=64
1507 if ( btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5) ) kgds(6)=kgds(6)+128
1508 if ( btest(igdstmpl(14),3) ) kgds(6)=kgds(6)+8
1510 kgds(7)=nint(float(igdstmpl(15))/float(iscale)*1000.)
1512 kgds(8)=nint(float(igdstmpl(16))/float(iscale)*1000.)
1514 kgds(9)=nint(float(igdstmpl(17))/float(iscale)*1000.)
1516 kgds(10)=nint(float(igdstmpl(18))/float(iscale)*1000.)
1520 if (btest(igdstmpl(19),7)) kgds(11) = 128
1521 if (btest(igdstmpl(19),6)) kgds(11) = kgds(11) + 64
1522 if (btest(igdstmpl(19),5)) kgds(11) = kgds(11) + 32
1524 kgds(12)=nint(float(igdstmpl(20))/float(iscale)*1000.)
1526 kgds(13)=nint(float(igdstmpl(21))/float(iscale)*1000.)
1532 res = ((float(kgds(9)) / 1000.0) + (float(kgds(10)) / 1000.0)) &
1535 elseif (igdtnum.eq.1)
then
1538 iscale=igdstmpl(10)*igdstmpl(11)
1539 if (iscale == 0) iscale = 1e6
1547 kgds(4)=nint(float(igdstmpl(12))/float(iscale)*1000.)
1549 kgds(5)=nint(float(igdstmpl(13))/float(iscale)*1000.)
1553 if (igdstmpl(1)==2 ) kgds(6)=64
1554 if ( btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5) ) kgds(6)=kgds(6)+128
1555 if ( btest(igdstmpl(14),3) ) kgds(6)=kgds(6)+8
1557 kgds(7)=nint(float(igdstmpl(20))/float(iscale)*1000.)
1559 kgds(8)=nint(float(igdstmpl(21))/float(iscale)*1000.)
1561 kgds(7) = kgds(7) + 90000.0
1562 print*,
"INPUT LAT, LON CENTER ", kgds(7), kgds(8)
1564 dpr = 180.0/3.1415926
1565 clatr=cos((float(kgds(4))/1000.0)/dpr)
1566 slatr=sin((float(kgds(4))/1000.0)/dpr)
1567 clonr=cos((float(kgds(5))/1000.0)/dpr)
1568 slat0=sin((float(kgds(7))/1000.0)/dpr)
1569 clat0=cos((float(kgds(7))/1000.0)/dpr)
1571 slat=clat0*slatr+slat0*clatr*clonr
1572 clat=sqrt(1-slat**2)
1573 clon=(clat0*clatr*clonr-slat0*slatr)/clat
1574 clon=min(max(clon,-1.0),1.0)
1578 rlon0=float(kgds(8))/1000.0
1580 if ((kgds(5)-kgds(8)) > 0)
then
1586 rlon = mod(rlon0+hs*dpr*acos(clon)+3600,360.0)
1588 kgds(4)=nint(rlat*1000.)
1589 kgds(5)=nint(rlon*1000.)
1591 kgds(12)=nint(float(igdstmpl(15))/float(iscale)*1000.)
1593 kgds(13)=nint(float(igdstmpl(16))/float(iscale)*1000.)
1596 clatr=cos((float(kgds(12))/1000.0)/dpr)
1597 slatr=sin((float(kgds(12))/1000.0)/dpr)
1598 clonr=cos((float(kgds(13))/1000.0)/dpr)
1600 slat=clat0*slatr+slat0*clatr*clonr
1603 clat=sqrt(1-slat**2)
1604 clon=(clat0*clatr*clonr-slat0*slatr)/clat
1605 clon=min(max(clon,-1.0),1.0)
1607 if ((kgds(13)-kgds(8)) > 0)
then
1613 rlon = mod(rlon0+hs*dpr*acos(clon)+3600,360.0)
1615 print*,
'got here last point ',kgds(12), kgds(13)
1616 print*,
'got here last point rotated ', rlat, rlon
1618 kgds(12)=nint(rlat*1000.)
1619 kgds(13)=nint(rlon*1000.)
1621 kgds(9)=igdstmpl(17)
1622 kgds(10)=igdstmpl(18)
1625 if (btest(igdstmpl(19),7)) kgds(11) = 128
1626 if (btest(igdstmpl(19),6)) kgds(11) = kgds(11) + 64
1627 if (btest(igdstmpl(19),5)) kgds(11) = kgds(11) + 32
1632 res = ((float(kgds(9)) / 1.e6) + (float(kgds(10)) / 1.e6)) &
1637 print*,
'final kgds ',i,kgds(i)
1641 elseif(igdtnum==30)
then
1650 kgds(4) = nint(float(igdstmpl(10))/1000.0)
1651 kgds(5) = nint(float(igdstmpl(11))/1000.0)
1654 if (igdstmpl(1)==2 ) kgds(6)=64
1655 if ( btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5) ) kgds(6)=kgds(6)+128
1656 if ( btest(igdstmpl(12),3) ) kgds(6)=kgds(6)+8
1658 kgds(7) = nint(float(igdstmpl(14))/1000.0)
1659 kgds(8) = nint(float(igdstmpl(15))/1000.0)
1660 kgds(9) = nint(float(igdstmpl(16))/1000.0)
1664 if (btest(igdstmpl(18),7)) kgds(11) = 128
1665 if (btest(igdstmpl(18),6)) kgds(11) = kgds(11) + 64
1666 if (btest(igdstmpl(18),5)) kgds(11) = kgds(11) + 32
1668 kgds(12) = nint(float(igdstmpl(19))/1000.0)
1669 kgds(13) = nint(float(igdstmpl(20))/1000.0)
1673 elseif(igdtnum==0)
then
1675 iscale=igdstmpl(10)*igdstmpl(11)
1676 if (iscale == 0) iscale = 1e6
1682 kgds(4)=nint(float(igdstmpl(12))/float(iscale)*1000.)
1683 kgds(5)=nint(float(igdstmpl(13))/float(iscale)*1000.)
1686 if (igdstmpl(1)==2 ) kgds(6)=64
1687 if ( btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5) ) kgds(6)=kgds(6)+128
1688 if ( btest(igdstmpl(14),3) ) kgds(6)=kgds(6)+8
1690 kgds(7)=nint(float(igdstmpl(15))/float(iscale)*1000.)
1691 kgds(8)=nint(float(igdstmpl(16))/float(iscale)*1000.)
1692 kgds(9)=nint(float(igdstmpl(17))/float(iscale)*1000.)
1693 kgds(10)=nint(float(igdstmpl(18))/float(iscale)*1000.)
1696 if (btest(igdstmpl(19),7)) kgds(11) = 128
1697 if (btest(igdstmpl(19),6)) kgds(11) = kgds(11) + 64
1698 if (btest(igdstmpl(19),5)) kgds(11) = kgds(11) + 32
subroutine get_model_mask_terrain(orog_file, idim, jdim, mask, terrain, land_frac)
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_grib2(npets)
Define input grid object for grib2 input data.
subroutine gdt_to_gds(igdtnum, igdstmpl, igdtlen, kgds, ni, nj, res)
Convert the GRIB2 grid description template to to the GRIB1 grid description section.
subroutine define_input_grid_gaussian(npets)
Define grid object for input data on global gaussian grids.
subroutine netcdf_err(err, string)
Error handler for netcdf.
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 error_handler(string, rc)
General error handler.
subroutine define_input_grid_mosaic(localpet, npets)
Define input grid for tiled data using the 'mosaic', 'grid' and orography files.
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.