Package ucar.unidata.io

Examples of ucar.unidata.io.RandomAccessFile


    }

    // create/show index
    String gribName = args[0].replaceAll(GribIndexName.currentSuffix, "");
    gbxName = GribIndexName.getCurrentSuffix(gribName);
    ucar.unidata.io.RandomAccessFile raf = new RandomAccessFile(gribName, "r");
    int edition = GribChecker.getEdition(raf);
    if (edition == 1) {
      Grib1WriteIndex.main(new String[]{gribName, gbxName});
    } else if (edition == 2) {
      Grib2WriteIndex.main(new String[]{gribName, gbxName});
View Full Code Here


    }
  }

  int scan(String filename) throws IOException {
    long start = System.nanoTime();
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    out.format("\nOpen %s size = %d Kb \n", raf.getLocation(), raf.length() / 1000);

    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    int bad = 0;
    while (scan.hasNext()) {
      Message m = scan.next();
      if (m == null) continue;
      //if (count == 0) new BufrDump2().dump(out, m);

      if (!m.isTablesComplete()) {
        out.format("**INCOMPLETE%n");
        bad++;
        continue;
      }

      int nbitsCounted = m.getTotalBits();
      if (!(Math.abs(m.getCountedDataBytes()- m.dataSection.getDataLength()) <= 1)) {
        out.format("**BitCount Fails expect=%d != dataLength=%d%n", m.getCountedDataBytes(), m.dataSection.getDataLength());
        bad++;
        continue;
      }

      byte[] mbytes = scan.getMessageBytesFromLast(m);

      NetcdfFile ncfile = NetcdfFile.openInMemory("test", mbytes);
      NetcdfDataset ncd = new NetcdfDataset(ncfile);

      writeMessage(m, ncd);
      count++;
    }
    raf.close();

    long took = (System.nanoTime() - start);
    double rate = (took > 0) ? ((double) (1000 * 1000) * count / took) : 0.0;
    out.format("----nmsgs= %d bad=%d nobs = %d took %d msecs rate = %f msgs/msec\n", count, bad, scan.getTotalObs(), took / (1000 * 1000), rate);
    return scan.getTotalObs();
View Full Code Here

  static public void main(String args[]) throws IOException, InvalidRangeException {
    String filename = "C:/data/cadis/tempting";
    //String filename = "C:/data/cadis/Y94179";
    //String filename = "C:/data/cadis/Y94132";
    NmcObsLegacy iosp = new NmcObsLegacy();
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    NetcdfFile ncfile = new MyNetcdfFile(iosp);
    ncfile.setLocation(filename);
    iosp.open(raf, ncfile, null);
    System.out.println("\n" + ncfile);
View Full Code Here

  }

  private static boolean showFile = true;

  static void testPelim(String filename) throws IOException {
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    NetcdfFile ncfile = new MyNetcdfFile();
    H4header header = new H4header();
    header.read(raf, ncfile);
    if (showFile) System.out.println(ncfile);
  }
View Full Code Here

     *
     * @throws IOException  problem reading the file
     */
    public static void main(String[] args) throws IOException {
        IOServiceProvider mciosp = new GempakSurfaceIOSP();
        RandomAccessFile  rf     = new RandomAccessFile(args[0], "r", 2048);
        NetcdfFile ncfile = new MakeNetcdfFile(mciosp, rf, args[0], null);
        if (args.length > 1) {
            ucar.nc2.FileWriter.writeToFile(ncfile, args[1]);
        } else {
            System.out.println(ncfile);
View Full Code Here

   * @throws IOException on gbx write
   */
  public final GridIndex writeGribIndex( File grib,
      String gribName, String gbxName, boolean makeIndex) throws IOException {

    RandomAccessFile raf = null;
    // default from standalone indexer, check for duplicate records and log to System.out
    //checkPDS = true;
    logPDS = pdsLogType.systemout;
    try {
      raf = new RandomAccessFile(gribName, "r");
      raf.order(RandomAccessFile.BIG_ENDIAN);
      return writeGribIndex(grib, gbxName, raf, makeIndex);
    } finally {
      if (raf != null)
        raf.close();
    }
  }
View Full Code Here

   */
  public final GridIndex extendGribIndex(
      File grib, File gbx,
      String gribName, String gbxName, boolean makeIndex) throws IOException {

    RandomAccessFile raf = null;
    // default from standalone indexer, check for duplicate records and log to System.out
    //checkPDS = true;
    logPDS = pdsLogType.systemout;
    try {
      raf = new RandomAccessFile(gribName, "r");
      raf.order(RandomAccessFile.BIG_ENDIAN);
      return extendGribIndex(grib, gbx, gbxName, raf, makeIndex);
    } finally {
      if (raf != null)
        raf.close();
    }
  }
View Full Code Here

   * @return Index if makeIndex is true, else null
   * @throws IOException  on Grib read
   */
  public final GridIndex writeGribIndex(File grib, String gribName, String gbxName, boolean makeIndex) throws IOException {

    RandomAccessFile raf = null;
    // default from standalone indexer, check for duplicate records and log to System.out
    checkPDS = true;
    logPDS = Grib2WriteIndex.pdsLogType.systemout;
    try {
      raf = new RandomAccessFile(gribName, "r");
      raf.order(RandomAccessFile.BIG_ENDIAN);
      return  writeGribIndex( grib, gbxName, raf, makeIndex);
    } finally {
      if (raf != null)
        raf.close();
    }
  }
View Full Code Here

   * @throws IOException on gbx write
   */
  public final GridIndex extendGribIndex(File grib, File gbx,
    String gribName, String gbxName, boolean makeIndex) throws IOException {

    RandomAccessFile raf = null;
    // default from standalone indexer, check for duplicate records and log to System.out
    checkPDS = true;
    logPDS = Grib2WriteIndex.pdsLogType.systemout;
    try {
      raf = new RandomAccessFile(gribName, "r");
      raf.order(RandomAccessFile.BIG_ENDIAN);
      return extendGribIndex( grib,  gbx, gbxName, raf,  makeIndex);
    } finally {
      if (raf != null)
        raf.close();
    }
  }
View Full Code Here

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

    // Reading of grib data must be inside a try-catch block
    try {
      // Create RandomAccessFile instance
      RandomAccessFile raf = null;
      PrintStream ps = System.out;
      long offset1 = 0;
      long offset2 = 0;
      boolean bmsExists = true;
      int decimalScale = 1;
      // input file, offset, decimalScale given
      // Create RandomAccessFile
      raf = new RandomAccessFile(args[0], "r");
      raf.order(RandomAccessFile.BIG_ENDIAN);
      offset1 = Long.decode(args[1]).longValue();
      //if ((args.length == 4) || (args.length == 5)) {
      if ((args.length == 4)) {
        decimalScale = Integer.parseInt(args[2]);
        Boolean B = Boolean.valueOf(args[3]);
        bmsExists = B.booleanValue();
      } else if ((args.length == 5)) {
        offset2 = Long.decode(args[2]).longValue();
        decimalScale = Integer.parseInt(args[3]);
        Boolean B = Boolean.valueOf(args[4]);
        bmsExists = B.booleanValue();
      } else if ((args.length == 6)) {
        offset2 = Long.decode(args[2]).longValue();
        decimalScale = Integer.parseInt(args[3]);
        Boolean B = Boolean.valueOf(args[4]);
        bmsExists = B.booleanValue();
        ps = new PrintStream(
          new BufferedOutputStream(
          new FileOutputStream(args[5], false)));
      } else {
        System.exit(0);
      }
      long start = System.currentTimeMillis();
      Grib1Data g1d = new Grib1Data(raf);
      float[] data;
      if ((args.length == 4)) {
        data = g1d.getData(offset1, decimalScale, bmsExists);
      } else {
        data = g1d.getData(offset1, offset2, decimalScale, bmsExists);
      }
      System.out.println("getting data size " + data.length + " took "
          + (System.currentTimeMillis() - start) + " msec");

      if (data != null) {
        //ps.println("length ="+ data.length );
        for (int j = 0; j < data.length; j++) {
          ps.println("data[ " + j + " ]=" + data[j]);
        }
      }
      raf.close();
      ps.close();

      // Catch thrown errors from Grib1GetData
    } catch (FileNotFoundException noFileError) {
      System.err.println("FileNotFoundException : " + noFileError);
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.