Re: "sign" function

From: Verena Lili <verena.prick_at_nyahnyahspammersnyahnyah>
Date: Sun Apr 06 2014 - 10:59:23 MDT

The problem is following:

ncl 0>
ncl 1> function sign( X )
ncl 2> begin
ncl 3> if X.eq.0 then
ncl 4> result = 0
ncl 5> else
ncl 6> if X.gt.0 then
ncl 7> result = 1
ncl 8> else
ncl 9> result = -1
ncl 10> end if
ncl 11> end if
ncl 12> return( result )
ncl 13> end
ncl 14>
ncl 15> a=(/-2,-3,-4,4,5,6-1/)
ncl 16>
ncl 17>* b=(a^2)*sign(a)*
*fatal:Conditional statements (if and do while) require SCALAR logical
values, see all and any functions*
*fatal:Execute: Error occurred at or near line 11*

*fatal:Execute: Error occurred at or near line 17*

Any subroutine that can work as global "sign" function in ncl and can be
used for multidimensional arrays? e.g.

X= [time, level, lat, lon]

y= (X^2) * sign (X)

Thank you.

On Thu, Apr 3, 2014 at 3:30 AM, Verena Lili <verena.prick@gmail.com> wrote:

> Thanks Brian!
>
>
> On Wed, Apr 2, 2014 at 6:50 PM, Brian Medeiros <brianpm@ucar.edu> wrote:
>
>> You could write that function:
>>
>> function sign( X )
>> begin
>> if X.eq.0 then
>> result = 0
>> else
>> if X.gt.0 then
>> result = 1
>> else
>> result = -1
>> end if
>> end if
>> return( result )
>> end
>>
>> .brian
>>
>>
>> On Apr 2, 2014, at 10:40 AM, Verena Lili <verena.prick@gmail.com> wrote:
>>
>> Hi NCL,
>>
>> Is there any function in NCL similar like `"*sign" *function in Matlab?
>>
>> --
>> Regards,
>> Dr. Verena.
>> School of Marine and Atmospheric Sciences
>> Stony Brook University
>> homepage: http://www.somas.stonybrook.edu/
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>>
>
>
> --
> Regards,
> Dr. Verena.
> School of Marine and Atmospheric Sciences
> Stony Brook University
> homepage: http://www.somas.stonybrook.edu/
>

-- 
Regards,
Dr. Verena.
School of Marine and Atmospheric Sciences
Stony Brook University
homepage: http://www.somas.stonybrook.edu/

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Apr 06 10:59:37 2014

This archive was generated by hypermail 2.1.8 : Tue Apr 15 2014 - 10:45:19 MDT