Exemple #1
0
 //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
 private System.String getGDSkey(Grib1GridDefinitionSection gds, System.Collections.Hashtable gdsCounter)
 {
     System.String key = gds.CheckSum;
     // only Lat/Lon grids can have > 1 GDSs
     if (gds.GridType == 0 || gds.GridType == 4)
     {
         if (!gdsHM.ContainsKey(key))
         {
             // check if gds is already saved
             gdsHM[key] = gds;
         }
     }
     else if (!gdsHM.ContainsKey(key))
     {
         // check if gds is already saved
         gdsHM[key] = gds;
         gdsCounter[key] = "1";
     }
     else
     {
         // increment the counter for this GDS
         //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapget_javalangObject'"
         int count = System.Int32.Parse((System.String) gdsCounter[key]);
         gdsCounter[key] = System.Convert.ToString(++count);
     }
     return key;
 }
Exemple #2
0
        /// <summary> scans a Grib file to gather information that could be used to
        /// create an index or dump the metadata contents.
        /// 
        /// </summary>
        /// <param gridTemplateName="getProducts">products have enough information for data extractions
        /// </param>
        /// <param gridTemplateName="oneRecord">returns after processing one record in the Grib file
        /// </param>
        /// <throws>  NotSupportedException </throws>
        public void scan(bool getProducts, bool oneRecord)
        {
            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
            // stores the number of times a particular GDS is used
            //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
            System.Collections.Hashtable gdsCounter = new System.Collections.Hashtable();
            Grib1ProductDefinitionSection pds = null;
            Grib1GridDefinitionSection gds = null;
            long startOffset = -1;

            //System.out.println("file position =" + gribStream.Position);
            while (raf.Position < raf.Length)
            {
                if (seekHeader(raf, raf.Length, out startOffset))
                {
                    // Read Section 0 Indicator Section
                    Grib1IndicatorSection is_Renamed = new Grib1IndicatorSection(raf);
                    //System.out.println( "Grib record lengthOfSection=" + is.getGribLength());
                    // EOR (EndOfRecord) calculated so skipping data sections is faster
                    long EOR = raf.Position + is_Renamed.GribLength - is_Renamed.Length;

                    // Read Section 1 Product Definition Section PDS
                    pds = new Grib1ProductDefinitionSection(raf);
                    if (pds.LengthErr)
                        continue;

                    if (pds.gdsExists())
                    {
                        // Read Section 2 Grid Definition Section GDS
                        gds = new Grib1GridDefinitionSection(raf);
                    }
                    else
                    {
                        // GDS doesn't exist so make one
                        //System.out.println("GribRecord: No GDS included.");
                        //System.out.println("Process ID:" + pds.getProcess_Id() );
                        //System.out.println("Grid ID:" + pds.getGrid_Id() );
                        gds = (Grib1GridDefinitionSection) new Grib1Grid(pds);
                    }
                    // obtain BMS or BDS offset in the file for this product
                    long dataOffset = 0;
                    if (pds.Center == 98)
                    {
                        // check for ecmwf offset by 1 bug
                        int length = (int)GribNumbers.uint3(raf); // should be lengthOfSection of BMS
                        if ((length + raf.Position) < EOR)
                        {
                            dataOffset = raf.Position - 3; // ok
                        }
                        else
                        {
                            dataOffset = raf.Position - 2;
                        }
                    }
                    else
                    {
                        dataOffset = raf.Position;
                    }
                    // position filePointer to EndOfRecord
                    raf.Seek(EOR, System.IO.SeekOrigin.Begin);
                    //System.out.println("file offset = " + gribStream.Position);

                    // assume scan ok
                    if (getProducts)
                    {
                        Grib1Product gp = new Grib1Product(header, pds, getGDSkey(gds, gdsCounter), dataOffset, raf.Position);
                        products.Add(gp);
                    }
                    else
                    {
                        Grib1Record gr = new Grib1Record(header, is_Renamed, pds, gds, dataOffset, raf.Position, startOffset);
                        records.Add(gr);
                    }
                    if (oneRecord)
                        return ;

                    // early return because ending "7777" missing
                    if (raf.Position > raf.Length)
                    {
                        raf.Seek(0, System.IO.SeekOrigin.Begin);
                        System.Console.Error.WriteLine("Grib1Input: possible file corruption");
                        checkGDSkeys(gds, gdsCounter);
                        return ;
                    }
                } // end if seekHeader
                //System.out.println( "gribStream.Position=" + gribStream.Position);
                //System.out.println( "gribStream.Length=" + gribStream.Length );
            } // end while gribStream.Position < gribStream.Length
            //System.out.println("GribInput: processed in " +
            //   (System.currentTimeMillis()- start) + " milliseconds");
            checkGDSkeys(gds, gdsCounter);
            return ;
        }
Exemple #3
0
 //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
 private void checkGDSkeys(Grib1GridDefinitionSection gds, System.Collections.Hashtable gdsCounter)
 {
     // lat/lon grids can have > 1 GDSs
     if (gds.GridType == 0 || gds.GridType == 4)
     {
         return ;
     }
     System.String bestKey = "";
     int count = 0;
     // find bestKey with the most counts
     //UPGRADE_TODO: Method 'java.util.HashMap.keySet' was converted to 'SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapkeySet'"
     //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
     for (System.Collections.IEnumerator it = new SupportClass.HashSetSupport(gdsCounter.Keys).GetEnumerator(); it.MoveNext(); )
     {
         //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
         System.String key = (System.String) it.Current;
         //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapget_javalangObject'"
         int gdsCount = System.Int32.Parse((System.String) gdsCounter[key]);
         if (gdsCount > count)
         {
             count = gdsCount;
             bestKey = key;
         }
     }
     // remove best key from gdsCounter, others will be removed from gdsHM
     gdsCounter.Remove(bestKey);
     // remove all GDSs using the gdsCounter
     //UPGRADE_TODO: Method 'java.util.HashMap.keySet' was converted to 'SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapkeySet'"
     //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
     for (System.Collections.IEnumerator it = new SupportClass.HashSetSupport(gdsCounter.Keys).GetEnumerator(); it.MoveNext(); )
     {
         //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
         System.String key = (System.String) it.Current;
         gdsHM.Remove(key);
     }
     // reset GDS keys in products too
     for (int i = 0; i < products.Count; i++)
     {
         Grib1Product g1p = (Grib1Product) products[i];
         g1p.GDSkey = bestKey;
     }
     return ;
 }
Exemple #4
0
 public Grib1Record(System.String hdr, Grib1IndicatorSection aIs, Grib1ProductDefinitionSection aPds, Grib1GridDefinitionSection aGds, long offset, long recOffset, long startOfRecordOffset)
 {
     header = hdr;
     is_Renamed = aIs;
     pds = aPds;
     gds = aGds;
     dataOffset = offset;
     endRecordOffset = recOffset;
     recordOffset = startOfRecordOffset;
 }