<div dir="ltr"><div class="gmail_quote">On Mon, Sep 15, 2008 at 12:09 PM, P.Romero <span dir="ltr"><<a href="mailto:romero619@hotmail.com">romero619@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">I need to implement the FLOOR function.</span></font></p>
<p><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">What's the best/easiest way to get this done?</span></font></p>
<p><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">I'm guessing as a UDF, but I need some help on setting
up the C code…</span></font></p></div></div></blockquote><div><br></div><div>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:</div><div>
<br></div><div><a href="http://opengrads.cvs.sourceforge.net/*checkout*/opengrads/grads/udf/dll/my_sqrt.c?revision=1.2">http://opengrads.cvs.sourceforge.net/*checkout*/opengrads/grads/udf/dll/my_sqrt.c?revision=1.2</a><br>
</div><div><br></div><div>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").</div>
<div><br></div><div>Here are some quick instructions to have your function built. Start with the sources from </div><div><br></div><div><a href="http://downloads.sourceforge.net/opengrads/grads-1.9.0-rc1-gex-r2.tar.gz?modtime=1207263579&big_mirror=0"> grads-1.9.0-rc1-gex-r2.tar.gz</a><br>
</div><div><br></div><div>Then</div><div><br></div><div>% tar xvfz grads-1.9.0-rc1-gex-r2.tar.gz</div><div>% cd grads-1.9.0-rc1-gex-rc2/extensions</div><div><br></div><div>Make a directory for your function and copy some basic files in it:</div>
<div><br></div><div>% mkdir floor</div><div>% cp hello/GNUmakefile floor</div><div><br></div><div>Now place your floor.c function in this new directory, and add a file named "<a href="http://floor.udxt.in">floor.udxt.in</a>" with something like:</div>
<div><br></div><div># Type Name Function Library</div><div># ------ --------------- ---------------- -------------------------------- </div><div> udf floor gaudf floor.gex.@DLLEXT@<br>
</div><div><br></div><div>Then build your function</div><div><br></div><div>% cd floor</div><div>% make</div><div><br></div><div>This should create <a href="http://floor.gex.so">floor.gex.so</a> (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. </div>
<div><br></div><div>To test it run grads from this directory and</div><div><br></div><div>% export GAUDXT="./floor.udxt"</div><div>% export LD_LIBRARY_PATH=`pwd`</div><div>% gradsnc -l</div><div>ga-> open something</div>
<div>ga-> q udft</div><div>(should show your floor function)</div><div>ga-> display floor(whatever)</div><div>(it should work)</div><div><br></div><div>Once you are convinced that it works install it. Add the contents of floor.udxt to your main udxt file and put <a href="http://floor.gex.so">floor.gex.so</a> alongside your other extensions. That is it.</div>
<div><br></div><div>Additional information about the opengrads extensions are here:<br></div><div><br></div><div> <a href="http://opengrads.org/wiki/index.php?title=User_Defined_Extensions">http://opengrads.org/wiki/index.php?title=User_Defined_Extensions</a><br>
</div><div><br></div><div>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.</div>
<div><br></div><div> Good Luck,</div><div><br></div><div> Arlindo</div><div><br></div></div>-- <br>Arlindo da Silva<br><a href="mailto:dasilva@alum.mit.edu">dasilva@alum.mit.edu</a><br>
</div>