Consider a 6x6 array of data with an "XXXX" header and a "YY" trailer on each line. Each data element is a space, a row ("y") index, a comma, and a column ("x") index, as shown below:
XXXX 0,0 0,1 0,2 0,3 0,4 0,5YY XXXX 1,0 1,1 1,2 1,3 1,4 1,5YY XXXX 2,0 2,1 2,2 2,3 2,4 2,5YY XXXX 3,0 3,1 3,2 3,3 3,4 3,5YY XXXX 4,0 4,1 4,2 4,3 4,4 4,5YY XXXX 5,0 5,1 5,2 5,3 5,4 5,5YY
The goal is to produce a data file that looks like the data below. To do that, we need to strip the headers and trailers, and transpose rows and columns:
0,0 1,0 2,0 3,0 4,0 5,0 0,1 1,1 2,1 3,1 4,1 5,1 0,2 1,2 2,2 3,2 4,2 5,2 0,3 1,3 2,3 3,3 4,3 5,3 0,4 1,4 2,4 3,4 4,4 5,4 0,5 1,5 2,5 3,5 4,5 5,5
The key to writing the input format description is understanding that the input data file is composed of four interleaved arrays:
The array of headers is a one-dimensional array composed of six elements (one for each line) with each element being four characters wide and separated from the next element by 28 bytes (24 + 2 + 2 -- 24 bytes for a row of data plus 2 bytes for the trailer plus two bytes for the newline).
The array of data is a two-dimensional array of six elements in each dimension with each element being four characters wide, each row is separated from the next by eight bytes (columns are adjacent and so have zero separation), and the first element begins in the fifth byte of the file (counting from one).
The array of trailers is a one-dimensional array composed of six elements with each element being two characters wide, each element is separated from the next by 30 bytes, and the first element begins in the 29th byte of the file.
The array of newlines is a one-dimensional array composed of six elements with each element being two characters wide (on a PC), each element is separated from the next by 30 bytes, and the first element begins in the 31st byte of the file.
The FreeForm ND input format description needed is:
dBASE_input_data "one" headers 1 4 ARRAY["line" 1 to 6 separation 28] OF text 0 data 5 8 ARRAY["y" 1 to 6 separation 8]["x" 1 to 6] OF text 0 trailers 29 30 ARRAY["line" 1 to 6 separation 30] OF text 0 PCnewline 31 32 ARRAY["line" 1 to 6 separation 30] OF text 0
The output data is composed of two interleaved arrays:
The array of data now has a separation of two bytes between each row, the first element begins in the first byte of the file, and the order of the dimensions has been switched.
The array of newlines now has a separation of 24 bytes and the first element begins in the 25th byte of the file. Each array can be operated on independently. In the case of the data array we simply transposed rows and columns, but we could do other reorientations as well, such as resequencing elements within either or both dimensions.
The FreeForm ND output format description needed is:
dBASE_output_data "two" data 1 4 ARRAY["x" 1 to 6 separation 2]["y" 1 to 6] OF text 0 PCnewline 25 26 ARRAY["line" 1 to 6 separation 24] OF text 0