Title: Mars Data Analysis Using IDL GG7101 Lecture 7
1Mars Data Analysis Using IDLGG710-1Lecture 7
- F. Scott Anderson
- Office POST 526B
- Phone 956-6887
- Email anderson_at_higp.hawaii.edu
2Review of Monday
- Finished Control Statements repeat, break,
continue, goto - Global variables
- Efficient Code
- I/O
- Homework 2
- Error Handling
3Today
- Questions from last time
- Quiz returned
- Quiz
- Finish I/O
- Assoc, EOF, File pointers, File info, finding
files, picking files - In class exercise
- reading binary I/O with a structure
- Review of today's class
4Quiz Scores
- Tapped a deep vein of lack of understanding
- Average 75
- StdDev 27
- Scores
- 31 38 71 92 94 100 100
5Quiz
- Show the command to resize an array containing
THEMIS floating point data called them_data that
is 800 samples by 1000 lines to a new array
called new_data that is 700 samples by 800 lines - new_data congrid(them_data, 700, 800)
- Assume there is a function called
seismic_scale_depth that is handed density and
returns a distance. Show how to call this
function with a density of 2.7 and store the
returned data in a variable zdepth - zdepth seismic_scale_depth(2.7)
6Quiz
- Show a for loop that prints the numbers 5.5 to
10.5 in steps of 0.5 - for ctr5.5, 10.5, 0.5 do print, ctr
- for ctr0, 10 do begin
- x5.5
- print, x
- xx0.5
- endfor
- Show an if statement that prints the words 'Got
ya!' if a variable named status1 equals 4.3 - if (status1 eq 4.3) then print, 'Got Ya!'
7Questions from 9/28
- Goto with multiple labels Gives an error
- Common blocks
- Main routine definition must list all variables
- Use in subroutines does not require showing
variables, but does require common block name - Strings in read Remind me of the question?
- Other questions I missed last time
8Question strtrim
- Recall that IDL will convert a number that is
written to the screen or a file as a string - The default format for converting a number to a
string includes many leading and trailing spaces - Hence
- print, 'Value ', 10 Number auto converted
to string - results in
- Value 10 where the underline
indicates spaces - To remove spaces from a string, use strtrim
- Form
- result strtrim(variable, 0,1,2)
- print, 'Value ', strtrim(10) Trim
trailing spaces - print, 'Value ', strtrim(10, 0) Trim
trailing spaces - print, 'Value ', strtrim(10, 1) Trim
leading spaces - print, 'Value ', strtrim(10, 2) Trim both
leading trailing spaces
9Question Filenames w/numbers
- You can create repeating numbered filenames
- This examples creates filenames that look like
- my_filename_no_1.dat
- my_filename_no_2.dat
- my_filename_no_3.dat
-
- my_filename_no_10.dat
- for ctr1,10 do begin
- filenamestring('my_filename_no_',
strtrim(ctr,2), '.dat') - openw, ilun, filename, /get_lun
- lets assume an array called joe with 1440,720
data points - printf, ilun, joe
- free_lun, ilun
- endfor
10Quiz
- What type of control statements result in
inefficient IDL code? - What are the three general steps required for
interacting with any file? - What is the difference between a floating point
ASCII file and a floating point binary file? - Is it possible to write a file with mixed ASCII
and binary data? - Show the IDL commands to write a 5 line, 10
sample, indexed array to an ASCII file.
11More on I/O
- Three very useful functions for I/O
12EOF
- End of File denotes the actual end of data in a
file - The eof() function tests to see if you are at the
end of a file - Form
- valueeof(lun)
- value is either true or false
- Example
- Imagine you have a file with 5 samples x n lines.
How to read? - while(not eof(ilun)) do readf, ilun, d1, d2, d3,
d4, d5
13fstat
- Provides a structure of information on an open
file - Form
- valuefstat(lun)
- Example
- openr, ilun, some_file.txt,
- /get_lun
- infofstat(ilun)
- help, info, /struct
Structure FSTAT, 17 tags, length64, data
length64 UNIT LONG
100 NAME STRING 'tmp' OPEN
BYTE 1 ISATTY BYTE
0 ISAGUI BYTE 0
INTERACTIVE BYTE 0 XDR
BYTE 0 COMPRESS BYTE 0
READ BYTE 1 WRITE
BYTE 1 ATIME LONG64
1097087305 CTIME LONG64
1097087344 MTIME LONG64
1097087344 TRANSFER_COUNT LONG
25 CUR_PTR LONG
330 SIZE LONG 330
REC_LEN LONG 0
14findfile
- Allows you to search for a file in a known
directory and retrieve its exact filename - Form
- valuefindfile(file_name, countvar1)
- Example
- iname findfile(/Users/home/my_data/.dat,
countnn) - openr, ilun, iname, /get_lun
-
- Should check nn to see if more than one file (or
none), and use inamen to access each
15diaglog_pickfile
- Allows you to choose a file with a GUI interface
- Form
- valuedialog_pickfile(filtermy_string,
many_other_options) - Example
- filt.jpg, .tif, .gif
- iname dialog_pickfile(filterfilt)
- openr, ilun, iname, /get_lun
-
- Many options allowing you to select directories,
multiple files, files to write, files to read,
default file names, etc. Check idl_help for more
details.
16point_lun
- Allows you to move to a given location in a file
- Can be used to skip headers, reread previously
read data, or skip to the end of a file - Form
- point_lun, lun, position_var
- if lun is negative, places the current position
in position_var - Example
- hdr_sz2048L Header of 2048 bytes
- openr, ilun, 'my_data.bin', /get_lun
- point_lun, ilun, hdr_sz
- point_lun, -ilun, pos
- print, pos
-
- start reading data here
17assoc
- Allows you to connect a variable (typically an
array or structure) and a data file - Allows you to read data repeatedly into this
variable by making a region of memory and a
region of the file equal - Does not know how many sets of data you seek
- Hence must determine number of sets or records
independently - Form
- varfltarr(10) or perhaps varint0,
dblarr(10,10) - resultassoc(lun, var, offset, /packed)
- result is an array of type var, with a number of
indices equal to the number of records - offset is used to skip an initial header of
offset bytes - /packed is used to insure that structures are
read correctly on a given computer - must know number of records independently
- Does not actually read data until you ask for
resultn, e.g. - print, result3
18assoc example
- Assume a file with 2 integers and five floats,
and 10 lines - varv10, v20, v3fltarr(5)
- openr, ilun, 'my_file', /get_lun
- resultassoc(ilun, var, /packed)
- print, result0 Works
- print, result0.v2 Fails - IDL can't do
structure - members when using assoc
- tmp1 result0
- tmp2 result100
- print, tmp1.v2
- print, tmp2.v1
- Only works if there are at least 100 records,
otherwise get EOF error
19In Class Exercise (10 minutes)
- Putting it all together
- Download the file my_data.bin from my website
- This file of mola data consists of an integer
value for orbit track, and three floats, lat,
lon, and topo - Assume an unknown number of records
- Create a program to read this data and print the
latitudes - Use the fstat command to calculate the of
records - Create a structure and replicate it to read data
- Use readu to read this data
20In Class Exercise Answer
pro molat chunk orb0, lat0.0, lon0.0,
topo0.0 openr, ilun, 'my_data.bin',
/get_lun infofstat(ilun) nrec
info.size/(12. 34.) datareplicate(chunk,
nrec) readu, ilun, data free_lun, ilun
may need to byte swap data if on PC data
swap_endian(data) plot, data.lat,
data.topo stop end