Exemple #1
0
        public int WriteToFile(string dfsFileName)
        {
            //create header
            FileType d = dfsFileType;

            pHeader = DfsDLLWrapper.dfsHeaderCreate(d, FileTitle, "DfsFileInfo", 1, Items.Length, statType);

            DfsDLLWrapper.dfsSetDataType(pHeader, DataType);

            //delval
            DfsDLLWrapper.dfsSetDeleteValFloat(pHeader, delVal);

            int rc = 0;

            switch (CustomBlockName)
            {
            case "MIKE_FM":
                int[] dfsuCBData = new int[4];
                dfsuCBData[0] = dfsuCustBlock.NoNodesTot;
                dfsuCBData[1] = dfsuCustBlock.NoElemTot;
                dfsuCBData[2] = dfsuCustBlock.Dim;
                dfsuCBData[3] = dfsuCustBlock.NoLayers;
                DfsDLLWrapper.dfsAddCustomBlock(pHeader, "MIKE_FM", dfsuCBData);
                break;

            case "M21_Misc":
                float[] dM21CBData = new float[7];
                dM21CBData[0] = (float)Orientation;
                dM21CBData[1] = m21CustBlock.f1;
                dM21CBData[2] = m21CustBlock.f2;
                dM21CBData[3] = m21CustBlock.f3;
                dM21CBData[4] = m21CustBlock.f4;
                dM21CBData[5] = m21CustBlock.f5;
                dM21CBData[6] = m21CustBlock.f6;
                DfsDLLWrapper.dfsAddCustomBlock(pHeader, "M21_Misc", dM21CBData);
                break;

            case "Unknown":
                break;

            default:
                //JdfsMisc.log("Warning: unsupported CustomBlockName encountered (" + CustomBlockName + "). Custom block not written.");
                break;
            }

            //projection
            if (Projection_type == ProjectionType.Projection)
            {
                DfsDLLWrapper.dfsSetGeoInfoUTMProj(pHeader, Projection, Longitude, Latitude, Orientation);
            }

            //timeaxis
            switch (this.tAxisType)
            {
            case TimeAxisType.CalendarEquidistant:
                DfsDLLWrapper.dfsSetEqCalendarAxis(pHeader, this.tAxis_StartDateStr, this.tAxis_StartTimeStr, (int)tAxis_EUMUnit, tAxis_dTStart, this.tAxis_dTStep, this.tAxis_indexTStart);
                break;

            case TimeAxisType.CalendarNonEquidistant:
                DfsDLLWrapper.dfsSetNeqCalendarAxis(pHeader, this.tAxis_StartDateStr, this.tAxis_StartTimeStr, (int)tAxis_EUMUnit, this.tAxis_dTStart, this.tAxis_indexTStart);
                break;

            default:
                _err("write of " + tAxisType.ToString() + " not supported");
                break;
            }

            if (compressed)
            {
                if ((compress_XKey.Length < 1) || (compress_XKey.Length != compress_YKey.Length || compress_XKey.Length != compress_ZKey.Length))
                {
                    _err("Compress keys does not have same length or is empty. Compression disabled.");
                    compressed = false;
                }
                else
                {
                    DfsDLLWrapper.dfsItemEnableCompression(pHeader);
                    DfsDLLWrapper.dfsSetEncodeKey(pHeader, compress_XKey, compress_YKey, compress_ZKey, compress_XKey.Length);
                }
            }

            //Dynamic Items
            for (int i = 1; i < Items.Length + 1; i++)
            {
                Items[i - 1].fileInfoRef = this;
                rc = Items[i - 1].Write(i);
                if (rc != 0)
                {
                    return(rc);
                }
            }

            //Static Items
            if (staticItems != null)
            {
                for (int i = 1; i < staticItems.Length + 1; i++)
                {
                    staticItems[i - 1].fileInfoRef = this;
                    rc = staticItems[i - 1].WriteStatic(i);
                    if (rc != 0)
                    {
                        return(rc);
                    }
                }
            }

            pFile = (IntPtr)0;
            DfsDLLWrapper.dfsFileCreate(dfsFileName, pHeader, out pFile);

            //write static data
            if (staticItems != null && staticItems.Length > 0 && writeStaticDataOnWrite)
            {
                rc = WriteStaticData();
                if (rc != 0)
                {
                    return(rc);
                }
            }

            m_fileName = dfsFileName;
            return(rc);
        }