Re: NCL user defined procedures in NCL scripting language

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Oct 11 2011 - 11:15:04 MDT

Ybou can always look at (say) contributed.ncl or shea_util.ncl.

%> less $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl

eg: pattern_cor2, stat_dispersion, ....

%> less $NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl

eg: specx_ci, SPECX_ANAL, advect_gradient

====================

procedure: perform an action (create a plot,...)
function: return a value/array to the the calling program.

Tips: 'undef' a function or procedure before creating yours.
       You can not 'undef' a builtin function.

        prototype variables when appropriate

undef("function/procedure name")
procedure/function foo(a, b[*], c:numeric, d:file, e[*][*], g[1]:string)
local q, r, s, t ; (optional but recommended)
begin
   ...
   return(answer) ; function only
end

In above:

a can be any type or dimension
b can be any type but MUST be one-dimensional
c can be any numeric type and any dimension;
   other types will cause error

e can be any type but must be 2D

g must ba a single string

Good luck

On 10/11/2011 10:53 AM, ugo merlini wrote:
> Hi,
>
> I just write a function
>
> begin ; begin function
> undef("New_function") ; function name
> function New_function(variable:variable type) ;where "variable" is the
> variable I want to import from the main code and variable type is type
> of variable I import (string, integer, ecc)
>
> function code
>
> return(variable); variable to send to main code
>
> end; end function
>
> begin ; start main code
>
>
> to call the function
>
> function_result = (New_function(variable)) ; where variable is the
> variable to pass to the function and function_result in the variable
> passed from the function to main code
>
> end; end main code
>
> hopes can help
>
> Ugo
>
>
>
>
>
> ------------------------------------------------------------------------
> Date: Tue, 11 Oct 2011 17:43:10 +0200
> From: gking@fc.ul.pt
> To: ncl-talk@ucar.edu
> Subject: NCL user defined procedures in NCL scripting language
>
> Dear All,
>
> I am trying to write my own NCL procedures in the NCL scripting
> language. The manuals are rather terse and I would like to study some
> simple examples. However, I have not been able to locate anything on the
> NCL website or talk archives.
>
> Is there an undocumented location where such example scripts can be found??
>
> Thanks,
> greg king
> _______________________________________________ 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

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Oct 11 11:15:11 2011

This archive was generated by hypermail 2.1.8 : Wed Oct 12 2011 - 15:59:45 MDT