Package ucar.unidata.io

Examples of ucar.unidata.io.RandomAccessFile


  static Map<List<String>, String> mixedSet = new HashMap<List<String>, String>();

  static void scanMixedMessageTypes(String filename) throws IOException {

    //RandomAccessFile raf = new RandomAccessFile("C:\\data\\bufr\\edition3\\idd\\radiosonde\\SoundingVerticalRadiosonde4.bufr", "r");
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    out.format("\n-----\nOpen %s size = %d Kb \n", raf.getLocation(), raf.length() / 1000);

    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {
      Message m = scan.next();
      if (m == null) continue;

      List<String> desc = m.dds.getDescriptors();
      String key = mixedSet.get(desc);
      if (null == key) {
        out.format(" new Message Type msg=%d <%s> ndesc=%d hashCode=%d\n", count, m.getHeader(), desc.size(), desc.hashCode());
        m.getRootDataDescriptor();
        m.dump(out);
        mixedSet.put(desc, filename);
      } else if (!key.equals(filename)) {
        out.format(" msg type from file= %s, hashcode=%d\n", key, desc.hashCode());
      }
      count++;
    }
    raf.close();
    out.format("nmsgs= %d nobs = %d\n", count, scan.getTotalObs());
  }
View Full Code Here


  }

  //////////////////////////////////////////////////////////////

  static void scanMessageSizes(String filename, Formatter formatter) throws IOException {
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    out.format("\n-----\nOpen %s size = %d Kb \n", raf.getLocation(), raf.length() / 1000);

    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {
      Message m = scan.next();
      if (m == null) continue;
      if (!m.isTablesComplete()) {
        out.format("Message "+count+" INCOMPLETE TABLES%n");
        count++;
        break;
      }

      DataDescriptor root = m.getRootDataDescriptor(); // make sure the dds has been formed
      m.dumpHeader(out);

      m.calcTotalBits(formatter);
      int nbitsCounted = m.getTotalBits();
      int nbitsGiven = 8 * (m.dataSection.getDataLength() - 4);

      boolean ok = Math.abs(m.getCountedDataBytes()- m.dataSection.getDataLength()) <= 1; // radiosondes dataLen not even number of bytes

      if (!ok) out.format("*** BAD ");
        long last = m.dataSection.getDataPos() + m.dataSection.getDataLength();
        out.format("Message %d nds=%d compressed=%s vlen=%s countBits= %d givenBits=%d data start=0x%x end=0x%x",
                count, m.getNumberDatasets(), m.dds.isCompressed(), root.isVarLength(),
                nbitsCounted, nbitsGiven, m.dataSection.getDataPos(), last);
        out.format(" countBytes= %d dataSize=%d", m.getCountedDataBytes(), m.dataSection.getDataLength());
        out.format("%n");
     
      /* if (m.getCountedDataBytes() != m.dataSection.dataLength) {
        out.format(" extra=");
        showBytes(out, raf, m.dataSection.dataPos + m.getCountedDataBytes(), m.dataSection.dataLength - m.getCountedDataBytes());
      } */
      count++;
    }
    raf.close();
    out.format("nmsgs= %d nobs = %d\n", count, scan.getTotalObs());
  }
View Full Code Here

  static Map<String, Counter> headerCount = new HashMap<String, Counter>();
  static int total_msgs, bad_msgs, bad_wmo, bad_tables, bad_operation, total_different, good_msgs, total_obs;
  static long file_size = 0;

  static void scanMessageTypes(String filename) throws IOException {
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    //out.format("\n-----\nOpen %s size = %d Kb \n", raf.getLocation(), raf.length() / 1000);
    file_size += raf.length();

    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {

      Message m = scan.next();
      if (m == null) {
        bad_msgs++;
        continue;
      }

      // incomplete tables
      try {
        if (!m.isTablesComplete()) {
          int[] nbad = badMap.get(m);
          if (nbad == null) {
            nbad = new int[1];
            badMap.put(m, nbad);
          }
          nbad[0]++;
          bad_tables++;
          //continue; dont exclude
        }
      } catch (UnsupportedOperationException e) {
        m.dumpHeader(out);
        bad_operation++;
        continue;
      }

      // track desc to headers
      String ttaaii = extractWMO(m.getHeader());
      if (ttaaii == null) {
        bad_wmo++;
        continue;
      }

      // map dds -> wmoheader
      Map<String, Counter> keys = typeMap.get(m);
      if (null == keys) {
        //out.format("  new Descriptor Type msg %d ttaaii=%s hashCode=%d cat=%s\n",
        //        count, ttaaii, m.hashCode(), m.getCategory());
        //new BufrDump2().dump(out, m);
        keys = new HashMap<String, Counter>();
        keys.put(ttaaii, new Counter(ttaaii));
        typeMap.put(m, keys);
      }
      Counter c = keys.get(ttaaii);
      if (c == null) {
        //out.format("  msg %d has different ttaaii = %s hashcode=%d cat=%s\n",
        //        count, ttaaii, m.hashCode(), m.getCategory());
        c = new Counter(ttaaii);
        keys.put(ttaaii, c);
      }
      c.count++;
      c.countObs += m.getNumberDatasets();

      // map wmoheader to dds
      List<Message> mtypes = headerMap.get(ttaaii);
      if (mtypes == null) {
        mtypes = new ArrayList<Message>();
        headerMap.put(ttaaii, mtypes);
        mtypes.add(m);
      } else if (!mtypes.contains(m)) {
        //out.format(" Different desc for header %s hashCode=%d prev hashcode=%d\n", ttaaii, desc.hashCode(), hdesc.hashCode());
        mtypes.add(m);
        total_different++;
      }

      // track header count
      Counter hc = headerCount.get(ttaaii);
      if (hc == null) {
        hc = new Counter(ttaaii);
        headerCount.put(ttaaii, hc);
      }
      hc.count++;

      count++;
    }
    raf.close();
    out.format(filename+" total_msgs= %d good=%d total_obs = %d\n", scan.getTotalMessages(), count, scan.getTotalObs());
    total_msgs += scan.getTotalMessages();
    good_msgs += count;
    total_obs += scan.getTotalObs();
  }
