Re: Help improving user defined procedure

From: Paulo Santiago <paulohsm_at_nyahnyahspammersnyahnyah>
Date: Fri Dec 20 2013 - 10:26:40 MST

Dear Mary,

Thank you for attention.

Unfortunately this is not my case. My variables are originally stored in an
ASCII file. So, I have to assign the attributes by hand.

However, your final comments answers my question.

Cheers,

Paulo Santiago

2013/12/20 Mary Haley <haley@ucar.edu>

> Dear Paulo,
>
> If a variable has coordinates and attributes attached to it, this
> information stays with the variable even when you pass it to a function or
> procedure.
>
> I think that you should simply be able to do this:
>
> > plot_profile(ultend, "ultend",res)
>
> Where "plot_profile" looks like this:
>
> > undef("plot_profile")
> > procedure plot_profile(Var:numeric, \
> > VarName:string, \
> > Resource:logical)
> > local pwks, pplot
> > begin
> > pwks = gsn_open_wks("epsi", "semiprog_"+VarName)
> > pplot = gsn_csm_contour(pwks,Var,Resource)
> > end
>
> There's no need to reattach all the attributes inside the procedure,
> because "Var" will contain everything.
>
> You do still have to pass in the variable, and the name of itself, though.
> There's no way to retrieve the name of a variable from itself.
>
> --Mary
>
> On Dec 19, 2013, at 5:25 PM, Paulo Santiago <paulohsm@gmail.com> wrote:
>
> > Dear NCL community,
> >
> > I need some help with a procedure I'm defining to assign attributes to
> variables I'm reading from ASCII file.
> >
> > Initially, I was doing that with the sequence of commands for each
> variable, i.e., not using procedures:
> >
> > ultend!0 = "plev"
> > ultend&plev = pmid
> > ultend!1 = "time"
> > ultend&time = time
> > ultend@units = "m/s2"
> > ultend@long_name = "Tendency of zonal wind"
> > wks = gsn_open_wks("epsi", "semiprog_ultend")
> > plot = gsn_csm_contour(wks,ultend,res)
> >
> > Then I defined the procedure below:
> >
> > undef("plot_profile")
> > procedure plot_profile(Var:numeric, \
> > VarName:string, \
> > LongName:string, \
> > Units:string, \
> > VertAxis:numeric, \
> > TimeAxis:numeric, \
> > Resource:logical)
> > local pwks, pplot
> > begin
> > Var!0 = "plev"
> > Var&plev = VertAxis ;pmid
> > Var!1 = "time"
> > Var&time = TimeAxis ;time
> > Var@name = VarName
> > Var@long_name = LongName
> > Var@units = Units
> > pwks = gsn_open_wks("epsi", "semiprog_"+VarName)
> > pplot = gsn_csm_contour(pwks,Var,Resource)
> > end
> >
> > The procedure works and I can do the same task with a single command
> line passing an argument list as in the example below:
> >
> > plot_profile(ultend, "ultend", "Tendency of zonal wind", "m s-2", pmid,
> time, res)
> >
> > Now I bring the issues.
> >
> > The first two arguments are, in some way, redundant, since I'll be
> passing the variable's name twice.
> >
> > The last three arguments are also redundant because they will be the
> same for all variables. However, I have to pass them in order to get the
> procedure working.
> >
> > I thought I could remove the variable's name redundancy with dynamic
> variable name, but I coudn't find in documentation how to do this.
> >
> > I have no idea on how to pass variables (coodrinates, resources, etc.)
> to a procedure without passing them as arguments. Is it even possible?
> >
> > What would you suggest to eliminate these redundancies?
> >
> > I think I could do equivalent automation defining one array for each
> argument I need (variable, long_name, units), and then doing the repeated
> task in a loop. However, I don't think it would work for attributes
> assignment. Also, it would make difficult for me to control which variable
> I'm going to process every time I run the script.
> >
> > Thanks in advance!
> >
> > Cheers,
> >
> > --
> > Paulo Santiago
> > Ph.D. Student in Meteorology
> > National Institute for Space Research
> > Phone.: +55 (12) 3186 8637
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

-- 
Paulo Santiago
Doutorado em Meteorologia
Programa de Pós-Graduação em Meteorologia
Instituto Nacional de Pesquisas Espaciais
Tel.: (12) 3186 8637

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Dec 20 10:27:30 2013

This archive was generated by hypermail 2.1.8 : Mon Jan 06 2014 - 13:02:22 MST