public NcMetaData GetMetadata()
        {
            NcMetaData metadata = new NcMetaData();

            Dictionary <uint, INetCDFDimension> .Enumerator allDims = this.Dimensions.GetEnumerator();
            while (allDims.MoveNext())
            {
                INetCDFDimension iDim = allDims.Current.Value;
                NcDim            dim  = new NcDim(iDim.Name, (int)iDim.Length);
            }

            return(metadata);
        }
Esempio n. 2
0
 /// <summary>
 /// Opens the files from the specified path for reading
 /// </summary>
 /// <param name="pathName"></param>
 /// <param name="mode"></param>
 public NcFile(string pathName, NcFileMode mode)
 {
     try
     {
         switch (mode)
         {
         case NcFileMode.ReadOnly:
             fs = new FileStream(pathName, FileMode.Open, FileAccess.Read);
             break;
         }
         this.metadata = new NcMetaData();
         this.ReadMetadata();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Fills the NcMetada with file metadata
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static NcMetaData GetMetaData(NetCDFReader reader)
        {
            NcMetaData metadata = new NcMetaData();

            //Add No of records
            metadata.NumberOfRecords = (int)reader.NumberOfRecords;

            //Add Dimensions
            Dictionary <uint, INetCDFDimension> .Enumerator dimEnumerator
                = reader.Dimensions.GetEnumerator();
            while (dimEnumerator.MoveNext())
            {
                string name = dimEnumerator.Current.Value.Name;
                int    size = (int)dimEnumerator.Current.Value.Length;
                NcDim  dim  = new NcDim(name, size);
                //dim.IsUnlimited = dimEnumerator.Current.Value.IsRecordDimension;

                metadata.AddDimension(dim);
            }

            //Add Global attributes
            Dictionary <string, INetCDFAttribute> .Enumerator attrEnumerator
                = reader.Attributes.GetEnumerator();
            while (attrEnumerator.MoveNext())
            {
                NcType attType  = (NcType)attrEnumerator.Current.Value.DataType;
                string attName  = attrEnumerator.Current.Key; //Get Attname here
                object attValue = attrEnumerator.Current.Value.Value;
                NcAtt  att      = new NcAtt(attName, attType, attValue);
                metadata.AddGlobalAttribute(att);
            }

            //Add Variables
            Dictionary <string, INetCDFVariable> .Enumerator varEnumerator
                = reader.Variables.GetEnumerator();

            while (varEnumerator.MoveNext())
            {
                string name = varEnumerator.Current.Value.Name;
                //object value = varEnumerator.Current.Value;
                NcType type = (NcType)varEnumerator.Current.Value.DataType;
                NcVar  var  = new NcVar(name, type);

                //Add dimenstions  to variables
                var.NumValues = (int)varEnumerator.Current.Value.NumValues;
                for (int i = 0; i < varEnumerator.Current.Value.DimensionIDs.Length; i++)
                {
                    uint  dimID = varEnumerator.Current.Value.DimensionIDs[i];
                    NcDim dim   = new NcDim(reader.Dimensions[dimID].Name, (int)reader.Dimensions[dimID].Length);
                    var.Dimensions.Insert(i, dim);
                }

                // Add variable attributes
                Dictionary <string, INetCDFAttribute> .Enumerator vattEnumerator
                    = varEnumerator.Current.Value.Attributes.GetEnumerator();
                while (vattEnumerator.MoveNext())
                {
                    NcType attType  = (NcType)vattEnumerator.Current.Value.DataType;
                    string attName  = vattEnumerator.Current.Key; //Get Attname here
                    object attValue = vattEnumerator.Current.Value.Value;
                    NcAtt  att      = new NcAtt(attName, attType, attValue);
                    var.VariableAttributes.Add(att);
                }

                metadata.AddVariable(var);
            }

            return(metadata);
        }
 public NetCDFFile(NetCDFReader reader, HyperCube cube)
 {
     this.reader   = reader;
     this.cube     = cube;
     this.metaData = NetCDFFile.GetMetaData(reader);
 }