[ncl-talk] Function in NCL

Rick Brownrigg brownrig at ucar.edu
Tue Aug 27 07:24:37 MDT 2019


Hi,

I don't see where you declare "a" to be an array before attempting to use
it as such. You'll need to do something like:

  a = new((/p/), float)

Also, as just a hint, its not necessary to set a(k) = 0 in the outer loop;
that could be done more simply by writing

  a = new((/ p /), float)
  a = 0    ; assigns all p-values of the array to zero

Rick


On Tue, Aug 27, 2019 at 3:56 AM Rashed Mahmood via ncl-talk <
ncl-talk at ucar.edu> wrote:

> 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
>> Facebook: jalal.hossen.39
>> LinkedIn: https://bd.linkedin.com/in/md-jalal-uddin-80a026b0
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190827/b5a869a0/attachment.html>


More information about the ncl-talk mailing list