21 atm_files_input_grid, &
22 grib2_file_input_grid, &
23 atm_core_files_input_grid, &
24 atm_tracer_files_input_grid, &
25 tracers_input, num_tracers_input, &
33 ip1_input, jp1_input, &
34 num_tiles_input_grid, &
35 latitude_input_grid, &
48 type(esmf_field
),
public :: dzdt_input_grid
49 type(esmf_field) :: dpres_input_grid
50 type(esmf_field),
public :: pres_input_grid
51 type(esmf_field),
public :: ps_input_grid
52 type(esmf_field),
public :: terrain_input_grid
53 type(esmf_field),
public :: temp_input_grid
55 type(esmf_field
),
public :: u_input_grid
56 type(esmf_field),
public :: v_input_grid
57 type(esmf_field),
public :: xwind_input_grid
58 type(esmf_field),
public :: ywind_input_grid
59 type(esmf_field),
public :: zwind_input_grid
60 type(esmf_field),
allocatable,
public :: tracers_input_grid(:)
62 integer,
public :: lev_input
63 integer,
public :: levp1_input
65 character(len=50),
private,
allocatable :: slevs(:)
81 integer,
intent(in) :: localpet
87 if (trim(input_type) ==
"restart")
then
95 elseif (trim(input_type) ==
"gaussian_netcdf")
then
103 elseif (trim(input_type) ==
"history")
then
111 elseif (trim(input_type) ==
"gaussian_nemsio")
then
119 elseif (trim(input_type) ==
"gfs_gaussian_nemsio")
then
127 elseif (trim(input_type) ==
"gfs_sigio")
then
135 elseif (trim(input_type) ==
"grib2")
then
153 print*,
"- INITIALIZE ATMOSPHERIC ESMF FIELDS."
155 print*,
"- CALL FieldCreate FOR INPUT GRID SURFACE PRESSURE."
156 ps_input_grid = esmf_fieldcreate(input_grid, &
157 typekind=esmf_typekind_r8, &
158 staggerloc=esmf_staggerloc_center, rc=rc)
159 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
162 print*,
"- CALL FieldCreate FOR INPUT GRID TERRAIN."
163 terrain_input_grid = esmf_fieldcreate(input_grid, &
164 typekind=esmf_typekind_r8, &
165 staggerloc=esmf_staggerloc_center, rc=rc)
166 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
169 print*,
"- CALL FieldCreate FOR INPUT GRID xwind."
170 xwind_input_grid = esmf_fieldcreate(input_grid, &
171 typekind=esmf_typekind_r8, &
172 staggerloc=esmf_staggerloc_center, &
173 ungriddedlbound=(/1/), &
174 ungriddedubound=(/lev_input/), rc=rc)
175 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
178 print*,
"- CALL FieldCreate FOR INPUT GRID ywind."
179 ywind_input_grid = esmf_fieldcreate(input_grid, &
180 typekind=esmf_typekind_r8, &
181 staggerloc=esmf_staggerloc_center, &
182 ungriddedlbound=(/1/), &
183 ungriddedubound=(/lev_input/), rc=rc)
184 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
187 print*,
"- CALL FieldCreate FOR INPUT GRID zwind."
188 zwind_input_grid = esmf_fieldcreate(input_grid, &
189 typekind=esmf_typekind_r8, &
190 staggerloc=esmf_staggerloc_center, &
191 ungriddedlbound=(/1/), &
192 ungriddedubound=(/lev_input/), rc=rc)
193 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
196 print*,
"- CALL FieldCreate FOR INPUT GRID TEMPERATURE."
197 temp_input_grid = esmf_fieldcreate(input_grid, &
198 typekind=esmf_typekind_r8, &
199 staggerloc=esmf_staggerloc_center, &
200 ungriddedlbound=(/1/), &
201 ungriddedubound=(/lev_input/), rc=rc)
202 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
205 allocate(tracers_input_grid(num_tracers_input))
207 do i = 1, num_tracers_input
208 print*,
"- CALL FieldCreate FOR INPUT GRID TRACER ", trim(tracers_input(i))
209 tracers_input_grid(i) = esmf_fieldcreate(input_grid, &
210 typekind=esmf_typekind_r8, &
211 staggerloc=esmf_staggerloc_center, &
212 ungriddedlbound=(/1/), &
213 ungriddedubound=(/lev_input/), rc=rc)
214 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
218 print*,
"- CALL FieldCreate FOR INPUT GRID DZDT."
219 dzdt_input_grid = esmf_fieldcreate(input_grid, &
220 typekind=esmf_typekind_r8, &
221 staggerloc=esmf_staggerloc_center, &
222 ungriddedlbound=(/1/), &
223 ungriddedubound=(/lev_input/), rc=rc)
224 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
227 print*,
"- CALL FieldCreate FOR INPUT GRID U."
228 u_input_grid = esmf_fieldcreate(input_grid, &
229 typekind=esmf_typekind_r8, &
230 staggerloc=esmf_staggerloc_center, &
231 ungriddedlbound=(/1/), &
232 ungriddedubound=(/lev_input/), rc=rc)
233 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
236 print*,
"- CALL FieldCreate FOR INPUT GRID V."
237 v_input_grid = esmf_fieldcreate(input_grid, &
238 typekind=esmf_typekind_r8, &
239 staggerloc=esmf_staggerloc_center, &
240 ungriddedlbound=(/1/), &
241 ungriddedubound=(/lev_input/), rc=rc)
242 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
245 print*,
"- CALL FieldCreate FOR INPUT GRID PRESSURE."
246 pres_input_grid = esmf_fieldcreate(input_grid, &
247 typekind=esmf_typekind_r8, &
248 staggerloc=esmf_staggerloc_center, &
249 ungriddedlbound=(/1/), &
250 ungriddedubound=(/lev_input/), rc=rc)
251 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
267 integer,
intent(in) :: localpet
269 character(len=300) :: the_file
271 integer(sigio_intkind) :: iret
272 integer :: rc, i, j, k
273 integer :: clb(3), cub(3)
275 real(esmf_kind_r8) :: ak, bk
276 real(esmf_kind_r8),
allocatable :: dummy2d(:,:)
277 real(esmf_kind_r8),
allocatable :: dummy3d(:,:,:)
278 real(esmf_kind_r8),
allocatable :: dummy3d2(:,:,:)
279 real(esmf_kind_r8),
pointer :: pptr(:,:,:), psptr(:,:)
280 real(esmf_kind_r8),
allocatable :: pi(:,:,:)
282 type(sigio_head
) :: sighead
283 type(sigio_dbta
) :: sigdata
285 the_file = trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(1))
287 print*,
"- ATMOSPHERIC DATA IN SIGIO FORMAT."
288 print*,
"- OPEN AND READ: ", trim(the_file)
290 call sigio_sropen(21, trim(the_file), iret)
295 call sigio_srhead(21, sighead, iret)
301 lev_input = sighead%levs
302 levp1_input = lev_input + 1
304 if (num_tracers_input /= sighead%ntrac)
then
308 if (sighead%idvt == 0 .or. sighead%idvt == 21)
then
309 if (trim(tracers_input(1)) /=
'spfh' .or. &
310 trim(tracers_input(2)) /=
'o3mr' .or. &
311 trim(tracers_input(3)) /=
'clwmr')
then
312 call
error_handler(
"TRACERS SELECTED DO NOT MATCH FILE CONTENTS.", 99)
315 print*,
'- UNRECOGNIZED IDVT: ', sighead%idvt
325 if (localpet == 0)
then
326 allocate(dummy2d(i_input,j_input))
327 allocate(dummy3d(i_input,j_input,lev_input))
328 allocate(dummy3d2(i_input,j_input,lev_input))
330 allocate(dummy2d(0,0))
331 allocate(dummy3d(0,0,0))
332 allocate(dummy3d2(0,0,0))
335 if (localpet == 0)
then
336 call sigio_aldbta(sighead, sigdata, iret)
341 call sigio_srdbta(21, sighead, sigdata, iret)
346 call sptez(0,sighead%jcap,4,i_input, j_input, sigdata%ps, dummy2d, 1)
347 dummy2d = exp(dummy2d) * 1000.0
348 print*,
'surface pres ',maxval(dummy2d),minval(dummy2d)
351 print*,
"- CALL FieldScatter FOR SURFACE PRESSURE."
352 call esmf_fieldscatter(ps_input_grid, dummy2d, rootpet=0, rc=rc)
353 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
356 if (localpet == 0)
then
357 call sptez(0,sighead%jcap,4,i_input, j_input, sigdata%hs, dummy2d, 1)
358 print*,
'terrain ',maxval(dummy2d),minval(dummy2d)
361 print*,
"- CALL FieldScatter FOR TERRAIN."
362 call esmf_fieldscatter(terrain_input_grid, dummy2d, rootpet=0, rc=rc)
363 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
366 do k = 1, num_tracers_input
368 if (localpet == 0)
then
369 call sptezm(0,sighead%jcap,4,i_input, j_input, lev_input, sigdata%q(:,:,k), dummy3d, 1)
370 print*,trim(tracers_input(k)),maxval(dummy3d),minval(dummy3d)
373 print*,
"- CALL FieldScatter FOR INPUT ", trim(tracers_input(k))
374 call esmf_fieldscatter(tracers_input_grid(k), dummy3d, rootpet=0, rc=rc)
375 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
380 if (localpet == 0)
then
381 call sptezm(0,sighead%jcap,4,i_input, j_input, lev_input, sigdata%t, dummy3d, 1)
382 print*,
'temp ',maxval(dummy3d),minval(dummy3d)
385 print*,
"- CALL FieldScatter FOR INPUT GRID TEMPERATURE."
386 call esmf_fieldscatter(temp_input_grid, dummy3d, rootpet=0, rc=rc)
387 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
395 if (localpet == 0)
then
396 print*,
"- NO VERTICAL VELOCITY RECORD. SET TO ZERO."
400 print*,
"- CALL FieldScatter FOR INPUT DZDT."
401 call esmf_fieldscatter(dzdt_input_grid, dummy3d, rootpet=0, rc=rc)
402 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
405 if (localpet == 0)
then
406 call sptezmv(0, sighead%jcap, 4, i_input, j_input, lev_input, sigdata%d, sigdata%z, dummy3d, dummy3d2, 1)
407 print*,
'u ',maxval(dummy3d),minval(dummy3d)
408 print*,
'v ',maxval(dummy3d2),minval(dummy3d2)
411 print*,
"- CALL FieldScatter FOR INPUT U-WIND."
412 call esmf_fieldscatter(u_input_grid, dummy3d, rootpet=0, rc=rc)
413 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
416 print*,
"- CALL FieldScatter FOR INPUT V-WIND."
417 call esmf_fieldscatter(v_input_grid, dummy3d2, rootpet=0, rc=rc)
418 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
421 deallocate(dummy2d, dummy3d, dummy3d2)
423 if (localpet == 0) call sigio_axdbta(sigdata, iret)
425 call sigio_sclose(21, iret)
437 print*,
"- COMPUTE 3-D PRESSURE."
439 print*,
"- CALL FieldGet FOR 3-D PRES."
441 call esmf_fieldget(pres_input_grid, &
442 computationallbound=clb, &
443 computationalubound=cub, &
444 farrayptr=pptr, rc=rc)
445 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
448 print*,
"- CALL FieldGet FOR SURFACE PRESSURE."
450 call esmf_fieldget(ps_input_grid, &
451 farrayptr=psptr, rc=rc)
452 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
459 allocate(pi(clb(1):cub(1),clb(2):cub(2),1:levp1_input),stat=rc)
462 ak = sighead%vcoord(k,1)
463 bk = sighead%vcoord(k,2)
466 pi(i,j,k) = ak + bk*psptr(i,j)
471 if (localpet == 0)
then
472 print*,
'pres int ',psptr(clb(1),clb(2)),pi(clb(1),clb(2),:)
482 pptr(i,j,k) = (pi(i,j,k)+pi(i,j,k+1))/2.0_esmf_kind_r8
489 if (localpet == 0)
then
490 print*,
'pres ',psptr(clb(1),clb(2)),pptr(clb(1),clb(2),:)
504 integer,
intent(in) :: localpet
506 character(len=300) :: the_file
507 character(len=20) :: vlevtyp, vname
509 integer(nemsio_intkind) :: vlev, iret
510 integer :: i, j, k, n, rc
511 integer :: clb(3), cub(3)
513 real(nemsio_realkind),
allocatable :: vcoord(:,:,:)
514 real(nemsio_realkind),
allocatable :: dummy(:)
515 real(esmf_kind_r8),
allocatable :: dummy2d(:,:)
516 real(esmf_kind_r8),
allocatable :: dummy3d(:,:,:)
517 real(esmf_kind_r8) :: ak, bk
518 real(esmf_kind_r8),
allocatable :: pi(:,:,:)
519 real(esmf_kind_r8),
pointer :: pptr(:,:,:), psptr(:,:)
521 type(nemsio_gfile
) :: gfile
523 the_file = trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(1))
525 print*,
"- READ ATMOS DATA FROM SPECTRAL GFS NEMSIO FILE: ", trim(the_file)
527 print*,
"- OPEN FILE."
528 call nemsio_open(gfile, the_file,
"read", iret=iret)
529 if (iret /= 0) call
error_handler(
"OPENING SPECTRAL GFS NEMSIO ATM FILE.", iret)
531 print*,
"- READ NUMBER OF VERTICAL LEVELS."
532 call nemsio_getfilehead(gfile, iret=iret, dimz=lev_input)
533 if (iret /= 0) call
error_handler(
"READING NUMBER OF VERTICAL LEVLES.", iret)
535 levp1_input = lev_input + 1
537 allocate(vcoord(levp1_input,3,2))
539 print*,
"- READ VERTICAL COORDINATE INFO."
540 call nemsio_getfilehead(gfile, iret=iret, vcoord=vcoord)
541 if (iret /= 0) call
error_handler(
"READING VERTICAL COORDINATE INFO.", iret)
549 if (localpet == 0)
then
550 allocate(dummy(i_input*j_input))
551 allocate(dummy2d(i_input,j_input))
552 allocate(dummy3d(i_input,j_input,lev_input))
555 allocate(dummy2d(0,0))
556 allocate(dummy3d(0,0,0))
564 if (localpet == 0)
then
565 print*,
"- READ TEMPERATURE."
567 vlevtyp =
"mid layer"
568 do vlev = 1, lev_input
569 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
570 if (iret /= 0) call
error_handler(
"READING TEMPERATURE RECORD.", iret)
571 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
576 print*,
"- CALL FieldScatter FOR INPUT GRID TEMPERATURE."
577 call esmf_fieldscatter(temp_input_grid, dummy3d, rootpet=0, rc=rc)
578 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
581 do n = 1, num_tracers_input
583 if (localpet == 0)
then
584 print*,
"- READ ", trim(tracers_input(n))
585 vname = trim(tracers_input(n))
586 vlevtyp =
"mid layer"
587 do vlev = 1, lev_input
588 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
589 if (iret /= 0) call
error_handler(
"READING TRACER RECORD.", iret)
591 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
595 print*,
"- CALL FieldScatter FOR INPUT ", trim(tracers_input(n))
596 call esmf_fieldscatter(tracers_input_grid(n), dummy3d, rootpet=0, rc=rc)
597 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
602 if (localpet == 0)
then
603 print*,
"- READ U-WINDS."
605 vlevtyp =
"mid layer"
606 do vlev = 1, lev_input
607 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
608 if (iret /= 0) call
error_handler(
"READING U-WIND RECORD.", iret)
610 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
614 print*,
"- CALL FieldScatter FOR INPUT U-WIND."
615 call esmf_fieldscatter(u_input_grid, dummy3d, rootpet=0, rc=rc)
616 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
619 if (localpet == 0)
then
620 print*,
"- READ V-WINDS."
622 vlevtyp =
"mid layer"
623 do vlev = 1, lev_input
624 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
625 if (iret /= 0) call
error_handler(
"READING V-WIND RECORD.", iret)
627 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
631 print*,
"- CALL FieldScatter FOR INPUT V-WIND."
632 call esmf_fieldscatter(v_input_grid, dummy3d, rootpet=0, rc=rc)
633 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
641 if (localpet == 0)
then
642 print*,
"- NO VERTICAL VELOCITY RECORD. SET TO ZERO."
646 print*,
"- CALL FieldScatter FOR INPUT DZDT."
647 call esmf_fieldscatter(dzdt_input_grid, dummy3d, rootpet=0, rc=rc)
648 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
651 if (localpet == 0)
then
656 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
657 if (iret /= 0) call
error_handler(
"READING HGT RECORD.", iret)
659 dummy2d = reshape(dummy, (/i_input,j_input/))
662 print*,
"- CALL FieldScatter FOR TERRAIN."
663 call esmf_fieldscatter(terrain_input_grid, dummy2d, rootpet=0, rc=rc)
664 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
667 if (localpet == 0)
then
668 print*,
"- READ PRES."
672 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
673 if (iret /= 0) call
error_handler(
"READING PRES RECORD.", iret)
675 dummy2d = reshape(dummy, (/i_input,j_input/))
678 print*,
"- CALL FieldScatter FOR SURFACE PRESSURE."
679 call esmf_fieldscatter(ps_input_grid, dummy2d, rootpet=0, rc=rc)
680 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
683 call nemsio_close(gfile)
685 deallocate(dummy, dummy2d, dummy3d)
697 print*,
"- COMPUTE 3-D PRESSURE."
699 print*,
"- CALL FieldGet FOR 3-D PRES."
701 call esmf_fieldget(pres_input_grid, &
702 computationallbound=clb, &
703 computationalubound=cub, &
704 farrayptr=pptr, rc=rc)
705 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
708 print*,
"- CALL FieldGet FOR SURFACE PRESSURE."
710 call esmf_fieldget(ps_input_grid, &
711 farrayptr=psptr, rc=rc)
712 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
719 allocate(pi(clb(1):cub(1),clb(2):cub(2),1:levp1_input))
726 pi(i,j,k) = ak + bk*psptr(i,j)
740 pptr(i,j,k) = (pi(i,j,k)+pi(i,j,k+1))/2.0
757 integer,
intent(in) :: localpet
759 character(len=300) :: the_file
760 character(len=20) :: vlevtyp, vname
762 integer :: i, j, k, n
763 integer :: rc, clb(3), cub(3)
764 integer(nemsio_intkind) :: vlev, iret
766 real(nemsio_realkind),
allocatable :: vcoord(:,:,:)
767 real(nemsio_realkind),
allocatable :: dummy(:)
768 real(esmf_kind_r8),
allocatable :: dummy2d(:,:)
769 real(esmf_kind_r8),
allocatable :: dummy3d(:,:,:)
770 real(esmf_kind_r8),
pointer :: presptr(:,:,:), psptr(:,:)
771 real(esmf_kind_r8),
pointer :: dpresptr(:,:,:)
772 real(esmf_kind_r8),
allocatable :: pres_interface(:)
774 type(nemsio_gfile
) :: gfile
776 the_file = trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(1))
778 print*,
"- READ ATMOS DATA FROM GAUSSIAN NEMSIO FILE: ", trim(the_file)
780 print*,
"- OPEN FILE."
781 call nemsio_open(gfile, the_file,
"read", iret=iret)
782 if (iret /= 0) call
error_handler(
"OPENING GAUSSIAN NEMSIO ATM FILE.", iret)
784 print*,
"- READ NUMBER OF VERTICAL LEVELS."
785 call nemsio_getfilehead(gfile, iret=iret, dimz=lev_input)
786 if (iret /= 0) call
error_handler(
"READING NUMBER OF VERTICAL LEVLES.", iret)
788 levp1_input = lev_input + 1
790 allocate(vcoord(levp1_input,3,2))
792 print*,
"- READ VERTICAL COORDINATE INFO."
793 call nemsio_getfilehead(gfile, iret=iret, vcoord=vcoord)
794 if (iret /= 0) call
error_handler(
"READING VERTICAL COORDINATE INFO.", iret)
802 print*,
"- CALL FieldCreate FOR INPUT DPRES."
803 dpres_input_grid = esmf_fieldcreate(input_grid, &
804 typekind=esmf_typekind_r8, &
805 staggerloc=esmf_staggerloc_center, &
806 ungriddedlbound=(/1/), &
807 ungriddedubound=(/lev_input/), rc=rc)
808 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
811 if (localpet == 0)
then
812 allocate(dummy(i_input*j_input))
813 allocate(dummy2d(i_input,j_input))
814 allocate(dummy3d(i_input,j_input,lev_input))
817 allocate(dummy2d(0,0))
818 allocate(dummy3d(0,0,0))
826 if (localpet == 0)
then
827 print*,
"- READ TEMPERATURE."
829 vlevtyp =
"mid layer"
830 do vlev = 1, lev_input
831 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
832 if (iret /= 0) call
error_handler(
"READING TEMPERATURE RECORD.", iret)
833 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
834 print*,
'temp check after read ',vlev, dummy3d(1,1,vlev)
838 print*,
"- CALL FieldScatter FOR INPUT GRID TEMPERATURE."
839 call esmf_fieldscatter(temp_input_grid, dummy3d, rootpet=0, rc=rc)
840 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
843 do n = 1, num_tracers_input
845 if (localpet == 0)
then
846 print*,
"- READ ", trim(tracers_input(n))
847 vname = trim(tracers_input(n))
848 vlevtyp =
"mid layer"
849 do vlev = 1, lev_input
850 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
851 if (iret /= 0) call
error_handler(
"READING TRACER RECORD.", iret)
852 print*,
'tracer ',vlev, maxval(dummy),minval(dummy)
853 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
857 print*,
"- CALL FieldScatter FOR INPUT ", trim(tracers_input(n))
858 call esmf_fieldscatter(tracers_input_grid(n), dummy3d, rootpet=0, rc=rc)
859 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
864 if (localpet == 0)
then
865 print*,
"- READ U-WINDS."
867 vlevtyp =
"mid layer"
868 do vlev = 1, lev_input
869 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
870 if (iret /= 0) call
error_handler(
"READING U-WIND RECORD.", iret)
871 print*,
'ugrd ',vlev, maxval(dummy),minval(dummy)
872 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
876 print*,
"- CALL FieldScatter FOR INPUT U-WIND."
877 call esmf_fieldscatter(u_input_grid, dummy3d, rootpet=0, rc=rc)
878 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
881 if (localpet == 0)
then
882 print*,
"- READ V-WINDS."
884 vlevtyp =
"mid layer"
885 do vlev = 1, lev_input
886 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
887 if (iret /= 0) call
error_handler(
"READING V-WIND RECORD.", iret)
888 print*,
'vgrd ',vlev, maxval(dummy),minval(dummy)
889 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
893 print*,
"- CALL FieldScatter FOR INPUT V-WIND."
894 call esmf_fieldscatter(v_input_grid, dummy3d, rootpet=0, rc=rc)
895 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
898 if (localpet == 0)
then
899 print*,
"- READ DPRES."
901 vlevtyp =
"mid layer"
902 do vlev = 1, lev_input
903 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
904 if (iret /= 0) call
error_handler(
"READING DPRES RECORD.", iret)
905 print*,
'dpres ',vlev, maxval(dummy),minval(dummy)
906 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
910 print*,
"- CALL FieldScatter FOR INPUT DPRES."
911 call esmf_fieldscatter(dpres_input_grid, dummy3d, rootpet=0, rc=rc)
912 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
915 if (localpet == 0)
then
916 print*,
"- READ DZDT."
918 vlevtyp =
"mid layer"
919 do vlev = 1, lev_input
920 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
921 if (iret /= 0) call
error_handler(
"READING DZDT RECORD.", iret)
922 print*,
'dzdt ',vlev, maxval(dummy),minval(dummy)
923 dummy3d(:,:,vlev) = reshape(dummy, (/i_input,j_input/))
927 print*,
"- CALL FieldScatter FOR INPUT DZDT."
928 call esmf_fieldscatter(dzdt_input_grid, dummy3d, rootpet=0, rc=rc)
929 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
932 if (localpet == 0)
then
937 call nemsio_readrecv(gfile, vname, vlevtyp, vlev, dummy, 0, iret)
938 if (iret /= 0) call
error_handler(
"READING HGT RECORD.", iret)
939 print*,
'hgt ',vlev, maxval(dummy),minval(dummy)
940 dummy2d = reshape(dummy, (/i_input,j_input/))
943 print*,
"- CALL FieldScatter FOR TERRAIN."
944 call esmf_fieldscatter(terrain_input_grid, dummy2d, rootpet=0, rc=rc)
945 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
948 call nemsio_close(gfile)
950 deallocate(dummy, dummy2d, dummy3d)
966 print*,
"- COMPUTE 3-D PRESSURE."
968 print*,
"- CALL FieldGet FOR DELTA PRESSURE."
970 call esmf_fieldget(dpres_input_grid, &
971 computationallbound=clb, &
972 computationalubound=cub, &
973 farrayptr=dpresptr, rc=rc)
974 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
977 print*,
"- CALL FieldGet FOR 3-D PRESSURE."
979 call esmf_fieldget(pres_input_grid, &
980 farrayptr=presptr, rc=rc)
981 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
984 print*,
"- CALL FieldGet FOR SURFACE PRESSURE."
986 call esmf_fieldget(ps_input_grid, &
987 farrayptr=psptr, rc=rc)
988 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
991 allocate(pres_interface(levp1_input))
993 if (localpet == 0)
then
994 do k = clb(3), cub(3)
995 print*,
'dpres is ',cub(1),cub(2),k, dpresptr(cub(1),cub(2),k)
999 do i = clb(1), cub(1)
1000 do j = clb(2), cub(2)
1001 pres_interface(levp1_input) = vcoord(levp1_input,1,1)
1002 do k = lev_input, 1, -1
1003 pres_interface(k) = pres_interface(k+1) + dpresptr(i,j,k)
1005 psptr(i,j) = pres_interface(1)
1007 presptr(i,j,k) = (pres_interface(k) + pres_interface(k+1)) / 2.0_8
1014 if (localpet == 0)
then
1015 print*,
'psfc is ',clb(1),clb(2),psptr(clb(1),clb(2))
1016 print*,
'pres is ',clb(1),clb(2),presptr(clb(1),clb(2),:)
1019 print*,
'pres check 1',localpet,maxval(presptr(:,:,1)),minval(presptr(:,:,1))
1020 print*,
'pres check lev',localpet,maxval(presptr(:,:,lev_input)),minval(presptr(:,:,lev_input))
1022 deallocate(pres_interface)
1024 call esmf_fielddestroy(dpres_input_grid, rc=rc)
1040 integer,
intent(in) :: localpet
1042 character(len=500) :: tilefile
1045 integer :: clb(3), cub(3)
1046 integer :: rc, tile, ncid, id_var
1047 integer :: error, id_dim
1049 real(esmf_kind_r8),
allocatable :: ak(:)
1050 real(esmf_kind_r8),
pointer :: presptr(:,:,:), psptr(:,:)
1051 real(esmf_kind_r8),
pointer :: dpresptr(:,:,:)
1052 real(esmf_kind_r8),
allocatable :: data_one_tile(:,:)
1053 real(esmf_kind_r8),
allocatable :: data_one_tile_3d(:,:,:)
1054 real(esmf_kind_r8),
allocatable :: pres_interface(:)
1060 tilefile = trim(data_dir_input_grid) //
"/" // trim(atm_core_files_input_grid(7))
1061 print*,
"- READ ATM VERTICAL LEVELS FROM: ", trim(tilefile)
1062 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1063 call
netcdf_err(error,
'opening: '//trim(tilefile) )
1065 error=nf90_inq_dimid(ncid,
'xaxis_1', id_dim)
1066 call
netcdf_err(error,
'reading xaxis_1 id' )
1067 error=nf90_inquire_dimension(ncid,id_dim,len=levp1_input)
1068 call
netcdf_err(error,
'reading xaxis_1 value' )
1070 lev_input = levp1_input - 1
1072 allocate(ak(levp1_input))
1074 error=nf90_inq_varid(ncid,
'ak', id_var)
1076 error=nf90_get_var(ncid, id_var, ak)
1079 error = nf90_close(ncid)
1087 print*,
"- CALL FieldCreate FOR INPUT GRID DELTA PRESSURE."
1088 dpres_input_grid = esmf_fieldcreate(input_grid, &
1089 typekind=esmf_typekind_r8, &
1090 staggerloc=esmf_staggerloc_center, &
1091 ungriddedlbound=(/1/), &
1092 ungriddedubound=(/lev_input/), rc=rc)
1093 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1096 if (localpet < num_tiles_input_grid)
then
1097 allocate(data_one_tile_3d(i_input,j_input,lev_input))
1098 allocate(data_one_tile(i_input,j_input))
1100 allocate(data_one_tile_3d(0,0,0))
1101 allocate(data_one_tile(0,0))
1104 if (localpet < num_tiles_input_grid)
then
1106 tilefile= trim(data_dir_input_grid) //
"/" // trim(atm_core_files_input_grid(tile))
1107 print*,
"- READ ATMOSPHERIC CORE FILE: ", trim(tilefile)
1108 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1109 call
netcdf_err(error,
'opening: '//trim(tilefile) )
1112 if (localpet < num_tiles_input_grid)
then
1113 error=nf90_inq_varid(ncid,
'phis', id_var)
1115 error=nf90_get_var(ncid, id_var, data_one_tile)
1117 data_one_tile = data_one_tile / 9.806_8
1120 do tile = 1, num_tiles_input_grid
1121 print*,
"- CALL FieldScatter FOR INPUT GRID TERRAIN for tile ",tile
1122 call esmf_fieldscatter(terrain_input_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=rc)
1123 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1127 if (localpet < num_tiles_input_grid)
then
1135 data_one_tile_3d = 0.0_8
1138 do tile = 1, num_tiles_input_grid
1139 print*,
"- CALL FieldScatter FOR INPUT GRID VERTICAL VELOCITY for tile ",tile
1140 call esmf_fieldscatter(dzdt_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1141 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1145 if (localpet < num_tiles_input_grid)
then
1146 error=nf90_inq_varid(ncid,
'T', id_var)
1148 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1150 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1153 do tile = 1, num_tiles_input_grid
1154 print*,
"- CALL FieldScatter FOR INPUT GRID TEMPERATURE."
1155 call esmf_fieldscatter(temp_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1156 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1160 if (localpet < num_tiles_input_grid)
then
1161 error=nf90_inq_varid(ncid,
'delp', id_var)
1163 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1165 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1168 do tile = 1, num_tiles_input_grid
1169 print*,
"- CALL FieldScatter FOR INPUT DELTA PRESSURE."
1170 call esmf_fieldscatter(dpres_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1171 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1175 if (localpet < num_tiles_input_grid)
then
1176 error=nf90_inq_varid(ncid,
'ua', id_var)
1178 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1180 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1183 do tile = 1, num_tiles_input_grid
1184 print*,
"- CALL FieldScatter FOR INPUT GRID U."
1185 call esmf_fieldscatter(u_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1186 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1190 if (localpet < num_tiles_input_grid)
then
1191 error=nf90_inq_varid(ncid,
'va', id_var)
1193 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1195 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1198 do tile = 1, num_tiles_input_grid
1199 print*,
"- CALL FieldScatter FOR INPUT GRID V."
1200 call esmf_fieldscatter(v_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1201 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1205 if (localpet < num_tiles_input_grid) error = nf90_close(ncid)
1207 if (localpet < num_tiles_input_grid)
then
1209 tilefile= trim(data_dir_input_grid) //
"/" // trim(atm_tracer_files_input_grid(tile))
1210 print*,
"- READ ATMOSPHERIC TRACER FILE: ", trim(tilefile)
1211 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1212 call
netcdf_err(error,
'opening: '//trim(tilefile) )
1215 do i = 1, num_tracers_input
1217 if (localpet < num_tiles_input_grid)
then
1218 error=nf90_inq_varid(ncid, tracers_input(i), id_var)
1220 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1222 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1225 do tile = 1, num_tiles_input_grid
1226 print*,
"- CALL FieldScatter FOR INPUT ", trim(tracers_input(i))
1227 call esmf_fieldscatter(tracers_input_grid(i), data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1228 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1234 if (localpet < num_tiles_input_grid) error=nf90_close(ncid)
1246 print*,
"- CALL FieldGet FOR SURFACE PRESSURE."
1247 call esmf_fieldget(ps_input_grid, &
1248 farrayptr=psptr, rc=rc)
1249 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1252 print*,
"- CALL FieldGet FOR PRESSURE."
1253 call esmf_fieldget(pres_input_grid, &
1254 computationallbound=clb, &
1255 computationalubound=cub, &
1256 farrayptr=presptr, rc=rc)
1257 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1260 print*,
"- CALL FieldGet FOR DELTA PRESSURE."
1261 call esmf_fieldget(dpres_input_grid, &
1262 farrayptr=dpresptr, rc=rc)
1263 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1266 allocate(pres_interface(levp1_input))
1268 do i = clb(1), cub(1)
1269 do j = clb(2), cub(2)
1270 pres_interface(levp1_input) = ak(1)
1271 do k = (levp1_input-1), 1, -1
1272 pres_interface(k) = pres_interface(k+1) + dpresptr(i,j,k)
1275 presptr(i,j,k) = (pres_interface(k) + pres_interface(k+1)) / 2.0_8
1277 psptr(i,j) = pres_interface(1)
1282 deallocate(pres_interface)
1284 call esmf_fielddestroy(dpres_input_grid, rc=rc)
1286 deallocate(data_one_tile_3d, data_one_tile)
1301 integer,
intent(in) :: localpet
1303 character(len=500) :: tilefile
1305 integer :: start(3), count(3), iscnt
1306 integer :: error, ncid, num_tracers_file
1307 integer :: id_dim, idim_input, jdim_input
1308 integer :: id_var, rc, nprocs, max_procs
1309 integer :: kdim, remainder, myrank, i, j, k, n
1310 integer :: clb(3), cub(3)
1311 integer,
allocatable :: kcount(:), startk(:), displ(:)
1312 integer,
allocatable :: ircnt(:)
1314 real(esmf_kind_r8),
allocatable :: phalf(:)
1315 real(esmf_kind_r8),
allocatable :: pres_interface(:)
1316 real(kind=4),
allocatable :: dummy3d(:,:,:)
1317 real(kind=4),
allocatable :: dummy3dall(:,:,:)
1318 real(esmf_kind_r8),
allocatable :: dummy3dflip(:,:,:)
1319 real(esmf_kind_r8),
allocatable :: dummy(:,:)
1320 real(esmf_kind_r8),
pointer :: presptr(:,:,:), dpresptr(:,:,:)
1321 real(esmf_kind_r8),
pointer :: psptr(:,:)
1323 print*,
"- READ INPUT ATMOS DATA FROM GAUSSIAN NETCDF FILE."
1325 tilefile = trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(1))
1326 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1327 call
netcdf_err(error,
'opening: '//trim(tilefile) )
1329 error=nf90_inq_dimid(ncid,
'grid_xt', id_dim)
1330 call
netcdf_err(error,
'reading grid_xt id' )
1331 error=nf90_inquire_dimension(ncid,id_dim,len=idim_input)
1332 call
netcdf_err(error,
'reading grid_xt value' )
1334 error=nf90_inq_dimid(ncid,
'grid_yt', id_dim)
1335 call
netcdf_err(error,
'reading grid_yt id' )
1336 error=nf90_inquire_dimension(ncid,id_dim,len=jdim_input)
1337 call
netcdf_err(error,
'reading grid_yt value' )
1339 if (idim_input /= i_input .or. jdim_input /= j_input)
then
1340 call
error_handler(
"DIMENSION MISMATCH BETWEEN SFC AND OROG FILES.", 2)
1343 error=nf90_inq_dimid(ncid,
'pfull', id_dim)
1345 error=nf90_inquire_dimension(ncid,id_dim,len=lev_input)
1346 call
netcdf_err(error,
'reading pfull value' )
1348 error=nf90_inq_dimid(ncid,
'phalf', id_dim)
1350 error=nf90_inquire_dimension(ncid,id_dim,len=levp1_input)
1351 call
netcdf_err(error,
'reading phalf value' )
1352 allocate(phalf(levp1_input))
1353 error=nf90_inq_varid(ncid,
'phalf', id_var)
1354 call
netcdf_err(error,
'getting phalf varid' )
1355 error=nf90_get_var(ncid, id_var, phalf)
1356 call
netcdf_err(error,
'reading phalf varid' )
1358 error=nf90_get_att(ncid, nf90_global,
'ncnsto', num_tracers_file)
1359 call
netcdf_err(error,
'reading ntracer value' )
1361 call mpi_comm_size(mpi_comm_world, nprocs, error)
1362 print*,
'- Running with ', nprocs,
' processors'
1364 call mpi_comm_rank(mpi_comm_world, myrank, error)
1365 print*,
'- myrank/localpet is ',myrank,localpet
1368 if (nprocs > lev_input)
then
1369 max_procs = lev_input
1372 kdim = lev_input / max_procs
1373 remainder = lev_input - (max_procs*kdim)
1375 allocate(kcount(0:nprocs-1))
1377 allocate(startk(0:nprocs-1))
1379 allocate(displ(0:nprocs-1))
1381 allocate(ircnt(0:nprocs-1))
1384 do k = 0, max_procs-2
1387 kcount(max_procs-1) = kdim + remainder
1390 do k = 1, max_procs-1
1391 startk(k) = startk(k-1) + kcount(k-1)
1394 ircnt(:) = idim_input * jdim_input * kcount(:)
1397 do k = 1, max_procs-1
1398 displ(k) = displ(k-1) + ircnt(k-1)
1401 iscnt=idim_input*jdim_input*kcount(myrank)
1405 if (myrank <= max_procs-1)
then
1406 allocate(dummy3d(idim_input,jdim_input,kcount(myrank)))
1408 allocate(dummy3d(0,0,0))
1411 if (myrank == 0)
then
1412 allocate(dummy3dall(idim_input,jdim_input,lev_input))
1414 allocate(dummy3dflip(idim_input,jdim_input,lev_input))
1416 allocate(dummy(idim_input,jdim_input))
1419 allocate(dummy3dall(0,0,0))
1420 allocate(dummy3dflip(0,0,0))
1421 allocate(dummy(0,0))
1430 print*,
"- CALL FieldCreate FOR INPUT GRID DELTA PRESSURE."
1431 dpres_input_grid = esmf_fieldcreate(input_grid, &
1432 typekind=esmf_typekind_r8, &
1433 staggerloc=esmf_staggerloc_center, &
1434 ungriddedlbound=(/1/), &
1435 ungriddedubound=(/lev_input/), rc=rc)
1436 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1441 if (myrank <= max_procs-1)
then
1442 start = (/1,1,startk(myrank)/)
1443 count = (/idim_input,jdim_input,kcount(myrank)/)
1444 error=nf90_inq_varid(ncid,
'tmp', id_var)
1445 call
netcdf_err(error,
'reading tmp field id' )
1446 error=nf90_get_var(ncid, id_var, dummy3d, start=start, count=count)
1450 call mpi_gatherv(dummy3d, iscnt, mpi_real, &
1451 dummy3dall, ircnt, displ, mpi_real, &
1452 0, mpi_comm_world, error)
1453 if (error /= 0) call
error_handler(
"IN mpi_gatherv of temperature", error)
1455 if (myrank == 0)
then
1456 dummy3dflip(:,:,1:lev_input) = dummy3dall(:,:,lev_input:1:-1)
1459 print*,
"- CALL FieldScatter FOR INPUT GRID TEMPERATURE "
1460 call esmf_fieldscatter(temp_input_grid, dummy3dflip, rootpet=0, rc=rc)
1461 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1466 if (myrank <= max_procs-1)
then
1467 error=nf90_inq_varid(ncid,
'dpres', id_var)
1468 call
netcdf_err(error,
'reading dpres field id' )
1469 error=nf90_get_var(ncid, id_var, dummy3d, start=start, count=count)
1470 call
netcdf_err(error,
'reading dpres field' )
1473 call mpi_gatherv(dummy3d, iscnt, mpi_real, &
1474 dummy3dall, ircnt, displ, mpi_real, &
1475 0, mpi_comm_world, error)
1476 if (error /= 0) call
error_handler(
"IN mpi_gatherv of dpres", error)
1478 if (myrank == 0)
then
1479 dummy3dflip(:,:,1:lev_input) = dummy3dall(:,:,lev_input:1:-1)
1482 print*,
"- CALL FieldScatter FOR INPUT GRID DPRES "
1483 call esmf_fieldscatter(dpres_input_grid, dummy3dflip, rootpet=0, rc=rc)
1484 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1489 if (myrank <= max_procs-1)
then
1490 error=nf90_inq_varid(ncid,
'ugrd', id_var)
1491 call
netcdf_err(error,
'reading ugrd field id' )
1492 error=nf90_get_var(ncid, id_var, dummy3d, start=start, count=count)
1493 call
netcdf_err(error,
'reading ugrd field' )
1496 call mpi_gatherv(dummy3d, iscnt, mpi_real, &
1497 dummy3dall, ircnt, displ, mpi_real, &
1498 0, mpi_comm_world, error)
1499 if (error /= 0) call
error_handler(
"IN mpi_gatherv of ugrd", error)
1501 if (myrank == 0)
then
1502 dummy3dflip(:,:,1:lev_input) = dummy3dall(:,:,lev_input:1:-1)
1505 print*,
"- CALL FieldScatter FOR INPUT GRID UGRD "
1506 call esmf_fieldscatter(u_input_grid, dummy3dflip, rootpet=0, rc=rc)
1507 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1512 if (myrank <= max_procs-1)
then
1513 error=nf90_inq_varid(ncid,
'vgrd', id_var)
1514 call
netcdf_err(error,
'reading vgrd field id' )
1515 error=nf90_get_var(ncid, id_var, dummy3d, start=start, count=count)
1516 call
netcdf_err(error,
'reading vgrd field' )
1519 call mpi_gatherv(dummy3d, iscnt, mpi_real, &
1520 dummy3dall, ircnt, displ, mpi_real, &
1521 0, mpi_comm_world, error)
1522 if (error /= 0) call
error_handler(
"IN mpi_gatherv of vgrd", error)
1524 if (myrank == 0)
then
1525 dummy3dflip(:,:,1:lev_input) = dummy3dall(:,:,lev_input:1:-1)
1528 print*,
"- CALL FieldScatter FOR INPUT GRID VGRD "
1529 call esmf_fieldscatter(v_input_grid, dummy3dflip, rootpet=0, rc=rc)
1530 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1535 do n = 1, num_tracers_input
1537 if (myrank <= max_procs-1)
then
1538 error=nf90_inq_varid(ncid, tracers_input(n), id_var)
1539 call
netcdf_err(error,
'reading tracer field id' )
1540 error=nf90_get_var(ncid, id_var, dummy3d, start=start, count=count)
1541 call
netcdf_err(error,
'reading tracer field' )
1544 call mpi_gatherv(dummy3d, iscnt, mpi_real, &
1545 dummy3dall, ircnt, displ, mpi_real, &
1546 0, mpi_comm_world, error)
1547 if (error /= 0) call
error_handler(
"IN mpi_gatherv of tracer", error)
1549 if (myrank == 0)
then
1550 dummy3dflip(:,:,1:lev_input) = dummy3dall(:,:,lev_input:1:-1)
1551 where(dummy3dflip < 0.0) dummy3dflip = 0.0
1554 print*,
"- CALL FieldScatter FOR INPUT GRID ", tracers_input(n)
1555 call esmf_fieldscatter(tracers_input_grid(n), dummy3dflip, rootpet=0, rc=rc)
1556 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1563 if (myrank == 0)
then
1567 print*,
"- CALL FieldScatter FOR INPUT GRID DZDT"
1568 call esmf_fieldscatter(dzdt_input_grid, dummy3dflip, rootpet=0, rc=rc)
1569 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1572 deallocate(dummy3dflip, dummy3dall, dummy3d)
1577 print*,
"- READ TERRAIN."
1578 error=nf90_inq_varid(ncid,
'hgtsfc', id_var)
1579 call
netcdf_err(error,
'reading hgtsfc field id' )
1580 error=nf90_get_var(ncid, id_var, dummy)
1581 call
netcdf_err(error,
'reading hgtsfc field' )
1584 print*,
"- CALL FieldScatter FOR INPUT GRID TERRAIN."
1585 call esmf_fieldscatter(terrain_input_grid, dummy, rootpet=0, rc=rc)
1586 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1592 print*,
"- READ SURFACE P."
1593 error=nf90_inq_varid(ncid,
'pressfc', id_var)
1594 call
netcdf_err(error,
'reading pressfc field id' )
1595 error=nf90_get_var(ncid, id_var, dummy)
1596 call
netcdf_err(error,
'reading pressfc field' )
1599 print*,
"- CALL FieldScatter FOR INPUT GRID SURFACE P."
1600 call esmf_fieldscatter(ps_input_grid, dummy, rootpet=0, rc=rc)
1601 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1604 deallocate(kcount, startk, displ, ircnt, dummy)
1616 print*,
"- CALL FieldGet FOR PRESSURE."
1617 call esmf_fieldget(pres_input_grid, &
1618 computationallbound=clb, &
1619 computationalubound=cub, &
1620 farrayptr=presptr, rc=rc)
1621 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1624 print*,
"- CALL FieldGet FOR DELTA PRESSURE."
1625 call esmf_fieldget(dpres_input_grid, &
1626 farrayptr=dpresptr, rc=rc)
1627 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1630 print*,
"- CALL FieldGet FOR SURFACE PRESSURE."
1631 call esmf_fieldget(ps_input_grid, &
1632 farrayptr=psptr, rc=rc)
1633 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1636 allocate(pres_interface(levp1_input))
1651 do i = clb(1), cub(1)
1652 do j = clb(2), cub(2)
1653 pres_interface(levp1_input) = phalf(1) * 100.0_8
1654 do k = lev_input, 1, -1
1655 pres_interface(k) = pres_interface(k+1) + dpresptr(i,j,k)
1657 psptr(i,j) = pres_interface(1)
1659 presptr(i,j,k) = (pres_interface(k) + pres_interface(k+1)) / 2.0_8
1664 deallocate(pres_interface, phalf)
1666 call esmf_fielddestroy(dpres_input_grid, rc=rc)
1685 integer,
intent(in) :: localpet
1687 character(len=500) :: tilefile
1689 integer :: error, ncid, rc, tile
1690 integer :: id_dim, idim_input, jdim_input
1691 integer :: id_var, i, j, k, n
1692 integer :: clb(3), cub(3), num_tracers_file
1694 real(esmf_kind_r8),
allocatable :: data_one_tile(:,:)
1695 real(esmf_kind_r8),
allocatable :: data_one_tile_3d(:,:,:)
1696 real(esmf_kind_r8),
pointer :: presptr(:,:,:), dpresptr(:,:,:)
1697 real(esmf_kind_r8),
pointer :: psptr(:,:)
1698 real(esmf_kind_r8),
allocatable :: pres_interface(:), phalf(:)
1700 print*,
"- READ INPUT ATMOS DATA FROM TILED HISTORY FILES."
1702 tilefile = trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(1))
1703 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1704 call
netcdf_err(error,
'opening: '//trim(tilefile) )
1706 error=nf90_inq_dimid(ncid,
'grid_xt', id_dim)
1707 call
netcdf_err(error,
'reading grid_xt id' )
1708 error=nf90_inquire_dimension(ncid,id_dim,len=idim_input)
1709 call
netcdf_err(error,
'reading grid_xt value' )
1711 error=nf90_inq_dimid(ncid,
'grid_yt', id_dim)
1712 call
netcdf_err(error,
'reading grid_yt id' )
1713 error=nf90_inquire_dimension(ncid,id_dim,len=jdim_input)
1714 call
netcdf_err(error,
'reading grid_yt value' )
1716 if (idim_input /= i_input .or. jdim_input /= j_input)
then
1717 call
error_handler(
"DIMENSION MISMATCH BETWEEN SFC AND OROG FILES.", 2)
1720 error=nf90_inq_dimid(ncid,
'pfull', id_dim)
1722 error=nf90_inquire_dimension(ncid,id_dim,len=lev_input)
1723 call
netcdf_err(error,
'reading pfull value' )
1725 error=nf90_inq_dimid(ncid,
'phalf', id_dim)
1727 error=nf90_inquire_dimension(ncid,id_dim,len=levp1_input)
1728 call
netcdf_err(error,
'reading phalf value' )
1729 allocate(phalf(levp1_input))
1730 error=nf90_inq_varid(ncid,
'phalf', id_var)
1731 call
netcdf_err(error,
'getting phalf varid' )
1732 error=nf90_get_var(ncid, id_var, phalf)
1733 call
netcdf_err(error,
'reading phalf varid' )
1735 error=nf90_get_att(ncid, nf90_global,
'ncnsto', num_tracers_file)
1736 call
netcdf_err(error,
'reading ntracer value' )
1738 error = nf90_close(ncid)
1740 print*,
'- FILE HAS ', num_tracers_file,
' TRACERS.'
1741 print*,
'- WILL PROCESS ', num_tracers_input,
' TRACERS.'
1749 print*,
"- CALL FieldCreate FOR INPUT GRID DELTA PRESSURE."
1750 dpres_input_grid = esmf_fieldcreate(input_grid, &
1751 typekind=esmf_typekind_r8, &
1752 staggerloc=esmf_staggerloc_center, &
1753 ungriddedlbound=(/1/), &
1754 ungriddedubound=(/lev_input/), rc=rc)
1755 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1758 if (localpet < num_tiles_input_grid)
then
1759 allocate(data_one_tile(i_input,j_input))
1760 allocate(data_one_tile_3d(i_input,j_input,lev_input))
1762 allocate(data_one_tile(0,0))
1763 allocate(data_one_tile_3d(0,0,0))
1766 if (localpet < num_tiles_input_grid)
then
1768 tilefile= trim(data_dir_input_grid) //
"/" // trim(atm_files_input_grid(tile))
1769 print*,
"- READ ATMOSPHERIC DATA FROM: ", trim(tilefile)
1770 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1771 call
netcdf_err(error,
'opening: '//trim(tilefile) )
1774 if (localpet < num_tiles_input_grid)
then
1784 data_one_tile_3d = 0.0_8
1787 do tile = 1, num_tiles_input_grid
1788 print*,
"- CALL FieldScatter FOR INPUT GRID VERTICAL VELOCITY."
1789 call esmf_fieldscatter(dzdt_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1790 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1794 do n = 1, num_tracers_input
1796 if (localpet < num_tiles_input_grid)
then
1797 print*,
"- READ ", trim(tracers_input(n))
1798 error=nf90_inq_varid(ncid, tracers_input(n), id_var)
1800 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1802 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1805 do tile = 1, num_tiles_input_grid
1806 print*,
"- CALL FieldScatter FOR INPUT GRID TRACER ", trim(tracers_input(n))
1807 call esmf_fieldscatter(tracers_input_grid(n), data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1808 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1814 if (localpet < num_tiles_input_grid)
then
1815 print*,
"- READ TEMPERATURE."
1816 error=nf90_inq_varid(ncid,
'tmp', id_var)
1818 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1820 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1823 do tile = 1, num_tiles_input_grid
1824 print*,
"- CALL FieldScatter FOR INPUT GRID TEMPERATURE."
1825 call esmf_fieldscatter(temp_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1826 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1830 if (localpet < num_tiles_input_grid)
then
1831 print*,
"- READ U-WIND."
1832 error=nf90_inq_varid(ncid,
'ugrd', id_var)
1834 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1836 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1839 do tile = 1, num_tiles_input_grid
1840 print*,
"- CALL FieldScatter FOR INPUT GRID U."
1841 call esmf_fieldscatter(u_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1842 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1846 if (localpet < num_tiles_input_grid)
then
1847 print*,
"- READ V-WIND."
1848 error=nf90_inq_varid(ncid,
'vgrd', id_var)
1850 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1852 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1855 do tile = 1, num_tiles_input_grid
1856 print*,
"- CALL FieldScatter FOR INPUT GRID V."
1857 call esmf_fieldscatter(v_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1858 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1862 if (localpet < num_tiles_input_grid)
then
1863 print*,
"- READ SURFACE PRESSURE."
1864 error=nf90_inq_varid(ncid,
'pressfc', id_var)
1866 error=nf90_get_var(ncid, id_var, data_one_tile)
1870 do tile = 1, num_tiles_input_grid
1871 print*,
"- CALL FieldScatter FOR INPUT GRID SURFACE PRESSURE."
1872 call esmf_fieldscatter(ps_input_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=rc)
1873 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1877 if (localpet < num_tiles_input_grid)
then
1878 print*,
"- READ TERRAIN."
1879 error=nf90_inq_varid(ncid,
'hgtsfc', id_var)
1881 error=nf90_get_var(ncid, id_var, data_one_tile)
1885 do tile = 1, num_tiles_input_grid
1886 print*,
"- CALL FieldScatter FOR INPUT GRID TERRAIN."
1887 call esmf_fieldscatter(terrain_input_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=rc)
1888 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1892 if (localpet < num_tiles_input_grid)
then
1893 print*,
"- READ DELTA PRESSURE."
1894 error=nf90_inq_varid(ncid,
'dpres', id_var)
1896 error=nf90_get_var(ncid, id_var, data_one_tile_3d)
1898 data_one_tile_3d(:,:,1:lev_input) = data_one_tile_3d(:,:,lev_input:1:-1)
1901 do tile = 1, num_tiles_input_grid
1902 print*,
"- CALL FieldScatter FOR INPUT DELTA PRESSURE."
1903 call esmf_fieldscatter(dpres_input_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=rc)
1904 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1908 if (localpet < num_tiles_input_grid) error = nf90_close(ncid)
1910 deallocate(data_one_tile_3d, data_one_tile)
1922 print*,
"- CALL FieldGet FOR PRESSURE."
1923 call esmf_fieldget(pres_input_grid, &
1924 computationallbound=clb, &
1925 computationalubound=cub, &
1926 farrayptr=presptr, rc=rc)
1927 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1930 print*,
"- CALL FieldGet FOR DELTA PRESSURE."
1931 call esmf_fieldget(dpres_input_grid, &
1932 farrayptr=dpresptr, rc=rc)
1933 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1936 print*,
"- CALL FieldGet FOR SURFACE PRESSURE."
1937 call esmf_fieldget(ps_input_grid, &
1938 farrayptr=psptr, rc=rc)
1939 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1942 allocate(pres_interface(levp1_input))
1948 do i = clb(1), cub(1)
1949 do j = clb(2), cub(2)
1950 pres_interface(1) = psptr(i,j)
1951 do k = 2, levp1_input
1952 pres_interface(k) = pres_interface(k-1) - dpresptr(i,j,k-1)
1955 presptr(i,j,k) = (pres_interface(k) + pres_interface(k+1)) / 2.0_8
1960 deallocate(pres_interface, phalf)
1962 call esmf_fielddestroy(dpres_input_grid, rc=rc)
1979 integer,
intent(in) :: localpet
1981 integer,
parameter :: ntrac_max=14
1982 integer,
parameter :: max_levs=1000
1984 character(len=300) :: the_file
1985 character(len=20) :: vname, &
1986 trac_names_vmap(ntrac_max), &
1988 method, tracers_input_vmap(num_tracers_input), &
1989 tracers_default(ntrac_max)
1991 integer :: i, j, k, n
1993 integer :: rc, clb(3), cub(3)
1994 integer :: vlev, iret,varnum, o3n, pdt_num
1995 integer :: intrp_ier, done_print
1996 integer :: trac_names_oct10(ntrac_max)
1997 integer :: tracers_input_oct10(num_tracers_input)
1998 integer :: trac_names_oct11(ntrac_max)
1999 integer :: tracers_input_oct11(num_tracers_input)
2000 integer :: lugb, lugi, jdisc, jpdt(200), jgdt(200), iscale
2001 integer :: jids(200), jpdtn, jgdtn, octet_23, octet_29
2002 integer :: count_spfh, count_rh, count_icmr, count_scliwc
2003 integer :: count_cice, count_rwmr, count_scllwc, count
2005 logical :: conv_omega=.false., &
2008 use_rh=.false. , unpack, &
2009 all_empty, is_missing
2011 real(esmf_kind_r8),
allocatable :: dum2d_1(:,:)
2014 real(esmf_kind_r8) :: rlevs_hold(max_levs)
2015 real(esmf_kind_r8),
allocatable :: rlevs(:)
2016 real(esmf_kind_r4),
allocatable :: dummy2d(:,:)
2017 real(esmf_kind_r8),
allocatable :: dummy3d(:,:,:), dummy2d_8(:,:),&
2018 u_tmp_3d(:,:,:), v_tmp_3d(:,:,:)
2019 real(esmf_kind_r8),
pointer :: presptr(:,:,:), psptr(:,:),tptr(:,:,:), &
2020 qptr(:,:,:), wptr(:,:,:), &
2021 uptr(:,:,:), vptr(:,:,:)
2022 real(esmf_kind_r4) :: value
2023 real(esmf_kind_r8),
parameter :: p0 = 100000.0
2024 real(esmf_kind_r8),
allocatable :: dummy3d_col_in(:),dummy3d_col_out(:)
2025 real(esmf_kind_r8),
parameter :: intrp_missing = -999.0
2026 real(esmf_kind_r4),
parameter :: lev_no_tr_fill = 20000.0
2027 real(esmf_kind_r4),
parameter :: lev_no_o3_fill = 40000.0
2029 type(gribfield
) :: gfld
2033 trac_names_oct10 = (/1, 1, 14, 1, 1, 1, 1, 6, 6, 1, 6, 13, 13, 2 /)
2034 trac_names_oct11 = (/0, 22, 192, 23, 24, 25, 32, 1, 29, 100, 28, 193, 192, 2 /)
2036 trac_names_vmap = (/
"sphum ",
"liq_wat ",
"o3mr ",
"ice_wat ", &
2037 "rainwat ",
"snowwat ",
"graupel ",
"cld_amt ",
"ice_nc ", &
2038 "rain_nc ",
"water_nc",
"liq_aero",
"ice_aero", &
2041 tracers_default = (/
"sphum ",
"liq_wat ",
"o3mr ",
"ice_wat ", &
2042 "rainwat ",
"snowwat ",
"graupel ",
"cld_amt ",
"ice_nc ", &
2043 "rain_nc ",
"water_nc",
"liq_aero",
"ice_aero", &
2046 the_file = trim(data_dir_input_grid) //
"/" // trim(grib2_file_input_grid)
2048 print*,
"- READ ATMOS DATA FROM GRIB2 FILE: ", trim(the_file)
2050 if (localpet == 0)
then
2054 call baopenr(lugb,the_file,iret)
2055 if (iret /= 0) call
error_handler(
"ERROR OPENING GRIB2 FILE.", iret)
2066 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2067 unpack, k, gfld, iret)
2079 if (gfld%idsect(1) == 7 .and. gfld%idsect(2) == 2)
then
2080 print*,
'- THIS IS NCEP GEFS DATA.'
2105 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2106 unpack, k, gfld, iret)
2109 print*,
'- DATA IS ON HYBRID LEVELS.'
2114 print*,
'- DATA IS ON ISOBARIC LEVELS.'
2131 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2132 unpack, k, gfld, iret)
2136 if (gfld%discipline == 0)
then
2137 if (gfld%ipdtnum == pdt_num)
then
2138 if (gfld%ipdtmpl(1) == 2 .and. gfld%ipdtmpl(2) == 2)
then
2140 if (gfld%ipdtmpl(10) == octet_23 .and. gfld%ipdtmpl(13) == octet_29)
then
2143 lev_input = lev_input + 1
2144 iscale = 10 ** gfld%ipdtmpl(11)
2145 rlevs_hold(lev_input) = float(gfld%ipdtmpl(12))/float(iscale)
2156 call mpi_barrier(mpi_comm_world, iret)
2157 call mpi_bcast(isnative,1,mpi_logical,0,mpi_comm_world,iret)
2158 call mpi_bcast(lev_input,1,mpi_integer,0,mpi_comm_world,iret)
2159 call mpi_bcast(pdt_num,1,mpi_integer,0,mpi_comm_world,iret)
2160 call mpi_bcast(rlevs_hold, max_levs, mpi_integer,0,mpi_comm_world,iret)
2162 allocate(slevs(lev_input))
2163 allocate(rlevs(lev_input))
2164 allocate(dummy3d_col_in(lev_input))
2165 allocate(dummy3d_col_out(lev_input))
2167 levp1_input = lev_input + 1
2172 rlevs(i) = rlevs_hold(i)
2179 write(slevs(i),
'(i6)') nint(rlevs(i))
2180 slevs(i) = trim(slevs(i)) //
" hybrid"
2182 if (any(slevs(1:i-1)==slevs(i))) call
error_handler(
"Duplicate vertical level entries found.",1)
2185 write(slevs(i),
'(f11.2)') rlevs(i)
2186 slevs(i) = trim(slevs(i)) //
" Pa"
2188 if (any(slevs(1:i-1)==slevs(i))) call
error_handler(
"Duplicate vertical level entries found.",1)
2193 if(localpet == 0)
then
2195 print*,
"- LEVEL AFTER SORT = ",trim(slevs(i))
2201 if (localpet == 0)
then
2212 do vlev = 1, lev_input
2214 jpdt(12) = nint(rlevs(vlev))
2216 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2217 unpack, k, gfld, iret)
2220 count_spfh = count_spfh + 1
2228 do vlev = 1, lev_input
2230 jpdt(12) = nint(rlevs(vlev))
2232 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2233 unpack, k, gfld, iret)
2236 count_rh = count_rh + 1
2240 if (count_spfh /= lev_input)
then
2244 if (count_spfh == 0 .or. use_rh)
then
2245 if (count_rh == 0)
then
2246 call
error_handler(
"READING ATMOSPHERIC WATER VAPOR VARIABLE.", 2)
2249 trac_names_oct10(1) = 1
2250 trac_names_oct11(1) = 1
2251 print*,
"- FILE CONTAINS RH."
2253 print*,
"- FILE CONTAINS SPFH."
2258 call mpi_barrier(mpi_comm_world, rc)
2259 call mpi_bcast(hasspfh,1,mpi_logical,0,mpi_comm_world,rc)
2263 if (localpet == 0)
then
2276 do vlev = 1, lev_input
2281 jpdt(12) = nint(rlevs(vlev))
2283 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2284 unpack, k, gfld, iret)
2287 count_icmr = count_icmr + 1
2293 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2294 unpack, k, gfld, iret)
2297 count_scliwc = count_scliwc + 1
2303 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2304 unpack, k, gfld, iret)
2307 count_cice = count_cice + 1
2313 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2314 unpack, k, gfld, iret)
2317 count_rwmr = count_rwmr + 1
2324 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2325 unpack, k, gfld, iret)
2328 count_scllwc = count_scllwc + 1
2333 if (count_icmr == 0)
then
2334 if (count_scliwc == 0)
then
2335 if (count_cice == 0)
then
2336 print*,
'- FILE DOES NOT CONTAIN CICE.'
2338 trac_names_oct10(4) = 6
2339 trac_names_oct11(4) = 0
2340 print*,
"- FILE CONTAINS CICE."
2343 trac_names_oct10(4) = 1
2344 trac_names_oct11(4) = 84
2345 print*,
"- FILE CONTAINS SCLIWC."
2348 print*,
"- FILE CONTAINS ICMR."
2351 if (count_rwmr == 0)
then
2352 if (count_scllwc == 0)
then
2353 print*,
"- FILE DOES NOT CONTAIN SCLLWC."
2355 trac_names_oct10(4) = 1
2356 trac_names_oct11(4) = 83
2358 print*,
"- FILE CONTAINS SCLLWC."
2361 print*,
"- FILE CONTAINS CLWMR."
2366 call mpi_barrier(mpi_comm_world, rc)
2367 call mpi_bcast(trac_names_oct10,ntrac_max,mpi_integer,0,mpi_comm_world,rc)
2368 call mpi_bcast(trac_names_oct11,ntrac_max,mpi_integer,0,mpi_comm_world,rc)
2370 print*,
"- COUNT NUMBER OF TRACERS TO BE READ IN BASED ON PHYSICS SUITE TABLE"
2371 do n = 1, num_tracers_input
2373 vname = tracers_input(n)
2375 i = maxloc(merge(1.,0.,trac_names_vmap == vname),dim=1)
2377 tracers_input_vmap(n)=trac_names_vmap(i)
2378 tracers(n)=tracers_default(i)
2379 if(trim(tracers(n)) .eq.
"o3mr") o3n = n
2381 tracers_input_oct10(n) = trac_names_oct10(i)
2382 tracers_input_oct11(n) = trac_names_oct11(i)
2392 if (localpet == 0)
then
2393 allocate(dummy2d(i_input,j_input))
2394 allocate(dummy2d_8(i_input,j_input))
2395 allocate(dummy3d(i_input,j_input,lev_input))
2396 allocate(dum2d_1(i_input,j_input))
2398 allocate(dummy2d(0,0))
2399 allocate(dummy2d_8(0,0))
2400 allocate(dummy3d(0,0,0))
2401 allocate(dum2d_1(0,0))
2410 if (localpet == 0)
then
2412 print*,
"- READ TEMPERATURE."
2427 do vlev = 1, lev_input
2429 jpdt(12) = nint(rlevs(vlev))
2431 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2432 unpack, k, gfld, iret)
2434 call
error_handler(
"READING IN TEMPERATURE AT LEVEL "//trim(slevs(vlev)),iret)
2437 dum2d_1 = reshape(gfld%fld, (/i_input,j_input/) )
2439 dummy3d(:,:,vlev) = dum2d_1
2445 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT GRID TEMPERATURE."
2446 call esmf_fieldscatter(temp_input_grid, dummy3d, rootpet=0, rc=rc)
2447 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2452 do n = 1, num_tracers_input
2454 if (localpet == 0) print*,
"- READ ", trim(tracers_input_vmap(n))
2456 vname = tracers_input_vmap(n)
2457 call
get_var_cond(vname,this_miss_var_method=method, this_miss_var_value=value, &
2458 this_field_var_name=tmpstr,loc=varnum)
2460 if (n==1 .and. .not. hasspfh)
then
2461 print*,
"- CALL FieldGather TEMPERATURE."
2462 call esmf_fieldgather(temp_input_grid,dummy3d,rootpet=0, tile=1, rc=rc)
2463 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2467 if (localpet == 0)
then
2480 do vlev = 1, lev_input
2483 jpdt(1) = tracers_input_oct10(n)
2484 jpdt(2) = tracers_input_oct11(n)
2485 jpdt(12) = nint(rlevs(vlev))
2487 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2488 unpack, k, gfld, iret)
2504 is_missing = .false.
2506 do vlev = 1, lev_input
2510 jpdt(1) = tracers_input_oct10(n)
2511 jpdt(2) = tracers_input_oct11(n)
2512 jpdt(12) = nint(rlevs(vlev) )
2514 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2515 unpack, k, gfld, iret)
2518 dummy2d =
real((reshape(gfld%fld, (/i_input,j_input/) )), kind=esmf_kind_r4)
2520 if (trim(method) .eq.
'intrp' .and. .not.all_empty)
then
2521 dummy2d = intrp_missing
2526 if (.not.all_empty .and. n == o3n)
then
2527 if (rlevs(vlev) .lt. lev_no_o3_fill) &
2528 call
error_handler(
"TRACER "//trim(tracers(n))//
" HAS MISSING DATA AT "//trim(slevs(vlev))//&
2529 ". SET MISSING VARIABLE CONDITION TO 'INTRP' TO AVOID THIS ERROR", 1)
2530 elseif (.not.all_empty .and. n .ne. o3n)
then
2531 if (rlevs(vlev) .gt. lev_no_tr_fill) &
2532 call
error_handler(
"TRACER "//trim(tracers(n))//
" HAS MISSING DATA AT "//trim(slevs(vlev))//&
2533 ". SET MISSING VARIABLE CONDITION TO 'INTRP' TO AVOID THIS ERROR.", 1)
2536 if (trim(method) .eq.
'intrp' .and. all_empty) method=
'set_to_fill'
2538 call
handle_grib_error(vname, slevs(vlev),method,value,varnum,read_from_input,iret,var=dummy2d)
2540 if ( (tracers_input_oct10(n) == 1 .and. tracers_input_oct11(n) == 0) .or. &
2541 (tracers_input_oct10(n) == 1 .and. tracers_input_oct11(n) == 1) .or. &
2542 (tracers_input_oct10(n) == 14 .and. tracers_input_oct11(n) == 192) )
then
2543 call
error_handler(
"READING IN "//trim(tracers(n))//
" AT LEVEL "//trim(slevs(vlev))&
2544 //
". SET A FILL VALUE IN THE VARMAP TABLE IF THIS ERROR IS NOT DESIRABLE.",iret)
2550 if (n==1 .and. .not. hasspfh)
then
2551 if (trim(external_model) .eq.
'GFS')
then
2552 print *,
'- CALL CALRH GFS'
2553 call
rh2spfh_gfs(dummy2d,rlevs(vlev),dummy3d(:,:,vlev))
2555 print *,
'- CALL CALRH non-GFS'
2556 call
rh2spfh(dummy2d,rlevs(vlev),dummy3d(:,:,vlev))
2560 dummy3d(:,:,vlev) =
real(dummy2d,esmf_kind_r8)
2565 if (is_missing .and. trim(method) .eq.
'intrp')
then
2566 print *,
'- INTERPOLATE TRACER '//trim(tracers(n))
2570 dummy3d_col_in=dummy3d(ii,jj,:)
2571 call
dint2p(rlevs,dummy3d_col_in,lev_input,rlevs,dummy3d_col_out, &
2572 lev_input, 2, intrp_missing, intrp_ier)
2573 if (intrp_ier .gt. 0) call
error_handler(
"Interpolation failed.",intrp_ier)
2574 dummy3d(ii,jj,:)=dummy3d_col_out
2578 dummy2d =
real(dummy3d(:,:,n) , kind=esmf_kind_r4)
2579 if (any(dummy2d .eq. intrp_missing))
then
2581 if (n == o3n .and. rlevs(vlev) .lt. lev_no_o3_fill)
then
2582 call
error_handler(
"TRACER "//trim(tracers(n))//
" HAS MISSING DATA AT "//trim(slevs(vlev)),1)
2583 elseif (n .ne. o3n .and. rlevs(vlev) .gt. lev_no_tr_fill)
then
2584 call
error_handler(
"TRACER "//trim(tracers(n))//
" HAS MISSING DATA AT "//trim(slevs(vlev)),1)
2586 if (done_print .eq. 0)
then
2587 print*,
"Pressure out of range of existing data. Defaulting to fill value."
2590 where(dummy2d .eq. intrp_missing) dummy2d = value
2591 dummy3d(:,:,vlev) = dummy2d
2595 where(dummy3d(:,:,vlev) .lt. 0.0) dummy3d(:,:,vlev) = 0.0
2601 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT ", trim(tracers_input_vmap(n))
2602 call esmf_fieldscatter(tracers_input_grid(n), dummy3d, rootpet=0, rc=rc)
2603 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2608 deallocate(dummy3d_col_in, dummy3d_col_out)
2610 call
read_winds(u_tmp_3d,v_tmp_3d,localpet,octet_23,rlevs,lugb,pdt_num)
2612 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT U-WIND."
2613 call esmf_fieldscatter(u_input_grid, u_tmp_3d, rootpet=0, rc=rc)
2614 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2617 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT V-WIND."
2618 call esmf_fieldscatter(v_input_grid, v_tmp_3d, rootpet=0, rc=rc)
2619 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2622 if (localpet == 0)
then
2624 print*,
"- READ SURFACE PRESSURE."
2637 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2638 unpack, k, gfld, iret)
2639 if (iret /= 0) call
error_handler(
"READING SURFACE PRESSURE RECORD.", iret)
2641 dummy2d_8 = reshape(gfld%fld, (/i_input,j_input/) )
2645 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT GRID SURFACE PRESSURE."
2646 call esmf_fieldscatter(ps_input_grid, dummy2d_8, rootpet=0, rc=rc)
2647 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2652 if (localpet == 0)
then
2654 print*,
"- READ DZDT."
2656 call
get_var_cond(vname,this_miss_var_method=method, this_miss_var_value=value, &
2672 do vlev = 1, lev_input
2674 jpdt(12) = nint(rlevs(vlev))
2676 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2677 unpack, k, gfld, iret)
2680 print*,
"DZDT not available at level ", trim(slevs(vlev)),
" so checking for VVEL"
2682 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2683 unpack, k, gfld, iret)
2685 call
handle_grib_error(vname, slevs(vlev),method,value,varnum,read_from_input,iret,var8=dum2d_1)
2691 dum2d_1 = reshape(gfld%fld, (/i_input,j_input/) )
2694 dum2d_1 = reshape(gfld%fld, (/i_input,j_input/) )
2697 dummy3d(:,:,vlev) = dum2d_1
2703 call mpi_bcast(conv_omega,1,mpi_logical,0,mpi_comm_world,rc)
2705 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT DZDT."
2706 call esmf_fieldscatter(dzdt_input_grid, dummy3d, rootpet=0, rc=rc)
2707 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2712 if (localpet == 0)
then
2714 print*,
"- READ TERRAIN."
2727 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2728 unpack, k, gfld, iret)
2729 if (iret /= 0) call
error_handler(
"READING TERRAIN HEIGHT RECORD.", iret)
2731 dummy2d_8 = reshape(gfld%fld, (/i_input,j_input/) )
2735 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT GRID TERRAIN."
2736 call esmf_fieldscatter(terrain_input_grid, dummy2d_8, rootpet=0, rc=rc)
2737 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2740 deallocate(dummy2d, dummy2d_8)
2742 if (.not. isnative)
then
2749 if (localpet == 0) print*,
"- CALL FieldGet FOR SURFACE PRESSURE."
2751 call esmf_fieldget(ps_input_grid, &
2752 farrayptr=psptr, rc=rc)
2753 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2757 if (localpet == 0) print*,
"- CALL FieldGet FOR 3-D PRESSURE."
2758 call esmf_fieldget(pres_input_grid, &
2759 computationallbound=clb, &
2760 computationalubound=cub, &
2761 farrayptr=presptr, rc=rc)
2762 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2766 if (localpet == 0) print*,
"- CALL FieldGet TEMPERATURE."
2767 call esmf_fieldget(temp_input_grid, &
2768 farrayptr=tptr, rc=rc)
2769 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2773 if (localpet == 0) print*,
"- CALL FieldGet FOR U"
2774 call esmf_fieldget(u_input_grid, &
2775 farrayptr=uptr, rc=rc)
2776 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2780 if (localpet == 0) print*,
"- CALL FieldGet FOR V"
2781 call esmf_fieldget(v_input_grid, &
2782 farrayptr=vptr, rc=rc)
2783 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2787 if (localpet == 0) print*,
"- CALL FieldGet FOR W"
2788 call esmf_fieldget(dzdt_input_grid, &
2789 farrayptr=wptr, rc=rc)
2790 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2793 if (localpet == 0) print*,
"- CALL FieldGet FOR TRACERS."
2794 do n=1,num_tracers_input
2796 call esmf_fieldget(tracers_input_grid(n), &
2797 farrayptr=qptr, rc=rc)
2798 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2800 do i = clb(1),cub(1)
2801 do j = clb(2),cub(2)
2802 qptr(i,j,:) = qptr(i,j,lev_input:1:-1)
2807 do i = clb(1),cub(1)
2808 do j = clb(2),cub(2)
2809 presptr(i,j,:) = rlevs(lev_input:1:-1)
2810 tptr(i,j,:) = tptr(i,j,lev_input:1:-1)
2811 uptr(i,j,:) = uptr(i,j,lev_input:1:-1)
2812 vptr(i,j,:) = vptr(i,j,lev_input:1:-1)
2813 wptr(i,j,:) = wptr(i,j,lev_input:1:-1)
2817 if (localpet == 0)
then
2818 print*,
'psfc is ',clb(1),clb(2),psptr(clb(1),clb(2))
2819 print*,
'pres is ',cub(1),cub(2),presptr(cub(1),cub(2),:)
2821 print*,
'pres check 1',localpet,maxval(presptr(clb(1):cub(1),clb(2):cub(2),1)), &
2822 minval(presptr(clb(1):cub(1),clb(2):cub(2),1))
2823 print*,
'pres check lev',localpet,maxval(presptr(clb(1):cub(1),clb(2):cub(2), &
2824 lev_input)),minval(presptr(clb(1):cub(1),clb(2):cub(2),lev_input))
2831 if (localpet == 0)
then
2833 print*,
"- READ PRESSURE."
2847 do vlev = 1, lev_input
2849 jpdt(12) = nint(rlevs(vlev))
2850 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2851 unpack, k, gfld, iret)
2853 call
error_handler(
"READING IN PRESSURE AT LEVEL "//trim(slevs(vlev)),iret)
2856 dum2d_1 = reshape(gfld%fld, (/i_input,j_input/) )
2858 dummy3d(:,:,vlev) = dum2d_1
2864 if (localpet == 0) print*,
"- CALL FieldScatter FOR INPUT GRID PRESSURE."
2865 call esmf_fieldscatter(pres_input_grid, dummy3d, rootpet=0, rc=rc)
2866 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2871 deallocate(dummy3d, dum2d_1)
2883 if (conv_omega)
then
2885 if (localpet == 0) print*,
"- CONVERT FROM OMEGA TO DZDT."
2888 if (localpet == 0) print*,
"- CALL FieldGet TEMPERATURE."
2889 call esmf_fieldget(temp_input_grid, &
2890 farrayptr=tptr, rc=rc)
2891 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2895 if (localpet == 0) print*,
"- CALL FieldGet SPECIFIC HUMIDITY."
2896 call esmf_fieldget(tracers_input_grid(1), &
2897 computationallbound=clb, &
2898 computationalubound=cub, &
2899 farrayptr=qptr, rc=rc)
2900 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2904 if (localpet == 0) print*,
"- CALL FieldGet DZDT."
2905 call esmf_fieldget(dzdt_input_grid, &
2906 computationallbound=clb, &
2907 computationalubound=cub, &
2908 farrayptr=wptr, rc=rc)
2909 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2913 call esmf_fieldget(pres_input_grid, &
2914 farrayptr=presptr, rc=rc)
2915 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2922 if (localpet == 0) call baclose(lugb, rc)
2944 integer,
intent(in) :: localpet, lugb
2945 integer,
intent(in) :: pdt_num, octet_23
2947 real(esmf_kind_r8),
intent(inout),
allocatable :: u(:,:,:),v(:,:,:)
2948 real(esmf_kind_r8),
intent(in),
dimension(lev_input) :: rlevs
2950 real(esmf_kind_r4),
dimension(i_input,j_input) :: alpha
2951 real(esmf_kind_r8),
dimension(i_input,j_input) :: lon, lat
2952 real(esmf_kind_r4),
allocatable :: u_tmp(:,:),v_tmp(:,:)
2953 real(esmf_kind_r8),
allocatable :: dum2d(:,:)
2954 real(esmf_kind_r4),
dimension(i_input,j_input) :: ws,wd
2955 real(esmf_kind_r4) :: value_u, value_v,lov,latin1,latin2
2956 real(esmf_kind_r8) :: d2r
2958 integer :: varnum_u, varnum_v, vlev, &
2960 integer :: j, k, lugi, jgdtn, jpdtn
2961 integer :: jdisc, jids(200), jgdt(200), jpdt(200)
2963 character(len=20) :: vname
2964 character(len=50) :: method_u, method_v
2968 type(gribfield
) :: gfld
2970 d2r=acos(-1.0_esmf_kind_r8) / 180.0_esmf_kind_r8
2971 if (localpet==0)
then
2972 allocate(u(i_input,j_input,lev_input))
2973 allocate(v(i_input,j_input,lev_input))
2980 call
get_var_cond(vname,this_miss_var_method=method_u, this_miss_var_value=value_u, &
2983 call
get_var_cond(vname,this_miss_var_method=method_v, this_miss_var_value=value_v, &
2986 print*,
"- CALL FieldGather FOR INPUT GRID LONGITUDE"
2987 call esmf_fieldgather(longitude_input_grid, lon, rootpet=0, tile=1, rc=error)
2988 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2991 print*,
"- CALL FieldGather FOR INPUT GRID LATITUDE"
2992 call esmf_fieldgather(latitude_input_grid, lat, rootpet=0, tile=1, rc=error)
2993 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2996 if (localpet==0)
then
3008 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
3009 unpack, k, gfld, iret)
3011 if (iret /= 0) call
error_handler(
"ERROR READING GRIB2 FILE.", iret)
3013 if (gfld%igdtnum == 32769)
then
3015 latin1 =
real(float(gfld%igdtmpl(15))/1.0e6, kind=esmf_kind_r4)
3016 lov =
real(float(gfld%igdtmpl(16))/1.0e6, kind=esmf_kind_r4)
3018 print*,
"- CALL CALCALPHA_ROTLATLON with center lat,lon = ",latin1,lov
3021 elseif (gfld%igdtnum == 1)
then
3023 latin1 =
real(float(gfld%igdtmpl(20))/1.0E6, kind=esmf_kind_r4) + 90.0_esmf_kind_r4
3024 lov =
real(float(gfld%igdtmpl(21))/1.0e6, kind=esmf_kind_r4)
3026 print*,
"- CALL CALCALPHA_ROTLATLON with center lat,lon = ",latin1,lov
3029 elseif (gfld%igdtnum == 30)
then
3031 lov =
real(float(gfld%igdtmpl(14))/1.0e6, kind=esmf_kind_r4)
3032 latin1 =
real(float(gfld%igdtmpl(19))/1.0e6, kind=esmf_kind_r4)
3033 latin2 =
real(float(gfld%igdtmpl(20))/1.0e6, kind=esmf_kind_r4)
3035 print*,
"- CALL GRIDROT for LC grid with lov,latin1/2 = ",lov,latin1,latin2
3036 call
gridrot(lov,latin1,latin2,lon,alpha)
3044 allocate(dum2d(i_input,j_input))
3045 allocate(u_tmp(i_input,j_input))
3046 allocate(v_tmp(i_input,j_input))
3048 do vlev = 1, lev_input
3054 jpdt(12) = nint(rlevs(vlev))
3056 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
3057 unpack, k, gfld, iret)
3060 call
handle_grib_error(vname, slevs(vlev),method_u,value_u,varnum_u,read_from_input,iret,var=u_tmp)
3062 call
error_handler(
"READING IN U AT LEVEL "//trim(slevs(vlev))//
". SET A FILL "// &
3063 "VALUE IN THE VARMAP TABLE IF THIS ERROR IS NOT DESIRABLE.",iret)
3066 dum2d = reshape(gfld%fld, (/i_input,j_input/) )
3067 u_tmp(:,:) =
real(dum2d, kind=esmf_kind_r4)
3074 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
3075 unpack, k, gfld, iret)
3078 call
handle_grib_error(vname, slevs(vlev),method_v,value_v,varnum_v,read_from_input,iret,var=v_tmp)
3080 call
error_handler(
"READING IN V AT LEVEL "//trim(slevs(vlev))//
". SET A FILL "// &
3081 "VALUE IN THE VARMAP TABLE IF THIS ERROR IS NOT DESIRABLE.",iret)
3084 dum2d = reshape(gfld%fld, (/i_input,j_input/) )
3085 v_tmp(:,:) =
real(dum2d, kind=esmf_kind_r4)
3090 if (gfld%igdtnum == 0)
then
3091 if (external_model ==
'UKMET')
then
3093 v(:,:,vlev) = (v_tmp(:,2:jp1_input) + v_tmp(:,1:j_input))/2
3098 else if (gfld%igdtnum == 32769 .or. gfld%igdtnum == 1)
then
3099 ws = sqrt(u_tmp**2 + v_tmp**2)
3100 wd =
real((atan2(-u_tmp,-v_tmp) / d2r), kind=esmf_kind_r4)
3101 wd =
real((wd + alpha + 180.0), kind=esmf_kind_r4)
3102 wd =
real((270.0 - wd), kind=esmf_kind_r4)
3103 u(:,:,vlev) = -ws*cos(wd*d2r)
3104 v(:,:,vlev) = -ws*sin(wd*d2r)
3106 u(:,:,vlev) =
real(u_tmp * cos(alpha) + v_tmp * sin(alpha),esmf_kind_r8)
3107 v(:,:,vlev) =
real(v_tmp * cos(alpha) - u_tmp * sin(alpha),esmf_kind_r8)
3110 print*,
'max, min U ', minval(u(:,:,vlev)), maxval(u(:,:,vlev))
3111 print*,
'max, min V ', minval(v(:,:,vlev)), maxval(v(:,:,vlev))
3124 integer :: clb(3), cub(3)
3125 integer :: i, j, k, rc
3127 real(esmf_kind_r8) :: latrad, lonrad
3128 real(esmf_kind_r8),
pointer :: xptr(:,:,:)
3129 real(esmf_kind_r8),
pointer :: yptr(:,:,:)
3130 real(esmf_kind_r8),
pointer :: zptr(:,:,:)
3131 real(esmf_kind_r8),
pointer :: uptr(:,:,:)
3132 real(esmf_kind_r8),
pointer :: vptr(:,:,:)
3133 real(esmf_kind_r8),
pointer :: latptr(:,:)
3134 real(esmf_kind_r8),
pointer :: lonptr(:,:)
3136 print*,
"- CALL FieldGet FOR xwind."
3137 call esmf_fieldget(xwind_input_grid, &
3138 computationallbound=clb, &
3139 computationalubound=cub, &
3140 farrayptr=xptr, rc=rc)
3141 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3144 print*,
"- CALL FieldGet FOR ywind."
3145 call esmf_fieldget(ywind_input_grid, &
3146 farrayptr=yptr, rc=rc)
3147 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3150 print*,
"- CALL FieldGet FOR zwind."
3151 call esmf_fieldget(zwind_input_grid, &
3152 farrayptr=zptr, rc=rc)
3153 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3156 print*,
"- CALL FieldGet FOR U."
3157 call esmf_fieldget(u_input_grid, &
3158 farrayptr=uptr, rc=rc)
3159 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3162 print*,
"- CALL FieldGet FOR V."
3163 call esmf_fieldget(v_input_grid, &
3164 farrayptr=vptr, rc=rc)
3165 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3168 print*,
"- CALL FieldGet FOR LATITUDE."
3169 call esmf_fieldget(latitude_input_grid, &
3170 farrayptr=latptr, rc=rc)
3171 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3174 print*,
"- CALL FieldGet FOR LONGITUDE."
3175 call esmf_fieldget(longitude_input_grid, &
3176 farrayptr=lonptr, rc=rc)
3177 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3180 do i = clb(1), cub(1)
3181 do j = clb(2), cub(2)
3182 latrad = latptr(i,j) * acos(-1.) / 180.0
3183 lonrad = lonptr(i,j) * acos(-1.) / 180.0
3184 do k = clb(3), cub(3)
3185 xptr(i,j,k) = uptr(i,j,k) * cos(lonrad) - vptr(i,j,k) * sin(latrad) * sin(lonrad)
3186 yptr(i,j,k) = uptr(i,j,k) * sin(lonrad) + vptr(i,j,k) * sin(latrad) * cos(lonrad)
3187 zptr(i,j,k) = vptr(i,j,k) * cos(latrad)
3192 call esmf_fielddestroy(u_input_grid, rc=rc)
3193 call esmf_fielddestroy(v_input_grid, rc=rc)
3216 real(esmf_kind_r4),
intent(in) :: lov,latin1,latin2
3217 real(esmf_kind_r4),
intent(inout) :: rot(i_input,j_input)
3218 real(esmf_kind_r8),
intent(in) :: lon(i_input,j_input)
3220 real(esmf_kind_r4) :: trot(i_input,j_input), tlon(i_input,j_input)
3221 real(esmf_kind_r4) :: dtor = 3.14159265359_esmf_kind_r4/180.0_esmf_kind_r4
3222 real(esmf_kind_r4) :: an
3228 if ( (latin1 - latin2) .lt. 0.000001 )
then
3229 an = sin(latin1*dtor)
3231 an =
real(log( cos(latin1*dtor) / cos(latin2*dtor) ) / &
log( tan(dtor*(90.0-latin1)/2.) / tan(dtor*(90.0-latin2)/2.)), kind=esmf_kind_r4)
3234 tlon =
real((mod(lon - lov + 180. + 3600., 360.) - 180.), kind=esmf_kind_r4)
3255 real(esmf_kind_r8),
intent(in) :: latgrid(i_input,j_input), &
3256 longrid(i_input,j_input)
3257 real(esmf_kind_r4),
intent(in) :: cenlat, cenlon
3258 real(esmf_kind_r4),
intent(out) :: alpha(i_input,j_input)
3261 real(esmf_kind_r8) :: d2r,lon0_r,lat0_r,sphi0,cphi0
3262 real(esmf_kind_r8),
DIMENSION(i_input,j_input) :: tlat,tlon,tph,sinalpha
3264 d2r = acos(-1.0_esmf_kind_r8) / 180.0_esmf_kind_r8
3265 if (cenlon .lt. 0)
then
3266 lon0_r = (cenlon + 360.0)*d2r
3275 tlat = latgrid * d2r
3276 tlon = longrid * d2r
3279 tlon = -tlon + lon0_r
3280 tph = asin(cphi0*sin(tlat) - sphi0*cos(tlat)*cos(tlon))
3281 sinalpha = sphi0 * sin(tlon) / cos(tph)
3282 alpha =
real((-asin(sinalpha)/D2R), kind=esmf_kind_r4)
3295 print*,
'- DESTROY ATMOSPHERIC INPUT DATA.'
3297 call esmf_fielddestroy(terrain_input_grid, rc=rc)
3298 call esmf_fielddestroy(pres_input_grid, rc=rc)
3299 call esmf_fielddestroy(dzdt_input_grid, rc=rc)
3300 call esmf_fielddestroy(temp_input_grid, rc=rc)
3301 call esmf_fielddestroy(xwind_input_grid, rc=rc)
3302 call esmf_fielddestroy(ywind_input_grid, rc=rc)
3303 call esmf_fielddestroy(zwind_input_grid, rc=rc)
3304 call esmf_fielddestroy(ps_input_grid, rc=rc)
3306 do n = 1, num_tracers_input
3307 call esmf_fielddestroy(tracers_input_grid(n), rc=rc)
3309 deallocate(tracers_input_grid)
3314
subroutine, public convert_omega(omega, p, t, q, clb, cub)
Convert omega to vertical velocity.
subroutine, public rh2spfh(rh_sphum, p, t)
Convert relative humidity to specific humidity.
subroutine dint2p(PPIN, XXIN, NPIN, PPOUT, XXOUT, NPOUT, LINLOG, XMSG, IER)
Pressure to presure vertical interpolation for tracers with linear or lnP interpolation.
recursive subroutine quicksort(a, first, last)
Sort an array of values.
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 handle_grib_error(vname, lev, method, value, varnum, read_from_input, iret, var, var8, var3d)
Handle GRIB2 read error based on the user selected method in the varmap file.
subroutine error_handler(string, rc)
General error handler.
subroutine, public rh2spfh_gfs(rh_sphum, p, t)
Convert relative humidity to specific humidity (GFS formula) Calculation of saturation water vapor pr...
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...
subroutine, public get_var_cond(var_name, this_miss_var_method, this_miss_var_value, this_field_var_name, loc)
Search the variable mapping table to find conditions for handling missing variables.
Utilities for use when reading grib2 data.