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 File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "mrilib.h"
#include <dlfcn.h>

Go to the source code of this file.


Data Structures

struct  MODEL_interface
struct  NLFIT_MODEL
struct  NLFIT_MODEL_array

Defines

#define DEFINE_MODEL_PROTOTYPE
#define ISVALID_DYNAMIC_handle(handle)   ((handle) != (DYNAMIC_handle) 0)
#define DYNAMIC_OPEN(libname, handle)   (handle) = dlopen( (libname) , RTLD_LAZY )
#define DYNAMIC_ERROR_STRING   dlerror()
#define DYNAMIC_CLOSE(handle)   (void) dlclose( (handle) )
#define DYNAMIC_SYMBOL(handle, symbol, address)   (address) = dlsym( (handle) , (symbol) )
#define DYNAMIC_suffix   ".so"
#define MAX_NAME_LENGTH   80
#define MAX_PARAMETERS   100
#define MAX_MODELS   100
#define MODEL_NOISE_TYPE   0
#define MODEL_SIGNAL_TYPE   1
#define MODEL_LABEL_strcpy(mlab, str)
#define NLFIT_MODEL_TYPE   1066
#define ISVALID_NLFIT_MODEL(pl)   ((pl)!=NULL && (pl)->type==NLFIT_MODEL_TYPE)
#define MAX_MODEL_NAME   128
#define INC_MODEL_ARRAY   8
#define INIT_MODEL_ARRAY(name)
#define ADDTO_MODEL_ARRAY(name, model)
#define DESTROY_MODEL_ARRAY(name)
#define FREE_MODEL_ARRAY(name)

Typedefs

typedef void(* vfp )()
typedef int int_func ()
typedef void * vptr_func ()
typedef char * cptr_func ()
typedef void * DYNAMIC_handle
typedef NLFIT_MODEL_array NLFIT_MODEL_array

Functions

NLFIT_MODEL_arrayNLFIT_get_all_MODELs (char *dname)
NLFIT_MODELNLFIT_read_MODEL (char *fname)
NLFIT_MODEL_arrayNLFIT_get_many_MODELs (void)
vptr_funcRWC_forced_loads (int n)

Variables

vptr_funcNL_forced_loads []

Define Documentation

#define ADDTO_MODEL_ARRAY name,
model   
 

Value:

do{ int nn , iq ;                                                          \
       if( (name)->num == (name)->nall ){                                     \
          nn = (name)->nall = 1.1*(name)->nall + INC_MODEL_ARRAY ;            \
          (name)->modar = realloc( (name)->modar,sizeof(NLFIT_MODEL *)*nn );  \
          for( iq=(name)->num ; iq < (name)->nall ; iq++ )                    \
            (name)->modar[iq] = NULL ;}                                       \
       nn = (name)->num ; ((name)->num)++ ;                                   \
       (name)->modar[nn] = (model) ;                                          \
     } while(0)
"model" is a variable of type (NLFIT_MODEL *) *

Definition at line 197 of file NLfit_model.h.

Referenced by NLFIT_get_all_MODELs(), and NLFIT_get_many_MODELs().

#define DEFINE_MODEL_PROTOTYPE
 

Definition at line 36 of file NLfit_model.h.

#define DESTROY_MODEL_ARRAY name   
 

Value:

do{ int nn ;                                                         \
       if( (name) != NULL ){                                            \
          for( nn=0 ; nn < (name)->num ; nn++ )                         \
             if( (name)->modar[nn] != NULL ) free( (name)->modar[nn] ) ;  \
          free( (name)->modar ) ; free((name)) ; (name) = NULL ;         \
       } } while(0)
this frees all the memory associated with this array *

Definition at line 210 of file NLfit_model.h.

Referenced by get_options(), NLFIT_get_all_MODELs(), NLFIT_get_many_MODELs(), and PLUGIN_init().

#define DYNAMIC_CLOSE handle       (void) dlclose( (handle) )
 

Definition at line 80 of file NLfit_model.h.

Referenced by NLFIT_read_MODEL(), and PLUG_read_plugin().

#define DYNAMIC_ERROR_STRING   dlerror()
 

Definition at line 78 of file NLfit_model.h.

Referenced by NLFIT_read_MODEL(), and PLUG_read_plugin().

#define DYNAMIC_OPEN libname,
handle       (handle) = dlopen( (libname) , RTLD_LAZY )
 

Definition at line 75 of file NLfit_model.h.

Referenced by NLFIT_read_MODEL(), and PLUG_read_plugin().

#define DYNAMIC_suffix   ".so"
 

