示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bits"></param>
        /// <param name="index"></param>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static GribMessage Create(byte[] bits, int index, GribContext ctx)
        {
            var buff = Marshal.AllocHGlobal(bits.Length);

            Marshal.Copy(bits, 0, buff, bits.Length);
            int   err = 0;
            SizeT sz  = (SizeT)bits.Length;

            GribMessage msg    = null;
            GribHandle  handle = null;

            lock (_fileLock)
            {
                // grib_api moves to the next message in a stream for each new handle
                handle = GribApiProxy.GribHandleNewFromMultiMessage(ctx, out buff, ref sz, out err);
            }

            if (err != 0)
            {
                Marshal.AllocHGlobal(buff);
                throw GribApiException.Create(err);
            }

            if (handle != null)
            {
                msg = new GribMessage(handle, ctx, buff, index);
            }

            return(msg);
        }
示例#2
0
  public static void GribValuesCheck(GribHandle h, SWIGTYPE_p_grib_values values, int count) {
    int ret = GribApiProxyPINVOKE.GribValuesCheck(h.Reference, SWIGTYPE_p_grib_values.getCPtr(values), count);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GribMessage" /> class.
 /// </summary>
 /// <param name="handle">The handle.</param>
 /// <param name="context">The context.</param>
 /// <param name="index">The index.</param>
 protected GribMessage(GribHandle handle, GribContext context = null, int index = 0)
     : base()
 {
     Handle     = handle;
     Namespace  = Namespaces[0];
     KeyFilters = Interop.KeyFilters.All;
     Index      = index;
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GribMessage" /> class.
 /// </summary>
 /// <param name="handle"></param>
 /// <param name="context"></param>
 /// <param name="buffer"></param>
 /// <param name="index"></param>
 protected GribMessage(GribHandle handle, GribContext context, GCHandle buffer, int index = 0)
     : base()
 {
     Handle       = handle;
     Namespace    = Namespaces[0];
     KeyFilters   = Interop.KeyFilters.All;
     Index        = index;
     BufferHandle = buffer;
 }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GribMessage" /> class.
 /// </summary>
 /// <param name="handle">The handle.</param>
 /// <param name="context">The context.</param>
 /// <param name="buffer">Pointer to a native array containing the message bytes.</param>
 /// <param name="index">The index.</param>
 protected GribMessage(GribHandle handle, GribContext context, IntPtr buffer, int index = 0)
     : base()
 {
     Handle       = handle;
     Namespace    = Namespaces[0];
     KeyFilters   = Interop.KeyFilters.All;
     Index        = index;
     NativeBuffer = buffer;
     OwnsMemory   = buffer != IntPtr.Zero;
 }
示例#6
0
        /// <summary>
        /// Creates a GribMessage instance from a <seealso cref="Grib.Api.GribFile"/>.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static GribMessage Create(GribFile file, int index)
        {
            GribMessage msg = null;
            int         err = 0;
            // grib_api moves to the next message in a stream for each new handle
            GribHandle handle = GribApiProxy.GribHandleNewFromFile(file.Context, file, out err);

            if (err != 0)
            {
                throw GribApiException.Create(err);
            }

            if (handle != null)
            {
                msg = new GribMessage(handle, file.Context, index);
            }

            return(msg);
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GribBox"/> class.
        /// </summary>
        /// <param name="msgHandle">The MSG handle.</param>
        /// <param name="nw">The nw.</param>
        /// <param name="se">The se.</param>
        public GribBox(GribHandle msgHandle, GeoCoordinate nw, GeoCoordinate se)
        {
            int err;
            var box = GribApiProxy.GribBoxNew(msgHandle, out err);

            if (err != 0)
            {
                throw GribApiException.Create(err);
            }

            var pts = GribApiProxy.GribBoxGetPoints(box, nw.Latitude, nw.Longitude, se.Latitude, se.Longitude, out err);

            if (err != 0)
            {
                throw GribApiException.Create(err);
            }

            _points = new GribPoints(SWIGTYPE_p_grib_points.getCPtr(pts).Handle, false);
        }
示例#8
0
        /// <summary>
        /// Creates a GribMessage instance from a buffer.
        /// </summary>
        /// <param name="bits"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static GribMessage Create(byte[] bits, int index = 0)
        {
            GCHandle h       = GCHandle.Alloc(bits, GCHandleType.Pinned);
            IntPtr   pHandle = h.AddrOfPinnedObject();

            int        err    = 0;
            SizeT      sz     = (SizeT)bits.Length;
            GribHandle handle = GribApiProxy.GribHandleNewFromMultiMessage(GribContext.Default, out pHandle, ref sz, out err);

            if (err != 0)
            {
                h.Free();
                throw GribApiException.Create(err);
            }

            GribMessage msg = null;

            if (handle != null)
            {
                msg = new GribMessage(handle, GribContext.Default, h, index);
            }

            return(msg);
        }
示例#9
0
 public static SWIGTYPE_p_grib_box GribBoxNew(GribHandle h, out int error) {
   global::System.IntPtr cPtr = GribApiProxyPINVOKE.GribBoxNew(h.Reference, out error);
   SWIGTYPE_p_grib_box ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_grib_box(cPtr, false);
   return ret;
 }
示例#10
0
  public static GribHandle GribUtilSetSpec(GribHandle h, GribUtilGridSpec grid_spec, GribUtilPackingSpec packing_spec, int flags, double[] data_values, SizeT data_values_count, out int err) {
		System.IntPtr pVal = GribApiProxyPINVOKE.GribUtilSetSpec(h.Reference, GribUtilGridSpec.getCPtr(grid_spec), GribUtilPackingSpec.getCPtr(packing_spec), flags, data_values, data_values_count.Value, out err);

		return pVal == System.IntPtr.Zero ? null : new GribHandle(pVal);
	}
示例#11
0
  public static bool GribIsMissing(GribHandle h, string key, out int err) {
    int ret = GribApiProxyPINVOKE.GribIsMissing(h.Reference, key, out err);
	
	if (err != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
	
	return ret == 1;
  }
示例#12
0
  public static void GribSetMissing(GribHandle h, string key) {
    int ret = GribApiProxyPINVOKE.GribSetMissing(h.Reference, key);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#13
0
  public static GribKeysIterator GribKeysIteratorNew(GribHandle h, uint filter_flags, string name_space) {
		System.IntPtr pVal = GribApiProxyPINVOKE.GribKeysIteratorNew(h.Reference, filter_flags, name_space);

		return pVal == System.IntPtr.Zero ? null : new GribKeysIterator(pVal);
	}
示例#14
0
  public static void GribGetNativeType(GribHandle h, string name, out int type) {
    int ret = GribApiProxyPINVOKE.GribGetNativeType(h.Reference, name, out type);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#15
0
  public static void GribNearestFind(SWIGTYPE_p_grib_nearest nearest, GribHandle h, double inlat, double inlon, uint flags, double[] outlats, double[] outlons, double[] values, double[] distances, int[] indexes, ref SizeT len) {
    int ret = GribApiProxyPINVOKE.GribNearestFind(SWIGTYPE_p_grib_nearest.getCPtr(nearest), h.Reference, inlat, inlon, flags, outlats, outlons, values, distances, indexes, ref  len.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#16
0
  public static void GribSetLongArray(GribHandle h, string key, int[] vals, SizeT length) {
    int ret = GribApiProxyPINVOKE.GribSetLongArray(h.Reference, key, vals, length.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#17
0
  public static GribValuesIterator GribIteratorNew(GribHandle h, uint flags, out int error) {
		System.IntPtr pVal = GribApiProxyPINVOKE.GribIteratorNew(h.Reference, flags, out error);

		return pVal == System.IntPtr.Zero ? null : new GribValuesIterator(pVal);
	}
示例#18
0
  public static void GribGetData(GribHandle h, double[] lats, double[] lons, double[] values, ref SizeT size) {
    int ret = GribApiProxyPINVOKE.GribGetData(h.Reference, lats, lons, values, ref  size.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#19
0
  public static void GribGetMessageCopy(GribHandle h, byte[] message, ref SizeT message_length) {
    int ret = GribApiProxyPINVOKE.GribGetMessageCopy(h.Reference, message, ref  message_length.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#20
0
  public static void GribMultiHandleAppend(GribHandle h, int start_section, SWIGTYPE_p_grib_multi_handle mh) {
    int ret = GribApiProxyPINVOKE.GribMultiHandleAppend(h.Reference, start_section, SWIGTYPE_p_grib_multi_handle.getCPtr(mh));
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#21
0
  public static void GribHandleDelete(GribHandle h) {
    int ret = GribApiProxyPINVOKE.GribHandleDelete(h.Reference);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#22
0
  public static GribHandle GribHandleClone(GribHandle h) {
		System.IntPtr pVal = GribApiProxyPINVOKE.GribHandleClone(h.Reference);

		return pVal == System.IntPtr.Zero ? null : new GribHandle(pVal);
	}
示例#23
0
  public static void GribNearestFindMultiple(GribHandle h, int is_lsm, double[] inlats, double[] inlons, int npoints, double[] outlats, double[] outlons, double[] values, double[] distances, int[] indexes) {
    int ret = GribApiProxyPINVOKE.GribNearestFindMultiple(h.Reference, is_lsm, inlats, inlons, npoints, outlats, outlons, values, distances, indexes);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#24
0
  public static void GribSetBytes(GribHandle h, string key, byte[] bytes, ref SizeT length) {
    int ret = GribApiProxyPINVOKE.GribSetBytes(h.Reference, key, bytes, ref  length.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#25
0
  public static void GribGetOffset(GribHandle h, string key, ref SizeT offset) {
    int ret = GribApiProxyPINVOKE.GribGetOffset(h.Reference, key, ref  offset.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#26
0
 public static void GribDumpContent(GribHandle h, GribFile arg1, string mode, uint option_flags, byte[] arg) {
   GribApiProxyPINVOKE.GribDumpContent(h.Reference, arg1.Reference, mode, option_flags, arg);
 }
示例#27
0
  public static void GribGetLong(GribHandle h, string key, out int value) {
    int ret = GribApiProxyPINVOKE.GribGetLong(h.Reference, key, out value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#28
0
 public static void GribUpdateSectionsLengths(GribHandle h) {
   GribApiProxyPINVOKE.GribUpdateSectionsLengths(h.Reference);
 }
示例#29
0
 /// <summary>
 /// Return true if the key name exists (is defined) in the grib message.
 /// </summary>
 /// <param name="handle"></param>
 /// <param name="keyName"></param>
 /// <returns></returns>
 public static bool IsKeyDefined(GribHandle handle, string keyName)
 {
     return(GribApiProxy.GribIsDefined(handle, keyName));
 }
示例#30
0
  public static void GribSetValues(GribHandle h, SWIGTYPE_p_grib_values grib_values, SizeT arg_count) {
    int ret = GribApiProxyPINVOKE.GribSetValues(h.Reference, SWIGTYPE_p_grib_values.getCPtr(grib_values), arg_count.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GribMessage" /> class.
 /// </summary>
 /// <param name="handle">The handle.</param>
 /// <param name="context">The context.</param>
 /// <param name="index">The index.</param>
 protected GribMessage(GribHandle handle, GribContext context, int index = 0)
     : this(handle, context, new GCHandle(), index)
 {
 }
示例#32
0
  public static bool GribIsDefined(GribHandle h, string key) {
    int ret = GribApiProxyPINVOKE.GribIsDefined(h.Reference, key);

	return ret == 1;
  }
示例#33
0
  public static void GribGetString(GribHandle h, string key, System.Text.StringBuilder mesg, ref SizeT length) {
    int ret = GribApiProxyPINVOKE.GribGetString(h.Reference, key, mesg, ref  length.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#34
0
  public static void GribGetMessageSize(GribHandle h, ref SizeT size) {
    int ret = GribApiProxyPINVOKE.GribGetMessageSize(h.Reference, ref  size.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GribMessage" /> class.
 /// </summary>
 /// <param name="handle">The handle.</param>
 /// <param name="context">The context.</param>
 /// <param name="index">The index.</param>
 protected GribMessage(GribHandle handle, GribContext context, int index = 0)
     : this(handle, context, IntPtr.Zero, index)
 {
 }
示例#36
0
  public static void GribPointsGetValues(GribHandle h, SWIGTYPE_p_grib_points points, out double val) {
    int ret = GribApiProxyPINVOKE.GribPointsGetValues(h.Reference, SWIGTYPE_p_grib_points.getCPtr(points), out val);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#37
0
  public static void GribCopyNamespace(GribHandle dest, string name, GribHandle src) {
    int ret = GribApiProxyPINVOKE.GribCopyNamespace(dest.Reference, name, src.Reference);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#38
0
  public static void GribGetDoubleElement(GribHandle h, string key, int i, out double value) {
    int ret = GribApiProxyPINVOKE.GribGetDoubleElement(h.Reference, key, i, out value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
示例#39
0
  public static GribHandle GribUtilSectionsCopy(GribHandle hfrom, GribHandle hto, int what, out int err) {
		System.IntPtr pVal = GribApiProxyPINVOKE.GribUtilSectionsCopy(hfrom.Reference, hto.Reference, what, out err);

		return pVal == System.IntPtr.Zero ? null : new GribHandle(pVal);
	}
示例#40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GribKeyValue"/> class.
 /// </summary>
 /// <param name="handle">The handle.</param>
 /// <param name="keyName">Name of the key.</param>
 internal GribKeyValue(GribHandle handle, string keyName)
 {
     _handle = handle;
     Key     = keyName;
 }
示例#41
0
  public static void GribGetDoubleElements(GribHandle h, string key, SWIGTYPE_p_int i, int size, out double value) {
    int ret = GribApiProxyPINVOKE.GribGetDoubleElements(h.Reference, key, SWIGTYPE_p_int.getCPtr(i), size, out value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }