📄 maketoc.java
字号:
// Debug.output("WARNING: File \"" + framename + // "\" doesn't match internal name \"" + head.filename + // "\" - Fixed."); // } isoverview = false; islegend = false; String padding = null; String seriesCode = head.filename.substring(9, 11); RpfProductInfo rpi = RpfProductInfo.get(seriesCode); String scaleString = rpi.scaleString; if (rpi == RpfConstants.UK) { Debug.output("MakeToc: " + frame.filename + " unknown map type " + seriesCode + " - ignoring."); continue; } else if (rpi.scale == RpfConstants.Various) { // need to figure out how to consult the frame for // what it is. // RpfAttributes.chartSeriesCode might have something // to base it off. // GNC = GN, JNC = JN, ONC = ON, TPC = TP, JOG = 15, // TLM50 = V7, // But I'm not sure about the others. For now, prompt // for scale. scaleString = promptForScale("What is the scale for " + frame.filename + "? (Answer should look like: 1:XXX,XXX)"); if (scaleString == null || scaleString.length() == 0) { Debug.error("Bad input for scale for " + frame.filename + ", skipping."); continue; } } if (rpi.dataType.equalsIgnoreCase(RpfConstants.CIB)) { frame.cib = true; } else if (rpi.dataType.equalsIgnoreCase(RpfConstants.CDTED)) { frame.cdted = true; } // else do nothing for CADRG // Set the string to length 12, was 15 for some reason. int scaleStringLength = 12; if (scaleString.length() < scaleStringLength) { padding = createPadding(scaleStringLength - scaleString.length(), false); scaleString = scaleString + padding; } else if (scaleString.length() > scaleStringLength) { scaleString = scaleString.substring(0, scaleStringLength); } frame.scale = scaleString; frame.zone = head.filename.charAt(11); if (isoverview) { coverage.nwlat = coverage.nelat = coverage.nwlon = coverage.swlon = coverage.swlat = coverage.selat = coverage.nelon = coverage.selon = 0; coverage.latInterval = coverage.lonInterval = coverage.nsVertRes = coverage.ewHorRes = 0; } if (islegend) { coverage.nwlat = coverage.nelat = coverage.nwlon = coverage.swlon = coverage.swlat = coverage.selat = coverage.nelon = coverage.selon = 0; coverage.latInterval = coverage.lonInterval = coverage.nsVertRes = coverage.ewHorRes = 0; } /* * PBF 6-18-94 check for rectangular coverage or polar * frame */ if (frame.zone == '9' || frame.zone == 'J') { /* * Polar. Convert boundary from lat-long degrees to * pixels */ /* DKS 1/95: North pole: "9" code */ if (frame.zone == '9') { if (Debug.debugging("maketoc")) Debug.output("Processing NORTH pole"); frame.left = (90.0 - coverage.nwlat) * Math.sin(coverage.nwlon * Math.PI / 180.0) / coverage.latInterval; frame.right = (90.0 - coverage.selat) * Math.sin(coverage.selon * Math.PI / 180.0) / coverage.latInterval; frame.top = -1 * (90.0 - coverage.nwlat) * Math.cos(coverage.nwlon * Math.PI / 180.0) / coverage.latInterval; frame.bottom = -1 * (90.0 - coverage.selat) * Math.cos(coverage.selon * Math.PI / 180.0) / coverage.latInterval; } else { /* DKS 1/95: South pole: "J" code */ if (Debug.debugging("maketoc")) Debug.output("Processing SOUTH pole"); frame.left = (90.0 + coverage.nwlat) * Math.sin(coverage.nwlon * Math.PI / 180.0) / coverage.latInterval; frame.right = (90.0 + coverage.selat) * Math.sin(coverage.selon * Math.PI / 180.0) / coverage.latInterval; frame.top = (90.0 + coverage.nwlat) * Math.cos(coverage.nwlon * Math.PI / 180.0) / coverage.latInterval; frame.bottom = (90.0 + coverage.selat) * Math.cos(coverage.selon * Math.PI / 180.0) / coverage.latInterval; } /* if South pole */ /* DKS 8/1/94: Added for GEOREF calc later */ frame.swlat = coverage.swlat; frame.swlon = coverage.swlon; if (Debug.debugging("maketoc")) { Debug.output("MakeToc: " + frame.filename + " is a Polar frame"); } /* if Debug.debugging("maketoc") */ } else { frame.left = coverage.nwlon; frame.right = coverage.selon; /* * NEW, DKS 6/94. Correct for frame straddling 180 * deg. */ if (coverage.selon < coverage.nwlon) { frame.right = 180.0; } frame.top = coverage.nwlat; frame.bottom = coverage.selat; } frame.h_interval = coverage.lonInterval; frame.v_interval = coverage.latInterval; frame.h_resolution = coverage.ewHorRes; frame.v_resolution = coverage.nsVertRes; frame.marked = false; if (Debug.debugging("maketocframedetail")) { Debug.output("MakeToc: nw_lon = " + coverage.nwlon + ", se_lon = " + coverage.selon + "\n nwlat = " + coverage.nwlat + ", selat = " + coverage.selat + "\n NEW: swlat = " + coverage.swlat + ", swlon = " + coverage.swlon + "\n vert_interval = " + coverage.latInterval + ", horiz_interval = " + coverage.lonInterval + "\n vertical resolution = " + coverage.nsVertRes + ", horizontal resolution = " + coverage.ewHorRes + "\n left = " + frame.left + ", right = " + frame.right + "\n top = " + frame.top + ", bottom = " + frame.bottom + "\n"); } } /* for i: each input frame file */ } /** * Prompt for input. */ public String promptForScale(String query) { try { String answer = null; System.out.println(query); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader bufr = new BufferedReader(isr); answer = bufr.readLine(); return answer; } catch (IOException ioe) { Debug.error("MakeToc: IOException trying to get an answer from you. Dang."); return null; } } /** * Create and write out an A.TOC file. * * @param filename the output filename. * @param head the RpfHeader containing header information. * @param frames the frame Vector. * @param groups the file groups Vector. */ public void writeTOCFile(String filename, RpfHeader head, Vector frames, Vector groups) throws MakeTocException { short us; int i, j, tail; /* * DKS changed from left, right for polar zone: new * left_bottom longit. */ double left_b, left_t, right_b, right_t, top, bottom; double xleft, xright, ytop, ybottom; /* !! To be filled in later */ int TOC_Nitf_hdr_size = 0; /* * ?? Nitf header size for output * TOC */ int Loc_sec_len; /* Location section length */ int Bound_tbl_len; /* Boundary rectangle table length */ int Frame_hdr_len = 13; /* Frame index header length */ int Frame_index_rec_len = 33; /* * Frame index record length * (was 37) */ int Frame_sec_len; /* Frame section length */ RandomAccessFile fout = null; int groupCount = groups.size(); int nFrames = frames.size(); /* cumulative pathname positions */ int[] pathname_pos = new int[nFrames]; /* List of pathnames: directories */ String[] direct = new String[nFrames]; /* Allocations for uniq directories */ int[] uniq_dir_ptr = new int[nFrames]; /* * index from filename * to uniq direct. */ int[] uniq_dir_pos = new int[nFrames]; /* * position of direct. * name in file */ /* list of direct. names */ String[] uniq_dir = new String[nFrames]; String georef = "AAAAAA"; /* GEOREF # */ Frame frame; Group group; // Right now, just write the new file locally. try { fout = new RandomAccessFile(filename, "rw"); /* WRITE TOC : */ if (Debug.debugging("maketoc")) { Debug.output("MakeToc: *** writing TOC ***\n at: " + filename); } /* HEADER SECTION */ if (Debug.debugging("maketoc")) { Debug.output("MakeToc: *** writing header section ***"); } String charString; char[] nt = new char[1]; nt[0] = '\0'; /* DKS. Can't write structure because of pad bytes */ /* fwrite(&head, sizeof(head), 1, fout); */ fout.writeBoolean(head.endian); // Big Endian - should // match head.endian fout.writeShort(RpfHeader.HEADER_SECTION_LENGTH); fout.writeBytes(" A.TOC"); // has to be padded. fout.writeByte(head.neww); fout.writeBytes(head.standardNumber); if (head.standardNumber.length() < 15) { fout.writeBytes(createPadding(15 - head.standardNumber.length(), false)); } fout.writeBytes(head.standardDate); if (head.standardDate.length() < 8) { fout.writeBytes(createPadding(8 - head.standardDate.length(), false)); } // All this trouble just for a silly character. char[] charArray = new char[1]; charArray[0] = head.classification; charString = new String(charArray); fout.writeBytes(charString); Debug.message("maketoc", "MakeToc: writing country(" + head.country + ") and release(" + head.release + ")"); fout.writeBytes(head.country); fout.writeBytes(head.release); /* * New, DKS. no longer head.loc_sec_phys_loc. Always write * 48. */ /* * DFD - This isn't true, but since we don't care about * NITF formatting, it may be. Just write out where we * are. */ int location_section_location = (int) fout.getFilePointer() + 4; fout.writeInt(location_section_location); if (Debug.debugging("maketoc")) { Debug.output("MakeToc: location section location is : " + location_section_location); } if (Debug.debugging("maketoc")) { Debug.output("MakeToc: *** writing location section ***"); } /* LOCATION SECTION */ int Loc_hdr_len = 14; /* Location section header length */ int Loc_sec_comp_len = 10; /* * Location section component * length */ /* 14 + 4 * 10 = 54 */ Loc_sec_len = Loc_hdr_len + (RpfFileSections.TOC_LOCATION_KEY * Loc_sec_comp_len); fout.writeShort(Loc_sec_len); /* compon. loc tbl offset: location section hdr length */ fout.writeInt(Loc_hdr_len); /* # records in location section: 4 */ fout.writeShort(RpfFileSections.TOC_LOCATION_KEY); /* component location record length: 10 */ fout.writeShort(Loc_sec_comp_len); if (Debug.debugging("maketoc")) { Debug.output("MakeToc:\n location section length: " + Loc_sec_len + "\n location header length: " + Loc_hdr_len + "\n number of location records: " + RpfFileSections.TOC_LOCATION_KEY + "\n location section comp length: " + Loc_sec_comp_len); } /* * compon. aggregate len: unknown here. Fill in after * doing all else.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -