8 integer, parameter :: MAX_DOMAINS = 21
11 integer :: iproj_type, n_domains, io_form_output, dyn_opt
12 integer :: i, j, max_dom, funit, io_form_geogrid
13 integer :: interval_seconds
15 integer, dimension(MAX_DOMAINS) :: parent_grid_ratio, parent_id, ixdim, jydim
16 integer, dimension(MAX_DOMAINS) :: i_parent_start, j_parent_start, &
17 s_we, e_we, s_sn, e_sn, &
18 start_year, start_month, start_day, start_hour, &
19 end_year, end_month, end_day, end_hour
20 logical, dimension(MAX_DOMAINS) :: active_grid
22 real :: known_lat, known_lon, stand_lon, truelat1, truelat2, known_x, known_y, &
23 dxkm, dykm, ref_lat, ref_lon, ref_x, ref_y
25 real :: ri, rj, rlats, rlons, rlate, rlone
27 real :: rparent_gridpts
28 real :: xa,xb,ya,yb,xxa,xxy,yya,yyb
29 real :: xs, xe, ys, ye
30 integer :: jproj, jgrid, jlts, iusout, idot, ier
31 integer :: ltype , idom
33 real, dimension(MAX_DOMAINS) :: parent_ll_x, parent_ll_y, parent_ur_x, parent_ur_y
35 character (len=128) :: geog_data_path, opt_output_from_geogrid_path, opt_geogrid_tbl_path
36 character (len=128), dimension(MAX_DOMAINS) :: geog_data_res
37 character (len=128) :: map_proj
38 character (len=128), dimension(MAX_DOMAINS) :: start_date, end_date
39 character (len=3) :: wrf_core
40 character (len=1) :: gridtype
42 logical :: do_tiled_output
43 integer :: debug_level
46 type (proj_info) :: map_projection
48 namelist /share/ wrf_core, max_dom, start_date, end_date, &
49 start_year, end_year, start_month, end_month, &
50 start_day, end_day, start_hour, end_hour, &
51 interval_seconds, io_form_geogrid, opt_output_from_geogrid_path, &
52 debug_level, active_grid
53 namelist /geogrid/ parent_id, parent_grid_ratio, &
54 i_parent_start, j_parent_start, s_we, e_we, s_sn, e_sn, &
55 map_proj, ref_x, ref_y, ref_lat, ref_lon, &
56 truelat1, truelat2, stand_lon, dx, dy, &
57 geog_data_res, geog_data_path, opt_geogrid_tbl_path
59 ! Set defaults for namelist variables
64 geog_data_path = 'NOT_SPECIFIED'
76 geog_data_res(i) = 'default'
78 parent_grid_ratio(i) = INVALID
91 start_date(i) = '0000-00-00_00:00:00'
92 end_date(i) = '0000-00-00_00:00:00'
94 opt_output_from_geogrid_path = './'
95 opt_geogrid_tbl_path = 'geogrid/'
96 interval_seconds = INVALID
98 ! Read parameters from Fortran namelist
100 inquire(unit=funit, opened=is_used)
101 if (.not. is_used) exit
103 open(funit,file='namelist.wps',status='old',form='formatted',err=1000)
116 ! Convert wrf_core to uppercase letters
118 if (ichar(wrf_core(i:i)) >= 97) wrf_core(i:i) = char(ichar(wrf_core(i:i))-32)
121 ! Before doing anything else, we must have a valid grid type
123 if (wrf_core == 'ARW') then
126 else if (wrf_core == 'NMM') then
131 if (gridtype /= 'C' .and. gridtype /= 'E') then
132 write(6,*) 'A valid wrf_core must be specified in the namelist. '// &
133 'Currently, only "ARW" and "NMM" are supported.'
137 if (max_dom > MAX_DOMAINS) then
138 write(6,*) 'In namelist, max_dom must be <= ',MAX_DOMAINS,'. To run with more'// &
139 ' than ',MAX_DOMAINS,' domains, increase the MAX_DOMAINS parameter.'
143 ! Every domain must have a valid parent id
145 if (parent_id(i) <= 0 .or. parent_id(i) >= i) then
146 write(6,*) 'In namelist, the parent_id of domain ',i,' must be in '// &
147 'the range 1 to ',i-1
152 ! Convert map_proj to uppercase letters
154 if (ichar(map_proj(i:i)) >= 97) map_proj(i:i) = char(ichar(map_proj(i:i))-32)
157 ! Assign parameters to module variables
158 if ((index(map_proj, 'LAMBERT') /= 0) .and. &
159 (len_trim(map_proj) == len('LAMBERT'))) then
165 else if ((index(map_proj, 'MERCATOR') /= 0) .and. &
166 (len_trim(map_proj) == len('MERCATOR'))) then
167 iproj_type = PROJ_MERC
172 else if ((index(map_proj, 'POLAR') /= 0) .and. &
173 (len_trim(map_proj) == len('POLAR'))) then
176 polat=SIGN(90., ref_lat)
179 else if ((index(map_proj, 'ROTATED_LL') /= 0) .and. &
180 (len_trim(map_proj) == len('ROTATED_LL'))) then
181 iproj_type = PROJ_ROTLL
184 write(6,*) 'In namelist, invalid map_proj specified. Valid '// &
185 'projections are "lambert", "mercator", "polar", '// &
193 ixdim(i) = e_we(i) - s_we(i) + 1
194 jydim(i) = e_sn(i) - s_sn(i) + 1
197 ! If the user hasn't supplied a known_x and known_y, assume the center of domain 1
198 if (known_x == NAN) known_x = ixdim(1) / 2.
199 if (known_y == NAN) known_y = jydim(1) / 2.
201 ! Checks specific to C grid
202 if (gridtype == 'C') then
204 ! C grid does not support the rotated lat/lon projection
205 if (iproj_type == PROJ_ROTLL) then
206 write(6,*) 'Rotated lat/lon projection is not supported for the ARW core. '// &
207 'Valid projecitons are "lambert", "mercator", and "polar".'
211 ! Check that nests have an acceptable number of grid points in each dimension
213 rparent_gridpts = real(ixdim(i)-1)/real(parent_grid_ratio(i))
214 if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
215 write(6,*) 'For nest ',i,' (e_we-s_we+1) must be one greater than an '// &
216 'integer multiple of the parent_grid_ratio.'
219 rparent_gridpts = real(jydim(i)-1)/real(parent_grid_ratio(i))
220 if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
221 write(6,*) 'For nest ',i,' (e_sn-s_sn+1) must be one greater than an '// &
222 'integer multiple of the parent_grid_ratio.'
228 ! Checks specific to E grid
229 if (gridtype == 'E') then
231 ! E grid supports only the rotated lat/lon projection
232 if (iproj_type /= PROJ_ROTLL) then
233 write(6,*) 'Rotated lat/lon is the only supported projection for the NMM core.'
237 ! Check that the parent_grid_ratio is set to 3 for all nests
239 if (parent_grid_ratio(i) /= 3) then
240 write(6,*) 'The parent_grid_ratio must be set to 3 for the NMM core.'
245 CALL plot_e_grid ( ref_lat , -1. * ref_lon , &
249 parent_id , parent_grid_ratio , &
250 i_parent_start , j_parent_start )
255 parent_ll_x(i) = real(i_parent_start(i))
256 parent_ll_y(i) = real(j_parent_start(i))
257 parent_ur_x(i) = real(i_parent_start(i))+real(ixdim(i))/real(parent_grid_ratio(i))-1.
258 parent_ur_y(i) = real(j_parent_start(i))+real(jydim(i))/real(parent_grid_ratio(i))-1.
261 call map_init(map_projection)
263 call map_set(iproj_type, map_projection, &
275 call ij_to_latlon(map_projection, 0.5, 0.5, rlats, rlons)
276 call ij_to_latlon(map_projection, real(e_we(1))-0.5, real(e_sn(1))-0.5, rlate, rlone)
281 call gscr(1, 0, 1.00, 1.00, 1.00)
282 call gscr(1, 1, 0.00, 0.00, 0.00)
284 ! Do not grind them with details
290 call supmap(jproj,polat,stand_lon,rot,&
291 rlats,rlons,rlate,rlone, &
292 jlts,jgrid,iusout,idot,ier)
294 call setusv('LW',1000)
295 call perim(e_we(1)-1,1,e_sn(1)-1,1)
296 call getset(xa,xb,ya,yb,xxa,xxy,yya,yyb,ltype)
297 call set (xa,xb,ya,yb, &
298 1.,real(e_we(1)),1.,real(e_sn(1)),ltype)
300 do idom = 2 , max_dom
301 call getxy ( xs, xe, ys, ye, &
304 parent_id , parent_grid_ratio , &
305 i_parent_start , j_parent_start )
306 call line ( xs , ys , xe , ys )
307 call line ( xe , ys , xe , ye )
308 call line ( xe , ye , xs , ye )
309 call line ( xs , ye , xs , ys )
315 write(6,*) 'Creating plot in NCAR Graphics metafile...'
320 write(6,*) ' *** Successful completion of program plotgrids.exe *** '
325 1000 write(6,*) 'Error opening namelist.wps'
328 end program plotgrids
330 subroutine getxy ( xs, xe, ys, ye, &
331 dom_id , num_domains , &
333 parent_id , parent_grid_ratio , &
334 i_parent_start , j_parent_start )
338 integer , intent(in) :: dom_id
339 integer , intent(in) :: num_domains
340 integer , intent(in) , dimension(num_domains):: e_we , e_sn , &
341 parent_id , parent_grid_ratio , &
342 i_parent_start , j_parent_start
343 real , intent(out) :: xs, xe, ys, ye
358 xs = (i_parent_start(idom) + xs -1 ) / &
359 real(parent_grid_ratio(parent_id(idom)))
360 xe = xe / real(parent_grid_ratio(idom))
362 ys = (j_parent_start(idom) + ys -1 ) / &
363 real(parent_grid_ratio(parent_id(idom)))
364 ye = ye / real(parent_grid_ratio(idom))
366 idom = parent_id(idom)
367 if ( idom .EQ. 1 ) then
380 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
381 !!!!!! E GRID MAP INFO BELOW !!!!!!!!!!!!!!
382 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
384 SUBROUTINE plot_e_grid ( rlat0d , rlon0d , dphd , dlmd, &
387 parent_id , parent_grid_ratio , &
388 i_parent_start , j_parent_start )
390 ! This routine generates a gmeta file of the area covered by an Arakawa e-grid.
391 ! We assume that NCAR Graphics has not been called yet (and will be closed
392 ! upon exit). The required input fields are as from the WPS namelist file.
396 ! 15 April 2005 NCEP/EMC
397 ! The Code and some instructions are provided by Tom BLACK to
398 ! NCAR/DTC Meral Demirtas
400 ! 4 May 2005 NCAR/DTC Meral DEMIRTAS
401 ! - An include file (plot_inc) is added to get
403 ! Central latitute and longnitute: RLAT0D,RLON0D
404 ! Horizontal resolution: DPHD, DLMD
409 ! Remove non-mapping portions
410 ! Make part of WPS domain plotting utility
413 ! Pass additional arguments to enable plotting of nests
415 ! Input map parameters for E grid.
417 REAL , INTENT(IN) :: rlat0d , & ! latitude of grid center (degrees)
418 rlon0d ! longitude of grid center (degrees, times -1)
420 REAL , INTENT(IN) :: dphd , & ! angular distance between rows (degrees)
421 dlmd ! angular distance between adjacent H and V points (degrees)
423 INTEGER , INTENT(in) :: n_domains ! number of domains
424 INTEGER , INTENT(in) , DIMENSION(n_domains):: e_we , &
427 parent_grid_ratio , &
436 INTEGER :: im, & ! number of H points in odd rows
437 jm , & ! number of rows
443 INTEGER :: imt , imtjm
444 REAL :: latlft,lonlft,latrgt,lonrgt
456 ! Get lat and lon of left and right points.
458 CALL corners ( rlat1d,rlon1d,im,jm,rlat0d,rlon0d,dphd,dlmd,&
459 ngpwe,ngpsn,ilowl,jlowl,latlft,lonlft,latrgt,lonrgt)
461 ! With corner points, make map background.
463 CALL mapbkg_egrid ( imt,jm,ilowl,jlowl,ngpwe,ngpsn,&
464 rlat0d,rlon0d,latlft,lonlft,latrgt,lonrgt,&
468 parent_id,parent_grid_ratio,&
469 i_parent_start,j_parent_start)
471 END SUBROUTINE plot_e_grid
473 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
475 SUBROUTINE corners ( glatd,glond,im,jm,tph0d,tlm0d,dphd,dlmd,&
476 ngpwe,ngpsn,ilowl,jlowl,glatl,glonl,glatr,glonr)
480 REAL , INTENT(IN) :: glatd,glond,tph0d,tlm0d,dphd,dlmd,&
481 glatl,glonl,glatr,glonr
483 INTEGER , INTENT(IN) :: im,jm,ngpwe,ngpsn
484 INTEGER , INTENT(OUT) :: ilowl,jlowl
488 REAL , PARAMETER :: d2r = 1.74532925E-2 , r2D = 1./D2R
490 REAL :: glat , glon , dph , dlm , tph0 , tlm0
491 REAL :: x , y , z , tlat , tlon , tlat1 , tlat2 , tlon1 , tlon2
493 REAL :: dlm1 , dlm2 , d1 , d2 , d3 , d4 , dmin
495 INTEGER :: jmt , ii , jj , iuppr , juppr
496 INTEGER :: nrow , ncol
500 ! Convert from geodetic to transformed coordinates (degrees).
509 x = COS(tph0) * COS(glat) * COS(glon-tlm0)+SIN(tph0) * SIN(glat)
510 y = -COS(glat) * SIN(glon-tlm0)
511 z = COS(tph0) * SIN(glat)-SIN(tph0) * COS(glat) * COS(glon-tlm0)
512 tlat = r2d * ATAN(z/SQRT(x*x + y*y))
513 tlon = r2d * ATAN(y/x)
515 ! Find the real (non-integer) row and column of the input location on
531 tlat1 = (nrow-jmt) * dph
533 tlon1 = (ncol-im) * dlm
539 d1 = ACOS(COS(tlat) * COS(tlat1) * COS(dlm1)+SIN(tlat) * SIN(tlat1))
540 d2 = ACOS(COS(tlat) * COS(tlat2) * COS(dlm1)+SIN(tlat) * SIN(tlat2))
541 d3 = ACOS(COS(tlat) * COS(tlat2) * COS(dlm2)+SIN(tlat) * SIN(tlat2))
542 d4 = ACOS(COS(tlat) * COS(tlat1) * COS(dlm2)+SIN(tlat) * SIN(tlat1))
544 dmin = MIN(d1,d2,d3,d4)
546 IF ( ABS(dmin-d1) .LT. 1.e-6 ) THEN
549 ELSE IF ( ABS(dmin-d2) .LT. 1.e-6 ) THEN
552 ELSE IF ( ABS(dmin-d3) .LT. 1.e-6 ) THEN
555 ELSE IF ( ABS(dmin-d4) .LT. 1.e-6 ) THEN
560 ! Now find the i and j of the lower left corner of the desired grid
561 ! region and of the upper right.
568 ! Find their geodetic coordinates.
570 CALL e2t2g(ilowl,jlowl,im,jm,tph0d,tlm0d,dphd,dlmd,glatl,glonl)
571 CALL e2t2g(iuppr,juppr,im,jm,tph0d,tlm0d,dphd,dlmd,glatr,glonr)
573 END SUBROUTINE corners
575 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
577 SUBROUTINE mapbkg_egrid ( imt,jm,ilowl,jlowl,ngpwe,ngpsn,&
578 rlat0d,rlon0d,glatl,glonl,glatr,glonr,&
582 parent_id,parent_grid_ratio,&
583 i_parent_start , j_parent_start )
587 INTEGER , INTENT(in) :: n_domains
588 INTEGER , INTENT(in) , DIMENSION(n_domains):: e_we , e_sn , &
589 parent_id , parent_grid_ratio , &
590 i_parent_start , j_parent_start
594 CHARACTER (LEN=97) :: string
596 REAL :: xs, xe, ys, ye
598 ! Yet more center lon messing around, hoo boy.
603 ! Open up NCAR Graphics
609 ! Make the background white, and the foreground black.
611 CALL gscr ( 1 , 0 , 1., 1., 1. )
612 CALL gscr ( 1 , 1 , 0., 0., 0. )
614 ! Line width default thickness.
616 CALL setusv('LW',1000)
618 ! Make map outline a solid line, not dots.
623 ! Map outlines are political and states.
625 CALL mapstc('OU','PS')
627 ! Cylindrical equidistant.
629 CALL maproj('CE',rlat0d,clonx,0.)
631 ! Specify corner points.
633 CALL mapset('CO',glatl,glonl,glatr,glonr)
635 ! Lat lon lines every 5 degrees.
639 ! Map takes up this much real estate.
641 CALL mappos( 0.05 , 0.95 , 0.05 , 0.95 )
643 ! Initialize and draw map.
648 ! Line width twice default thickness.
650 CALL setusv('LW',2000)
652 ! Add approx grid point tick marks
654 CALL perim(((imt+3)/2)-1,1,jm-1,1)
656 ! Line width default thickness.
658 CALL setusv('LW',1000)
660 ! Put on a quicky description.
662 WRITE ( string , FMT = '("E-GRID E_WE = ",I4,", E_SN = ",I4 , &
663 &", DX = ",F6.4,", DY = ",F6.4 , &
664 &", REF_LAT = ",F8.3,", REF_LON = ",F8.3)') &
665 (imt+3)/2,jm+1,dlmd,dphd,rlat0d,-1.*rlon0d
666 CALL getset(xa,xb,ya,yb,xxa,xxy,yya,yyb,ltype)
667 CALL pchiqu(xxa,yya-(yyb-yya)/20.,string,8.,0.,-1.)
668 CALL set (xa,xb,ya,yb,&
669 1.,real(e_we(1)),1.,real(e_sn(1)),ltype)
671 ! Line width twice default thickness.
673 CALL setusv('LW',2000)
675 ! Draw a box for each nest.
678 call getxy ( xs, xe, ys, ye, &
681 parent_id , parent_grid_ratio , &
682 i_parent_start , j_parent_start )
684 call line ( xs , ys , xe , ys )
685 call line ( xe , ys , xe , ye )
686 call line ( xe , ye , xs , ye )
687 call line ( xs , ye , xs , ys )
692 ! Close workstation and NCAR Grpahics.
697 END SUBROUTINE mapbkg_egrid
699 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
701 SUBROUTINE e2t2g ( ncol,nrow,im,jm,tph0d,tlm0d,dphd,dlmd,glatd,glond)
705 REAL , PARAMETER :: D2R=1.74532925E-2 , R2D=1./D2R
712 !*** FIND THE TRANSFORMED LAT (POSITIVE NORTH) AND LON (POSITIVE EAST)
714 TLATD=(NROW-(JM+1)/2)*DPHD
717 !*** NOW CONVERT TO GEODETIC LAT (POSITIVE NORTH) AND LON (POSITIVE EAST)
721 ARG1=SIN(TLATR)*COS(TPH0)+COS(TLATR)*SIN(TPH0)*COS(TLONR)
724 ARG2=COS(TLATR)*COS(TLONR)/(COS(GLATR)*COS(TPH0))- &
726 IF(ABS(ARG2).GT.1.)ARG2=ABS(ARG2)/ARG2
728 IF(TLOND.GT.0.)FCTR=-1.
729 GLOND=TLM0D+FCTR*ACOS(ARG2)*R2D