{"action":"created","issue":{"url":"https://api.github.com/repos/Unidata/thredds/issues/340","labels_url":"https://api.github.com/repos/Unidata/thredds/issues/340/labels{/name}","comments_url":"https://api.github.com/repos/Unidata/thredds/issues/340/comments","events_url":"https://api.github.com/repos/Unidata/thredds/issues/340/events","html_url":"https://github.com/Unidata/thredds/issues/340","id":123689797,"number":340,"title":"Out of range Lon normalized incorrectly for grib file.","user":{"login":"rgaskill","id":1427914,"avatar_url":"https://avatars.githubusercontent.com/u/1427914?v=3","gravatar_id":"","url":"https://api.github.com/users/rgaskill","html_url":"https://github.com/rgaskill","followers_url":"https://api.github.com/users/rgaskill/followers","following_url":"https://api.github.com/users/rgaskill/following{/other_user}","gists_url":"https://api.github.com/users/rgaskill/gists{/gist_id}","starred_url":"https://api.github.com/users/rgaskill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgaskill/subscriptions","organizations_url":"https://api.github.com/users/rgaskill/orgs","repos_url":"https://api.github.com/users/rgaskill/repos","events_url":"https://api.github.com/users/rgaskill/events{/privacy}","received_events_url":"https://api.github.com/users/rgaskill/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Unidata/thredds/labels/CDM","name":"CDM","color":"e11d21"},{"url":"https://api.github.com/repos/Unidata/thredds/labels/Coordinate%20Systems","name":"Coordinate Systems","color":"009800"},{"url":"https://api.github.com/repos/Unidata/thredds/labels/GRIB","name":"GRIB","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Unidata/thredds/milestones/1","html_url":"https://github.com/Unidata/thredds/milestones/Final%20push%20for%20new%20features%20on%20the%204.x%20branch","labels_url":"https://api.github.com/repos/Unidata/thredds/milestones/1/labels","id":1277907,"number":1,"title":"Final push for new features on the 4.x branch","description":"This is the last planned release of the 4 branch to include new features. >=4.7.1 will be bug fixes only. Note that starting with version 5, the THREDDS group will begin using [semantic versioning](http://semver.org/) for releases.","creator":{"login":"lesserwhirls","id":67096,"avatar_url":"https://avatars.githubusercontent.com/u/67096?v=3","gravatar_id":"","url":"https://api.github.com/users/lesserwhirls","html_url":"https://github.com/lesserwhirls","followers_url":"https://api.github.com/users/lesserwhirls/followers","following_url":"https://api.github.com/users/lesserwhirls/following{/other_user}","gists_url":"https://api.github.com/users/lesserwhirls/gists{/gist_id}","starred_url":"https://api.github.com/users/lesserwhirls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lesserwhirls/subscriptions","organizations_url":"https://api.github.com/users/lesserwhirls/orgs","repos_url":"https://api.github.com/users/lesserwhirls/repos","events_url":"https://api.github.com/users/lesserwhirls/events{/privacy}","received_events_url":"https://api.github.com/users/lesserwhirls/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":10,"state":"open","created_at":"2015-08-28T16:39:01Z","updated_at":"2016-01-06T16:38:23Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2015-12-23T16:46:52Z","updated_at":"2016-01-25T21:33:24Z","closed_at":null,"body":"Outputting the stats of the file in question with wgrib I get the following:\r\n\r\n```\r\nrec 1:0:date 2015120900 TMPA kpds5=25 kpds6=105 kpds7=2 levels=(0,2) grid=211 2 m above gnd valid 30-30d: bitmap: 55047 undef\r\n  TMPA=Temp. anomaly [K]\r\n  timerange 2 P1 30 P2 30 TimeU 2  nx 360 ny 179 GDS grid 0 num_in_ave 0 missing 0\r\n  center 250 subcenter 1 process 255 Table 2 scan: WE:SN winds(grid) \r\n  latlon: lat  -89.001000 to 88.998000 by 0.000000  nxny 64440\r\n          long -180.000000 to 179.000000 by 0.000000, (360 x 179) scan 64 mode 8 bdsgrid 1\r\n  min/max data -0.7 3.7  num bits 6  BDS_Ref -7  DecScale 1 BinScale 0\r\n```\r\n\r\nbut when I read in the same file via GridDataset (`GridDataset gridDataset = GridDataset.open(filename);`) the lon range is wrong.\r\n\r\n```\r\nlat -> min: -89.00100708007812 max: 88.99800872802734\r\nlon -> min: 179.99998474121094 max: 539.0\r\n```\r\n\r\nI tracked the issue down to [this](https://github.com/Unidata/thredds/blob/5612f5ff64823b8bd36513887236df48748c4290/cdm/src/main/java/ucar/unidata/geoloc/LatLonPointImpl.java#L121)\r\n\r\n```\r\n  static public double lonNormal(double lon) {\r\n    if ((lon < -180.) || (lon > 180.)) {\r\n      return Math.IEEEremainder(lon, 360.0);\r\n    } else {\r\n      return lon;\r\n    }\r\n  }\r\n```\r\n\r\nWhich normalizes the value `-180.00001525878906` to the positive value of  `179.99998474121094`.\r\n\r\nI just naively updated the `lonNormal` function to:\r\n\r\n```\r\nstatic public double lonNormal(double lon) {\r\n    if (lon < -180.) {\r\n      return -180.;\r\n    } else if (lon > 180.) {\r\n      return 180.;\r\n    } else {\r\n      return lon;\r\n    }\r\n  }\r\n```\r\n\r\nWhich is similar to what `latNormal` does, but this breaks a number of tests.  So I think I may be fixing this in the wrong place.  "},"comment":{"url":"https://api.github.com/repos/Unidata/thredds/issues/comments/174672381","html_url":"https://github.com/Unidata/thredds/issues/340#issuecomment-174672381","issue_url":"https://api.github.com/repos/Unidata/thredds/issues/340","id":174672381,"user":{"login":"JohnLCaron","id":613568,"avatar_url":"https://avatars.githubusercontent.com/u/613568?v=3","gravatar_id":"","url":"https://api.github.com/users/JohnLCaron","html_url":"https://github.com/JohnLCaron","followers_url":"https://api.github.com/users/JohnLCaron/followers","following_url":"https://api.github.com/users/JohnLCaron/following{/other_user}","gists_url":"https://api.github.com/users/JohnLCaron/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnLCaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnLCaron/subscriptions","organizations_url":"https://api.github.com/users/JohnLCaron/orgs","repos_url":"https://api.github.com/users/JohnLCaron/repos","events_url":"https://api.github.com/users/JohnLCaron/events{/privacy}","received_events_url":"https://api.github.com/users/JohnLCaron/received_events","type":"User","site_admin":false},"created_at":"2016-01-25T21:33:24Z","updated_at":"2016-01-25T21:33:24Z","body":"Possibly we could change to double precision for the internal params. Or skip normalization. Probably dont want BigDecimal, i would assume too slow.\r\n\r\nBut we really need a sample record to make much progress."}}