📄 rpftochandler.java
字号:
Debug.output("RpfTocHandler: parseToc(): frameIndexTableOffset: " + frameIndexTableOffset); Debug.output("RpfTocHandler: parseToc(): # Frame file index recs: " + numFrameIndexRecords); Debug.output("RpfTocHandler: parseToc(): # pathname records: " + numPathnameRecords); Debug.output("RpfTocHandler: parseToc(): Index rec len(33): " + indexRecordLength); } // Read frame file index records for (i = 0; i < numFrameIndexRecords; i++) { if (DEBUG_RPFTOCFRAMEDETAIL) { Debug.output("RpfTocHandler: parseToc(): Read frame file index rec #: " + i); } // Index_subhdr_len (9) instead of table_offset (11) // indexRecordLength (33) instead of 35 // componentLocation, not index // locations[3] is frame file index table subsection binFile.seek(locations[3].componentLocation + indexRecordLength * i); boundaryId = (int) binFile.readShort(); if (DEBUG_RPFTOCFRAMEDETAIL) { Debug.output("boundary id for frame: " + i + " is " + boundaryId); } // DKS NEW: changed from 1 to 0 to agree w/ spec. -1 // added also. // if (boundaryId < 0 || boundaryId > numBoundaries - // 1 ) if (boundaryId > numBoundaries - 1) { Debug.output("Bad boundary id in FF index record " + i); return false; } // DKS NEW: -1 removed to match spec entry = entries[boundaryId]; frameRow = (int) binFile.readShort(); frameCol = (int) binFile.readShort(); // DKS. switched from horizFrames to vertFrames // DKS NEW: CHANGED FROM 1 to 0 to agree w/spec. ALSO // COL below // if (frameRow < 1 || frameRow > entry->vertFrames) if (frameRow > entry.vertFrames - 1) { Debug.output(" Bad row number: " + frameRow + ", in FF index record " + i); Debug.output(" Min row num=0; Max. row num:" + (entry.horizFrames - 1)); return false; } // DKS. switched from vertFrames to horizFrames if (frameCol > entry.horizFrames - 1) { Debug.output(" Bad col number in FF index record " + i); return false; } // DKS NEW: -1 removed on frameRow, col // JRB // frame = &entry->frames[frameRow][frameCol]; // [(entry->vertFrames - 1L)-frameRow] flips the array // over, so that the frames can be referenced // correctly from the top left, instead of the // specification notation of bottom left. frame = entry.frames[(entry.vertFrames - 1) - frameRow][frameCol]; if (frame.exists && DEBUG_RPFTOCDETAIL) { Debug.output("FF " + i + " is a duplicate"); } // DKS: phys_loc deleted // pathname offset pathOffset = (long) binFile.readInteger(); // Save file position for later currentPosition = (int) binFile.getFilePointer(); // Go to start of pathname record // DKS. New pathOffset offset from start of frame file // index section of TOC?? if (DEBUG_RPFTOCFRAMEDETAIL) { Debug.output("RpfTocHandler: parseToc(): locations[1].componentLocation: " + locations[1].componentLocation); } // DKS. Add pathoffset wrt frame file index table // subsection (loc[3]) binFile.seek(locations[3].componentLocation + pathOffset); pathLength = (int) binFile.readShort(); if (DEBUG_RPFTOCFRAMEDETAIL) { Debug.output("RpfTocHandler: parseToc(): pathLength:" + pathLength); } // 1st part of directory name is passed as arg: // e.g. "../RPF2/" frame.rpfdir = dir; StringBuffer sBuf = new StringBuffer(); // read rest of directory name from toc // DKS: skip 1st 2 chars: "./": String pathTest = binFile.readFixedLengthString(2); if (pathTest.equals("./")) { fullPathsInATOC = false; } else { fullPathsInATOC = true; } if (!fullPathsInATOC) { // DKS: Make up for skipped 2 chars sBuf.append(binFile.readFixedLengthString(pathLength - 2)); } else { sBuf.append(pathTest); sBuf.append(binFile.readFixedLengthString(pathLength - 2)); } // Add the trim because it looks like NIMA doesn't // always get the pathLength correct... frame.directory = sBuf.toString().trim(); if (DEBUG_RPFTOCFRAMEDETAIL) { Debug.output("RpfTocHandler: parseToc(): frame directory: " + frame.directory); } /* Go back to get filename tail */ binFile.seek(currentPosition); frame.filename = binFile.readFixedLengthString(12); if (DEBUG_RPFTOCFRAMEDETAIL) { Debug.output("RpfTocHandler: parseToc(): frame filename: " + frame.filename); } // Figure out the chart series ID int dot = frame.filename.lastIndexOf('.'); // Interned so we can look it up in the catalog // later... entry.setInfo(frame.filename.substring(dot + 1, dot + 3) .toUpperCase().intern()); // We duplicate this below!!! // frame.framePath = new String(frame.rpfdir + // frame.directory + // "/" + frame.filename); // DKS new DCHUM. Fill in last digit v of vv version // #. fffffvvp.JNz or ffffffvp.IMz for CIB boundaryId // will equal frame file number: 1 boundary rect. per // frame. // if (Dchum) // entries[boundaryId].version = // frame.filename.charAt(6); // do diskspace calculations String tempPath; if (!fullPathsInATOC) { tempPath = frame.rpfdir + frame.directory + frame.filename; } else { tempPath = frame.directory + frame.filename; frame.rpfdir = null; // The path to the rpf dir is // in frame.directory } long diskspace = 288000; // boolean exists = true; // Turns out this check is wicked expensive!!!!!! // Assume it's there, the RPFFrame has been modified // to try lower case names if needed. // if (local) { // exists = BinaryFile.exists(tempPath); // // This may fail because of FTP and/or CDROM // filename // // shinanagins. The A.TOC file should always think // // that the filenames are uppercase. They may get // // copied as lowercase, so we'll check that here. // If // // they are actually lowercase, we'll change it // here // // so that everything will work at runtime. - DFD // 8/20/99 // // OK, with the advent of the new BinaryFile that // // will let these files be read from a jar file or // // from a URL, we have to assume that the files // // are there, and deal with it if they are not. // } // if (exists) { frame.diskspace = diskspace; frame.framePath = tempPath; frame.exists = true; // } else if (!fullPathsInATOC) { // // This should only be an issue for local files. // tempPath = frame.rpfdir + // frame.directory.toLowerCase() + // frame.filename.toLowerCase(); // // if (BinaryFile.exists(tempPath)) { // frame.diskspace = diskspace; // frame.framePath = tempPath; // frame.exists = true; // // } // } if (frame.framePath == null) { Debug.output("RpfTocHandler: Frame " + tempPath + " doesn't exist. Please rebuild A.TOC file using MakeToc, or check read permissions for the file."); } } /* for i = numFrameIndexRecords */ } catch (IOException ioe) { Debug.error("RpfTocHandler: IO ERROR parsing file!\n\t" + ioe); return false; } catch (FormatException fe) { Debug.error("RpfTocHandler: Format ERROR parsing file!\n\t" + fe); return false; } if (DEBUG_RPFTOC) { Debug.output("LEAVE TOC parsing..."); } return true; } /** * Util-like function that translates a long to the string * representation found in the A>TOC file. */ public static String translateScaleToSeries(long scale) { if (scale == 0) return "Various "; else if (scale == 50000L) return "1:50K "; else if (scale == 100000L) return "1:100K "; else if (scale == 200000L) return "1:200K "; else if (scale == 250000L) return "1:250K "; else if (scale == 500000L) return "1:500K "; else if (scale == 1000000L) return "1:1M "; else if (scale == 2000000L) return "1:2M "; else if (scale == 5000000L) return "1:5M "; else if (scale == 66666L) return "10M "; else if (scale == 33333L) return "5M "; else return (String) null; } /** * Given the scale string found in the A.TOC file, decode it into * a 'long' scale. */ public static long textScaleToLong(String textScale) { Long resolution; Long realValue; int expLetter; // location of m, M, K int expLetterSmall; int colon = textScale.indexOf(":"); try { if (colon == -1) { // dealing with an imagery scale expLetter = textScale.indexOf("m"); if (expLetter == -1) { expLetter = textScale.indexOf("M"); if (expLetter == -1) return -1; // ERROR } resolution = new Long(textScale.substring(0, expLetter)); return (long) (resolution.longValue() / .000150); } // dealing with a map scale String expValue = ""; resolution = new Long(textScale.substring(0, colon)); expLetter = textScale.lastIndexOf('K'); expLetterSmall = textScale.lastIndexOf('k'); if (expLetter == -1 && expLetterSmall == -1) { expLetter = textScale.lastIndexOf('M'); expLetterSmall = textScale.lastIndexOf('m'); if (expLetter != -1 || expLetterSmall != -1) { expValue = "000000"; } } else { expValue = "000"; } StringBuffer buf; if (!expValue.equals("")) { // make sure we have the right index variable if (expLetter == -1) { expLetter = expLetterSmall; } buf = new StringBuffer(textScale.substring(colon + 1, expLetter)); buf.append(expValue); } else { buf = new StringBuffer(textScale.substring(colon + 1)); } String longString = buf.toString().trim(); realValue = new Long(longString); } catch (NumberFormatException nfe) { if (Debug.debugging("rpftoc")) { Debug.output("textScaleToLong: Number Format Exception!!!!" + textScale); } return (long) RpfConstants.UK.scale; } catch (StringIndexOutOfBoundsException sioobe) { if (Debug.debugging("rpftoc")) { Debug.output("textScaleToLong: String index out of bounds:\n" + sioobe.getMessage()); } return (long) RpfConstants.UK.scale; } long ret = (realValue.longValue() / resolution.longValue()); if (Debug.debugging("rpftoc")) { Debug.output("RpfTocHandler: textScaleToLong converted " + textScale + " to " + ret); } return ret; } protected int getASCIIZone(float ullat, int zone) { int z = zone; // Now convert it to ASCII to compare if (ullat > 0) z += 48; // for ASCII compare next else { z += 64; if (z == 73) z++; // Can't be equal to I -> J } return z; } /** * Given a coordinate box and a scale, return the entries that * have coverage over the given area. The chart types returned are * dictated by the chartSeriesCode passed in, which must be an * entry from an RpfProductInfo.seriesCode. * * @param ullat upper left latitude, in decimal degrees * @param ullon upper left longitude, in decimal degrees * @param lrlat lower right latitude, in decimal degrees * @param lrlon lower right longitude, in decimal degrees * @param proj CADRG projection describing map. * @param chartSeriesCode chart selection. If null, all coverage * boxes fitting on the screen will be returned. * @param coverages a list of potential coverages * @return a Vector of applicable RpfCoverageBoxes. */ public void getCatalogCoverage(float ullat, float ullon, float lrlat, float lrlon, CADRG proj, String chartSeriesCode, Vector coverages) { if (!valid) return; String chartSeries; for (int i = 0; i < numBoundaries; i++) { // Try to get the boundary rectangle with the most // coverage, so reset the entry for this particular query.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -