Mars Data Analysis Using IDL GG7101 Lecture 7 - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Mars Data Analysis Using IDL GG7101 Lecture 7

Description:

Assoc, EOF, File pointers, File info, finding files, picking files. In class ... to resize an array containing THEMIS floating point data called them_data that ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 21
Provided by: fscotta
Category:

less

Transcript and Presenter's Notes

Title: Mars Data Analysis Using IDL GG7101 Lecture 7


1
Mars Data Analysis Using IDLGG710-1Lecture 7
  • F. Scott Anderson
  • Office POST 526B
  • Phone 956-6887
  • Email anderson_at_higp.hawaii.edu

2
Review of Monday
  • Finished Control Statements repeat, break,
    continue, goto
  • Global variables
  • Efficient Code
  • I/O
  • Homework 2
  • Error Handling

3
Today
  • 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

4
Quiz Scores
  • Tapped a deep vein of lack of understanding
  • Average 75
  • StdDev 27
  • Scores
  • 31 38 71 92 94 100 100

5
Quiz
  • 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)

6
Quiz
  • 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!'

7
Questions 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

8
Question 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

9
Question 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

10
Quiz
  • 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.

11
More on I/O
  • Three very useful functions for I/O

12
EOF
  • 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

13
fstat
  • 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
14
findfile
  • 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

15
diaglog_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.

16
point_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

17
assoc
  • 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

18
assoc 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

19
In 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

20
In 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
Write a Comment
User Comments (0)
About PowerShow.com