📄 maketoc.java
字号:
*/ /* location component aggregate length file location */ long agg_loc = fout.getFilePointer(); /* save for later */ fout.writeInt(0); // place holder. /* Begin: location section, component location table */ int Bound_hdr_len = 8; /* Boundary section header length */ int Bound_rec_len = 132; /* Boundary record length */ /* Boundary section length */ int Bound_sec_len = Bound_hdr_len + (groupCount * Bound_rec_len); /* Compute frame section length, for later */ pathname_pos[0] = 0; /* cum. offset */ int uniq_dir_cnt = 0; /* # of unique directory paths. */ // Looking for the directory name for each file. for (i = 0; i < nFrames; i++) { /* for each frame file */ /* * set tail to ptr to last occurrence of '/' in * filename */ /* frames[i].filename is full pathname */ frame = (Frame) frames.elementAt(i); tail = frame.filename.lastIndexOf(File.separatorChar); if (tail == -1) { direct[i] = frame.filename; } else { // Java-cise the name, so it meets spec. direct[i] = frame.filename.substring(0, ++tail) .replace('\\', '/'); } if (Debug.debugging("maketocdetail")) Debug.output("MakeToc: Matching directory: " + direct[i]); /* Match direct. names with list of uniq direct. names */ /* flag for found name in list */ boolean uniq_dir_match = false; String tmpDir = null; if (relativeFramePaths) { int rpfIndex = direct[i].indexOf("RPF"); if (rpfIndex == -1) { rpfIndex = direct[i].indexOf("rpf"); } if (rpfIndex != -1) { rpfIndex += 3; if (direct[i].length() > rpfIndex && direct[i].charAt(rpfIndex) == '/') { rpfIndex++; } tmpDir = "./" + direct[i].substring(rpfIndex); } else { if (Debug.debugging("maketoc")) { Debug.output("RPF directory not found in directory path " + direct[i] + ", using absolute path"); } tmpDir = direct[i]; } } else { tmpDir = direct[i]; } for (j = 0; j < uniq_dir_cnt; j++) { if (tmpDir.equals(uniq_dir[j])) { uniq_dir_ptr[i] = j; uniq_dir_match = true; if (Debug.debugging("maketocdetail")) Debug.output("Found match with: " + uniq_dir[j]); break; } } if (!uniq_dir_match) { uniq_dir[uniq_dir_cnt] = tmpDir; uniq_dir_ptr[i] = uniq_dir_cnt; if (Debug.debugging("maketoc")) Debug.output("Adding Unique directory: " + uniq_dir[uniq_dir_cnt]); uniq_dir_cnt++; } /* if */ } /* for i */ if (Debug.debugging("maketoc")) Debug.output("Uniq_dir_cnt: " + uniq_dir_cnt); /* compute uniq dir pathname table length */ int path_table_len = 0; for (j = 0; j < uniq_dir_cnt; j++) { /* 2 for path length var. in hdr */ path_table_len += 2 + uniq_dir[j].length(); } /* for j */ /* compute directory name positions in file */ uniq_dir_pos[0] = 0; for (j = 1; j < uniq_dir_cnt; j++) { uniq_dir_pos[j] = uniq_dir_pos[j - 1] + 2 + uniq_dir[j - 1].length(); } /* for j */ for (j = 0; j < uniq_dir_cnt; j++) { if (Debug.debugging("maketocdetail")) Debug.output("j: " + j + ", uniq_dir_pos[j]: " + uniq_dir_pos[j]); } /* for j */ /* compute direct. positions for each input file pathname */ for (i = 0; i < nFrames; i++) { pathname_pos[i] = uniq_dir_pos[uniq_dir_ptr[i]]; if (Debug.debugging("maketocdetail")) Debug.output("i: " + i + ", pathname_pos[i]:" + pathname_pos[i]); } /* for i */ /* * frame file index record length: 9 + nFrames * 33 + * path_table_len */ Frame_sec_len = Frame_hdr_len + nFrames * Frame_index_rec_len + path_table_len; /* START LOCATION RECORD 1 */ /* ID #: */ fout.writeShort((short) RpfFileSections.LOC_BOUNDARY_SECTION_SUBHEADER); // The boundary section subheader is the first part of the // bounfary rectangle section. The boundary section comes // right after the header (in this program - the spec will // allow it to be anywhere). /* Boundary section subheader length */ fout.writeInt(Bound_hdr_len); /* DKS. Physical location */ /* 0 + 48 + 54 */ fout.writeInt(TOC_Nitf_hdr_size + RpfHeader.HEADER_SECTION_LENGTH + Loc_sec_len); /* START LOCATION RECORD 2 */ /* ID #: */ fout.writeShort((short) RpfFileSections.LOC_BOUNDARY_RECTANGLE_TABLE); /* Boundary rectangle table length */ Bound_tbl_len = groupCount * Bound_rec_len; fout.writeInt(Bound_tbl_len); /* DKS. Physical location */ /* 0 + 48 + 54 + 8 */ fout.writeInt(TOC_Nitf_hdr_size + RpfHeader.HEADER_SECTION_LENGTH + Loc_sec_len + Bound_hdr_len); Bound_sec_len = Bound_hdr_len + Bound_tbl_len; /* START LOCATION RECORD 3 */ /* ID #: */ fout.writeShort((short) RpfFileSections.LOC_FRAME_FILE_INDEX_SUBHEADER); /* length */ fout.writeInt(Frame_hdr_len); /* physical index (offset) */ fout.writeInt(TOC_Nitf_hdr_size + RpfHeader.HEADER_SECTION_LENGTH + Loc_sec_len + Bound_sec_len); /* START LOCATION RECORD 4 */ /* ID #: */ fout.writeShort((short) RpfFileSections.LOC_FRAME_FILE_INDEX_SUBSECTION); /* length */ /* Frame_sec_len computed above */ fout.writeInt(Frame_sec_len - Frame_hdr_len); /* physical index (offset) */ fout.writeInt(TOC_Nitf_hdr_size + RpfHeader.HEADER_SECTION_LENGTH + Loc_sec_len + Bound_sec_len + Frame_hdr_len); if (Debug.debugging("maketoc")) { Debug.output("MakeToc: boundary section at : " + fout.getFilePointer()); } /* START BOUNDARY RECTANGLE SECTION */ if (Debug.debugging("maketoc")) { Debug.output("MakeToc: *** writing boundary rectangles ***"); } /* Subheader */ /* boundary rectangle table offset */ fout.writeInt(0); /* # of boundary rectangle records */ fout.writeShort((short) groupCount); /* boundary rectangle record length */ fout.writeShort((short) Bound_rec_len); /* For each boundary rectangle record */ for (i = 0; i < groupCount; i++) { group = (Group) groups.elementAt(i); /* * Key off flag to write proper data to A.TOC for * browse menu later */ if (group.cib) { fout.writeBytes("CIB "); fout.writeBytes("8:1 "); /* Compr. ratio */ } else if (group.cdted) { fout.writeBytes("CDTED"); fout.writeBytes("6.5:1"); /* * Compr. ratio: * VARIABLE */ } else { fout.writeBytes("CADRG"); fout.writeBytes("55:1 "); } /* else */ // Should be 12 padded chars, check just in case... if (group.scale.length() < 12) { fout.writeBytes(group.scale); fout.writeBytes(createPadding(12 - group.scale.length(), false)); } else { fout.writeBytes(group.scale.substring(0, 12)); // Already // 12 // padded // chars } // All this trouble just for a silly character. charArray[0] = group.zone; charString = new String(charArray); fout.writeBytes(charString); /* DKS changed from AFESC to DMAAC 8/2/94 */ /* Producer: */ // Should be OpenMap BBN, I guess. fout.writeBytes(producer); /* * PBF - If group is polar, change boundaries from * rect coordinates to lat-lon -- 6-19-94 */ if (group.zone == '9' || group.zone == 'J') { /* * polar * zone */ /* * DKS: switched x,y to match spec: x increases * right, y up. */ ytop = group.horiz_pos[group.top]; ybottom = group.horiz_pos[group.bottom]; xleft = group.vert_pos[group.left]; xright = group.vert_pos[group.right]; if (Debug.debugging("maketoc")) { Debug.output("POLAR ZONE. ytop: " + ytop + ", ybottom: " + ybottom + ", xleft: " + xleft + ", xright:" + xright); } /* see CADRG SPEC 89038, p. 50 */ /* * FIND LATITUDES from x,y. x increases right, y * up. */ /* DKS new 1/95 to handle South pole separately. */ /* h_interval converts from pix to deg. */ if (group.zone == '9') { /* "9": NORTH POLE */ top = 90 - (Math.sqrt((ytop * ytop) + (xleft * xleft)) * (group.h_interval)); bottom = 90 - (Math.sqrt((ybottom * ybottom) + (xright * xright)) * (group.h_interval)); } /* North pole */ else { /* "J": South Pole */ top = -90 + (Math.sqrt((ytop * ytop) + (xleft * xleft)) * (group.h_interval)); bottom = -90 + (Math.sqrt((ybottom * ybottom) + (xright * xright)) * (group.h_interval)); } /* South pole */ if (Debug.debugging("maketoc")) Debug.output("LATS. top: " + top + ", bottom: " + bottom); /* * Cvt from x,y to LONGITUDE; from radians to * degrees */ /* DKS added South pole case 1/95 */ if (group.zone == '9') { /* "9": NORTH POLE */ left_t = 180.0 / Math.PI * Math.acos(-ytop / Math.sqrt((ytop * ytop) + (xleft * xleft))); /* DKS fixed bug 1/95: from ytop to ybottom */ left_b = 180.0 / Math.PI * Math.acos(-ybottom / Math.sqrt((ybottom * ybottom) + (xleft * xleft))); right_t = 180.0 / Math.PI * Math.acos(-ytop / Math.sqrt((ytop * ytop) + (xright * xright))); /* DKS fixed bug 1/95: from ytop to ybottom */ right_b = 180.0 / Math.PI * Math.acos(-ybottom / Math.sqrt((ybottom * ybottom) + (xright * xright))); } /* if North pole */ else { /* South Pole */ left_t = 180.0 / Math.PI * Math.acos(ytop / Math.sqrt((ytop * ytop) + (xleft * xleft))); /* DKS fixed bug 1/95: from ytop to ybottom */ left_b = 180.0 / Math.PI * Math.acos(ybottom / Math.sqrt((ybottom * ybottom) + (xleft * xleft))); right_t = 180.0 / Math.PI * Math.acos(ytop / Math.sqrt((ytop * ytop) + (xright * xright)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -