private List <float[]> _getFloatData(string itemName, int timeStep)
        {
            float[]        itemFloatData     = null;
            List <float[]> itemFloatDataList = new List <float[]>();

            object[]       ncVars = _util.GetVariables();
            ucar.ma2.Array xData  = null;
            ucar.ma2.Array yData  = null;

            foreach (object ncVar in ncVars)
            {
                ucar.nc2.Variable var     = ((ucar.nc2.Variable)ncVar);
                string            varName = var.getFullName();

                if (varName == _settings.ZAxisName)
                {
                    yData = _util.GetAllVariableData(var);
                }
            }

            foreach (object ncVar in ncVars)
            {
                ucar.nc2.Variable var     = ((ucar.nc2.Variable)ncVar);
                string            varName = var.getFullName();

                if (varName == _settings.XAxisName)
                {
                    xData = _util.GetAllVariableData(var);
                }
            }

            foreach (object ncVar in ncVars)
            {
                ucar.nc2.Variable var     = ((ucar.nc2.Variable)ncVar);
                string            varName = var.getFullName();

                if (varName == itemName)
                {
                    List <ucar.ma2.Array> itemDataLst = _util.Get2DVariableDataTrans(var, _settings.ZLayer, _settings.ZAxisName, timeStep, _settings.TimeAxisName, _settings.XAxisName, _settings.YAxisName, _settings.TransectPoints, _settings.TransectSpaceStepsNumber);
                    for (int i = 0; i < itemDataLst.Count; i++)
                    {
                        ucar.ma2.Array itemData = itemDataLst[i];
                        itemData = _util.ProcessedVariableData(var, itemData);
                        java.util.List ncVarAtt = var.getAttributes();
                        itemFloatData = _util.GetFloatData(itemData, ncVarAtt, _fdel);
                        itemFloatDataList.Add(itemFloatData);
                    }
                }
            }
            return(itemFloatDataList);
        }
Exemple #2
0
        private float[] _getFloatData(string itemName, int timeStep, double j, double k, double lat0, double lon0, double dx, double dy)
        {
            try
            {
                float[]        itemFloatData = null;
                object[]       ncVars        = _util.GetVariables();
                ucar.ma2.Array xData         = null;
                ucar.ma2.Array yData         = null;
                ucar.ma2.Array zData         = null;

                foreach (object ncVar in ncVars)
                {
                    ucar.nc2.Variable var     = ((ucar.nc2.Variable)ncVar);
                    string            varName = var.getFullName();

                    if (varName == _settings.YAxisName)
                    {
                        yData = _util.GetAllVariableData(var);
                    }
                }

                foreach (object ncVar in ncVars)
                {
                    ucar.nc2.Variable var     = ((ucar.nc2.Variable)ncVar);
                    string            varName = var.getFullName();

                    if (varName == _settings.XAxisName)
                    {
                        xData = _util.GetAllVariableData(var);
                    }
                }

                foreach (object ncVar in ncVars)
                {
                    ucar.nc2.Variable var     = ((ucar.nc2.Variable)ncVar);
                    string            varName = var.getFullName();

                    if (varName == _settings.ZAxisName)
                    {
                        zData = _util.GetAllVariableData(var);
                    }
                }

                foreach (object ncVar in ncVars)
                {
                    ucar.nc2.Variable var     = ((ucar.nc2.Variable)ncVar);
                    string            varName = var.getFullName();

                    java.util.List varDims = ((ucar.nc2.Variable)var).getDimensions();
                    int            zPosition = -1, xAxisPosition = -1, yAxisPosition = -1;
                    for (int i = 0; i < varDims.size(); i++)
                    {
                        string dimName = ((ucar.nc2.Dimension)varDims.get(i)).getName();
                        if (_settings.ZAxisDimensionName == dimName)
                        {
                            zPosition = i;
                        }
                        if (_settings.XAxisDimensionName == dimName)
                        {
                            xAxisPosition = i;
                        }
                        if (_settings.YAxisDimensionName == dimName)
                        {
                            yAxisPosition = i;
                        }
                    }

                    if (varName == itemName)
                    {
                        ucar.ma2.Array itemData = _util.Get3DVariableData(var, _settings.ZAxisName, timeStep, _settings.TimeAxisName, _settings.XLayer, _settings.XAxisName, _settings.YLayer, _settings.YAxisName);
                        itemData = _util.ProcessedVariableData(var, itemData);
                        java.util.List ncVarAtt = var.getAttributes();
                        itemFloatData = _util.GetFloatData(itemData, xData, yData, zData, ncVarAtt, _fdel, _zValues);
                        if (_customDFSGrid)
                        {
                            //reassign the data to the grid (nearest neighbour)
                            itemFloatData = _reassignData(itemData, xData, yData, zData, ncVarAtt, _fdel, _zValues, j, k, lat0, lon0, dx, dy, xAxisPosition, yAxisPosition, zPosition);
                        }
                    }
                }
                return(itemFloatData);
            }
            catch (Exception ex)
            {
                throw new Exception("_getFloatData Error: " + ex.Message);
            }
        }
