Beispiel #1
0
 /**
  * <summary>Notify observers of a single data read.</summary>
  * <param param="field">The field that has been read.</param>
  * <param param="value">The value that has been read.</param>
  * <param param="coordinates">The data coordinates within the matrix in (layer, row, column) ordering for 3D matrices or (row, column) for 2D matrices.
  * <br/>If data is a single field and not a matrix, the size of the coordinate array is 0.</param>
  */
 private void NotifyObserversDataRead(Dym2Field field, Object value, int[] coordinates)
 {
     // Notify from last to first.
     foreach (IDymReadObserver observer in observers.AsEnumerable().Reverse())
     {
         observer.DataRead(field, value, coordinates);
     }
 }
Beispiel #2
0
 /**
  * <summary>Notify observers of a single data read.</summary>
  * <param param="field">The field that has been read.</param>
  * <param param="value">The value that has been read.</param>
  */
 private void NotifyObserversDataRead(Dym2Field field, Object value)
 {
     NotifyObserversDataRead(field, value, new int[0]);
 }
Beispiel #3
0
            public void DataRead(Dym2Field field, Object value, int[] coordinates)
            {
                switch (field)
                {
                case Dym2Field.IDFUNC:
                    Dym2Stretching idFunc = (Dym2Stretching)((int)value);
                    Console.Out.Write("Strecthing: ");
                    switch (idFunc)
                    {
                    case Dym2Stretching.NONE:
                        Console.Out.WriteLine("None");
                        break;

                    case Dym2Stretching.PARALLEL:
                        Console.Out.WriteLine("Parallel");
                        break;

                    case Dym2Stretching.GRAVITY:
                        Console.Out.WriteLine("Gravity Sink");
                        break;

                    default:
                        Console.Out.WriteLine("Unknown");
                        break;
                    }
                    break;

                case Dym2Field.NLONG:
                    nlong = (int)value;
                    Console.Out.WriteLine("Longitude records " + nlong);
                    break;

                case Dym2Field.NLAT:
                    nlat = (int)value;
                    Console.Out.WriteLine("Latitude records " + nlat);
                    break;

                case Dym2Field.NLEVEL:
                    nlevel = (int)value;
                    Console.Out.WriteLine("Time/depth records " + nlevel);
                    break;

                case Dym2Field.START_DATE:
                    Console.Out.WriteLine("Start date " + (float)value);
                    break;

                case Dym2Field.END_DATE:
                    Console.Out.WriteLine("End date " + (float)value);
                    break;

                case Dym2Field.MAX_VALUE:
                    Console.Out.WriteLine("Start date " + (float)value);
                    break;

                case Dym2Field.MIN_VALUE:
                    Console.Out.WriteLine("End date " + (float)value);
                    break;

                case Dym2Field.XLON:
                    //Console.Out.Write((float)value);
                    //Console.Out.Write(" ");
                    //if (coordinates[1] == nlong - 1)
                    //{
                    //    Console.Out.WriteLine();
                    //}
                    break;

                case Dym2Field.YLAT:
                    //Console.Out.Write((float)value);
                    //Console.Out.Write(" ");
                    //if (coordinates[1] == nlat - 1)
                    //{
                    //    Console.Out.WriteLine();
                    //}
                    break;

                case Dym2Field.ZLEVEL:
                    //Console.Out.Write((float)value);
                    //Console.Out.Write(" ");
                    //if (coordinates[0] == nlevel - 1)
                    //{
                    //    Console.Out.WriteLine();
                    //}
                    break;

                case Dym2Field.MSKSP:
                    //Console.Out.Write((int) value);
                    //Console.Out.Write(" ");
                    //if (coordinates[1] == nlong -1)
                    //{
                    //    Console.Out.WriteLine();
                    //}
                    break;

                case Dym2Field.DATA:
                    //Console.Out.Write((float)value);
                    //Console.Out.Write(" ");
                    //if (coordinates[2] == nlong - 1)
                    //{
                    //    Console.Out.WriteLine();
                    //}
                    break;
                }
                ;
            }