Definition at line 86 of file NLfit_model.h.

Referenced by NLFIT_get_all_MODELs(), PLUG_get_all_plugins(), and PLUG_read_plugin().

#define DYNAMIC_SYMBOL handle,
symbol,
address       (address) = dlsym( (handle) , (symbol) )
 

Definition at line 83 of file NLfit_model.h.

Referenced by NLFIT_read_MODEL(), and PLUG_read_plugin().

#define FREE_MODEL_ARRAY name   
 

Value:

do{ int nn ;                                                         \
       if( (name) != NULL ){                                            \
          free( (name)->modar ) ; free((name)) ; (name) = NULL ;         \
       } } while(0)
this just frees the control data associated with this array -- the actual MODELs are not freed. *

Definition at line 221 of file NLfit_model.h.

Referenced by NLFIT_get_many_MODELs().

#define INC_MODEL_ARRAY   8
 

Definition at line 182 of file NLfit_model.h.

#define INIT_MODEL_ARRAY name   
 

Value:

do{ int iq ;                                                                  \
     (name)       = (NLFIT_MODEL_array *) malloc(sizeof(NLFIT_MODEL_array));  \
     (name)->num  = 0 ;                                                       \
     (name)->nall = INC_MODEL_ARRAY ;                                         \
     (name)->modar= (NLFIT_MODEL **)malloc(sizeof(NLFIT_MODEL*)*(name)->nall);\
     for (iq=(name)->num; iq < (name)->nall; iq++ ) (name)->modar[iq] = NULL; \
     } while(0)
"name" is a variable of type (NLFIT_MODEL_array *) *

Definition at line 186 of file NLfit_model.h.

Referenced by NLFIT_get_all_MODELs(), and NLFIT_get_many_MODELs().

#define ISVALID_DYNAMIC_handle handle       ((handle) != (DYNAMIC_handle) 0)
 

Definition at line 73 of file NLfit_model.h.

Referenced by NLFIT_read_MODEL(), and PLUG_read_plugin().

#define ISVALID_NLFIT_MODEL pl       ((pl)!=NULL && (pl)->type==NLFIT_MODEL_TYPE)
 

Definition at line 158 of file NLfit_model.h.

#define MAX_MODEL_NAME   128
 

Definition at line 160 of file NLfit_model.h.

Referenced by NLFIT_read_MODEL().

#define MAX_MODELS   100
 

Definition at line 126 of file NLfit_model.h.

#define MAX_NAME_LENGTH   80
 

Definition at line 124 of file NLfit_model.h.

#define MAX_PARAMETERS   100
 

Definition at line 125 of file NLfit_model.h.

#define MODEL_LABEL_strcpy mlab,
str   
 

Value:

do{ int ll=strlen((str)) , ii ;                                   \
       if( ll >= MAX_NAME_LENGTH ) ll = MAX_NAME_LENGTH - 1 ;    \
       for( ii=0 ; ii < ll ; ii++ ) (mlab)[ii] = (str)[ii] ;         \
       for( ; ii < MAX_NAME_LENGTH - 1 ; ii++ ) (mlab)[ii] = ' ' ; \
       mlab[MAX_NAME_LENGTH - 1] = '\0' ; } while(0)
macro to copy string into MODEL label array, filling with blanks or truncating length, as needed *

Definition at line 135 of file NLfit_model.h.

#define MODEL_NOISE_TYPE   0
 

Definition at line 129 of file NLfit_model.h.

Referenced by initialize_model(), initialize_noise_model(), and PLUGIN_init().

#define MODEL_SIGNAL_TYPE   1
 

Definition at line 130 of file NLfit_model.h.

Referenced by initialize_model(), initialize_signal_model(), and PLUGIN_init().

#define NLFIT_MODEL_TYPE   1066
 

Definition at line 157 of file NLfit_model.h.

Referenced by NLFIT_read_MODEL().


Typedef Documentation

typedef char* cptr_func()
 

Definition at line 60 of file NLfit_model.h.

Referenced by new_PLUGIN_interface(), and new_PLUGIN_interface_1999().

typedef void* DYNAMIC_handle
 

Definition at line 71 of file NLfit_model.h.

typedef int int_func()
 

Definition at line 58 of file NLfit_model.h.

Referenced by PLUTO_popup_dset_chooser().

typedef struct NLFIT_MODEL_array NLFIT_MODEL_array
 

typedef void(* vfp)()
 

Definition at line 49 of file NLfit_model.h.

