IDL Programming Techniques 读书笔记

作者:北京大学KIAA/天文系 孙宁晨

CHAPTER 1 GETTING STARTED
Chapter Overview
> How this book is organized
> How to use this book
> How to download and organize the files that come with this book
> How to use variables, keywords, and commands in IDL
> How to create and work with vectors and arrays in IDL
> How to work with graphyics windows in IDL
Philosophy Behind this Book
Using this Book
Working with IDL Commands
Creating Variables
> Data Type
————————————————————
Byte: 0B, Byte(var), BytArr, BIndGen
Int: 0, Fix(var), IntArr, IndGen
UInt: 0U, UInt(var), UIntArr, UIndGen
Long: 0L, Long(var), LonArr, LIndGen
ULong: 0UL, ULong(var), ULonArr, ULIndGen
Long64: 0LL, Long64(var), Lon64Arr, L64IndGen
ULong64: 0ULL, ULong64(var), ULon64Arr, UL64IndGen
————————————————————–
Float: 0.0, Float(var), FltArr, FIndGen
Double: 0.0D, Double(var), DblArr, DIndGen
Complex: Complex(0.0,0.0), Complex(var), ComplexArr, CIndGen
DComplex: DComplex(0.0D,0.0D), DComplex(var), DComplexArr, DCIndGen
————————————————————–
String: ” or “”, string(var), StrArr, SIndGen
————————————————————–
Working with Vectors and Arrays
Working with IDL Graphics Windows
> Creating Graphics Windows
Window: create a new window with index number of 0

Window, N: create a new window with index number of N
Window, /Free: create a new window with unused index number

> Positioning and Sizing Graphics Window

Window, N, XSize=XSize, YSize=YSize, XPos=XPos, YPos=YPos

> Putting a Title on the Graphics Window

Window, N, Title=Title

> Determining the Current Graphics Window

WSet, N: set the window with index number of N as the current graphics window

> Bringing a Graphics Window Forward on the Display
WShow: bring the current graphics window forward on the display

WShow, N: bring the graphics window with index number of N forward on the display

> Deleting Graphics Window
WDelete: delete the current graphics window

WDelete, N: delete the graphics window with index number of N

> Erasing a Graphics Window
Erase: erase the current graphics window

Erase, Color=Color: erase the current graphics window with color

CHAPTER 2 SIMPLE GRAPHICAL DISPLAYS
Chapter Overview
> How to display data as a line plot with the Plot command
> How to display data as a surface with the Surface and Shade_Surf commands
> How to display data as a contour plot with the Contour command
> How to position simple graphical displays in the display window
> How to use common keywords to annotate and customize your graphical displays
Simple Graphical Displays in IDL
> Two kinds of graphics systems
Direct graphics
Object graphics
Creating Line Plots
> Plot command

Plot, y, XTitle=XTitle, YTitle=YTitle, Title=Title, [XY]CharSize=[XY]CharSize
Plot, x, y, XTitle=XTitle, YTitle=YTitle, Title=Title, [XY]CharSize=[XY]CharSize

Customizing Graphics Plots
> Modifying linestyles and thicknesses

Plot, x, y, LineStyle=LineStyle, Thick=Thick

> Displaying data with symbols

Plot, x, y, PSym=PSym, SymSize=SymSize ;only symbols
Plot, x, y, PSym=-PSym, SymSize=SymSize ;symbols and lines

————————————————————–
;Creating your own symbol

x=[0.0,0.5,-0.8,0.8,-0.5,0.0]
y=[1.0,-0.8,0.3,0.3,-0.8,1.0]
TvLCT, 255, 255, 0, 150
UserSym, x, y, Color=150, /Fill
Device, Decomposed=0
Plot, x, y, Psym=-8, SymSize=2.0

————————————————————–
> Drawing line plots in color
————————————————————–

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Plot, x, y, Color=2, Background=1, /NoData
OPlot, x, y, Color=3

————————————————————–
> Limiting the range of line plots

Plot, x, y, XRange=XRange, YRange=YRange

> Changing the style of line plots

Plot, x, y, XStyle=XStyle, YStyle=YStyle

————————————————————–
1    Force exact axis range
2    Extend axis range
4    Suppress entire axis
8    Suppress box style axis
16    Inhibit setting the Y axis starting value to 0
————————————————————–

Plot, x, y, XTicks=XTicks, XMinor=XMinor, YTicks=YTicks, YMinor=YMinor ;set number of ticks
Plot, x, y, [XY]TickLen=[XY]TickLen ;set tick length
Plot, x, y, [XY]TickLen=-[XY]TickLen ;set outward facing tick length
Plot, x, y, [XY]TickLen=0.5, XGridStyle=XGridStyle, YGridStyle=YGridStyle ;show grids

Plotting Multiple Data Sets on Line Plots
> OPlot command

OPlot, x, y

> Plot data on multiple axes
————————————————————–

Plot, x, y1, LineStyle=0, YTitle='Solid Line'
Axis, YAxis=1, YRange=YRange, /Save, YTitle='Dashed Line'
OPlot, x, y2, LineStyle=2

————————————————————–
Creating Surface Plots
> Surface command

Surface, z ;array: z
Surface, z, x, y ;regularly spacing vectors: x and y
Surface, z, newx, newy ;irregularly spacing vectors: newx and newy

Customizing Surface Plots
> Rotating surface plots

Surface, z, x, y, Az=Az, Ax=Ax

> Adding color to a surface plot
————————————————————–

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Surface, z, x, y, Color=Color, Background=Background, Bottom=Bottom

————————————————————–

;Make the axes with different color from the surface plots
TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Surface, z, x, y, Color=Color, Background=Background, /NoData ;plot axes and background
Surface, z, x, y, Color=Color, Bottom=Bottom, /NoErase, XStyle=4, YStyle=4, ZStyle=4 ;plot surface and bottom

————————————————————–
;Display the color according to elevation

LoadCT, 5
Device, Decomposed=0
Surface, z, x, y, Shades=BytScl(z,Top=!D.Table_Size-1)

————————————————————–
> Modifying the appearence of the surface plot

Surface, z, x, y, Skirt=Skirt ;display skirt
Surface, z, x, y, /Horizontal ;plot only horizontal lines
Surface, z, x, y, XStyle=4, YStyle=4, ZStyle=4 ;with no axes

Creating Shaded Surface Plots
> Shade_Surf command

Shade_Surf, z ;array: z
Shade_Surf, z, x, y ;regularly spacing vectors: x and y
Shade_Surf, z, newx, newy ;irregularly spacing vectors: newx and newy

> Combining shaded surface and meshed grids

Shade_Surf, z, x, y
Surface, z, x, y, /NoErase

Creating Contour Plots
> Contour command

Contour, z ;array: z
Contour, z, x, y ;regularly spacing vectors: x and y
Contour, z, newx, newy ;irregularly spacing vectors: newx and newy

Selecting Contour Levels
> Determining the number of levels

Contour, z, x, y, NLevels=NLevels
Contour, z, x, y, Levels=Levels

————————————————————–
;Display nlevels equally spacing contour levels

step=(Max(z)-Min(z))/nlevels
levels=FIndGen(nlevels)*step+Min(z)
Contour, z, x, y, Levels=levels

————————————————————–
> Label the levels

Contour, z, x, y, C_Label=C_Label ;label with values, ex. C_Label=[0,1,0,1,0,1]
Contour, z, x, y, C_Annotation=C_Annotation ;label with specified strings

Modifying a Contour Plot
> Changing the appearence of a contour plot

Contour, z, x, y, C_LineStyle=C_LineStyle ;change the line style of contour lines
Contour, z, x, y, C_LineStyle=[0,0,2] ;Make every three contour line dashed
Contour, z, x, y, C_Thick=C_Thick; change the line width of contour lines
Contour, z, x, y, C_Thick=[1,1,2] ;Make every three contour line thickened
Contour, z, x, y, /Downhill ;show the downhill direction

> Adding color to a contour plot
————————————————————–

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Contour, z, x, y, Color=Color, Background=Background

————————————————————–
;Color individual contour lines

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Contour, z, x, y, Color=Color, Background=Background, C_Colors=C_Colors

————————————————————–
;Color every 3 contour lines

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Contour, z, x, y, Color=Color, Background=Background, C_Colors=[2,2,3]

————————————————————–
Creating a Filled Contour Plot
> Fill and Cell_Fill Keyword
————————————————————–
;Fill the contour

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Contour, z, x, y, Color=Color, Background=Background, C_Colors=C_Colors, /Fill

————————————————————–
;Cell_Fill the contour, used when some data points are missing or for open contours

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Contour, z, x, y, Color=Color, Background=Background, C_Colors=C_Colors, /Cell_Fill

————————————————————–
;Overplot the contour lines over the filled contours

TvLCT, [70,255,0],[70,255,255],[70,0,0],1
Device, Decomposed=0
Contour, z, x, y, Color=Color, Background=Background, C_Colors=C_Colors, /Fill
Contour, z, x, y, Color=Color, Background=Background, /NoErase, /Overplot

————————————————————–
Positioning Graphic Output in the Display Window
> Three definitions
Graphic position
Graphic region
Graphic margin
> Setting the graphic margins

Plot, x, y, XMargin=XMargin, YMargin=YMargin ;ex. XMargin=[10,10], YMargin=[5,5], in character size
!X.Margin, !Y.Margin

> Setting the graphic position

Plot, x, y, Position=Position ;ex. Position=[0.1,0.1,0.9,0.9], in normalized units
!P.Position ;set back to default: !P.Position=0

> Setting the graphic region

!P.Region

> Creating multiple graphics plots
————————————————————–

!P.Multi[0]: the number of graphics plots remaining to plot on the display, normally set to 0
!P.Multi[1]: number of columns
!P.Multi[2]: number of rows
!P.Multi[3]: number of plots stacked in the z direction
!P.Multi[4]: filling up the rows first (=0) or the columns first(=1)

————————————————————–
;Leaving room for title

!P.Multi=[0,2,2,0,1]
!Y.OMargin=[2,4] ;in character size
Plot, x1, y1
Plot, x2, y2
Plot, x3, y3
Plot, x4, y4
XYOutS, 0.5, 0.9, /Normal, 'Title'

————————————————————–
;Creating non-symmetrical arrangements

!P.Multi=[0,2,2,0,0]
Plot, x1, y1
Plot, x2, y2
!P.Multi=[1,1,2,0,0]
Plot, x3, y3

————————————————————–
Adding Text to Graphical Displays
> Adding text using the XYOutS command

XYOutS, x, y, string, /Data ;in data coordiantes, default
XYOutS, x, y, string, /Device ;in device coordinates, unit: pixel
XYOutS, x, y, string, /Normal ;in normalized coordinates, from 0 to 1

> Using XYOutS with vector fonts
————————————————————–
!3: Simplex Roman
!4: Simplex Greek ;important
!5: Duplex Roman
!6: Complex Roman
!7: Complex Greek ;important
!8: Complex Italian
!9: Math Font
!10: Special Characters
!11: Gothic English
!12: Simplex Script
!13: Complex Script
!14: Gothic Italian
!15: Gothic German
!16: Cyrillic
!17: Triplex Roman
!18: Triplex Italian
!20: Miscellaneous
!X: Revert to entry font
————————————————————–
> Aligning text

XYOutS, x, y, string, Alignment=Alignment ;Alignment from 0 (left justify) to 1 (right justify)

> Erasing text
————————————————————–
;Erasing text

XYOutS, x, y, string
XYOuts, x, y, string, Color=!P.Background

————————————————————–
> Orienting text

XYOutS, x, y, string, Orientation=Orientation ;Orientation in degrees

> Positioning text
————————————————————–
!A: Shift text above the division line
!B: Shift text below the division line
!C: Insert a carriable return and begin new line of text
!D: Create a first-level subscript ;important
!E: Create a first-level superscript ;important
!I: Create an index-type subscript
!L: Create a second-level subscript
!N: Shift back to normal level after changing level ;important
!R: Restore text position to last saved position
!S: Save the current text position
!U: Creat an index-type superscript
!X: Return to entry font
!!: Display the exclaimation mark ! ;important
————————————————————–
Adding Lines and Symbols to Graphical Displays
> PlotS command

PlotS, x, y, /Data ;in data coordiantes, default
PlotS, x, y, /Device ;in device coordinates, unit: pixel
PlotS, x, y, /Normal ;in normalized coordinates, from 0 to 1

Adding Color to Your Graphical Displays
> PollyFill command

PollyFill, x, y, Color=Color, /Data; in data coordiantes, default
PollyFill, x, y, Color=Color, /Device ;in device coordinates, unit: pixel
PollyFill, x, y, Color=Color, /Normal ;in normalized coordinates, from 0 to 1

CHAPTER 3 WORKING WITH IMAGE DATA
Chapter Overview
> How to read and display image data
> The difference between 8-bit and 24-bit images
> How to scale image data
> How to position an image in the display window
> How to change image sizes
> How to read image from the display device
> How to perform basic image processing tasks
> How to construct simple image filters
Working With Images
> Displaying images

TV, image
TVScl, image

————————————————————–

;TVScl is identical to:
scaledImage=BytScl(image, Top=!D.Table_Size-1)
TV, scaledImage

————————————————————–
> Scaling image data

scaledImage=BytScl(image, Min=Min, Max=Max, Top=Top)

> Displaying 24-bit images
————————————————————–

Device, Decomposed=1
TV, image, True=1

————————————————————–
> Controlling image display order

TV, image, Order=Order ;Order=0 or 1
TVScl, image, Order=Order ;Order=0 or 1
!Order

> Changing image size
————————————————————–

;factor must be an interger
;bilinear interpolation when magnifying, nearest sampling when demagnifying
;or, nearest sampling when /Sample is turned on
new=Rebin(image, x*/factor1, x*/factor2, /Sample)

————————————————————–

;factor may not be an interger
;nearest sampling
;or, bilinear interpolation when /Interp is turned on
new=Congrid(image, x*/factor1, y*/factor2, /Interp)

————————————————————–
> Positioning an image in the display window

TV, image, position ;position=0, 1, 2, 3 ...
TVScl, image, position ;position=0, 1, 2, 3 ...
TV, image, x, y ;x and y in pixels from the lower-left corner
TVScl, image, x, y ;x and y in pixels from the lower-left corner

————————————————————–

;Positioning an image using normalized coordinates
Position=[0.1,0.1,0.9,0.9]
xSize=(Position[2]-Position[0])*!D.X_VSize
ySize=(Position[3]-Position[1])*!D.Y_VSize
xStart=Position[0]*!D.X_VSize
yStart=Position[1]*!D.Y_VSize
TV, Congrid(image, xSize, ySize), xStart, yStart

————————————————————–
> Reading images from the display device
————————————————————–

;Reading and redisplaying 8-bit image
Window, XSize=XSize, YSize=YSize
TV, image
newImage=TVRD() ;newImage is an XSize * YSize array
Window, XSize=XSize, YSize=YSize
TV, newImage

————————————————————–

;Reading and redisplaying 24-bit image
Window, XSize=XSize, YSize=YSize
TV, image
newImage=TVRD(True=1)
Window, XSize=XSize, YSize=YSize
Device, Decomposed=1
TV, newImage, True=1

————————————————————–

