X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 01 Aug 2011 07:58 PM by  anon
READ BINARY with skip
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
01 Aug 2011 07:58 PM
    Hi Folks, I am trying to read some specific binary data coming from planetary missions. I am currently using MATLAB for that, but I want for some reasons switch to IDL for a few of my analysis. I am blocked to a stupid issue because so far I know, READ_BINARY command does not offer to skip between record as the FREAD Matlab command does. Here is the line I use under MATLAB for reading my data: val = fread(fid,rows,precision,skip); where, fid is the identifier, rows the number of records, precision it the data type and then skip specifies the number of bytes to skip after each precision value. IDL do not provide such easy way to read binary data like MATLAB does. Does anybody have any idea how I can convert my current line (which is really simple) into IDL ? Thank you, ~A.

    Deleted User



    New Member


    Posts:
    New Member


    --
    10 Aug 2011 11:04 AM
    I think the easiest way to achieve your goals is to use the OPENR, READU, and FREE_LUN routine. The READU routine will data read binary files into IDL variables. For example give READU a float variable, it will assign the next four bytes of data in the open binary file to that variable. To skip bytes of data in the file you don't care about, you can create byte array where the number elements corresponds to the number bytes you want to skip. You can then use READU to assign the skipped data to this array. Below is an example program called "pro skip_example". In this example program, a binary file is written with three arrays (byte, float, double). 10 unnecessary bytes are written between these arrays using the variable "junk". The file is then read using the READU command. The unnecessary bytes are skipped using the variable "new_junk". pro skip_example junk = bytarr(10) x = bindgen(10) y = findgen(10) z = dindgen(10) openw, lun, 'testdata.dat', /get_lun writeu, lun, x, junk writeu, lun, y, junk writeu, lun, z, junk free_lun, lun openr, lun, 'testdata.dat', /get_lun newx = bytarr(10) newy = fltarr(10) newz = dblarr(10) new_junk=bytarr(10) readu, lun, newx, new_junk readu, lun, newy, new_junk readu, lun, newz, new_junk print, newx, newy, newz free_lun, lun end You may also want to try using the BINARY_TEMPLATE routine with READ_ASCII and the TEMPLATE keyword. BINARY_TEMPLATE displays a GUI which allows you to specify the format of your data.
    You are not authorized to post a reply.