Beispiel #1
0
 /**
  *  Description of the Method
  */
 public void close()
 {
     try
     {
         if (din != null)
         {
             din.close();
             //Console.WriteLine("**** CLOSED: ::: " + din);
             din = null;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
     }
 }
Beispiel #2
0
    //-----------------------------------------------------------------------
    //  Descroption: Method to open a Level2 Format file and build internal
    //               tables.
    //  Input: file      - File object for the universal format data file
    //         startFlag - unused at this time
    //-----------------------------------------------------------------------

    //public void open (File file, int startFlag) {

    /**
     *  Description of the Method
     *
     *@param  nexrad_url  Description of the Parameter
     *@param  start_flag  Description of the Parameter
     */
    public void read(string nexrad_url, int start_flag)
    {
        /*
         *  Read the file until we get an I/O exception (i.e., EOF)
         */
        try
        {
            float azi;
            float ele;
            int   i;
            int   julianDate;
            int   seconds;

            byte[] bins = new byte[2332];

            //if (file != level2File) {

            //level2File = file;
            _numberOfRecords = 0;

            //din = new RandomAccessFile (file,"r");
            //Console.WriteLine ("-----"+file+"-----");
            //Console.WriteLine ("\nLoading Data starting with record"+
            //               numberOfRecords+" Be patient!");

            try
            {
                if (nexrad_url.getProtocol().equals("file"))
                {
                    din = new ucar.unidata.io.RandomAccessFile(nexrad_url.getFile().replaceAll("%20", " "), "r");
                }
                else
                {
                    din = new ucar.unidata.io.http.HTTPRandomAccessFile(nexrad_url.toString());
                }
                din.order(ucar.unidata.io.RandomAccessFile.BIG_ENDIAN);

                Console.WriteLine("**** OPENING: " + nexrad_url + " ::: " + din);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("ERROR WITH URL: " + nexrad_url);
                return;
            }

            //Console.WriteLine("-----" + nexrad_url + "-----");
            //Console.WriteLine("\nLoading Data starting with record" +
            //      numberOfRecords + " Be patient!");

            //      Skip over the 12 byte record header which is not used

            din.skipBytes(RECORD_HEADER_SIZE);

            //      Read the date (julian from 1/1/1970) and time (milliseconds
            //      past midnight

            julianDate = din.readInt();
            seconds    = din.readInt();

            //Console.WriteLine("File header julian date [" + julianDate +
            //      "] - seconds [" + seconds + "]");

            //      }

            //    Initialize the cut fields.  Remember that the number of cuts will
            //    probably be larger than the number of true cuts since the lowest
            //    few cuts a split (surveillance and Doppler).  A true cut is
            //    basically a unique elevation.

            numberOfCuts     = 0;
            numberOfTrueCuts = 0;

            //for (cut=0;cut<20;cut++)  // s.ansari - changed to 50 in case new vcp with more scans
            for (cut = 0; cut < 50; cut++)
            {
                cutStart[cut] = -1;
            }

            //    Read the entire file and return when we get an end-of-file
            //    exception.  We assume that all level2 files contain less than
            //    MAX_LEVEL2_RECORDS.

            for (record = _numberOfRecords; record < MAX_LEVEL2_RECORDS; record++)
            {
                readHeader(record);

                //      Check for and end-of-file condition

                if (eof() != 0)
                {
                    cutStart[oldCut + 1] = record;
                    return;
                }

                //      Check to see if this is the last radial in the volume.  If so,
                //      set the end of volume flag to 1.

                if (radialStatus == 4)
                {
                    endOfVolume = 1;
                }
                else
                {
                    endOfVolume = 0;
                }

                //      Only process digital radar data messages.  Ignore the rest for
                //	now.

                if (getMessageType() == 1)
                {
                    //        Extract the azimuth and elevation angles of the radial.

                    azimuth[record]   = getAzimuth();
                    elevation[record] = getElevation();

                    //        If a new elevation cut has started, update the cut LUT

                    if (oldCut != getElevationNum())
                    {
                        if (verbose)
                        {
                            Console.WriteLine("messageSize [" + messageSize + "]");
                        }

                        if (getElevationNum() > 0)
                        {
                            if (verbose)
                            {
                                Console.WriteLine("New cut --> " + getElevationNum() +
                                                  " at record " + record);
                            }
                            oldCut = getElevationNum();
                            cutStart[getElevationNum() - 1] = record;
                            cutElevation[numberOfCuts]      = elevation[record];

                            //            We also need to maintain a table of unique elevation
                            //            cuts to account for split cuts.

                            deltaElevation = Math.Abs(elevation[record] - oldElevation);

                            if (deltaElevation > 0.1)
                            {
                                trueElevation[numberOfTrueCuts] = elevation[record];
                                numberOfTrueCuts++;
                            }

                            oldElevation           = elevation[record];
                            cutIndex[numberOfCuts] = numberOfTrueCuts;
                            numberOfCuts++;

                            if (verbose)
                            {
                                Console.WriteLine("dBZ bins [" + getBinNum(REFLECTIVITY) + "]");
                                Console.WriteLine("Vel bins [" + getBinNum(VELOCITY) + "]");
                            }
                        }
                        else
                        {
                            return;
                        }
                    }

                    _numberOfRecords++;
                }
                else
                {
                    //        Since this message doesn't contain radar data, set the
                    //        azimuth/elevation LUT table entries to -1 to indicate this
                    //        record doesn't contain radar data.

                    if (verbose)
                    {
                        Console.WriteLine("Message type " + getMessageType() + " detected");
                    }
                    azimuth[record]   = -1;
                    elevation[record] = -1;
                }
            }
            //  For EOF exceptions just print a message.
        }
        catch (Exception e)
        {
            //      Console.WriteLine (e);
        }
    }