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

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Fri, 19 Jan 2007 13:50:37 -0700

Hi Mateus,

I do not see anything wrong with your function, and I assume you are not
getting back any error messages anymore. I wonder if you are not calling
the function in the correct place in your script. When using gsn_add_*
functions, you have to make sure the function call is after the plot
calls, but before the gsn_panel call.

Also, you have to save the primitive to a unique name in your calling
script or the primitives will be erased. (You are already correctly
doing that in your st_brazil function.) Thus, you will need to place the
returned array from st_brazil in a unique place each time you can
st_brazil. In the following example, I create an array named poli that
is of dimension size (Number of plots, number of polylines), and the
output of each call to st_brazil is placed in poli...

plot = new(6,graphic)
poli = new(/6,dimsizes(systemfunc("ls estados/c*.boundary"))/),graphic)
do gg = 0,5
    plot(gg) = gsn_csm_contour_map_ce(wks,array(gg,:,:),res)
    poli(gg,:) = st_brazil(wks,plot(gg),opts)
end do
gsn_panel(wks,plot,(/3,2/),False)

Hope that helps...
Adam

Mateus da Silva Teixeira wrote:
> 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
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
Received on Fri Jan 19 2007 - 13:50:37 MST

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