I am writing a C # program that uses the Microsoft Scientific Data-Set to read NetCDF files.
using System; using System.IO; using sds = Microsoft.Research.Science.Data; using Microsoft.Research.Science.Data.Imperative; namespace NetCDFConsoleApp { class Program { static void Main(string[] args) {
Files contain predicted precipitation data on a map grid (X, Y). Each grid link must contain data for 85 hours.
E:\temp>sds list test.nc [2] ACPR of type Single (Time:85) (south_north:213) (west_east:165) [1] Times of type SByte (Time:85) (DateStrLen:19)
But sometimes they may have less (say 60-70 hours). When this happens, my C # programs do not work when importing data.
var dataset = sds.DataSet.Open("test.nc?openMode=readOnly"); Single[,,] dataValues = dataset.GetData<Single[,,]>("ACPR");
I can reproduce the error on the command line.
Here I can successfully extract the clock 60-65 for Grid XY: 125 130. The last value that I have in this file is Time = 69.
E:\temp>sds data test.nc ACPR[60:65,125:125,130:130] [2] ACPR of type Single (Time:85) (south_north:213) (west_east:165) Name = ACPR description = ACCUMULATED TOTAL GRID SCALE PRECIPITATION MemoryOrder = XY coordinates = XLONG XLAT XTIME stagger = FieldType = 104 units = mm [60,125,130] 13.4926 [61,125,130] 15.24556 [62,125,130] 16.3638 [63,125,130] 17.39618 [64,125,130] 20.00507 [65,125,130] 23.57192
If I try to read past hour 69, I get the following error.
E:\temp>sds data test.nc ACPR[60:70,125:125,130:130] [2] ACPR of type Single (Time:85) (south_north:213) (west_east:165) Name = ACPR description = ACCUMULATED TOTAL GRID SCALE PRECIPITATION MemoryOrder = XY coordinates = XLONG XLAT XTIME stagger = FieldType = 104 units = mm Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at nc_get_vara_float(Int32 , Int32 , UInt64* , UInt64* , Single* ) at NetCDFInterop.NetCDF.nc_get_vara_float(Int32 ncid, Int32 varid, IntPtr[] start, IntPtr[] count, Single[] data) at Microsoft.Research.Science.Data.NetCDF4.NetCdfVariable`1.ReadData(Int32[] origin, Int32[] shape) at sdsutil.Program.PrintData(Variable v, String range, String format) at sdsutil.Program.DoData(String uri, String[] args) at sdsutil.Program.Main(String[] args) E:\temp>
If the file contains all 85 hours, I can request Time 0-100, and it still gives me 85 values ββwithout errors.
I am convinced that this problem is NULL / missing data. Is there a way I can specify when importing data where the variable is not null? or use some type of try / catch?
Single[,,] dataValues = dataset.GetData<Single[,,]>("ACPR")>> where it not blank thanks. ;
Edit: I am starting to suspect that the file is not formed correctly. Using the SDS Viewer The meta data for a good file and a bad one look like this:


However, on the command line, metadata is the same for both.
E:\temp>sds good.nc [2] ACPR of type Single (Time:85) (south_north:213) (west_east:165) [1] Times of type SByte (Time:85) (DateStrLen:19) E:\temp>sds bad.nc [2] ACPR of type Single (Time:85) (south_north:213) (west_east:165) [1] Times of type SByte (Time:85) (DateStrLen:19) E:\temp>