예제 #1
0
        public void WriteVariableVal(int variableType, string varName, object[] valArray)
        {
            VariableWr var = null;

            for (int j = 0; j < this.varList.Count; ++j)
            {
                if (varName == this.varList[j].varName)
                {
                    var = this.varList[j];
                    break;
                }
            }

            // Get the offset
            this.bw.Seek((int)var.varOffset, SeekOrigin.Begin);
            this.WriteIntNumber(this.GetByteSize(variableType));
            this.WriteIntNumber((int)this.bw.BaseStream.Length);

            // If this is a record var then update record count
            if (false == this.isRecordWritten)
            {
                UpdateRecordCount(ref var, valArray.Length);
                this.isRecordWritten = true;
            }

            // Now move to the end of the file and start writing values
            this.bw.Seek((int)this.bw.BaseStream.Length, SeekOrigin.Begin);
            for (int i = 0; i < valArray.Length; ++i)
            {
                this.WriteVal(variableType, valArray[i]);
            }
        }
예제 #2
0
        private void UpdateRecordCount(ref VariableWr var, int dataLength)
        {
            int divisor = 1;

            for (int i = 0; i < var.dimList.Count; ++i)
            {
                if (false == var.dimList[i].isRecord)
                {
                    divisor = divisor * var.dimList[i].size;
                }
            }
            int recCount = dataLength / divisor;

            this.bw.Seek(4, SeekOrigin.Begin);
            this.WriteIntNumber(recCount);
        }
예제 #3
0
        public void WriteVariable(int variableType, string varName, List <NcDim> dimArray,
                                  int[] attribTypeArray, string[] attribNamrArr, string[] AttribVal)
        {
            // Start with writing the variable name
            this.WriteIntNumber(varName.Length);
            this.WriteStringVal(varName);

            VariableWr varWr = new VariableWr();

            varWr.varName = varName;
            varWr.dimList = new List <DimensionWr>();

            // Write the dimensions
            this.WriteIntNumber(dimArray.Count);
            for (int i = 0; i < dimArray.Count; ++i)
            {
                foreach (DimensionWr d in this.dimList)
                {
                    if (d.valName == dimArray[i].Name)
                    {
                        this.WriteIntNumber(d.dimIndex);
                        varWr.dimList.Add(d);
                    }
                }
            }

            this.AddGlobalAttHeader(attribNamrArr.Length);

            for (int i = 0; i < attribNamrArr.Length; ++i)
            {
                this.WriteAttribute(attribTypeArray[i], attribNamrArr[i],
                                    AttribVal[i]);
            }

            // Write the variable type. Write two bytes with values zero
            // for size and offset. They will be overwritten when writing values
            // for this variable.
            this.WriteType(variableType);

            // Add this to the internal var list
            varWr.varOffset = this.bw.BaseStream.Length;

            this.WriteIntNumber(0);
            this.WriteIntNumber(0);
            this.varList.Add(varWr);
        }