Changeset 1620 in lmdz_wrf
- Timestamp:
- Sep 7, 2017, 2:52:14 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/module_scientific.f90
r1618 r1620 32 32 CONTAINS 33 33 34 SUBROUTINE all_polygons_properties(dx, dy, Npoly, polys, lon, lat, values, xres, yres, projN, & 35 Npolyptss, xxtrms, yxtrms, meanctrs, areas, nvals, xvals, mvals, m2vals, stdvals, Nquant, quants) 34 SUBROUTINE all_polygons_properties(dbg, dx, dy, Npoly, polys, lon, lat, values, xres, yres, projN, & 35 Npolyptss, xxtrms, yxtrms, meanctrs, meanwctrs, areas, nvals, xvals, mvals, m2vals, stdvals, & 36 Nquant, quants, nvcoords, xvcoords, meanvnctrs, meanvxctrs) 36 37 ! Subroutine to determine the properties of all polygons in a 2D field: 37 38 ! Number of grid points 38 39 ! grid-point coordinates of the minimum and maximum of the path along x,y axes 39 ! center from the mean of the coordinates of the paths locations 40 ! grid coordinates of center from the mean of the coordinates of the poygon locations 41 ! lon, lat center from the area weighted mean of the coordinates of the polygon locations 40 42 ! area of the polygon (km2) 41 43 ! minimum and maximum of the values within the polygon … … 45 47 ! number of quantiles 46 48 ! quantiles of the values within the polygon 49 ! grid coordinates of the minimum, maximum value within the polygon 50 ! lon, lat coordinates of the area center weighted and also by distance to the lowest or highest values of the polygon 47 51 48 52 IMPLICIT NONE 49 53 54 LOGICAL, INTENT(in) :: dbg 50 55 INTEGER, INTENT(in) :: dx, dy, Npoly, Nquant 51 56 INTEGER, DIMENSION(dx,dy), INTENT(in) :: polys 52 57 REAL(r_k), DIMENSION(dx,dy), INTENT(in) :: lon, lat, values 53 58 REAL(r_k), INTENT(in) :: xres, yres 54 CHARACTER(len= 50), INTENT(in):: projN59 CHARACTER(len=1000), INTENT(in) :: projN 55 60 INTEGER, DIMENSION(Npoly), INTENT(out) :: Npolyptss 56 INTEGER, DIMENSION(Npoly, 2), INTENT(out):: xxtrms, yxtrms, meanctrs61 INTEGER, DIMENSION(Npoly,2), INTENT(out) :: xxtrms, yxtrms, meanctrs 57 62 REAL(r_k), DIMENSION(Npoly), INTENT(out) :: areas 58 63 REAL(r_k), DIMENSION(Npoly), INTENT(out) :: nvals, xvals, mvals, m2vals, stdvals 59 64 REAL(r_k), DIMENSION(Npoly, Nquant), INTENT(out) :: quants 65 INTEGER, DIMENSION(Npoly,2), INTENT(out) :: nvcoords, xvcoords 66 REAL(r_k), DIMENSION(Npoly,2), INTENT(out) :: meanwctrs, meanvnctrs, meanvxctrs 60 67 61 68 ! Local … … 72 79 ! projN: name of the projection 73 80 ! 'lon/lat': for regular longitude-latitude 81 ! 'nadir-sat,[lonNADIR],[latNADIR]': for satellite data with the resolution given at nadir (lonNADIR, latNADIR) 74 82 ! Npolyptss: number of points of the polygons 75 83 ! [x/y]xtrms: grid-point coordinates of minimum and maximum coordinates of the polygons 76 84 ! meanctrs: center from the mean of the coordinates of the polygons 85 ! meanwctrs: lon, lat coordinates of the center from the spatial-weighted mean of the polygons 77 86 ! areas: area of the polygons [km] 78 87 ! [n/x]vals: minimum and maximum of the values within the polygons … … 82 91 ! Nquant: number of quantiles 83 92 ! quants: quantiles of the values within the polygons 93 ! [n/x]vcoords: grid coordinates of the minimum/maximum of the values within the polygons 94 ! meanv[n/x]ctrs: lon, lat coordinates of the area center weighted and also by distance to the lowest or highest values of the polygons 84 95 85 96 fname = 'all_polygons_properties' … … 90 101 yxtrms = fillval64 91 102 meanctrs = fillval64 103 meanwctrs = fillval64 92 104 areas = fillval64 93 105 nvals = -1 … … 97 109 stdvals = fillval64 98 110 quants = fillval64 111 nvcoords = -1 112 xvcoords = -1 113 meanvnctrs = fillval64 114 meanvxctrs = fillval64 99 115 100 116 DO ip=1, Npoly 101 117 boolpoly = polys == ip 102 CALL polygon_properties(dx, dy, boolpoly, lon, lat, values, xres, yres, projN, Npolyptss(ip), & 103 xxtrms(ip,:), yxtrms(ip,:), meanctrs(ip,:), areas(ip), nvals(ip), xvals(ip), mvals(ip), & 104 m2vals(ip), stdvals(ip), Nquant, quants(ip,:)) 118 CALL polygon_properties(dbg, dx, dy, boolpoly, lon, lat, values, xres, yres, projN, Npolyptss(ip),& 119 xxtrms(ip,:), yxtrms(ip,:), meanctrs(ip,:), meanwctrs(ip,:), areas(ip), nvals(ip), xvals(ip), & 120 mvals(ip), m2vals(ip), stdvals(ip), Nquant, quants(ip,:), nvcoords(ip,:), xvcoords(ip,:), & 121 meanvnctrs(ip,:), meanvxctrs(ip,:)) 105 122 END DO 106 123 … … 109 126 END SUBROUTINE all_polygons_properties 110 127 111 SUBROUTINE polygon_properties(dx, dy, poly, lon, lat, values, xres, yres, projN, Npolypts, xxtrm, & 112 yxtrm, meanctr, area, nval, xval, mval, m2val, stdval, Nquant, quant) 128 SUBROUTINE polygon_properties(dbg, dx, dy, poly, lon, lat, values, xres, yres, projN, Npolypts, & 129 xxtrm, yxtrm, meanctr, meanwctr, area, nval, xval, mval, m2val, stdval, Nquant, quant, nvcoord, & 130 xvcoord, meanvnctr, meanvxctr) 113 131 ! Subroutine to determine the properties of a polygon (as .TRUE. matrix) 114 132 ! Number of grid points 115 133 ! grid-point coordinates of the minimum and maximum of the path along x,y axes 116 ! center from the mean of the coordinates of the paths locations 134 ! grid coordinates of center from the mean of the coordinates of the poygon locations 135 ! lon, lat center from the area weighted mean of the coordinates of the polygon locations 117 136 ! area of the polygon (km2) 118 137 ! minimum and maximum of the values within the polygon … … 122 141 ! number of quantiles 123 142 ! quantiles of the values within the polygon 143 ! grid coordinates of the minimum, maximum value within the polygon 144 ! lon, lat coordinates of the area center weighted and also by distance to the lowest or highest values of the polygon 124 145 125 146 IMPLICIT NONE 126 147 148 LOGICAL, INTENT(in) :: dbg 127 149 INTEGER, INTENT(in) :: dx, dy, Nquant 128 150 LOGICAL, DIMENSION(dx,dy), INTENT(in) :: poly 129 151 REAL(r_k), DIMENSION(dx,dy), INTENT(in) :: lon, lat, values 130 152 REAL(r_k), INTENT(in) :: xres, yres 131 CHARACTER(len= 50), INTENT(in):: projN153 CHARACTER(len=1000), INTENT(in) :: projN 132 154 INTEGER, INTENT(out) :: Npolypts 133 155 INTEGER, DIMENSION(2), INTENT(out) :: xxtrm, yxtrm, meanctr 156 INTEGER, DIMENSION(2), INTENT(out) :: nvcoord, xvcoord 157 REAL(r_k), DIMENSION(2), INTENT(out) :: meanwctr, meanvnctr, meanvxctr 134 158 REAL(r_k), INTENT(out) :: area 135 159 REAL(r_k), INTENT(out) :: nval, xval, mval, m2val, stdval … … 140 164 INTEGER :: ierr 141 165 INTEGER, DIMENSION(:,:), ALLOCATABLE :: polypts 142 REAL(r_k), DIMENSION(:), ALLOCATABLE :: polyvals 166 REAL(r_k), DIMENSION(:), ALLOCATABLE :: polyvals, distvn, distvx 167 REAL(r_k) :: lonNADIR, latNADIR 168 REAL(r_k) :: sumRESx, sumRESy 169 REAL(r_k), DIMENSION(dx,dy) :: xcorr, ycorr 170 CHARACTER(len=200), DIMENSION(3) :: satSvals 171 CHARACTER(len=50) :: projS 172 REAL(r_k) :: sumDISTnlon, sumDISTnlat, sumDISTxlon, & 173 sumDISTxlat 143 174 144 175 !!!!!!! Variables … … 149 180 ! [x/y]res resolution along the x and y axis 150 181 ! projN: name of the projection 182 ! 'ctsarea': Constant Area 151 183 ! 'lon/lat': for regular longitude-latitude 184 ! 'nadir-sat,[lonNADIR],[latNADIR]': for satellite data with the resolution given at nadir (lonNADIR, latNADIR) 152 185 ! Npolypts: number of points of the polygon 153 186 ! [x/y]xtrm: grid-point coordinates of minimum and maximum coordinates of the polygon 154 187 ! meanctr: center from the mean of the coordinates of the polygon 188 ! meanwctr: lon, lat coordinates of the center from the spatial-weighted mean of the polygon 155 189 ! area: area of the polygon [km] 156 190 ! [n/x]val: minimum and maximum of the values within the polygon … … 159 193 ! stdval: standard deviation of the values within the polygon 160 194 ! Nquant: number of quantiles 161 ! quant: quantiles of the values within the polygon 195 ! quant: quantiles of the values within the polygon 196 ! [n/x]vcoord: grid coordinates of the minimum/maximum of the values within the polygon 197 ! meanv[n/x]ctr: lon, lat coordinates of the area center weighted and also by distance to the lowest or highest values of the polygon 162 198 163 199 fname = 'polygon_properties' 200 201 IF (dbg) PRINT *," '" // TRIM(fname) // "' ..." 164 202 165 203 ! Getting grid-point coordinates of the polygon … … 176 214 CALL ErrMsg(msg, fname, ierr) 177 215 216 IF (ALLOCATED(distvn)) DEALLOCATE(distvn) 217 ALLOCATE(distvn(Npolypts), STAT=ierr) 218 msg = "Problems allocating 'distvn'" 219 CALL ErrMsg(msg, fname, ierr) 220 221 IF (ALLOCATED(distvx)) DEALLOCATE(distvx) 222 ALLOCATE(distvx(Npolypts), STAT=ierr) 223 msg = "Problems allocating 'distvx'" 224 CALL ErrMsg(msg, fname, ierr) 225 226 IF (projN(1:7) == 'lon/lat') THEN 227 projS = projN 228 ELSE IF (projN(1:7) == 'ctsarea') THEN 229 projS = projN 230 ELSE IF (projN(1:9) == 'nadir-sat') THEN 231 projS = 'nadir-sat' 232 CALL split(projN, ',', 3, satSvals) 233 READ(satSvals(2),'(F200.100)')lonNadir 234 READ(satSvals(3),'(F200.100)')latNadir 235 IF (dbg) PRINT *," 'nadir-geostationary-satellite' based projection of data with nadir " // & 236 "location at:", lonNadir, latNadir 237 ELSE 238 msg = "Projection '" // TRIM(projN) // "' not ready" // CHAR(10) // " available ones: " // & 239 "'ctsarea', 'lon/lat', 'nadir-sat'" 240 CALL ErrMsg(msg,fname,-1) 241 END IF 242 243 area = 0. 244 sumRESx = 0. 245 sumRESy = 0. 246 meanwctr = 0. 247 meanvnctr = 0. 248 meanvxctr = 0. 249 250 nval = fillval64 251 xval = -fillval64 252 178 253 ip = 1 179 area = 0.180 254 DO i=1,dx 181 255 DO j=1,dy … … 183 257 polypts(ip,:) = (/ i,j /) 184 258 polyvals(ip) = values(i,j) 185 SELECT CASE (TRIM(projN)) 259 SELECT CASE (TRIM(projS)) 260 CASE ('ctsarea') 261 ! Constant Area 262 xcorr(i,j) = 1. 263 ycorr(i,j) = 1. 186 264 CASE ('lon/lat') 187 265 ! Area as fixed yres and sinus-lat varying for xres 188 area = area + xres*DABS(DSIN(lon(i,j)*DegRad))*yres 189 CASE DEFAULT 190 msg = "Projection '" // TRIM(projN) // "' not ready" // CHAR(10) // & 191 " available ones: 'lon/lat'" 266 xcorr(i,j) = DABS(DSIN(lon(i,j)*DegRad)) 267 ycorr(i,j) = 1. 268 CASE ('nadir-sat') 269 ! Area from nadir resolution and degrading as we get far from satellite's nadir 270 ! GOES-E: 0 N, 75 W 271 xcorr(i,j) = DABS(DSIN(lon(i,j)*DegRad)) 272 ycorr(i,j) = 1. 192 273 END SELECT 274 area = area + xres*xcorr(i,j)*yres*ycorr(i,j) 275 meanwctr(1) = meanwctr(1) + lon(i,j)*xres*xcorr(i,j) 276 meanwctr(2) = meanwctr(2) + lat(i,j)*yres*ycorr(i,j) 277 IF (nval > values(i,j)) THEN 278 nvcoord(1) = i 279 nvcoord(2) = j 280 nval = values(i,j) 281 END IF 282 IF (xval < values(i,j)) THEN 283 xvcoord(1) = i 284 xvcoord(2) = j 285 xval = values(i,j) 286 END IF 193 287 ip = ip + 1 194 288 END IF 195 289 END DO 196 290 END DO 291 292 IF (dbg) THEN 293 PRINT *,' Values: ', polyvals 294 END IF 295 296 sumRESx = xres*SUM(xcorr) 297 sumRESy = yres*SUM(ycorr) 197 298 198 299 xxtrm = (/ MINVAL(polypts(:,1)), MAXVAL(polypts(:,1)) /) 199 300 yxtrm = (/ MINVAL(polypts(:,2)), MAXVAL(polypts(:,2)) /) 200 301 meanctr = (/ SUM(polypts(:,1))/Npolypts, SUM(polypts(:,2))/Npolypts /) 201 302 meanwctr = (/ meanwctr(1)/sumRESx, meanwctr(2)/sumRESy /) 303 304 IF (dbg) THEN 305 PRINT *,' mean grid center: ', meanctr, ' weighted mean center: ', meanwctr 306 END IF 307 202 308 ! Statistics of the values within the polygon 203 309 CALL StatsR_K(Npolypts, polyvals, nval, xval, mval, m2val, stdval) 310 311 IF (dbg) THEN 312 PRINT *,' minimum value: ', nval, ' maximum:', xval, ' mean:', mval 313 PRINT *,' coor. minimum: ', nvcoord 314 PRINT *,' coor. maximum: ', xvcoord 315 END IF 316 317 ! Mean center weighted to minimum and maximum values 318 distvn = DABS(polyvals - nval) 319 distvx = DABS(polyvals - xval) 320 321 meanvnctr = 0. 322 meanvxctr = 0. 323 sumDISTnlon = 0. 324 sumDISTnlat = 0. 325 sumDISTxlon = 0. 326 sumDISTxlat = 0. 327 328 ip = 1 329 DO i=1,dx 330 DO j=1,dy 331 IF (poly(i,j)) THEN 332 meanvnctr(1) = meanvnctr(1)+lon(i,j)*distvn(ip)*xres*xcorr(i,j) 333 meanvnctr(2) = meanvnctr(2)+lat(i,j)*distvn(ip)*yres*ycorr(i,j) 334 335 meanvxctr(1) = meanvxctr(1)+lon(i,j)*distvx(ip)*xres*xcorr(i,j) 336 meanvxctr(2) = meanvxctr(2)+lat(i,j)*distvx(ip)*yres*ycorr(i,j) 337 338 sumDISTnlon = sumDISTnlon + lon(i,j)*distvn(ip)*xres*xcorr(i,j) 339 sumDISTnlat = sumDISTnlat + lat(i,j)*distvn(ip)*yres*ycorr(i,j) 340 sumDISTxlon = sumDISTxlon + lon(i,j)*distvx(ip)*xres*xcorr(i,j) 341 sumDISTxlat = sumDISTxlat + lat(i,j)*distvx(ip)*yres*ycorr(i,j) 342 343 ip = ip + 1 344 END IF 345 END DO 346 END DO 347 348 meanvnctr = (/ meanvnctr(1)/sumDISTnlon, meanvnctr(2)/sumDISTnlat /) 349 meanvxctr = (/ meanvxctr(1)/sumDISTxlon, meanvxctr(2)/sumDISTxlat /) 350 351 IF (dbg) THEN 352 PRINT *,' mean center to minimum: ', meanvnctr, ' to maximum: ', meanvxctr 353 END IF 204 354 205 355 ! Quantiles of the values within the polygon
Note: See TracChangeset
for help on using the changeset viewer.