Beispiel #4
0
        /**
         * <summary>Gets the offset of a particular field in the file.
         * <br/>When querying offset for non matrix fields, parameters can all be 0.</summary>
         * <param name="nlong">Number of longitudinal records.</param>
         * <param name="nlat">Number of latitudinal records.</param>
         * <param name="nlevel">Number of time/depth records.</param>
         * <returns>The offset within the file.</returns>
         */
        public static int GetOffset(Dym2Field field, int nlong, int nlat, int nlevel)
        {
            int result = 0;

            switch (field)
            {
            case Dym2Field.DATA:
                result += Dym2Constants.WORD_SIZE * nlat * nlong;
                goto case Dym2Field.MSKSP;

            case Dym2Field.MSKSP:
                result += Dym2Constants.WORD_SIZE * nlevel;
                goto case Dym2Field.ZLEVEL;

            case Dym2Field.ZLEVEL:
                result += Dym2Constants.WORD_SIZE * nlong * nlat;
                goto case Dym2Field.YLAT;

            case Dym2Field.YLAT:
                result += Dym2Constants.WORD_SIZE * nlat * nlong;
                goto case Dym2Field.XLON;

            case Dym2Field.XLON:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.END_DATE;

            case Dym2Field.END_DATE:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.START_DATE;

            case Dym2Field.START_DATE:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.NLEVEL;

            case Dym2Field.NLEVEL:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.NLAT;

            case Dym2Field.NLAT:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.NLONG;

            case Dym2Field.NLONG:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.MAX_VALUE;

            case Dym2Field.MAX_VALUE:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.MIN_VALUE;

            case Dym2Field.MIN_VALUE:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.IDFUNC;

            case Dym2Field.IDFUNC:
                result += Dym2Constants.WORD_SIZE;
                goto case Dym2Field.MAGIC;

            case Dym2Field.MAGIC:
                result += 0;
                break;
            }
            return(result);
        }
Beispiel #5
0
        /**
         * <summary>Implement IDymReadObserver.</summary>
         */
        public void DataRead(Dym2Field field, Object value, int[] coordinates)
        {
            switch (field)
            {
            case Dym2Field.NLONG:
                nlong = (int)value;
                Console.Out.WriteLine(String.Format("Nlong: {0}", nlong));
                break;

            case Dym2Field.NLAT:
                nlat = (int)value;
                Console.Out.WriteLine(String.Format("Nlat: {0}", nlat));
                break;

            case Dym2Field.NLEVEL:
                nlevel = (int)value;
                Console.Out.WriteLine(String.Format("Nlevel: {0}", nlevel));
                totalExports = nlong * nlat * nlevel;
                break;

            case Dym2Field.MIN_VALUE:
                Console.Out.WriteLine(String.Format("Min value: {0}", (float)value));
                break;

            case Dym2Field.MAX_VALUE:
                Console.Out.WriteLine(String.Format("Max value: {0}", (float)value));
                break;

            case Dym2Field.START_DATE:
                Console.Out.WriteLine(String.Format("Start date: {0}", (float)value));
                break;

            case Dym2Field.END_DATE:
                Console.Out.WriteLine(String.Format("End date: {0}", (float)value));
                break;

            case Dym2Field.XLON:
                // @todo This will not be correct if idfunc is not 0 or 1.
                if (xlon == null)
                {
                    xlon = new float[nlong];
                }
                xlon[coordinates[1]] = (float)value;
                break;

            case Dym2Field.YLAT:
                // @todo This will not be correct if idfunc is not 0 or 1.
                if (ylat == null)
                {
                    ylat = new float[nlat];
                }
                if (coordinates[1] == 0)
                {
                    ylat[coordinates[0]] = (float)value;
                }
                break;

            case Dym2Field.ZLEVEL:
                if (zlevel == null)
                {
                    zlevel = new float[nlevel];
                }
                zlevel[coordinates[0]] = (float)value;
                break;

            case Dym2Field.MSKSP:
                break;

            case Dym2Field.DATA:
                float val       = (float)value;
                float longitude = xlon[coordinates[2]];
                float latitude  = ylat[coordinates[1]];
                float time      = zlevel[coordinates[0]];
                dateBuffer = Dym2Utils.ToIntDate(time, dateBuffer);
                //String line = String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", dateBuffer[0], dateBuffer[1] + 1, latitude, longitude, val, exportedCells);
                String line = String.Format("{0}\t{1}\t{2}\t{3}\t{4}", dateBuffer[0], dateBuffer[1] + 1, latitude, longitude, val);
                if (output == null)
                {
                    output = new StreamWriter(File.Open(path, FileMode.Create));
                }
                output.WriteLine(line);
                exportedCells++;
                break;
            }
            ;
        }