Referenced by analyze_results(), calc_full_model(), calc_partial_derivatives(), calc_sse(), full_model(), generate_ts_array(), get_options(), initialize_noise_model(), initialize_options(), initialize_program(), initialize_signal_model(), initialize_simplex(), main(), nlfit(), RAN_setup(), random_search(), restart(), save_results(), and simplex_optimization().

typedef void* vptr_func()
 

Definition at line 59 of file NLfit_model.h.

Referenced by MCW_onen_i_estel_edain(), NLFIT_read_MODEL(), PLUG_read_plugin(), and RWC_forced_loads().


Function Documentation

NLFIT_MODEL_array* NLFIT_get_all_MODELs char *    dname
 

Definition at line 37 of file NLfit_model.c.

References ADDTO_MODEL_ARRAY, THD_string_array::ar, DESTROY_MODEL_ARRAY, DESTROY_SARR, DYNAMIC_suffix, INIT_MODEL_ARRAY, NLFIT_read_MODEL(), NLFIT_MODEL_array::num, THD_string_array::num, THD_extract_regular_files(), THD_get_all_filenames(), and THD_is_directory().

Referenced by NLFIT_get_many_MODELs().

00038 {
00039    THD_string_array * flist , * rlist ;
00040    int ir , ii ;
00041    char * fname , * suff ;
00042    NLFIT_MODEL_array * outar ;
00043    NLFIT_MODEL       * model ;
00044 
00045    /*----- sanity check and initialize -----*/
00046 
00047    if( dname == NULL || strlen(dname) == 0 )  return (NULL) ;
00048    if( ! THD_is_directory(dname) )            return (NULL) ;
00049 
00050    INIT_MODEL_ARRAY( outar ) ;
00051 
00052    if (NL_DEBUG)
00053      { 
00054        char str[256] ; 
00055        sprintf (str,"scanning directory %s \n",dname) ; 
00056        printf (str) ; 
00057      }
00058 
00059    /*----- find all filenames -----*/
00060 
00061    flist = THD_get_all_filenames( dname ) ;
00062    if( flist == NULL || flist->num <= 0 ){
00063       DESTROY_SARR(flist) ;
00064       DESTROY_MODEL_ARRAY(outar) ;
00065       return (NULL) ;
00066    }
00067 
00068    rlist = THD_extract_regular_files( flist ) ;
00069    DESTROY_SARR(flist) ;
00070    if( rlist == NULL || rlist->num <= 0 ){
00071       DESTROY_SARR(rlist) ;
00072       DESTROY_MODEL_ARRAY(outar) ;
00073       return (NULL) ;
00074    }
00075 
00076   if (NL_DEBUG)
00077     { 
00078       char str[256] ; 
00079       sprintf(str,"%d files to scan \n",rlist->num) ; 
00080       printf (str) ; 
00081     }
00082 
00083 
00084    /*----- scan thru and find all filenames ending in DYNAMIC_suffix -----*/
00085 
00086    for( ir=0 ; ir < rlist->num ; ir++ ){
00087       fname = rlist->ar[ir] ; if( fname == NULL ) continue ;
00088       if (strstr(fname, "model") == NULL)  continue;
00089 
00090       suff = strstr(fname,DYNAMIC_suffix) ;
00091       if( suff != NULL  &&  strlen(suff) == strlen(DYNAMIC_suffix)){
00092          model  = NLFIT_read_MODEL( fname ) ;
00093          if( model != NULL ) ADDTO_MODEL_ARRAY( outar , model ) ;
00094       }
00095    }
00096 
00097   if (NL_DEBUG)
00098     { 
00099       char str[256] ;
00100       sprintf (str,"directory %s has %d MODELs \n",dname,outar->num) ; 
00101       printf (str) ; 
00102     }
00103 
00104 
00105    DESTROY_SARR(rlist) ;
00106    if( outar->num == 0 ) DESTROY_MODEL_ARRAY(outar) ;
00107    return (outar) ;
00108 }

NLFIT_MODEL_array* NLFIT_get_many_MODELs void   
 

Definition at line 211 of file NLfit_model.c.

References ADDTO_MODEL_ARRAY, ADDTO_SARR, THD_string_array::ar, DESTROY_MODEL_ARRAY, DESTROY_SARR, FREE_MODEL_ARRAY, INIT_MODEL_ARRAY, INIT_SARR, NLFIT_MODEL_array::modar, my_getenv(), myXtFree, NLFIT_get_all_MODELs(), NLFIT_MODEL_array::num, THD_string_array::num, THD_equiv_files(), THD_is_directory(), THD_MAX_NAME, and XtMalloc.

