- 积分
- 5997
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2017-3-7
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
刚开始学习这门语言,运行一个实例代码有一个错误,Variable is undefined: PRECIPMONTHS.我懵逼了,这个变量是赋值变量,怎么还没有定义呢?难道也要像fortran一样,定义变量。求大神帮忙。数据在http://www.idlcoyote.com/gallery/small_multiple_contour_plot.zip。
- ; docformat = 'rst'
- ;+
- ; This is an example program to demonstrate how to create a small multiple contour plot
- ; to compared contour plots of different dates with Coyote Graphics routines.
- ;
- ; :Categories:
- ; Graphics
- ;
- ; :Examples:
- ; Save the program as "small_multiple_contour_plot.pro" and run it like this::
- ; IDL> .RUN small_multiple_contour_plot
- ;
- ; :Author:
- ; FANNING SOFTWARE CONSULTING::
- ; David W. Fanning
- ; 1645 Sheely Drive
- ; Fort Collins, CO 80526 USA
- ; Phone: 970-221-0438
- ; E-mail: david@idlcoyote.com
- ; Coyote's Guide to IDL Programming: http://www.idlcoyote.com
- ;
- ; :History:
- ; Change History::
- ; Written, 12 February 2013 by David W. Fanning.
- ;
- ; :Copyright:
- ; Copyright (c) 2013, Fanning Software Consulting, Inc.
- ;-
- PRO Small_Multiple_Contour_Plot
- ; Set up variables for the plot. Normally, these values would be
- ; passed into the program as positional and keyword parameters.
- ; Data file is the NCEP Reanalysis Monthly Mean Precipitation
- ; data set, available here: ftp://ftp.cdc.noaa.gov/Datasets/cmap/std/precip.mon.mean.nc.
- datafile = 'precip.mon.mean.nc'
- ; To browse data file.
- ; nCDF_Browser, datafile
- ; Open the file and read the data. Variable names are case sensitive.
- file = Obj_New('ncdf_file', datafile)
- lats = file -> GetVarData('lat')
- lons = file -> GetVarData('lon')
- time = file -> GetVarData('time') ; Hours since 1-1-1 00:00:0.0
- rain = file -> GetVarData('precip', MissingIndices=missing)
-
- Obj_Destroy, file
- ; Make sure all missing values are set to 0. Find the contour levels.
- rain[missing] = 0.0
- divisions = 12
- levels = Indgen(12)
- ; Convert the time vector to a date string.
- timeOffset = Julday(1, 1, 0001, 0, 0, 0)
- julianDayTime = timeOffset + time / 24.0
- timeString = cgJulian2Date(julianDayTime, Format=20) ; yyyymmdd
- ; Find all months of July for the years 2000 through 2011.
- year = Fix(StrMid(timeString, 0, 4))
- month = Fix(StrMid(timeString, 4, 2))
- indices = Where( (year GE 2000) AND (year LE 2011) AND (month EQ 7), count)
- IF count GT 0 THEN BEGIN
- precipMonths = rain[*,*,indices]
- year = year[indices]
- ENDIF
- ; Open a display window.
- cgDisplay, 1200, 900
- ; Get contour positions.
- pos = cgLayout([4, 3], OXMargin=[3, 3], OYMargin=[6, 14], XGap=5, YGap=8)
- ; Load contour colors.
- ncolors = N_Elements(levels)
- cgLoadCT, 28, /Brewer, /Reverse, NColors=ncolors, Bottom=1, Clip=[10, 210]
- TVLCT, cgColor('white', /Triple), 0
- TVLCT, cgColor('charcoal', /Triple), ncolors
- ; Draw small multiple contour plots for these 12 years.
- FOR j=0,11 DO BEGIN
- cgMap_Set, /Cylindrical, 0, 180, LIMIT=[Min(lats), Min(lons), Max(lats), Max(lons)], $
- Position=pos[*,j], /NoErase
- charsize = (!D.Name EQ 'PS') ? cgDefCharsize()*0.5 : cgDefCharsize()*0.75
- cgMap_Grid, /Box_Axes, Charsize=charsize
- cgMap_Grid, Color='charcoal', GLinestyle=1
- cgContour, precipMonths[*,*,j], lons, lats, /Overplot, /Cell_Fill, $
- Levels=levels, C_Colors=Bindgen(ncolors), NoErase=(j NE 0), $
- Position=pos[*,j]
- cgMap_Grid, Color='charcoal', GLinestyle=1
- cgMap_Continents, Color='gray'
- fudge = (!D.Name EQ 'PS') ? 0.03 : 0.025
- cgText, pos[0,j], pos[3,j]+fudge, /Normal, StrTrim(year[j],2)
- ENDFOR
- cgColorbar, NColors=ncolors-1, Bottom=1, OOB_Low=0B, OOB_High=Fix(ncolors), $
- Title='Precipitation (mm) for July', TLocation='Top', $
- Divisions=ncolors, /Discrete, Range=[Min(levels), Max(levels)], $
- Position=[0.25, 0.915, 0.75, 0.930], TCharsize=cgDefCharsize()*1.5
- END ;*****************************************************************
- ; This main program shows how to call the program and produce
- ; various types of output.
- ; Display the plot in a graphics window.
- Small_Multiple_Contour_Plot
- ; Create a PostScript file.
- cgPS_Open, 'small_multiple_contour_plot.ps'
- Small_Multiple_Contour_Plot
- cgPS_Close
- ; Create a PNG file with a width of 600 pixels.
- cgPS2Raster, 'small_multiple_contour_plot.ps', /PNG, Width=600
- END
复制代码
|
|