;Reading a portion of the display
newImage=TVRD(xStart, yStart, xEnd, yEnd[, True=1])

————————————————————–
Basic Image Processing in IDL
> Histogram equalization
————————————————————–

;Histogram equalization and display the result
equalized=Hist_Equal(image)
Window, XSize=x*2, YSize=y
TV, equalized
Plot, Histogram(equalized), /NoErase, XStyle=1, Position=[0.6,0.05, 0.95, 0.95]

————————————————————–
> Smoothing images

Smoothed=Smooth(image, boxSize[, /Edge_Truncate])
Smoothed=Convol(image, kernel, Total(kernel)[, /Edge_Truncate]) ;using like Gaussian kernel

> Enhancing the edges of images

Enhanced=Sobel(image)
Enhanced=Roberts(image)
Enhanced=Convol(image, kernel) ;using like Laplacian kernel

Frequency Domain Filtering of Images
> FFT images

image_k=FFT(image, -1) ;from spatial domain to frequency domain
image=FFT(image_k, 1) ;from frequency domain to spatial domain

> Frequency domain filtering

newImage=FFT(FFT(image, -1)*filter,1)

CHAPTER 04 GRAPHICAL DISPLAY TECHNIQUES
Chapter Overview
> How IDL works with colors
> How to ask for color in a device independent way
> How to create and save color tables in IDL
> How to modify axis annotation to your specifications
> How to set up a 3D coordinates system in IDL direct graphics
> How to combine graphical displays
> How to work with bad or missing data in IDL
> How to animate graphicl displays
> How to grid XYZ data for graphical display
> How to provide cursor interaction with your graphical display
> How to erase annotation from your graphical display
> How to draw a “rubberhand” box on your graphical display
> How to use the Z graphics buffer for graphical display tricks
Working with Colors in IDL
> Using the indexed versus the RGB color model
Indexed color model, on 8-bit displays, for most part is dynamic color display
RGB color model, on 24-bit displays, for most part is static color display

Device, Get_Visual_Name=thisName, Get_Visual_Depth=thisDepth
Device, Get_Decomposed=usingDecomposed

————————————————————–
;Specifying decomposed colors on 24-bit displays

Device, Decomposed=1
Plot, x, y, Color=70L+70L*256L+70L*256L*256L

————————————————————–

;Specifying undecomposed colors on 24-bit displays
Device, Decomposed=0
TVLCT, 70, 70, 70, 0
Plot, x, y, Color=0

————————————————————–

;Display a 24-bit image on PC or Mac
Device, Decomposed=1
TV, image, True=1

————————————————————–
> Loading color tables on a 24-bit display
> Obtaining a copy of the color table

TVLCT, red, green, blue, /Get

> Modifying and creating color tables

XLoadCT
XPalette

> Saving your own color tables
————————————————————–

TVLCT, red, green, blue, /Get
Save, red, green, blue, filename='ColorTable.sav'

————————————————————–
Creating Your Own Axis Annotations
> Adjusting axis tick intervals

Plot, x, y, XTicks=XTicks, YTicks=YTicks, XMinor=XMinor, YMinor=YMinor

> Formatting axis annotations

Plot, x, y, XTickFormat=XTickFormat, YTickFormat=YTickFormat
Plot, x, y, XTickFormat='(A1)', YTickFormat='(A1)' ;Suppress axis annotation
Plot, x, y, XTickName=XTickName, YTickName=YTickName

Handling Missing Data in IDL
> the NaN value
————————————————————–

;Assign NaN to bad data
badX=x
badY=y
badX[badXIndex]=!Values.F_NaN
badY[badYIndex]=!Values.F_NaN
Plot, badX, badY

————————————————————–
> Min_Value and Max_Value keyword

Plot, badX, badY, Min_Value=Min_Value, Max_Value=Max_Value

Setting Up a 3D Coordinate System in IDL
> Loading a transformation matrix

