コード例 #1
0
ファイル: ConvertDfs3ToNc.cs プロジェクト: DHI/netcdf-client
        public void dfs3ToNc()
        {
            //strategy:
            // 1) read the dfs2 file and dissect them into dimensions, variables and attributes with cf convention
            // 2) write the netcdf file

            DfsUtilities df_in = new DfsUtilities();
            int          rc    = df_in.ReadDfsFile(_settings.InputFileName); //read header info for input file

            if (rc != 0)
            {
                throw new Exception(df_in.errMsg);
            }

            //create netcdf file
            ucar.nc2.NetcdfFileWriteable newNetcdfFile = ucar.nc2.NetcdfFileWriteable.createNew(_settings.OutputFileName, false);

            //create dimensions (for dfs3 - time, x, y and z)
            ucar.nc2.Dimension timeDim, xDim, yDim, zDim = null;
            _addDimensionVariables(df_in, newNetcdfFile, out timeDim, out xDim, out yDim, out zDim);

            //adding item variables
            for (int itemCount = 0; itemCount < _settings.Variables.Count; itemCount++)
            {
                if (_settings.IsVariablesSelected[itemCount])
                {
                    _addItemVariable(df_in.Items[itemCount], newNetcdfFile, timeDim, xDim, yDim, zDim, df_in.delVal, itemCount);
                }
            }

            //global attributes
            _addGlobalAttributes(df_in, newNetcdfFile);

            //write data to ncFile
            _writeDimensionData(df_in, newNetcdfFile);
            _writeItemData(df_in, newNetcdfFile);

            //close the ncFile
            newNetcdfFile.close();
        }
コード例 #2
0
ファイル: ConvertDfs3ToNc.cs プロジェクト: DHI/netcdf-client
        private void _addItemVariable(DfsItemInfo dfsItem, ucar.nc2.NetcdfFileWriteable newNetcdfFile, ucar.nc2.Dimension timeDim, ucar.nc2.Dimension xDim, ucar.nc2.Dimension yDim, ucar.nc2.Dimension zDim, float delVal, int itemCount)
        {
            java.util.ArrayList varDims = new java.util.ArrayList();
            varDims.add(timeDim);
            varDims.add(xDim);
            varDims.add(yDim);
            varDims.add(zDim);

            newNetcdfFile.addVariable(dfsItem.Name.Replace(' ', '_'), ucar.ma2.DataType.FLOAT, varDims);
            newNetcdfFile.addVariableAttribute(dfsItem.Name.Replace(' ', '_'), "units", _settings.VariablesMappings[itemCount].CFStandardUnit);
            newNetcdfFile.addVariableAttribute(dfsItem.Name.Replace(' ', '_'), "long_name", _settings.VariablesMappings[itemCount].CFStandardName);
            if (!String.IsNullOrEmpty(_settings.VariablesMappings[itemCount].CFStandardDesc))
            {
                newNetcdfFile.addVariableAttribute(dfsItem.Name.Replace(' ', '_'), "description", _settings.VariablesMappings[itemCount].CFStandardDesc);
            }
            newNetcdfFile.addVariableAttribute(dfsItem.Name.Replace(' ', '_'), "missing_value", new java.lang.Float(delVal));
            newNetcdfFile.addVariableAttribute(dfsItem.Name.Replace(' ', '_'), "DHIUnitName", dfsItem.EUMUnitString);
        }
