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  

niml.h

Go to the documentation of this file.
00001 #ifndef _NIML_HEADER_FILE_
00002 #define _NIML_HEADER_FILE_
00003 
00004 #include <stddef.h>
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <unistd.h>
00008 #include <ctype.h>
00009 #include <errno.h>
00010 #include <sys/types.h>
00011 #include <sys/stat.h>
00012 #include <unistd.h>
00013 #include <string.h>
00014 #include <sys/socket.h>
00015 #include <netinet/in.h>
00016 #ifndef TCP_NODELAY
00017 # include <netinet/tcp.h>
00018 #endif
00019 #include <netdb.h>
00020 #include <arpa/inet.h>
00021 #include <sys/time.h>
00022 #include <fcntl.h>
00023 #include <sys/times.h>
00024 #include <limits.h>
00025 
00026 /*****---------------------------------------------------*****/
00027 
00028 /* This is suppose to be defined in stddef.h, but
00029    apparently it isn't on all systems for some reason. */
00030 
00031 #ifndef offsetof
00032 # define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
00033 #endif
00034 
00035 /*****---------------------------------------------------*****/
00036 
00037 #ifndef TYPEDEF_byte
00038 #define TYPEDEF_byte
00039 typedef unsigned char byte ;
00040 #endif
00041 
00042 #ifndef TYPEDEF_rgb
00043 #define TYPEDEF_rgb
00044 typedef struct { byte r,g,b ; } rgb ;
00045 #endif
00046 
00047 #ifndef TYPEDEF_rgba
00048 #define TYPEDEF_rgba
00049 typedef struct { byte r,g,b,a ; } rgba ;
00050 #endif
00051 
00052 #ifdef _SUNPERF_COMPLEX
00053 # define TYPEDEF_complex
00054 #endif
00055 
00056 #ifndef TYPEDEF_complex
00057 #define TYPEDEF_complex
00058 typedef struct { float r,i ; } complex ;
00059 #endif
00060 
00061 /*****---------------------------------------------------*****/
00062 
00063 /***** Macros for data type codes. *****/
00064 /*---- The first 8 match mrilib.h. ----*/
00065 
00066 #define NI_BYTE        0               /* == MRI_byte    */
00067 #define NI_SHORT       1               /* == MRI_short   */
00068 #define NI_INT         2               /* == MRI_int     */
00069 #define NI_FLOAT32     3               /* == MRI_float   */
00070 #define NI_FLOAT       NI_FLOAT32
00071 #define NI_FLOAT64     4               /* == MRI_double  */
00072 #define NI_DOUBLE      NI_FLOAT64
00073 #define NI_COMPLEX64   5               /* == MRI_complex */
00074 #define NI_COMPLEX     NI_COMPLEX64
00075 #define NI_RGB         6               /* == MRI_rgb     */
00076 #define NI_RGBA        7               /* == MRI_rgba    */
00077 
00078 #define NI_IS_NUMERIC_TYPE(t) ( (t) >= 0 && (t) <= NI_RGBA )
00079 
00080 #define NI_STRING      8               /* after "basic" types */
00081 
00082 /*! One more than the last NI_ data type code defined above. */
00083 
00084 #define NI_NUM_TYPES        9
00085 
00086 /*! Number of types of fixed size ("basic" types).
00087     Note that if this changes,
00088     the NI_rowtype stuff must be altered accordingly. */
00089 
00090 #define NI_NUM_BASIC_TYPES  8
00091 
00092 /*! Valid data type character codes. */
00093 
00094 #define IS_DATUM_CHAR(c) ( (c) == 'b' || (c) == 's' || (c) == 'i' ||  \
00095                            (c) == 'f' || (c) == 'd' || (c) == 'c' ||  \
00096                            (c) == 'r' || (c) == 'S' || (c) == 'L' ||  \
00097                            (c) == 'R'                               )
00098 
00099 #define NI_is_builtin_type(t)                                         \
00100   ( (t) >= 0 && (t) < NI_NUM_TYPES )
00101 
00102 #define NI_is_basic_type(t)                                           \
00103   ( (t) >= 0 && (t) < NI_NUM_BASIC_TYPES )
00104 
00105 /*--------------------------------------------------------------------------*/
00106 /*! This type stores the information about user-defined types. 09 Dec 2002. */
00107 
00108 #ifndef TYPEDEF_NI_rowtype
00109 #define TYPEDEF_NI_rowtype
00110 struct NI_rowtype ;  /* incomplete definition */
00111 
00112 typedef struct NI_rowtype {
00113   int   code ;         /*!< unique integer code for this type */
00114   int   size ;         /*!< number of bytes for this type (w/padding) */
00115   int   psiz ;         /*!< sum of sizes of the parts (no padding)
00116                             - will be zero if has variable type arrays */
00117   int   algn ;         /*!< byte alignment for this type */
00118   int   flag ;         /*!< various bit flags */
00119   char *name ;         /*!< unique string name for this type */
00120   char *userdef ;      /*!< definition user gave for this type */
00121   int   comp_num ;     /*!< number of components (components may be rowtypes) */
00122   int  *comp_typ ;     /*!< integer codes of the components */
00123   int  *comp_dim ;     /*!< if >=0, index of dimension of this component */
00124   int   part_num ;     /*!< number of parts (parts are usually basic types) */
00125   int  *part_typ ;     /*!< integer codes of the parts */
00126   int  *part_off ;     /*!< byte offsets of the parts */
00127   int  *part_siz ;     /*!< byte sizes of the parts */
00128   int  *part_dim ;     /*!< if >=0, index of dimension of this part */
00129 
00130   struct NI_rowtype **part_rtp; /*!< rowtype ptr for each part;
00131                                      N.B.: builtin types point to themselves! */
00132 } NI_rowtype ;
00133 #endif
00134 
00135 /*! NI_rowtype bit flag for variable size data. */
00136 
00137 #define ROWTYPE_VARSIZE_MASK (1<<0)
00138 
00139 /*! Check if a NI_rowtype struct is marked as having variable size data */
00140 
00141 #define ROWTYPE_is_varsize(rr) (((rr)->flag & ROWTYPE_VARSIZE_MASK) != 0)
00142 
00143 /*! Get the dimension of the qq-th part of
00144     the struct stored at pointer pt, of type rt.
00145     This macro should only be used if rt->part_dim[qq] >= 0. */
00146 
00147 #define ROWTYPE_part_dimen(rt,pt,qq)                           \
00148  ( *((int *)( (pt) + (rt)->part_off[ (rt)->part_dim[qq] ] )) )
00149 
00150 /*! Macro to delete a NI_rowtype struct.  Only used when an
00151     error happens when creating one, since new types last forever. */
00152 
00153 #define delete_rowtype(rr)                 \
00154  do{ NI_free((rr)->name)     ;             \
00155      NI_free((rr)->userdef)  ;             \
00156      NI_free((rr)->comp_typ) ;             \
00157      NI_free((rr)->part_typ) ;             \
00158      NI_free((rr)->part_off) ;             \
00159      NI_free(rr)             ; } while(0)
00160 
00161 extern int          NI_rowtype_define       ( char *, char * ) ;
00162 extern NI_rowtype * NI_rowtype_find_name    ( char * ) ;
00163 extern NI_rowtype * NI_rowtype_find_code    ( int ) ;
00164 extern int          NI_rowtype_name_to_code ( char * ) ;
00165 extern char *       NI_rowtype_code_to_name ( int ) ;
00166 extern char *       NI_rowtype_code_to_alias( int ) ;    /* 19 Feb 2003 */
00167 extern int          NI_rowtype_name_to_size ( char * ) ;
00168 extern int          NI_rowtype_code_to_size ( int ) ;
00169 
00170 extern int          NI_rowtype_vsize     ( NI_rowtype *, void * ) ;
00171 extern void         NI_val_to_text       ( NI_rowtype *, char *, char * ) ;
00172 extern int          NI_val_to_binary     ( NI_rowtype *, char *, char * ) ;
00173 extern void         NI_multival_to_text  ( NI_rowtype *, int, char *, char * );
00174 extern int          NI_multival_to_binary( NI_rowtype *, int, char *, char * );
00175 extern int          NI_has_String        ( NI_rowtype * ) ;
00176 extern void         NI_swap_column       ( NI_rowtype * , int , char * ) ;
00177 
00178 extern void         NI_rowtype_debug( int ) ;
00179 
00180 /*! Used to test if a rowtype code is a basic type. */
00181 
00182 #define ROWTYPE_is_basic_code  NI_is_basic_type
00183 
00184 /*! Integer type code to name string. */
00185 
00186 extern char * NI_type_name( int ) ;
00187 
00188 /*****------------------------------------------------------------------*****/
00189 
00190 #define NI_ELEMENT_TYPE  17
00191 #define NI_GROUP_TYPE    18
00192 #define NI_PROCINS_TYPE  19
00193 
00194 /*! A data element. */
00195 
00196 #ifndef TYPEDEF_NI_element
00197 #define TYPEDEF_NI_element
00198 typedef struct {
00199    int    type ;       /*!< What type of struct is this? */
00200    int    outmode ;    /*!< If >=0, output mode. */
00201    char  *name ;       /*!< Name of element. */
00202    int    attr_num ;   /*!< Number of attributes. */
00203    char **attr_lhs ;   /*!< Left-hand-sides of attributes. */
00204    char **attr_rhs ;   /*!< Right-hand-sides of attributes. */
00205    int    vec_num ;    /*!< Number of vectors (may be 0). */
00206    int    vec_len ;    /*!< Length of each vector. */
00207    int    vec_filled ; /*!< Length that each one was filled up. */
00208    int   *vec_typ ;    /*!< Type code for each vector. */
00209    void **vec ;        /*!< Pointer to each vector. */
00210 
00211    int    vec_rank ;        /*!< Number of dimensions, from ni_dimen. */
00212    int   *vec_axis_len ;    /*!< Array of dimensions, from ni_dimen. */
00213    float *vec_axis_delta ;  /*!< Array of step sizes, from ni_delta. */
00214    float *vec_axis_origin ; /*!< Array of origins, from ni_origin. */
00215    char **vec_axis_unit ;   /*!< Array of units, from ni_units. */
00216    char **vec_axis_label ;  /*!< Array of labels, from ni_axes. */
00217 } NI_element ;
00218 #endif
00219 
00220 /*! A bunch of elements. */
00221 
00222 #ifndef TYPEDEF_NI_group
00223 #define TYPEDEF_NI_group
00224 typedef struct {
00225    int    type ;       /*!< What type of struct is this? */
00226    int    outmode ;    /*!< If >=0, output mode. */
00227    int    attr_num ;   /*!< Number of attributes. */
00228    char **attr_lhs ;   /*!< Left-hand-sides of attributes. */
00229    char **attr_rhs ;   /*!< Right-hand-sides of attributes. */
00230 
00231    int    part_num ;   /*!< Number of parts within this group. */
00232    int   *part_typ ;   /*!< Type of each part (element or group). */
00233    void **part ;       /*!< Pointer to each part. */
00234 
00235    char  *name ;       /*!< Name (default="ni_group") - 03 Jun 2002 */
00236 } NI_group ;
00237 #endif
00238 
00239 /*! A processing instruction. */
00240 
00241 #ifndef TYPEDEF_NI_procins
00242 #define TYPEDEF_NI_procins
00243 typedef struct {
00244    int    type ;       /*!< What type of struct is this? */
00245    int    attr_num ;   /*!< Number of attributes. */
00246    char **attr_lhs ;   /*!< Left-hand-sides of attributes. */
00247    char **attr_rhs ;   /*!< Right-hand-sides of attributes. */
00248    char  *name ;       /*!< The 'PItarget', as in '<?name ...?>' */
00249 } NI_procins ;
00250 #endif
00251 
00252 extern NI_procins * NI_rowtype_procins( NI_rowtype * ) ; /* 19 Apr 2005 */
00253 
00254 /*-----------------------------------------------------------------
00255   Stuff for shared memory transport between processes
00256 -------------------------------------------------------------------*/
00257 
00258 #ifdef CYGWIN
00259 # define DONT_USE_SHM
00260 #endif
00261 
00262 #ifndef DONT_USE_SHM
00263 # include <sys/ipc.h>
00264 # include <sys/shm.h>
00265 
00266 # define SHM_WAIT_CREATE   9
00267 # define SHM_WAIT_ACCEPT  10
00268 # define SHM_IS_DEAD      99
00269 
00270 # define SHM_CREATOR      33
00271 # define SHM_ACCEPTOR     44
00272 
00273 # define SHM_DEFAULT_SIZE 196689
00274 
00275 # define SHM_HSIZE        128  /* header size in bytes    */
00276 # define SHM_SIZE1        0    /* size1   = shmhead[this] */
00277 # define SHM_BSTART1      1    /* bstart1 = shmhead[this] */
00278 # define SHM_BEND1        2    /* bend1   = shmhead[this] */
00279 # define SHM_SIZE2        3
00280 # define SHM_BSTART2      4
00281 # define SHM_BEND2        5
00282 
00283  /**
00284    The shm segment is split into a 128 byte header and 2 buffers:
00285      buf1 is written into by the "w" creator and read by the "r" acceptor;
00286      buf2 is written into by the "r" acceptor and read by the "w" creator.
00287    Each of these is a circular buffer, as described below.
00288    The header currently contains 6 ints.  For buf1:
00289      size1   = size of buf1 in bytes (fixed by creator)
00290      bstart1 = offset into buf1 where good data starts (changed by acceptor)
00291      bend1   = offset into buf1 where good data ends (changed by creator)
00292    For buf2, a similar triple is set (mutatis mutandum).
00293  **/
00294 
00295  typedef struct {
00296    int id ;          /* shmid */
00297    int bad ;         /* tells whether I/O is OK for this yet */
00298    int whoami ;      /* SHM_CREATOR or SHM_ACCEPTOR? */
00299 
00300    char name[128] ;  /* keystring */
00301 
00302    char * shmbuf ;   /* actual shm buffer */
00303    int  * shmhead ;  /* buffer as ints */
00304 
00305    int bufsize1 ;    /* size of 1st internal buffer */
00306    char * buf1 ;     /* 1st internal buffer [after header] */
00307    int  * bstart1 ;
00308    int  * bend1 ;
00309 
00310    int bufsize2 ;    /* size of 2nd internal buffer */
00311    char * buf2 ;     /* 2nd internal buffer [after buf1] */
00312    int  * bstart2 ;
00313    int  * bend2 ;
00314 
00315    int goodcheck_time ;   /*!< NI_clock_time() of last SHM_goodcheck() */
00316  } SHMioc ;
00317 
00318 #else  /* DONT_USE_SHM */
00319 
00320 # define SHMioc void  /* dummy definition */
00321 
00322 #endif /* DONT_USE_SHM */
00323 /*-----------------------------------------------------------------*/
00324 
00325 /*! Size of NI_stream buffer. */
00326 
00327 #define NI_BUFSIZE (31*1024)
00328 
00329 /*! Data needed to process input stream. */
00330 
00331 #ifndef TYPEDEF_NI_stream_type
00332 #define TYPEDEF_NI_stream_type
00333 typedef struct {
00334    int type ;        /*!< NI_TCP_TYPE, NI_FILE_TYPE, etc. */
00335    int bad ;         /*!< Tells whether I/O is OK for this yet */
00336 
00337    int port ;        /*!< TCP only: port number */
00338    int sd ;          /*!< TCP only: socket descriptor */
00339 
00340    FILE *fp ;        /*!< FILE only: pointer to open file */
00341    int fsize ;       /*!< FILE only: length of file for input */
00342 
00343    char name[256] ;  /*!< Hostname or filename */
00344 
00345    int io_mode ;     /*!< Input or output? */
00346    int data_mode ;   /*!< Text, binary, or base64? */
00347 
00348    int bin_thresh ;  /*!< Threshold size for binary write. */
00349 
00350    int nbuf ;             /*!< Number of bytes left in buf. */
00351    int npos ;             /*!< Index of next unscanned byte in buf. */
00352    int bufsize ;          /*!< Length of buf array. */
00353    char *buf ;            /*!< I/O buffer (may be NULL). */
00354 
00355    SHMioc *shmioc ;       /*!< for NI_SHM_TYPE only */
00356 
00357    char orig_name[256] ;  /*!< original (input) name when opened */
00358 
00359    int goodcheck_time ;   /*!< NI_clock_time() of last NI_stream_goodcheck() */
00360 
00361    int b64_numleft ;      /*!< For use in NI_stream_readbuf64() */
00362    byte b64_left[4] ;     /*!< Leftover decoded bytes from NI_stream_readbuf64() */
00363 } NI_stream_type ;
00364 #endif
00365 
00366 /*! Opaque type for the C API. */
00367 
00368 #ifndef TYPEDEF_NI_stream
00369 #define TYPEDEF_NI_stream
00370 typedef NI_stream_type *NI_stream ;
00371 #endif
00372 
00373 #define NI_TCP_TYPE    1  /* tcp: */
00374 #define NI_FILE_TYPE   2  /* file: */
00375 #define NI_STRING_TYPE 3  /* str: */
00376 #define NI_REMOTE_TYPE 4  /* http: or ftp: */
00377 #define NI_FD_TYPE     5  /* fd: */
00378 #define NI_SHM_TYPE    6  /* shm: */
00379 
00380 #define TCP_WAIT_ACCEPT   7
00381 #define TCP_WAIT_CONNECT  8
00382 
00383 #define MARKED_FOR_DEATH  6666
00384 
00385 /* I/O Modes for a NI_stream_type: input or output. */
00386 
00387 #define NI_INPUT_MODE  0
00388 #define NI_OUTPUT_MODE 1
00389 
00390 /* Data modes for a NI_stream_type: text, binary, base64. */
00391 
00392 #define NI_TEXT_MODE    0
00393 #define NI_BINARY_MODE  1
00394 #define NI_BASE64_MODE  2
00395 
00396 #define NI_HEADERONLY_FLAG  (1<<8)  /* 20 Feb 2003 */
00397 #define NI_HEADERSHARP_FLAG (1<<9)  /* 20 Mar 2003 */
00398 
00399 #define NI_LSB_FIRST    1
00400 #define NI_MSB_FIRST    2
00401 
00402 /* Attribute writing modes [15 Oct 2002] */
00403 
00404 #define NI_ATTMODE_NORMAL 0
00405 #define NI_ATTMODE_SPACED 1
00406 #define NI_ATTMODE_LAST   1
00407 
00408 extern void NI_set_attribute_mode( int ) ;
00409 
00410 /* Type name writing modes [19 Feb 2003] */
00411 
00412 #define NI_NAMEMODE_NORMAL 0
00413 #define NI_NAMEMODE_ALIAS  1
00414 #define NI_NAMEMODE_LAST   1
00415 
00416 extern void NI_set_typename_mode ( int ) ;
00417 
00418 /*****---------- Hash table stuff [26 Aug 2002] ----------*****/
00419 
00420 #ifndef TYPEDEF_Htable
00421 #define TYPEDEF_Htable
00422 typedef struct {
00423   int     len , ntot ;
00424   void ***vtab ;             /* pointers */
00425   char ***ctab ;             /* digests */
00426   int    *ntab ;             /* counts */
00427 } Htable ;
00428 #endif
00429 
00430 extern Htable * new_Htable( int ) ;
00431 extern void     destroy_Htable( Htable * ) ;
00432 extern void     addto_Htable( char *, void *, Htable * ) ;
00433 extern void *   findin_Htable( char *, Htable * ) ;
00434 extern void     removefrom_Htable( char *, Htable * ) ;
00435 extern void     profile_Htable( char *, Htable * ) ;
00436 extern void     subsume_Htable( Htable *, Htable * ) ;
00437 extern void     Htable_set_vtkill( int ) ;
00438 extern void     resize_Htable( int , Htable * ) ;
00439 
00440 #define         sizeof_Htable(ht) ((ht)->ntot)
00441 
00442 /*--- double Htable (string-string pairs) [15 Oct 2003] ---*/
00443 
00444 #ifndef TYPEDEF_Dtable
00445 #define TYPEDEF_Dtable
00446 typedef struct { Htable *hta, *htb ; } Dtable ;
00447 #endif
00448 
00449 extern Dtable * new_Dtable( int ) ;
00450 extern void     destroy_Dtable( Dtable * ) ;
00451 extern void     addto_Dtable( char *, char *, Dtable * ) ;
00452 extern char *   findin_Dtable_a( char *, Dtable * ) ;
00453 extern char *   findin_Dtable_b( char *, Dtable * ) ;
00454 extern void     removefrom_Dtable_a( char *, Dtable * ) ;
00455 extern void     removefrom_Dtable_b( char *, Dtable * ) ;
00456 extern int      listize_Dtable( Dtable *, char ***, char *** ) ;
00457 extern char *   Dtable_to_nimlstring( Dtable * , char * ) ;
00458 extern Dtable * Dtable_from_nimlstring( char * ) ;
00459 
00460 /*****------------------- DIME stuff [04 Nov 2002] ------------------*****/
00461 
00462 #ifndef TYPEDEF_DIME_part
00463 #define TYPEDEF_DIME_part
00464 typedef struct {
00465    int          type ;
00466    int          flags ;
00467    char        *id_string ;
00468    char        *type_string ;
00469    unsigned int data_len ;
00470    byte        *data ;
00471 } DIME_part ;
00472 #endif
00473 
00474 #ifndef TYPEDEF_DIME_message
00475 #define TYPEDEF_DIME_message
00476 typedef struct {
00477    int         num_part ;
00478    DIME_part **part ;
00479 } DIME_message ;
00480 #endif
00481 
00482 #define DIME_MB_MASK      (1<<0)
00483 #define DIME_ME_MASK      (1<<1)
00484 #define DIME_CF_MASK      (1<<2)
00485 
00486 #define DIME_VERSION_MASK (0xf8)
00487 
00488 DIME_message * DIME_read_message( NI_stream_type * , int ) ;
00489 DIME_part    * DIME_read_part   ( NI_stream_type * , int ) ;
00490 
00491 void           DIME_destroy_message( DIME_message * ) ;
00492 
00493 /*****------------------------- prototypes -------------------------*****/
00494 
00495 /** 18 Nov 2002: replace old malloc functions with new ones **/
00496 
00497 #undef NIML_OLD_MALLOC
00498 #if (defined(NIML_OLD_MALLOC) || defined(DONT_USE_MCW_MALLOC)) && !defined(__cplusplus) && !defined(c_plusplus)
00499 #define NI_malloc(typ,a) (typ*) old_NI_malloc((a))
00500 #define NI_realloc(a,typ,b)  (typ*) old_NI_realloc((a),(b))
00501 
00502   extern void * old_NI_malloc( size_t ) ;
00503   extern void   NI_free( void * ) ;
00504   extern void * old_NI_realloc( void *, size_t ) ;
00505 #else
00506 #  define NI_malloc(typ,a)   (typ*) hidden_NI_malloc((a),__FILE__,__LINE__)
00507 #  define NI_calloc(a,b)   hidden_NI_malloc((a)*(b),__FILE__,__LINE__)
00508 #  define NI_realloc(a,typ,b) (typ*) hidden_NI_realloc((a),(b),__FILE__,__LINE__)
00509 #  define NI_free(a)       hidden_NI_free((a),__FILE__,__LINE__)
00510 
00511   extern void * hidden_NI_malloc( size_t , char * , int ) ;
00512   extern void * hidden_NI_realloc( void * , size_t , char * , int ) ;
00513   extern void   hidden_NI_free( void * , char * , int ) ;
00514 #endif
00515 
00516 extern char * NI_malloc_status(void) ;
00517 extern void NI_malloc_dump(void) ;
00518 extern void NI_malloc_enable_tracking(void) ;
00519 extern int NI_malloc_tracking_enabled(void) ;
00520 
00521 extern int NI_malloc_replace( void *(*um)(size_t)        ,
00522                               void *(*ur)(void *,size_t) ,
00523                               void  (*uf)(void *)         ) ;
00524 
00525 /*! Free and set pointer to NULL. */
00526 #define NI_FREE(p) ( NI_free(p), (p)=NULL )
00527 
00528 /*! Make a new block of a given type. */
00529 
00530 /* #define NI_new(typ) ( (typ *)NI_malloc(sizeof(typ)) )   09 Dec 2002 */
00531 #define NI_new(typ) ( NI_malloc(typ, sizeof(typ)) )   /* 15 Dec 2003 */
00532 
00533 extern char * NI_strncpy( char *, const char *, size_t ) ;
00534 extern char * NI_strdup( char * ) ;
00535 extern int    NI_strlen( char * ) ;
00536 extern long   NI_filesize( char * ) ;
00537 extern int    NI_clock_time(void) ;
00538 extern int    NI_byteorder(void) ;
00539 extern void   NI_swap2( int, void * ) ;
00540 extern void   NI_swap4( int, void * ) ;
00541 extern void   NI_swap8( int, void * ) ;
00542 
00543 #define NI_is_file(pn) (NI_filesize(pn) >= 0)   /* 10 Dec 2002 */
00544 
00545 extern char * NI_mktemp( char * ) ;  /* 21 Aug 2002 */
00546 
00547 extern int    NI_type_size( int ) ;
00548 
00549 extern int NI_element_rowsize( NI_element * ) ;
00550 extern int NI_element_allsize( NI_element * ) ;
00551 
00552 extern void NI_free_element( void * ) ;
00553 extern int  NI_element_type( void * ) ;
00554 extern char * NI_element_name( void * ) ;  /* 18 Apr 2005 */
00555 
00556 extern NI_element * NI_new_data_element( char *, int ) ;
00557 extern void NI_add_column( NI_element *, int, void * ) ;
00558 extern void NI_set_attribute( void *, char *, char * ) ;
00559 extern char * NI_get_attribute( void *, char * ) ;
00560 extern void NI_insert_value( NI_element *, int,int, void * );       /* 03 Apr 2003 */
00561 extern void NI_add_column_stride( NI_element *, int, void *, int ); /* 29 May 2003 */
00562 extern void NI_fill_column_stride( NI_element *,int,void *,int,int);/* 23 Mar 2004 */
00563 extern void NI_insert_string( NI_element *, int,int, char *);       /* 19 Apr 2005 */
00564 extern void NI_alter_veclen( NI_element * , int ) ;                 /* 19 Apr 2005 */
00565 
00566 extern NI_group * NI_new_group_element(void) ;
00567 extern void NI_add_to_group( NI_group *, void * ) ;
00568 extern void NI_rename_group( NI_group *, char * ) ;                 /* 03 Jun 2002 */
00569 extern void NI_remove_from_group( NI_group *, void * ) ;            /* 16 Apr 2005 */
00570 
00571 extern int NI_search_group_shallow( NI_group *, char *, void *** ); /* 18 Apr 2005 */
00572 extern int NI_search_group_deep   ( NI_group *, char *, void *** ); /* 18 Apr 2005 */
00573 
00574 extern NI_procins * NI_new_processing_instruction( char * ) ;       /* 16 Mar 2005 */
00575 
00576 extern void NI_swap_vector( int, int, void * ) ;
00577 
00578 /** I/O functions **/
00579 
00580 extern NI_stream NI_stream_open( char *, char * ) ;
00581 extern int NI_stream_goodcheck( NI_stream_type *, int ) ;
00582 extern void NI_stream_close( NI_stream_type * ) ;
00583 extern void NI_stream_kill ( NI_stream_type * ) ;      /* 02 Jan 2004 */
00584 extern void NI_stream_closenow( NI_stream_type * ) ;   /* 02 Jan 2004 */
00585 extern int NI_stream_readcheck( NI_stream_type *, int  ) ;
00586 extern int NI_stream_writecheck( NI_stream_type *, int  ) ;
00587 extern int NI_stream_write( NI_stream_type *, char *, int ) ;
00588 extern int NI_stream_read( NI_stream_type *, char *, int ) ;
00589 extern void NI_binary_threshold( NI_stream_type *, int ) ;
00590 extern void NI_sleep( int ) ;
00591 extern char * NI_stream_getbuf( NI_stream_type * ) ;
00592 extern void   NI_stream_clearbuf( NI_stream_type * ) ;
00593 extern void   NI_stream_setbuf( NI_stream_type *, char * ) ;
00594 extern char * NI_stream_name( NI_stream_type * ) ;
00595 extern int NI_stream_readable( NI_stream_type * ) ;
00596 extern int NI_stream_writeable( NI_stream_type * ) ;
00597 extern int NI_stream_hasinput( NI_stream_type * , int ) ;
00598 extern void NI_stream_seek( NI_stream_type * , int , int ) ; /* 24 Mar 2003 */
00599 extern int NI_stream_writestring( NI_stream_type * , char * ) ;
00600 
00601 extern int NI_stream_setbufsize( NI_stream_type *, int ) ; /* 03 Jan 2003 */
00602 extern int NI_stream_getbufsize( NI_stream_type * ) ;
00603 extern int NI_stream_readbuf( NI_stream_type *, char *, int ) ;
00604 extern int NI_stream_readbuf64( NI_stream_type *, char *, int ) ;  /* 20 Apr 2005 */
00605 extern int NI_text_to_val  ( NI_stream_type *, NI_rowtype *, void *, int );
00606 extern int NI_binary_to_val( NI_stream_type *, NI_rowtype *, void *, int );
00607 extern int NI_base64_to_val( NI_stream_type *, NI_rowtype *, void *, int );
00608 
00609 extern int NI_stream_setb64( NI_stream_type * , int ) ;   /* 20 Apr 2005 */
00610 
00611 extern int NI_stream_reopen( NI_stream_type *, char * ) ; /* 23 Aug 2002 */
00612 
00613 extern void NI_binary_threshold( NI_stream_type *, int ) ;
00614 
00615 extern void * NI_read_element ( NI_stream_type *, int ) ;
00616 extern int    NI_write_element( NI_stream_type *, void *, int ) ;
00617 extern int    NI_write_procins( NI_stream_type *, char * ) ; /* 17 Mar 2005 */
00618 extern int    NI_write_columns( NI_stream_type * ,
00619                                 int , int * , int , void ** , int ) ;
00620 extern int    NI_write_rowtype( NI_stream_type * ,
00621                                 NI_rowtype * , int , void * , int ) ;
00622 extern int    NI_read_columns ( NI_stream_type *,
00623                                 int, int *, int, void **, int,int ) ;
00624 extern void   NI_free_column  ( NI_rowtype * , int , void * );
00625 extern void * NI_copy_column  ( NI_rowtype * , int , void * );
00626 extern int    NI_size_column  ( NI_rowtype * , int , void * ); /* 26 Mar 2003 */
00627 
00628 extern void   NI_read_header_only   ( int ) ;                  /* 21 Mar 2003 */
00629 extern void * NI_read_element_header( NI_stream_type *, int ); /* 26 Mar 2003 */
00630 extern void   NI_skip_procins( int ) ;                         /* 03 Jun 2005 */
00631 
00632 #define NI_SWAP_MASK  (1<<0)
00633 #define NI_LTEND_MASK (1<<1)
00634 
00635 /* prototypes for Web data fetchers */
00636 
00637 extern int  NI_read_URL_tmpdir( char *url, char **tname ) ;
00638 extern int  NI_read_URL       ( char *url, char **data  ) ;
00639 extern void NI_set_URL_ftp_ident( char *name, char *pwd ) ;
00640 
00641 /* prototypes for Base64 and MD5 functions */
00642 
00643 extern void   B64_set_crlf( int nn ) ;
00644 extern void   B64_set_linelen( int ll ) ;
00645 extern void   B64_to_binary( int nb64, byte * b64, int * nbin, byte ** bin ) ;
00646 extern void   B64_to_base64( int nbin, byte * bin, int * nb64, byte ** b64 ) ;
00647 
00648 extern char * MD5_static_array( int n, char * bytes ) ;
00649 extern char * MD5_malloc_array( int n, char * bytes ) ;
00650 extern char * MD5_static_string( char * string ) ;
00651 extern char * MD5_malloc_string( char * string ) ;
00652 extern char * MD5_static_file(char * filename) ;
00653 extern char * MD5_malloc_file(char * filename) ;
00654 
00655 extern char * MD5_B64_array( int n, char * bytes ) ;
00656 extern char * MD5_B64_string( char * string ) ;
00657 extern char * MD5_B64_file(char * filename) ;
00658 
00659 extern char * UNIQ_idcode(void) ;
00660 extern void   UNIQ_idcode_fill( char * ) ;
00661 extern char * UNIQ_hashcode( char * ) ;
00662 
00663 extern char * UUID_hashcode( char * ) ;   /* 20 Aug 2002 */
00664 extern char * UUID_idcode(void) ;
00665 
00666 /* trusted host manipulation */
00667 
00668 extern char * NI_hostname_to_inet( char *host ) ;
00669 extern void   NI_add_trusted_host( char *hostname ) ;
00670 extern int    NI_trust_host( char *hostid ) ;
00671 
00672 /*! Close a NI_stream, and set the pointer to NULL. */
00673 
00674 #define NI_STREAM_CLOSE(nn) do{ NI_stream_close(nn); (nn)=NULL; } while(0)
00675 
00676 /****************************************************************************
00677   This stuff defines various types, macros, and function prototypes
00678   for generic datasets and domains for neuroimaging applications.
00679 *****************************************************************************/
00680 
00681 #ifndef TYPEDEF_NI_INDEX_T
00682 #define TYPEDEF_NI_INDEX_T
00683 typedef int NI_index_t ;      /* used to store indexes, vector lengths */
00684 #endif
00685 
00686 /*---------------------------------------------------------------------------*/
00687 /*! Stuff that goes at the top of every NI struct:
00688      - type is a code that lets us tell what kind of struct it is
00689      - nref is a reference count
00690      - idcode is a globally unique string (max 63 characters)
00691      - name is an arbitrary string for fun, profit, and elucidation
00692      - either or both of these strings may be NULL
00693 -----------------------------------------------------------------------------*/
00694 
00695 #define NI_BASIC_PARTS  \
00696   int type ;            \
00697   int nref ;            \
00698   char *idcode ;        \
00699   char *name
00700 
00701 /*---------------------------------------------------------------------------*/
00702 /*! The minimal NI struct, with only the basic elements. */
00703 
00704 typedef struct {
00705   NI_BASIC_PARTS ;
00706 } NI_struct ;
00707 
00708 extern void   NI_free_struct      ( void * ) ;
00709 extern void * NI_copy_struct      ( void * ) ;
00710 extern void * NI_pointto_struct   ( void * ) ;
00711 
00712 extern void   NI_register_struct  ( void * ) ;
00713 extern void * NI_find_struct      ( char * ) ;
00714 extern void   NI_unregister_struct( void * ) ;
00715 
00716 /*---------------------------------------------------------------------------*/
00717 /*! NI struct to hold one float. */
00718 
00719 typedef struct {
00720   NI_BASIC_PARTS ;
00721   float val ;
00722 } NI_float_one ;
00723 
00724 #define NI_float_val(nd) ((nd)->val)
00725 
00726 /*---------------------------------------------------------------------------*/
00727 /*! NI struct to hold the definition of a statistical distribution for
00728     a NI_vector (call it v):
00729       - statcode  = one of the NI_STAT_* codes
00730       - param_num = number of parameters for this distribution
00731       - param[i]  = parameter #i, for i=0..param_num-1:
00732              - this will either be a NI_float_one, which means it
00733                 is constant for all elements of the vector
00734              - OR
00735              - this will be a NI_vector itself, of float type,
00736                 which means that the #i parameter for v[j] is stored
00737                 in param[i][j]
00738              - for example, you can have an F-statistic with the
00739                first DOF param being different for every node and
00740                the second DOF param being fixed
00741 -----------------------------------------------------------------------------*/
00742 
00743 typedef struct {
00744   NI_BASIC_PARTS ;
00745   int statcode ;
00746   NI_index_t param_num ;
00747   NI_struct  **param ;
00748 } NI_statistic ;
00749 
00750 #define NI_stat_code(nd)      ((nd)->statcode)
00751 #define NI_stat_param_num(nd) ((nd)->param_num)
00752 #define NI_stat_param(nd,i,j)                             \
00753   ( ((nd)->param[i]->type == NI_FLOAT_ONE_TYPE)           \
00754      ? ( ((NI_float_one *)(nd)->param[i])->val )          \
00755      : ( ((NI_float_vector *)(nd)->param[i])->vec[j] ) )
00756 
00757 /*--- Statistical type codes:
00758        2..10 match AFNI's 3ddata.h
00759        the rest match those in NIfTI-1.1 (nifti1.h) ---*/
00760 
00761                                  /** Parameters **/
00762 #define NI_STAT_CORREL      2   /* Samples, fits, orts   */
00763 #define NI_STAT_TTEST       3   /* DOF                   */
00764 #define NI_STAT_FTEST       4   /* 2 DOF                 */
00765 #define NI_STAT_ZSCORE      5   /* no params             */
00766 #define NI_STAT_CHISQ       6   /* DOF                   */
00767 #define NI_STAT_BETA        7   /* a and b params        */
00768 #define NI_STAT_BINOM       8   /* # trials, p per trial */
00769 #define NI_STAT_GAMMA       9   /* shape, scale params   */
00770 #define NI_STAT_POISSON    10   /* mean                  */
00771 
00772 #define NI_STAT_NORMAL     11   /* mean, variance        */
00773 #define NI_STAT_FTEST_NONC 12   /* 2 DOF, noncentrality  */
00774 #define NI_STAT_CHISQ_NONC 13   /* DOF, noncentrality    */
00775 #define NI_STAT_LOGISTIC   14   /* location, scale       */
00776 #define NI_STAT_LAPLACE    15   /* location, scale       */
00777 #define NI_STAT_UNIFORM    16   /* start, end            */
00778 #define NI_STAT_TTEST_NONC 17   /* DOF, noncentrality    */
00779 #define NI_STAT_WEIBULL    18   /* location, scale, power*/
00780 #define NI_STAT_CHI        19   /* DOF                   */
00781 #define NI_STAT_INVGAUSS   20   /* mu, lambda            */
00782 #define NI_STAT_EXTVAL     21   /* location, scale       */
00783 
00784 #define NI_STAT_PVAL       22
00785 #define NI_STAT_LOGPVAL    23
00786 #define NI_STAT_LOG10PVAL  24
00787 
00788 #define NI_STAT_FIRSTCODE   2
00789 #define NI_STAT_LASTCODE   24
00790 
00791 extern int    NI_stat_numparam( int ) ;
00792 extern char * NI_stat_distname( int ) ;
00793 extern void   NI_stat_decode( char *, int *, float *, float *, float * ) ;
00794 extern char * NI_stat_encode( int , float,float,float ) ;
00795 
00796 /*---------------------------------------------------------------------------*/
00797 /*! NI struct to hold a vector of values:
00798      - vec_len   = number of values
00799      - vec_typ   = type of values (e.g., NI_FLOAT, etc.)
00800      - vec       = pointer to array of data of length vec_len
00801      - vec_range = pointer to array of length 2 (if not NULL):
00802                    - vec_range[0] = smallest value in vec
00803                    - vec_range[1] = largest value in vec
00804      - statistic = defines statistical distribution for these values
00805                    (if not NULL)
00806      - the size in bytes of each element of vec can be determined
00807        by NI_datatype_size(vec_typ)
00808 -----------------------------------------------------------------------------*/
00809 
00810 typedef struct {
00811   NI_BASIC_PARTS ;
00812   NI_index_t vec_len ;
00813   int vec_typ ;
00814   void *vec ;
00815   void *vec_range ;
00816   NI_statistic *statistic ;
00817 } NI_vector ;
00818 
00819 extern void * NI_new_vector( int , NI_index_t ) ;
00820 extern void   NI_set_vector_range( void * ) ;
00821 
00822 /*********************************************************
00823    The special vector types below are mostly convenient
00824    for having vectors of the basic types pre-defined.
00825    Field for field, they match the NI_vector above,
00826    except that the "void *" components are pre-declared
00827    to be the correct basic type (don't have to cast).
00828    Therefore, you can do casts like this:
00829      NI_vector *vv ;
00830      if( vv->vec_typ == NI_FLOAT ){
00831        NI_float_vector *ff = (NI_float_vector *) vv ;
00832        ff->vec[0] = 7.3 ;
00833      }
00834 **********************************************************/
00835 
00836 /*---------------------------------------------------------------------------*/
00837 /*! NI struct to hold a vector of byte values:
00838      - vec_len   = number of values
00839      - vec_typ   = type of values (must be NI_BYTE)
00840      - vec       = pointer to array of data of length vec_len
00841      - vec_range = pointer to array of length 2 (if not NULL):
00842                    - vec_range[0] = smallest value in vec
00843                    - vec_range[1] = largest value in vec
00844      - statistic = defines statistical distribution for these values
00845                    (if not NULL)
00846 -----------------------------------------------------------------------------*/
00847 
00848 typedef struct {
00849   NI_BASIC_PARTS ;
00850   NI_index_t vec_len ;
00851   int vec_typ ;
00852   byte *vec ;
00853   byte *vec_range ;
00854   NI_statistic *statistic ;
00855 } NI_byte_vector ;
00856 
00857 /*---------------------------------------------------------------------------*/
00858 /*! NI struct to hold a vector of short values:
00859      - vec_len   = number of values
00860      - vec_typ   = type of values (must be NI_SHORT)
00861      - vec       = pointer to array of data of length vec_len
00862      - vec_range = pointer to array of length 2 (if not NULL):
00863                    - vec_range[0] = smallest value in vec
00864                    - vec_range[1] = largest value in vec
00865      - statistic = defines statistical distribution for these values
00866                    (if not NULL)
00867 -----------------------------------------------------------------------------*/
00868 
00869 typedef struct {
00870   NI_BASIC_PARTS ;
00871   NI_index_t vec_len ;
00872   int vec_typ ;
00873   short *vec ;
00874   short *vec_range ;
00875   NI_statistic *statistic ;
00876 } NI_short_vector ;
00877 
00878 /*---------------------------------------------------------------------------*/
00879 /*! NI struct to hold a vector of int values:
00880      - vec_len   = number of values
00881      - vec_typ   = type of values (must be NI_INT)
00882      - vec       = pointer to array of data of length vec_len
00883      - vec_range = pointer to array of length 2 (if not NULL):
00884                    - vec_range[0] = smallest value in vec
00885                    - vec_range[1] = largest value in vec
00886      - statistic = defines statistical distribution for these values
00887                    (if not NULL)
00888 -----------------------------------------------------------------------------*/
00889 
00890 typedef struct {
00891   NI_BASIC_PARTS ;
00892   NI_index_t vec_len ;
00893   int vec_typ ;
00894   int *vec ;
00895   int *vec_range ;
00896   NI_statistic *statistic ;
00897 } NI_int_vector ;
00898 
00899 /*---------------------------------------------------------------------------*/
00900 /*! NI struct to hold a vector of float values:
00901      - vec_len   = number of values
00902      - vec_typ   = type of values (must be NI_FLOAT)
00903      - vec       = pointer to array of data of length vec_len
00904      - vec_range = pointer to array of length 2 (if not NULL):
00905                    - vec_range[0] = smallest value in vec
00906                    - vec_range[1] = largest value in vec
00907      - statistic = defines statistical distribution for these values
00908                    (if not NULL)
00909 -----------------------------------------------------------------------------*/
00910 
00911 typedef struct {
00912   NI_BASIC_PARTS ;
00913   NI_index_t vec_len ;
00914   int vec_typ ;
00915   float *vec ;
00916   float *vec_range ;
00917   NI_statistic *statistic ;
00918 } NI_float_vector ;
00919 
00920 /*---------------------------------------------------------------------------*/
00921 /*! NI struct to hold a vector of double values:
00922      - vec_len   = number of values
00923      - vec_typ   = type of values (must be NI_DOUBLE)
00924      - vec       = pointer to array of data of length vec_len
00925      - vec_range = pointer to array of length 2 (if not NULL):
00926                    - vec_range[0] = smallest value in vec
00927                    - vec_range[1] = largest value in vec
00928      - statistic = defines statistical distribution for these values
00929                    (if not NULL)
00930 -----------------------------------------------------------------------------*/
00931 
00932 typedef struct {
00933   NI_BASIC_PARTS ;
00934   NI_index_t vec_len ;
00935   int vec_typ ;
00936   double *vec ;
00937   double *vec_range ;
00938   NI_statistic *statistic ;
00939 } NI_double_vector ;
00940 
00941 /*---------------------------------------------------------------------------*/
00942 /*! NI struct to hold a vector of complex values:
00943      - vec_len   = number of values
00944      - vec_typ   = type of values (must be NI_COMPLEX)
00945      - vec       = pointer to array of data of length vec_len
00946      - vec_range = pointer to array of length 2 (if not NULL):
00947                    - vec_range[0] = smallest value in vec
00948                    - vec_range[1] = largest value in vec
00949      - statistic = defines statistical distribution for these values
00950                    (if not NULL)
00951 -----------------------------------------------------------------------------*/
00952 
00953 typedef struct {
00954   NI_BASIC_PARTS ;
00955   NI_index_t vec_len ;
00956   int vec_typ ;
00957   complex *vec ;
00958   complex *vec_range ;
00959   NI_statistic *statistic ;
00960 } NI_complex_vector ;
00961 
00962 /*---------------------------------------------------------------------------*/
00963 /*! NI struct to hold a vector of rgb values:
00964      - vec_len   = number of values
00965      - vec_typ   = type of values (must be NI_RGB)
00966      - vec       = pointer to array of data of length vec_len
00967      - vec_range = pointer to array of length 2 (if not NULL):
00968                    - vec_range[0] = smallest value in vec
00969                    - vec_range[1] = largest value in vec
00970      - statistic = defines statistical distribution for these values
00971                    (if not NULL)
00972 -----------------------------------------------------------------------------*/
00973 
00974 typedef struct {
00975   NI_BASIC_PARTS ;
00976   NI_index_t vec_len ;
00977   int vec_typ ;
00978   rgb *vec ;
00979   rgb *vec_range ;
00980   NI_statistic *statistic ;
00981 } NI_rgb_vector ;
00982 
00983 /*---------------------------------------------------------------------------*/
00984 /*! NI struct to hold a vector of rgba values:
00985      - vec_len   = number of values
00986      - vec_typ   = type of values (must be NI_RGBA)
00987      - vec       = pointer to array of data of length vec_len
00988      - vec_range = pointer to array of length 2 (if not NULL):
00989                    - vec_range[0] = smallest value in vec
00990                    - vec_range[1] = largest value in vec
00991      - statistic = defines statistical distribution for these values
00992                    (if not NULL)
00993 -----------------------------------------------------------------------------*/
00994 
00995 typedef struct {
00996   NI_BASIC_PARTS ;
00997   NI_index_t vec_len ;
00998   int vec_typ ;
00999   rgba *vec ;
01000   rgba *vec_range ;
01001   NI_statistic *statistic ;
01002 } NI_rgba_vector ;
01003 
01004 /*---------------------------------------------------------------------------*/
01005 /*! NI struct to hold a vector of string values:
01006      - vec_len   = number of values
01007      - vec_typ   = type of values (must be NI_STRING)
01008      - vec       = pointer to array of data of length vec_len
01009      - vec_range = pointer to array of length 2 (if not NULL):
01010                    - vec_range[0] = smallest value in vec
01011                    - vec_range[1] = largest value in vec
01012      - statistic = defines statistical distribution for these values
01013                    (if not NULL)
01014 -----------------------------------------------------------------------------*/
01015 
01016 typedef struct {
01017   NI_BASIC_PARTS ;
01018   NI_index_t vec_len ;
01019   int vec_typ ;
01020   char **vec ;
01021   char **vec_range ;
01022   NI_statistic *statistic ;
01023 } NI_string_vector ;
01024 
01025 /*---------------------------------------------------------------------------*/
01026 /*! NI struct to define a coordinate mapping between one 3D domain
01027     and another.
01028 -----------------------------------------------------------------------------*/
01029 
01030 typedef struct {
01031   NI_BASIC_PARTS ;
01032   float mat[4][4] ;
01033 } NI_affine_3dmap ;
01034 
01035 /*---------------------------------------------------------------------------*/
01036 /*! NI struct to define a 1..4 dimensional rectangular domain:
01037      - nx,ny,nz,nt = number of voxels along each axis
01038      - nvox        = total number of voxels
01039      - dx,dy,dz,dt = grid spacing along each axis
01040      - xo,yo,zo,to = origin of each axis
01041 -----------------------------------------------------------------------------*/
01042 
01043 typedef struct {
01044   NI_BASIC_PARTS ;
01045   NI_index_t nx,ny,nz,nt , nvox ;
01046   float dx,dy,dz,dt ;
01047   float xo,yo,zo,to ;
01048 } NI_rect_domain ;
01049 
01050 /*---------------------------------------------------------------------------*/
01051 /*! NI struct to define a domain of scattered points:
01052      - num_node = number of nodes (points)
01053      - id       = list of integer node identifiers
01054      - x,y,z    = list of spatial coordinates
01055      - seq      = If 1, node id's are sequential
01056      - seqbase  = If id's are sequential, is smallest id
01057      - sorted   = If 1, id's are sorted into increasing order
01058 -----------------------------------------------------------------------------*/
01059 
01060 typedef struct {
01061   NI_BASIC_PARTS ;
01062   NI_index_t  num_node ;
01063   NI_index_t *id ;
01064   float        *x , *y , *z ;
01065   int           seq ;
01066   int           seqbase ;
01067   int           sorted ;
01068 } NI_points_domain ;
01069 
01070 /*---------------------------------------------------------------------------*/
01071 /*! NI struct to hold a generic dataset, which is a collection of value
01072     vectors defined over a common domain.
01073       - num_node = number of nodes in the domain
01074       - num_val  = number of values at each node
01075       - order    = code indicated whether the value vectors are
01076                    along the node direction or value index direction
01077       - vec[i]   = i-th value vector
01078       - domain   = definition of domain the nodes occupy (if not NULL)
01079 -----------------------------------------------------------------------------*/
01080 
01081 typedef struct {
01082   NI_BASIC_PARTS ;
01083   NI_index_t num_node , num_val ;
01084   int order ;
01085   NI_vector **vec ;
01086   NI_struct  *domain ;
01087 } NI_dataset ;
01088 
01089 #define NI_NODE_DIRECTION  55   /* for the order element */
01090 #define NI_INDEX_DIRECTION 56
01091 
01092 #define NI_dataset_vecnum(nd)  \
01093   ( ((nd)->order == NI_NODE_DIRECTION) ? (nd)->num_val : (nd)->num_node )
01094 
01095 #define NI_dataset_veclen(nd)  \
01096   ( ((nd)->order == NI_NODE_DIRECTION) ? (nd)->num_node: (nd)->num_val  )
01097 
01098 #define NI_opposite_order(oo)  \
01099   ( ((oo) == NI_NODE_DIRECTION) ? NI_INDEX_DIRECTION : NI_NODE_DIRECTION )
01100 
01101 extern void * NI_dataset_transpose( void * ) ;
01102 
01103 /*---------------------------------------------------------------------------*/
01104 /* Codes for the "type" element of a NI struct. */
01105 
01106 #define NI_STRUCT_TYPE          6660000
01107 #define NI_FLOAT_ONE_TYPE       6660002
01108 #define NI_STATISTIC_TYPE       6660003
01109 #define NI_DATASET_TYPE         6660004
01110 
01111 #define NI_VECTOR_TYPE          6660100
01112 #define NI_BYTE_VECTOR_TYPE     6660101
01113 #define NI_SHORT_VECTOR_TYPE    6660102
01114 #define NI_INT_VECTOR_TYPE      6660103
01115 #define NI_FLOAT_VECTOR_TYPE    6660104
01116 #define NI_DOUBLE_VECTOR_TYPE   6660105
01117 #define NI_COMPLEX_VECTOR_TYPE  6660106
01118 #define NI_RGB_VECTOR_TYPE      6660107
01119 #define NI_RGBA_VECTOR_TYPE     6660108
01120 #define NI_STRING_VECTOR_TYPE   6660109
01121 
01122 #define NI_is_vector_type(tt)                                 \
01123  ( (tt) >= NI_VECTOR_TYPE && (tt) <= NI_STRING_VECTOR_TYPE )
01124 
01125 #define NI_patch_vector_type(nn)                              \
01126  do{ if( NI_is_vector_type((nn)->type) &&                     \
01127          NI_is_builtin_type((nn)->vec_typ) )                  \
01128        (nn)->type = NI_VECTOR_TYPE + (nn)->vec_typ + 1 ;      \
01129  } while(0)
01130 
01131 #define NI_RECT_DOMAIN_TYPE     6660201
01132 #define NI_POINTS_DOMAIN_TYPE   6660202
01133 
01134 #define NI_is_domain_type(tt)                                     \
01135  ( (tt) >= NI_RECT_DOMAIN_TYPE && (tt) <= NI_POINTS_DOMAIN_TYPE )
01136 
01137 #define NI_AFFINE_3DMAP_TYPE    6660301
01138 
01139 #define NI_is_3dmap_type(tt)                                      \
01140  ( (tt) >= NI_AFFINE_3DMAP_TYPE && (tt) <= NI_AFFINE_3DMAP_TYPE )
01141 
01142 #define NI_datatype_size(n) NI_rowtype_code_to_size(n)
01143 
01144 /*-------------------------------------------------------------------------*/
01145 
01146 typedef void NI_voidfunc() ;
01147 
01148 extern int NI_do( NI_stream_type * , NI_element * ) ;
01149 extern void NI_register_doer( char *, NI_voidfunc * ) ;
01150 /*-------------------------------------------------------------------------*/
01151 /*! An array of strings, each allocated with NI_malloc(). */
01152 
01153 typedef struct { int num; char **str;} NI_str_array ;
01154 
01155 #define NI_delete_str_array(sar)             \
01156   do{ int pp ;                               \
01157       for( pp=0 ; pp < (sar)->num ; pp++ )   \
01158         NI_free( (sar)->str[pp] );           \
01159       NI_free((sar)->str) ; NI_free(sar) ;   \
01160   } while(0)
01161 
01162 extern NI_str_array * NI_decode_string_list( char *ss , char *sep ) ;
01163 #define NI_decode_str_array NI_decode_string_list
01164 
01165 /*-------------------------------------------------------------------------*/
01166 /* Registry stuff -- niml_registry.c [25 Feb 2005] */
01167 
01168 extern void * NI_registry_malloc          ( char *, char *, size_t ) ;
01169 extern void * NI_registry_realloc         ( void *, size_t ) ;
01170 extern void   NI_registry_free            ( void * ) ;
01171 extern void * NI_registry_idcode_to_ptr   ( char * ) ;
01172 extern char * NI_registry_idcode_to_name  ( char * ) ;
01173 extern char * NI_registry_ptr_to_idcode   ( void * ) ;
01174 extern char * NI_registry_ptr_to_name     ( void * ) ;
01175 extern void   NI_registry_idcode_altername( char *, char * ) ;
01176 extern void   NI_registry_ptr_altername   ( void *, char * ) ;
01177 extern size_t NI_registry_idcode_to_len   ( char * ) ;
01178 extern size_t NI_registry_ptr_to_len      ( void * ) ;
01179 extern void * NI_registry_add             ( char *, char *, void * ) ;
01180 extern void * NI_registry_replace         ( void *, void * ) ;
01181 
01182 /*-------------------------------------------------------------------------*/
01183 
01184 #define IDCODE_LEN 32
01185 #define LEN_IDCODE IDCODE_LEN
01186 
01187 #ifndef TYPEDEF_NI_datacontainer
01188 #define TYPEDEF_NI_datacontainer
01189 typedef struct {
01190   char typename   [IDCODE_LEN] ; /* e.g., "NI_ELEMENT"   */
01191   char self_name  [IDCODE_LEN] ; /* e.g., "AFNI_dataset" */
01192   char self_idcode[IDCODE_LEN] ;
01193   int  ival , jval ;
01194   void *self_data ;              /* the actual data */
01195 } NI_objcontainer ;
01196 
01197 typedef int (*NI_objconverter_func)( NI_objcontainer * ) ;
01198 #endif
01199 
01200 extern char * NI_self_idcode( void * ) ;
01201 extern void   NI_suck_stream( char *, int, int *, NI_objcontainer *** ) ;
01202 extern void   NI_convert_elm_to_obj( NI_objcontainer * ) ;
01203 extern void   NI_convert_obj_to_elm( NI_objcontainer * ) ;
01204 extern void   NI_register_objconverters( char * ,
01205                                          NI_objconverter_func ,
01206                                          NI_objconverter_func  ) ;
01207 
01208 #endif /* _NIML_HEADER_FILE */
 

Powered by Plone

This site conforms to the following standards: