Re: [Bulk] Re: [ncl-talk] gsn_add_polyline in a procedure

From: Mateus da Silva Teixeira <mtex2k3_at_nyahnyahspammersnyahnyah>
Date: Fri, 19 Jan 2007 17:27:15 -0200

Hi Mary,

Thank you by the hints! By transforming my procedure in a function works
perfectly.
However, now I'm having another problem: I'm trying to assign some
attributes to gsn_add_polyline by my function, but it isn't work.
Please, see below how is the function now:

function st_brazil(wks:graphic,plot:graphic,opts:logical)
local wks,plot,resp,arquivos,narqs,front,npts,poli,latlon,opts
begin

  resp=True
  ; verifying for color attribute
  if (opts .and. isatt(opts,"color")) then
     resp_at_gsLineColor=opts_at_color ; specified line color
  else
     resp_at_gsLineColor="Foreground" ; default line color
  end if

  ; verifying for thickness attribute
  if (opts .and. isatt(opts,"thickness")) then
     resp_at_gsLineThicknessF=opts_at_thickness ; specified line thickness
  else
     resp_at_gsLineThicknessF=1.5 ; default line thickness
  end if

  ; listing boundary files
  arquivos=systemfunc("ls
$NCARG_ROOT/lib/ncarg/nclscripts/myscripts/brazil/c*.boundary")
  narqs=dimsizes(arquivos) ; total of boundary files
  poli=new(narqs,graphic) ; graphical vector

  do i=0,narqs-1
    front=asciiread(arquivos(i),-1,"float") ; reading lat/lon points
    npts=dimsizes(front(0::2)) ; total of lat/lon points

    latlon=new((/2,npts/),float) ; creating lat/lon matrix
    latlon(0,:)=(/front(1::2)/) ; latitudes
    latlon(1,:)=(/front(0::2)/) ; longitudes

    ; adding lines
    poli(i)=gsn_add_polyline(wks,plot,latlon(1,:),latlon(0,:),resp)

    delete(front) ;
    delete(npts) ; => deleting variables to make them uniques
    delete(latlon) ;
  end do
  return(poli) ; returning the graphical variable with political division
end

Am I doing something wrong on provide the attibutes to gsn_add_polyline?

Thank you
Mateus

Mary Haley escreveu:
>
> 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
>
Received on Fri Jan 19 2007 - 12:27:15 MST

This archive was generated by hypermail 2.2.0 : Mon Feb 05 2007 - 07:15:45 MST