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
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 ;
00041
00042
00043
00044
00045
00046
00047
00048
00049 typedef void (*vfp)();
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() ;
00059 typedef void * vptr_func() ;
00060 typedef char * cptr_func() ;
00061
00062
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()
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
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)
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
00121
00122
00123
00124 #define MAX_NAME_LENGTH 80
00125 #define MAX_PARAMETERS 100
00126 #define MAX_MODELS 100
00127
00128
00129 #define MODEL_NOISE_TYPE 0
00130 #define MODEL_SIGNAL_TYPE 1
00131
00132
00133
00134
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];
00145 int model_type;
00146 int params;
00147 char plabel[MAX_PARAMETERS][MAX_NAME_LENGTH];
00148 float min_constr[MAX_PARAMETERS];
00149 float max_constr[MAX_PARAMETERS];
00150 void_func * call_func ;
00151 } MODEL_interface ;
00152
00153
00154
00155
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
00163
00164 typedef struct {
00165 int type ;
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
00174
00175 typedef struct NLFIT_MODEL_array {
00176 int num , nall ;
00177 NLFIT_MODEL ** modar ;
00178 } NLFIT_MODEL_array ;
00179
00180
00181
00182 #define INC_MODEL_ARRAY 8
00183
00184
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
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
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
00219
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
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
00237
00238
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){
00251 return NL_forced_loads[n] ;
00252 }
00253
00254 #endif
00255
00256
00257
00258
00259 #endif
00260
00261