nice_contourlevels.pro 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function nice_contourlevels, data, nlevels=nlevels
  2. ;+----------------------------------------------------------------------------------------
  3. ; nice_contourlevels.pro
  4. ;
  5. ; Select nice contour levels based on the data input and the number of levels
  6. ;
  7. ; Author: D. J. Lea - Feb 2008
  8. ;
  9. ;+----------------------------------------------------------------------------------------
  10. if (n_elements(nlevels) eq 0) then nlevels=15
  11. mx=max(data)
  12. mn=min(data)
  13. ; use this to select colors to plot and labels
  14. clevels=findgen(nlevels)/nlevels*(mx-mn)+mn
  15. ocint=1./nlevels*(mx-mn)
  16. print,'ocint ',ocint
  17. ; contour interval at 2 sig figs
  18. ;digits=2
  19. ;p10 = floor(alog10(abs(ocint)))
  20. ;expo = 10.0d^(digits -1 - p10)
  21. ;cint = long(ocint*expo)/expo
  22. ;print,'cint ',cint
  23. ;does it end in 5 or 0?
  24. digits=1
  25. p10 = floor(alog10(abs(ocint)))
  26. expo = 10.0d^(digits -1 - p10)
  27. cint = long(ocint*expo)/expo
  28. print,'cint ',cint
  29. if (mx ne mn) then begin
  30. mxfix=fix(mx/cint)*cint
  31. mnfix=fix(mn/cint)*cint
  32. print, mx, mxfix
  33. print, mn, mnfix
  34. ; nice contour values
  35. ;calculate new nlevels
  36. nlevels=fix((mxfix-mnfix)/cint+1)
  37. ;print,nlevels
  38. if (nlevels gt 0) then begin
  39. clevels=findgen(nlevels)*cint+mnfix
  40. endif else begin
  41. clevels=mnfix
  42. endelse
  43. endif else begin
  44. clevels=mn
  45. endelse
  46. return, clevels
  47. end