//static GribEnvironment () //{ // GribEnvironment.Init(); // // grib_api discourages enabling multi-fields, however leaving it disabled has caused // // considerable confusion among users. // GribContext.Default.EnableMultipleFieldMessages = true; //} /// <summary> /// Initializes GribApi.NET. In very rare cases, you may need to call this method directly /// to ensure the native libraries are bootstrapped and the environment setup correctly. /// </summary> /// <exception cref="System.ComponentModel.Win32Exception"></exception> public static void Init() { lock (_initLock) { if (Initialized) { return; } Initialized = true; if (String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("GRIB_API_NO_ABORT"))) { NoAbort = true; } string definitions = Environment.GetEnvironmentVariable("GRIB_DEFINITION_PATH"); if (String.IsNullOrWhiteSpace(definitions)) { GribEnvironmentLoadHelper.TryFindDefinitions(out definitions); } AssertValidEnvironment(definitions); _libHandle = GribEnvironmentLoadHelper.BootStrapLibrary(); GribApiNative.HookGribExceptions(); SamplesPath = definitions.Remove(definitions.LastIndexOf("definitions")) + "samples"; DefinitionsPath = definitions; } }
static GribEnvironment() { if (Initialized) { return; } lock (_initLock) { Initialized = true; if (String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("GRIB_API_NO_ABORT"))) { NoAbort = true; } string definitions = Environment.GetEnvironmentVariable("GRIB_DEFINITION_PATH"); if (String.IsNullOrWhiteSpace(definitions)) { GribEnvironmentLoadHelper.TryFindDefinitions(out definitions); } AssertValidEnvironment(definitions); _libHandle = GribEnvironmentLoadHelper.BootStrapLibrary(); GribApiNative.HookGribExceptions(); SamplesPath = definitions.Remove(definitions.LastIndexOf("definitions")) + "samples"; DefinitionsPath = definitions; // grib_api discourages enabling multi-fields because they do not use them regularly and do not feel they // are well-tested, however leaving them disabled has caused considerable confusion among users. GribContext.Default.EnableMultipleFieldMessages = true; } }
/// <summary> /// Initializes a new instance of the <see cref="GribFile" /> class. File read rights are shared between processes. /// </summary> /// <param name="fileName">Name of the file.</param> /// <exception cref="System.IO.IOException">Could not open file. See inner exception for more detail.</exception> /// <exception cref="System.IO.FileLoadException">The file is empty.</exception> public GribFile(string fileName) { FileInfo fi = new FileInfo(fileName); // need a better check if (fi.Length < 4) { throw new FileLoadException("This file is empty or invalid."); } _pFileHandleProxy = GribApiNative.CreateFileHandleProxy(fileName); if (_pFileHandleProxy == IntPtr.Zero) { throw new IOException("Could not open file. See inner exception for more detail.", new Win32Exception(Marshal.GetLastWin32Error())); } _fileHandleProxy = (FileHandleProxy)Marshal.PtrToStructure(_pFileHandleProxy, typeof(FileHandleProxy)); FileName = fileName; Reference = new HandleRef(this, _fileHandleProxy.File); Context = GribApiProxy.GribContextGetDefault(); // set the message count here; the result seems to be connected to the message iterator so // that after you begin iterating messages, the count decreases until it reaches 1. int count = 0; GribApiProxy.GribCountInFile(Context, this, out count); MessageCount = count; }
/// <summary> /// Called when [dispose]. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void OnDispose(bool disposing) { if (_pFileHandleProxy != IntPtr.Zero) { GribApiNative.DestroyFileHandleProxy(_pFileHandleProxy); } }
/// <summary> /// Called when [dispose]. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void OnDispose(bool disposing) { if (this._nearest != null) { this._nearest.Dispose(); } if (_pFileHandleProxy != IntPtr.Zero) { GribApiNative.DestroyFileHandleProxy(_pFileHandleProxy); } }
/// <summary> /// Resets the underlying file pointer to the beginning of the file. /// </summary> public void Rewind() { GribApiNative.RewindFileHandleProxy(this._pFileHandleProxy); }
/// <summary> /// Initializes a new instance of the <see cref="GribContext"/> class. /// </summary> /// <param name="h">The h.</param> public GribContext(IntPtr h) : base(h) { GribApiNative.GribSetContextLogger(h, this.OnLogReceived); }