| Re: save an IDLanROI to file? (newbie question) [message #40776] |
Thu, 26 August 2004 08:36 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jeff writes:
> Saving the data size info before the actual data is a neat trick, wish
> I'd thought of it :)
Well, after I hit the SEND button I realized I really
didn't show you the neatest trick of all. The data
array should really be created with the Make_Array
function like this:
OpenR, lun, filename, /Get_LUN
sizeInfo = LonArr(5)
ReadU, lun, sizeInfo
data = Make_Array(Size=sizeInfo)
ReadU, lun, data
Free_Lun, lun
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
|
|
| Re: save an IDLanROI to file? (newbie question) [message #40784 is a reply to message #40778] |
Wed, 25 August 2004 21:15  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jeff writes:
> I need to save an IDLanROI object (returned by XROI) to a file
> programmatically. I know how to compute a mask and save that, but I'd
> like to save the actual ROI data too, just to be safe. Should I be
> thinking about making a .sav file?
Well, creating a save file is certainly something you
should *consider*, but whether you should use it or
not often depends on other factors. There are problems
restoring objects in general. See this for example:
http://www.dfanning.com/tips/saved_objects.html
Although you are not likely to run into these problems
with IDLanROI objects. Probably the *next* object you
try to save. :-)
In any case, I often find it more convenient to just
get the information I need from an object (e.g, the
data) and save that in a regular binary data file.
Then I can easily read the data file and recreate
an object when I need it.
The only trick is to be sure to put enough information
in the data file so you can read it again. Something
like this:
myROI -> GetProperty, Data=theData
filename = Dialog_Pickfile(File='myroi.dat', /Write)
IF filename NE "" THEN BEGIN
Obj_Destroy, myROI
OpenW, lun, filename, /Get_LUN
WriteU, lun, Size(data), data
Free_Lun, lun
ENDIF
Then, when you want to read it:
filename = Dialog_Pickfile(File='myroi.dat', /Write)
IF filename NE "" THEN BEGIN
OpenR, lun, filename, /Get_LUN
sizeInfo = LonArr(5)
ReadU, lun, sizeInfo
data = FltArr(sizeInfo[1], sizeInfo[2])
ReadU, lun, data
Free_Lun, lun
myRoi = Obj_New('IDLanROI', data)
ENDIF
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|