Exemple #3
0
        private void _getMinAndInterval(ucar.nc2.Variable ncDim, string minMaxStr, out double interval, out double minVal, out List <double> interpolatedVal, out List <double> originalVal, bool useDefinedDZ)
        {
            ucar.ma2.Array dataArr = _util.GetAllVariableData(ncDim);
            int            minCount = 0, maxCount = (int)dataArr.getSize() - 1;

            minVal = double.MaxValue;
            double maxVal = double.MinValue;

            double        prevVal   = 0.0;
            List <double> intervals = new List <double>();

            interpolatedVal = new List <double>();
            originalVal     = new List <double>();
            interval        = 0.0;

            if (!string.IsNullOrEmpty(minMaxStr))
            {
                minCount = Convert.ToInt32(minMaxStr.Split(':')[0]);
                maxCount = Convert.ToInt32(minMaxStr.Split(':')[1]);
            }

            java.util.List ncVarAtt   = ncDim.getAttributes();
            bool           stepExists = false;

            for (int attCount = 0; attCount < ncVarAtt.size(); attCount++)
            {
                ucar.nc2.Attribute varAtt  = (ucar.nc2.Attribute)ncVarAtt.get(attCount);
                string             attName = varAtt.getName();
                if (attName == "step")
                {
                    java.lang.Number attVal = (java.lang.Number)varAtt.getValue(0);
                    interval   = attVal.doubleValue();
                    stepExists = true;
                }
            }

            for (int dCount = minCount; dCount <= maxCount; dCount++)
            {
                ucar.ma2.Index dIndex = dataArr.getIndex();
                double         data   = dataArr.getDouble(dIndex.set(dCount));
                originalVal.Add(data);
                if (minVal >= data)
                {
                    minVal = data;
                }
                if (maxVal <= data)
                {
                    maxVal = data;
                }

                if (!stepExists)
                {
                    if (dCount > 0)
                    {
                        prevVal  = dataArr.getDouble(dIndex.set(dCount - 1));
                        interval = data - prevVal;
                        intervals.Add(interval);
                    }
                }
            }

            if (!stepExists)
            {
                if (intervals.Average() != interval)
                {
                    if (useDefinedDZ)
                    {
                        for (double min = minVal; min <= maxVal; min += Convert.ToDouble(_settings.DZ))
                        {
                            interpolatedVal.Add(min);
                        }
                        interval = Convert.ToDouble(_settings.DZ);
                    }
                    else
                    {
                        //generate a list of interpolatedVal
                        for (double min = minVal; min <= maxVal; min += intervals.Min())
                        {
                            interpolatedVal.Add(min);
                        }
                        interval = intervals.Min();
                    }
                }
            }
        }