请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 3890|回复: 0

[求助] IDL代码求教!谢谢大神们!

[复制链接]

新浪微博达人勋

发表于 2019-12-13 18:15:52 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
刚开始学习这门语言,运行一个实例代码有一个错误,Variable is undefined: PRECIPMONTHS.我懵逼了,这个变量是赋值变量,怎么还没有定义呢?难道也要像fortran一样,定义变量。求大神帮忙。数据在http://www.idlcoyote.com/gallery/small_multiple_contour_plot.zip
  1. ; docformat = 'rst'
  2. ;+
  3. ; This is an example program to demonstrate how to create a small multiple contour plot
  4. ; to compared contour plots of different dates with Coyote Graphics routines.
  5. ;
  6. ; :Categories:
  7. ;    Graphics
  8. ;
  9. ; :Examples:
  10. ;    Save the program as "small_multiple_contour_plot.pro" and run it like this::
  11. ;       IDL> .RUN small_multiple_contour_plot
  12. ;
  13. ; :Author:
  14. ;    FANNING SOFTWARE CONSULTING::
  15. ;       David W. Fanning
  16. ;       1645 Sheely Drive
  17. ;       Fort Collins, CO 80526 USA
  18. ;       Phone: 970-221-0438
  19. ;       E-mail: david@idlcoyote.com
  20. ;       Coyote's Guide to IDL Programming: http://www.idlcoyote.com
  21. ;
  22. ; :History:
  23. ;     Change History::
  24. ;        Written, 12 February 2013 by David W. Fanning.
  25. ;
  26. ; :Copyright:
  27. ;     Copyright (c) 2013, Fanning Software Consulting, Inc.
  28. ;-
  29. PRO Small_Multiple_Contour_Plot

  30.   ; Set up variables for the plot. Normally, these values would be
  31.   ; passed into the program as positional and keyword parameters.
  32.   ; Data file is the NCEP Reanalysis Monthly Mean Precipitation
  33.   ; data set, available here: ftp://ftp.cdc.noaa.gov/Datasets/cmap/std/precip.mon.mean.nc.
  34.   datafile = 'precip.mon.mean.nc'

  35.   ; To browse data file.
  36.   ; nCDF_Browser, datafile

  37.   ; Open the file and read the data. Variable names are case sensitive.
  38.   file = Obj_New('ncdf_file', datafile)
  39.   lats = file -> GetVarData('lat')
  40.   lons = file -> GetVarData('lon')
  41.   time = file -> GetVarData('time') ; Hours since 1-1-1 00:00:0.0
  42.   rain = file -> GetVarData('precip', MissingIndices=missing)
  43.   
  44.   Obj_Destroy, file

  45.   ; Make sure all missing values are set to 0. Find the contour levels.
  46.   rain[missing] = 0.0
  47.   divisions = 12
  48.   levels = Indgen(12)

  49.   ; Convert the time vector to a date string.
  50.   timeOffset = Julday(1, 1, 0001, 0, 0, 0)
  51.   julianDayTime = timeOffset + time / 24.0
  52.   timeString = cgJulian2Date(julianDayTime, Format=20) ; yyyymmdd

  53.   ; Find all months of July for the years 2000 through 2011.
  54.   year = Fix(StrMid(timeString, 0, 4))
  55.   month = Fix(StrMid(timeString, 4, 2))
  56.   indices  = Where( (year GE 2000) AND (year LE 2011) AND (month EQ 7), count)
  57.   IF count GT 0 THEN BEGIN
  58.     precipMonths = rain[*,*,indices]
  59.     year = year[indices]
  60.   ENDIF

  61.   ; Open a display window.
  62.   cgDisplay, 1200, 900

  63.   ; Get contour positions.
  64.   pos = cgLayout([4, 3], OXMargin=[3, 3], OYMargin=[6, 14], XGap=5, YGap=8)

  65.   ; Load contour colors.
  66.   ncolors = N_Elements(levels)
  67.   cgLoadCT, 28, /Brewer, /Reverse, NColors=ncolors, Bottom=1, Clip=[10, 210]
  68.   TVLCT, cgColor('white', /Triple), 0
  69.   TVLCT, cgColor('charcoal', /Triple), ncolors

  70.   ; Draw small multiple contour plots for these 12 years.
  71.   FOR j=0,11 DO BEGIN
  72.     cgMap_Set, /Cylindrical, 0, 180, LIMIT=[Min(lats), Min(lons), Max(lats), Max(lons)], $
  73.       Position=pos[*,j], /NoErase
  74.     charsize = (!D.Name EQ 'PS') ? cgDefCharsize()*0.5 : cgDefCharsize()*0.75
  75.     cgMap_Grid, /Box_Axes, Charsize=charsize
  76.     cgMap_Grid, Color='charcoal', GLinestyle=1
  77.     cgContour, precipMonths[*,*,j], lons, lats, /Overplot, /Cell_Fill, $
  78.       Levels=levels, C_Colors=Bindgen(ncolors), NoErase=(j NE 0), $
  79.       Position=pos[*,j]
  80.     cgMap_Grid, Color='charcoal', GLinestyle=1
  81.     cgMap_Continents, Color='gray'
  82.     fudge = (!D.Name EQ 'PS') ? 0.03 : 0.025
  83.     cgText, pos[0,j], pos[3,j]+fudge, /Normal, StrTrim(year[j],2)
  84.   ENDFOR

  85.   cgColorbar, NColors=ncolors-1, Bottom=1, OOB_Low=0B, OOB_High=Fix(ncolors), $
  86.     Title='Precipitation (mm) for July', TLocation='Top', $
  87.     Divisions=ncolors, /Discrete, Range=[Min(levels), Max(levels)], $
  88.     Position=[0.25, 0.915, 0.75, 0.930], TCharsize=cgDefCharsize()*1.5
  89. END ;*****************************************************************

  90. ; This main program shows how to call the program and produce
  91. ; various types of output.

  92. ; Display the plot in a graphics window.
  93. Small_Multiple_Contour_Plot

  94. ; Create a PostScript file.
  95. cgPS_Open, 'small_multiple_contour_plot.ps'
  96. Small_Multiple_Contour_Plot
  97. cgPS_Close

  98. ; Create a PNG file with a width of 600 pixels.
  99. cgPS2Raster, 'small_multiple_contour_plot.ps', /PNG, Width=600

  100. END
复制代码


密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表