{ From user Lonnie, Model Reading_binary_data_ at 2-Nov-2016 5:23:45 PM, encoding="UTF-8" } SoftwareVersion 5.0.0 { System Variables with non-default values: } SampleSize := 1000 TypeChecking := 1 Checking := 1 SaveOptions := 2 SaveValues := 0 {!40000|Sys_DefaultNumberFmt := 2,G,4,2,0,0,4,0,$,0,"ABBREV",0,,,0,0,15} NodeInfo FormNode: 1,0,0,1,0,0,0,,0,0,,0,0 AskAttribute Domain,Variable,Yes {!40000|AskAttribute TableCellDefault,Variable,Yes} {!40700|AskAttribute EditBoxCueText,Variable,Yes} Model Reading_binary_data_ Title: Reading binary data file Description: Reads the header of a *.shx file (or header of an *.shp) file, and the index records of the shx file. This demonstrates the use of ReadBinaryFile when the sizes and data types of the items being read vary along the result index.~ ~ I've set this up in a fairly re-usable way, so you can easily change the Header Layout table to match a different binary header layout and select the data types of the items. Author: Lonnie Chrisman, Ph.D.~ Lumina Decision Systems Date: Mon, Oct 31, 2016 9:49 AM SaveAuthor: Lonnie SaveDate: Wed, Nov 2, 2016 5:23 PM DiagState: 2,1,0,943,724,17 WindState: 2,808,390,720,350 FontStyle: Arial,15 FileInfo: 0,Model Reading_binary_data_,2,2,0,0,C:\Users\Lonnie\Documents\Analytica\Example Models\Reading a binary data block.ana Constant Flag_BigEndian Title: Flag BigEndian Description: The flag value added to the itemType parameter of ReadBinaryData to indicate that the data iis in big-endian order. Definition: 32 NodeLocation: 96,480,1 NodeSize: 48,24 NodeInfo: 1,1,0,1,1,1,0,,0,,0,,, Index Binary_data_type Title: Binary data type Definition: ['Int8','Int16','Int32','Int64','UInt8','UInt16','UInt32','UInt64','Float','Double'] IndexVals: ['item 1'] NodeLocation: 96,176,1 NodeSize: 48,24 Objective Shape_header Title: Shape header Description: Reads the binary header. Definition: ReadBinaryFile(File_to_read,~ bytesPer: Bytes_per_header_ite, ~ typeFlags:Type_flag_code + Flag_BigEndian * Big_endian,~ resultIndex: Header_item ) NodeLocation: 448,328,1 NodeSize: 48,24 ValueState: 2,910,4,375,409,,MIDM Aliases: FormNode Fo1478130843 NumberFormat: 2,G,4,2,0,0,4,0,$,0,"ABBREV",0,,,0,0,15 Variable File_to_read Title: File to read Description: The binary file name to read. The example assumes this is an *.shx file. The header of a *.shp file can also be read, but the index records are valid only when it really is a *.shx file. Definition: 'NHDWaterbody.shx' NodeLocation: 448,240,1 NodeSize: 48,24 WindState: 2,538,444,720,350 Aliases: FormNode Fo1478130539 {!40700|Att_CellFormat: CellEntry(0,0,1)} {!40700|EditBoxCueText: Enter *.shx filename (with extension) here} Index Header_item Title: Header item Description: The fields in the binary header. Definition: ['File Code','Unused','Unused','Unused','Unused','Unused','File length','Version','Shape type','Xmin','Ymin','Xmax','Ymax','Zmin','Zmax','Mmin','Mmax'] NodeLocation: 96,232,1 NodeSize: 48,24 WindState: 2,802,440,720,350 ValueState: 2,1134,23,416,303,,MIDM Aliases: FormNode Fo1478130975 {!40000|Att_PrevIndexValue: ['File Code','Unused','Unused','Unused','Unused','Unused','File length','Version','Shape type','Xmin','Ymin','Xmax','Ymax','Zmin','Zmax','Mmin','Mmax']} Variable Header_item_type Title: Header item type Description: The data type of each header item. Definition: Table(Header_item)(Choice(Self,7,0),Choice(Self,7,0),Choice(Self,7,0),Choice(Self,7,0),Choice(Self,7,0),Choice(Self,7,0),Choice(Self,7,0),Choice(Self,7,0),Choice(Self,7,0),Choice(Self,10,0),Choice(Self,10,0),Choice(Self,10,0),Choice(Self,10,0),Choice(Self,10,0),Choice(Self,10,0),Choice(Self,10,0),Choice(Self,10,0)) NodeLocation: 96,288,1 NodeSize: 48,24 WindState: 2,825,456,720,350 DefnState: 2,773,492,424,404,,DFNM Domain: Binary_data_type {!40300|DomainExpr: Binary_data_type} {!40000|TableCellDefault: Choice(Self,4,0)} {!40200|Att_ChoiceIndexes: Keyword Self} Variable Big_endian Title: Big endian Description: True if the data item is stored in most-significant byte first (big-endian). False if stored with least-significant byte first.~ ~ For example, the 16-bit integer 8545 is 33 * 256 + 97, and requires at least two bytes to store. The bytes can be stored in the order: 33, 97 (big endian) or 97,33 (little endian). Definition: Table(Header_item)(Checkbox(1),Checkbox(1),Checkbox(1),Checkbox(1),Checkbox(1),Checkbox(1),Checkbox(1),Checkbox(0),Checkbox(0),Checkbox(0),Checkbox(0),Checkbox(0),Checkbox(0),Checkbox(0),Checkbox(0),Checkbox(0),Checkbox(0)) NodeLocation: 96,352,1 NodeSize: 48,24 WindState: 2,850,462,720,350 DefnState: 2,771,427,441,497,,DFNM DisplayInputs: Variable Bytes_per_header_ite {!40000|TableCellDefault: Checkbox(0)} Variable Bytes_per_header_ite Title: Bytes per header item Description: The number of bytes used by each data type. Definition: DetermTable(Header_item_type)(1,2,4,8,1,2,4,8,4,8) NodeLocation: 296,384,1 NodeSize: 48,32 WindState: 2,665,490,720,350 DefnState: 2,792,533,416,343,,DFNM ValueState: 2,504,113,416,700,,MIDM DisplayOutputs: Variable Big_endian Variable Type_flag_code Title: Type flag code Description: Maps the data type to the itemType parameter value for ReadBinaryFile. Definition: DetermTable(Header_item_type)(1,1,1,1,0,0,0,0,2,2) NodeLocation: 296,288,1 NodeSize: 48,24 WindState: 2,868,504,720,350 DefnState: 2,781,535,416,303,,DFNM Index Index_record Title: Index record Description: Fields in each SHX record. Definition: ['Offset','Content length'] NodeLocation: 592,176,1 NodeSize: 48,24 Variable Num_records Title: Num records Description: The number of records in the *.SHX file just read. This is only valid when the file read really is an SHX file. Definition: (Shape_header[Header_item='File length'] - 50 /*words in header*/) / 4 /*16-bit words per record*/ NodeLocation: 448,424,1 NodeSize: 48,24 ValueState: 2,830,496,416,303,,MIDM NumberFormat: 2,G,4,2,0,0,4,0,$,0,"ABBREV",0,,,0,0,15 Objective Index_records Title: Index records Description: The actual records of the SHX file. These records are easy -- they are all 16-bit positive integers in big-endian order, with no gaps between records. There are two dimensions -- the Index_record is the layout for each record, while the Shape_number indexes all the shapes in the file. Definition: ReadBinaryFile(File_to_read, ~ bytesPer:4, ~ typeFlags:Flag_BigEndian, ~ offset:100, ~ resultIndex:Shape_Number, Index_record ) NodeLocation: 592,240,1 NodeSize: 48,24 ValueState: 2,1047,608,460,222,,MIDM Aliases: FormNode Fo1478130851 ReformVal: [Index_record,0] Variable Header_layout Title: Header layout Description: User interface for selecting the data type and endian-ness of each header item in the binary file. Definition: MultiTable(Self)(Header_item_type,Big_endian) IndexVals: ['Type','Big endian?'] NodeLocation: 96,416,1 NodeSize: 48,24 WindState: 2,813,488,720,350 DefnState: 2,1024,332,337,493,,DFNM Aliases: FormNode Fo1478130578 ReformDef: [Self,Header_item] {!40000|Att_PrevIndexValue: ['Type','Big endian?']} FormNode Fo1478130539 Title: File to read Definition: 0 NodeLocation: 308,40,1 NodeSize: 252,16 NodeInfo: 1,,,,,,0,392,,,,,,0 Original: File_to_read FormNode Fo1478130578 Title: Header layout Definition: 0 NodeLocation: 168,72,1 NodeSize: 112,16 Original: Header_layout Index Shape_number Title: Shape number Description: Indexes all the shape records read from the SHX file. Definition: 1..Num_records NodeLocation: 592,424,1 NodeSize: 48,24 FormNode Fo1478130843 Title: Shape header Definition: 1 NodeLocation: 156,104,1 NodeSize: 100,16 Original: Shape_header FormNode Fo1478130851 Title: Index records Definition: 1 NodeLocation: 352,104,1 NodeSize: 96,16 Original: Index_records FormNode Fo1478130975 Title: Header item Definition: 0 NodeLocation: 372,72,1 NodeSize: 92,16 Original: Header_item Close Reading_binary_data_