Referenced by get_options(), and PLUGIN_init().

00212 {
00213    char * epath , * elocal , * eee ;
00214    char ename[THD_MAX_NAME] , efake[]="/usr/local/lib/afni:./" ;
00215    NLFIT_MODEL_array * outar , * tmpar ;
00216    int epos , ll , ii , id ;
00217    THD_string_array *qlist ;  /* 02 Feb 2002 */
00218 
00219    /*----- sanity checks -----*/
00220 
00221    epath = my_getenv("AFNI_MODELPATH") ;     /* get the path list to read from */
00222 
00223    if( epath == NULL )
00224       epath = my_getenv("AFNI_PLUGINPATH") ; /* try another name? */
00225 
00226    if( epath == NULL )
00227       epath = my_getenv("PATH") ;             /* try another name? */
00228 
00229    if( epath == NULL ) epath = efake ;     /* put in a fake path instead? */
00230 
00231    /*----- copy path list into local memory -----*/
00232 
00233    ll = strlen(epath) ;
00234    elocal = (char *) XtMalloc( sizeof(char) * (ll+2) ) ;
00235 
00236    /*----- put a blank at the end -----*/
00237 
00238    strcpy( elocal , epath ) ; elocal[ll] = ' ' ; elocal[ll+1] = '\0' ;
00239 
00240    /*----- replace colons with blanks -----*/
00241 
00242    for( ii=0 ; ii < ll ; ii++ )
00243       if( elocal[ii] == ':' ) elocal[ii] = ' ' ;
00244 
00245    if (NL_DEBUG)
00246      { 
00247        printf ("paths to be searched for MODELs follow:") ;
00248        printf("%s\n",elocal) ; 
00249        fflush(stdout) ; 
00250      }
00251 
00252 
00253    INIT_SARR(qlist) ; /* 02 Feb 2002: list of searched directories */
00254 
00255    /*----- extract blank delimited strings;
00256            use as directory names to get libraries -----*/
00257 
00258    INIT_MODEL_ARRAY( outar ) ;
00259    epos = 0 ;
00260 
00261    do{
00262       ii = sscanf( elocal+epos , "%s%n" , ename , &id ) ; /* next substring */
00263       if( ii < 1 || id < 1 ) break ;                     /* none --> end of work */
00264       epos += id ;                               /* char after last scanned */
00265 
00266       if( !THD_is_directory(ename) ) continue ;  /* 21 May 2002 - rcr */
00267 
00268       /* 02 Feb 2002: check if ename has already been checked */
00269 
00270       for( ii=0 ; ii < qlist->num ; ii++ )
00271          if( THD_equiv_files(qlist->ar[ii],ename) ) break ;
00272       if( ii < qlist->num ) continue ;
00273       ADDTO_SARR(qlist,ename) ;
00274 
00275       ii = strlen(ename) ;                           /* make sure name has */
00276       if( ename[ii-1] != '/' ){                     /* a trailing '/' on it */
00277         ename[ii]  = '/' ; ename[ii+1] = '\0' ; 
00278       }
00279 
00280       tmpar = NLFIT_get_all_MODELs( ename ) ;        /* read this directory */
00281       if( tmpar != NULL ){
00282          for( ii=0 ; ii < tmpar->num ; ii++ )     /* move results to output */
00283             ADDTO_MODEL_ARRAY( outar , tmpar->modar[ii] ) ;
00284 
00285          FREE_MODEL_ARRAY(tmpar) ;                      /* toss temp array */
00286       }
00287    } while( epos < ll ) ;  /* scan until 'epos' is after end of epath */
00288 
00289    myXtFree(elocal) ;
00290 
00291    if (NL_DEBUG)
00292      { 
00293        char str[256] ; 
00294        sprintf (str,"found %d MODELs \n",outar->num) ; 
00295        printf (str) ; 
00296      }
00297 
00298    if( outar->num == 0 ) DESTROY_MODEL_ARRAY(outar) ;
00299 
00300    DESTROY_SARR(qlist) ; /* 02 Feb 2002 */
00301    return (outar) ;
00302 }

NLFIT_MODEL* NLFIT_read_MODEL char *    fname
 

Definition at line 116 of file NLfit_model.c.

References DYNAMIC_CLOSE, DYNAMIC_ERROR_STRING, DYNAMIC_OPEN, DYNAMIC_SYMBOL, NLFIT_MODEL::interface, ISVALID_DYNAMIC_handle, MODEL_interface::label, NLFIT_MODEL::libhandle, NLFIT_MODEL::libinit_func, NLFIT_MODEL::libname, MAX_MODEL_NAME, MCW_strncpy, myXtFree, NLFIT_MODEL_TYPE, THD_is_file(), NLFIT_MODEL::type, vptr_func, and XtMalloc.

