Esempio n. 1
0
        public float[][][] Read3DFloatArray(string name)
        {
            Variable var = _file.findVariable(name);

            ucar.ma2.Array arr = var.read();

            int[] shape = arr.getShape();

            float[][][] ret = new float[shape[0]][][];

            for (int t = 0, i = 0; t < shape[0]; t++)
            {
                ret[t] = new float[shape[1]][];
                for (int y = 0; y < shape[1]; y++)
                {
                    ret[t][y] = new float[shape[2]];
                    for (int x = 0; x < shape[2]; x++, i++)
                    {
                        ret[t][y][x] = arr.getFloat(i);
                    }
                }
            }

            return(ret);
        }
Esempio n. 2
0
        public string[] ReadStringArray(string variableName)
        {
            Variable variable = _file.findVariable(variableName);

            ucar.ma2.Array array1 = variable.read();

            int[]    shape = array1.getShape();
            string[] ret   = new string[shape[0]];

            for (int c = 0, arrayIndex = 0; c < ret.Length; c++)
            {
                StringBuilder sb = new StringBuilder(shape[1]);
                for (int d = 0; d < shape[1]; d++, arrayIndex++)
                {
                    sb.Append(array1.getChar(arrayIndex));
                }
                ret[c] = sb.ToString();
            }

            return(ret);
        }
Esempio n. 3
0
        private List <DataIndex> _generateNCIndexes1D(ucar.ma2.Array sourceData, ucar.ma2.Array xData, ucar.ma2.Array yData, ucar.ma2.Index xIndex, ucar.ma2.Index yIndex, int[] resShape, int xPosition, int yPosition, java.util.List attList, List <double> xList, List <double> yList)
        {
            //assuming that the file is 1D with the same lat. or same lon.

            List <DataIndex> ncIndexes = new List <DataIndex>();

            ucar.ma2.Index resIndex = sourceData.getIndex();

            //find closest x and y points
            int[] ydataShape = yData.getShape();
            int[] xdataShape = xData.getShape();

            int yCount = 0; //static

            for (int xCount = 1; xCount < (int)resShape[xPosition]; xCount++)
            {
                double latFromNC         = 0;
                double prevLatFromNC     = 0;
                double prevPrevLatFromNC = 0;
                if (ydataShape.Length == 2)
                {
                    latFromNC     = yData.getDouble(yIndex.set(yCount, xCount));
                    prevLatFromNC = yData.getDouble(yIndex.set(yCount - 1, xCount));
                    if (yCount >= 2)
                    {
                        prevPrevLatFromNC = yData.getDouble(yIndex.set(yCount - 2, xCount));
                    }
                }
                else if (ydataShape.Length == 1)
                {
                    latFromNC = yData.getDouble(yCount);
                }

                double lonFromNC         = 0;
                double prevLonFromNC     = 0;
                double prevPrevLonFromNC = 0;
                if (xdataShape.Length == 2)
                {
                    lonFromNC     = xData.getDouble(xIndex.set(yCount, xCount));
                    prevLonFromNC = xData.getDouble(xIndex.set(yCount, xCount - 1));
                    if (xCount >= 2)
                    {
                        prevPrevLonFromNC = xData.getDouble(xIndex.set(yCount, xCount - 2));
                    }
                }
                else if (xdataShape.Length == 1)
                {
                    lonFromNC = xData.getDouble(xCount);
                }

                int rangeCount = 0;

                if (latFromNC >= yList.Min())
                {
                    rangeCount++;
                }
                if (latFromNC <= yList.Max())
                {
                    rangeCount++;
                }
                if (lonFromNC >= xList.Min())
                {
                    rangeCount++;
                }
                if (lonFromNC <= xList.Max())
                {
                    rangeCount++;
                }


                DataIndex newIndex = new DataIndex();
                newIndex.xIndex     = xCount;
                newIndex.prevXIndex = xCount - 1;
                newIndex.yIndex     = yCount;
                newIndex.prevYIndex = yCount - 1;
                newIndex.nc_X       = lonFromNC;
                newIndex.nc_Y       = latFromNC;
                newIndex.pnc_X      = prevLonFromNC;
                newIndex.pnc_Y      = prevLatFromNC;

                newIndex.data     = sourceData.getDouble(resIndex.set(xCount));
                newIndex.prevData = sourceData.getDouble(resIndex.set(xCount - 1));

                newIndex.lonFromDfs = new List <double>();
                foreach (double xPoint in xList)
                {
                    if (xPoint >= prevLonFromNC && xPoint <= lonFromNC)
                    {
                        newIndex.lonFromDfs.Add(xPoint);
                    }
                    else if (xPoint >= prevPrevLonFromNC && xPoint <= lonFromNC)
                    {
                        newIndex.lonFromDfs.Add(xPoint);
                    }
                    else if (xPoint == lonFromNC)
                    {
                        newIndex.lonFromDfs.Add(xPoint);
                    }
                }

                newIndex.latFromDfs = new List <double>();
                foreach (double yPoint in yList)
                {
                    if (yPoint >= prevLatFromNC && yPoint <= latFromNC)
                    {
                        newIndex.latFromDfs.Add(yPoint);
                    }
                    else if (yPoint >= prevPrevLatFromNC && yPoint <= latFromNC)
                    {
                        newIndex.latFromDfs.Add(yPoint);
                    }
                    else if (yPoint == latFromNC)
                    {
                        newIndex.latFromDfs.Add(yPoint);
                    }
                }

                if (_util.IsValueValid(attList, newIndex.data) && rangeCount == 4)
                {
                    ncIndexes.Add(newIndex);
                }
            }


            return(ncIndexes);
        }