[ncl-talk] gsn_add_polyline error

Mary Haley haley at ucar.edu
Wed Jun 1 17:41:37 MDT 2016


Hi David,

The issue is that when you have a line with missing value segments, a
graphical object has to be created for every line segment. It therefore may
return several objects if you have several line segments.

You have this code:

        dum1(0) = gsn_add_polyline
(wks,plot,flight_time(mintime:maxtime),vert_accel(mintime:maxtime),polyres)

which is failing because "dum1(0)" is one object, but gsn_add_polyline is
trying to return two objects.

The error "Dimension sizes on right hand side of assignment do not match
dimension sizes of left hand side", was telling you that the thing on the
left of the "=" doesn't match what the right side is trying to return.

If you simply remove or comment this line:

      dum1       = new(20,"graphic")

and then do this:

         dum1 =
gsn_add_polyline(wks,plot,flight_time(mintime:maxtime),vert_accel(mintime:maxtime),polyres)

it should work fine.

BTW, I think to get gsn_polyline to work you could move the "draw(plot)"
command to before the gsn_polyline call.  However, it's better to use
gsn_add_polyline in general, because then the lines become part of the
plot. If you need to resize the plot later, like in a call to gsn_panel,
then the lines will stay with the plot.

--Mary



On Wed, Jun 1, 2016 at 11:38 AM, Vollaro, David <dvollaro at albany.edu> wrote:

> Hi,
>
>
> I am trying to add a line that has missing values onto an XY plot using
> gsn_add_polyline.  If the missing values are arranged such that 2 segments
> are created(ie MM###MMM## where M=missval and #=a number) the following
> error occurs:
>
>
> fatal:Dimension sizes on right hand side of assignment do not match
> dimension sizes of left hand side
> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 85 in
> file polylin_order.ncl
>
> If only 1 segment is created(#####MMMM) then everything works fine.  A
> simplified version of the script is below with a sample dataset attached.
> Any help is appreciated.
>
> Dave
>
>
>
> ---------------------------------------------------------------------------------------------------------------------
>
> 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/contributed.ncl"
> ;-----------------------------------------------------------------;
> ;polylin_test.ncl
> ; djv 3/16
> ; This program is tests polyline issue w/missvals.  If have more than 1
> segment
> ; and use gsn_add_polyline will get error:
> ;fatal:Dimension sizes on right hand side of assignment do not match
> dimension sizes of left hand side
> ;fatal:["Execute.c":8575]:Execute: Error occurred at or near line 95 in
> file ploylin_order.ncl
>
> ; Can avoid using gsn_polyline but cannot control order of plotting
> ;-----------------------------------------------------------------;
>
> begin
>  res = True
>  resplan = True
> ;------------------ User PARAMETERS -----------------------------
>
> ;------------------ End User PARAMETERS -------------------------
>
>    datafile = "test.dat"
>    data   = asciiread(datafile,-1,"string")
>    vert_accel = stringtofloat(str_get_cols(data, 0,6))
>    altkm = stringtofloat(str_get_cols(data, 7,12))
>    vert_accel at _FillValue = -32767
>    altkm at _FillValue = -32767
>
>    mintime = 0
>    maxtime = numAsciiRow(datafile) - 1
>    flight_time = fspan(mintime,maxtime,maxtime+1)
>
> ;Set some resources for xy plots
>     ytres = True              ;Resources for timeseries plots
>     ytres at tiXAxisString = "minutes"
>     ytres at trXMinF    = 0
>     ytres at trXMaxF    = maxtime
>     ytres at xyLineThicknessF = 2.
>     ytres at gsnDraw     = False     ;Set to False so can plot multi-colored
> lines
>     ytres at gsnFrame    = False
>     ytres at tiYAxisOn   = True
>
> ; Set plt resources for vert accel
>     ytresa = ytres
>     ytresa at trYMinF = -2
>     ytresa at trYMaxF = 2
>     ytresa at tiYAxisString = "Vacc(Yellow)"
> ;     ytresa at xyCurveDrawOrder = "PreDraw"
> ;     ytresa at xyLineColor = -1          ;Set=Transparent so polyline
> colors work
>
> ; Set plt resources for altitude
>     altres = ytres
>     altres at trYMinF = 10
>     altres at trYMaxF = 15
>     altres at tiYAxisString = "Alt"
>     altres at xyLineColor = 1          ;Set=Transparent so polyline colors
> work
>     wks = gsn_open_wks("X11","outfile")
>
>     plot =
> gsn_csm_xy2(wks,flight_time(mintime:maxtime),vert_accel(mintime:maxtime),altkm(mintime:maxtime),ytresa,altres)
>
> ;----------------------------------------------
> ;   Overlay colored lines
> ;   gsn_add_polyline does not work if segment is brken up into 2 due to
> missval
> ;   Will work w/gsn_ployline but will plot 1st and then overlay gsn_csm_xy
> plt
> ;----------------------------------------------
>      dum1       = new(20,"graphic")
>      polyres = True
>      polyres at gsLineThicknessF = 8.
>      polyres at gsLineColor = "yellow"
> ;     ytresa at tfPolyDrawOrder = "PostDraw"
>
>     if(any(.not.ismissing(vert_accel(mintime:maxtime))))then
> ;        dum1(0) =
> gsn_add_polyline(wks,plot,flight_time(mintime:maxtime),vert_accel(mintime:maxtime),polyres)
>
>
> gsn_polyline(wks,plot,flight_time(mintime:maxtime),vert_accel(mintime:maxtime),polyres)
>     end if
>     draw(plot)
>     frame(wks)
> end
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160601/8d4052c6/attachment.html 


More information about the ncl-talk mailing list