Surface, z, /Save, /NoData, Ax=Ax, Az=Az, XRange=XRange, YRange=YRange, ZRange=ZRange
Scale3, Ax=Ax, Az=Az, XRange=XRange, YRange=YRange, ZRange=ZRange

> Setting up a 3D scatter plot
————————————————————–
;setting up a 3D scatter plot

Surface, Dist(10), /Save, /NoData, Ax=Ax, Az=Az, XRange=XRange, YRange=YRange, ZRange=ZRange
Axis, 0, 1, 0, XAxis=1, XRange=XRange, /T3D
Axis, 1, 0, 0, YAxis=1, YRange=YRange, /T3D
PlotS, x, y, z, PSym=PSym, /T3D
For j=0, N-1 DO PlotS, [x[j],x[j]], [y[j],y[j]], [z[j],0], /T3D

————————————————————–
Combining Simple Graphical Displays
> Combining shaded surface plot with contour
————————————————————–

Contour, z, x, y, /T3D, XStyle=1, YStyle=1, ZValue=1, /NoClip, /NoErase

————————————————————–
Gridding Data in IDL
> Gridding data for graphical display
> Delaunay triangulation method of gridding

Triangulate, x, y, angles[, hull]
gridZ=TriGrid(x, y, z, angles, mapSpacing, mapBounds, Missing=Missing, XGrid=gridX, YGrid=gridY) ;optional keywords: /smooth, /quintic, extrapolate=hull
Contour, gridZ, gridX, gridY

> Spherical gridding of data
Using the Cursor with Graphical Displays
> Cursor command

Cursor, xLocation, yLocation, /Data
Cursor, xLocation, yLocation, /Device
Cursor, xLocation, yLocation, /Normal

> When is the cursor position returned?
————————————————————–

/Wait ;default
/NoWait
/Down
/Up
/Change

————————————————————–
> Which mouse button was used with the cursor?

!Mouse.Button ;0 no button, 1 left button, 2 middle button, 4 right button

> Annotating graphics output with the cursor
————————————————————–
;Draw a box with cursor

Plot, x, y
Cursor, x1, y1, /Down
Cursor, x2, y2, /Down
PlotS, [x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1]

————————————————————–

;Zoom in with cursor
Plot, x, y
Cursor, x1, y1, /Down
Cursor, x2, y2, /Down
xMin=Min([x1,x2])
xMax=Max([x1,x2])
yMin=Min([y1,y2])
yMax=Max([y1,y2])
Plot, x, y, XRange=[xMin,xMax], YRange=[yMin,yMax], XStyle=1, YStyle=1

————————————————————–
> Using the cursor with images
————————————————————–

;Display column and row profile with cursor
Window, XSize=XSize, YSize=YSize
TV, image
Cursor, col, row, /Device
!P.Multi=[0,2,1,0,0]
Plot, image[col, *]
Plot, image[*, row]

————————————————————–
> Using the cursor in loops
Erasing Annotation From the Display
Graphics Display Tricks in the Z-Graphics Buffer

CHAPTER 7 CREATING HARDCOPY GRAPHICS OUTPUT
Chapter Overview
> How to select a hardcopy output device
> How to configure a hardcopy output device
> How to send graphical output directly to printer
> How to send graphical output to a file
> How to create graphical output for the hardcopy output device
> How PostScript output differs from the output on your display
> How to position plots and images on the PostScript page
> How to produce graphical output that can be included in other documents
> How to write graphical programs that are easily converted to hardcopy output
> How to use color in PostScript output
Selecting the Graphics Hardcopy Output Device
> Set_Plot command

Set_Plot, option

————————————————————–
‘PS’: written to a file in PostScript format
‘WIN’: a personal computer running Microsoft Windows system
‘MAC’: a computer running MacOS system
‘X’: a computer running X Window windowing system
————————————————————–

;Using !D.Name ;always stored in uppercase characters
thisDevice=!D.Name
Set_Plot, 'PS'
...
set_Plot, thisDevice

