Example #1
0
        public bool GetDataSizeInfos(string datasetName, out int rank, out int[] dimsizes, out HDF4Helper.DataTypeDefinitions hdf4Type, out Type dataType, out int dataTypeSize)
        {
            StringBuilder sds_name = new StringBuilder();

            rank         = 0;
            dimsizes     = new int[MAX_DIMSIZES];
            dataType     = typeof(UInt16);
            hdf4Type     = HDF4Helper.DataTypeDefinitions.DFNT_NUINT16;
            dataTypeSize = 0;
            int id = HDF4Helper.SDstart(_fname, HDF4Helper.AccessCodes.DFACC_READ);

            try
            {
                int dsIndex  = HDF4Helper.SDnametoindex(id, datasetName);
                int dsObjId  = HDF4Helper.SDselect(id, dsIndex);
                int attCount = 0;
                HDF4Helper.SDgetinfo(dsObjId, sds_name, out rank, dimsizes, out hdf4Type, out attCount);
                if (rank != 0)
                {
                    dataType = GetTypeFromHDF4DataType(hdf4Type, out dataTypeSize);
                    return(true);
                }
            }
            finally
            {
                HDF4Helper.SDend(id);
            }
            return(false);
        }
Example #2
0
        public Dictionary <string, string> GetAttributes(string datasetName)
        {
            StringBuilder sds_name = new StringBuilder();
            int           rank     = 0;

            int[] dimsizes = new int[MAX_DIMSIZES];
            HDF4Helper.DataTypeDefinitions datatype;
            int id = HDF4Helper.SDstart(_fname, HDF4Helper.AccessCodes.DFACC_READ);

            try
            {
                int dsIndex  = HDF4Helper.SDnametoindex(id, datasetName);
                int dsObjId  = HDF4Helper.SDselect(id, dsIndex);
                int attCount = 0;
                HDF4Helper.SDgetinfo(dsObjId, sds_name, out rank, dimsizes, out datatype, out attCount);
                //int dsCount = 0;
                //HDF4Helper.SDfileinfo(id, out dsCount, out attCount);
                if (attCount == 0)
                {
                    return(null);
                }
                return(GetAttributes(dsObjId, attCount));
            }
            finally
            {
                HDF4Helper.SDend(id);
            }
        }
Example #3
0
 public Dictionary <string, string> GetAttributes()
 {
     if (!_readFileAttrs)
     {
         Dictionary <string, string> cacheAttrs = GlobalFileAttributeCache.GetFileAttributes(_fname);
         if (cacheAttrs == null)
         {
             _readFileAttrs = true;
             int id = HDF4Helper.SDstart(_fname, HDF4Helper.AccessCodes.DFACC_READ);
             try
             {
                 int dsCount  = 0;
                 int attCount = 0;
                 HDF4Helper.SDfileinfo(id, out dsCount, out attCount);
                 if (attCount == 0)
                 {
                     return(null);
                 }
                 _fileAttrs = GetAttributes(id, attCount);
                 GlobalFileAttributeCache.SetFileAttributes(_fname, _fileAttrs);
             }
             finally
             {
                 HDF4Helper.SDend(id);
             }
         }
         else
         {
             _fileAttrs = cacheAttrs;
         }
     }
     return(_fileAttrs);
 }
Example #4
0
        private string ReadAttribute(int objId, int attIndex)
        {
            HDF4Helper.DataTypeDefinitions dType = HDF4Helper.DataTypeDefinitions.DFNT_CHAR;
            int           count    = 0;
            StringBuilder attrName = new StringBuilder(256);

            HDF4Helper.SDattrinfo(objId, attIndex, attrName, out dType, out count);
            string attValue = GetAttributevalue(dType, objId, attIndex, count);

            return(attValue);
        }
Example #5
0
        private void GetAttribute(int objId, int attIndex, out string attName, out string attValue)
        {
            attName  = "";
            attValue = "";
            StringBuilder attr_name = new StringBuilder(256);

            HDF4Helper.DataTypeDefinitions data_type;
            int data_count = 0;

            HDF4Helper.SDattrinfo(objId, attIndex, attr_name, out data_type, out data_count);
            attName  = attr_name.ToString();
            attValue = GetAttributevalue(data_type, objId, attIndex, data_count);
        }
Example #6
0
        public string GetAttributeValue(string datasetName, string attributeName)
        {
            int id = HDF4Helper.SDstart(_fname, HDF4Helper.AccessCodes.DFACC_READ);

            try
            {
                int dsIndex  = HDF4Helper.SDnametoindex(id, datasetName);
                int dsObjId  = HDF4Helper.SDselect(id, dsIndex);
                int attIndex = HDF4Helper.SDfindattr(dsObjId, attributeName);
                return(ReadAttribute(dsObjId, attIndex));
            }
            finally
            {
                HDF4Helper.SDend(id);
            }
        }
