Package ucar.unidata.io

Examples of ucar.unidata.io.RandomAccessFile


  static private void readDataRegexp(String filename) throws IOException {
    int balony = 0;
    long start = System.currentTimeMillis();
    System.out.printf("regexp %s%n",filename);
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    String line;
    while (true) {
      line = raf.readLine();
      if (line == null) break;
      if (line.startsWith("#")) continue;
      if (line.trim().length() == 0) continue;
      balony += parseLine(line);
    }
View Full Code Here


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

     *
     * @throws IOException   problem reading file
     */
    public static RandomAccessFile getFile(String filename)
            throws IOException {
        return new RandomAccessFile(filename, "r", 2048);
    }
View Full Code Here

    int pos = dataFile.lastIndexOf(".");
    String base = dataFile.substring(0, pos);
    String ext = dataFile.substring(pos);

    if (ext.equals(IDX_EXT)) {
      dataRaf = new RandomAccessFile(base+DAT_EXT, "r");
      stnRaf = new RandomAccessFile(base+STN_EXT, "r");

     } else if (ext.equals(DAT_EXT)) {
      dataRaf = raff;
      stnRaf = new RandomAccessFile(base+STN_EXT, "r");

     } else {
      stnRaf = raff;
      dataRaf = new RandomAccessFile(base+DAT_EXT, "r");
     }

    NcmlConstructor ncmlc = new NcmlConstructor();
    if (!ncmlc.populateFromResource("resources/nj22/iosp/ghcnm.ncml", ncfile)) {
      throw new IllegalStateException(ncmlc.getErrlog().toString());
View Full Code Here

  public class Raf implements FileCacheable {
    private ucar.unidata.io.RandomAccessFile raf;

    Raf(String location) throws IOException {
      this.raf = new RandomAccessFile( location, "r");
    }
View Full Code Here

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

    // Reading of Grib files must be inside a try-catch block
    try {
      //ParameterTable.addParametersUser("/home/rkambic/code/grib/resources/resources/grib/tables/grib2userparameters" );
      RandomAccessFile raf = null;
      PrintStream ps = System.out;
      if (args.length == 3) {  // input file, output file, get data for dump
        raf = new RandomAccessFile(args[0], "r");
        ps = new PrintStream(
                new FilterOutputStream(
                        new FileOutputStream(args[1], false)));
        displayData = args[2].equalsIgnoreCase("true");
      } else if (args.length == 2) {  // input file and output file for dump
        raf = new RandomAccessFile(args[0], "r");
        if (args[1].equalsIgnoreCase("true")
                || args[1].equalsIgnoreCase("false")) {
          displayData = args[1].equalsIgnoreCase("true");
        } else {
          ps = new PrintStream(
                  new FilterOutputStream(
                          new FileOutputStream(args[1], false)));
        }
      } else if (args.length == 1) {
        raf = new RandomAccessFile(args[0], "r");
      } else {
        System.exit(0);
      }
      raf.order(RandomAccessFile.BIG_ENDIAN);
      // Create Grib2Input instance
      Grib2Input g2i = new Grib2Input(raf);
      // boolean params getProductsOnly, oneRecord
      g2i.scan(false, false);
      // record contains objects for all 8 Grib2 sections
      List records = g2i.getRecords();
      for (int i = 0; i < records.size(); i++) {
        Grib2Record record = (Grib2Record) records.get(i);
        Grib2IndicatorSection is = record.getIs();
        Grib2IdentificationSection id = record.getId();
        Grib2GridDefinitionSection gds = record.getGDS();
        Grib2ProductDefinitionSection pds = record.getPDS();

        // create dump output here
        ps.println(
                "--------------------------------------------------------------------");
        ps.println("                        Header : "
                + record.getHeader());
        printIS(is, ps);
        printID(id, dateFormat, ps);
        printGDS(gds, ps);
        printPDS(is, pds, ps);

        if (displayData) {
          float[] data = null;
          ps.println(
                  "--------------------------------------------------------------------");
          Grib2Data gd = new Grib2Data(raf);
          data = gd.getData(record.getGdsOffset(), record.getPdsOffset(), id.getRefTime());
          if (data != null) {
            //float missingValue =
            //        record.getDRS().getPrimaryMissingValue();
            for (int j = 0; j < data.length; j++) {
              //if( data[ j ] != missingValue )
              ps.println("data[ " + j + " ]=" + data[j]);
            }
          }
          break// only display data for 1st record
        }
      }
      raf.close();    // done reading

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

   * @param args  Grib name and PDS offset in Grib
   * @throws IOException on io error
   */
  // process command line switches
  static public void main(String[] args) throws IOException {
    RandomAccessFile raf    = null;
    PrintStream ps = System.out;
    String           infile = args[0];
    raf = new RandomAccessFile(infile, "r");
    raf.order(RandomAccessFile.BIG_ENDIAN);
    raf.skipBytes( Integer.parseInt( args[1]));
    Grib2ProductDefinitionSection pds = new Grib2ProductDefinitionSection( raf, 0 );
    Grib2Pds gpv = pds.pdsVars;
    ps.println( "Section = "+ gpv.getSection());
    ps.println( "Length = "+ gpv.getLength());
    ps.println( "ProductDefinition = "+ gpv.getProductDefinitionTemplate());
View Full Code Here

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

    // 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 == 3) || (args.length == 4)) {
        // 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);
      float data[] = g2d.getData(GdsOffset, PdsOffset, 0);

      float min = 9999, max = -9999;
      if (data != null) {
        //int row = 0;
        for (int j = 0; j < data.length; j++) {
          //if( j % 800 == 0 ) // used to test quasi data
          //ps.println( "row ="+ row++ );

          if (data[j] < min)
            min = data[j];
          if (data[j] > max)
            max = data[j];
          ps.println("data[ " + j + " ]=" + data[j]);
          // This code is used to compare the output to the wgrib2 program output
          // Caution it can round the output to 0 wrongly
          if( ! Float.isNaN( data[j] ))
            data[j] = (float) (Math.round(data[j]*1000.0) / 1000.0);

          //ps.println( data[j] );
        }
      }
      //ps.println("min =" + min + " max =" + max);
      raf.close();
      ps.close();

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

    } else {
      System.out.println("Not correct number of parms, either 1 or 2");
      return;
    }
    RandomAccessFile raf = new RandomAccessFile(fileName, "r");
    Grib1ExtractRawData erd = new Grib1ExtractRawData(raf);
    erd.scan(number);
  }
View Full Code Here

            func.usage(cl.getName());
        }

        // Opening of grib data must be inside a try-catch block
        try {
            RandomAccessFile raf     = null;
            PrintStream      ps      = System.out;
            String           outfile = args[0];
            if (args.length == 1) {  // input file given
                raf = new RandomAccessFile(outfile, "r");
            } else {
                ps.println("no file name given");
                System.exit(0);
            }
            int result = getEdition(raf);
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.