Пример #1
0
        public int Read(IntPtr pItem)
        {
            int           eumT = 0, eumU = 0;
            DfsSimpleType dataT = DfsSimpleType.Int;

            DfsDLLWrapper.dfsGetItemInfo(pItem, out eumT, out EUMTypeString, out Name, out eumU, out EUMUnitString, out dataT);

            EUMType  = (eumItem)eumT;
            EUMUnit  = (eumUnit)eumU;
            dataType = (DfsSimpleType)dataT;

            //if (dataType != UfsSimpleType.UFS_FLOAT)return err("Only float dataType supported.");

            dim = DfsDLLWrapper.dfsGetItemDim(pItem);

            dataValType = DfsDLLWrapper.dfsGetItemValueType(pItem);

            sAxisType = (SpaceAxisType)DfsDLLWrapper.dfsGetItemAxisType(pItem);
            switch (sAxisType)
            {
            case SpaceAxisType.EqD0:
                DfsDLLWrapper.dfsGetItemAxisEqD0(pItem, out eumU, out axisEUMUnitString);
                nPointsX = 1;
                break;

            case SpaceAxisType.EqD1:
                DfsDLLWrapper.dfsGetItemAxisEqD1(pItem, out eumU, out axisEUMUnitString, out m_nPointsX, out XMinLimit, out DX);
                break;

            case SpaceAxisType.EqD2:
                DfsDLLWrapper.dfsGetItemAxisEqD2(pItem, out eumU, out axisEUMUnitString, out m_nPointsX, out m_nPointsY, out XMinLimit, out YMinLimit, out DX, out DY);
                break;

            case SpaceAxisType.EqD3:
                DfsDLLWrapper.dfsGetItemAxisEqD3(pItem, out eumU, out axisEUMUnitString, out m_nPointsX, out m_nPointsY, out m_nPointsZ, out XMinLimit, out YMinLimit, out ZMinLimit, out DX, out DY, out DZ);
                break;

            default:
                return(_err("Unsupported space axis " + sAxisType.ToString()));
            }

            axisEUMUnit = (eumUnit)eumU;
            return(0);
        }
