Ejemplo n.º 1
0
        public static NcVar GetVariable(int ncID, int variableID, NcDimList dims)
        {
            NcType variableType;

            NcInqVartype(ncID, variableID, out variableType);
            switch (variableType)
            {
            case NcType.ncDouble:
                return(new NcVarDouble(ncID, variableID, dims));

            case NcType.ncShort:
                return(new NcVarShort(ncID, variableID, dims));

            case NcType.ncFloat:
                return(new NcVarFloat(ncID, variableID, dims));

            case NcType.ncInt:
                return(new NcVarInt(ncID, variableID, dims));

            case NcType.ncByte:
                return(new NcVarByte(ncID, variableID, dims));

            case NcType.ncChar:
                return(new NcVarChar(ncID, variableID, dims));

            default:
                throw new Exception(variableType.ToString() + " factory not yet implemented!");
            }
        }
Ejemplo n.º 2
0
        protected NcVar(int ncID, int variableID, IList <NcDim> dims)
            : base(ncID, variableID)
        {
            StringBuilder variableName;
            int           attributeCount, dimCount;
            var           dimIDs = new int[100];
            NcType        variableType;

            NcInqVar(ncID, variableID, out variableName, out variableType, out dimCount, ref dimIDs, out attributeCount);

            Varid         = variableID;
            DimIds        = new int[dimCount];
            Dims          = new int[dimCount];
            Strides       = new int[dimCount];
            ComponentName = variableName.ToString();
            _ncDims       = new NcDimList(dimCount);
            _ncAtts       = new NcAttList(attributeCount);
            for (var i = 0; i < dimCount; i++)
            {
                DimIds[i] = dimIDs[i];
            }
            for (var i = 0; i < dimCount; i++)
            {
                _ncDims.Add(dims[DimIds[i]]);
                Dims[i] = (int)_ncDims[i].Size;
            }
            Elements = 1;
            for (var i = 0; i < dimCount; i++)
            {
                Elements *= Dims[i];
            }

            switch (dimCount)
            {
            case 1:
                Strides[0] = 1;
                break;

            case 2:
                Strides[1] = 1;
                Strides[0] = Dims[1];
                break;

            default:
                Strides[dimCount - 1] = 1;
                for (var i = dimCount - 2; i >= 0; i--)
                {
                    Strides[i] = Dims[i + 1] * Strides[i + 1];
                }
                break;
            }

            for (var i = 0; i < attributeCount; i++)
            {
                _ncAtts.Add(GetAttribute(ncID, variableID, i));
            }
        }
Ejemplo n.º 3
0
        public NcFile(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            int i, j;

            base.filename = filename;
            NcResult status = NcOpen(base.filename, 0, out Ncid);

            if (status != NcResult.NC_NOERR)
            {
                throw new ApplicationException(String.Format("Error constructing NcFile object for file \"{0}\".  NC_open returned {1}", filename, status.ToString()));
            }

            status = NcInq(Ncid, out _ndims, out _nvars, out _natts, out _unlimdimid);
            if (status != NcResult.NC_NOERR)
            {
                throw new ApplicationException(String.Format("Error constructing NcFile object for file \"{0}\".  NC_inq returned {1}", filename, status.ToString()));
            }

            _atts = new NcAttList(_natts);
            for (j = 0; j < _natts; j++)
            {
                _atts.Add(NcComponent.GetAttribute(Ncid, j));
            }

            _dims = new NcDimList(_ndims);
            // Get the list of dimensions
            for (i = 0; i < _ndims; i++)
            {
                _dims.Add(NcComponent.GetDimension(Ncid, i, (_unlimdimid == i)));
            }

            _vars = new NcVarList(_nvars);
            // Get the list of variables
            for (i = 0; i < _nvars; i++)
            {
                _vars.Add(NcComponent.GetVariable(Ncid, i, _dims));
            }
        }