View Full Code Here

  static Set<Message> messSet = new HashSet<Message>();

  static void writeUniqueDDS(String filename, WritableByteChannel wbc) throws IOException {
    System.out.printf("open %s ",filename);
    RandomAccessFile raf = new RandomAccessFile(filename, "r");

    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {

      Message m = scan.next();
      if (m == null) {
        bad_msgs++;
        System.out.printf("Bad Message%n");
        continue;
      }

      if (!messSet.contains(m)) {
        scan.writeCurrentMessage(wbc);
        messSet.add(m);
      }

      count++;
    }
    raf.close();
    System.out.printf(" read  = %d%n ", count);

  }
View Full Code Here

  static Map<Message, Counter> messMap = new HashMap<Message, Counter>();
  static Map<Short, Counter> ddsMap = new HashMap<Short, Counter>();
  static Map<Short, Counter> descMap = new HashMap<Short, Counter>();

  static void scanMessageDDS(String filename) throws IOException {
    RandomAccessFile raf = new RandomAccessFile(filename, "r");
    //out.format("\n-----\nOpen %s size = %d Kb \n", raf.getLocation(), raf.length() / 1000);
    file_size += raf.length();

    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {

      Message m = scan.next();
      if (m == null) {
        bad_msgs++;
        continue;
      }

      // incomplete tables
      try {
        if (!m.isTablesComplete()) {
          int[] nbad = badMap.get(m);
          if (nbad == null) {
            nbad = new int[1];
            badMap.put(m, nbad);
          }
          nbad[0]++;
          bad_tables++;
          //continue;
        }
      } catch (UnsupportedOperationException e) {
        m.dumpHeader(out);
        bad_operation++;
        continue;
      }

      String ttaaii = extractWMO(m.getHeader());

      Counter c = messMap.get(m);
      if (null == c) {
        c = new Counter(ttaaii);
        c.m = m;
        messMap.put(m, c);

        addDDS(ttaaii, m, m.getRootDataDescriptor());
        addDesc(m, m.dds.getDescriptors());
      }
      c.count++;
      c.countObs += m.getNumberDatasets();
      c.countBytes += m.getMessageSize();

      count++;
    }
    raf.close();
    out.format("total_msgs= %d good=%d total_obs = %d\n", scan.getTotalMessages(), count, scan.getTotalObs());
    total_msgs += scan.getTotalMessages();
    good_msgs += count;
    total_obs += scan.getTotalObs();
  }
View Full Code Here

  // extract the msgno-th message to fileOut

  static void scanReader(String filein) throws IOException {
    Formatter f = new Formatter(System.out);

    RandomAccessFile raf = new RandomAccessFile(filein, "r");
    MessageScanner scan = new MessageScanner(raf);
    while (scan.hasNext()) {
      Message m = scan.next();
      m.dumpHeader(out);
      if (!m.dds.isCompressed()) {
View Full Code Here

  // extract the msgno-th message to fileOut
  static void extractNthMessage(String filein, int msgno, String fileout) throws IOException {
    FileOutputStream fos = new FileOutputStream(fileout);
    WritableByteChannel wbc = fos.getChannel();

    RandomAccessFile raf = new RandomAccessFile(filein, "r");
    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {
      Message m = scan.next();
      if (msgno == count) {
        scan.writeCurrentMessage(wbc);
        wbc.close();
        raf.close();
        return;
      }
      count++;
    }
  }
View Full Code Here

  static void extractMessageByListhash(String filein, int want, String fileout) throws IOException {
    FileOutputStream fos = new FileOutputStream(fileout);
    WritableByteChannel wbc = fos.getChannel();

    int count = 0;
    RandomAccessFile raf = new RandomAccessFile(filein, "r");
    MessageScanner scan = new MessageScanner(raf);
    while (scan.hasNext()) {
      Message m = scan.next();
      int listHash = m.dds.getDataDescriptors().hashCode();

      if (listHash == want) {
        scan.writeCurrentMessage(wbc);
        wbc.close();
        raf.close();
        System.out.printf("output %d from %s %n",count, filein);
        return;
      }
      count++;
    }
View Full Code Here

  // extract n messages to fileOut
  static void extractNMessages(String filein, int n, String fileout) throws IOException {
    FileOutputStream fos = new FileOutputStream(fileout);
    WritableByteChannel wbc = fos.getChannel();

    RandomAccessFile raf = new RandomAccessFile(filein, "r");
    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext() && (count < n)) {
      Message m = scan.next();
        scan.writeCurrentMessage(wbc);
      count++;
    }
    wbc.close();
    raf.close();
  }
View Full Code Here

  // extract the first message that contains the header string to fileOut
  static void extractFirstMessageWithHeader(String filein, String header, String fileout) throws IOException {
    FileOutputStream fos = new FileOutputStream(fileout);
    WritableByteChannel wbc = fos.getChannel();

    RandomAccessFile raf = new RandomAccessFile(filein, "r");
    MessageScanner scan = new MessageScanner(raf);
    int count = 0;
    while (scan.hasNext()) {
      Message m = scan.next();
      if (m.getHeader().contains(header)) {
        scan.writeCurrentMessage(wbc);
        wbc.close();
        raf.close();
        return;
      }
      count++;
    }
  }
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.