New NCL script from Ming Chen. This will plot out
[WPS-merge.git] / util / src / plotgrids.F
blobb61768c52db274ed2b5d7c58648a3355344bfd2c
1 program plotgrids
3    use map_utils
4  
5    implicit none
7    ! Parameters
8    integer, parameter :: MAX_DOMAINS = 21
10    ! Variables
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
24    real :: dx, dy
25    real :: ri, rj, rlats, rlons, rlate, rlone
26    real :: polat , rot
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
44    logical :: is_used
45    logical :: nocolons
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
59   
60    ! Set defaults for namelist variables
61    debug_level = 0
62    io_form_geogrid = 2
63    wrf_core = 'ARW'
64    max_dom = 1
65    geog_data_path = 'NOT_SPECIFIED'
66    ref_x = NAN
67    ref_y = NAN
68    ref_lat = NAN
69    ref_lon = NAN
70    dx = 10000.
71    dy = 10000.
72    map_proj = 'Lambert'
73    truelat1 = NAN
74    truelat2 = NAN
75    stand_lon = NAN
76    do i=1,MAX_DOMAINS
77       geog_data_res(i) = 'default'
78       parent_id(i) = 1
79       parent_grid_ratio(i) = INVALID
80       s_we(i) = 1
81       e_we(i) = INVALID
82       s_sn(i) = 1
83       e_sn(i) = INVALID
84       start_year(i) = 0
85       start_month(i) = 0
86       start_day(i) = 0
87       start_hour(i) = 0
88       end_year(i) = 0
89       end_month(i) = 0
90       end_day(i) = 0
91       end_hour(i) = 0
92       start_date(i) = '0000-00-00_00:00:00'
93       end_date(i) = '0000-00-00_00:00:00'
94    end do
95    opt_output_from_geogrid_path = './'
96    opt_geogrid_tbl_path = 'geogrid/'
97    interval_seconds = INVALID
98    
99    ! Read parameters from Fortran namelist
100    do funit=10,100
101       inquire(unit=funit, opened=is_used)
102       if (.not. is_used) exit
103    end do
104    open(funit,file='namelist.wps',status='old',form='formatted',err=1000)
105    read(funit,share)
106    read(funit,geogrid)
107    close(funit)
109    dxkm = dx
110    dykm = dy
112    known_lat = ref_lat
113    known_lon = ref_lon
114    known_x = ref_x
115    known_y = ref_y
117    ! Convert wrf_core to uppercase letters
118    do i=1,3
119       if (ichar(wrf_core(i:i)) >= 97) wrf_core(i:i) = char(ichar(wrf_core(i:i))-32)
120    end do
122    ! Before doing anything else, we must have a valid grid type 
123    gridtype = ' '
124    if (wrf_core == 'ARW') then
125       gridtype = 'C'
126       dyn_opt = 2
127    else if (wrf_core == 'NMM') then
128       gridtype = 'E'
129       dyn_opt = 4
130    end if
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.'
135       stop
136    end if
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.'
141       stop
142    end if
144    ! Every domain must have a valid parent id
145    do i=2,max_dom
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
149           stop
150       end if
151    end do
153    ! Convert map_proj to uppercase letters
154    do i=1,len(map_proj)
155       if (ichar(map_proj(i:i)) >= 97) map_proj(i:i) = char(ichar(map_proj(i:i))-32)
156    end do
158    ! Assign parameters to module variables
159    if ((index(map_proj, 'LAMBERT') /= 0) .and. &
160        (len_trim(map_proj) == len('LAMBERT'))) then
161       iproj_type = PROJ_LC 
162       rot=truelat1
163       polat=truelat2
164       jproj = 3
166    else if ((index(map_proj, 'MERCATOR') /= 0) .and. &
167             (len_trim(map_proj) == len('MERCATOR'))) then
168       iproj_type = PROJ_MERC 
169       rot=0.
170       polat=0.
171       jproj = 9
173    else if ((index(map_proj, 'POLAR') /= 0) .and. &
174             (len_trim(map_proj) == len('POLAR'))) then
175       iproj_type = PROJ_PS 
176       rot=0.
177       polat=SIGN(90., ref_lat)
178       jproj = 1
180    else if ((index(map_proj, 'ROTATED_LL') /= 0) .and. &
181             (len_trim(map_proj) == len('ROTATED_LL'))) then
182       iproj_type = PROJ_ROTLL 
184    else
185          write(6,*) 'In namelist, invalid map_proj specified. Valid '// &
186                     'projections are "lambert", "mercator", "polar", '// &
187                     'and "rotated_ll".'
188          stop
189    end if
191    n_domains = max_dom
193    do i=1,n_domains
194       ixdim(i) = e_we(i) - s_we(i) + 1
195       jydim(i) = e_sn(i) - s_sn(i) + 1
196    end do
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".'
209          stop
210       end if
212       ! Check that nests have an acceptable number of grid points in each dimension
213       do i=2,n_domains
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.'
218             stop
219          end if
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.'
224             stop
225          end if
226       end do
227    end if
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.'
235          stop
236       end if
238       ! Check that the parent_grid_ratio is set to 3 for all nests
239       do i=2,n_domains
240          if (parent_grid_ratio(i) /= 3) then
241             write(6,*) 'The parent_grid_ratio must be set to 3 for the NMM core.'
242             stop
243          end if
244       end do
246       CALL plot_e_grid ( ref_lat , -1. * ref_lon , &
247                          dy , dx, &
248                          n_domains , &
249                          e_we , e_sn , &
250                          parent_id , parent_grid_ratio , &
251                          i_parent_start , j_parent_start )
252       stop
253    end if
255    do i=1,n_domains
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.
260    end do
262    call map_init(map_projection)
264    call map_set(iproj_type, map_projection, &
265                 lat1=known_lat, &
266                 lon1=known_lon, &
267                 knowni=known_x, &
268                 knownj=known_y, &
269                 dx=dx, &
270                 stdlon=stand_lon, &
271                 truelat1=truelat1, &
272                 truelat2=truelat2, &
273                 ixdim=ixdim(1), &
274                 jydim=jydim(1))
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)
279    call opngks
281    ! Set some colors
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
286    jgrid=10
287    jlts=-2
288    iusout=1
289    idot=0
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, &
303                    idom , max_dom , &
304                    e_we , e_sn , &
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 )
311    end do
313    call frame
315    write(6,*) ' '
316    write(6,*) 'Creating plot in NCAR Graphics metafile...'
317    write(6,*) ' '
319    call clsgks
321    write(6,*) ' *** Successful completion of program plotgrids.exe *** '
324    stop
326 1000 write(6,*) 'Error opening namelist.wps'
327    stop
328   
329 end program plotgrids
331 subroutine getxy ( xs, xe, ys, ye, &
332                    dom_id , num_domains , &
333                    e_we , e_sn , &
334                    parent_id , parent_grid_ratio , &
335                    i_parent_start , j_parent_start )
337    implicit none
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
347    !  local vars
349    integer :: idom
351    xs = 0.
352    xe = e_we(dom_id) -1
353    ys = 0.
354    ye = e_sn(dom_id) -1
356    idom = dom_id
357    compute_xy : DO
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
369          exit compute_xy
370       end if
372    END DO compute_xy
374    xs = xs + 1
375    xe = xs + xe
376    ys = ys + 1
377    ye = ys + ye
379 end subroutine getxy
381 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
382 !!!!!!  E GRID MAP INFO BELOW     !!!!!!!!!!!!!!
383 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
385 SUBROUTINE plot_e_grid ( rlat0d , rlon0d , dphd , dlmd, &
386                          n_domains , &
387                          e_we , e_sn , &
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.
395    IMPLICIT NONE
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
403 !    Domain size: IM,JM
404 !    Central latitute and longnitute: RLAT0D,RLON0D
405 !    Horizontal resolution: DPHD, DLMD
407 !  Feb 2007 NCAR/MMM
408 !    Turn into f90
409 !    Add implicit none
410 !    Remove non-mapping portions
411 !    Make part of WPS domain plotting utility
413 !  Dec 2008 NCAR/DTC
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 , &
426                                                  e_sn , &
427                                                  parent_id , &
428                                                  parent_grid_ratio , &
429                                                  i_parent_start , &
430                                                  j_parent_start
432    !  Some local vars
434    REAL :: rlat1d , &
435            rlon1d
437    INTEGER :: im, &     ! number of H points in odd rows
438               jm , &    ! number of rows
439               ngpwe , &
440               ngpsn , &
441               ilowl , &
442               jlowl
443      
444    INTEGER :: imt , imtjm
445    REAL :: latlft,lonlft,latrgt,lonrgt
447    im = e_we(1)-1
448    jm = e_sn(1)-1
450    imt=2*im-1
451    imtjm=imt*jm
452    rlat1d=rlat0d
453    rlon1d=rlon0d
454    ngpwe=2*im-1
455    ngpsn=jm
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,&
466                        dlmd,dphd,&
467                        n_domains,&
468                        e_we,e_sn,&
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)
479    IMPLICIT NONE
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
487    !  Local vars
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
493    REAL :: row , col
494    REAL :: dlm1 , dlm2 , d1 , d2 , d3 , d4 , dmin
496    INTEGER :: jmt , ii , jj , iuppr , juppr
497    INTEGER :: nrow , ncol
499    jmt = jm/2+1
501    !  Convert from geodetic to transformed coordinates (degrees).
503    glat = glatd * d2r
504    glon = glond * d2r
505    dph = dphd * d2r
506    dlm = dlmd * d2r
507    tph0 = tph0d * d2r
508    tlm0 = tlm0d * d2r
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 
517    !  the filled e-grid.
519    row = tlat/dphd+jmt
520    col = tlon/dlmd+im
521    nrow = INT(row)
522    ncol = INT(col)
523    tlat = tlat * d2r
524    tlon = tlon * d2r
526 !               E2     E3
529 !                  X
530 !               E1     E4
532    tlat1 = (nrow-jmt) * dph
533    tlat2 = tlat1+dph
534    tlon1 = (ncol-im) * dlm
535    tlon2 = tlon1+dlm
537    dlm1 = tlon-tlon1
538    dlm2 = tlon-tlon2
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
548      ii = ncol
549      jj = nrow
550    ELSE IF ( ABS(dmin-d2) .LT. 1.e-6 ) THEN
551      ii = ncol
552      jj = nrow+1
553    ELSE IF ( ABS(dmin-d3) .LT. 1.e-6 ) THEN
554      ii = ncol+1
555      jj = nrow+1
556    ELSE IF ( ABS(dmin-d4) .LT. 1.e-6 ) THEN
557      ii = ncol+1
558      jj = nrow
559    END IF
561    !  Now find the i and j of the lower left corner of the desired grid 
562    !  region and of the upper right.
564    ilowl = ii-ngpwe/2
565    jlowl = jj-ngpsn/2
566    iuppr = ii+ngpwe/2
567    juppr = jj+ngpsn/2
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,&
580                           dlmd,dphd,&
581                           n_domains,&
582                           e_we,e_sn,&
583                           parent_id,parent_grid_ratio,&
584                           i_parent_start , j_parent_start )
586 !  IMPLICIT NONE
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
593    !  Some local vars
595    CHARACTER (LEN=97) :: string
596    INTEGER :: i
597    REAL :: xs, xe, ys, ye
599    !  Yet more center lon messing around, hoo boy.
601 !  clonx=180.-rlon0d
602    clonx=-rlon0d
604    !  Open up NCAR Graphics
606    CALL opngks
607    CALL gopwk(8,9,3)
608    CALL gsclip(0)
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.
621    CALL mapsti('MV',8)
622    CALL mapsti('DO',0)
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.
638    CALL mapsti('GR',5)
640    !  Map takes up this much real estate.
642    CALL mappos( 0.05 , 0.95 , 0.05 , 0.95 )
644    !  Initialize and draw map.
646    CALL mapint
647    CALL mapdrw
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.
678    do i=2 , n_domains
679       call getxy ( xs, xe, ys, ye, &
680                    i , n_domains , &
681                    e_we , e_sn , &
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 )
689    end do
691    CALL frame
693    !  Close workstation and NCAR Grpahics.
695    CALL gclwk(8)
696    CALL clsgks
698 END SUBROUTINE mapbkg_egrid
700 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
702 SUBROUTINE e2t2g ( ncol,nrow,im,jm,tph0d,tlm0d,dphd,dlmd,glatd,glond)
704 !  IMPLICIT NONE
706    REAL , PARAMETER :: D2R=1.74532925E-2 , R2D=1./D2R
708    DPH=DPHD*D2R
709    DLM=DLMD*D2R
710    TPH0=TPH0D*D2R
711    TLM0=TLM0D*D2R
713 !***  FIND THE TRANSFORMED LAT (POSITIVE NORTH) AND LON (POSITIVE EAST)
715    TLATD=(NROW-(JM+1)/2)*DPHD
716    TLOND=(NCOL-IM)*DLMD
718 !***  NOW CONVERT TO GEODETIC LAT (POSITIVE NORTH) AND LON (POSITIVE EAST)
720    TLATR=TLATD*D2R
721    TLONR=TLOND*D2R
722    ARG1=SIN(TLATR)*COS(TPH0)+COS(TLATR)*SIN(TPH0)*COS(TLONR)
723    GLATR=ASIN(ARG1)
724    GLATD=GLATR*R2D
725    ARG2=COS(TLATR)*COS(TLONR)/(COS(GLATR)*COS(TPH0))- & 
726         TAN(GLATR)*TAN(TPH0)
727    IF(ABS(ARG2).GT.1.)ARG2=ABS(ARG2)/ARG2
728    FCTR=1.
729    IF(TLOND.GT.0.)FCTR=-1.
730    GLOND=TLM0D+FCTR*ACOS(ARG2)*R2D
731    GLOND=-GLOND
733 END SUBROUTINE e2t2g