Example #7
0
        private string[] GetALLDataset()
        {
            int sd_id = HDF4Helper.SDstart(_fname, HDF4Helper.AccessCodes.DFACC_READ);

            try
            {
                int num_datasets     = 0;
                int num_global_attrs = 0;
                HDF4Helper.SDfileinfo(sd_id, out num_datasets, out num_global_attrs);
                string[] dsNames = ReadSDinfo(sd_id, num_datasets);
                return(dsNames);
            }
            finally
            {
                HDF4Helper.SDend(sd_id);
            }
        }
Example #8
0
 private static string[] ReadSDinfo(int sd_id, int num_datasets)
 {
     string[] dsNames = new string[num_datasets];
     for (int dsIndex = 0; dsIndex < num_datasets; dsIndex++)
     {
         int sds_id = HDF4Helper.SDselect(sd_id, dsIndex);
         try
         {
             StringBuilder sds_name = new StringBuilder(256);
             int           rank;
             int[]         dimsizes = new int[256];
             GeoDo.HDF4.HDF4Helper.DataTypeDefinitions data_type;
             int num_attrs;
             HDF4Helper.SDgetinfo(sds_id, sds_name, out rank, dimsizes, out data_type, out num_attrs);
             dsNames[dsIndex] = sds_name.ToString();
         }
         finally
         {
             HDF4Helper.SDend(sds_id);
         }
     }
     return(dsNames);
 }
Example #9
0
        private string GetAttributevalue(HDF4Helper.DataTypeDefinitions data_type, int objId, int attIndex, int data_count)
        {
            StringBuilder attr_Data = new StringBuilder(256);

            switch (data_type)
            {
            case HDF4Helper.DataTypeDefinitions.DFNT_CHAR:
            case HDF4Helper.DataTypeDefinitions.DFNT_UCHAR:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                byte[] dest = new byte[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (char value in dest)
                {
                    attr_Data.Append(value);
                }
                break;
            }

            case HDF4Helper.DataTypeDefinitions.DFNT_INT8:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                byte[] dest = new byte[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (sbyte value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
                break;
            }

            case HDF4Helper.DataTypeDefinitions.DFNT_UINT8:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                byte[] dest = new byte[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (byte value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
                break;
            }

            case HDF4Helper.DataTypeDefinitions.DFNT_INT16:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(short)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                short[] dest = new short[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (short value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
            }
            break;

            case HDF4Helper.DataTypeDefinitions.DFNT_UINT16:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(short)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                short[] dest = new short[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (ushort value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
            }
            break;

            case HDF4Helper.DataTypeDefinitions.DFNT_INT32:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                int[] dest = new int[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (int value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
            }
            break;

            case HDF4Helper.DataTypeDefinitions.DFNT_UINT32:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                int[] dest = new int[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (uint value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
            }
            break;

            case HDF4Helper.DataTypeDefinitions.DFNT_FLOAT32:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                float[] dest = new float[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (float value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
            }
            break;

            case HDF4Helper.DataTypeDefinitions.DFNT_FLOAT64:
            {
                IntPtr attr_buff = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * data_count);
                HDF4Helper.SDreadattr(objId, attIndex, attr_buff);
                double[] dest = new double[data_count];
                Marshal.Copy(attr_buff, dest, 0, data_count);
                Marshal.FreeHGlobal(attr_buff);
                foreach (double value in dest)
                {
                    attr_Data.Append(value);
                    attr_Data.Append(",");
                }
            }
            break;

            case HDF4Helper.DataTypeDefinitions.DFNT_NINT8:
            case HDF4Helper.DataTypeDefinitions.DFNT_NUINT8:
            case HDF4Helper.DataTypeDefinitions.DFNT_NINT16:
            case HDF4Helper.DataTypeDefinitions.DFNT_NUINT16:
            case HDF4Helper.DataTypeDefinitions.DFNT_NINT32:
            case HDF4Helper.DataTypeDefinitions.DFNT_NUINT32:
            case HDF4Helper.DataTypeDefinitions.DFNT_NFLOAT32:
            case HDF4Helper.DataTypeDefinitions.DFNT_NFLOAT64:
                break;

            default:
                break;
            }
            string str = attr_Data.ToString();

            if (str != null)
            {
                if (str.EndsWith(","))
                {
                    str = str.Substring(0, str.Length - 1);
                }
                str = str.Replace('\0', ' ');
            }
            return(str);
        }