107 use nemsio_module
, only: nemsio_getheadvar, nemsio_gfile, nemsio_init, nemsio_open, &
108 nemsio_getfilehead,nemsio_close
109 use ctlblk_mod
, only: filenameaer, me, num_procs, num_servers, mpi_comm_comp, datestr, &
110 mpi_comm_inter, filename, ioform, grib, idat, filenameflux, filenamed3d, gdsdegr, &
111 spldef, modelname, ihrst, lsmdef,vtimeunits, tprec, pthresh, datahandle, im, jm, lm, &
112 lp1, lm1, im_jm, isf_surface_physics, nsoil, spl, lsmp1, global, imp_physics, &
113 ista, iend, ista_m, iend_m, ista_2l, iend_2u, &
114 jsta, jend, jsta_m, jend_m, jsta_2l, jend_2u, novegtype, icount_calmict, npset, datapd,&
115 lsm, fld_info, etafld2_tim, eta2p_tim, mdl2sigma_tim, cldrad_tim, miscln_tim, &
116 mdl2agl_tim, mdl2std_tim, mdl2thandpv_tim, calrad_wcloud_tim, &
117 fixed_tim, time_output, imin, surfce2_tim, komax, ivegsrc, d3d_on, gocart_on,rdaod, &
118 readxml_tim, spval, fullmodelname, submodelname, hyb_sigp, filenameflat, aqfcmaq_on,numx
119 use grib2_module, only: gribit2,num_pset,nrecout,first_grbtbl,grib_info_finalize
123 type(nemsio_gfile
) :: nfile,ffile,rfile
132 real(kind=8) :: time_initpost=0.,initpost_tim=0.,btim,bbtim
133 real rinc(5), untcnvt
134 integer :: status=0,iostatusd3d=0,iostatusflux=0
135 integer i,j,iii,l,k,ierr,nrec,ist,lusig,idrt,ncid3d,ncid2d,varid
136 integer :: prntsec,iim,jjm,llm,ioutcount,itmp,iret,iunit, &
137 iunitd3d,iyear,imn,iday,lcntrl,ieof
138 integer :: iostatusaer
141 integer :: kpo,kth,kpv
142 real,
dimension(komax) :: po,th,pv
143 namelist/nampgb/kpo,po,kth,th,kpv,pv,filenameaer,d3d_on,gocart_on,popascal &
144 ,hyb_sigp,rdaod,aqfcmaq_on,vtimeunits,numx
146 namelist/model_inputs/filename,ioform,grib,datestr,modelname,submodelname &
147 ,filenameflux,filenameflat
149 character startdate*19,sysdepinfo*80,iowrfname*3,post_fname*255
150 character cgar*1,cdum*4,line*10
159 CALL setup_servers(me, &
176 print*,
'ME,NUM_PROCS,NUM_SERVERS=',me,num_procs,num_servers
178 if (me == 0) CALL w3tagb(
'nems ',0000,0000,0000,
'np23 ')
180 if ( me >= num_procs )
then
194 read(5,nml=model_inputs,iostat=itag_ierr,err=888)
196 888
if (itag_ierr /= 0)
then
197 print*,
'Incorrect namelist variable(s) found in the itag file,stopping!'
201 if (me==0) print*,
'fileName= ',filename
202 if (me==0) print*,
'IOFORM= ',ioform
204 if (me==0) print*,
'OUTFORM= ',grib
205 if (me==0) print*,
'DateStr= ',datestr
206 if (me==0) print*,
'MODELNAME= ',modelname
207 if (me==0) print*,
'SUBMODELNAME= ',submodelname
208 if (me==0) print*,
'numx= ',numx
215 303
format(
'MODELNAME="',a,
'" SUBMODELNAME="',a,
'"')
217 write(0,*)
'MODELNAME: ', modelname, submodelname
219 if (me==0) print 303,modelname,submodelname
221 read(datestr,300) iyear,imn,iday,ihrst,imin
222 if (me==0)
write(*,*)
'in WRFPOST iyear,imn,iday,ihrst,imin', &
223 iyear,imn,iday,ihrst,imin
224 300
format(i4,1x,i2,1x,i2,1x,i2,1x,i2)
240 if (me==0) print*,
'MODELNAME= ',modelname,
'grib=',grib
241 if(modelname ==
'GFS' .OR. modelname ==
'FV3R')
then
242 if (me == 0) print*,
'first two file names in GFS or FV3= ' &
243 ,trim(filename),trim(filenameflux)
246 if(grib==
'grib2')
then
249 if (me==0) print *,
'gdsdegr=',gdsdegr
255 th = (/310.,320.,350.,450.,550.,650.,(0.,k=kth+1,komax)/)
257 pv = (/0.5,-0.5,1.0,-1.0,1.5,-1.5,2.0,-2.0,(0.,k=kpv+1,komax)/)
270 filenameflat=
'postxconfig-NT.txt'
271 read(5,nampgb,iostat=iret,end=119)
273 if (me==0) print*,
'in itag, mod(num_procs,numx)=', mod(num_procs,numx)
274 if(mod(num_procs,numx)/=0)
then
276 print*,
'total proces, num_procs=', num_procs
277 print*,
'number of subdomain in x direction, numx=', numx
278 print*,
'remainder of num_procs/numx = ', mod(num_procs,numx)
279 print*,
'Warning!!! the remainder of num_procs/numx is not 0, reset numx=1 &
280 & in this run or you adjust numx in the itag file to restart'
284 if(me == 0) print*,
'Warning!!! Reset numx as 1, numx=',numx
286 if(numx>num_procs/2)
then
288 print*,
'total proces, num_procs=', num_procs
289 print*,
'number of subdomain in x direction, numx=', numx
290 print*,
'Warning!!! numx cannot exceed num_procs/2, reset numx=1 in this run'
291 print*,
'or you adjust numx in the itag file to restart'
294 if(me == 0) print*,
'Warning!!! Reset numx as 1, numx=',numx
297 print*,
'komax,iret for nampgb= ',komax,iret
298 print*,
'komax,kpo,kth,th,kpv,pv,fileNameAER,popascal= ',komax,kpo &
299 & ,kth,th(1:kth),kpv,pv(1:kpv),trim(filenameaer),popascal
300 print*,
'NUM_PROCS=',num_procs
304 IF(trim(ioform) /=
'netcdfpara' .AND. trim(ioform) /=
'netcdf' )
THEN
306 if(me == 0) print*,
'2D decomposition only supports netcdfpara IO.'
307 if(me == 0) print*,
'Reset numx= ',numx
310 IF(modelname /=
'FV3R' .AND. modelname /=
'GFS')
THEN
312 if(me == 0) print*,
'2D decomposition only supports GFS and FV3R.'
313 if(me == 0) print*,
'Reset numx= ',numx
320 print*,
'using default pressure levels,spldef=',(spldef(l),l=1,lsmdef)
329 print*,
'using pressure levels from POSTGPVARS'
332 if( .not. popascal )
then
337 if(po(lsm) < po(1))
then
339 spl(l) = po(lsm-l+1)*untcnvt
343 spl(l) = po(l)*untcnvt
348 if (me==0) print*,
'LSM, SPL = ',lsm,spl(1:lsm)
353 if(modelname ==
'NMM')
then
359 if(trim(ioform) ==
'netcdf' .OR. trim(ioform) ==
'netcdfpara')
THEN
360 IF(modelname ==
'NCAR' .OR. modelname ==
'RAPR' .OR. modelname ==
'NMM')
THEN
361 call ext_ncd_ioinit(sysdepinfo,status)
362 print*,
'called ioinit', status
363 call ext_ncd_open_for_read( trim(filename), 0, 0,
" ", &
365 print*,
'called open for read', status
366 if ( status /= 0 )
then
367 print*,
'error opening ',filename,
' Status = ', status ; stop
369 call ext_ncd_get_dom_ti_integer(datahandle &
370 ,
'WEST-EAST_GRID_DIMENSION',iim,1,ioutcount, status )
372 call ext_ncd_get_dom_ti_integer(datahandle &
373 ,
'SOUTH-NORTH_GRID_DIMENSION',jjm,1,ioutcount, status )
375 call ext_ncd_get_dom_ti_integer(datahandle &
376 ,
'BOTTOM-TOP_GRID_DIMENSION',llm,1,ioutcount, status )
382 print*,
'im jm lm from wrfout= ',im,jm, lm
385 call ext_ncd_get_dom_ti_integer(datahandle &
386 ,
'SF_SURFACE_PHYSICS',itmp,1,ioutcount, status )
387 isf_surface_physics = itmp
388 print*,
'SF_SURFACE_PHYSICS= ',isf_surface_physics
394 ELSE IF(itmp == 3)
then
396 ELSE IF(itmp == 7)
then
399 print*,
'NSOIL from wrfout= ',nsoil
401 call ext_ncd_ioclose( datahandle, status )
405 status = nf90_open(trim(filename),ior(nf90_nowrite,nf90_mpiio), &
406 ncid3d,comm=mpi_comm_world,info=mpi_info_null)
407 if ( status /= 0 )
then
408 print*,
'error opening ',filename,
' Status = ', status
411 status = nf90_open(trim(filenameflux),ior(nf90_nowrite,nf90_mpiio), &
412 ncid2d,comm=mpi_comm_world,info=mpi_info_null)
413 if ( status /= 0 )
then
414 print*,
'error opening ',filenameflux,
' Status = ', status
418 status=nf90_get_att(ncid2d,nf90_global,
'landsfcmdl', isf_surface_physics)
420 print*,
'landsfcmdl not found; assigning to 2'
421 isf_surface_physics=2
423 if(isf_surface_physics<2)
then
424 isf_surface_physics=2
426 status=nf90_get_att(ncid2d,nf90_global,
'nsoil', nsoil)
428 print*,
'nsoil not found; assigning to 4'
431 if(me==0)print*,
'SF_SURFACE_PHYSICS= ',isf_surface_physics
432 if(me==0)print*,
'NSOIL= ',nsoil
434 status=nf90_get_att(ncid2d,nf90_global,
'imp_physics',imp_physics)
436 print*,
'imp_physics not found; assigning to GFDL 11'
439 if (me == 0) print*,
'MP_PHYSICS= ',imp_physics
441 status = nf90_inq_dimid(ncid3d,
'grid_xt',varid)
442 if ( status /= 0 )
then
446 status = nf90_inquire_dimension(ncid3d,varid,len=im)
447 if ( status /= 0 )
then
451 status = nf90_inq_dimid(ncid3d,
'grid_yt',varid)
452 if ( status /= 0 )
then
456 status = nf90_inquire_dimension(ncid3d,varid,len=jm)
457 if ( status /= 0 )
then
461 status = nf90_inq_dimid(ncid3d,
'pfull',varid)
462 if ( status /= 0 )
then
466 status = nf90_inquire_dimension(ncid3d,varid,len=lm)
467 if ( status /= 0 )
then
478 print*,
'im jm lm nsoil from fv3 output = ',im,jm,lm,nsoil
481 ELSE IF(trim(ioform) ==
'binary' .OR. &
482 trim(ioform) ==
'binarympiio' )
THEN
483 print*,
'WRF Binary format is no longer supported'
486 ELSE IF(trim(ioform) ==
'binarynemsio' .or. &
487 trim(ioform) ==
'binarynemsiompiio' )
THEN
491 call nemsio_init(iret=status)
492 print *,
'nemsio_init, iret=',status
493 call nemsio_open(nfile,trim(filename),
'read',iret=status)
494 if ( status /= 0 )
then
495 print*,
'error opening ',filename,
' Status = ', status ; stop
498 call nemsio_getfilehead(nfile,iret=status,nrec=nrec &
499 ,dimx=im,dimy=jm,dimz=lm,nsoil=nsoil)
500 if ( status /= 0 )
then
501 print*,
'error finding model dimensions '; stop
503 call nemsio_getheadvar(nfile,
'global',global,iret)
505 print*,
"global not found in file-Assigned false"
508 IF(modelname ==
'GFS') global = .true.
510 if(global .and. modelname ==
'NMM') im = im-1
514 CALL mpi_bcast(im, 1,mpi_integer,0, mpi_comm_comp,status)
515 call mpi_bcast(jm, 1,mpi_integer,0, mpi_comm_comp,status)
516 call mpi_bcast(lm, 1,mpi_integer,0, mpi_comm_comp,status)
517 call mpi_bcast(nsoil,1,mpi_integer,0, mpi_comm_comp,status)
519 if (me == 0) print*,
'im jm lm nsoil from NEMS= ',im,jm, lm ,nsoil
520 call mpi_bcast(global,1,mpi_logical,0,mpi_comm_comp,status)
521 if (me == 0) print*,
'Is this a global run ',global
527 IF(modelname ==
'GFS')
THEN
529 call nemsio_open(ffile,trim(filenameflux),
'read',iret=iostatusflux)
530 if ( iostatusflux /= 0 )
then
531 print*,
'error opening ',filenameflux,
' Status = ', iostatusflux
537 call nemsio_open(rfile,trim(filenameaer),
'read',iret=iostatusaer)
538 if ( iostatusaer /= 0 .and. me == 0)
then
539 print*,
'error opening AER ',filenameaer,
' Status = ', iostatusaer
547 print*,
'UNKNOWN MODEL OUTPUT FORMAT, STOPPING'
553 print*,
'jsta,jend,jsta_m,jend_m,jsta_2l,jend_2u,spval=',jsta, &
554 jend,jsta_m,jend_m, jsta_2l,jend_2u,spval
567 if(modelname ==
'GFS')
THEN
570 else if(modelname==
'NMM' .and. trim(ioform)==
'binarynemsio')
then
573 else if(modelname==
'RAPR')
then
583 IF(trim(ioform) ==
'netcdf' .OR. trim(ioform) ==
'netcdfpara')
THEN
584 IF(modelname ==
'NCAR' .OR. modelname ==
'RAPR')
THEN
585 print*,
'CALLING INITPOST TO PROCESS NCAR NETCDF OUTPUT'
587 ELSE IF (modelname ==
'FV3R' .OR. modelname ==
'GFS')
THEN
589 print*,
'CALLING INITPOST_NETCDF'
590 CALL initpost_netcdf(ncid2d,ncid3d)
592 print*,
'POST does not have netcdf option for model,',modelname,
' STOPPING,'
595 ELSE IF(trim(ioform) ==
'binarympiio')
THEN
596 IF(modelname ==
'NCAR' .OR. modelname ==
'RAPR' .OR. modelname ==
'NMM')
THEN
597 print*,
'WRF BINARY IO FORMAT IS NO LONGER SUPPORTED, STOPPING'
599 ELSE IF(modelname ==
'RSM')
THEN
600 print*,
'MPI BINARY IO IS NOT YET INSTALLED FOR RSM, STOPPING'
603 print*,
'POST does not have mpiio option for this model, STOPPING'
606 ELSE IF(trim(ioform) ==
'binarynemsio')
THEN
607 IF(modelname ==
'NMM')
THEN
608 CALL initpost_nems(nrec,nfile)
610 print*,
'POST does not have nemsio option for model,',modelname,
' STOPPING,'
615 ELSE IF(trim(ioform) ==
'binarynemsiompiio')
THEN
616 IF(modelname ==
'GFS')
THEN
618 call nemsio_close(nfile,iret=status)
619 call nemsio_close(ffile,iret=status)
620 call nemsio_close(rfile,iret=status)
621 CALL initpost_gfs_nems_mpiio(iostatusaer)
623 print*,
'POST does not have nemsio mpi option for model,',modelname, &
630 print*,
'UNKNOWN MODEL OUTPUT FORMAT, STOPPING'
633 initpost_tim = initpost_tim +(mpi_wtime() - btim)
635 WRITE(6,*)
'WRFPOST: INITIALIZED POST COMMON BLOCKS'
640 if(grib ==
"grib2")
then
643 readxml_tim = readxml_tim + (mpi_wtime() - btim)
651 first_grbtbl = .true.
688 if (me==0)
write(0,*)
' in WRFPOST OUTFORM= ',grib
689 if (me==0)
write(0,*)
' GRIB1 IS NOT SUPPORTED ANYMORE'
690 if (grib ==
"grib2")
then
691 do while (npset < num_pset)
693 if (me==0)
write(0,*)
' in WRFPOST npset=',npset,
' num_pset=',num_pset
694 CALL set_outflds(kth,th,kpv,pv)
695 if (me==0)
write(0,*)
' in WRFPOST size datapd',
size(datapd)
696 if(
allocated(datapd))
deallocate(datapd)
699 allocate(datapd(1:iend-ista+1,1:jend-jsta+1,nrecout+100))
710 call get_postfilename(post_fname)
711 if (me==0)
write(0,*)
'post_fname=',trim(post_fname)
712 if (me==0)
write(0,*)
'get_postfilename,post_fname=',trim(post_fname), &
713 'npset=',npset,
'num_pset=',num_pset, &
714 'iSF_SURFACE_PHYSICS=',isf_surface_physics
721 CALL process(kth,kpv,th(1:kth),pv(1:kpv),iostatusd3d)
722 IF(me == 0)
WRITE(6,*)
'WRFPOST: PREPARE TO PROCESS NEXT GRID'
725 call mpi_barrier(mpi_comm_comp,ierr)
729 call gribit2(post_fname)
740 call grib_info_finalize()
744 WRITE(6,*)
'ALL GRIDS PROCESSED.'
755 print*,
'INITPOST_tim = ', initpost_tim
756 print*,
'MDLFLD_tim = ', etafld2_tim
757 print*,
'MDL2P_tim = ',eta2p_tim
758 print*,
'MDL2SIGMA_tim = ',mdl2sigma_tim
759 print*,
'MDL2AGL_tim = ',mdl2agl_tim
760 print*,
'SURFCE_tim = ',surfce2_tim
761 print*,
'CLDRAD_tim = ',cldrad_tim
762 print*,
'MISCLN_tim = ',miscln_tim
763 print*,
'MDL2STD_tim = ',mdl2std_tim
764 print*,
'FIXED_tim = ',fixed_tim
765 print*,
'MDL2THANDPV_tim = ',mdl2thandpv_tim
766 print*,
'CALRAD_WCLOUD_tim = ',calrad_wcloud_tim
767 print*,
'Total time = ',(mpi_wtime() - bbtim)
768 print*,
'Time for OUTPUT = ',time_output
769 print*,
'Time for READxml = ',readxml_tim
785 if (me == 0) CALL w3tage(
'UNIFIED_POST')
786 CALL mpi_finalize(ierr)