106 use nemsio_module
, only: nemsio_getheadvar, nemsio_gfile, nemsio_init, nemsio_open, &
107 nemsio_getfilehead,nemsio_close
108 use ctlblk_mod
, only: filenameaer, me, num_procs, num_servers, mpi_comm_comp, datestr, &
109 mpi_comm_inter, filename, ioform, grib, idat, filenameflux, filenamed3d, gdsdegr, &
110 spldef, modelname, ihrst, lsmdef,vtimeunits, tprec, pthresh, datahandle, im, jm, lm, &
111 lp1, lm1, im_jm, isf_surface_physics, nsoil, spl, lsmp1, global, imp_physics, &
112 jsta, jend, jsta_m, jend_m, jsta_2l, jend_2u, novegtype, icount_calmict, npset, datapd,&
113 lsm, fld_info, etafld2_tim, eta2p_tim, mdl2sigma_tim, cldrad_tim, miscln_tim, &
114 mdl2agl_tim, mdl2std_tim, mdl2thandpv_tim, calrad_wcloud_tim, &
115 fixed_tim, time_output, imin, surfce2_tim, komax, ivegsrc, d3d_on, gocart_on,rdaod, &
116 readxml_tim, spval, fullmodelname, submodelname, hyb_sigp, filenameflat, aqfcmaq_on
117 use grib2_module, only: gribit2,num_pset,nrecout,first_grbtbl,grib_info_finalize
121 type(nemsio_gfile
) :: nfile,ffile,rfile
130 real(kind=8) :: time_initpost=0.,initpost_tim=0.,btim,bbtim
131 real rinc(5), untcnvt
132 integer :: status=0,iostatusd3d=0,iostatusflux=0
133 integer i,j,iii,l,k,ierr,nrec,ist,lusig,idrt,ncid3d,ncid2d,varid
134 integer :: prntsec,iim,jjm,llm,ioutcount,itmp,iret,iunit, &
135 iunitd3d,iyear,imn,iday,lcntrl,ieof
136 integer :: iostatusaer
139 integer :: kpo,kth,kpv
140 real,
dimension(komax) :: po,th,pv
141 namelist/nampgb/kpo,po,kth,th,kpv,pv,filenameaer,d3d_on,gocart_on,popascal &
142 ,hyb_sigp,rdaod,aqfcmaq_on,vtimeunits
144 namelist/model_inputs/filename,ioform,grib,datestr,modelname,submodelname &
145 ,filenameflux,filenameflat
147 character startdate*19,sysdepinfo*80,iowrfname*3,post_fname*255
148 character cgar*1,cdum*4,line*10
157 CALL setup_servers(me, &
174 print*,
'ME,NUM_PROCS,NUM_SERVERS=',me,num_procs,num_servers
176 if (me == 0) CALL w3tagb(
'nems ',0000,0000,0000,
'np23 ')
178 if ( me >= num_procs )
then
191 read(5,nml=model_inputs,iostat=itag_ierr,err=888)
193 888
if (itag_ierr /= 0)
then
194 print*,
'Incorrect namelist variable(s) found in the itag file,stopping!'
197 if (me==0) print*,
'fileName= ',filename
198 if (me==0) print*,
'IOFORM= ',ioform
200 if (me==0) print*,
'OUTFORM= ',grib
201 if (me==0) print*,
'DateStr= ',datestr
202 if (me==0) print*,
'MODELNAME= ',modelname
203 if (me==0) print*,
'SUBMODELNAME= ',submodelname
210 303
format(
'MODELNAME="',a,
'" SUBMODELNAME="',a,
'"')
212 write(0,*)
'MODELNAME: ', modelname, submodelname
214 if (me==0) print 303,modelname,submodelname
216 read(datestr,300) iyear,imn,iday,ihrst,imin
217 if (me==0)
write(*,*)
'in WRFPOST iyear,imn,iday,ihrst,imin', &
218 iyear,imn,iday,ihrst,imin
219 300
format(i4,1x,i2,1x,i2,1x,i2,1x,i2)
235 if (me==0) print*,
'MODELNAME= ',modelname,
'grib=',grib
236 if(modelname ==
'GFS' .OR. modelname ==
'FV3R')
then
237 if (me == 0) print*,
'first two file names in GFS or FV3= ' &
238 ,trim(filename),trim(filenameflux)
241 if(grib==
'grib2')
then
244 if (me==0) print *,
'gdsdegr=',gdsdegr
250 th = (/310.,320.,350.,450.,550.,650.,(0.,k=kth+1,komax)/)
252 pv = (/0.5,-0.5,1.0,-1.0,1.5,-1.5,2.0,-2.0,(0.,k=kpv+1,komax)/)
265 filenameflat=
'postxconfig-NT.txt'
266 read(5,nampgb,iostat=iret,end=119)
269 print*,
'komax,iret for nampgb= ',komax,iret
270 print*,
'komax,kpo,kth,th,kpv,pv,fileNameAER,popascal= ',komax,kpo &
271 & ,kth,th(1:kth),kpv,pv(1:kpv),trim(filenameaer),popascal
278 print*,
'using default pressure levels,spldef=',(spldef(l),l=1,lsmdef)
287 print*,
'using pressure levels from POSTGPVARS'
290 if( .not. popascal )
then
295 if(po(lsm) < po(1))
then
297 spl(l) = po(lsm-l+1)*untcnvt
301 spl(l) = po(l)*untcnvt
306 if (me==0) print*,
'LSM, SPL = ',lsm,spl(1:lsm)
311 if(modelname ==
'NMM')
then
317 if(trim(ioform) ==
'netcdf' .OR. trim(ioform) ==
'netcdfpara')
THEN
318 IF(modelname ==
'NCAR' .OR. modelname ==
'RAPR' .OR. modelname ==
'NMM')
THEN
319 call ext_ncd_ioinit(sysdepinfo,status)
320 print*,
'called ioinit', status
321 call ext_ncd_open_for_read( trim(filename), 0, 0,
" ", &
323 print*,
'called open for read', status
324 if ( status /= 0 )
then
325 print*,
'error opening ',filename,
' Status = ', status ; stop
327 call ext_ncd_get_dom_ti_integer(datahandle &
328 ,
'WEST-EAST_GRID_DIMENSION',iim,1,ioutcount, status )
330 call ext_ncd_get_dom_ti_integer(datahandle &
331 ,
'SOUTH-NORTH_GRID_DIMENSION',jjm,1,ioutcount, status )
333 call ext_ncd_get_dom_ti_integer(datahandle &
334 ,
'BOTTOM-TOP_GRID_DIMENSION',llm,1,ioutcount, status )
340 print*,
'im jm lm from wrfout= ',im,jm, lm
343 call ext_ncd_get_dom_ti_integer(datahandle &
344 ,
'SF_SURFACE_PHYSICS',itmp,1,ioutcount, status )
345 isf_surface_physics = itmp
346 print*,
'SF_SURFACE_PHYSICS= ',isf_surface_physics
352 ELSE IF(itmp == 3)
then
354 ELSE IF(itmp == 7)
then
357 print*,
'NSOIL from wrfout= ',nsoil
359 call ext_ncd_ioclose( datahandle, status )
363 status = nf90_open(trim(filename),ior(nf90_nowrite,nf90_mpiio), &
364 ncid3d,comm=mpi_comm_world,info=mpi_info_null)
365 if ( status /= 0 )
then
366 print*,
'error opening ',filename,
' Status = ', status
369 status = nf90_open(trim(filenameflux),ior(nf90_nowrite,nf90_mpiio), &
370 ncid2d,comm=mpi_comm_world,info=mpi_info_null)
371 if ( status /= 0 )
then
372 print*,
'error opening ',filenameflux,
' Status = ', status
376 status=nf90_get_att(ncid2d,nf90_global,
'landsfcmdl', isf_surface_physics)
378 print*,
'landsfcmdl not found; assigning to 2'
379 isf_surface_physics=2
381 if(isf_surface_physics<2)
then
382 isf_surface_physics=2
384 status=nf90_get_att(ncid2d,nf90_global,
'nsoil', nsoil)
386 print*,
'nsoil not found; assigning to 4'
389 if(me==0)print*,
'SF_SURFACE_PHYSICS= ',isf_surface_physics
390 if(me==0)print*,
'NSOIL= ',nsoil
392 status=nf90_get_att(ncid2d,nf90_global,
'imp_physics',imp_physics)
394 print*,
'imp_physics not found; assigning to GFDL 11'
397 if (me == 0) print*,
'MP_PHYSICS= ',imp_physics
399 status = nf90_inq_dimid(ncid3d,
'grid_xt',varid)
400 if ( status /= 0 )
then
404 status = nf90_inquire_dimension(ncid3d,varid,len=im)
405 if ( status /= 0 )
then
409 status = nf90_inq_dimid(ncid3d,
'grid_yt',varid)
410 if ( status /= 0 )
then
414 status = nf90_inquire_dimension(ncid3d,varid,len=jm)
415 if ( status /= 0 )
then
419 status = nf90_inq_dimid(ncid3d,
'pfull',varid)
420 if ( status /= 0 )
then
424 status = nf90_inquire_dimension(ncid3d,varid,len=lm)
425 if ( status /= 0 )
then
436 print*,
'im jm lm nsoil from fv3 output = ',im,jm,lm,nsoil
439 ELSE IF(trim(ioform) ==
'binary' .OR. &
440 trim(ioform) ==
'binarympiio' )
THEN
441 print*,
'WRF Binary format is no longer supported'
444 ELSE IF(trim(ioform) ==
'binarynemsio' .or. &
445 trim(ioform) ==
'binarynemsiompiio' )
THEN
449 call nemsio_init(iret=status)
450 print *,
'nemsio_init, iret=',status
451 call nemsio_open(nfile,trim(filename),
'read',iret=status)
452 if ( status /= 0 )
then
453 print*,
'error opening ',filename,
' Status = ', status ; stop
456 call nemsio_getfilehead(nfile,iret=status,nrec=nrec &
457 ,dimx=im,dimy=jm,dimz=lm,nsoil=nsoil)
458 if ( status /= 0 )
then
459 print*,
'error finding model dimensions '; stop
461 call nemsio_getheadvar(nfile,
'global',global,iret)
463 print*,
"global not found in file-Assigned false"
466 IF(modelname ==
'GFS') global = .true.
468 if(global .and. modelname ==
'NMM') im = im-1
472 CALL mpi_bcast(im, 1,mpi_integer,0, mpi_comm_comp,status)
473 call mpi_bcast(jm, 1,mpi_integer,0, mpi_comm_comp,status)
474 call mpi_bcast(lm, 1,mpi_integer,0, mpi_comm_comp,status)
475 call mpi_bcast(nsoil,1,mpi_integer,0, mpi_comm_comp,status)
477 if (me == 0) print*,
'im jm lm nsoil from NEMS= ',im,jm, lm ,nsoil
478 call mpi_bcast(global,1,mpi_logical,0,mpi_comm_comp,status)
479 if (me == 0) print*,
'Is this a global run ',global
485 IF(modelname ==
'GFS')
THEN
487 call nemsio_open(ffile,trim(filenameflux),
'read',iret=iostatusflux)
488 if ( iostatusflux /= 0 )
then
489 print*,
'error opening ',filenameflux,
' Status = ', iostatusflux
495 call nemsio_open(rfile,trim(filenameaer),
'read',iret=iostatusaer)
496 if ( iostatusaer /= 0 .and. me == 0)
then
497 print*,
'error opening AER ',filenameaer,
' Status = ', iostatusaer
505 print*,
'UNKNOWN MODEL OUTPUT FORMAT, STOPPING'
511 print*,
'jsta,jend,jsta_m,jend_m,jsta_2l,jend_2u,spval=',jsta, &
512 jend,jsta_m,jend_m, jsta_2l,jend_2u,spval
525 if(modelname ==
'GFS')
THEN
528 else if(modelname==
'NMM' .and. trim(ioform)==
'binarynemsio')
then
531 else if(modelname==
'RAPR')
then
541 IF(trim(ioform) ==
'netcdf' .OR. trim(ioform) ==
'netcdfpara')
THEN
542 IF(modelname ==
'NCAR' .OR. modelname ==
'RAPR')
THEN
543 print*,
'CALLING INITPOST TO PROCESS NCAR NETCDF OUTPUT'
545 ELSE IF (modelname ==
'FV3R' .OR. modelname ==
'GFS')
THEN
547 print*,
'CALLING INITPOST_NETCDF'
548 CALL initpost_netcdf(ncid2d,ncid3d)
550 print*,
'POST does not have netcdf option for model,',modelname,
' STOPPING,'
553 ELSE IF(trim(ioform) ==
'binarympiio')
THEN
554 IF(modelname ==
'NCAR' .OR. modelname ==
'RAPR' .OR. modelname ==
'NMM')
THEN
555 print*,
'WRF BINARY IO FORMAT IS NO LONGER SUPPORTED, STOPPING'
557 ELSE IF(modelname ==
'RSM')
THEN
558 print*,
'MPI BINARY IO IS NOT YET INSTALLED FOR RSM, STOPPING'
561 print*,
'POST does not have mpiio option for this model, STOPPING'
564 ELSE IF(trim(ioform) ==
'binarynemsio')
THEN
565 IF(modelname ==
'NMM')
THEN
566 CALL initpost_nems(nrec,nfile)
568 print*,
'POST does not have nemsio option for model,',modelname,
' STOPPING,'
573 ELSE IF(trim(ioform) ==
'binarynemsiompiio')
THEN
574 IF(modelname ==
'GFS')
THEN
576 call nemsio_close(nfile,iret=status)
577 call nemsio_close(ffile,iret=status)
578 call nemsio_close(rfile,iret=status)
579 CALL initpost_gfs_nems_mpiio(iostatusaer)
581 print*,
'POST does not have nemsio mpi option for model,',modelname, &
588 print*,
'UNKNOWN MODEL OUTPUT FORMAT, STOPPING'
591 initpost_tim = initpost_tim +(mpi_wtime() - btim)
593 WRITE(6,*)
'WRFPOST: INITIALIZED POST COMMON BLOCKS'
598 if(grib ==
"grib2")
then
601 readxml_tim = readxml_tim + (mpi_wtime() - btim)
609 first_grbtbl = .true.
646 if (me==0)
write(0,*)
' in WRFPOST OUTFORM= ',grib
647 if (me==0)
write(0,*)
' GRIB1 IS NOT SUPPORTED ANYMORE'
648 if (grib ==
"grib2")
then
649 do while (npset < num_pset)
651 if (me==0)
write(0,*)
' in WRFPOST npset=',npset,
' num_pset=',num_pset
652 CALL set_outflds(kth,th,kpv,pv)
653 if (me==0)
write(0,*)
' in WRFPOST size datapd',
size(datapd)
654 if(
allocated(datapd))
deallocate(datapd)
655 allocate(datapd(im,1:jend-jsta+1,nrecout+100))
664 call get_postfilename(post_fname)
665 if (me==0)
write(0,*)
'post_fname=',trim(post_fname)
666 if (me==0)
write(0,*)
'get_postfilename,post_fname=',trim(post_fname), &
667 'npset=',npset,
'num_pset=',num_pset, &
668 'iSF_SURFACE_PHYSICS=',isf_surface_physics
675 CALL process(kth,kpv,th(1:kth),pv(1:kpv),iostatusd3d)
676 IF(me == 0)
WRITE(6,*)
'WRFPOST: PREPARE TO PROCESS NEXT GRID'
679 call mpi_barrier(mpi_comm_comp,ierr)
683 call gribit2(post_fname)
694 call grib_info_finalize()
698 WRITE(6,*)
'ALL GRIDS PROCESSED.'
709 print*,
'INITPOST_tim = ', initpost_tim
710 print*,
'MDLFLD_tim = ', etafld2_tim
711 print*,
'MDL2P_tim = ',eta2p_tim
712 print*,
'MDL2SIGMA_tim = ',mdl2sigma_tim
713 print*,
'MDL2AGL_tim = ',mdl2agl_tim
714 print*,
'SURFCE_tim = ',surfce2_tim
715 print*,
'CLDRAD_tim = ',cldrad_tim
716 print*,
'MISCLN_tim = ',miscln_tim
717 print*,
'MDL2STD_tim = ',mdl2std_tim
718 print*,
'FIXED_tim = ',fixed_tim
719 print*,
'MDL2THANDPV_tim = ',mdl2thandpv_tim
720 print*,
'CALRAD_WCLOUD_tim = ',calrad_wcloud_tim
721 print*,
'Total time = ',(mpi_wtime() - bbtim)
722 print*,
'Time for OUTPUT = ',time_output
723 print*,
'Time for READxml = ',readxml_tim
739 if (me == 0) CALL w3tage(
'UNIFIED_POST')
740 CALL mpi_finalize(ierr)