plotting bar charts

From: Qiaozhen Mu (qiaozhen AT XXXXXX)
Date: Fri Oct 11 2002 - 08:39:15 MDT


Hi all,

I am trying to use NCL to plot bar charts. Can someone tell me what's wrong with
my script to plot the bar charts? When I use it, the erron information is as
following,

*******************************************
fatal:Subscript out of range, error in subscript #1
fatal:Execute: Error occurred at or near line 7244 in file
$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl

fatal:Execute: Error occurred at or near line 120
*******************************************

I have checked it many times, I can't find what's wrong. When I use the similiar
script to plot the dotted figures, there is no problem. Please help me with
this. Thanks.

Qiaozhen
***************************************
*The University of Texas at Austin *
*Institute for Geophysics *
*4412 Spicewood Springs Rd., Bldg. 600*
*Austin, Texas 78759-8500 *
*phone:(512) 471-0462 *
*fax :(512) 471-0348 *
***************************************

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;************************************************
begin
;************************************************
; read in netCDF file
;************************************************
fields=(/"CLDTOT","FLNT","FSDS","FSNT", \
         "LHFLX", "PRECT","PSL","SHFLX",\
         "TREFHT" /)
clim=(/"DJF","MAM","JJA","SON","ANN"/)
inptr = (/\
          "alfa3_hsnoc15_","alfa3_ricr5_", \
          "alfa3_tau216_", "hsnoc15_tau216_", \
          "rhmin86_alfa3_","rhmin86_hsnoc15_", \
          "rhmin86_ricr5_","rhmin86_tau216_", \
          "ricr5_hsnoc15_","ricr5_tau216_" /)
inptr1 = (/\
          "alfa3_","hsnoc15_", \
          "ricr5_","ccm86_", \
          "tau216_" /)
nfields = dimsizes(fields)
parameter = (/"alfa","hsnoc","ricr","rhmin","tau"/)
ninptr = dimsizes(inptr)
ninptr1 = dimsizes(inptr1)
nclim = dimsizes(clim)
nparameter = dimsizes(parameter)
;************************************************
do infields =0, nfields-1
;************************************************
do j = 0, nclim-1
;************************************************
;************************************************
  error = new((/ninptr/), "float")
  error!0 ="experiment"
  error&experiment= ispan(1,ninptr,1)
;************************************************
  error1 = new((/ninptr1/), "float")
  error1!0 ="experiment"
  error1&experiment= ispan(1,ninptr1,1)
;************************************************
   ascii_file = "./nc/"+fields(infields)+"_"+clim(j)+"_to_ccmavg_EOFCOMP_error.asc"
   error=asciiread(ascii_file,(/ninptr/),"float")
;************************************************
;************************************************
   ascii_file1 = "./nc/"+fields(infields)+"_"+clim(j)+"_indiv_to_ccmavg_EOFCOMP_error.asc"
   error1=asciiread(ascii_file1,(/ninptr1/),"float")
;************************************************
; error_comp = new((/3*ninptr/), "float")
    error_comp = new((/30/), "float")
    error_comp = (/0.0/)
    error_comp!0 ="all"
    error_comp&all= ispan(1,30,1)
;************************************************
    error_comp(0)=(/error(0)/)
    error_comp(1)=(/error1(0)/)
    error_comp(2)=(/error1(1)/)
    error_comp(3)=(/error(1)/)
    error_comp(4)=(/error1(0)/)
    error_comp(5)=(/error1(2)/)
    error_comp(6)=(/error(2)/)
    error_comp(7)=(/error1(0)/)
    error_comp(8)=(/error1(4)/)
    error_comp(9)=(/error(3)/)
    error_comp(10)=(/error1(1)/)
    error_comp(11)=(/error1(4)/)
    error_comp(12)=(/error(4)/)
    error_comp(13)=(/error1(3)/)
    error_comp(14)=(/error1(0)/)
    error_comp(15)=(/error(5)/)
    error_comp(16)=(/error1(3)/)
    error_comp(17)=(/error1(1)/)
    error_comp(18)=(/error(6)/)
    error_comp(19)=(/error1(3)/)
    error_comp(20)=(/error1(2)/)
    error_comp(21)=(/error(7)/)
    error_comp(22)=(/error1(3)/)
    error_comp(23)=(/error1(4)/)
    error_comp(24)=(/error(8)/)
    error_comp(25)=(/error1(2)/)
    error_comp(26)=(/error1(1)/)
    error_comp(27)=(/error(9)/)
    error_comp(28)=(/error1(2)/)
    error_comp(29)=(/error1(4)/)
   ascii_file = "./nc/"+fields(infields)+"_"+clim(j)+"_to_ccmavg_compare_EOFCOMP_error.asc" ; Create name of ASCII file.
   system("/bin/rm -f " + ascii_file) ; Remove ASCII file.
   asciiwrite(ascii_file,error_comp) ; Write part of temp to ASCII file.

