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
47 type (proj_info) :: map_projection
49 namelist /share/ wrf_core, max_dom, start_date, end_date, &
50 start_year, end_year, start_month, end_month, &
51 start_day, end_day, start_hour, end_hour, &
52 interval_seconds, io_form_geogrid, opt_output_from_geogrid_path, &
53 debug_level, active_grid, nocolons
54 namelist /geogrid/ parent_id, parent_grid_ratio, &
55 i_parent_start, j_parent_start, s_we, e_we, s_sn, e_sn, &
56 map_proj, ref_x, ref_y, ref_lat, ref_lon, &
57 truelat1, truelat2, stand_lon, dx, dy, &
58 geog_data_res, geog_data_path, opt_geogrid_tbl_path
60 ! Set defaults for namelist variables
65 geog_data_path = 'NOT_SPECIFIED'
77 geog_data_res(i) = 'default'
79 parent_grid_ratio(i) = INVALID
92 start_date(i) = '0000-00-00_00:00:00'
93 end_date(i) = '0000-00-00_00:00:00'
95 opt_output_from_geogrid_path = './'
96 opt_geogrid_tbl_path = 'geogrid/'
97 interval_seconds = INVALID
99 ! Read parameters from Fortran namelist
101 inquire(unit=funit, opened=is_used)
102 if (.not. is_used) exit
104 open(funit,file='namelist.wps',status='old',form='formatted',err=1000)
117 ! Convert wrf_core to uppercase letters
119 if (ichar(wrf_core(i:i)) >= 97) wrf_core(i:i) = char(ichar(wrf_core(i:i))-32)
122 ! Before doing anything else, we must have a valid grid type
124 if (wrf_core == 'ARW') then
127 else if (wrf_core == 'NMM') then
132 if (gridtype /= 'C' .and. gridtype /= 'E') then
133 write(6,*) 'A valid wrf_core must be specified in the namelist. '// &
134 'Currently, only "ARW" and "NMM" are supported.'
138 if (max_dom > MAX_DOMAINS) then
139 write(6,*) 'In namelist, max_dom must be <= ',MAX_DOMAINS,'. To run with more'// &
140 ' than ',MAX_DOMAINS,' domains, increase the MAX_DOMAINS parameter.'
144 ! Every domain must have a valid parent id
146 if (parent_id(i) <= 0 .or. parent_id(i) >= i) then
147 write(6,*) 'In namelist, the parent_id of domain ',i,' must be in '// &
148 'the range 1 to ',i-1
153 ! Convert map_proj to uppercase letters
155 if (ichar(map_proj(i:i)) >= 97) map_proj(i:i) = char(ichar(map_proj(i:i))-32)
158 ! Assign parameters to module variables
159 if ((index(map_proj, 'LAMBERT') /= 0) .and. &
160 (len_trim(map_proj) == len('LAMBERT'))) then
166 else if ((index(map_proj, 'MERCATOR') /= 0) .and. &
167 (len_trim(map_proj) == len('MERCATOR'))) then
168 iproj_type = PROJ_MERC
173 else if ((index(map_proj, 'POLAR') /= 0) .and. &
174 (len_trim(map_proj) == len('POLAR'))) then
177 polat=SIGN(90., ref_lat)
180 else if ((index(map_proj, 'ROTATED_LL') /= 0) .and. &
181 (len_trim(map_proj) == len('ROTATED_LL'))) then
182 iproj_type = PROJ_ROTLL
185 write(6,*) 'In namelist, invalid map_proj specified. Valid '// &
186 'projections are "lambert", "mercator", "polar", '// &
194 ixdim(i) = e_we(i) - s_we(i) + 1
195 jydim(i) = e_sn(i) - s_sn(i) + 1
198 ! If the user hasn't supplied a known_x and known_y, assume the center of domain 1
199 if (known_x == NAN) known_x = ixdim(1) / 2.
200 if (known_y == NAN) known_y = jydim(1) / 2.
202 ! Checks specific to C grid
203 if (gridtype == 'C') then
205 ! C grid does not support the rotated lat/lon projection
206 if (iproj_type == PROJ_ROTLL) then
207 write(6,*) 'Rotated lat/lon projection is not supported for the ARW core. '// &
208 'Valid projecitons are "lambert", "mercator", and "polar".'
212 ! Check that nests have an acceptable number of grid points in each dimension
214 rparent_gridpts = real(ixdim(i)-1)/real(parent_grid_ratio(i))
215 if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
216 write(6,*) 'For nest ',i,' (e_we-s_we+1) must be one greater than an '// &
217 'integer multiple of the parent_grid_ratio.'
220 rparent_gridpts = real(jydim(i)-1)/real(parent_grid_ratio(i))
221 if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
222 write(6,*) 'For nest ',i,' (e_sn-s_sn+1) must be one greater than an '// &
223 'integer multiple of the parent_grid_ratio.'
229 ! Checks specific to E grid
230 if (gridtype == 'E') then
232 ! E grid supports only the rotated lat/lon projection
233 if (iproj_type /= PROJ_ROTLL) then
234 write(6,*) 'Rotated lat/lon is the only supported projection for the NMM core.'
238 ! Check that the parent_grid_ratio is set to 3 for all nests
240 if (parent_grid_ratio(i) /= 3) then
241 write(6,*) 'The parent_grid_ratio must be set to 3 for the NMM core.'
246 CALL plot_e_grid ( ref_lat , -1. * ref_lon , &
250 parent_id , parent_grid_ratio , &
251 i_parent_start , j_parent_start )
256 parent_ll_x(i) = real(i_parent_start(i))
257 parent_ll_y(i) = real(j_parent_start(i))
258 parent_ur_x(i) = real(i_parent_start(i))+real(ixdim(i))/real(parent_grid_ratio(i))-1.
259 parent_ur_y(i) = real(j_parent_start(i))+real(jydim(i))/real(parent_grid_ratio(i))-1.
262 call map_init(map_projection)
264 call map_set(iproj_type, map_projection, &
276 call ij_to_latlon(map_projection, 0.5, 0.5, rlats, rlons)
277 call ij_to_latlon(map_projection, real(e_we(1))-0.5, real(e_sn(1))-0.5, rlate, rlone)
282 call gscr(1, 0, 1.00, 1.00, 1.00)
283 call gscr(1, 1, 0.00, 0.00, 0.00)
285 ! Do not grind them with details
291 call supmap(jproj,polat,stand_lon,rot,&
292 rlats,rlons,rlate,rlone, &
293 jlts,jgrid,iusout,idot,ier)
295 call setusv('LW',1000)
296 call perim(e_we(1)-1,1,e_sn(1)-1,1)
297 call getset(xa,xb,ya,yb,xxa,xxy,yya,yyb,ltype)
298 call set (xa,xb,ya,yb, &
299 1.,real(e_we(1)),1.,real(e_sn(1)),ltype)
301 do idom = 2 , max_dom
302 call getxy ( xs, xe, ys, ye, &
305 parent_id , parent_grid_ratio , &
306 i_parent_start , j_parent_start )
307 call line ( xs , ys , xe , ys )
308 call line ( xe , ys , xe , ye )
309 call line ( xe , ye , xs , ye )
310 call line ( xs , ye , xs , ys )
316 write(6,*) 'Creating plot in NCAR Graphics metafile...'
321 write(6,*) ' *** Successful completion of program plotgrids.exe *** '
326 1000 write(6,*) 'Error opening namelist.wps'
329 end program plotgrids
331 subroutine getxy ( xs, xe, ys, ye, &
332 dom_id , num_domains , &
334 parent_id , parent_grid_ratio , &
335 i_parent_start , j_parent_start )
339 integer , intent(in) :: dom_id
340 integer , intent(in) :: num_domains
341 integer , intent(in) , dimension(num_domains):: e_we , e_sn , &
342 parent_id , parent_grid_ratio , &
343 i_parent_start , j_parent_start
344 real , intent(out) :: xs, xe, ys, ye
359 xs = (i_parent_start(idom) + xs -1 ) / &
360 real(parent_grid_ratio(parent_id(idom)))
361 xe = xe / real(parent_grid_ratio(idom))
363 ys = (j_parent_start(idom) + ys -1 ) / &
364 real(parent_grid_ratio(parent_id(idom)))
365 ye = ye / real(parent_grid_ratio(idom))
367 idom = parent_id(idom)
368 if ( idom .EQ. 1 ) then
381 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
382 !!!!!! E GRID MAP INFO BELOW !!!!!!!!!!!!!!
383 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
385 SUBROUTINE plot_e_grid ( rlat0d , rlon0d , dphd , dlmd, &
388 parent_id , parent_grid_ratio , &
389 i_parent_start , j_parent_start )
391 ! This routine generates a gmeta file of the area covered by an Arakawa e-grid.
392 ! We assume that NCAR Graphics has not been called yet (and will be closed
393 ! upon exit). The required input fields are as from the WPS namelist file.
397 ! 15 April 2005 NCEP/EMC
398 ! The Code and some instructions are provided by Tom BLACK to
399 ! NCAR/DTC Meral Demirtas
401 ! 4 May 2005 NCAR/DTC Meral DEMIRTAS
402 ! - An include file (plot_inc) is added to get
404 ! Central latitute and longnitute: RLAT0D,RLON0D
405 ! Horizontal resolution: DPHD, DLMD
410 ! Remove non-mapping portions
411 ! Make part of WPS domain plotting utility
414 ! Pass additional arguments to enable plotting of nests
416 ! Input map parameters for E grid.
418 REAL , INTENT(IN) :: rlat0d , & ! latitude of grid center (degrees)
419 rlon0d ! longitude of grid center (degrees, times -1)
421 REAL , INTENT(IN) :: dphd , & ! angular distance between rows (degrees)
422 dlmd ! angular distance between adjacent H and V points (degrees)
424 INTEGER , INTENT(in) :: n_domains ! number of domains
425 INTEGER , INTENT(in) , DIMENSION(n_domains):: e_we , &
428 parent_grid_ratio , &
437 INTEGER :: im, & ! number of H points in odd rows
438 jm , & ! number of rows
444 INTEGER :: imt , imtjm
445 REAL :: latlft,lonlft,latrgt,lonrgt
457 ! Get lat and lon of left and right points.
459 CALL corners ( rlat1d,rlon1d,im,jm,rlat0d,rlon0d,dphd,dlmd,&
460 ngpwe,ngpsn,ilowl,jlowl,latlft,lonlft,latrgt,lonrgt)
462 ! With corner points, make map background.
464 CALL mapbkg_egrid ( imt,jm,ilowl,jlowl,ngpwe,ngpsn,&
465 rlat0d,rlon0d,latlft,lonlft,latrgt,lonrgt,&
469 parent_id,parent_grid_ratio,&
470 i_parent_start,j_parent_start)
472 END SUBROUTINE plot_e_grid
474 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
476 SUBROUTINE corners ( glatd,glond,im,jm,tph0d,tlm0d,dphd,dlmd,&
477 ngpwe,ngpsn,ilowl,jlowl,glatl,glonl,glatr,glonr)
481 REAL , INTENT(IN) :: glatd,glond,tph0d,tlm0d,dphd,dlmd,&
482 glatl,glonl,glatr,glonr
484 INTEGER , INTENT(IN) :: im,jm,ngpwe,ngpsn
485 INTEGER , INTENT(OUT) :: ilowl,jlowl
489 REAL , PARAMETER :: d2r = 1.74532925E-2 , r2D = 1./D2R
491 REAL :: glat , glon , dph , dlm , tph0 , tlm0
492 REAL :: x , y , z , tlat , tlon , tlat1 , tlat2 , tlon1 , tlon2
494 REAL :: dlm1 , dlm2 , d1 , d2 , d3 , d4 , dmin
496 INTEGER :: jmt , ii , jj , iuppr , juppr
497 INTEGER :: nrow , ncol
501 ! Convert from geodetic to transformed coordinates (degrees).
510 x = COS(tph0) * COS(glat) * COS(glon-tlm0)+SIN(tph0) * SIN(glat)
511 y = -COS(glat) * SIN(glon-tlm0)
512 z = COS(tph0) * SIN(glat)-SIN(tph0) * COS(glat) * COS(glon-tlm0)
513 tlat = r2d * ATAN(z/SQRT(x*x + y*y))
514 tlon = r2d * ATAN(y/x)
516 ! Find the real (non-integer) row and column of the input location on
532 tlat1 = (nrow-jmt) * dph
534 tlon1 = (ncol-im) * dlm
540 d1 = ACOS(COS(tlat) * COS(tlat1) * COS(dlm1)+SIN(tlat) * SIN(tlat1))
541 d2 = ACOS(COS(tlat) * COS(tlat2) * COS(dlm1)+SIN(tlat) * SIN(tlat2))
542 d3 = ACOS(COS(tlat) * COS(tlat2) * COS(dlm2)+SIN(tlat) * SIN(tlat2))
543 d4 = ACOS(COS(tlat) * COS(tlat1) * COS(dlm2)+SIN(tlat) * SIN(tlat1))
545 dmin = MIN(d1,d2,d3,d4)
547 IF ( ABS(dmin-d1) .LT. 1.e-6 ) THEN
550 ELSE IF ( ABS(dmin-d2) .LT. 1.e-6 ) THEN
553 ELSE IF ( ABS(dmin-d3) .LT. 1.e-6 ) THEN
556 ELSE IF ( ABS(dmin-d4) .LT. 1.e-6 ) THEN
561 ! Now find the i and j of the lower left corner of the desired grid
562 ! region and of the upper right.
569 ! Find their geodetic coordinates.
571 CALL e2t2g(ilowl,jlowl,im,jm,tph0d,tlm0d,dphd,dlmd,glatl,glonl)
572 CALL e2t2g(iuppr,juppr,im,jm,tph0d,tlm0d,dphd,dlmd,glatr,glonr)
574 END SUBROUTINE corners
576 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
578 SUBROUTINE mapbkg_egrid ( imt,jm,ilowl,jlowl,ngpwe,ngpsn,&
579 rlat0d,rlon0d,glatl,glonl,glatr,glonr,&
583 parent_id,parent_grid_ratio,&
584 i_parent_start , j_parent_start )
588 INTEGER , INTENT(in) :: n_domains
589 INTEGER , INTENT(in) , DIMENSION(n_domains):: e_we , e_sn , &
590 parent_id , parent_grid_ratio , &
591 i_parent_start , j_parent_start
595 CHARACTER (LEN=97) :: string
597 REAL :: xs, xe, ys, ye
599 ! Yet more center lon messing around, hoo boy.
604 ! Open up NCAR Graphics
610 ! Make the background white, and the foreground black.
612 CALL gscr ( 1 , 0 , 1., 1., 1. )
613 CALL gscr ( 1 , 1 , 0., 0., 0. )
615 ! Line width default thickness.
617 CALL setusv('LW',1000)
619 ! Make map outline a solid line, not dots.
624 ! Map outlines are political and states.
626 CALL mapstc('OU','PS')
628 ! Cylindrical equidistant.
630 CALL maproj('CE',rlat0d,clonx,0.)
632 ! Specify corner points.
634 CALL mapset('CO',glatl,glonl,glatr,glonr)
636 ! Lat lon lines every 5 degrees.
640 ! Map takes up this much real estate.
642 CALL mappos( 0.05 , 0.95 , 0.05 , 0.95 )
644 ! Initialize and draw map.
649 ! Line width twice default thickness.
651 CALL setusv('LW',2000)
653 ! Add approx grid point tick marks
655 CALL perim(((imt+3)/2)-1,1,jm-1,1)
657 ! Line width default thickness.
659 CALL setusv('LW',1000)
661 ! Put on a quicky description.
663 WRITE ( string , FMT = '("E-GRID E_WE = ",I4,", E_SN = ",I4 , &
664 &", DX = ",F6.4,", DY = ",F6.4 , &
665 &", REF_LAT = ",F8.3,", REF_LON = ",F8.3)') &
666 (imt+3)/2,jm+1,dlmd,dphd,rlat0d,-1.*rlon0d
667 CALL getset(xa,xb,ya,yb,xxa,xxy,yya,yyb,ltype)
668 CALL pchiqu(xxa,yya-(yyb-yya)/20.,string,8.,0.,-1.)
669 CALL set (xa,xb,ya,yb,&
670 1.,real(e_we(1)),1.,real(e_sn(1)),ltype)
672 ! Line width twice default thickness.
674 CALL setusv('LW',2000)
676 ! Draw a box for each nest.
679 call getxy ( xs, xe, ys, ye, &
682 parent_id , parent_grid_ratio , &
683 i_parent_start , j_parent_start )
685 call line ( xs , ys , xe , ys )
686 call line ( xe , ys , xe , ye )
687 call line ( xe , ye , xs , ye )
688 call line ( xs , ye , xs , ys )
693 ! Close workstation and NCAR Grpahics.
698 END SUBROUTINE mapbkg_egrid
700 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
702 SUBROUTINE e2t2g ( ncol,nrow,im,jm,tph0d,tlm0d,dphd,dlmd,glatd,glond)
706 REAL , PARAMETER :: D2R=1.74532925E-2 , R2D=1./D2R
713 !*** FIND THE TRANSFORMED LAT (POSITIVE NORTH) AND LON (POSITIVE EAST)
715 TLATD=(NROW-(JM+1)/2)*DPHD
718 !*** NOW CONVERT TO GEODETIC LAT (POSITIVE NORTH) AND LON (POSITIVE EAST)
722 ARG1=SIN(TLATR)*COS(TPH0)+COS(TLATR)*SIN(TPH0)*COS(TLONR)
725 ARG2=COS(TLATR)*COS(TLONR)/(COS(GLATR)*COS(TPH0))- &
727 IF(ABS(ARG2).GT.1.)ARG2=ABS(ARG2)/ARG2
729 IF(TLOND.GT.0.)FCTR=-1.
730 GLOND=TLM0D+FCTR*ACOS(ARG2)*R2D