My NetCDF file has 4 dimensions (longitude, latitude, time, level pressure) and several variables.
I want to replace the longitude data which is [340 342 344 ... 36
I realise this is an old thread, but as I had a very similar problem recently I thought I'd add my solution as I didn't manage to find it elsewhere...
I used the cdo package (https://code.zmaw.de/projects/cdo) command sellonlatbox to translate my input data from [0, 360) longitude range to be [-180, 180), and also reorder latitudes to be [-90, 90] (i.e. S -> N):
cdo sellonlatbox,-180,180,-90,90 infile.nc outfile.nc