The following example simply adds two scalars. Other examples can be found in subdirectories of $CEI/ensight251/src/math_functions/
#include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef WIN32 #include <unistd.h> #endif #include "../extern/udmf_extern.h" /*-------------------------------------------------------------------- * USERD_get_name_of_mf *-------------------------------------------------------------------- * * Gets the name of the math function, so gui can list as a calculator * function. * * (OUT) mf_name = the name of the math function * (max length is UDMFSNAME, which is 64) * * returns: Z_OK if successful * Z_ERR if not successful * *--------------------------------------------------------------------*/ int USERD_get_name_of_mf(char mf_name[UDMFSNAME]) { memset(mf_name,'\0',UDMFSNAME); strcpy(mf_name, "addTwoScalars"); return(Z_OK); } /*-------------------------------------------------------------------- * USERD_get_mf_version *-------------------------------------------------------------------- * * Gets the version number of the user defined math function supported API * * (OUT) version_number = the version number of the math function * (max length is UDMFSNAME, which is 64) * * returns: Z_OK if successful * Z_ERR if not successful * * Notes: * * version needs to be "1.000". *--------------------------------------------------------------------*/ int USERD_get_mf_version(char version_number[UDMFSNAME]) { strcpy(version_number, "1.000"); return(Z_OK); } /*-------------------------------------------------------------------- * USERD_get_nargs *-------------------------------------------------------------------- * * Gets the number of arguments needed by the function. * * (OUT) nArgs = the number of arguments * * returns: Z_OK if successful * Z_ERR if not successful * *--------------------------------------------------------------------*/ int USERD_get_nargs(int *nArgs) { *nArgs = 2; return(Z_OK); } /*-------------------------------------------------------------------- * USERD_get_meta_data *-------------------------------------------------------------------- * * Get the function descriptions, argument types, and return type. * * (OUT) listDescription = description shown in general function column * (OUT) funcDescription = description shown in feedback window * (OUT) argTypes = data types of arguments passed into USERD_evaluate * (OUT) returnType = data type returned by function USERD_evaluate * * returns: Z_OK if successful * Z_ERR if not successful * *--------------------------------------------------------------------*/ int USERD_get_meta_data(char listDescription[UDMFLNAME], char funcDescription[UDMFLNAME], int *argTypes, int *returnType) { strcpy(listDescription, "add2(part, scalar, scalar)"); strcpy(funcDescription, "add2(any part(s), scalar, scalar)"); argTypes[0] = UDMFSCL; argTypes[1] = UDMFSCL; *returnType = UDMFSCL; return(Z_OK); } /*-------------------------------------------------------------------- * USERD_evaluate *-------------------------------------------------------------------- * * Evaluate the function. * * (OUT) args = pointers to arguments * (OUT) undefined = boolean; true if return value is undefined. * (OUT) value = returned value * * returns: Z_OK if successful * Z_ERR if not successful * *--------------------------------------------------------------------*/ int USERD_evaluate(void *args[], void *value, int *undefined) { float *result; float *arg1, *arg2; result = value; arg1 = args[0]; arg2 = args[1]; *result = *arg1 + *arg2; *undefined = 0; return(Z_OK); }