IDL - Data Input & Output
-
Upload
peter-gibson -
Category
Documents
-
view
54 -
download
0
description
Transcript of IDL - Data Input & Output
IDL - Data Input & Output
NCKU Phys. Cheng-Ling [email protected]
Data IO
Data Stream Input: keyboard, input device Output: terminal, printer
File – data is read from file and write to a file Types: data, image, and any type of
signals
IDL - File types
ASCII FilesBinary FilesImage FilesWAV Audio Files
ASCII & Binary
ASCII Slower Portable Need more memory size Edited directly
Binary Efficient Not portable Compact Not directly human readable
The two level of IDL’s IO
High-Level Easy using and time efficient Inflexible
Low-Level Difficult and time-consuming Flexible
High-Level IDL’s IO
Function list File:
read_ascii(ascii_template) read_binary(binary_template)
Image read_bmp, read_jpeg, read_tiff
Sound read_wave
Low-level IDL’s IO
LUN(logic unit number) File support limit 2.3 GB
Adress up to 2^31-1 bytes (32-bit program) Range –2 to 128 0, -1, -2 are stdin, stdout, stderr 1-99: user specified 100-128: managed by GET_LUN and FREE
_LUN
Low-level IDL’s IO
Formated / Unformatted Formated
readf(read), printf(write) Unformatted
readu, writeu
Low-level IDL’s IO
Manipulate files Open files: openr, openw, openu Get detail information: fstat Position the file pointer(unit byte): point_lun Check end-of-file: eof Close files: close IDL current open files: help, /files
Low-level IDL’s IO
Format Fortran style
A(Character), D(double), F(float), I(integer), O(octal), Z(Hexadecimal)
print, !PI, format='("I guess pi value is ", 1X, F24.12)'
C style %C(Character), D(double), F(float), I(integer),
O(octal), Z(Hexadecimal) print, !PI, format='(%"I guess pi value is %12.4f")'
Low-level IDL’s IO
Formatted IOName Years Salary-------------------------Johnny 2002 2000.5Ted 2003 1000.5Ken 2001 1500.5
CommandIDL>openr, 1, "D:\doc\ 教育訓練及展示 \IDL\io\format.txt“IDL>head=‘’IDL>name=‘’ & yy=0L & ss=0.0IDL>readf, 1, format="(A30)", headIDL>readf, 1, format="(A10, 1X, I4, 4X, F10.5)", name, yy, ssIDL>Close, 1
Low-level IDL’s IO
Unformatted IO Not portable because various
machines have different the representation of binary data
XDR(portable) Add extra bookkeeping information to
stored in the file
Image Input&Output
IDL’s Image Representation Pixel: byte(0-255) Color System
RGB(Red, Green, Blue) HLS(Hue, Lightness, and Saturation) HSV(Hue, Saturation, and Value)
Device
Device means graphics environmentSupported Devices
CGM Computer Graphics MetafileHP Hewlett-Packard Graphics Language (HP-GL)LJ Digital Equipment LJ250 (VMS Only)MAC Macintosh displayMETAFILE Windows Metafile Format (WMF)NULL No graphics outputPCL Hewlett-Packard Printer Control Language (PCL)PRINTER System printerPS PostScriptREGIS Regis graphics protocol (DEC systems only)TEK Tektronix compatible terminalWIN Microsoft Windows X X Window SystemZ Z-buffer pseudo device
Device
select the graphic device Set_plot, “win” To check the system variable, !
d.name
Device
Most keywords to the DEVICE procedure are sticky ?that is, once you set them, they remain in effect until you explicitly change them again, or end your IDL session.
Device(win)
It can do? VISUAL_DEPTH – color system Font Graphic function
Device(win)
Which’s your system’s graphics environment 24bits 16bits 8bits
Get your system’s visual depthIDL>device, get_visual_depth=depthIDL>print, depth
The color system
TrueColor (16-, 24-, or 32-bit)-DefaultIDL>device, decomposed=1 Image
IDL>READ_jpeg,'C:\Documents and Settings\johnny\My Documents\My Pictures\Sample.jpg', img)IDL>TV, img, true=1
color indices to be interpreted as 3, 8-bit color indices, ‘(bbggrr)’xlIDL>PLOT, [0,1], col=‘ff0000’xl
ColorTable(8bit)IDL>device, decomposed=0
(the least-significant 8 bits of the color index value to be interpreted as a PseudoColor index)
Color table
Set palette loadct, xloadct
Show palette xpalette
Get color values of palette tvlct, r, g, b, /get
Image Input
Functions list: read_bmp, read_jpeg, read_gif, read_tiff
Example True colorIDL>READ_JPEG, 'E:\RSI\IDL54\examples\data\rose.jpg', img24 Color tableIDL>img8 = READ_TIFF('E:\RSI\IDL54\examples\data\examples.tif', r, g, b)IDL>img8 = READ_PNG("E:\RSI\IDL54\examples\data\avhrr.png", r, g, b)IDL>img8 = READ_BMP("c:\winnt\Greenstone.bmp", r,g,b)
Image display
True colorIDL>Device, decomped=1IDL>Tv, img24, true=1
Color tableIDL>Device, decomped=0IDL>tvlct, r, g, bIDL>Tv, img8
Read screen
True colorIDL>Img24=tvrd(true=1)
Color tableIDL>tvlct, r, g, b, /getIDL>img8=tvrd()
Image Output
Functions list: write_bmp, write_jpeg, write_gif, write_tiff
Example True color
IDL>WRITE_TIFF, ‘test.tif', TVRD(true=1)IDL>WRITE_JPEG, ‘test.jpg', TVRD(true=1), true=1
IDL>WRITE_BMP, "test.bmp",img24, /rgb Color table
IDL>WRITE_TIFF, ‘test.tif', TVRD(), red=r, green=g, blue=b IDL>WRITE_BMP, "test.bmp",img8, r, g,
IDL>WRITE_PNG, "test.png",img8, r, g, b
Postscript Device
Set device = psIDL> SET_PLOT, “ps”
Setup device parametersIDL> DEVICE, file=“test.ps”, /color, /landscape
PlotIDL>TVLCT, [0,255,0,0], [0,0,255,0], [0,0,0,255]IDL> PLOT, [0,1], color=1
Close deviceIDL> DEVICE, /close
Printer Device
Set device = printerIDL> set_plot, “printer”
Setup printerIDL>p= DIALOG_PRINTERSETUP()IDL>j=DIALOG_PRINTJOB()
PlotIDL>TVLCT, [0,255,0,0], [0,0,255,0], [0,0,0,255]IDL> PLOT, [0,1], color=1
Close deviceIDL> device, /CLOSE_DOCUMENT