コード例 #3
0
ファイル: ConvertDfs3ToNc.cs プロジェクト: DHI/netcdf-client
        private void _addDimensionVariables(DfsUtilities df_in, ucar.nc2.NetcdfFileWriteable newNetcdfFile, out ucar.nc2.Dimension timeDim, out ucar.nc2.Dimension xDim, out ucar.nc2.Dimension yDim, out ucar.nc2.Dimension zDim)
        {
            timeDim = newNetcdfFile.addDimension("time", df_in.tAxis_nTSteps);
            xDim    = newNetcdfFile.addDimension("lon", df_in.Items[0].nPointsX);
            yDim    = newNetcdfFile.addDimension("lat", df_in.Items[0].nPointsY);
            zDim    = newNetcdfFile.addDimension("depth", df_in.Items[0].nPointsZ);

            java.util.ArrayList dims = new java.util.ArrayList();
            dims.add(timeDim);
            newNetcdfFile.addVariable(_settings.TimeAxisName, ucar.ma2.DataType.FLOAT, dims);
            string unit   = "";
            int    dtStep = (int)df_in.tAxis_dTStep;

            switch (dtStep)
            {
            case 31556926:
                unit = "years since ";
                break;

            case 2629743:
                unit = "months since ";
                break;

            case 604800:
                unit = "weeks since ";
                break;

            case 86400:
                unit = "days since ";
                break;

            case 3600:
                unit = "hours since ";
                break;

            case 60:
                unit = "minutes since ";
                break;

            case 1:
                unit = "seconds since ";
                break;
            }
            newNetcdfFile.addVariableAttribute(_settings.TimeAxisName, "units", unit + df_in.tAxis_StartDateStr + " " + df_in.tAxis_StartTimeStr);
            newNetcdfFile.addVariableAttribute(_settings.TimeAxisName, "long_name", "time");

            dims = new java.util.ArrayList();
            dims.add(xDim);
            newNetcdfFile.addVariable(_settings.XAxisName, ucar.ma2.DataType.FLOAT, dims);
            newNetcdfFile.addVariableAttribute(_settings.XAxisName, "units", "degrees east");//df_in.Items[0].axisEUMUnitString);
            newNetcdfFile.addVariableAttribute(_settings.XAxisName, "long_name", "longitude");
            newNetcdfFile.addVariableAttribute(_settings.XAxisName, "axis", "x");
            newNetcdfFile.addVariableAttribute(_settings.XAxisName, "DHIUnitName", df_in.Items[0].axisEUMUnitString);
            newNetcdfFile.addVariableAttribute(_settings.XAxisName, "projection", df_in.Projection);

            dims = new java.util.ArrayList();
            dims.add(yDim);
            newNetcdfFile.addVariable(_settings.YAxisName, ucar.ma2.DataType.FLOAT, dims);
            newNetcdfFile.addVariableAttribute(_settings.YAxisName, "units", "degrees north");//df_in.Items[0].axisEUMUnitString);
            newNetcdfFile.addVariableAttribute(_settings.YAxisName, "long_name", "latitude");
            newNetcdfFile.addVariableAttribute(_settings.YAxisName, "axis", "y");
            newNetcdfFile.addVariableAttribute(_settings.YAxisName, "DHIUnitName", df_in.Items[0].axisEUMUnitString);
            newNetcdfFile.addVariableAttribute(_settings.YAxisName, "projection", df_in.Projection);

            dims = new java.util.ArrayList();
            dims.add(zDim);
            newNetcdfFile.addVariable(_settings.ZAxisName, ucar.ma2.DataType.FLOAT, dims);
            newNetcdfFile.addVariableAttribute(_settings.ZAxisName, "units", df_in.Items[0].axisEUMUnitString);
            newNetcdfFile.addVariableAttribute(_settings.ZAxisName, "long_name", "depth");
            newNetcdfFile.addVariableAttribute(_settings.ZAxisName, "DHIUnitName", df_in.Items[0].axisEUMUnitString);
            newNetcdfFile.addVariableAttribute(_settings.ZAxisName, "projection", df_in.Projection);
        }
コード例 #4
0
ファイル: ConvertDfs0ToNc.cs プロジェクト: DHI/netcdf-client
        private void _addDimensionVariables(DfsUtilities df_in, ucar.nc2.NetcdfFileWriteable newNetcdfFile, out ucar.nc2.Dimension timeDim)
        {
            timeDim = newNetcdfFile.addDimension(_settings.TimeAxisName, df_in.tAxis_nTSteps);

            java.util.ArrayList dims = new java.util.ArrayList();
            dims.add(timeDim);
            newNetcdfFile.addVariable(_settings.TimeAxisName, ucar.ma2.DataType.FLOAT, dims);
            string unit   = "";
            int    dtStep = (int)df_in.tAxis_dTStep;

            switch (dtStep)
            {
            case 31556926:
                unit = "years since ";
                break;

            case 2629743:
                unit = "months since ";
                break;

            case 604800:
                unit = "weeks since ";
                break;

            case 86400:
                unit = "days since ";
                break;

            case 3600:
                unit = "hours since ";
                break;

            case 60:
                unit = "minutes since ";
                break;

            case 1:
                unit = "seconds since ";
                break;
            }
            newNetcdfFile.addVariableAttribute(_settings.TimeAxisName, "units", unit + df_in.tAxis_StartDateStr + " " + df_in.tAxis_StartTimeStr);
            newNetcdfFile.addVariableAttribute(_settings.TimeAxisName, "long_name", "time");
        }