Пример #2
0
        /// <summary>
        /// Opens an existing dfs-file
        /// </summary>
        /// <param name="DFSFileName"></param>
        public DFSBase(string DFSFileName)
            : this()
        {
            _filename        = DFSFileName;
            AbsoluteFileName = Path.GetFullPath(DFSFileName);

            try
            {
                DfsDLLWrapper.dfsFileRead(AbsoluteFileName, out _headerPointer, out _filePointer);
            }
            catch (Exception e)
            {
                return; //Not a valid file.
            }
            NumberOfItems = DfsDLLWrapper.dfsGetNoOfItems(_headerPointer);


            string eum_unit  = "";
            int    unit      = 0;
            int    data_type = 0;
            int    item_type = 0;

            float x = 0;
            float y = 0;
            float z = 0;

            float dx = 0;
            float dy = 0;
            float dz = 0;

            IntPtr name = new IntPtr();


            //Reads the projection
            LastStatus = dfsGetGeoInfoUTMProj(_headerPointer, ref name, ref _xOrigin, ref _yOrigin, ref _orientation);

            //Reads the space axis
            _spaceAxis = (SpaceAxisType)DfsDLLWrapper.dfsGetItemAxisType(FirstItem.ItemPointer);

            //Now read axes info dependent on the type of axis
            switch (_spaceAxis)
            {
            case SpaceAxisType.CurveLinearD2:
                break;

            case SpaceAxisType.CurveLinearD3:
                break;

            case SpaceAxisType.EqD0:
                break;

            case SpaceAxisType.EqD1:
                break;

            case SpaceAxisType.EqD2:   //DFS2 from MikeShe
                DfsDLLWrapper.dfsGetItemAxisEqD2(FirstItem.ItemPointer, out item_type, out eum_unit, out _numberOfColumns, out _numberOfRows, out x, out y, out dx, out dy);
                break;

            case SpaceAxisType.EqD3: //DFS3 from MikeShe
                DfsDLLWrapper.dfsGetItemAxisEqD3(FirstItem.ItemPointer, out item_type, out eum_unit, out _numberOfColumns, out _numberOfRows, out _numberOfLayers, out x, out y, out z, out dx, out dy, out dz);
                break;

            case SpaceAxisType.NeqD1:
                var coords = new Coords[1];
                DfsDLLWrapper.dfsGetItemAxisNeqD1(FirstItem.ItemPointer, out unit, out eum_unit, out data_type, out coords);
                break;

            case SpaceAxisType.NeqD2:
                break;

            case SpaceAxisType.NeqD3:
                break;

            case SpaceAxisType.Undefined:
                break;

            default:
                break;
            }

            _gridSize = dx;

            //Prepares an array of floats to recieve the data
            dfsdata = new float[_numberOfColumns * _numberOfRows * _numberOfLayers];

            //Now look at time axis
            _timeAxis = (TimeAxisType)DfsDLLWrapper.dfsGetTimeAxisType(_headerPointer);
            string startdate = "";
            string starttime = "";
            double tstart    = 0;
            double tstep     = 0;
            int    nt        = 0;
            int    tindex    = 0;

            switch (_timeAxis)
            {
            case TimeAxisType.TimeEquidistant: //Some DFS2 here
                DfsDLLWrapper.dfsGetEqTimeAxis(_headerPointer, out unit, out eum_unit, out tstart, out tstep, out nt, out tindex);
                break;

            case TimeAxisType.CalendarEquidistant: //Dfs2 and dfs3 here
                DfsDLLWrapper.dfsGetEqCalendarAxis(_headerPointer, out startdate, out starttime, out unit, out eum_unit, out tstart, out tstep, out nt, out tindex);
                if (unit == 1400)
                {
                    _timeStep = TimeSpan.FromSeconds(tstep);
                }
                else if (unit == 1401) //This is a guess
                {
                    _timeStep = TimeSpan.FromMinutes(tstep);
                }
                else if (unit == 1402)
                {
                    _timeStep = TimeSpan.FromHours(tstep);
                }
                break;

            case TimeAxisType.TimeNonEquidistant: //This has not been tested
                DfsDLLWrapper.dfsGetNeqTimeAxis(_headerPointer, out unit, out eum_unit, out tstart, out tstep, out nt, out tindex);
                break;

            case TimeAxisType.CalendarNonEquidistant://Only dfs0 can have varying time steps
                DfsDLLWrapper.dfsGetNeqCalendarAxis(_headerPointer, out startdate, out starttime, out unit, out eum_unit, out tstart, out tstep, out nt, out tindex);
                break;

            case TimeAxisType.Undefined:
                break;

            default:
                break;
            }

            NumberOfTimeStepsWritten = nt;
            timeStepUnit             = (TimeInterval)unit;

            if (_timeAxis == TimeAxisType.CalendarNonEquidistant | _timeAxis == TimeAxisType.TimeEquidistant)
            {
                _times = new double[nt];
            }

            if (startdate != "" & starttime != "")
            {
                _timesteps.Add(DateTime.Parse(startdate).Add(TimeSpan.Parse(starttime)));
            }
            else //Time equidistant files enter here.
            {
                _timesteps.Add(new DateTime(2002, 1, 1));
            }

            //Now build the list of timesteps
            for (int i = 1; i < nt; i++)
            {
                if (_timeAxis == TimeAxisType.CalendarNonEquidistant) //dfs0 with time varying.
                {
                    _timesteps.Add(_timesteps[0].Add(GetTimeSpan(i)));
                }
                else
                {
                    _timesteps.Add(_timesteps[i - 1].Add(_timeStep));
                }
            }
        }