floor function for grads

Arlindo da Silva dasilva at ALUM.MIT.EDU
Mon Sep 15 22:56:43 EDT 2008


On Mon, Sep 15, 2008 at 12:09 PM, P.Romero <romero619 at hotmail.com> wrote:

>  I need to implement the FLOOR function.
>
> What's the best/easiest way to get this done?
>
> I'm guessing as a UDF, but I need some help on setting up the C code…
>

It should be relatively simple to do it as a dynamic UDF for v1.9.0-rc1.
Here is the example of the sqrt function implemented as such:

http://opengrads.cvs.sourceforge.net/*checkout*/opengrads/grads/udf/dll/my_sqrt.c?revision=1.2

Basically, you just need to replace the sqrt() call with floor() and removed
the test for positive values. Everything else should stay the same. (You
could start with a global search+replace "sqrt" -> "floor").

Here are some quick instructions to have your function built. Start with the
 sources from

 grads-1.9.0-rc1-gex-r2.tar.gz<http://downloads.sourceforge.net/opengrads/grads-1.9.0-rc1-gex-r2.tar.gz?modtime=1207263579&big_mirror=0>

Then

% tar xvfz grads-1.9.0-rc1-gex-r2.tar.gz
% cd grads-1.9.0-rc1-gex-rc2/extensions

Make a directory for your function and copy some basic files in it:

% mkdir floor
% cp hello/GNUmakefile floor

Now place your floor.c function in this new directory, and add a file named
"floor.udxt.in" with something like:

#  Type       Name            Function                 Library
# ------  ---------------  ----------------
 --------------------------------
   udf        floor          gaudf         floor.gex. at DLLEXT@

Then build your function

% cd floor
% make

This should create floor.gex.so (or floor.gex.dylib on Mac OS X) and
floor.udxt . It is just a bit more complicated to do this on Windows but it
can be done.

To test it run grads from this directory and

% export GAUDXT="./floor.udxt"
% export LD_LIBRARY_PATH=`pwd`
% gradsnc -l
ga-> open something
ga-> q udft
(should show your floor function)
ga-> display floor(whatever)
(it should work)

Once you are convinced that it works install it. Add the contents of
floor.udxt to your main udxt file and put floor.gex.so alongside your other
extensions. That is it.

Additional information about the opengrads extensions are here:

      http://opengrads.org/wiki/index.php?title=User_Defined_Extensions

VERY IMPORTANT: This is the procedure in v1.9.0-rc1 and details will very
likely change for grads v2. So, any function developed for v1.9 will need to
be ported to v2.0. Therefore, unless you need something that cannot wait,
there is no much point in developing new functions for v1.9.

   Good Luck,

      Arlindo

-- 
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080915/aa57f458/attachment.html 


More information about the gradsusr mailing list