wrf-model/WPS

Ungrib not scaling negative starting latitudes

mgduda opened this issue · 6 comments

Typically, the starting latitude in a GRIB grid definition section is scaled by 1e6, and the ungrib code divides by this scaling factor. However, if the starting latitude is negative, no division by the scaling factor takes place in ungrib. For a discussion of this issue, see this forum post.

One fix that appears to work (see the forum post) is to change this code:

              ! Scale lat/lon values to 0-180, default range is 1e6.
              if (map%lat1.ge.scale_factor) then
                 map%lat1 = map%lat1/scale_factor
              endif

around line 494 of rd_grib2.F to this:

              ! Scale lat/lon values to 0-180, default range is 1e6.
              if (abs(map%lat1).ge.scale_factor) then
                 map%lat1 = map%lat1/scale_factor
              endif

@jimbresch Does the fix proposed here seem reasonable to you? If so, I'll create a PR to be included in the v4.2 release on Thursday.

@mgduda
Michael,
The abs() mod will work for GRIB data with < 1 million latitude points (plenty of room for data sets to get much larger). This seems like a simple fix that should not impact the existing positive lat1 values.

@davegill Why would this work only for datasets with < 1 M latitude points?

@mgduda
Here's what I was thinking: If the scale factor is about 1e3, and we have 1e6 grid points between the equator and the pole, and the lat1 point is just north of the equator, lat1 * scale_factor < scale_factor.

However, if these corner grid values are scaled so that they are always integers (which is probably what happens in the GRIB code), I guess that the scale factor will just get larger with the resolution.

The merge of PR #145 resolves this issue.