# [ncl-talk] Function in NCL

Rashed Mahmood rashidcomsis at gmail.com
Tue Aug 27 03:55:46 MDT 2019

```There are obvious errors in the code...e.g.
1) I do not think that you should use function sizeof, i guess what you
need is: N=dimsizes(in), please read the documents for details.
2) a and b were never predefined, so a(0) = 0 and b(0) = 0, would NOT work.
You need to define both of them using something like: a = new(,,,)

Cheers,
Rashed

On Tue, Aug 27, 2019 at 10:54 AM Md. Jalal Uddin via ncl-talk <
ncl-talk at ucar.edu> wrote:

> Hi all,
>
> I made a function in NCL that showed an error like *fatal:Undefined
> identifier: (a) is undefined, can't continue.  The error line highlighted
> in green color. Any suggestions would be appreciated.*
>
> *Code:*
>
> undef ("fftwavenumber")
> function fftwavenumber (in,k1,k2)
>
> ; K1, k2 are high and low-frequency wave numbers.
> ; You can determine bandpass, lowpass, highpass filtering,
> ; and in is the input data time series according to your needs.
>
> local in,p,a,b,f,k1,k2
>
> begin
>     N=sizeof(in)
>
>    if mod(N,2).eq.0 then
>          p=N/2     ; N even
>    else
>          p=(N-1)/2 ; N odd
>    end if
>
> pi=3.1416
>
> do k=0,p-1
>       a(k)=0
>       b(k)=0
>
>   do t=0,N-1
>       a(k)=a(k)+(2/N)*( in(t)*cos(2*pi*k*t/N) )
>       b(k)=b(k)+(2/N)*( in(t)*sin(2*pi*k*t/N) )
>   end do
> end do
>
> do t=0,N-1
>    do k=0,p-1
>         f(k,t)=a(k)*cos(2*pi*k*t/N)+b(k)*sin(2*pi*k*t/N)
>    end do
>    return (sum(f(k1:k2,t)))
> end do
>
> end
>
>
> Jalal
> --
> *Md. Jalal Uddin*
> MSc in Applied Meteorology
> Nanjing University of Information, Science and Technology, China
> B.Sc. in Disaster Management (Hons.)
> Patuakhali Science and Technology University, Bangladesh.
> Cell: +8613260859092, +8801792052662
> Web: www.dmjalal90.weebly.com