Re: Shortening a script

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sun Sep 23 2012 - 20:57:47 MDT

If you are "new to NCL", please see

http://www.ncl.ucar.edu/Document/Manuals/

Read the Mini-Language Manual & scan the Reference Manual.
See the sections on writing functions and procedures.

undef("getPrecip")
function getPrecip(f[1]:file,ymStrt[1]:integer,ymLast[1]:integer \
                ,vname[1]:string)
local TIME, YYYYMM, iStrt, iLast, x
begin
    TIME = f->time
    YYYYMM = cd_calendar(TIME, -1) ; convert
    iStrt = ind(ymStrt.eq.YYYYMM) ; index of start time
    iLast = ind(ymStrt.eq.YYYYMM) ; last time
    x = f->$vname$(iStrt:iLast,:,:) ; read specified time period
    return(x)
end

....
    trmmpre = getPrecip(trmm, ymStrt, yrLast, "pcp")
    udelpre = getPrecip(udel, ymStrt, yrLast, "precip")

===
Also, you can eliminate the addfile in the driver

undef("getPrecip")
function getPrecip(fname[1]:string \
                   ,ymStrt[1]:integer,ymLast[1]:integer, vname[1]:string)
local TIME, YYYYMM, iStrt, iLast, x
begin
    f = addfile(fname, "r")
    TIME = f->time
    YYYYMM = cd_calendar(TIME, -1) ; convert
    iStrt = ind(ymStrt.eq.YYYYMM) ; index of start time
    iLast = ind(ymStrt.eq.YYYYMM) ; last time
    x = f->$vname$(iStrt:iLast,:,:) ; read specified time period
    return(x)
end

...
    trmmpre = getPrecip("TRMM_1998-2011_3B42.nc", ymStrt, yrLast, "pcp")

etc

On 9/23/12 8:26 PM, Almami Johnson wrote:
> Dear all,
>
> I'm new in NCL and manage to write this script attached. However, I find
> it a bit long and may be it is possible to shorten the sections (see
> script): "Converting date and Read the variables" and "Taking JJA
> Seasonnal Average". For that latter, I even try to create a data array
> without any success.
>
> Could you please help me in shortening this script?
> Thanks in advance.
> Best regards
>
>
> _______________________________________________
> 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 Sun Sep 23 20:58:00 2012

This archive was generated by hypermail 2.1.8 : Wed Sep 26 2012 - 13:56:04 MDT