public Int32 GetAttLength() { Int32 lenp = 0; NcCheck.Check(NetCDF.nc_inq_attlen(groupId, varId, myName, ref lenp)); return(lenp); }
public static DateTime ImportDateTime(string inputNcFile) { DateTime dt = DateTime.Now; int ncid = 0, varid = 0; CorrectFilePath(ref inputNcFile); if (File.Exists(inputNcFile)) { try { NetCDF.nc_open(inputNcFile, NetCDF.CreateMode.NC_NOWRITE, out ncid); NetCDF.nc_inq_varid(ncid, "time", out varid); // Days since 1800-01-01 long[] daysElapsed = new long[1]; NetCDF.nc_get_var_long(ncid, varid, daysElapsed); dt = new DateTime(1800, 1, 1, 0, 0, 0); dt = dt.AddDays(daysElapsed[0]); } catch (Exception ex) { string s = ex.Message; } finally { NetCDF.nc_close(ncid); } } return(dt); }
private void ReadNetCDFFile(string filename) { int result = OpenNetCDFFile(filename); if (result == 0) { int dimlen = 0; result = NetCDF.nc_inq_dimlen(_ncid, 0, ref dimlen); if (result == 0) { positions = new int[dimlen]; result = NetCDF.nc_get_var_int(_ncid, 0, positions); daynum = new float[dimlen]; result = NetCDF.nc_get_var_float(_ncid, 1, daynum); m_DataSize = 0; result = NetCDF.nc_inq_dimlen(_ncid, 1, ref m_DataSize); } } if (result != 0) { positions = null; } int closeresult = NetCDF.nc_close(_ncid); }
public async Task <IActionResult> Edit(int id, [Bind("Id,GaseId,Date,Name,Unit,Longtitude,Latitude,Value")] NetCDF netCDF) { if (id != netCDF.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(netCDF); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NetCDFExists(netCDF.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["GaseId"] = new SelectList(_context.Gase.Where(g => g.Id != 4), "Id", "Formula", netCDF.GaseId); //not show NO2 return(View(netCDF)); }
public int GetNumVariables() { int size; NetCDF.nc_inq_nvars(_fileID, out size); return(size); }
public Int32 GetTypeSize() { byte[] buffer = null; Int32 sizep = 0; NcCheck.Check(NetCDF.nc_inq_opaque(groupId, myId, buffer, ref sizep)); return(sizep); }
public Int32 GetSize() { CheckNull(); Int32 dimSize = 0; NcCheck.Check(NetCDF.nc_inq_dimlen(groupId, myId, ref dimSize)); return(dimSize); }
public string GetName() { CheckNull(); StringBuilder dimName = new StringBuilder((int)NetCDF.netCDF_limits.NC_MAX_NAME); NcCheck.Check(NetCDF.nc_inq_dimname(groupId, myId, dimName)); return(dimName.ToString()); }
public string GetName() { StringBuilder charName = new StringBuilder((int)NetCDF.netCDF_limits.NC_MAX_NAME); Int32 sizep = 0; NcCheck.Check(NetCDF.nc_inq_type(groupId, myId, charName, ref sizep)); return(charName.ToString()); }
public Int32 GetMemberCount() { byte[] buffer = null; Int32 base_nc_typep = 0; Int32 base_sizep = 0; Int32 num_membersp = 0; NcCheck.Check(NetCDF.nc_inq_enum(groupId, myId, buffer, ref base_nc_typep, ref base_sizep, ref num_membersp)); return(num_membersp); }
public void GetValues(double[] dataValues, bool strictChecking = true) { CheckNull(); if (strictChecking) { CheckAttLen(dataValues.Length); } CheckFixedType(); NcCheck.Check(NetCDF.nc_get_att_double(groupId, varId, myName, dataValues)); }
public string GetValues() { CheckNull(); ASCIIEncoding encoder = new ASCIIEncoding(); int attLen = GetAttLength(); byte[] buffer = new byte[attLen]; NcCheck.Check(NetCDF.nc_get_att_text(groupId, varId, myName, buffer)); return(encoder.GetString(buffer)); }
public string GetMemberNameFromValue(sbyte memberValue) { byte[] nameBuffer = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME + 1]; ASCIIEncoding encoder = new ASCIIEncoding(); NcCheck.Check(NetCDF.nc_inq_enum_ident(groupId, myId, (Int64)memberValue, nameBuffer)); string buf = encoder.GetString(nameBuffer); return(buf.Substring(0, buf.IndexOf('\0'))); }
public void Open() { Debug.Assert(_numOpenFiles == 0, "Another NetCDF file is still open!"); NetCDF.ResultCode result = NetCDF.nc_open(_fileDirectory, NetCDF.CreateMode.NC_NOWRITE, out _fileID); Debug.Assert(result == NetCDF.ResultCode.NC_NOERR, result.ToString()); result = NetCDF.nc_inq_nvars(_fileID, out _numVars); Debug.Assert(result == NetCDF.ResultCode.NC_NOERR, result.ToString()); _numOpenFiles++; }
private int OpenNetCDFFile(string filename) { //should return 0 if successfull string netcdf_file = Path.ChangeExtension(filename, ".nc"); if (!File.Exists(netcdf_file)) { return(-1); } return(NetCDF.nc_open(netcdf_file, NetCDF.cmode.NC_NOWRITE.GetHashCode(), ref _ncid)); }
// Constructor for an existing global attr public NcGroupAtt(NcGroup grp, int index) : base(false) { ASCIIEncoding encoder = new ASCIIEncoding(); groupId = grp.GetId(); varId = NC_GLOBAL; byte[] buffer = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME]; NcCheck.Check(NetCDF.nc_inq_attname(groupId, varId, index, buffer)); string sbuffer = encoder.GetString(buffer); myName = sbuffer.Substring(0, sbuffer.IndexOf('\0')); // A null-terminated C-string }
public NcVarAtt(Int32 groupId, Int32 varId, Int32 index) : base(false) { ASCIIEncoding encoder = new ASCIIEncoding(); this.groupId = groupId; this.varId = varId; byte[] buffer = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME]; NcCheck.Check(NetCDF.nc_inq_attname(groupId, varId, index, buffer)); string sbuffer = encoder.GetString(buffer); myName = sbuffer.Substring(0, sbuffer.IndexOf('\0')); // A null-terminated C-string }
/// <summary> /// Display variable names in the console. /// </summary> public void DisplayContent() { StringBuilder name = new StringBuilder(null); int nDims; for (int i = 0; i < _numVars; ++i) { NetCDF.nc_inq_varname(_fileID, i, name); NetCDF.nc_inq_varndims(_fileID, i, out nDims); Console.Out.WriteLine("Var " + i + ":\t" + name + ",\tNumDims: " + nDims); name = new StringBuilder(null); } }
public SliceRange(LoaderNCF file, RedSea.Variable var) : base() { // Query number of dimensions of variable. int numDims; NetCDF.ResultCode ncState = NetCDF.nc_inq_varndims(file.GetID(), (int)var, out numDims); Debug.Assert(ncState == NetCDF.ResultCode.NC_NOERR); int[] dimIDs = new int[numDims]; // Query relevant dimensions. ncState = NetCDF.nc_inq_vardimid(file.GetID(), (int)var, dimIDs); Debug.Assert(ncState == NetCDF.ResultCode.NC_NOERR); Initialize(dimIDs, var); }
public NcTypeEnum GetTypeClass() { switch (myId) { case (int)NcTypeEnum.NC_BYTE: return(NcTypeEnum.NC_BYTE); case (int)NcTypeEnum.NC_UBYTE: return(NcTypeEnum.NC_UBYTE); case (int)NcTypeEnum.NC_CHAR: return(NcTypeEnum.NC_CHAR); case (int)NcTypeEnum.NC_SHORT: return(NcTypeEnum.NC_SHORT); case (int)NcTypeEnum.NC_USHORT: return(NcTypeEnum.NC_USHORT); case (int)NcTypeEnum.NC_INT: return(NcTypeEnum.NC_INT); case (int)NcTypeEnum.NC_UINT: return(NcTypeEnum.NC_UINT); case (int)NcTypeEnum.NC_INT64: return(NcTypeEnum.NC_INT64); case (int)NcTypeEnum.NC_UINT64: return(NcTypeEnum.NC_UINT64); case (int)NcTypeEnum.NC_FLOAT: return(NcTypeEnum.NC_FLOAT); case (int)NcTypeEnum.NC_DOUBLE: return(NcTypeEnum.NC_DOUBLE); case (int)NcTypeEnum.NC_STRING: return(NcTypeEnum.NC_STRING); case (int)NcTypeEnum.NC_VLEN: return(NcTypeEnum.NC_VLEN); case (int)NcTypeEnum.NC_OPAQUE: return(NcTypeEnum.NC_OPAQUE); case (int)NcTypeEnum.NC_ENUM: return(NcTypeEnum.NC_ENUM); case (int)NcTypeEnum.NC_COMPOUND: return(NcTypeEnum.NC_COMPOUND); default: break; } byte[] readBuffer = null; Int32 sizep = 0; Int32 base_nc_typep = 0; Int32 nfieldsp = 0; Int32 classp = 0; NcCheck.Check(NetCDF.nc_inq_user_type(groupId, myId, readBuffer, ref sizep, ref base_nc_typep, ref nfieldsp, ref classp)); return((NcTypeEnum)classp); }
public bool IsUnlimited() { CheckNull(); Int32 numlimdims = 0; Int32[] unlimdimidsp = null; NcCheck.Check(NetCDF.nc_inq_unlimdims(groupId, ref numlimdims, unlimdimidsp)); unlimdimidsp = new Int32[numlimdims]; NcCheck.Check(NetCDF.nc_inq_unlimdims(groupId, ref numlimdims, unlimdimidsp)); for (int i = 0; i < numlimdims; i++) { if (unlimdimidsp[i] == myId) { return(true); } } return(false); }
private T[] GetData <T>(string path, string variable, int levelCount, int levelIdx) { int ncid = 0, varid = 0; if (File.Exists(path)) { try { Console.WriteLine($"Reading data from: {Path.GetFileName(path)}, variable: {variable}, level {levelIdx} of {levelCount} "); NetCDF.nc_open(path, NetCDF.CreateMode.NC_NOWRITE, out ncid); NetCDF.nc_inq_varid(ncid, variable, out varid); if (typeof(T) == typeof(float)) { float[] data = new float[levelCount * EH * EW]; float[] levelData = new float[EH * EW]; NetCDF.nc_get_var_float(ncid, varid, data); Array.Copy(data, levelIdx * EH * EW, levelData, 0, EH * EW); return(levelData as T[]); } if (typeof(T) == typeof(short)) { short[] data = new short[levelCount * EH * EW]; short[] levelData = new short[EH * EW]; NetCDF.nc_get_var_short(ncid, varid, data); Array.Copy(data, levelIdx * EH * EW, levelData, 0, EH * EW); return(levelData as T[]); } } catch { } finally { NetCDF.nc_close(ncid); } } return(null); }
public NcFile(string filePath, NcFileMode fMode, NcFileFormat fFormat) { Int32 format = 0; switch (fFormat) { case NcFileFormat.classic: format = 0; break; case NcFileFormat.classic64: format = NC_64BIT_OFFSET; break; case NcFileFormat.nc4: format = NC_NETCDF4; break; case NcFileFormat.nc4classic: format = NC_NETCDF4 | NC_CLASSIC_MODEL; break; } switch (fMode) { case NcFileMode.write: NcCheck.Check(NcCheck.NC_EINVAL); break; case NcFileMode.read: NcCheck.Check(NcCheck.NC_EINVAL); break; case NcFileMode.newFile: NcCheck.Check(NetCDF.nc_create(filePath, format | NC_NOCLOBBER, ref myId)); break; case NcFileMode.replace: NcCheck.Check(NetCDF.nc_create(filePath, format | NC_CLOBBER, ref myId)); break; } this.filePath = filePath; nullObject = false; }
public NcType GetBaseType() { byte[] buffer = null; Int32 base_type = 0; Int32 base_sizep = 0; Int32 num_membersp = 0; NcCheck.Check(NetCDF.nc_inq_enum(groupId, myId, buffer, ref base_type, ref base_sizep, ref num_membersp)); switch ((NcTypeEnum)base_type) { case NcTypeEnum.NC_BYTE: return(NcByte.Instance); case NcTypeEnum.NC_UBYTE: return(NcUbyte.Instance); case NcTypeEnum.NC_CHAR: return(NcChar.Instance); case NcTypeEnum.NC_SHORT: return(NcShort.Instance); case NcTypeEnum.NC_USHORT: return(NcUshort.Instance); case NcTypeEnum.NC_INT: return(NcInt.Instance); case NcTypeEnum.NC_UINT: return(NcUint.Instance); case NcTypeEnum.NC_INT64: return(NcInt64.Instance); case NcTypeEnum.NC_UINT64: return(NcUint64.Instance); case NcTypeEnum.NC_FLOAT: return(NcFloat.Instance); case NcTypeEnum.NC_DOUBLE: return(NcDouble.Instance); case NcTypeEnum.NC_STRING: return(NcString.Instance); default: return(new NcType(GetParentGroup(), (int)base_type)); } return(new NcType()); // Null }
public void NetCDF(int GaseId, DateTime DateTime, string Name, string Unit, decimal Longtitude, decimal Latitude, decimal Value) { NetCDF netCDF = new NetCDF { GaseId = GaseId, Date = DateTime, Name = Name, Unit = Unit, Longtitude = Longtitude, Latitude = Latitude, Value = Value }; _context.NetCDF.Add(netCDF); _context.SaveChanges(); }
public NcType GetBaseType() { byte[] buffer = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME + 1]; Int32 base_nc_typep = 0; Int32 datum_sizep = 0; NcCheck.Check(NetCDF.nc_inq_vlen(groupId, myId, buffer, ref datum_sizep, ref base_nc_typep)); switch ((NcTypeEnum)base_nc_typep) { case NcTypeEnum.NC_BYTE: return(NcByte.Instance); case NcTypeEnum.NC_UBYTE: return(NcUbyte.Instance); case NcTypeEnum.NC_CHAR: return(NcChar.Instance); case NcTypeEnum.NC_SHORT: return(NcShort.Instance); case NcTypeEnum.NC_USHORT: return(NcUshort.Instance); case NcTypeEnum.NC_INT: return(NcInt.Instance); case NcTypeEnum.NC_UINT: return(NcUint.Instance); case NcTypeEnum.NC_INT64: return(NcInt64.Instance); case NcTypeEnum.NC_UINT64: return(NcUint64.Instance); case NcTypeEnum.NC_FLOAT: return(NcFloat.Instance); case NcTypeEnum.NC_DOUBLE: return(NcDouble.Instance); case NcTypeEnum.NC_STRING: return(NcString.Instance); default: return(new NcType(GetParentGroup(), base_nc_typep)); } return(new NcType()); // null }
public NcFile(string filePath, NcFileMode fMode) { switch (fMode) { case NcFileMode.write: NcCheck.Check(NetCDF.nc_open(filePath, NC_WRITE, ref myId)); break; case NcFileMode.read: NcCheck.Check(NetCDF.nc_open(filePath, NC_NOWRITE, ref myId)); break; case NcFileMode.newFile: NcCheck.Check(NetCDF.nc_create(filePath, NC_NETCDF4 | NC_NOCLOBBER, ref myId)); break; case NcFileMode.replace: NcCheck.Check(NetCDF.nc_create(filePath, NC_NETCDF4 | NC_CLOBBER, ref myId)); break; } this.filePath = filePath; nullObject = false; }
public NcType GetNcType() { int xtypep = 0; NcCheck.Check(NetCDF.nc_inq_atttype(groupId, varId, myName, ref xtypep)); if (xtypep <= 12) { // This is an atomic type return(new NcType(xtypep)); } else { Dictionary <string, NcType> typeMap = GetParentGroup().GetTypes(Location.ParentsAndCurrent); foreach (KeyValuePair <string, NcType> k in typeMap) { if (k.Value.GetId() == xtypep) { return(k.Value); } } } return(new NcType()); }
public void Close() { NcCheck.Check(NetCDF.nc_close(myId)); nullObject = true; myId = 0; }
public void AddMember(string name, UInt64 memberValue) { NcCheck.Check(NetCDF.nc_insert_enum(groupId, myId, name, ref memberValue)); }