title: How to change longitude range in a NetCDF
body: <p>My NetCDF file has 4 dimensions (longitude, latitude, time, level pressure) and several variables. </p>
  
  <p>I want to replace the longitude data which is [340 342 344 ... 360 0 2 4 ... 18 20] by [-20 -18 -16 ... -2 0 2 4 ... 18 20]. In fact the longitude is counted from 0° to 360° but I need to have it from -180° to 180°.</p>
  
  <p>I have found some ideas on Internet but I don't know how to apply them.</p>
  
  <p>Here an explanation: </p>
  
  <p>"Some netcdf files contain strictly positive values [0,360] which are not compatible with the way gdal/QGis treat longitude values - they do not wrap around the dateline. This also causes errors with gdalwarp and when combined with other datasets (with [-180,180] values), they are not aligned properly due to a 180 degree longitude shift.</p>
  
  <p>Simple fix is to test for longitude variables and convert any values in the [180,360] interval to [-180,180] by subtracting 180 - in IReadBlock and also in SRS detection."</p>
  
  <p>I also read about "gdal-translate" but I don't know how to use it.</p>
  
  <p>Edit: I also had a problem with the latitude which was N -> S (I wanted it S -> N) and I reversed it thanks to "cdo invertlat"</p>