public boolean isValidFile(RandomAccessFile raf) { int data_msecs = 0; short data_julian_date = 0; try { raf.order(RandomAccessFile.LITTLE_ENDIAN); raf.seek(0); raf.skipBytes(14); short message_type = raf.readShort(); if (message_type != 1) return false; raf.skipBytes(12); // data header byte[] b4 = raf.readBytes(4); data_msecs = bytesToInt(b4, true); byte[] b2 = raf.readBytes(2); data_julian_date = (short) bytesToShort(b2, true); java.util.Date dd = Cinrad2Record.getDate(data_julian_date, data_msecs); Calendar cal = new GregorianCalendar(new SimpleTimeZone(0, "GMT")); cal.clear(); cal.setTime(dd); int year = cal.get(Calendar.YEAR); cal.setTime(new Date()); int cyear = cal.get(Calendar.YEAR); if (year < 1990 || year > cyear) return false; return true; } catch (IOException ioe) { return false; } }
/** Check if this is a valid SIGMET-IRIS file for this IOServiceProvider. */ public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) { try { raf.order(RandomAccessFile.LITTLE_ENDIAN); // The first struct in the file is the product_hdr, which will have the // standard structure_header, followed by other embedded structures. // Each of these structures also have a structure header. To validate // the file we check for a product_hdr (by looking for type 27 in the // structure_header), then a product_configuration structure (by looking // for type 26 in its structure_header), then checking that that // the product_configuration does indicate a type of RAW data (type 15) raf.seek(0); short[] data = new short[13]; raf.readShort(data, 0, 13); return (data[0] == (short) 27 && data[6] == (short) 26 && data[12] == (short) 15); } catch (IOException ioe) { System.out.println("In isValidFile(): " + ioe.toString()); return false; } }
/** * Read some global data from SIGMET file. The SIGMET file consists of records with fixed * length=6144 bytes. */ public static java.util.Map<String, Number> readRecordsHdr(ucar.unidata.io.RandomAccessFile raf) { java.util.Map<String, Number> recHdr1 = new java.util.HashMap<String, Number>(); try { int nparams = 0; // -- Read from <product_end> of the 1st record -- 12+320+120 // -- Calculate Nyquist velocity -------------------- raf.seek(452); int prf = raf.readInt(); raf.seek(480); int wave = raf.readInt(); float vNyq = calcNyquist(prf, wave); recHdr1.put("vNyq", vNyq); // -- Read from the 2nd record----------- 6144+12(strucr_hdr)+168(from ingest_config) raf.seek(6324); int radar_lat = raf.readInt(); int radar_lon = raf.readInt(); // 6328 short ground_height = raf.readShort(); // 6332 short radar_height = raf.readShort(); // 6334 raf.skipBytes(4); short num_rays = raf.readShort(); // 6340 raf.skipBytes(2); int radar_alt = raf.readInt(); // 6344 raf.seek(6648); int time_beg = raf.readInt(); raf.seek(6652); int time_end = raf.readInt(); raf.seek(6772); int data_mask = raf.readInt(); for (int j = 0; j < 32; j++) { nparams += ((data_mask >> j) & (0x1)); } raf.seek(6912); short multiprf = raf.readShort(); raf.seek(7408); int range_first = raf.readInt(); // cm 7408 int range_last = raf.readInt(); // cm 7412 raf.skipBytes(2); short bins = raf.readShort(); // 7418 if (bins % 2 != 0) bins = (short) (bins + 1); raf.skipBytes(4); int step = raf.readInt(); // cm 7424 raf.seek(7574); short number_sweeps = raf.readShort(); // 7574 raf.seek(12312); int base_time = raf.readInt(); // <ingest_data_header> 3d rec raf.skipBytes(2); short year = raf.readShort(); short month = raf.readShort(); short day = raf.readShort(); recHdr1.put("radar_lat", calcAngle(radar_lat)); recHdr1.put("radar_lon", calcAngle(radar_lon)); recHdr1.put("range_first", range_first); recHdr1.put("range_last", range_last); recHdr1.put("ground_height", ground_height); recHdr1.put("radar_height", radar_height); recHdr1.put("radar_alt", radar_alt); recHdr1.put("step", step); recHdr1.put("bins", bins); // System.out.println(" bins="+bins); recHdr1.put("num_rays", num_rays); // System.out.println(" rays="+num_rays); recHdr1.put("nparams", nparams); // System.out.println(" nparams="+nparams); recHdr1.put("multiprf", multiprf); recHdr1.put( "number_sweeps", number_sweeps); // System.out.println("IN HDR: number_sweeps="+number_sweeps); recHdr1.put("year", year); recHdr1.put("month", month); recHdr1.put("day", day); recHdr1.put("base_time", base_time); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } return recHdr1; }