X
33 Rate this article:
No rating

Internal: How can I open an ASCII file with wrapped data to use in iTools?

Anonym

The routine used to import or open ASCII files into iTools such as iMap assumes that the file is in a format of columns representing fields, such as x, y, and z, or latitude, longitude, and temperature.

Datasets that are in the format of an n x m array whereby the data is already gridded according to the x and y axes is not recognized as such by the ASCII Template routine used by iTools. In order for it to do so, the fields need to be grouped into one field.

Should the ASCII data be in a format where the data are wrapped within the file, with one line of data being spread out over several lines within the file, the data needs to be formatted to be one line of data per line in the file.

The ASCII_template dialog box pops up when opening an ASCII file in an iTool such as iContour. This routine assumes that data will be presented in the format below, with fields or columns of data representing different dimensions.

Latitude      Longitude      Temperature
60.00         -115.00      0.0
60.05         -115.05      10.0
60.25         -115.25      15.0
60.15         -115.15      20.0

Data is sometimes available in the form of an n x m array whereby temperature, for example, is already gridded, as in the example below.

0.0   5.0   10.0   5.0   3.0
2.0   7.0   11.0   7.0   4.0
4.0   10.0   14.0   9.0   5.0
3.0   9.0   12.0   13.0   7.0
4.0   11.0   12.0   10.0   9.0

To see how to get ASCII_Template to read gridded data, go ahead and follow these steps below. We will use the function DIST to generate an artificial n x m data array.

1. Open IDL and enter the following commands:

openw, lun, 'test_data.txt', /get_lun
printf, lun, DIST(50), format = '(50f10.2)'
free_lun, lun

This data file will be saved to the directory indicated in your IDL Preferences/Path.

2. Go ahead and open the iTool, iContour, by typing iContour in the IDLDE command line.

3. In iContour, select File ' Open, and select the file 'test_data.txt.'
This will automatically open the ASCII_Template dialog box.

4. At Step 1, leave the radio button on "Delimited" where it is, and click on "Next" in the bottom right corner.

5. At Step 2, leave the radio button on the page marked "White Space" and other buttons as they are and click on "Next" in the lower right-hand corner.

6. At Step 3 on the ASCII Template dialog box, click on the button "Group All."
This tells the ASCII reader that this data is not in fields or columns containing different variables such as x, y, and z. "Group All" instructs the ASCII reader to see the data as one field of data in an n x m array.

7. Click on "Finish" in the lower right-hand corner. A simple contour plot of this data set will show up. You can modify this contour plot by right-clicking on a contour line to call up the visualization browser.

The data have now been read by the iTool.

*****

How can I get iTools to read the ASCII data if the file contains enough columns in each row such that the data is wrapped?

For example, in the case below, the data might be intended to have 20 columns by 2 rows, that is 20x 2. However, when I wrote the data to a file, it wrapped it, creating six rows with variable numbers of columns in it.

0.0   5.0   10.0   5.0   3.0    7.0   8.0   9.0
2.0   7.0   11.0   7.0   4.0   6.0   5.0   6.0
4.0   10.0   14.0   9.0   5.0
3.0   9.0   12.0   13.0   7.0   7.0   8.0   5.0
4.0   11.0   12.0   10.0   9.0   6.0   7.0   6.0
5.0   10.0   9.0   8.0

You will then need to format the data so that it does not wrap in order for the ASCII TEMPLATE to be able to read the data properly and plot it in an iTool. For example,

pro write_data
xs = 20
ys = 30
file = 'test.txt'
data = dist(xs,ys)
openw, lun, file, /get_lun
; In the format statement below, it is taking the value of the number of columns, xs, defined above, converting it into a string, trimming white space off the beginning and end using the argument '2', and then formatting it to allow for seven digits (including the decimal) with three digits given space after the decimal. In this case, since there are 20 columns, xs is 20.
format_code = '(' + strtrim(xs,2) + 'f7.3)'
;print, format_code
printf, lun, data, format = format_code
free_lun, lun
end

If you check the data file that was written by this program, you will see that the twenty columns are laid out with no wrapping. If you were to remove the formatting from the line:

Printf, lun, data

You would see wrapping of the data in the ASCII file.

Formatting the data will create a data file in the exact format needed by the ASCII TEMPLATE.