X
20 Rate this article:
No rating

[INTERNAL] How to programmatically remove comments from an ASD binary file

Anonym

When capturing spectra with an ASD spectrometer (using FS3, for example), users have the option of providing text in a comment field, which is then embedded in the outputted binary file. When this binary file in brought into ENVI by way of a Spectral Library dialog, the comment field is used as the name for the spectrum in that library. This is not always ideal. This Help Article describes how to programmatically remove a comment from the ASD binary file so that the unique name of the file is used for the spectrum instead.

When a user imports an ASD binary file into ENVI, ENVI searches the embedded file header for a comment. If a comment is not found, the name of the file (e.g., example.001) is used as the name of the spectrum that appears in the Spectral Library dialog. If a comment is found, it is used instead. However, comments can be lengthy, or even identical, across multiple files. If files with complicated or identical comments are brought into the same Spectral Library, the resulting spectra list can be very confusing. The most straightforward solution is to programmatically strip comments from the binary files so that each spectrum has a unique name based on the original ASD file name. To do this, only a few lines of IDL code are necessary. The example code below does the following:

- Opens the selected ASD binary file as an unformatted binary file.
- Points IDL to the fourth position in the file, which is where the comment field begins.
- Replaces existing data within the comment field (157 characters in length) with an empty array of the same length (each position having a value of 0).

The above process essentially "erases" the portion of the embedded header that contains any information about comments. The result is an ASD file that, when brought into ENVI, will produce a spectrum name based on the name of the file.

This program, with some modification to allow for string to byte conversion, could also be used to programmatically write comments into an embedded ASD header.

Code example:

pro remove_asd_description
	compile_opt idl2

	filename=dialog_pickfile()

	openu, lun, filename, /get_lun

	point_lun, lun, 3

	writeu, lun, bytarr(157)

	free_lun, lun

end