121 integer,
intent(in) :: localpet, npets
123 if (trim(
input_type) ==
"gaussian_nemsio" .or. &
124 trim(
input_type) ==
"gfs_gaussian_nemsio" .or. &
163 integer,
intent(in) :: localpet, npets
165 character(len=250) :: the_file
167 integer :: i, j, rc, clb(2), cub(2), ncid, id_grid
168 integer(sfcio_intkind) :: rc2
169 integer(sigio_intkind) :: rc3
171 real(esmf_kind_r8),
allocatable :: latitude(:,:)
172 real(esmf_kind_r8),
allocatable :: longitude(:,:)
173 real(esmf_kind_r8),
pointer :: lat_src_ptr(:,:)
174 real(esmf_kind_r8),
pointer :: lon_src_ptr(:,:)
175 real(esmf_kind_r8),
pointer :: lat_corner_src_ptr(:,:)
176 real(esmf_kind_r8),
pointer :: lon_corner_src_ptr(:,:)
177 real(esmf_kind_r8) :: deltalon
178 real(esmf_kind_r8),
allocatable :: slat(:), wlat(:)
180 type(nemsio_gfile) :: gfile
181 type(esmf_polekind_flag) :: polekindflag(2)
182 type(sfcio_head) :: sfchead
183 type(sigio_head) :: sighead
185 print*,
"- DEFINE INPUT GRID OBJECT FOR GAUSSIAN DATA." 199 print*,
"- OPEN AND READ ", trim(the_file)
200 call sfcio_sropen(21, trim(the_file), rc2)
202 call sfcio_srhead(21, sfchead, rc2)
204 call sfcio_sclose(21, rc2)
208 print*,
"- OPEN AND READ ", trim(the_file)
209 call sigio_sropen(21, trim(the_file), rc3)
211 call sigio_srhead(21, sighead, rc3)
213 call sigio_sclose(21, rc3)
218 elseif (trim(
input_type) ==
"gaussian_netcdf")
then 220 print*,
'- OPEN AND READ: ',trim(the_file)
221 rc=nf90_open(trim(the_file),nf90_nowrite,ncid)
224 print*,
"- READ grid_xt" 225 rc=nf90_inq_dimid(ncid,
'grid_xt', id_grid)
227 rc=nf90_inquire_dimension(ncid,id_grid,len=
i_input)
230 print*,
"- READ grid_yt" 231 rc=nf90_inq_dimid(ncid,
'grid_yt', id_grid)
233 rc=nf90_inquire_dimension(ncid,id_grid,len=
j_input)
236 rc = nf90_close(ncid)
240 call nemsio_init(iret=rc)
242 print*,
"- OPEN AND READ ", trim(the_file)
243 call nemsio_open(gfile, the_file,
"read", iret=rc)
246 call nemsio_getfilehead(gfile, iret=rc, dimx=
i_input, dimy=
j_input)
249 call nemsio_close(gfile)
256 polekindflag(1:2) = esmf_polekind_monopole
258 print*,
"- CALL GridCreate1PeriDim FOR INPUT GRID." 259 input_grid = esmf_gridcreate1peridim(minindex=(/1,1/), &
261 polekindflag=polekindflag, &
264 coordsys=esmf_coordsys_sph_deg, &
265 regdecomp=(/1,npets/), &
266 indexflag=esmf_index_global, rc=rc)
267 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
270 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE." 272 typekind=esmf_typekind_r8, &
273 staggerloc=esmf_staggerloc_center, &
274 name=
"input_grid_latitude", rc=rc)
275 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
278 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE." 280 typekind=esmf_typekind_r8, &
281 staggerloc=esmf_staggerloc_center, &
282 name=
"input_grid_longitude", rc=rc)
283 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
289 deltalon = 360.0_esmf_kind_r8 /
real(i_input,kind=esmf_kind_r8)
291 longitude(i,:) =
real((i-1),kind=esmf_kind_r8) * deltalon
296 call splat(4,
j_input, slat, wlat)
299 latitude(:,i) = 90.0_esmf_kind_r8 - (acos(slat(i))* 180.0_esmf_kind_r8 / &
300 (4.0_esmf_kind_r8*atan(1.0_esmf_kind_r8)))
303 deallocate(slat, wlat)
305 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE." 307 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
310 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE." 312 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
315 print*,
"- CALL GridAddCoord FOR INPUT GRID." 317 staggerloc=esmf_staggerloc_center, rc=rc)
318 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
321 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD." 324 staggerloc=esmf_staggerloc_center, &
326 farrayptr=lon_src_ptr, rc=rc)
327 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
330 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD." 333 staggerloc=esmf_staggerloc_center, &
335 computationallbound=clb, &
336 computationalubound=cub, &
337 farrayptr=lat_src_ptr, rc=rc)
338 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
341 do j = clb(2), cub(2)
342 do i = clb(1), cub(1)
343 lon_src_ptr(i,j) = longitude(i,j)
344 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
345 lat_src_ptr(i,j) = latitude(i,j)
349 print*,
"- CALL GridAddCoord FOR INPUT GRID." 351 staggerloc=esmf_staggerloc_corner, rc=rc)
352 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
355 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD." 356 nullify(lon_corner_src_ptr)
358 staggerloc=esmf_staggerloc_corner, &
360 farrayptr=lon_corner_src_ptr, rc=rc)
361 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
364 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD." 365 nullify(lat_corner_src_ptr)
367 staggerloc=esmf_staggerloc_corner, &
369 computationallbound=clb, &
370 computationalubound=cub, &
371 farrayptr=lat_corner_src_ptr, rc=rc)
372 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
375 do j = clb(2), cub(2)
376 do i = clb(1), cub(1)
377 lon_corner_src_ptr(i,j) = longitude(i,1) - (0.5_esmf_kind_r8*deltalon)
378 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
380 lat_corner_src_ptr(i,j) = 90.0_esmf_kind_r8
384 lat_corner_src_ptr(i,j) = -90.0_esmf_kind_r8
387 lat_corner_src_ptr(i,j) = 0.5_esmf_kind_r8 * (latitude(i,j-1)+ latitude(i,j))
391 deallocate(latitude,longitude)
410 character(len=500) :: the_file
412 integer,
intent(in) :: localpet, npets
414 integer :: id_tiles, id_dim, tile
415 integer :: extra, error, ncid
416 integer,
allocatable :: decomptile(:,:)
418 integer(esmf_kind_i8),
allocatable :: landmask_one_tile(:,:)
420 real(esmf_kind_r8),
allocatable :: latitude_one_tile(:,:)
421 real(esmf_kind_r8),
allocatable :: latitude_s_one_tile(:,:)
422 real(esmf_kind_r8),
allocatable :: latitude_w_one_tile(:,:)
423 real(esmf_kind_r8),
allocatable :: longitude_one_tile(:,:)
424 real(esmf_kind_r8),
allocatable :: longitude_s_one_tile(:,:)
425 real(esmf_kind_r8),
allocatable :: longitude_w_one_tile(:,:)
429 call netcdf_err(error,
'opening grid mosaic file')
431 print*,
"- READ NUMBER OF TILES" 432 error=nf90_inq_dimid(ncid,
'ntiles', id_tiles)
437 error = nf90_close(ncid)
442 call error_handler(
"MUST RUN WITH A TASK COUNT THAT IS A MULTIPLE OF 6.", 1)
454 decomptile(:,tile)=(/1,extra/)
457 print*,
"- CALL GridCreateMosaic FOR INPUT MODEL GRID" 459 regdecompptile=decomptile, &
460 staggerloclist=(/esmf_staggerloc_center, esmf_staggerloc_corner, &
461 esmf_staggerloc_edge1, esmf_staggerloc_edge2/), &
462 indexflag=esmf_index_global, &
465 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
472 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE." 474 typekind=esmf_typekind_r8, &
475 staggerloc=esmf_staggerloc_center, &
476 name=
"input_grid_latitude", &
478 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
481 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE." 483 typekind=esmf_typekind_r8, &
484 staggerloc=esmf_staggerloc_center, &
485 name=
"input_grid_longitude", &
487 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
490 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE_S." 492 typekind=esmf_typekind_r8, &
493 staggerloc=esmf_staggerloc_edge2, &
494 name=
"input_grid_latitude_s", &
496 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
499 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE_S." 501 typekind=esmf_typekind_r8, &
502 staggerloc=esmf_staggerloc_edge2, &
503 name=
"input_grid_longitude_s", &
505 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
508 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE_W." 510 typekind=esmf_typekind_r8, &
511 staggerloc=esmf_staggerloc_edge1, &
512 name=
"input_grid_latitude_w", &
514 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
517 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE_W." 519 typekind=esmf_typekind_r8, &
520 staggerloc=esmf_staggerloc_edge1, &
521 name=
"input_grid_longitude_w", &
523 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
528 print*,
'- OPEN FIRST INPUT GRID OROGRAPHY FILE: ',trim(the_file)
529 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
530 call netcdf_err(error,
'opening ororgraphy file')
531 print*,
"- READ GRID DIMENSIONS" 532 error=nf90_inq_dimid(ncid,
'lon', id_dim)
534 error=nf90_inquire_dimension(ncid,id_dim,len=
i_input)
536 error=nf90_inq_dimid(ncid,
'lat', id_dim)
538 error=nf90_inquire_dimension(ncid,id_dim,len=
j_input)
540 error = nf90_close(ncid)
542 print*,
"- I/J DIMENSIONS OF THE INPUT GRID TILES ",
i_input,
j_input 547 if (localpet == 0)
then 556 allocate(longitude_one_tile(0,0))
557 allocate(longitude_s_one_tile(0,0))
558 allocate(longitude_w_one_tile(0,0))
559 allocate(latitude_one_tile(0,0))
560 allocate(latitude_s_one_tile(0,0))
561 allocate(latitude_w_one_tile(0,0))
562 allocate(landmask_one_tile(0,0))
566 if (localpet == 0)
then 569 latitude_s_one_tile, latitude_w_one_tile, longitude_one_tile, &
570 longitude_s_one_tile, longitude_w_one_tile)
572 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE. TILE IS: ", tile
573 call esmf_fieldscatter(
latitude_input_grid, latitude_one_tile, rootpet=0, tile=tile, rc=error)
574 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
576 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE. TILE IS: ", tile
577 call esmf_fieldscatter(
longitude_input_grid, longitude_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 LATITUDE_S. TILE IS: ", tile
582 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
584 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE_S. TILE IS: ", tile
586 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
588 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE_W. TILE IS: ", tile
590 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
592 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE_W. TILE IS: ", tile
594 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
598 deallocate(longitude_one_tile)
599 deallocate(longitude_s_one_tile)
600 deallocate(longitude_w_one_tile)
601 deallocate(latitude_one_tile)
602 deallocate(latitude_s_one_tile)
603 deallocate(latitude_w_one_tile)
604 deallocate(landmask_one_tile)
623 integer,
intent(in) :: localpet, npets
625 character(len=500) :: the_file
627 integer :: i, j, k, jdisc, jgdtn, jpdtn, lugb, lugi
628 integer :: jids(200), jgdt(200), jpdt(200), rc
629 integer :: kgds(200), nret, clb(2), cub(2)
634 real,
allocatable :: rlon(:,:),rlat(:,:),xpts(:,:),ypts(:,:)
635 real,
allocatable :: rlon_corner(:,:),rlat_corner(:,:)
636 real,
allocatable :: rlon_diff(:,:),rlat_diff(:,:)
637 real,
allocatable :: xpts_corner(:,:),ypts_corner(:,:)
638 real(esmf_kind_r8),
allocatable :: latitude(:,:)
639 real(esmf_kind_r8),
allocatable :: longitude(:,:)
640 real(esmf_kind_r8),
allocatable :: latitude_corner(:,:)
641 real(esmf_kind_r8),
allocatable :: longitude_corner(:,:)
642 real(esmf_kind_r8),
pointer :: lat_src_ptr(:,:)
643 real(esmf_kind_r8),
pointer :: lat_corner_src_ptr(:,:)
644 real(esmf_kind_r8),
pointer :: lon_src_ptr(:,:)
645 real(esmf_kind_r8),
pointer :: lon_corner_src_ptr(:,:)
647 type(esmf_polekind_flag) :: polekindflag(2)
649 type(gribfield) :: gfld
655 print*,
"- OPEN AND READ INPUT DATA GRIB2 FILE: ", trim(the_file)
656 call baopenr(lugb,the_file,rc)
671 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
673 if (rc /= 0)
call error_handler(
"DEGRIBBING INPUT FILE.", rc)
675 call baclose(lugb,rc)
677 if (gfld%igdtnum == 0)
then 678 print*,
"- INPUT DATA ON LAT/LON GRID." 680 elseif (gfld%igdtnum == 30)
then 681 print*,
"- INPUT DATA ON LAMBERT CONFORMAL GRID." 683 elseif (gfld%igdtnum == 32769)
then 684 print*,
"- INPUT DATA ON ROTATED LAT/LON GRID." 714 print*,
"- COMPUTE GRID CELL CENTER COORDINATES." 715 call gdswzd(kgds,1,(
i_input*
j_input),-9999.,xpts,ypts,rlon,rlat,nret)
718 call error_handler(
"GDSWZD RETURNED WRONG NUMBER OF POINTS.", 2)
721 deallocate(xpts, ypts)
725 xpts_corner(i,j) = float(i) - 0.5
726 ypts_corner(i,j) = float(j) - 0.5
730 print*,
"- COMPUTE GRID CELL CORNER COORDINATES." 731 call gdswzd(kgds,1,(
ip1_input*
jp1_input),-9999.,xpts_corner,ypts_corner,rlon_corner,rlat_corner,nret)
734 call error_handler(
"GDSWZD RETURNED WRONG NUMBER OF POINTS.", 2)
737 deallocate(xpts_corner, ypts_corner)
739 if (gfld%igdtnum == 0)
then 741 print*,
"- CALL GridCreate1PeriDim FOR INPUT GRID." 743 polekindflag(1:2) = esmf_polekind_monopole
745 input_grid = esmf_gridcreate1peridim(minindex=(/1,1/), &
747 polekindflag=polekindflag, &
750 coordsys=esmf_coordsys_sph_deg, &
751 regdecomp=(/1,npets/), &
752 indexflag=esmf_index_global, rc=rc)
756 print*,
"- CALL GridCreateNoPeriDim FOR INPUT GRID." 759 indexflag=esmf_index_global, &
764 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
767 print*,
"- CALL FieldCreate FOR INPUT GRID LATITUDE." 769 typekind=esmf_typekind_r8, &
770 staggerloc=esmf_staggerloc_center, &
771 name=
"input_grid_latitude", rc=rc)
772 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
775 print*,
"- CALL FieldCreate FOR INPUT GRID LONGITUDE." 777 typekind=esmf_typekind_r8, &
778 staggerloc=esmf_staggerloc_center, &
779 name=
"input_grid_longitude", rc=rc)
780 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
789 deallocate (rlat, rlon)
791 print*,
"- CALL FieldScatter FOR INPUT GRID LONGITUDE." 793 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
796 print*,
"- CALL FieldScatter FOR INPUT GRID LATITUDE." 798 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
801 print*,
"- CALL GridAddCoord FOR INPUT GRID." 803 staggerloc=esmf_staggerloc_center, rc=rc)
804 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
807 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD." 810 staggerloc=esmf_staggerloc_center, &
812 farrayptr=lon_src_ptr, rc=rc)
813 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
816 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD." 819 staggerloc=esmf_staggerloc_center, &
821 computationallbound=clb, &
822 computationalubound=cub, &
823 farrayptr=lat_src_ptr, rc=rc)
824 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
827 do j = clb(2), cub(2)
828 do i = clb(1), cub(1)
829 lon_src_ptr(i,j) = longitude(i,j)
830 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
831 lat_src_ptr(i,j) = latitude(i,j)
835 deallocate(latitude, longitude)
840 latitude_corner = rlat_corner
841 longitude_corner = rlon_corner
843 deallocate (rlat_corner, rlon_corner)
845 print*,
"- CALL GridAddCoord FOR INPUT GRID." 847 staggerloc=esmf_staggerloc_corner, rc=rc)
848 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
851 print*,
"- CALL GridGetCoord FOR INPUT GRID X-COORD." 852 nullify(lon_corner_src_ptr)
854 staggerloc=esmf_staggerloc_corner, &
856 farrayptr=lon_corner_src_ptr, rc=rc)
857 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
860 print*,
"- CALL GridGetCoord FOR INPUT GRID Y-COORD." 861 nullify(lat_corner_src_ptr)
863 staggerloc=esmf_staggerloc_corner, &
865 computationallbound=clb, &
866 computationalubound=cub, &
867 farrayptr=lat_corner_src_ptr, rc=rc)
868 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
871 do j = clb(2), cub(2)
872 do i = clb(1), cub(1)
873 lon_corner_src_ptr(i,j) = longitude_corner(i,j)
874 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
875 lat_corner_src_ptr(i,j) = latitude_corner(i,j)
879 deallocate(latitude_corner, longitude_corner)
898 integer,
intent(in) :: localpet, npets
900 character(len=500) :: the_file
902 integer :: error, ncid, extra
904 integer :: id_dim, id_grid_tiles
906 integer,
allocatable :: decomptile(:,:)
907 integer(esmf_kind_i8),
allocatable :: landmask_one_tile(:,:)
908 integer(esmf_kind_i8),
allocatable :: seamask_one_tile(:,:)
910 real(esmf_kind_r8),
allocatable :: latitude_one_tile(:,:)
911 real(esmf_kind_r8),
allocatable :: latitude_s_one_tile(:,:)
912 real(esmf_kind_r8),
allocatable :: latitude_w_one_tile(:,:)
913 real(esmf_kind_r8),
allocatable :: longitude_one_tile(:,:)
914 real(esmf_kind_r8),
allocatable :: longitude_s_one_tile(:,:)
915 real(esmf_kind_r8),
allocatable :: longitude_w_one_tile(:,:)
916 real(esmf_kind_r8),
allocatable :: terrain_one_tile(:,:)
922 call netcdf_err(error,
'opening grid mosaic file')
924 print*,
"- READ NUMBER OF TILES" 925 error=nf90_inq_dimid(ncid,
'ntiles', id_tiles)
929 error=nf90_inq_varid(ncid,
'gridtiles', id_grid_tiles)
930 call netcdf_err(error,
'reading gridtiles id')
933 print*,
"- READ TILE NAMES" 937 error = nf90_close(ncid)
942 call error_handler(
"MUST RUN WITH TASK COUNT THAT IS A MULTIPLE OF # OF TILES.", 1)
951 print*,
'- OPEN FIRST TARGET GRID OROGRAPHY FILE: ',trim(the_file)
952 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
953 call netcdf_err(error,
'opening orography file')
954 print*,
"- READ GRID DIMENSIONS" 955 error=nf90_inq_dimid(ncid,
'lon', id_dim)
957 error=nf90_inquire_dimension(ncid,id_dim,len=
i_target)
959 error=nf90_inq_dimid(ncid,
'lat', id_dim)
961 error=nf90_inquire_dimension(ncid,id_dim,len=
j_target)
963 error = nf90_close(ncid)
979 decomptile(:,tile)=(/1,extra/)
982 print*,
"- CALL GridCreateMosaic FOR TARGET GRID" 984 regdecompptile=decomptile, &
985 staggerloclist=(/esmf_staggerloc_center, esmf_staggerloc_corner, &
986 esmf_staggerloc_edge1, esmf_staggerloc_edge2/), &
987 indexflag=esmf_index_global, &
989 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
997 print*,
"- CALL FieldCreate FOR TARGET GRID LANDMASK." 999 typekind=esmf_typekind_i8, &
1000 staggerloc=esmf_staggerloc_center, &
1001 name=
"target_grid_landmask", rc=error)
1002 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1005 print*,
"- CALL FieldCreate FOR TARGET GRID SEAMASK." 1007 typekind=esmf_typekind_i8, &
1008 staggerloc=esmf_staggerloc_center, &
1009 name=
"target_grid_seamask", rc=error)
1010 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1013 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE." 1015 typekind=esmf_typekind_r8, &
1016 staggerloc=esmf_staggerloc_center, &
1017 name=
"target_grid_latitude", rc=error)
1018 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1021 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE_S." 1023 typekind=esmf_typekind_r8, &
1024 staggerloc=esmf_staggerloc_edge2, &
1025 name=
"target_grid_latitude_s", rc=error)
1026 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1029 print*,
"- CALL FieldCreate FOR TARGET GRID LATITUDE_W." 1031 typekind=esmf_typekind_r8, &
1032 staggerloc=esmf_staggerloc_edge1, &
1033 name=
"target_grid_latitude_w", &
1035 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1038 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE." 1040 typekind=esmf_typekind_r8, &
1041 staggerloc=esmf_staggerloc_center, &
1042 name=
"target_grid_longitude", &
1044 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1047 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE_S." 1049 typekind=esmf_typekind_r8, &
1050 staggerloc=esmf_staggerloc_edge2, &
1051 name=
"target_grid_longitude_s", &
1053 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1056 print*,
"- CALL FieldCreate FOR TARGET GRID LONGITUDE_W." 1058 typekind=esmf_typekind_r8, &
1059 staggerloc=esmf_staggerloc_edge1, &
1060 name=
"target_grid_longitude_w", &
1062 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1065 print*,
"- CALL FieldCreate FOR TARGET GRID TERRAIN." 1067 typekind=esmf_typekind_r8, &
1068 staggerloc=esmf_staggerloc_center, &
1069 name=
"target_grid_terrain", &
1071 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1074 if (localpet == 0)
then 1085 allocate(landmask_one_tile(0,0))
1086 allocate(seamask_one_tile(0,0))
1087 allocate(longitude_one_tile(0,0))
1088 allocate(longitude_s_one_tile(0,0))
1089 allocate(longitude_w_one_tile(0,0))
1090 allocate(latitude_one_tile(0,0))
1091 allocate(latitude_s_one_tile(0,0))
1092 allocate(latitude_w_one_tile(0,0))
1093 allocate(terrain_one_tile(0,0))
1097 if (localpet == 0)
then 1101 seamask_one_tile = 0
1102 where(landmask_one_tile == 0) seamask_one_tile = 1
1105 latitude_s_one_tile, latitude_w_one_tile, longitude_one_tile, &
1106 longitude_s_one_tile, longitude_w_one_tile)
1108 print*,
"- CALL FieldScatter FOR TARGET GRID LANDMASK. TILE IS: ", tile
1109 call esmf_fieldscatter(
landmask_target_grid, landmask_one_tile, rootpet=0, tile=tile, rc=error)
1110 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1112 print*,
"- CALL FieldScatter FOR TARGET GRID SEAMASK. TILE IS: ", tile
1113 call esmf_fieldscatter(
seamask_target_grid, seamask_one_tile, rootpet=0, tile=tile, rc=error)
1114 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1116 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE. TILE IS: ", tile
1118 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1120 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE_S. TILE IS: ", tile
1122 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1124 print*,
"- CALL FieldScatter FOR TARGET GRID LONGITUDE_W. TILE IS: ", tile
1126 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1128 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE. TILE IS: ", tile
1129 call esmf_fieldscatter(
latitude_target_grid, latitude_one_tile, rootpet=0, tile=tile, rc=error)
1130 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1132 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE_S. TILE IS: ", tile
1134 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1136 print*,
"- CALL FieldScatter FOR TARGET GRID LATITUDE_W. TILE IS: ", tile
1138 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1140 print*,
"- CALL FieldScatter FOR TARGET GRID TERRAIN. TILE IS: ", tile
1141 call esmf_fieldscatter(
terrain_target_grid, terrain_one_tile, rootpet=0, tile=tile, rc=error)
1142 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1146 deallocate(landmask_one_tile)
1147 deallocate(seamask_one_tile)
1148 deallocate(longitude_one_tile)
1149 deallocate(longitude_s_one_tile)
1150 deallocate(longitude_w_one_tile)
1151 deallocate(latitude_one_tile)
1152 deallocate(latitude_s_one_tile)
1153 deallocate(latitude_w_one_tile)
1154 deallocate(terrain_one_tile)
1177 i_tile, j_tile, ip1_tile, jp1_tile, &
1178 latitude, latitude_s, latitude_w, &
1179 longitude, longitude_s, longitude_w)
1185 character(len=*),
intent(in) :: mosaic_file, orog_dir
1187 integer,
intent(in) :: num_tiles, tile
1188 integer,
intent(in) :: i_tile, j_tile
1189 integer,
intent(in) :: ip1_tile, jp1_tile
1191 real(esmf_kind_r8),
intent(out) :: latitude(i_tile, j_tile)
1192 real(esmf_kind_r8),
intent(out) :: latitude_s(i_tile, jp1_tile)
1193 real(esmf_kind_r8),
intent(out) :: latitude_w(ip1_tile, j_tile)
1194 real(esmf_kind_r8),
intent(out) :: longitude(i_tile, j_tile)
1195 real(esmf_kind_r8),
intent(out) :: longitude_s(i_tile, jp1_tile)
1196 real(esmf_kind_r8),
intent(out) :: longitude_w(ip1_tile, j_tile)
1198 character(len=25) :: grid_files(num_tiles)
1199 character(len=255) :: grid_file
1201 integer :: error, id_var, ncid
1202 integer :: id_dim, nxp, nyp, i, j, ii, jj
1204 real(esmf_kind_r8),
allocatable :: tmpvar(:,:)
1206 print*,
"- READ MODEL GRID FILE" 1208 print*,
'- OPEN MOSAIC FILE: ', trim(mosaic_file)
1209 error=nf90_open(trim(mosaic_file), nf90_nowrite, ncid)
1210 call netcdf_err(error,
'opening mosaic file')
1212 print*,
"- READ GRID FILE NAMES" 1213 error=nf90_inq_varid(ncid,
'gridfiles', id_var)
1214 call netcdf_err(error,
'reading gridfiles id')
1215 error=nf90_get_var(ncid, id_var, grid_files)
1218 error = nf90_close(ncid)
1220 grid_file = trim(orog_dir) // trim(grid_files(tile))
1222 print*,
'- OPEN GRID FILE: ', trim(grid_file)
1223 error=nf90_open(trim(grid_file), nf90_nowrite, ncid)
1226 print*,
'- READ NXP ID' 1227 error=nf90_inq_dimid(ncid,
'nxp', id_dim)
1231 error=nf90_inquire_dimension(ncid,id_dim,len=nxp)
1234 print*,
'- READ NYP ID' 1235 error=nf90_inq_dimid(ncid,
'nyp', id_dim)
1239 error=nf90_inquire_dimension(ncid,id_dim,len=nyp)
1242 if ((nxp/2 /= i_tile) .or. (nyp/2 /= j_tile))
then 1246 allocate(tmpvar(nxp,nyp))
1248 print*,
'- READ LONGITUDE ID' 1249 error=nf90_inq_varid(ncid,
'x', id_var)
1250 call netcdf_err(error,
'reading longitude id')
1252 print*,
'- READ LONGITUDE' 1253 error=nf90_get_var(ncid, id_var, tmpvar)
1260 longitude(i,j) = tmpvar(ii,jj)
1268 longitude_s(i,j) = tmpvar(ii,jj)
1276 longitude_w(i,j) = tmpvar(ii,jj)
1280 print*,
'- READ LATITUDE ID' 1281 error=nf90_inq_varid(ncid,
'y', id_var)
1282 call netcdf_err(error,
'reading latitude id')
1284 print*,
'- READ LATIITUDE' 1285 error=nf90_get_var(ncid, id_var, tmpvar)
1292 latitude(i,j) = tmpvar(ii,jj)
1300 latitude_s(i,j) = tmpvar(ii,jj)
1308 latitude_w(i,j) = tmpvar(ii,jj)
1314 error = nf90_close(ncid)
1333 character(len=*),
intent(in) :: orog_file
1335 integer,
intent(in) :: idim, jdim
1336 integer(esmf_kind_i8),
intent(out) :: mask(idim,jdim)
1338 real(esmf_kind_i8),
intent(out) :: terrain(idim,jdim)
1340 integer :: error, lat, lon
1341 integer :: ncid, id_dim, id_var
1343 real(kind=4),
allocatable :: dummy(:,:)
1345 print*,
"- READ MODEL LAND MASK FILE" 1347 print*,
'- OPEN LAND MASK FILE: ', orog_file
1348 error=nf90_open(orog_file,nf90_nowrite,ncid)
1349 call netcdf_err(error,
'opening land mask file')
1351 print*,
"- READ I-DIMENSION" 1352 error=nf90_inq_dimid(ncid,
'lon', id_dim)
1354 error=nf90_inquire_dimension(ncid,id_dim,len=lon)
1357 print*,
"- READ J-DIMENSION" 1358 error=nf90_inq_dimid(ncid,
'lat', id_dim)
1360 error=nf90_inquire_dimension(ncid,id_dim,len=lat)
1363 print*,
"- I/J DIMENSIONS: ", lon, lat
1365 if ((lon /= idim) .or. (lat /= jdim))
then 1369 allocate(dummy(idim,jdim))
1371 print*,
"- READ LAND MASK" 1372 error=nf90_inq_varid(ncid,
'slmsk', id_var)
1374 error=nf90_get_var(ncid, id_var, dummy)
1378 print*,
"- READ RAW OROGRAPHY." 1379 error=nf90_inq_varid(ncid,
'orog_raw', id_var)
1380 call netcdf_err(error,
'reading orog_raw id')
1381 error=nf90_get_var(ncid, id_var, dummy)
1385 error = nf90_close(ncid)
1400 print*,
"- DESTROY MODEL DATA." 1449 subroutine gdt_to_gds(igdtnum, igdstmpl, igdtlen, kgds, ni, nj, res)
1453 integer,
intent(in ) :: igdtnum, igdtlen, igdstmpl(igdtlen)
1454 integer,
intent( out) :: kgds(200), ni, nj
1457 real,
intent( out) :: res
1461 if (igdtnum.eq.32769)
then 1463 iscale=igdstmpl(10)*igdstmpl(11)
1464 if (iscale == 0) iscale = 1e6
1471 kgds(4)=nint(float(igdstmpl(12))/float(iscale)*1000.)
1473 kgds(5)=nint(float(igdstmpl(13))/float(iscale)*1000.)
1477 if (igdstmpl(1)==2 ) kgds(6)=64
1478 if ( btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5) ) kgds(6)=kgds(6)+128
1479 if ( btest(igdstmpl(14),3) ) kgds(6)=kgds(6)+8
1481 kgds(7)=nint(float(igdstmpl(15))/float(iscale)*1000.)
1483 kgds(8)=nint(float(igdstmpl(16))/float(iscale)*1000.)
1485 kgds(9)=nint(float(igdstmpl(17))/float(iscale)*1000.)
1487 kgds(10)=nint(float(igdstmpl(18))/float(iscale)*1000.)
1491 if (btest(igdstmpl(19),7)) kgds(11) = 128
1492 if (btest(igdstmpl(19),6)) kgds(11) = kgds(11) + 64
1493 if (btest(igdstmpl(19),5)) kgds(11) = kgds(11) + 32
1495 kgds(12)=nint(float(igdstmpl(20))/float(iscale)*1000.)
1497 kgds(13)=nint(float(igdstmpl(21))/float(iscale)*1000.)
1503 res = ((float(kgds(9)) / 1000.0) + (float(kgds(10)) / 1000.0)) &
1506 elseif(igdtnum==30)
then 1515 kgds(4) = nint(float(igdstmpl(10))/1000.0)
1516 kgds(5) = nint(float(igdstmpl(11))/1000.0)
1519 if (igdstmpl(1)==2 ) kgds(6)=64
1520 if ( btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5) ) kgds(6)=kgds(6)+128
1521 if ( btest(igdstmpl(12),3) ) kgds(6)=kgds(6)+8
1523 kgds(7) = nint(float(igdstmpl(14))/1000.0)
1524 kgds(8) = nint(float(igdstmpl(15))/1000.0)
1525 kgds(9) = nint(float(igdstmpl(16))/1000.0)
1529 if (btest(igdstmpl(18),7)) kgds(11) = 128
1530 if (btest(igdstmpl(18),6)) kgds(11) = kgds(11) + 64
1531 if (btest(igdstmpl(18),5)) kgds(11) = kgds(11) + 32
1533 kgds(12) = nint(float(igdstmpl(19))/1000.0)
1534 kgds(13) = nint(float(igdstmpl(20))/1000.0)
1538 elseif(igdtnum==0)
then 1540 iscale=igdstmpl(10)*igdstmpl(11)
1541 if (iscale == 0) iscale = 1e6
1547 kgds(4)=nint(float(igdstmpl(12))/float(iscale)*1000.)
1548 kgds(5)=nint(float(igdstmpl(13))/float(iscale)*1000.)
1551 if (igdstmpl(1)==2 ) kgds(6)=64
1552 if ( btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5) ) kgds(6)=kgds(6)+128
1553 if ( btest(igdstmpl(14),3) ) kgds(6)=kgds(6)+8
1555 kgds(7)=nint(float(igdstmpl(15))/float(iscale)*1000.)
1556 kgds(8)=nint(float(igdstmpl(16))/float(iscale)*1000.)
1557 kgds(9)=nint(float(igdstmpl(17))/float(iscale)*1000.)
1558 kgds(10)=nint(float(igdstmpl(18))/float(iscale)*1000.)
1561 if (btest(igdstmpl(19),7)) kgds(11) = 128
1562 if (btest(igdstmpl(19),6)) kgds(11) = kgds(11) + 64
1563 if (btest(igdstmpl(19),5)) kgds(11) = kgds(11) + 32
integer, public j_target
j dimension of each global tile, or of a nest, target grid.
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...
integer, public num_tiles_target_grid
Number of tiles, target grid.
subroutine, public cleanup_input_target_grid_data
Deallocate all esmf grid objects.
integer, public lsoil_target
Number of soil layers, target grid.
integer, public ip1_input
i_input plus 1
type(esmf_field), public longitude_w_target_grid
longitude of 'west' edge of grid box, target grid
subroutine define_input_grid_grib2(localpet, npets)
Define input grid object for grib2 input data.
integer, public j_input
j-dimension of input grid (or of each global tile)
subroutine define_input_grid_mosaic(localpet, npets)
Define input grid for tiled data using the 'mosaic', 'grid' and orography files.
integer, public jp1_input
j_input plus 1
integer, public nsoill_out
Number of soil levels desired in the output data.
type(esmf_field), public longitude_s_target_grid
longitude of 'south' edge of grid box, target grid
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
type(esmf_field), public latitude_input_grid
latitude of grid center, input grid
type(esmf_field), public latitude_target_grid
latitude of grid center, target grid
integer, public i_target
i dimension of each global tile, or of a nest, target 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.
integer, public num_tiles_input_grid
Number of tiles, input grid.
type(esmf_field), public latitude_s_target_grid
latitude of 'south' edge of grid box, target grid
type(esmf_field), public latitude_w_input_grid
latitude of 'west' edge of grid box, input grid
type(esmf_grid), public target_grid
target grid esmf grid object.
logical, public convert_sfc
Convert sfc data when true.
character(len=500), public orog_dir_target_grid
Directory containing the target grid orography files.
character(len=500), dimension(6), public orog_files_input_grid
Input grid orography files.
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.
type(esmf_field), public latitude_w_target_grid
latitude of 'west' edge of grid box, target grid
character(len=500), public orog_dir_input_grid
Directory containing the input grid orography files.
type(esmf_field), public landmask_target_grid
land mask target grid - '1' land; '0' non-land
character(len=500), public mosaic_file_target_grid
Target grid mosaic file.
character(len=500), public mosaic_file_input_grid
Input grid mosaic file.
type(esmf_field), public longitude_w_input_grid
longitude of 'west' edge of grid box, input grid
character(len=500), dimension(6), public atm_files_input_grid
File names of input atmospheric data.
type(esmf_field), public latitude_s_input_grid
latitude of 'south' edge of grid box, input grid
subroutine, public define_target_grid(localpet, npets)
Setup the esmf grid object for the target grid.
character(len=500), dimension(6), public orog_files_target_grid
Target grid orography files.
subroutine define_input_grid_gaussian(localpet, npets)
Define grid object for input data on global gaussian grids.
type(esmf_field), public longitude_s_input_grid
longitude of 'south' edge of grid box, input grid
subroutine netcdf_err(err, string)
Error handler for netcdf.
logical, public convert_atm
Convert atmospheric data when true.
type(esmf_field), public longitude_target_grid
longitude of grid center, target grid
subroutine, public define_input_grid(localpet, npets)
Driver routine to setup the esmf grid object for the input grid.
type(esmf_grid), public input_grid
input grid esmf grid object
character(len=500), public data_dir_input_grid
Directory containing input atm or sfc files.
subroutine error_handler(string, rc)
General error handler.
subroutine gdt_to_gds(igdtnum, igdstmpl, igdtlen, kgds, ni, nj, res)
Convert the GRIB2 grid description template to to the GRIB1 grid description section.
character(len=50), public input_grid_type
map projection of input grid
integer, public ip1_target
ip1_target plus 1
character(len=25), public input_type
Input data type:
type(esmf_field), public terrain_target_grid
terrain height target grid
character(len=5), dimension(:), allocatable, public tiles_target_grid
Tile names of target grid.
type(esmf_field), public longitude_input_grid
longitude of grid center, input grid
character(len=500), public grib2_file_input_grid
REQUIRED.
type(esmf_field), public seamask_target_grid
sea mask target grid - '1' non-land; '0' land
character(len=500), dimension(6), public sfc_files_input_grid
File names containing input surface data.
integer, public i_input
i-dimension of input grid (or of each global tile)
integer, public jp1_target
jp1_target plus 1