Referenced by NLFIT_get_all_MODELs().

00117 {
00118    NLFIT_MODEL * model ;
00119    static int firsterr=1 ;
00120 
00121    /*----- sanity checks -----*/
00122 
00123    if( fname == NULL || strlen(fname) == 0 )  return (NULL) ;
00124    if( ! THD_is_file(fname) )                 return (NULL) ;
00125 
00126    /*----- make space for new MODEL -----*/
00127 
00128    model = (NLFIT_MODEL *) XtMalloc( sizeof(NLFIT_MODEL) ) ;
00129    model->type = NLFIT_MODEL_TYPE ;
00130 
00131    /*----- copy name into model structure -----*/
00132 
00133    MCW_strncpy( model->libname , fname , MAX_MODEL_NAME ) ;
00134 
00135    /*----- open the library (we hope) -----*/
00136 
00137    DYNAMIC_OPEN( fname , model->libhandle ) ;
00138    if( ! ISVALID_DYNAMIC_handle( model->libhandle ) ){
00139       char *er ;
00140       if( firsterr ){ fprintf(stderr,"\n"); firsterr=0; }
00141       fprintf (stderr,"failed to open library %s ",fname); 
00142       er = (char *)DYNAMIC_ERROR_STRING ;
00143       if( er != NULL ) fprintf(stderr," -- %s\n",er) ;
00144       else             fprintf(stderr,"\n") ;
00145       myXtFree(model) ;
00146       return (NULL) ;
00147    }
00148 
00149    if (NL_DEBUG)
00150      { 
00151        char str[256] ;
00152        sprintf (str,"opened library %s with handle %p \n" , 
00153                fname,model->libhandle ) ;
00154        printf (str) ; 
00155      }
00156 
00157 
00158    /*----- find the required symbols -----*/
00159    /*..... 13 Sep 2001: add _ for Mac OS X [RWCox] .....*/
00160    /*..... 30 Oct 2003: remove it for OS X 10.3    .....*/
00161 
00162 #ifndef NEED_UNDERSCORE
00163    DYNAMIC_SYMBOL(model->libhandle, "initialize_model" , 
00164                   model->libinit_func );
00165 #else
00166    DYNAMIC_SYMBOL(model->libhandle, "_initialize_model" , 
00167                   model->libinit_func );
00168 #endif
00169 
00170    /*----- if symbols not found, complain and kill this MODEL -----*/
00171 
00172    if( model->libinit_func == (vptr_func *) NULL ){
00173       char *er = (char *)DYNAMIC_ERROR_STRING ;
00174       if( firsterr ){ fprintf(stderr,"\n"); firsterr=0; }
00175       fprintf(stderr,"model %s lacks initialize_model() function\n",fname) ;
00176       if( er != NULL ) fprintf(stderr," -- %s\n",er) ;
00177       DYNAMIC_CLOSE( model->libhandle ) ;
00178       myXtFree(model) ;
00179       return (NULL) ;
00180    }
00181 
00182    /*----- create interface(s) by calling initialization function -----*/
00183 
00184    model->interface = (MODEL_interface *) model->libinit_func() ;
00185    if( model->interface == NULL ) 
00186      {
00187        DYNAMIC_CLOSE( model->libhandle ) ;
00188        myXtFree(model) ;
00189        return (NULL) ;
00190      }
00191 
00192    if (NL_DEBUG)
00193      { 
00194        char str[256] ;
00195        sprintf (str,"Interface created for %s model\n",
00196                 model->interface->label) ; 
00197        printf (str) ; 
00198      }
00199 
00200    /*----- done -----*/
00201 
00202    return (model) ;
00203 }

vptr_func* RWC_forced_loads int    n
 

Definition at line 250 of file NLfit_model.h.

References NL_forced_loads, and vptr_func.

00250                                    {  /* this function is to try to ensure   */
00251   return NL_forced_loads[n] ;         /* that the array isn't optimized away */
00252 }

Variable Documentation

vptr_func* NL_forced_loads[] [static]
 

Initial value:

 {
   (vptr_func *) mri_read_ascii ,
   (vptr_func *) mri_to_float ,
   (vptr_func *) mri_transpose ,
   (vptr_func *) mri_free ,
NULL }

Definition at line 243 of file NLfit_model.h.

Referenced by RWC_forced_loads().

 

Powered by Plone

This site conforms to the following standards: