Package ucar.unidata.io

Examples of ucar.unidata.io.RandomAccessFile


  }

    // extract all messages that contains the header string to fileOut
  static void extractAllWithHeader(String filein, Pattern p, WritableByteChannel wbc) throws IOException {
    System.out.println("extract "+filein);
    RandomAccessFile raf = new RandomAccessFile(filein, "r");
    MessageScanner scan = new MessageScanner(raf);
    while (scan.hasNext()) {
      Message m = scan.next();
      Matcher matcher = p.matcher(m.getHeader());
      if (matcher.matches()) {
        scan.writeCurrentMessage(wbc);
        System.out.println(" found match "+m.getHeader());
      }
    }
    raf.close();
  }
View Full Code Here


     *
     * @throws IOException  problem reading the file
     */
    public static void main(String[] args) throws IOException {
        IOServiceProvider mciosp = new GempakSoundingIOSP();
        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

  }

  ///////////////////////////
  private static void dump(String filename) throws IOException {
    System.out.printf("Dump %s%n", filename);
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    NetcdfFile ncfile = new MyNetcdfFile();

    // its a netcdf-3 file
    raf.order(RandomAccessFile.BIG_ENDIAN);
    N3header headerParser = new N3header();

    headerParser.read(raf, ncfile, new Formatter(System.out));
    raf.close();
  }
View Full Code Here

      returns normally.
      @return true = ok, false = error.
  */
  boolean write_v5d_header() throws IOException {
    int vr, time, filler, maxnl;
    RandomAccessFile f;
    boolean newfile;

    if (FileFormat != 0) {
      System.err.println("Error: " +
        "v5d library can't write comp5d format files.");
      return false;
    }

    f = FileDesc;

    if (!v5dVerifyStruct()) return false;

    // Determine if we're writing to a new file
    newfile = (FirstGridPos == 0);

    // compute grid sizes
    SumGridSizes = 0;
    for (vr=0; vr<NumVars; vr++) {
      GridSize[vr] = 8 * Nl[vr] + v5dSizeofGrid(0, vr);
      SumGridSizes += GridSize[vr];
    }

    // set file pointer to start of file
    f.seek(0);
    CurPos = 0;

    // Write the tagged header info

    // ID
    if (!write_tag(TAG_ID, 0, newfile)) return false;

    // File Version
    if (!write_tag(TAG_VERSION, 10, newfile)) return false;
    f.write(FILE_VERSION.getBytes(), 0, 10);

    // Number of timesteps
    if (!write_tag(TAG_NUMTIMES, 4, newfile)) return false;
    f.writeInt(NumTimes);

    // Number of variables
    if (!write_tag(TAG_NUMVARS, 4, newfile)) return false;
    f.writeInt(NumVars);

    // Names of variables
    for (vr=0; vr<NumVars; vr++) {
      if (!write_tag(TAG_VARNAME, 14, newfile)) return false;
      f.writeInt(vr);
      for (int q=0; q<10; q++) f.writeByte((byte) VarName[vr][q]);
    }

    // Physical Units
    for (vr=0; vr<NumVars; vr++) {
      if (!write_tag(TAG_UNITS, 24, newfile)) return false;
      f.writeInt(vr);
      for (int q=0; q<20; q++) f.writeByte((byte) Units[vr][q]);
    }

    // Date and time of each timestep
    for (time=0; time<NumTimes; time++) {
      if (!write_tag(TAG_TIME, 8, newfile)) return false;
      f.writeInt(time);
      f.writeInt(TimeStamp[time]);
      if (!write_tag(TAG_DATE, 8, newfile)) return false;
      f.writeInt(time);
      f.writeInt(DateStamp[time]);
    }

    // Number of rows
    if (!write_tag(TAG_NR, 4, newfile)) return false;
    f.writeInt(Nr);

    // Number of columns
    if (!write_tag(TAG_NC, 4, newfile)) return false;
    f.writeInt(Nc);

    // Number of levels, compute maxnl
    maxnl = 0;
    for (vr=0; vr<NumVars; vr++) {
      if (!write_tag(TAG_NL_VAR, 8, newfile)) return false;
      f.writeInt(vr);
      f.writeInt(Nl[vr]);
      if (!write_tag(TAG_LOWLEV_VAR, 8, newfile)) return false;
      f.writeInt(vr);
      f.writeInt(LowLev[vr]);
      if (Nl[vr] + LowLev[vr] > maxnl) maxnl = Nl[vr]+LowLev[vr];
    }

    // Min/Max values
    for (vr=0; vr<NumVars; vr++) {
      if (!write_tag(TAG_MINVAL, 8, newfile)) return false;
      f.writeInt(vr);
      f.writeFloat(MinVal[vr]);
      if (!write_tag(TAG_MAXVAL, 8, newfile)) return false;
      f.writeInt(vr);
      f.writeFloat(MaxVal[vr]);
    }

    // Compress mode
    if (!write_tag(TAG_COMPRESS, 4, newfile)) return false;
    f.writeInt(CompressMode);

    // Vertical Coordinate System
    if (!write_tag(TAG_VERTICAL_SYSTEM, 4, newfile)) return false;
    f.writeInt(VerticalSystem);
    if (!write_tag(TAG_VERT_ARGS, 4+4*MAXVERTARGS, newfile)) return false;
    f.writeInt(MAXVERTARGS);
    for (int q=0; q<MAXVERTARGS; q++) f.writeFloat(VertArgs[q]);

    // Map Projection
    if (!write_tag(TAG_PROJECTION, 4, newfile)) return false;
    f.writeInt(Projection);
    if (!write_tag(TAG_PROJ_ARGS, 4+4*MAXPROJARGS, newfile)) return false;
    f.writeInt(MAXPROJARGS);
    for (int q=0; q<MAXPROJARGS; q++) f.writeFloat(ProjArgs[q]);

    // write END tag
    if (newfile) {
      // We're writing to a brand new file.
      // Reserve 10000 bytes for future header growth.
      if (!write_tag(TAG_END, 10000, newfile)) return false;
      f.skipBytes(10000);

      // Let file pointer indicate where first grid is stored
      FirstGridPos = (int) f.getFilePointer();
    }
    else {
      // we're rewriting a header
      filler = FirstGridPos - (int) f.getFilePointer();
      if (!write_tag(TAG_END, filler - 8, newfile)) return false;
    }

    return true;
  }
