<div dir="ltr"><div>Giorgio, I think you are right, there may be something wrong with the way the Netcdf file is created.  Your link pointed to "Write Data to NetCDF File Using Low-Level Functions".  Try using the Matlab high-level Netcdf export functions instead, such as <b>ncwrite</b>.  Those do a better job of preserving dimensions and data alignment.</div><div><br></div><div>It will be more constructive to debug your Matlab export process, than to try to manipulate a damaged data file.  Check your work by comparing dimensions and data alignment with Matlab and Netcdf diagnostic functions.  Dimensions before and after export should match exactly.  Data samples at the same indices should match exactly.  I find that NCL is convenient for examining small data samples, such as:</div><div><br></div><div>    print (temp(24089,20,0:3))</div><div><br></div><div>Matlab has something similar.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 15, 2023 at 5:47 AM Giorgio Graffino via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><p><span style="font-family:Arial;font-size:12pt">Dear NCL experts,</span></p><p> </p><p><span style="font-family:Arial;font-size:12pt">Hope you're all well. As per the subject, I want to read a .mat file containing daily SST data from 1940 to 2005 and run some analysis I've already written in NCL. If I try to directly read the file with NCL I get Segmentation fault, so that's not the right way to go. I converted the file into NetCDF using Matlab (<a href="https://uk.mathworks.com/help/matlab/import_export/exporting-to-network-common-data-form-netcdf-files.html?s_tid=answers_rc2-3_p6_MLT#bsxb70y-1" target="_blank">https://uk.mathworks.com/help/matlab/import_export/exporting-to-network-common-data-form-netcdf-files.html?s_tid=answers_rc2-3_p6_MLT#bsxb70y-1</a>), but there is a problem with the data. </span></p><p> </p><p><span style="font-family:Arial;font-size:12pt">At some point in the time series (around 1962), the data get shifted in the longitude sense by about 40 degrees. I checked this in NCL and in Ferret, as shown in the attached screenshot: the left-hand side is SST on a random day before 1962, while the right-hand side is after 1962. It's like there is an offset in the data longitudes. The plots are drawn using only four lines in Ferret, so the error can't be due to the the software. There must be something wrong going on when the file is created. It would be great to know what happens to the data in the first place, but maybe it's a discussion that doesn't belong here.</span></p><p> </p><p><span style="font-family:Arial;font-size:12pt">This is the printVarSummary of the full data. The longitudes array does not change over time, but the data are shifted.</span></p><p> </p><p><span style="font-family:Arial;font-size:12pt">Variable: temp</span><br><span style="font-family:Arial;font-size:12pt">Type: float</span><br><span style="font-family:Arial;font-size:12pt">Total Size: 710269560 bytes</span><br><span style="font-family:Arial;font-size:12pt">           177567390 values</span><br><span style="font-family:Arial;font-size:12pt">Number of Dimensions: 3</span><br><span style="font-family:Arial;font-size:12pt">Dimensions and sizes:   [time | 24090] x [lats | 120] x [lons | 180]</span><br><span style="font-family:Arial;font-size:12pt">Coordinates: </span><br><span style="font-family:Arial;font-size:12pt">           time: [350616..929160]</span><br><span style="font-family:Arial;font-size:12pt">           lats: [ -90..88.5]</span><br><span style="font-family:Arial;font-size:12pt">           lons: [   0.. 358]</span><br><span style="font-family:Arial;font-size:12pt">Number Of Attributes: 1</span><br><span style="font-family:Arial;font-size:12pt"> _FillValue :  -9e+33</span><br> </p><p><span style="font-family:Arial;font-size:12pt">I'd like to know how I can correct the second part of the time series to make it like the first part. I tried with LonFlip and LonPivot but I couldn't make it work. I'm thinking about a way to shift the data back by that longitude offset, but I can't wrap my head around it.</span></p><p> </p><p><span style="font-family:Arial;font-size:12pt">Please let me know.</span></p><p> <span style="font-family:Arial;font-size:12pt">Cheers,</span></p><p><span style="font-family:Arial;font-size:12pt">Giorgio</span></p>
</blockquote></div></div>