————————————————————–
Configuring the Graphics Hardcopy Output Device
> Determining the current device configuration

Help, /Device

> Common Device command keywords
————————————————————–
Filename
/Landscape
/Portrait
XSize
YSize
XOffset
YOffset
/Inches
/Close_File
————————————————————–
> Creating the PostScipt file
————————————————————–

;Creating the PostScript file
thisDevice=!D.Name
Set_Plot, 'PS'
Device, Filename='output.ps', XSize=XSize, YSize=YSize, XOffset=XOffset, YOffset=YOffset, /Inches
Plot, x, y
Device, /Close_File
Set_Plot, thisDevice

————————————————————–
Sending Graphics to the Hardcopy Device
————————————————————–

Set_Plot, 'PS' ;select output hardcopy device
Device, ... ;configure output hardcopy device
Plot, x, y ;plot
Device, /Close_File ;close output hardcopy device

————————————————————–
Printing PostScript Files
Producing Encapsulated PostScript Output
> Encapsulated keyword

Device, /Encapsulated
Device, Encapsulated=0

Producing Color PostScript Output
> Color keyword

Device, /Color
Device, Color=0

> Color and gray scale images in PostScript

Device, Bits_Per_Pixel=Bits_Per_Pixel

————————————————————–

;Display 24-bit image in PostScipt
thisDevice=!D.Name
Set_Plot, 'PS'
Device, Filename=Filename, /Color, /Encapsulated, Bits_Per_Pixel=8, Decomposed=1
TV, image, True=1
Device, /Close_File
Set_Plot, thisDevice

————————————————————–
Creating Quality Output on PostScript Devices
> Similarities between the display and PostScript devices
> differences between the display and PostScript devices
————————————————————–
;Problem: PostScript windows may have a different aspect ratio
;Solution: make the aspect ratios of graphics windows the same size
————————————————————–
;Problem: PostScript devices have a higher display resolution
;Solution: don’t use device coordinates to position graphics
————————————————————–
;Problem: PostScript devices can use different display fonts
;Solution: Take care in designing and positioning text
————————————————————–
;Problem: PostScript devices use background and plotting colors differently
;Solution: understand how PostScript handles background and plotting colors
————————————————————–
;Problem: PostScript devices often have more colors than the display device
;Solution: Be sure to scale your data appropriately in PostScript
————————————————————–
;Problem: PostScript devices display images differently
;Solution: Size images with the TV command
————————————————————–
Calculating PostScipt Offsets in Landscape Mode
Configuring the PostScript Device with PSConfig
Configuring and Using the Printer Device

CHAPTER 8 IDL PROGRAMMING FUNDAMENTALS
Chapter Overview
> How to pass information into and out of IDL programs
> How to use positional and keyword parameters in IDL programs
> How to compile and run IDL programs
> The syntax of many common programming control statements
Writing and IDL Batch File
> Format
————————————————————–

;Format of IDL batch file
...

————————————————————–
> Execute batch file

@filename

Writing a Main-Level IDL Program
> Format
————————————————————–

;Format of main-level IDL program
...
END

————————————————————–
> Execute main-level IDL program

.Run filename

————————————————————–
;Execute main-level IDL program

.Compile filename
.Go

————————————————————–
Writing an IDL Procedure
> Format
————————————————————–

;Format of IDL procedure
PRO filename
...
END

————————————————————–
> Execute procedure

filename

————————————————————–

;Execute procedure
.Compile filename
filename

————————————————————–
> Scope of procedure and function variables
Only commands inside the procedure or function can access variables created inside the procedure or function
> Creating a positional parameter
————————————————————–

;Creating a positional parameter
PRO filename, param1, param2, ..., paramN
...
END

————————————————————–
> Defining a optional or required positional parameter
Convention: positional parameters used for required parameters and keywords used for optional parameters
————————————————————–

