Help improving user defined procedure

From: Paulo Santiago <paulohsm_at_nyahnyahspammersnyahnyah>
Date: Thu Dec 19 2013 - 17:25:32 MST

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 ( <%2812%29%203186%208637>12) 3186 8637

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Dec 19 17:26:03 2013

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