| 1 | program pltfmt |
|---|
| 2 | |
|---|
| 3 | use read_met_module |
|---|
| 4 | |
|---|
| 5 | implicit none |
|---|
| 6 | ! |
|---|
| 7 | ! Utility program to plot up the files created by pregrid. |
|---|
| 8 | ! Uses NCAR graphics routines. If you don't have NCAR Graphics, you're |
|---|
| 9 | ! out of luck. |
|---|
| 10 | ! |
|---|
| 11 | INTEGER :: istatus, version, nx, ny, iproj |
|---|
| 12 | integer :: idum, ilev |
|---|
| 13 | REAL :: xfcst, xlvl, startlat, startlon, starti, startj, & |
|---|
| 14 | deltalat, deltalon, dx, dy, xlonc, truelat1, truelat2, earth_radius |
|---|
| 15 | REAL, POINTER, DIMENSION(:,:) :: slab |
|---|
| 16 | LOGICAL :: is_wind_grid_rel |
|---|
| 17 | |
|---|
| 18 | CHARACTER ( LEN =132 ) :: flnm |
|---|
| 19 | |
|---|
| 20 | CHARACTER ( LEN = 24 ) :: hdate |
|---|
| 21 | CHARACTER ( LEN = 9 ) :: field |
|---|
| 22 | CHARACTER ( LEN = 25 ) :: units |
|---|
| 23 | CHARACTER ( LEN = 46 ) :: desc |
|---|
| 24 | CHARACTER ( LEN = 32 ) :: map_source |
|---|
| 25 | |
|---|
| 26 | ! |
|---|
| 27 | ! Set up the graceful stop (Sun, SGI, DEC). |
|---|
| 28 | ! |
|---|
| 29 | integer, external :: graceful_stop |
|---|
| 30 | integer, external :: signal |
|---|
| 31 | integer :: iii |
|---|
| 32 | |
|---|
| 33 | iii = signal(2, graceful_stop, -1) |
|---|
| 34 | |
|---|
| 35 | call getarg(1,flnm) |
|---|
| 36 | |
|---|
| 37 | call gopks(6,idum) |
|---|
| 38 | call gopwk(1,55,1) |
|---|
| 39 | call gopwk(2,56,3) |
|---|
| 40 | call gacwk(1) |
|---|
| 41 | call gacwk(2) |
|---|
| 42 | call pcseti('FN', 21) |
|---|
| 43 | call pcsetc('FC', '~') |
|---|
| 44 | |
|---|
| 45 | call gscr(1,0, 1.000, 1.000, 1.000) |
|---|
| 46 | call gscr(1,1, 0.000, 0.000, 0.000) |
|---|
| 47 | call gscr(1,2, 0.900, 0.600, 0.600) |
|---|
| 48 | |
|---|
| 49 | CALL read_met_init(TRIM(flnm), .true., '0000-00-00_00', istatus) |
|---|
| 50 | |
|---|
| 51 | IF ( istatus == 0 ) THEN |
|---|
| 52 | |
|---|
| 53 | CALL read_next_met_field(version, field, hdate, xfcst, xlvl, units, desc, & |
|---|
| 54 | iproj, startlat, startlon, starti, startj, deltalat, & |
|---|
| 55 | deltalon, dx, dy, xlonc, truelat1, truelat2, earth_radius, & |
|---|
| 56 | nx, ny, map_source, & |
|---|
| 57 | slab, is_wind_grid_rel, istatus) |
|---|
| 58 | |
|---|
| 59 | DO WHILE (istatus == 0) |
|---|
| 60 | |
|---|
| 61 | ilev = nint(xlvl) |
|---|
| 62 | |
|---|
| 63 | if (iproj == PROJ_LATLON) then |
|---|
| 64 | call plt2d(slab, nx, ny, iproj, & |
|---|
| 65 | startlat, startlon, deltalon, deltalat, xlonc, truelat1, truelat2, & |
|---|
| 66 | field, ilev, units, version, desc, map_source) |
|---|
| 67 | else |
|---|
| 68 | call plt2d(slab, nx, ny, iproj, & |
|---|
| 69 | startlat, startlon, dx, dy, xlonc, truelat1, truelat2, & |
|---|
| 70 | field, ilev, units, version, desc, map_source) |
|---|
| 71 | end if |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | IF (ASSOCIATED(slab)) DEALLOCATE(slab) |
|---|
| 75 | |
|---|
| 76 | CALL read_next_met_field(version, field, hdate, xfcst, xlvl, units, desc, & |
|---|
| 77 | iproj, startlat, startlon, starti, startj, deltalat, & |
|---|
| 78 | deltalon, dx, dy, xlonc, truelat1, truelat2, earth_radius, & |
|---|
| 79 | nx, ny, map_source, & |
|---|
| 80 | slab, is_wind_grid_rel, istatus) |
|---|
| 81 | END DO |
|---|
| 82 | |
|---|
| 83 | CALL read_met_close() |
|---|
| 84 | |
|---|
| 85 | ELSE |
|---|
| 86 | |
|---|
| 87 | print *, 'File = ',TRIM(flnm) |
|---|
| 88 | print *, 'Problem with input file, I can''t open it' |
|---|
| 89 | STOP |
|---|
| 90 | |
|---|
| 91 | END IF |
|---|
| 92 | |
|---|
| 93 | call stopit |
|---|
| 94 | |
|---|
| 95 | end program pltfmt |
|---|
| 96 | |
|---|
| 97 | subroutine plt2d(scr2d, ix, jx, llflag, & |
|---|
| 98 | lat1, lon1, dx, dy, lov, truelat1, truelat2, & |
|---|
| 99 | field, ilev, units, ifv, Desc, source) |
|---|
| 100 | |
|---|
| 101 | use misc_definitions_module |
|---|
| 102 | |
|---|
| 103 | implicit none |
|---|
| 104 | |
|---|
| 105 | integer :: llflag |
|---|
| 106 | integer :: ix, jx, ifv |
|---|
| 107 | real, dimension(ix,jx) :: scr2d(ix,jx) |
|---|
| 108 | real :: lat1, lon1, lov, truelat1, truelat2 |
|---|
| 109 | real :: dx, dy |
|---|
| 110 | character(len=*) :: field |
|---|
| 111 | character(len=*) :: units |
|---|
| 112 | character(len=*) :: Desc |
|---|
| 113 | character(len=*) :: source |
|---|
| 114 | character(len=30) :: hunit |
|---|
| 115 | character(len=32) :: tmp32 |
|---|
| 116 | |
|---|
| 117 | integer :: iproj, ierr |
|---|
| 118 | real :: pl1, pl2, pl3, pl4, plon, plat, rota, phic |
|---|
| 119 | real :: xl, xr, xb, xt, wl, wr, wb, wt |
|---|
| 120 | integer :: ml, ih, i |
|---|
| 121 | |
|---|
| 122 | integer, parameter :: lwrk = 20000, liwk = 50000 |
|---|
| 123 | real, dimension(lwrk) :: rwrk |
|---|
| 124 | integer, dimension(liwk) :: iwrk |
|---|
| 125 | |
|---|
| 126 | integer :: ilev |
|---|
| 127 | character(len=8) :: hlev |
|---|
| 128 | |
|---|
| 129 | select case (llflag) |
|---|
| 130 | case (PROJ_LATLON) |
|---|
| 131 | pl1 = lat1 |
|---|
| 132 | pl2 = lon1 |
|---|
| 133 | call fmtxyll(float(ix), float(jx), pl3, pl4, 'CE', pl1, pl2, & |
|---|
| 134 | plon, truelat1, truelat2, dx, dy) |
|---|
| 135 | plon = (pl2 + pl4) / 2. |
|---|
| 136 | plat = 0. |
|---|
| 137 | rota = 0. |
|---|
| 138 | iproj=8 |
|---|
| 139 | case (PROJ_MERC) |
|---|
| 140 | pl1 = lat1 |
|---|
| 141 | pl2 = lon1 |
|---|
| 142 | plon = 0. |
|---|
| 143 | call fmtxyll(float(ix), float(jx), pl3, pl4, 'ME', pl1, pl2, & |
|---|
| 144 | plon, truelat1, truelat2, dx, dy) |
|---|
| 145 | plat = 0. |
|---|
| 146 | rota = 0 |
|---|
| 147 | iproj = 9 |
|---|
| 148 | case (PROJ_LC) |
|---|
| 149 | pl1 = lat1 |
|---|
| 150 | pl2 = lon1 |
|---|
| 151 | plon = lov |
|---|
| 152 | call fmtxyll(float(ix), float(jx), pl3, pl4, 'LC', pl1, pl2,& |
|---|
| 153 | plon, truelat1, truelat2, dx, dy) |
|---|
| 154 | plat = truelat1 |
|---|
| 155 | rota = truelat2 |
|---|
| 156 | iproj=3 |
|---|
| 157 | ! This never used to be a problem, but currently we seem to need |
|---|
| 158 | ! truelat1 (in plat) differ from truelat2 (in rota) for the |
|---|
| 159 | ! NCAR-Graphics map routines to work. Maybe it's just a compiler |
|---|
| 160 | ! thing. So if the truelats are the same, we add an epsilon: |
|---|
| 161 | if (abs(plat - rota) < 1.E-8) then |
|---|
| 162 | plat = plat + 1.E-8 |
|---|
| 163 | rota = rota - 1.E-8 |
|---|
| 164 | endif |
|---|
| 165 | case (PROJ_PS) |
|---|
| 166 | print*, 'ix, jx = ', ix, jx |
|---|
| 167 | print*, 'lat1, lon1 = ', lat1, lon1 |
|---|
| 168 | pl1 = lat1 |
|---|
| 169 | pl2 = lon1 |
|---|
| 170 | plon = lov |
|---|
| 171 | plat = 90. |
|---|
| 172 | print*, 'plon, plat = ', plon, plat |
|---|
| 173 | phic = 90. |
|---|
| 174 | rota = 0. |
|---|
| 175 | call fmtxyll(float(ix), float(jx), pl3, pl4, 'ST', pl1, pl2,& |
|---|
| 176 | plon, truelat1, truelat2, dx, dy) |
|---|
| 177 | iproj=1 |
|---|
| 178 | print*, pl1, pl2, pl3, pl4 |
|---|
| 179 | case default |
|---|
| 180 | print*,'Unsupported map projection ',llflag,' in input' |
|---|
| 181 | stop |
|---|
| 182 | end select |
|---|
| 183 | |
|---|
| 184 | call supmap(iproj,plat,plon,rota,pl1,pl2,pl3,pl4,2,30,4,0,ierr) |
|---|
| 185 | ! call supmap(iproj,plat+0.001,plon,rota-0.001,pl1,pl2,pl3,pl4,2,30,4,0,ierr) |
|---|
| 186 | if (ierr.ne.0) then |
|---|
| 187 | print*, 'supmap ierr = ', ierr |
|---|
| 188 | stop |
|---|
| 189 | ! stop |
|---|
| 190 | endif |
|---|
| 191 | call getset(xl,xr,xb,xt,wl,wr,wb,wt,ml) |
|---|
| 192 | |
|---|
| 193 | write(hlev,'(I8)') ilev |
|---|
| 194 | |
|---|
| 195 | call set(0., 1., 0., 1., 0., 1., 0., 1., 1) |
|---|
| 196 | call pchiqu(0.1, xb-0.04, hlev//' '//field, .020, 0.0, -1.0) |
|---|
| 197 | print*, field//'#'//units//'#'//trim(Desc) |
|---|
| 198 | ! call pchiqu(0.1, xb-0.12, Desc, .012, 0.0, -1.0) |
|---|
| 199 | hunit = ' ' |
|---|
| 200 | ih = 0 |
|---|
| 201 | do i = 1, len(units) |
|---|
| 202 | if (units(i:i).eq.'{') then |
|---|
| 203 | hunit(ih+1:ih+3) = '~S~' |
|---|
| 204 | ih = ih + 3 |
|---|
| 205 | elseif (units(i:i).eq.'}') then |
|---|
| 206 | hunit(ih+1:ih+3) = '~N~' |
|---|
| 207 | ih = ih + 3 |
|---|
| 208 | else |
|---|
| 209 | ih = ih + 1 |
|---|
| 210 | hunit(ih:ih) = units(i:i) |
|---|
| 211 | endif |
|---|
| 212 | enddo |
|---|
| 213 | if ( ifv .le. 3 ) then |
|---|
| 214 | tmp32 = 'MM5 intermediate format' |
|---|
| 215 | else if ( ifv .eq. 4 ) then |
|---|
| 216 | tmp32 = 'SI intermediate format' |
|---|
| 217 | else if ( ifv .eq. 5 ) then |
|---|
| 218 | tmp32 = 'WPS intermediate format' |
|---|
| 219 | endif |
|---|
| 220 | call pchiqu(0.1, xb-0.08, hunit, .015, 0.0, -1.0) |
|---|
| 221 | call pchiqu(0.1, xb-0.12, Desc, .013, 0.0, -1.0) |
|---|
| 222 | call pchiqu(0.6, xb-0.12, source, .013, 0.0, -1.0) |
|---|
| 223 | call pchiqu(0.1, xb-0.15, tmp32, .013, 0.0, -1.0) |
|---|
| 224 | |
|---|
| 225 | call set(xl,xr,xb,xt,1.,float(ix),1.,float(jx),ml) |
|---|
| 226 | |
|---|
| 227 | call CPSETI ('SET - Do-SET-Call Flag', 0) |
|---|
| 228 | call CPSETR ('SPV - Special Value', -1.E30) |
|---|
| 229 | |
|---|
| 230 | if (dy.lt.0.) then |
|---|
| 231 | call array_flip(scr2d, ix, jx) |
|---|
| 232 | endif |
|---|
| 233 | |
|---|
| 234 | call cpseti('LLP', 3) |
|---|
| 235 | call cprect(scr2d,ix,ix,jx,rwrk,lwrk,iwrk,liwk) |
|---|
| 236 | call cpcldr(scr2d,rwrk,iwrk) |
|---|
| 237 | call cplbdr(scr2d,rwrk,iwrk) |
|---|
| 238 | |
|---|
| 239 | if (dy.lt.0.) then |
|---|
| 240 | call array_flip(scr2d, ix, jx) |
|---|
| 241 | endif |
|---|
| 242 | |
|---|
| 243 | call frame |
|---|
| 244 | |
|---|
| 245 | end subroutine plt2d |
|---|
| 246 | |
|---|
| 247 | subroutine stopit |
|---|
| 248 | call graceful_stop |
|---|
| 249 | end |
|---|
| 250 | |
|---|
| 251 | subroutine graceful_stop |
|---|
| 252 | call gdawk(2) |
|---|
| 253 | call gdawk(1) |
|---|
| 254 | call gclwk(2) |
|---|
| 255 | call gclwk(1) |
|---|
| 256 | call gclks |
|---|
| 257 | print*, 'Graceful Stop.' |
|---|
| 258 | stop |
|---|
| 259 | end subroutine graceful_stop |
|---|
| 260 | |
|---|
| 261 | subroutine fmtxyll(x, y, xlat, xlon, project, glat1, glon1, gclon,& |
|---|
| 262 | gtrue1, gtrue2, gdx, gdy) |
|---|
| 263 | implicit none |
|---|
| 264 | |
|---|
| 265 | real , intent(in) :: x, y, glat1, glon1, gtrue1, gtrue2, gdx, gdy, gclon |
|---|
| 266 | character(len=2), intent(in) :: project |
|---|
| 267 | real , intent(out) :: xlat, xlon |
|---|
| 268 | |
|---|
| 269 | real :: gx1, gy1, gkappa |
|---|
| 270 | real :: grrth = 6370. |
|---|
| 271 | |
|---|
| 272 | real :: r, y1 |
|---|
| 273 | integer :: iscan, jscan |
|---|
| 274 | real, parameter :: pi = 3.1415926534 |
|---|
| 275 | real, parameter :: degran = pi/180. |
|---|
| 276 | real, parameter :: raddeg = 180./pi |
|---|
| 277 | real :: gt |
|---|
| 278 | |
|---|
| 279 | if (project.eq.'CE') then ! Cylindrical Equidistant grid |
|---|
| 280 | |
|---|
| 281 | xlat = glat1 + gdy*(y-1.) |
|---|
| 282 | xlon = glon1 + gdx*(x-1.) |
|---|
| 283 | |
|---|
| 284 | elseif (project == "ME") then |
|---|
| 285 | |
|---|
| 286 | gt = grrth * cos(gtrue1*degran) |
|---|
| 287 | xlon = glon1 + (gdx*(x-1.)/gt)*raddeg |
|---|
| 288 | y1 = gt*alog((1.+sin(glat1*degran))/cos(glat1*degran))/gdy |
|---|
| 289 | xlat = 90. - 2. * atan(exp(-gdy*(y+y1-1.)/gt))*raddeg |
|---|
| 290 | |
|---|
| 291 | elseif (project.eq.'ST') then ! Polar Stereographic grid |
|---|
| 292 | |
|---|
| 293 | r = grrth/gdx * tand((90.-glat1)/2.) * (1.+sind(gtrue1)) |
|---|
| 294 | gx1 = r * sind(glon1-gclon) |
|---|
| 295 | gy1 = - r * cosd(glon1-gclon) |
|---|
| 296 | |
|---|
| 297 | r = sqrt((x-1.+gx1)**2 + (y-1+gy1)**2) |
|---|
| 298 | xlat = 90. - 2.*atan2d((r*gdx),(grrth*(1.+sind(gtrue1)))) |
|---|
| 299 | xlon = atan2d((x-1.+gx1),-(y-1.+gy1)) + gclon |
|---|
| 300 | |
|---|
| 301 | elseif (project.eq.'LC') then ! Lambert-conformal grid |
|---|
| 302 | |
|---|
| 303 | call glccone(gtrue1, gtrue2, 1, gkappa) |
|---|
| 304 | |
|---|
| 305 | r = grrth/(gdx*gkappa)*sind(90.-gtrue1) * & |
|---|
| 306 | (tand(45.-glat1/2.)/tand(45.-gtrue1/2.)) ** gkappa |
|---|
| 307 | gx1 = r*sind(gkappa*(glon1-gclon)) |
|---|
| 308 | gy1 = -r*cosd(gkappa*(glon1-gclon)) |
|---|
| 309 | |
|---|
| 310 | r = sqrt((x-1.+gx1)**2 + (y-1+gy1)**2) |
|---|
| 311 | xlat = 90. - 2.*atand(tand(45.-gtrue1/2.)* & |
|---|
| 312 | ((r*gkappa*gdx)/(grrth*sind(90.-gtrue1)))**(1./gkappa)) |
|---|
| 313 | xlon = atan2d((x-1.+gx1),-(y-1.+gy1))/gkappa + gclon |
|---|
| 314 | |
|---|
| 315 | else |
|---|
| 316 | |
|---|
| 317 | write(*,'("Unrecoginzed projection: ", A)') project |
|---|
| 318 | write(*,'("Abort in FMTXYLL",/)') |
|---|
| 319 | stop |
|---|
| 320 | |
|---|
| 321 | endif |
|---|
| 322 | contains |
|---|
| 323 | real function sind(theta) |
|---|
| 324 | real :: theta |
|---|
| 325 | sind = sin(theta*degran) |
|---|
| 326 | end function sind |
|---|
| 327 | real function cosd(theta) |
|---|
| 328 | real :: theta |
|---|
| 329 | cosd = cos(theta*degran) |
|---|
| 330 | end function cosd |
|---|
| 331 | real function tand(theta) |
|---|
| 332 | real :: theta |
|---|
| 333 | tand = tan(theta*degran) |
|---|
| 334 | end function tand |
|---|
| 335 | real function atand(x) |
|---|
| 336 | real :: x |
|---|
| 337 | atand = atan(x)*raddeg |
|---|
| 338 | end function atand |
|---|
| 339 | real function atan2d(x,y) |
|---|
| 340 | real :: x,y |
|---|
| 341 | atan2d = atan2(x,y)*raddeg |
|---|
| 342 | end function atan2d |
|---|
| 343 | |
|---|
| 344 | subroutine glccone (fsplat,ssplat,sign,confac) |
|---|
| 345 | implicit none |
|---|
| 346 | real, intent(in) :: fsplat,ssplat |
|---|
| 347 | integer, intent(in) :: sign |
|---|
| 348 | real, intent(out) :: confac |
|---|
| 349 | if (abs(fsplat-ssplat).lt.1.E-3) then |
|---|
| 350 | confac = sind(fsplat) |
|---|
| 351 | else |
|---|
| 352 | confac = log10(cosd(fsplat))-log10(cosd(ssplat)) |
|---|
| 353 | confac = confac/(log10(tand(45.-float(sign)*fsplat/2.))- & |
|---|
| 354 | log10(tand(45.-float(sign)*ssplat/2.))) |
|---|
| 355 | endif |
|---|
| 356 | end subroutine glccone |
|---|
| 357 | |
|---|
| 358 | end subroutine fmtxyll |
|---|
| 359 | |
|---|
| 360 | subroutine array_flip(array, ix, jx) |
|---|
| 361 | implicit none |
|---|
| 362 | integer :: ix, jx |
|---|
| 363 | real , dimension(ix,jx) :: array |
|---|
| 364 | |
|---|
| 365 | real, dimension(ix) :: hold |
|---|
| 366 | integer :: i, j, jj |
|---|
| 367 | |
|---|
| 368 | do j = 1, jx/2 |
|---|
| 369 | jj = jx+1-j |
|---|
| 370 | hold = array(1:ix, j) |
|---|
| 371 | array(1:ix,j) = array(1:ix,jj) |
|---|
| 372 | array(1:ix,jj) = hold |
|---|
| 373 | enddo |
|---|
| 374 | end subroutine array_flip |
|---|
| 375 | |
|---|