X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



5442 Rate this article:
1.0

Tutorial for using BINARY_TEMPLATE and READ_BINARY

Topic:

This article provides an example of how to use the BINARY_TEMPLATE and READ_BINARY functions.

Discussion:

First there is an example of how to use the BINARY_TEMPLATE function on the following help pages:

http://www.harrisgeospatial.com/docs/READ_BINARY.html

The example starts in the "Working with a READ_BINARY Data structure" section of the READ_BINARY help which references the steps listed in the BINARY_TEMPLATE example.

An additional example of how to use the BINARY_TEMPLATE is shown below:

1) First, create a binary file using the code below. This will create a binary file with three data sets (float, long, byte) that is composed of 10 elements each.

pro ex_create_binary_4temp

  compile_opt idl2

  a = findgen(10)
  b =lindgen(10)*10
  c =bindgen(10)+10b

  openw,lun,"ex_binary_file_4temp.dat",/get_lun

  writeu,lun,a,b,c
  free_lun, lun

end

2) Enter "file = dialog_pickfile()" into the IDL console and navigate to the "ex_binary_file_4temp.dat" file that you created in step 1.

3) Enter "ex_temp=binary_template(file)" into the IDL console.

4) This will bring up the "Binary Template"dialog. Click the "New Field" button.

5) This will bring up the "New Field" dialog.The first field in your data is the float array. Enter "float_data"as the Field name. Select "Float (32 bits)" as the type and"1" as the Number of dimensions. Enter "10" as the size and click "OK".

6) Repeat steps 3 and 4 for the long field. Enter the following information into the New Field dialog:

Field name : "long_data"
Type: "Long (32 bits)"
Number of dimensions: '1'
Size:10

7) Repeat steps 3 and 4 for the byte field. Enter the following information into the New Field dialog:

Field name: "byte_data"
Type: "Byte (unsigned 8 bits)"
Number of dimensions: '1'
Size: 10

Click "OK" in the "Binary Template"dialog.

8) Enter "rr = read_binary(file,template=ex_temp)" into the IDL console to read the data.

IDL> rr = READ_BINARY(file, TEMPLATE=ex_temp)

IDL> help, rr
** Structure <a260470>, 3 tags, length=92, datalength=90, refs=1:
  FLOAT_DATA      FLOAT    Array[10]
  LONG_DATA       LONG     Array[10]
  BYTE_DATA       BYTE     Array[10]

IDL> print, rr.float_data
     0.000000      1.00000      2.00000      3.00000      4.00000
    5.00000     6.00000      7.00000      8.00000      9.00000

IDL> print, rr.long_data
         0          10          20          30          40          50
       60          70          80          90

IDL> print, rr.byte_data
10  11 12  13  14  15  16 17  18  19

9) You can save the template for future use with the SAVE routine:

save, ex_temp, FILENAME="ex_temp.sav"

You can use the RESTORE routine to load this variable into a new session of IDL:

restore, "ex_temp.sav"

9) You can modify the existing the template using the TEMPLATE keyword when calling BINARY_TEMPLATE:

ex_temp_new = BINARY_TEMPLATE(file, TEMPLATE=ex_temp)


Written by DS and reviewed by JU 02/07/2014

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »