Package ucar.unidata.io

Examples of ucar.unidata.io.RandomAccessFile


        //System.out.println(now.toString() + " ... Start of TestGrib2GetData");

        // Reading of grib data must be inside a try-catch block
        try {
            // Create RandomAccessFile instance
            RandomAccessFile raf       = null;
            PrintStream      ps        = System.out;
            long             GdsOffset = 0;
            long             PdsOffset = 0;

            // input file and Gds/Pds Offsets given
            if (args.length == 1) {
                // Create RandomAccessFile
                raf = new RandomAccessFile(args[0], "r");
                raf.order(RandomAccessFile.BIG_ENDIAN);
                //GdsOffset = Long.parseLong(args[1]);
                //PdsOffset = Long.parseLong(args[2]);
            } else {
                System.exit(0);
            }
            if (args.length == 4) {
                ps = new PrintStream(
                    new BufferedOutputStream(
                        new FileOutputStream(args[3], false)));
            }
            Grib2Data g2d    = new Grib2Data(raf);
            // open index file
            InputStream ios = open( GribIndexName.getCurrentSuffix(args[ 0 ] ) );

    long start = System.currentTimeMillis();

    BufferedReader dataIS =
            new BufferedReader(new InputStreamReader(ios));

    // section 1 - global attributes
    while (true) {
      String line = dataIS.readLine();
      if (line == null || line.length() == 0) { // 0 length/corrupted index
        break;
      }
      if (line.startsWith("--")) {
        break;
      }
    }

    // section 2 -- grib records
    while (true) {
      String line = dataIS.readLine();
      if (line == null || line.length() == 0) { // 0 length/corrupted index
        break;
      }
      if (line.startsWith("--")) {
        break;
      }

      StringTokenizer stoke = new StringTokenizer(line);

      String productType = stoke.nextToken();
      String discipline = stoke.nextToken();
      String category = stoke.nextToken();
      String param = stoke.nextToken();
      String typeGenProcess = stoke.nextToken();
      String levelType1 = stoke.nextToken();
      String levelValue1 = stoke.nextToken();
      String levelType2 = stoke.nextToken();
      String levelValue2 = stoke.nextToken();
      String refTime = stoke.nextToken();
      String foreTime = stoke.nextToken();
      String gdsKey = stoke.nextToken();
      GdsOffset = Long.parseLong( stoke.nextToken() );
      PdsOffset = Long.parseLong( stoke.nextToken() );
            float     data[] = g2d.getData(GdsOffset, PdsOffset, 0);

            if (data != null) {
                System.err.println("OK "+ line );
/*
                int row = 0;
                for (int j = 0; j < data.length; j++) {
                    //if( j % 800 == 0 ) // used to test quasi data
                    //ps.println( "row ="+ row++ );
                    ps.println("data[ " + j + " ]=" + data[j]);
                }
*/
            } else {
                System.err.println("No data returned "+ line );
            }
        }
            raf.close();
            ps.close();

            // Catch thrown errors from Grib2GetData
        } catch (FileNotFoundException noFileError) {
            System.err.println("FileNotFoundException : " + noFileError);
View Full Code Here


   * .
   *
   * @throws IOException
   */
  public final void testEdition() throws IOException {
    RandomAccessFile raf;
    int edition = 0;
    System.out.println("Testing GRIB edition of ndfd.wmo");
    raf = new RandomAccessFile(dataPath + "ndfd.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("ndfd.wmo edition", 2, edition);

    System.out.println("Testing GRIB edition of eta2.wmo");
    raf = new RandomAccessFile(dataPath + "eta2.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("eta2.wmo edition", 2, edition);

    System.out.println("Testing GRIB edition of AVN.5deg.wmo");
    raf = new RandomAccessFile(dataPath + "AVN.5deg.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("eta2.wmo edition", 2, edition);

    System.out.println("Testing GRIB edition of CLDGRIB2.2005040905");
    raf = new RandomAccessFile(dataPath + "CLDGRIB2.2005040905", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("eta2.wmo edition", 2, edition);
  }
View Full Code Here

    return true;
  }

  private boolean switchToCompleteGrib()
  {
    RandomAccessFile input = null, output = null;
    try {
    // read in extra data
    input = new RandomAccessFile( dataFile.getPath() +".extra", "r");
    byte[] extra = new byte[ (int) input.length()];
    input.read( extra );
    input.close();

    output = new RandomAccessFile( dataFile.getPath(), "rw");
    output.seek( output.length());
    output.write( extra );
    output.close();

    } catch (Exception e ) {
      fail( "Failed to add file [" + input.getLocation() + "] to  file [" + dataFile.getPath() + "]: " + e.getMessage());
      return false;
    }

    return true;
  }
View Full Code Here

  private boolean gribAppend13_18() { return gribAppend( dataSuffix13_18); }
  private boolean gribAppend19_21() { return gribAppend( dataSuffix19_21); }

  private boolean gribAppend( String suffix )
  {
    RandomAccessFile input = null, output = null;
    try
    {
      // read in extra data
      input = new RandomAccessFile( dataFile.getPath() + suffix, "r" );
      byte[] extra = new byte[(int) input.length()];
      input.read( extra );
      input.close();

      output = new RandomAccessFile( dataFile.getPath(), "rw" );
      output.seek( output.length() );
      output.write( extra );
      output.close();

    }
    catch ( Exception e )
    {
      fail( "Failed to add file [" + input.getLocation() + "] to  file [" + dataFile.getPath() + "]: " + e.getMessage() );
      return false;
    }

    return true;
  }
View Full Code Here

  private int readBufr(String filename) throws IOException {
    System.out.printf("%n***READ bufr %s%n", filename);
    int count = 0;
    int totalObs = 0;
    RandomAccessFile raf = null;
    try {
      raf = new RandomAccessFile(filename, "r");

      MessageScanner scan = new MessageScanner(raf);
      while (scan.hasNext()) {
        try {
         
          Message m = scan.next();
          if (m == null) continue;
          int nobs = m.getNumberDatasets();
          System.out.printf(" %3d nobs = %4d %s", count++, nobs, m.getHeader());
          if (m.isTablesComplete()) {
            if (m.isBitCountOk()) {
              totalObs += nobs;
              System.out.printf("%n");
            } else
              System.out.printf(" BITS NOT OK%n");                                                          
          } else
            System.out.printf(" TABLES NOT COMPLETE%n");

        } catch (Exception e) {
          System.out.printf(" CANT READ %n");
          e.printStackTrace();
        }

      }

    } finally {
      if (raf != null)
        raf.close();
    }

    return totalObs;
  }
View Full Code Here

*/
public class TestReadIDD extends TestCase {

  public void testReadSamples() throws IOException {
    String location = TestAll.cdmUnitTestDir + "bufr/sample.bufr";
    RandomAccessFile raf = new RandomAccessFile(location, "r");
    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {
      Message m = scan.next();
      if (m == null) continue;
View Full Code Here

          return new File(filePath).getParentFile().getParentFile();
        }

        private void transfer(String dest, String driver, LicenseDialog dialog)
            throws IOException {
          RandomAccessFile out = null;
          RandomAccessFile in = null;
          try {
            String fromPath = new File(dialog.getPath(),driver).getPath();
           
            String toPath = new File(dest, driver).getPath();
            out = new RandomAccessFile(toPath, "rw");
            in = new RandomAccessFile(fromPath.trim(), "r");

            out.seek(0);
            byte[] cs = new byte[(int) in.length()];
            in.readFully(cs);
            out.write(cs);
          } finally {
            if (out != null)
              try {
                out.close();
              } catch (IOException e1) {
                throw new RuntimeException(e1);
              }
            if (in != null)
              try {
                in.close();
              } catch (IOException e1) {
                throw new RuntimeException(e1);
              }
          }
View Full Code Here

                dos.close();
                dis.close();;
            }
        }

        vertexDataFile = new RandomAccessFile(vertexfile.getAbsolutePath(), "rwd");
        vertexEn = vertexSt = 0;
    }
View Full Code Here

        File sparseFile = new File(ChiFilenames.getFilenameOfDegreeData(baseFilename, true));
        File denseFile = new File(ChiFilenames.getFilenameOfDegreeData(baseFilename, false));

        if (sparseFile.exists()) {
            sparse = true;
            degreeFile = new RandomAccessFile(sparseFile.getAbsolutePath(), "r");
        } else {
            sparse = false;
            degreeFile = new RandomAccessFile(denseFile.getAbsolutePath(), "r");
        }
        vertexEn = vertexSt = 0;
    }
View Full Code Here

        private Shard(String fileName, int shardNum, int numShards) throws IOException {
            this.shardNum = shardNum;
            this.numShards = numShards;
            this.fileName = fileName;
            File f = new File(ChiFilenames.getFilenameShardsAdj(fileName, shardNum, numShards));
            adjFile = new RandomAccessFile(f.getAbsolutePath(), "r", 64 * 1024);
            index = new ShardIndex(f);
        }
View Full Code Here

TOP

Related Classes of ucar.unidata.io.RandomAccessFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.