Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

NLfit_model.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2001, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 /*
00008   This file contains header information for NLfit_model.c.
00009   This file was adapted from afni_plugin.h.
00010 
00011   File:     NLfit_model.h
00012   Author:   B. Douglas Ward
00013   Date:     6 June 1997
00014 
00015   Mod:      Increased maximum number of model parameters, and maximum number
00016             of models.
00017   Date:     08 August 2001
00018 
00019 */
00020 
00021 /*---------------------------------------------------------------------------*/
00022 
00023 #ifndef _NLFIT_MODEL_HEADER_
00024 #define _NLFIT_MODEL_HEADER_
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <math.h>
00030 #include "mrilib.h"
00031 
00032 #if defined(__cplusplus) || defined(c_plusplus)
00033 # define DEFINE_MODEL_PROTOTYPE \
00034   extern "C" { MODEL_interface * initialize_model() ; }
00035 #else
00036 # define DEFINE_MODEL_PROTOTYPE
00037 #endif
00038 
00039 
00040 struct NLFIT_MODEL_array ; /* incomplete definition */
00041 
00042 /*******************************************************************
00043    Define macros and typedefs for opening, closing, and finding
00044    symbols from dynamic libraries.  This is not done the same
00045    way on all Unixoid systems, unfortunately (that is to say,
00046    HP-UX is different).
00047 *******************************************************************/
00048 
00049 typedef void (*vfp)();       /* pointer to generic function */
00050 
00051 #ifndef VOID_FUNC
00052 #define VOID_FUNC
00053 typedef void void_func() ;
00054 #endif
00055 
00056 #ifndef _AFNI_PLUGIN_HEADER_
00057 
00058 typedef int int_func() ;     /* generic function returning integer */
00059 typedef void * vptr_func() ; /* generic function returning void *  */
00060 typedef char * cptr_func() ; /* generic function returning char *  */
00061 
00062 /***************** The dlfcn.h and dl library ****************/
00063 
00064 #ifdef DYNAMIC_LOADING_VIA_DL
00065 
00066 #ifndef DARWIN
00067 #  include <dlfcn.h>
00068 #else
00069 #  include "dlcompat/dlfcn.h"
00070 #endif
00071    typedef void * DYNAMIC_handle ;
00072 
00073 #  define ISVALID_DYNAMIC_handle(handle) ((handle) != (DYNAMIC_handle) 0)
00074 
00075 #  define DYNAMIC_OPEN(libname,handle) \
00076       (handle) = dlopen( (libname) , RTLD_LAZY )
00077 
00078 #  define DYNAMIC_ERROR_STRING  dlerror()  /* 18 May 2001 */
00079 
00080 #  define DYNAMIC_CLOSE(handle) \
00081       (void) dlclose( (handle) )
00082 
00083 #  define DYNAMIC_SYMBOL(handle,symbol,address) \
00084       (address) = dlsym( (handle) , (symbol) )
00085 
00086 #  define DYNAMIC_suffix ".so"
00087 #endif
00088 
00089 /****************** The dl.h and dld library ******************/
00090 
00091 #ifdef DYNAMIC_LOADING_VIA_SHL
00092 #  include <dl.h>
00093    typedef shl_t DYNAMIC_handle ;
00094 
00095 #  define ISVALID_DYNAMIC_handle(handle) ((handle) != (DYNAMIC_handle) 0)
00096 
00097 #  define DYNAMIC_OPEN(libname,handle) \
00098       (handle) = shl_load( (libname) , BIND_DEFERRED , 0L )
00099 
00100 #  define DYNAMIC_ERROR_STRING strerror(errno) /* 18 May 2001 */
00101 
00102 #  define DYNAMIC_CLOSE(handle) \
00103       (void) shl_unload( (handle) )
00104 
00105 #  define DYNAMIC_SYMBOL(handle,symbol,address)      \
00106       do{ (address) = NULL ;                         \
00107           (void) shl_findsym( &(handle) , (symbol) , \
00108                               TYPE_UNDEFINED , &(address) ) ; } while(0)
00109 
00110 #  define DYNAMIC_suffix ".sl"
00111 #endif
00112 
00113 #ifndef DYNAMIC_suffix
00114 #  error "Plugins not properly set up -- see machdep.h"
00115 #endif
00116 
00117 #endif
00118 
00119 /*****************************************************************
00120    Data to define the interface between a MODEL and NLFIT
00121 ******************************************************************/
00122 
00123 /*----- dimensions of various arrays -----*/
00124 #define MAX_NAME_LENGTH  80          /* for model and file names */
00125 #define MAX_PARAMETERS  100          /* maximum number of model parameters */
00126 #define MAX_MODELS      100          /* maximum number of models */
00127 
00128 /*----- model type codes -----*/
00129 #define MODEL_NOISE_TYPE   0
00130 #define MODEL_SIGNAL_TYPE  1 
00131 
00132 
00133 /** macro to copy string into MODEL label array,
00134     filling with blanks or truncating length, as needed **/
00135 #define MODEL_LABEL_strcpy(mlab,str)                                \
00136    do{ int ll=strlen((str)) , ii ;                                   \
00137        if( ll >= MAX_NAME_LENGTH ) ll = MAX_NAME_LENGTH - 1 ;    \
00138        for( ii=0 ; ii < ll ; ii++ ) (mlab)[ii] = (str)[ii] ;         \
00139        for( ; ii < MAX_NAME_LENGTH - 1 ; ii++ ) (mlab)[ii] = ' ' ; \
00140        mlab[MAX_NAME_LENGTH - 1] = '\0' ; } while(0)
00141 
00142 
00143 typedef struct {
00144   char label[MAX_NAME_LENGTH];          /* name of the model */
00145   int  model_type;                      /* noise or signal model? */
00146   int  params;                          /* number of parameters */
00147   char plabel[MAX_PARAMETERS][MAX_NAME_LENGTH];   /* parameter labels */
00148   float min_constr[MAX_PARAMETERS];   /* minimum parameter constraints */
00149   float max_constr[MAX_PARAMETERS];   /* maximum parameter constraints */
00150   void_func * call_func ;             /* function which implements the model */
00151 } MODEL_interface ;
00152 
00153 
00154 /**************************************************************************/
00155 /***** Define data structures to hold control information for MODELs *****/
00156 
00157 #define NLFIT_MODEL_TYPE        1066
00158 #define ISVALID_NLFIT_MODEL(pl) ((pl)!=NULL && (pl)->type==NLFIT_MODEL_TYPE)
00159 
00160 #define MAX_MODEL_NAME 128
00161 
00162 /*** one MODEL ***/
00163 
00164 typedef struct {
00165    int type ;        /* identifier */
00166 
00167    char              libname[MAX_MODEL_NAME] ;
00168    DYNAMIC_handle    libhandle ;
00169    vptr_func       * libinit_func ;
00170    MODEL_interface * interface ;
00171 } NLFIT_MODEL ;
00172 
00173 /*** dynamic array of many MODELs ***/
00174 
00175 typedef struct NLFIT_MODEL_array {
00176    int num , nall ;
00177    NLFIT_MODEL ** modar ;
00178 } NLFIT_MODEL_array ;
00179 
00180 /*** macros to create, add to, destroy, and free an array of MODELs ***/
00181 
00182 #define INC_MODEL_ARRAY 8
00183 
00184 /** "name" is a variable of type (NLFIT_MODEL_array *) **/
00185 
00186 #define INIT_MODEL_ARRAY(name)                                                \
00187    do{ int iq ;                                                               \
00188      (name)       = (NLFIT_MODEL_array *) malloc(sizeof(NLFIT_MODEL_array));  \
00189      (name)->num  = 0 ;                                                       \
00190      (name)->nall = INC_MODEL_ARRAY ;                                         \
00191      (name)->modar= (NLFIT_MODEL **)malloc(sizeof(NLFIT_MODEL*)*(name)->nall);\
00192      for (iq=(name)->num; iq < (name)->nall; iq++ ) (name)->modar[iq] = NULL; \
00193      } while(0)
00194 
00195 /** "model" is a variable of type (NLFIT_MODEL *) **/
00196 
00197 #define ADDTO_MODEL_ARRAY(name,model)                                         \
00198    do{ int nn , iq ;                                                          \
00199        if( (name)->num == (name)->nall ){                                     \
00200           nn = (name)->nall = 1.1*(name)->nall + INC_MODEL_ARRAY ;            \
00201           (name)->modar = realloc( (name)->modar,sizeof(NLFIT_MODEL *)*nn );  \
00202           for( iq=(name)->num ; iq < (name)->nall ; iq++ )                    \
00203             (name)->modar[iq] = NULL ;}                                       \
00204        nn = (name)->num ; ((name)->num)++ ;                                   \
00205        (name)->modar[nn] = (model) ;                                          \
00206      } while(0)
00207 
00208 /** this frees all the memory associated with this array **/
00209 
00210 #define DESTROY_MODEL_ARRAY(name)                                      \
00211    do{ int nn ;                                                         \
00212        if( (name) != NULL ){                                            \
00213           for( nn=0 ; nn < (name)->num ; nn++ )                         \
00214              if( (name)->modar[nn] != NULL ) free( (name)->modar[nn] ) ;  \
00215           free( (name)->modar ) ; free((name)) ; (name) = NULL ;         \
00216        } } while(0)
00217 
00218 /** this just frees the control data associated
00219     with this array -- the actual MODELs are not freed. **/
00220 
00221 #define FREE_MODEL_ARRAY(name)                                         \
00222    do{ int nn ;                                                         \
00223        if( (name) != NULL ){                                            \
00224           free( (name)->modar ) ; free((name)) ; (name) = NULL ;         \
00225        } } while(0)
00226 
00227 /*---------------------------------------------------------------------------*/
00228 
00229 /*----- Other prototypes -----*/
00230 
00231 extern NLFIT_MODEL_array * NLFIT_get_all_MODELs (char * dname);
00232 extern NLFIT_MODEL *       NLFIT_read_MODEL (char * fname);
00233 extern NLFIT_MODEL_array * NLFIT_get_many_MODELs (void);
00234 
00235 /*---------------------------------------------------------------------------*/
00236 /*----- Array of pointers to functions that are needed by the model_conv*.c  */
00237 /*----- routines.  This array is just to force loading of these functions    */
00238 /*----- from libraries. ----- RW Cox (21 July 1998) -------------------------*/
00239 
00240 #ifndef RWC_FORCED_LOADS
00241 #define RWC_FORCED_LOADS
00242 
00243 static vptr_func * NL_forced_loads[] = {
00244    (vptr_func *) mri_read_ascii ,
00245    (vptr_func *) mri_to_float ,
00246    (vptr_func *) mri_transpose ,
00247    (vptr_func *) mri_free ,
00248 NULL } ;
00249 
00250 vptr_func * RWC_forced_loads(int n){  /* this function is to try to ensure   */
00251   return NL_forced_loads[n] ;         /* that the array isn't optimized away */
00252 }
00253 
00254 #endif
00255 
00256 
00257 /*---------------------------------------------------------------------------*/
00258 
00259 #endif /* _NLFIT_MODEL_HEADER_ */
00260 
00261 
 

Powered by Plone

This site conforms to the following standards: