コード例 #1
0
        /// <summary>
        /// Read the variable attributes and fill it to Ncvar object passed as parameter
        /// </summary>
        /// <param name="count"></param>
        /// <param name="var"></param>
        private void ReadVariableAttributes(int count, ref NcVar var)
        {
            for (int i = 0; i < count; ++i)
            {
                string str      = ReadBytes(0, 4);
                int    numval   = ReadInteger(str); // Get the length of the name of the variable attribute
                string attrName = ReadStringName(numval);

                int    controlNum = ReadInteger(ReadBytes(0, 4));
                object attrVal    = null;
                NcType type       = NcType.NcByte;
                switch (controlNum)
                {
                case NC_BYTE:
                    break;

                case NC_CHAR:
                    //Read variable name length
                    str     = ReadBytes(0, 4);
                    numval  = ReadInteger(str);       // Get the length of the attribute value
                    attrVal = ReadStringName(numval); // Get the attribute value
                    type    = NcType.NcChar;
                    break;

                case NC_INT:
                    str    = ReadBytes(0, 4);
                    numval = ReadInteger(str);     //length of arrary
                    break;

                case NC_FLOAT:
                    str    = ReadBytes(0, 4);
                    numval = ReadInteger(str);     //length of arrary
                    float[] arrF = new float[numval];
                    for (int j = 0; j < numval; j++)
                    {
                        arrF[j] = ReadFloat(0);
                    }
                    attrVal = arrF;
                    type    = NcType.NcFloat;
                    break;

                case NC_DOUBLE:
                    str    = ReadBytes(0, 4);
                    numval = ReadInteger(str);     //length of arrary
                    double[] arrD = new double[numval];
                    for (int j = 0; j < numval; j++)
                    {
                        arrD[j] = ReadDouble(0);
                    }
                    attrVal = arrD;
                    type    = NcType.NcDouble;
                    break;
                }
                // Add variable attributes to the varible object here.
                NcAtt varAtt = new NcAtt(attrName, type, attrVal);

                var.VariableAttributes.Add(varAtt);
            }
        }
コード例 #2
0
        private bool IfExists(NcAtt attr)
        {
            foreach (NcAtt myAttr in this.globalAttributeList)
            {
                if (string.Compare(myAttr.Name, attr.Name) == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// Read the global attributes and add them to meta data
        /// </summary>
        /// <param name="count"></param>
        private void ReadGlobalAttributes(int count)
        {
            for (int i = 0; i < count; ++i)
            {
                string str     = ReadBytes(0, 4);
                int    numval  = ReadInteger(str); // Get the length of the name of the global attributes
                string attName = ReadStringName(numval);

                // the nane and value of the attributes are separated by control char 2
                int    controlChar    = ReadInteger(ReadBytes(0, 4));
                NcType type           = NcType.NcByte; //default nc type
                object attributeValue = null;
                switch (controlChar)
                {
                case NC_BYTE:
                    type = NcType.NcByte;
                    break;

                case NC_CHAR:
                    type           = NcType.NcChar;
                    str            = ReadBytes(0, 4);
                    numval         = ReadInteger(str);       // length of the attribute values
                    attributeValue = ReadStringName(numval); // attribute value
                    break;

                case NC_SHORT:
                    type = NcType.NcShort;
                    break;

                case NC_INT:
                    type = NcType.NcInt;
                    break;

                case NC_FLOAT:
                    type   = NcType.NcFloat;
                    str    = ReadBytes(0, 4);
                    numval = ReadInteger(str);      // length of the attribute values
                    float[] fArr = new float[numval];
                    for (int j = 0; j < numval; j++)
                    {
                        fArr[j] = ReadFloat(0);
                    }

                    attributeValue = fArr;      //pass array of float as object
                    break;

                case NC_DOUBLE:
                    type   = NcType.NcDouble;
                    str    = ReadBytes(0, 4);
                    numval = ReadInteger(str);      // length of the attribute values
                    double[] dArr = new double[numval];
                    for (int j = 0; j < numval; j++)
                    {
                        dArr[j] = ReadDouble(0);
                    }

                    attributeValue = dArr;      //pass array of double ad object
                    break;
                }

                NcAtt ncAtt = new NcAtt(attName, type, attributeValue);

                this.metadata.AddGlobalAttribute(ncAtt);
            }
        }
コード例 #5
0
 public void AddGlobalAttribute(NcAtt globalAttr)
 {
     globalAttributeList.Add(globalAttr);
 }