Re: gsn_add_polyline in a procedure

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri, 19 Jan 2007 09:31:17 -0700 (MST)

On Fri, 19 Jan 2007, Mateus da Silva Teixeira wrote:

> Dear NCL users,
>
> I'm trying to make a procedure in NCL that draw the political division of
> Brazil. To make it useful when multiple figures are drawn in a panel, I'm
> trying to use gsn_add_polyline, but when call the procedure I get some
> warnings and any polylines are drawn. When I use gsn_polyline they are drawn
> but I can't paneling. Please, see below the warnings and the procedure:
>
> The warning messages:
>
> warning:TransformPostDraw: tfPolyDrawList element 0 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 1 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 2 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 3 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 4 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 5 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 6 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 7 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 8 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 9 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 10 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 11 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 12 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 13 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 14 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 15 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 16 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 17 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 18 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 19 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 20 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 21 is invalid
>
> The procedure:
>
> undef("st_brazil")
> procedure st_brazil(wks:graphic,plot:graphic,opts:logical)
> local wks,plot,resp,arquivos,narqs,front,npts,poli,latlon,opts
> begin
>
> resp=True resp_at_gsLineColor="Foreground" ; lines color
> resp_at_gsLineThicknessF=1.5 ; lines thickness
>
> ; lista de arquivos com posicoes de fronteiras
> arquivos=systemfunc("ls estados/c*.boundary") ; listing files with
> boundaries
> narqs=dimsizes(arquivos) ; number of files
> poli=new(narqs,graphic)
>
> do i=0,narqs-1
> front=asciiread(arquivos(i),-1,"float") ; read lat/lon points
> npts=dimsizes(front(0::2)) ; number of lat/lon points
>
> latlon=new((/2,npts/),float)
> latlon(0,:)=(/front(1::2)/) ; latitudes
> latlon(1,:)=(/front(0::2)/) ; longitudes
>
> ; adding line
> poli(i)=gsn_add_polyline(wks,plot,latlon(1,:),latlon(0,:),resp)
>
> delete(front) ;
> delete(npts)
> delete(latlon);
> end do
> end
>
> Can you help me? What's wrong in my procedure?
> Thank you
> Mateus
>

Hi Mateus,

You are correct in using gsn_add_polyline. The unfortunate side effect
of adding primitives is that you have to use a unique variable every
time, *and* you need to make sure this variable "lives" for the
duration that the script is being executed (or at least while the
workstation is still active).

I believe what's happening here is that "poli" is disappearing once
the procedure is exited, and hence the primitives no longer exist.
You need to make sure "poli" continues to exist outside the procedure.

You can do this a couple of ways. One is to turn your procedure into
a function and have it return "poli":

funcion st_brazil(wks:graphic,plot:graphic,opts:logical)
    ...
    delete(npts)
    delete(latlon);
  end do
  return(poli)
end

Then later:

   poli = st_brazil(wks,plot,opts)

Or, and this is probably not a great way to do this, you can
attach "poli" to one of the input arguments as an attribute:

procedure st_brazil(wks:graphic,plot:graphic,opts:logical)
    ...
    delete(npts)
    delete(latlon);
  end do
  wks_at_poli = poli
end

--Mary
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jan 19 2007 - 09:31:17 MST

This archive was generated by hypermail 2.2.0 : Fri Jan 19 2007 - 09:46:39 MST