A SERVICE OF

logo

244 Chapter 9: Creating a File Reader
Creating a New File Reader iTool Developer’s Guide
; Get the name of the file currently associated with the reader.
filename = self->GetFilename()
; Read the file.
READ_PPM, filename, image
; Store image data in Image Data object.
oImageData = OBJ_NEW('IDLitDataIDLImage', $
NAME = FILE_BASENAME(fileName))
IF OBJ_VALID(oImageData) THEN BEGIN
RETURN, oImageData->SetData(image, 'ImagePixels', /NO_COPY)
ENDIF
RETURN, 0
END
Discussion
The GetData method accepts a single argument, which is a named variable that will
contain the data object. Our GetData method’s first step is to retrieve the file name of
the file on which the method is being called using the GetFilename method. Since our
example file reader reads data from PPM files, the file name is then passed to the IDL
READ_PPM procedure. An IDLitDataIDLImage object that will hold the image data
is created in the named variable specified by the argument to the GetData method
(oImageData, in this case); the NAME property set to the filename of the original
data file. We check to ensure that the oImageData object was created successfully
and add the image data returned by the READ_PPM procedure using the
IDLitData::SetData method. Note the use of the NO_COPY keyword to prevent
making copies of the image data array, which could be quite large. Finally, we return
the value returned by the SetData method (1 for success, 0 for failure), or we return 0
if oImageData is not a valid object.
Note
The type of data object created (IDLitDataIDLImage, in this example) affects how a
particular tool will behave when reading the file. If the data type of the object
returned by the file reader matches one of the data types specified for a parameter of
the visualization being created, the data object is associated with that parameter.
See “Data Type Matching” on page 63 for additional information.