;************************************************
 wks = gsn_open_wks ("ps", "./figure/"+fields(infields)+"_"+clim(j)+"_to_ccmavg_compare_EOFCOMP_error")
  gsn_define_colormap(wks,"gui_default") ; choose colormap
  res = True ; plot mods desired
  res@gsnScale = True
  
; these four resources allow the user to stretch the plot size, and
; decide exactly where on the page to draw it.
  
  res@vpXF = 0.10 ; In page coordinates, where to start
  res@vpYF = 0.75 ; the plot
  res@vpHeightF = 0.43 ; Changes the aspect ratio
  res@vpWidthF = 0.85
  
  res@trYMinF = -3.0 ; min value on y-axis
  res@trYMaxF = 3.0 ; max value on y-axis
  
res@tiYAxisString = fields(infields)
res@tiXAxisString = "combine"
; this resource changes a regular line plot to a bar chart
  res@gsnXYBarChart = True ; create bar chart
; this resource is required to get bars above and below a reference line
  res@gsnYRefLine = 0. ; reference line
  
; these two resources control the colors of the bars above and below
; the reference line.

  plot = new(1,graphic) ; create graphic array
    res@tiMainString = fields(infields)+"_"+clim(j)+"_to_ccmavg_EOFCOMP_error"
; res@gsnCenterString = fields(infields)+"_"+clim(j)+"_to_ccmavg_EOFCOMP_error"
 plot = gsn_csm_xy(wks,error_comp&all,error_comp,res)
;**********************************************************
; add text labels
;**********************************************************
; txres = True ; text mods desired
; txres@txFontHeightF = 0.018 ; default size is HUGE!
; txres@txAngleF = 52. ; text angle
; txres@txJust = "CenterLeft" ; puts text on top of bars
;
; do n = 0,3*ninptr-1
; mmmm=floattointeger(n/3)
; gsn_text(wks,plot,inptr(mmmm),n,error_comp(n)+1500,txres) ; add labels
; end do
; frame(wks)
;************************************************
; add legend to second plot
;**********************************************************
  getvalues plot ; get plot size for use in creating legend
  "vpXF" : vpx
  "vpYF" : vpy
  "vpHeightF" : vph
  "vpWidthF" : vpw
  end getvalues

  lbw = 0.4 * vpw ; Make labelbar size a fraction of the plot.
  lbh = 0.5 * vph
  nboxes = dimsizes(res@gsnXYBarChartColors)
   
  lbres = True ; legend only resources
  lbres@vpWidthF = 0.4 * vpw ; legend width
  lbres@vpHeightF = 0.5 * vph ; legend height
  lbres@lbBoxMajorExtentF = 0.75 ; puts space between color boxes
  lbres@lbFillColors = res@gsnXYBarChartColors ; legend colors
  lbres@lbMonoFillPattern = True ; Solid fill pattern
  lbres@lbLabelFontHeightF = 0.08 ; font height. default is small
  lbres@lbLabelJust = "CenterLeft" ; left justify labels
   
  gsn_labelbar_ndc(wks,nboxes,inptr,vpx+vph-lbw,0.77,lbres)
   
  frame(wks)
;************************************************
delete(error)
delete(error1)
delete(error_comp)
;************************************************
  delete(res)
  delete(plot)
  delete(pres)
  delete(wks)
  delete(txres)
;************************************************

end do
;************************************************
;************************************************

end do

end

_______________________________________________
ncl-talk mailing list
ncl-talk AT ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk



This archive was generated by hypermail 2b29 : Fri Oct 11 2002 - 08:56:17 MDT