Re: calculate the remains after division

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sat, 7 Oct 2006 11:22:41 -0600 (MDT)

> Is there a function in NCL that calculate the remains after division? (like
> the function mod in Matlab and Fortran)
> _______________________________________________

NCL uses a operator, % , to perform the "mod" function.
One caveat, this works with variables of type integer, short and byte.
If n and m are (say) integers,

     k = n%m

see:
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclExpressions.shtml#TypesOfExpressions

---
You can write your own MOD function that behaves like the
the fortran mod function. A simple version would be:
undef ("MOD")
function MOD (r1:numeric, r2:numeric) 
begin
   if (typeof(r1).eq."float"   .and. typeof(r2).eq."float") then
       return( r1 - (r2 * floattointeger(r1 / r2)) )
   end if
   if (typeof(r1).eq."double"  .or. typeof(r2).eq."double") then
       return( r1 - (r2 * doubletointeger(r1 / r2)) ) ; be careful mixing types
   end if
   return( r1 % r2 )   ; type must be integer, short, byte
end
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Oct 07 2006 - 11:22:41 MDT

This archive was generated by hypermail 2.2.0 : Mon Oct 09 2006 - 09:24:50 MDT