Re: Help improving user defined procedure

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Dec 20 2013 - 09:43:14 MST

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

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

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