View Full Code Here

      it will be deleted.
      @param filename  name of v5d file to create
      @return true = ok, false = error.
  */
  boolean v5dCreateFile(String filename) throws IOException {
    RandomAccessFile fd = new RandomAccessFile(filename, "rw");

    if (fd == null) {
      System.err.println("Error in v5dCreateFile: open failed");
      FileDesc = null;
      Mode = 0;
View Full Code Here

        Date now = Calendar.getInstance().getTime();
        System.out.println(now.toString() + " ... Start of " + className);

        try {
            System.out.println("reading GEMPAK grid file=" + args[0]);
            RandomAccessFile rf = new RandomAccessFile(args[0], "r", 2048);
            NetcdfFile ncfile   = new MakeNetcdfFile(ggsp, rf, args[0], null);
            if (args.length == 2) {
                System.out.print("writing to netCDF file=" + args[1]);
                NetcdfFile nc = FileWriter.writeToFile(ncfile, args[1]);
                nc.close();
            }
            rf.close()// done reading

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

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

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

         throw new FileNotFoundException(datFile.getPath()+" must exist");
      File stnFile = new File(base+STN_EXT);
      if (!stnFile.exists())
         throw new FileNotFoundException(stnFile.getPath()+" must exist");

      this.raf = new RandomAccessFile(base+DAT_EXT, "r");
      this.stnRaf = new RandomAccessFile(base+STN_EXT, "r");
      readIndex(raf.getLocation());
      raf.close();

    } else { // must be the data file, we will write an index if needed below
      this.raf = raf;
      if (!(ext.equals(DAT_EXT)))
        throw new FileNotFoundException("Ghcnm: file must end with "+DAT_EXT);

      File stnFile = new File(base+STN_EXT);
      if (!stnFile.exists())
        throw new FileNotFoundException(stnFile.getPath()+" must exist");
      this.stnRaf = new RandomAccessFile(base+STN_EXT, "r");
   }

    //////////////////////////////////////////////////
    // LOOK - can we externalize config ??
View Full Code Here

  /////////////////////////////////////////////////////////////////////////////////
  // debug

  static private NetcdfFile open(String filename) throws IOException {
    Ghcnm iosp = new Ghcnm();
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    MyNetcdfFile ncfile = new MyNetcdfFile(iosp);
    iosp.open(raf, ncfile, null);
    return ncfile;
  }
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.