public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException { // Vgroup vgroup = (Vgroup) v2.getSPobject(); // Range scanRange = section.getRange(0); // Range radialRange = section.getRange(1); // Range gateRange = section.getRange(2); Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape()); IndexIterator ii = data.getIndexIterator(); List<List<Ray>> groups; String shortName = v2.getShortName(); if (shortName.startsWith("Reflectivity")) groups = volScan.getReflectivityGroups(); else if (shortName.startsWith("Velocity")) groups = volScan.getVelocityGroups(); else if (shortName.startsWith("TotalPower")) groups = volScan.getTotalPowerGroups(); else if (shortName.startsWith("Width")) groups = volScan.getWidthGroups(); else if (shortName.startsWith("DiffReflectivity")) groups = volScan.getDifferentialReflectivityGroups(); else throw new IllegalStateException("Illegal variable name = " + shortName); if (section.getRank() == 2) { Range radialRange = section.getRange(0); Range gateRange = section.getRange(1); List<Ray> lli = groups.get(0); readOneScan(lli, radialRange, gateRange, ii); } else { Range scanRange = section.getRange(0); Range radialRange = section.getRange(1); Range gateRange = section.getRange(2); for (int i = scanRange.first(); i <= scanRange.last(); i += scanRange.stride()) { readOneScan(groups.get(i), radialRange, gateRange, ii); } } return data; }
/** * Fill all of the variables/attributes in the ncfile * * @param ncfile NetcdfFile object which will be filled. * @param bst number of seconds since midnight for start of sweep * @param yr year of start of each sweep * @param m month of start of each sweep * @param dda day of start of each sweep * @param varList ArrayList of Variables of ncfile * @param recHdr java.util.Map with values for Attributes */ public void doNetcdfFileCoordinate( ucar.nc2.NetcdfFile ncfile, int[] bst, short[] yr, short[] m, short[] dda, ArrayList<Variable> varList, java.util.Map<String, Number> recHdr) { // prepare attribute values String[] unit = {" ", "dbZ", "dbZ", "m/sec", "m/sec", "dB"}; String def_datafile = "SIGMET-IRIS"; Short header_length = 80; Short ray_header_length = 6; int ngates = 0; float radar_lat = recHdr.get("radar_lat").floatValue(); // System.out.println("rad_lat="+radar_lat); float radar_lon = recHdr.get("radar_lon").floatValue(); // System.out.println("rad_lon="+radar_lon); short ground_height = recHdr.get("ground_height").shortValue(); // System.out.println("ground_H="+ground_height); short radar_height = recHdr.get("radar_height").shortValue(); // System.out.println("radar_H="+radar_height); int radar_alt = (recHdr.get("radar_alt").intValue()) / 100; // System.out.println("rad_alt="+radar_alt); short num_rays = recHdr.get("num_rays").shortValue(); // System.out.println("HERE!! num_rays="+num_rays); float range_first = (recHdr.get("range_first").intValue()) * 0.01f; // System.out.println("range_1st="+range_first); float range_last = (recHdr.get("range_last").intValue()) * 0.01f; // System.out.println("step="+step); short number_sweeps = recHdr.get("number_sweeps").shortValue(); int nparams = (recHdr.get("nparams").intValue()); // System.out.println("nparams="+nparams); // define date/time // int last_t=(int)(ray[nparams*number_sweeps-1][num_rays-1].getTime()); int last_t = volScan.lastRay.getTime(); String sss1 = Short.toString(m[0]); if (sss1.length() < 2) sss1 = "0" + sss1; String sss2 = Short.toString(dda[0]); if (sss2.length() < 2) sss2 = "0" + sss2; String base_date0 = String.valueOf(yr[0]) + "-" + sss1 + "-" + sss2; String sss11 = Short.toString(m[number_sweeps - 1]); if (sss11.length() < 2) sss11 = "0" + sss11; String sss22 = Short.toString(dda[number_sweeps - 1]); if (sss22.length() < 2) sss22 = "0" + sss22; String base_date1 = String.valueOf(yr[number_sweeps - 1]) + "-" + sss11 + "-" + sss22; String start_time = base_date0 + "T" + calcTime(bst[0], 0) + "Z"; String end_time = base_date1 + "T" + calcTime(bst[number_sweeps - 1], last_t) + "Z"; ncfile.addAttribute(null, new Attribute("time_coverage_start", start_time)); ncfile.addAttribute(null, new Attribute("time_coverage_end", end_time)); // set all of Variables try { int sz = varList.size(); ArrayFloat.D2[] dataArr = new ArrayFloat.D2[nparams * number_sweeps]; Index[] dataIndex = new Index[nparams * number_sweeps]; Ray[] rtemp = new Ray[(int) num_rays]; // NCdump.printArray(dataArr[0], "Total_Power", System.out, null); Variable[] distanceR = new Variable[number_sweeps]; ArrayFloat.D1[] distArr = new ArrayFloat.D1[number_sweeps]; Index[] distIndex = new Index[number_sweeps]; String distName = "distanceR"; for (int i = 0; i < number_sweeps; i++) { if (number_sweeps > 1) { distName = "distanceR_sweep_" + (i + 1); } for (Variable aVarList : varList) { if ((aVarList.getShortName()).equals(distName.trim())) { distanceR[i] = aVarList; break; } } distArr[i] = (ArrayFloat.D1) Array.factory(DataType.FLOAT, distanceR[i].getShape()); distIndex[i] = distArr[i].getIndex(); // for (int jj=0; jj<num_rays; jj++) { rtemp[jj]=ray[i][jj]; } ngates = sweep_bins[i]; float stp = calcStep(range_first, range_last, (short) ngates); for (int ii = 0; ii < ngates; ii++) { distArr[i].setFloat(distIndex[i].set(ii), (range_first + ii * stp)); } } // NCdump.printArray(distArr[0], "distanceR", System.out, null); List rgp = volScan.getTotalPowerGroups(); if (rgp.size() == 0) rgp = volScan.getReflectivityGroups(); List[] sgp = new ArrayList[number_sweeps]; for (int i = 0; i < number_sweeps; i++) { sgp[i] = (List) rgp.get((short) i); } Variable[] time = new Variable[number_sweeps]; ArrayInt.D1[] timeArr = new ArrayInt.D1[number_sweeps]; Index[] timeIndex = new Index[number_sweeps]; String t_n = "time"; for (int i = 0; i < number_sweeps; i++) { if (number_sweeps > 1) { t_n = "time_sweep_" + (i + 1); } for (Variable aVarList : varList) { if ((aVarList.getShortName()).equals(t_n.trim())) { time[i] = aVarList; break; } } // if (time[i].getShape().length == 0) { // continue; // } timeArr[i] = (ArrayInt.D1) Array.factory(DataType.INT, time[i].getShape()); timeIndex[i] = timeArr[i].getIndex(); List rlist = sgp[i]; for (int jj = 0; jj < num_rays; jj++) { rtemp[jj] = (Ray) rlist.get(jj); } // ray[i][jj]; } for (int jj = 0; jj < num_rays; jj++) { timeArr[i].setInt(timeIndex[i].set(jj), rtemp[jj].getTime()); } } // NCdump.printArray(timeArr[0], "time", System.out, null); Variable[] azimuthR = new Variable[number_sweeps]; ArrayFloat.D1[] azimArr = new ArrayFloat.D1[number_sweeps]; Index[] azimIndex = new Index[number_sweeps]; String azimName = "azimuthR"; for (int i = 0; i < number_sweeps; i++) { if (number_sweeps > 1) { azimName = "azimuthR_sweep_" + (i + 1); } for (Variable aVarList : varList) { if ((aVarList.getShortName()).equals(azimName.trim())) { azimuthR[i] = aVarList; break; } } azimArr[i] = (ArrayFloat.D1) Array.factory(DataType.FLOAT, azimuthR[i].getShape()); azimIndex[i] = azimArr[i].getIndex(); List rlist = sgp[i]; for (int jj = 0; jj < num_rays; jj++) { rtemp[jj] = (Ray) rlist.get(jj); } // ray[i][jj]; } for (int jj = 0; jj < num_rays; jj++) { azimArr[i].setFloat(azimIndex[i].set(jj), rtemp[jj].getAz()); } } // NCdump.printArray(azimArr[0], "azimuthR", System.out, null); Variable[] elevationR = new Variable[number_sweeps]; ArrayFloat.D1[] elevArr = new ArrayFloat.D1[number_sweeps]; Index[] elevIndex = new Index[number_sweeps]; String elevName = "elevationR"; for (int i = 0; i < number_sweeps; i++) { if (number_sweeps > 1) { elevName = "elevationR_sweep_" + (i + 1); } for (Variable aVarList : varList) { if ((aVarList.getShortName()).equals(elevName.trim())) { elevationR[i] = aVarList; break; } } elevArr[i] = (ArrayFloat.D1) Array.factory(DataType.FLOAT, elevationR[i].getShape()); elevIndex[i] = elevArr[i].getIndex(); List rlist = sgp[i]; for (int jj = 0; jj < num_rays; jj++) { rtemp[jj] = (Ray) rlist.get(jj); } // ray[i][jj]; } for (int jj = 0; jj < num_rays; jj++) { elevArr[i].setFloat(elevIndex[i].set(jj), rtemp[jj].getElev()); } } // NCdump.printArray(elevArr[0], "elevationR", System.out, null); Variable numGates = null; for (int i = 0; i < number_sweeps; i++) { for (Variable aVarList : varList) { if ((aVarList.getShortName()).equals("numGates")) { numGates = aVarList; break; } } } ArrayInt.D1 gatesArr = (ArrayInt.D1) Array.factory(DataType.INT, numGates.getShape()); Index gatesIndex = gatesArr.getIndex(); for (int i = 0; i < number_sweeps; i++) { List rlist = sgp[i]; for (int jj = 0; jj < num_rays; jj++) { rtemp[jj] = (Ray) rlist.get(jj); } // ray[i][jj]; } ngates = rtemp[0].getBins(); gatesArr.setInt(gatesIndex.set(i), ngates); } for (int i = 0; i < number_sweeps; i++) { distanceR[i].setCachedData(distArr[i], false); time[i].setCachedData(timeArr[i], false); azimuthR[i].setCachedData(azimArr[i], false); elevationR[i].setCachedData(elevArr[i], false); } numGates.setCachedData(gatesArr, false); // startSweep.setCachedData(sweepArr, false); // ------------------------------------------------- // int b=(int)ray[0][0].getBins(); // -- Test of readData() and readToByteChannel() ----------------- /* Range r1=new Range(356, 359); Range r2=new Range(0, 15); java.util.List arlist=new ArrayList(); arlist.add(r1); arlist.add(r2); Array testArr=readData(v[0], new Section(arlist)); NCdump.printArray(testArr, "Total_Power_sweep_1", System.out, null); WritableByteChannel channel=new FileOutputStream(new File("C:\\netcdf\\tt.dat")).getChannel(); long ikk=readToByteChannel(v[0], new Section(arlist), channel); System.out.println("IKK="+ikk); channel.close(); */ // --------------------------------------------------- } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } } // ----------- end of doNetcdf ----------------------------------