Exemplo n.º 1
0
        private void WriteAttribute(int varId, NetCdfAttribute ncAttribute)
        {
            var value = ncAttribute.Value;

            if (value is string)
            {
                var str = (string)value;
                CheckResult(NetCdfWrapper.nc_put_att_text(id, varId, ncAttribute.Name,
                                                          new IntPtr(str.Length), UTF8Marshal.StringUTF8ToPtr(str)));
            }
            else if (value is double)
            {
                var d = (double)value;
                CheckResult(NetCdfWrapper.nc_put_att_double(id, varId, ncAttribute.Name,
                                                            NetCdfDataType.NC_DOUBLE, new IntPtr(1),
                                                            new[] { d }));
            }
            else if (value is float)
            {
                var i = (float)value;
                CheckResult(NetCdfWrapper.nc_put_att_float(id, varId, ncAttribute.Name,
                                                           NetCdfDataType.NC_FLOAT, new IntPtr(1),
                                                           new[] { i }));
            }
            else if (value is int)
            {
                var i = (int)value;
                CheckResult(NetCdfWrapper.nc_put_att_int(id, varId, ncAttribute.Name,
                                                         NetCdfDataType.NC_INT, new IntPtr(1),
                                                         new[] { i }));
            }
            else
            {
                throw new NotImplementedException(string.Format("NetCdf Attribute type '{0}' not implemented",
                                                                value != null ? value.GetType().ToString() : "<null>"));
            }
        }