home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / idlpvwa / 631 < prev    next >
Encoding:
Text File  |  1993-01-23  |  4.2 KB  |  108 lines

  1. Newsgroups: comp.lang.idl-pvwave
  2. Path: sparky!uunet!usc!sdd.hp.com!saimiri.primate.wisc.edu!aplcen.apl.jhu.edu!warper.jhuapl.edu!sterner
  3. From: sterner@warper.jhuapl.edu (Ray Sterner)
  4. Subject: Re: PV-WAVE Filled Contours
  5. Message-ID: <sterner.727743609@warper.jhuapl.edu>
  6. Sender: news@aplcen.apl.jhu.edu (USENET News System)
  7. Organization: Johns Hopkins University
  8. References: <C185K8.7KC@csn.org>
  9. Date: 22 Jan 93 23:00:09 GMT
  10. Lines: 96
  11.  
  12. mayer@teal.csn.org (Mike Mayer) writes:
  13.  
  14. >Hello,
  15.  
  16. >Does anyone have a procedure written in PV-WAVE that will allow
  17. >one to create filled contours correctly? 
  18.  
  19. >Have seen a few here in comp.lang.idl-pvwave, but were either written
  20. >for IDL (WAVE didn't have the routines it was calling) and one to 
  21. >replace POLYCONTOUR (looked the same when plotted).  
  22.  
  23. >Trying to get around having to write out a polygon/path file or 
  24. >otherwise fiddle with the original array.  In an ideal world, we'd
  25. >have something like CONTOUR, array, /Fill   ...and bingo there it is.
  26.  
  27. >Thanks.
  28.  
  29. >Mike
  30.  
  31. >-- 
  32. >___---^^^---___---^^^---___---^^^---___---^^^--- Catch The WAVE ---___      
  33. >Michael Mayer, Senior Technical Support Engineer, Visual Numerics, Inc. (was   
  34. >Precision Visuals, Inc.) 32915 Aurora Rd. Suite # 160, Solon, OH, 44139  USA
  35. >Email: mayer@pvi.com   Human: 216/248-4900   Fax: 216-248-2733
  36.  
  37.   Here is a short function that does filled contours (one screen long
  38.   after dropping the help text and blank lines).  It won't do all the
  39.   fancy stuff, but if you just want simple filled contours it might
  40.   work.  It uses only the standard routines that come with IDL (and
  41.   probably PV-WAVE).  To display the help text do something like:
  42.     x=fill_cont(/help)
  43.  
  44.   If z is a 2-d array try something like:
  45.     tv,fill_cont(z),0
  46.     tvscl,z,1
  47.   The first should have 8 colors, the second should be continuous.
  48.   tv,fill_cont(z,n_levels=16) will give 16 colors and so on.
  49.   You may also specify the actual levels to contour and the colors
  50.   to use.  It has not been tested on many cases sinces its only a few
  51.   minutes old.
  52.  
  53.   Ray Sterner                     sterner%str.decnet@warper.jhuapl.edu 
  54.   Johns Hopkins University        North latitude 39.16 degrees.
  55.   Applied Physics Laboratory      West longitude 76.90 degrees.
  56.   Laurel, MD 20723-6099
  57.  
  58. ;---------  fill_cont.pro  = fill contours with colors  -----------
  59. ;    R. Sterner, 22 Jan, 1993
  60.  
  61.     function fill_cont, z, levels=lv, colors=clr, n_levels=n_lv, help=hlp
  62.  
  63.     if (n_params(0) lt 1) or keyword_set(hlp) then begin
  64.       print,' Returns a byte array with filled contours.'
  65.       print,' fill_cont, z'
  66.       print,'   z = 2-d array to contour.    in'
  67.       print,' Keywords:'
  68.       print,'   LEVELS=lv  Array of contour levels.  Default'
  69.       print,'     is 8 contours from array min to max.  First value'
  70.       print,'     in LEVELS should be the minimum of the first contour'
  71.       print,'     range, and the last should be the maximum of the'
  72.       print,'     last contour range.  For example, for 3 contour'
  73.       print,'     ranges from 23 to 130 LEVEL should be:'
  74.       print,'     23.0000      58.6667      94.3333      130.00'
  75.       print,'   N_LEVELS=n Number of evenly spaced levels to contour'
  76.       print,'     from array min to max.  Only if LEVELS not given.' 
  77.       print,'   COLORS=clr Array of contour colors.  Default'
  78.       print,'     is enough colors to handle LEVELS'
  79.       print,'     spaced from 0 to !d.ncolors-1.  Number of colors'
  80.       print,'     is 1 less than the number in LEVELS.'
  81.       return, -1
  82.     endif
  83.  
  84.     ;--------  Set defaults  ---------
  85.     mn = min(z,max=mx)            ; Find data min and max.
  86.     d = mx-mn                ; Data range.
  87.     if n_elements(n_lv) eq 0 then n_lv=8    ; Default number of levels.
  88.     n_lv = n_lv>1                ; Must be at least 1.
  89.     ;---  If LEVELS array not given make it.  -----
  90.     if n_elements(lv) eq 0 then lv = findgen(n_lv+1)*d/n_lv+mn
  91.     nlv = n_elements(lv)            ; How many levels?
  92.     ;---  If COLORS array not given make it.  -----
  93.     if n_elements(clr) eq 0 then $
  94.       clr = (findgen(nlv)*(!d.n_colors-1)/(nlv-1))(1:*)
  95.     lstc = n_elements(clr)-1        ; Last color index.
  96.  
  97.     ;-------  Set up output array  ----------
  98.     out = byte(z*0)
  99.  
  100.     ;---  Loop through levels filling contours.  -------
  101.     for i = 0, nlv-2 do begin
  102.       w = where((z ge lv(i)) and (z le lv(i+1)), cnt)
  103.       if cnt gt 0 then out(w) = clr(i<lstc)
  104.     endfor
  105.  
  106.     return, out
  107.     end
  108.