Example #1
0
        public int ReadDfsFile(string dfsFileName)
        {
            int rc;

            DfsDLLWrapper.dfsFileRead(dfsFileName, out pHeader, out pFile);
            m_fileName = dfsFileName;

            compressed = (DfsDLLWrapper.dfsIsFileCompressed(pHeader));
            if (compressed)
            {
                encodeKeySize = DfsDLLWrapper.dfsGetEncodeKeySize(pHeader);
                if (encodeKeySize > 0)
                {
                    compress_XKey = new int[encodeKeySize];
                    compress_YKey = new int[encodeKeySize];
                    compress_ZKey = new int[encodeKeySize];
                    DfsDLLWrapper.dfsGetEncodeKey(pHeader, compress_XKey, compress_YKey, compress_ZKey);
                }
                else
                {
                    compressed = false;
                }
            }

            // general info about file
            dfsFileType = (FileType)DfsDLLWrapper.dfsGetFileType(pHeader);
            DataType    = DfsDLLWrapper.dfsGetDataType(pHeader);

            //delete value
            delVal = DfsDLLWrapper.dfsGetDeleteValFloat(pHeader);

            //statisics type
            statType = DfsDLLWrapper.dfsGetItemStatsType(pHeader);

            //Custom blocks
            DfsSimpleType iDataType   = DfsSimpleType.Float;
            int           iMiscVarNos = 0;
            IntPtr        pData       = pHeader;
            IntPtr        pNextBlock  = pHeader;
            IntPtr        pBlock      = pHeader;

            pBlock = DfsDLLWrapper.dfsGetCustomBlockRef(pHeader);

            if (pBlock.ToInt32() != 0)
            {
                DfsDLLWrapper.dfsGetCustomBlock(pBlock, out iDataType, out CustomBlockName, out iMiscVarNos, ref pData, out pNextBlock);
                switch ((DfsSimpleType)iDataType)
                {
                case DfsSimpleType.Float:
                    custBlockDataFloat = new float[iMiscVarNos];
                    Marshal.Copy(pData, custBlockDataFloat, 0, custBlockDataFloat.Length);     // copy data from pointer to array
                    break;

                case DfsSimpleType.Int:
                    custBlockDataInt = new int[iMiscVarNos];
                    Marshal.Copy(pData, custBlockDataInt, 0, custBlockDataInt.Length);     // copy data from pointer to array
                    break;

                default:
                    throw new Exception("Unsupported CustomBlock data tyoe encountered (" + iDataType + ".");
                }
                if (CustomBlockName == "MIKE_FM")
                {
                    //dfsu
                    if (custBlockDataInt.Length > 0)
                    {
                        dfsuCustBlock.NoNodesTot = custBlockDataInt[0];
                    }
                    if (custBlockDataInt.Length > 1)
                    {
                        dfsuCustBlock.NoElemTot = custBlockDataInt[1];
                    }
                    if (custBlockDataInt.Length > 2)
                    {
                        dfsuCustBlock.Dim = custBlockDataInt[2];
                    }
                    if (custBlockDataInt.Length > 3)
                    {
                        dfsuCustBlock.NoLayers = custBlockDataInt[3];
                    }
                }
                else if (CustomBlockName == "M21_Misc")
                {
                    if (custBlockDataFloat.Length > 0)
                    {
                        m21CustBlock.ori = custBlockDataFloat[0];                                //m_LITOrientation
                    }
                    if (custBlockDataFloat.Length > 1)
                    {
                        m21CustBlock.f1 = custBlockDataFloat[1];
                    }
                    if (custBlockDataFloat.Length > 2)
                    {
                        m21CustBlock.f2 = custBlockDataFloat[2];
                    }
                    if (custBlockDataFloat.Length > 3)
                    {
                        m21CustBlock.f3 = custBlockDataFloat[3];                                //m_LandValue
                    }
                    if (custBlockDataFloat.Length > 4)
                    {
                        m21CustBlock.f4 = custBlockDataFloat[4];
                    }
                    if (custBlockDataFloat.Length > 5)
                    {
                        m21CustBlock.f5 = custBlockDataFloat[5];
                    }
                    if (custBlockDataFloat.Length > 6)
                    {
                        m21CustBlock.f6 = custBlockDataFloat[6];                                //m_GISLITOrientation
                    }
                }
            }

            //time axis
            tAxisType = (TimeAxisType)DfsDLLWrapper.dfsGetTimeAxisType(pHeader);
            switch (tAxisType)
            {
            case TimeAxisType.CalendarEquidistant:
                DfsDLLWrapper.dfsGetEqCalendarAxis(pHeader, out tAxis_StartDateStr, out tAxis_StartTimeStr, out tAxis_EUMUnit, out tAxis_EUMUnitStr, out tAxis_dTStart, out tAxis_dTStep, out tAxis_nTSteps, out tAxis_indexTStart);
                break;

            case TimeAxisType.Undefined:
                DfsDLLWrapper.dfsGetEqCalendarAxis(pHeader, out tAxis_StartDateStr, out tAxis_StartTimeStr, out tAxis_EUMUnit, out tAxis_EUMUnitStr, out tAxis_dTStart, out tAxis_dTStep, out tAxis_nTSteps, out tAxis_indexTStart);
                break;

            case TimeAxisType.CalendarNonEquidistant:
                DfsDLLWrapper.dfsGetNeqCalendarAxis(pHeader, out tAxis_StartDateStr, out tAxis_StartTimeStr, out tAxis_EUMUnit, out tAxis_EUMUnitStr, out tAxis_dTStart, out tAxis_dTStep, out tAxis_nTSteps, out tAxis_indexTStart);
                break;

            case TimeAxisType.TimeEquidistant:
                DfsDLLWrapper.dfsGetEqTimeAxis(pHeader, out tAxis_EUMUnit, out tAxis_EUMUnitStr, out tAxis_dTStart, out tAxis_dTStep, out tAxis_nTSteps, out tAxis_indexTStart);
                break;

            case TimeAxisType.TimeNonEquidistant:
                DfsDLLWrapper.dfsGetNeqTimeAxis(pHeader, out tAxis_EUMUnit, out tAxis_EUMUnitStr, out tAxis_dTStart, out tAxis_dTStep, out tAxis_nTSteps, out tAxis_indexTStart);
                break;

            default:
                return(_err(tAxisType.ToString() + " not supported"));
            }

            //Projection
            Projection_type = (ProjectionType)DfsDLLWrapper.dfsGetGeoInfoType(pHeader);
            if (Projection_type == ProjectionType.Projection)
            {
                DfsDLLWrapper.dfsGetGeoInfoUTMProj(pHeader, out Projection, out Longitude, out Latitude, out Orientation);
            }

            //Dynamic Items
            int ItemCount = DfsDLLWrapper.dfsGetNoOfItems(pHeader);

            Items = new DfsItemInfo[ItemCount];
            for (int i = 1; i < Items.Length + 1; i++)
            {
                Items[i - 1]             = new DfsItemInfo();
                Items[i - 1].fileInfoRef = this;
                Items[i - 1].Read(i); // reads header
            }

            //Static Items
            rc = 0;
            int sItemNo = 0;

            while (true)
            {
                sItemNo++;
                try
                { DfsDLLWrapper.dfsFindItemStatic(pHeader, pFile, sItemNo); }
                catch
                { break; }// no more static items
            }
            if (sItemNo > 0)
            {
                staticItems = new DfsItemInfo[sItemNo - 2];
                for (int i = 0; i < staticItems.Length; i++)
                {
                    staticItems[i]             = new DfsItemInfo();
                    staticItems[i].fileInfoRef = this;
                    rc = staticItems[i].ReadStatic(i + 1); // read header
                }
                if (readStaticDataOnRead)
                {
                    rc = ReadStaticData();
                }
            }

            return(rc);
        }