It is currently Mon Nov 20, 2017 5:27 pm


All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: GT.M wrappers for C library math functions
PostPosted: Tue Apr 30, 2013 10:34 pm 
User avatar

Joined: Mon Nov 01, 2010 1:39 pm
Posts: 47
Real Name: John Willis
Began Programming in MUMPS: 01 Apr 2010
This was developed for the upcoming VistA geospatial extensions:

Code:
/**
 * xgismath.c
 * 
 * Math wrappers for GT.M callout interface
 *
 * Copyright (C) 2013 Coherent Logic Development LLC
 *
 * Author: JP Willis <jwillis@coherent-logic.com>
 * Date: 28 Apr 2013
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include <math.h>
#include "gtmxc_types.h"

int m_sin(int c, double *x, double *out)
{
  *out = sin(*x);
  return(0);
}

int m_cos(int c, double *x, double *out)
{
  *out = cos(*x);
  return(0);
}

int m_tan(int c, double *x, double *out)
{
  *out = tan(*x);
  return(0);
}

int m_asin(int c, double *x, double *out)
{
  *out = asin(*x);
  return(0);
}

int m_acos(int c, double *x, double *out)
{
  *out = acos(*x);
  return(0);
}

int m_atan(int c, double *x, double *out)
{
  *out = atan(*x);
  return(0);
}

int m_atan2(int c, double *y, double *x, double *out)
{
  *out = atan2(*y, *x);
  return(0);
}

int m_sinh(int c, double *x, double *out)
{
  *out = sinh(*x);
  return(0);
}

int m_cosh(int c, double *x, double *out)
{
  *out = cosh(*x);
  return(0);
}

int m_tanh(int c, double *x, double *out)
{
  *out = tanh(*x);
  return(0);
}

int m_exp(int c, double *x, double *out)
{
  *out = exp(*x);
  return(0);
}

int m_log(int c, double *x, double *out)
{
  *out = log(*x);
  return(0);
}

int m_log10(int c, double *x, double *out)
{
  *out = log10(*x);
  return(0);
}

int m_pow(int c, double *x, double *y, double *out)
{
  *out = pow(*x, *y);
  return(0);
}

int m_sqrt(int c, double *x, double *out)
{
  *out = sqrt(*x);
  return(0);
}

int m_ceil(int c, double *x, double *out)
{
  *out = ceil(*x);
  return(0);
}

int m_floor(int c, double *x, double *out)
{
  *out = floor(*x);
  return(0);
}

int m_fabs(int c, double *x, double *out)
{
  *out = fabs(*x);
  return(0);
}


Callout Table (xgismath.xc):
Code:
$HOME/lib/xgismath.so
sin: gtm_status_t m_sin(I:gtm_double_t*, O:gtm_double_t*)
cos: gtm_status_t m_cos(I:gtm_double_t*, O:gtm_double_t*)
tan: gtm_status_t m_tan(I:gtm_double_t*, O:gtm_double_t*)
asin: gtm_status_t m_asin(I:gtm_double_t*, O:gtm_double_t*)
acos: gtm_status_t m_acos(I:gtm_double_t*, O:gtm_double_t*)
atan: gtm_status_t m_atan(I:gtm_double_t*, O:gtm_double_t*)
atan2: gtm_status_t m_atan2(I:gtm_double_t*, I:gtm_double_t*, O:gtm_double_t*)
sinh: gtm_status_t m_sinh(I:gtm_double_t*, O:gtm_double_t*)
cosh: gtm_status_t m_cosh(I:gtm_double_t*, O:gtm_double_t*)
tanh: gtm_status_t m_tanh(I:gtm_double_t*, O:gtm_double_t*)
exp: gtm_status_t m_exp(I:gtm_double_t*, O:gtm_double_t*)
log: gtm_status_t m_log(I:gtm_double_t*, O:gtm_double_t*)
log10: gtm_status_t m_log10(I:gtm_double_t*, O:gtm_double_t*)
pow: gtm_status_t m_pow(I:gtm_double_t*, I:gtm_double_t*, O:gtm_double_t*)
sqrt: gtm_status_t m_sqrt(I:gtm_double_t*, O:gtm_double_t*)
ceil: gtm_status_t m_ceil(I:gtm_double_t*, O:gtm_double_t*)
floor: gtm_status_t m_floor(I:gtm_double_t*, O:gtm_double_t*)
abs: gtm_status_t m_fabs(I:gtm_double_t*, O:gtm_double_t*)


Makefile:
Code:
#
# Makefile
#
# Part of XGIS
# Copyright (C) 2013 Coherent Logic Development LLC
#
# Author: JP Willis <jwillis@coherent-logic.com>
# Date: 28 Apr 2013
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

CFLAGS=-Wall
GTMDIST=$(gtm_dist)

all: xgismath.so

xgismath.so: xgismath.o
   gcc $(CFLAGS) -o xgismath.so -shared xgismath.o

xgismath.o: xgismath.c
   gcc $(CFLAGS) -c -fPIC -I$(GTMDIST) xgismath.c

clean:
   rm xgismath.so
   rm xgismath.o

install:
   cp xgismath.so $(HOME)/lib
   cp xgismath.xc $(HOME)/lib


To use this, you'll need the following in ~/.bash_profile:

Code:
export GTMXC_xgismath=${HOME}/lib/xgismath.xc

_________________
John Willis, Founder
Coherent Logic Development
http://youngmumpster.wordpress.com/
jwillis@coherent-logic.com


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net