;Defining a required positional parameter
PRO filename, param
IF N_Params() NE 1 THEN message, 'Error!'
END

————————————————————–

;Defining a optional positional parameter
PRO filename, param
IF N_Params() NE 1 THEN param=defaultValue
END

————————————————————–
> Defining a keyword parameter
————————————————————–

;Defining a keyword parameter
PRO filename, param1, param2, ..., paramN, keyword1=keyword1, keyword2=keyword2, ..., keywordM=keywordM
...
END

————————————————————–

;Using keyword abbreviations
PRO filename, param, keyword=keyword
...
END
filename, param, key=3

————————————————————–

;Defining optional keyword
PRO filename, param, keyword=keyword
IF N_Elements(keyword) EQ 0 THEN keyword=defaultValue
END

————————————————————–

;Handling keywords with binary properties. Keyword_set: return true if set and nozero; return false if unset or zero
PRO filename, param, keyword=keyword
IF Keyword_Set(keyword) THEN BEGIN
...
ENDIF ELSE BEGIN
...
ENDELSE
END

————————————————————–

;Passing undefined keywords by keyword inheritance
PRO filename, param, keyword=keyword, _extra=extra
...
Plot, x, y, _extra=extra ;any inherited keyword not appropriate for this command is quietly ignored
...
TV, image, _extra=extra ;any inherited keyword not appropriate for this command is quietly ignored
...
END

————————————————————–
> Creating output parameters
————————————————————–

;Passing by reference
variables

————————————————————–
;Passing by value
constants
subscripted variables
system variables
expressions
structure de-references
————————————————————–
Writing an IDL Function
> Format
————————————————————–

;Format of function
FUNCTION filename, param1=param1, param2=param2, ..., paramN=paramN, keyword1=keyword1, keyword2=keyword2, ..., keywordM=keywordM
...
return, returnValue
END

————————————————————–
> Execute function
————————————————————–

;Execute function
.compile filename
var=filename(param1, param2, ..., paramN, keyword1=keyword1, keyword2=keyword2, ..., keywordM=keywordM)

————————————————————–
Using Program Control Statements
> True expressions in IDL
————————————————————–
odd values for byte, integer, long
non-zero values for float, double, complex and double complex
non-null string
————————————————————–
> The IF…THEN…ELSE control statement
————————————————————–

IF ... THEN BEGIN
...
ENDIF ELSE BEGIN
...
ENDELSE

————————————————————–
> The conditional expression
(…)?value1:value2
> The FOR loop control statement
————————————————————–

FOR j=1, N DO BEGIN
...
ENDFOR

————————————————————–
> The WHILE loop control statement
————————————————————–

WHILE ... DO BEGIN
...
ENDWHILE

————————————————————–
> The REPEAT…UNTIL loop control statement
————————————————————–

REPEAT BEGIN
...
ENDREP UNTIL ...

————————————————————–
> The BREAK control statement
> The CONTINUE control statement
> The CASE control statement
————————————————————–

;only execute one statement which matches the condition
CASE .. OF
value1: ...
value2: ...
...
valueN: ...
ELSE: ...
ENDCASE

————————————————————–
> The SWITCH control statement
————————————————————–

;also execute the following statements from the statement which matches the condition
SWITCH .. OF
value1: ...
value2: ...
...
valueN: ...
ELSE: ...
ENDCASE

————————————————————–
> The GOTO control statement
> Error handling control statements
Compiling and Running IDL Program Modules
> Resolve_Routine command
Resolve_Routine, filename

    分享到:

One Reply to “IDL Programming Techniques 读书笔记”

  1. Mengyao Xue

    Firefox 10.0.11 Windows XP

    膜拜下…
    看了好一阵才意识到,“啊,这本书的中文电子版不就是我经常在看/写程序的时候打开ctrl+F的那本么”
    看了这篇文章才知道那本书的原作书名… 翻译书的人完全没有在中文版提过英文原作叫什么…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.