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  

SUMA_DataSets.h

Go to the documentation of this file.
00001 #ifndef SUMA_DATASETS_INCLUDED
00002 #define SUMA_DATASETS_INCLUDED
00003 
00004 #define SUMA_MAX_NAME_LENGTH 500   /*!< Maximum number of characters in a filename */
00005 #define SUMA_MAX_DIR_LENGTH 2000    /*!< Maximum number of characters in a directory name */
00006 #ifndef SUMA_IDCODE_LENGTH
00007    #define SUMA_IDCODE_LENGTH 50
00008 #endif
00009 
00010 #define SUMA_VERSION_VECTOR 20041229, 20040610, 20040116, \
00011                             20040106, -10000 /*!< modify this dude and you must update SUMA_New_Additions_perver 
00012                                        in SUMA_help.c. 
00013                                        Add to the left of the vector, leave the last value of -10000 untouched
00014                                        If you like to think of floating point version numbers,divide by 10000
00015                                        This define is stuck here so that non-SUMA DataSet manipulating programs 
00016                                        can use it, one hopes.
00017                                        Numbering is yyyymmdd */
00018 #define SUMA_EMPTY_ATTR "~"
00019 #define SUMA_NI_SS ","    /* string separator */
00020 
00021 typedef enum { NOPE, YUP} SUMA_Boolean;
00022 
00023 typedef enum { SUMA_notypeset = -1, 
00024                SUMA_byte = NI_BYTE, 
00025                SUMA_short = NI_SHORT, 
00026                SUMA_int = NI_INT, 
00027                SUMA_float = NI_FLOAT32, 
00028                SUMA_double = NI_FLOAT64, 
00029                SUMA_complex = NI_COMPLEX64,
00030                SUMA_string = NI_STRING} SUMA_VARTYPE;
00031 
00032 /*! simple vectors */
00033 typedef struct {
00034    int n;
00035    int *v;
00036 } SUMA_IVEC;
00037 
00038 typedef struct {
00039    int n;
00040    float *v;
00041 } SUMA_FVEC;
00042 
00043 typedef struct {
00044    int n;
00045    double *v;
00046 } SUMA_DVEC;
00047 
00048 /*! filename and path */
00049 typedef struct {
00050    char *Path;
00051    char *FileName;
00052 }SUMA_FileName;
00053 
00054 /*! filename, extension and path */
00055 typedef struct {
00056    char *Path;
00057    char *FileName;
00058    char *FileName_NoExt;
00059    char *Ext;
00060 }SUMA_PARSED_NAME;
00061 
00062 
00063 /*! string stucture 
00064 */
00065 typedef struct {
00066    int N_alloc;  /*!< space allocated for s */
00067    char *s; /*!< string s */
00068 } SUMA_STRING;
00069 
00070 typedef enum {
00071    SUMA_ERROR_DSET_TYPE = -1,
00072    SUMA_NO_DSET_TYPE,
00073    SUMA_NODE_BUCKET,
00074    SUMA_AFNI_NODE_BUCKET,
00075    SUMA_NODE_ROI, /*!< Col0: Node ID, Col1: ROI label (int) */
00076    SUMA_NODE_RGB,
00077    SUMA_NODE_RGBb,
00078    SUMA_NODE_RGBA,
00079    SUMA_NODE_RGBAb,
00080    SUMA_NODE_XYZ,
00081    SUMA_NEW_NODE_XYZ,
00082    SUMA_NODE_CONVEXITY,
00083    SUMA_NEW_MESH_IJK,
00084    SUMA_MESH_IJK,
00085    SUMA_PREP_NEW_SURFACE,
00086    SUMA_VIEWER_SETTING,
00087    SUMA_SURFACE_VOLUME_PARENT,
00088    SUMA_SURFACE_OBJECT,
00089    SUMA_N_DSET_TYPES
00090 } SUMA_DSET_TYPE; /*!<  Type of data set ( should be called Object, not DSET ) 
00091                         When you add a new element, modify functions
00092                         SUMA_Dset_Type_Name
00093                         SUMA_Dset_Type */
00094 
00095 typedef enum {
00096    SUMA_ERROR_DSET_FORMAT = -1,
00097    SUMA_NO_DSET_FORMAT,       /* 0 */
00098    SUMA_ASCII_NIML,           /* 1 */
00099    SUMA_BINARY_NIML,          /* 2 */
00100    SUMA_NIML,                 /* 3 */
00101    SUMA_1D,                   /* 4 */
00102    SUMA_1D_PURE,              /* 5 */
00103    SUMA_ASCII_OPEN_DX_DSET,   /* 6 */
00104 } SUMA_DSET_FORMAT; /*!<  Format of data set
00105                           When you add a new element, modify functions
00106                           SUMA_Dset_Format_Name
00107                           SUMA_Dset_Format */ 
00108 
00109 typedef enum {
00110    SUMA_ERROR_COL_TYPE = -1,
00111    SUMA_NO_COL_TYPE,
00112    SUMA_NODE_INT,    /*!< Generic integer */
00113    SUMA_NODE_INDEX,  /*!< index of a node to locate it in its domain */
00114    SUMA_NODE_ILABEL, /*!< An integer coding for a label */
00115    SUMA_NODE_FLOAT,  /*!< Generic float */ 
00116    SUMA_NODE_CX,     /*!< Node convexity */
00117    SUMA_NODE_X,      /*!< Node X coordinate */
00118    SUMA_NODE_Y,      /*!< Node Y coordinate */
00119    SUMA_NODE_Z,      /*!< Node Z coordinate */
00120    SUMA_NODE_3C,     /*!<  Node XYZ triplets */
00121    SUMA_NODE_R,      /*!< Node R color */
00122    SUMA_NODE_G,      /*!< Node G color */
00123    SUMA_NODE_B,      /*!< Node B color */
00124    SUMA_NODE_A,      /*!< Node A value */ 
00125    SUMA_NODE_BYTE,   /*!< Generic byte */
00126    SUMA_NODE_Rb,      /*!< Node R color in bytes*/
00127    SUMA_NODE_Gb,      /*!< Node G color in bytes*/
00128    SUMA_NODE_Bb,      /*!< Node B color in bytes*/
00129    SUMA_NODE_Ab,      /*!< Node A value in bytes*/ 
00130    SUMA_NODE_STRING,   /*!< Generic String */
00131    SUMA_NODE_SHORT,      /*!< Generic short */
00132    SUMA_NODE_DOUBLE,     /*!< Generic double */
00133    SUMA_NODE_XCORR      /*!< Cross Correlation Coefficient */ 
00134 }  SUMA_COL_TYPE; /*!<  Column types.
00135                         When you add a new element, you need to modify
00136                         SUMA_AddColAttr
00137                         SUMA_Col_Type 
00138                         SUMA_Col_Type_Name
00139                         SUMA_ColType2TypeCast
00140                         */
00141 
00142 
00143 /*! 
00144 I do not think we can have both nodes and triangles in this struct.
00145 I guess I can make this be a Node Datum then create a similar struct
00146 for triangle Datum and add them to SUMA_NIML_DRAWN_ROI.
00147 If you do something like this rename:
00148 SUMA_NIML_ROI_DATUM to SUMA_NIML_NODE_ROI_DATUM
00149 */
00150 typedef struct {
00151    int action; /*!< action taken with this datum, 
00152                      see same field in SUMA_ROI_DATUM */
00153    int Type; /*!< describes the type of the DrawnROI datum 
00154                   (see SUMA_ROI_TYPE) */
00155    int N_n; 
00156    int *nPath;
00157 /* int Type;
00158    int N_t;
00159    int *tPath; */
00160 } SUMA_NIML_ROI_DATUM; /*!< a version of SUMA_ROI_DATUM struct 
00161                            that can be used by niml. */
00162 
00163 typedef struct {
00164    int Type;         /*!< The final type of the DrawnROI, 
00165                            see SUMA_ROI_DRAWING_TYPE*/
00166    char *idcode_str;
00167    char *Parent_idcode_str;
00168    char *Label;
00169    char *ColPlaneName;
00170    float FillColor[3];  /*!< RGB fill color */
00171    float EdgeColor[3];  /*!< RGB edge color */
00172    int EdgeThickness;   /*!< thickness of edge */
00173    int iLabel;
00174    SUMA_NIML_ROI_DATUM *ROI_datum; /*!< a vector of ROI data 
00175                                        (a multitude of ROI datum) */
00176    int N_ROI_datum;
00177 } SUMA_NIML_DRAWN_ROI; /*!< a version of SUMA_DRAWN_ROI struct that 
00178                            can be used by niml. Fields are a reflection 
00179                            of those in SUMA_DRAWN_ROI*/
00180 
00181 typedef enum { SUMA_NO_PTR_TYPE, 
00182                SUMA_LINKED_DSET_TYPE, /*!< For pointers to SUMA_DSET */
00183                SUMA_LINKED_OVERLAY_TYPE, /*!< For pointers to SUMA_OVERLAYS */
00184                SUMA_LINKED_ND_FRST_NEI_TYPE, /*!< For pointers to SUMA_NODE_FIRST_NEIGHB*/
00185                SUMA_LINKED_MEMB_FACE_TYPE, /*!< For pointers to SUMA_MEMBER_FACE_SETS*/
00186                SUMA_LINKED_SURFCONT_TYPE, /*!< For pointers to SUMA_X_SurfCont*/
00187                SUMA_N_LINKED_PTR_TYPES } SUMA_LINKED_PTR_TYPES;
00188 /*!   
00189    Structure to track copies of a certain pointer.
00190    DO NOT CHANGE THE ORDER OF THE STRUCTURE's FIELDS 
00191 */
00192 
00193 typedef struct {
00194    int LinkedPtrType; /*!< Indicates the type of linked pointer */
00195    int N_links;   /*!< Number of links to this pointer */
00196    char owner_id[SUMA_IDCODE_LENGTH];   /*!< The id of whoever created that pointer. Might never get used.... */
00197 } SUMA_LinkedPtr;
00198 
00199 /*! Structure to contain a dataset defined on the surface */
00200 
00201 typedef struct {
00202    /* *** DO NOT ADD ANYTHING BEFORE THESE FIELDS
00203           DO NOT CHANGE THE ORDER OF THESE FIELDS
00204           These fields are use for tracking copies
00205           (links) to a pointer.
00206           ANY CHANGES HERE SHOULD BE REFLECTED IN 
00207           SUMA_LinkedPtr structure 
00208    */
00209    int LinkedPtrType; /*!< Indicates the type of linked pointer */
00210    int N_links;   /*!< Number of links to this pointer */
00211    char owner_id[SUMA_IDCODE_LENGTH];   /*!< The id of whoever created that pointer. Might never get used.... */
00212    
00213    #ifdef OLD_DSET
00214    NI_element *nel;  /*!< The whole deal 
00215       nel is a NIML data element which is briefly
00216       defined by a set of attributes, and a collection
00217       of data columns.
00218       nel contains the following string attributes:
00219          filename: The filename
00220          label: A short text label identifying the data set.
00221                 Typically, a short version of the filename                          
00222          idcode_str: Unique identifier for the data set
00223          MeshParent_idcode: Unique identifier of the surface containing the mesh  
00224                             over which this set is defined
00225          GeomParent_idcode: Unique identifier of the surface containing the 
00226                             coordinates of the nodes whose attributes 
00227                             (values) are in this set.
00228          sorted_node_def: flag indicating that nodes in NodeDef are sorted
00229                           see NodeDef below. 
00230          LabelCol_'i': Label of column i
00231          RangeCol_'i': Range of values in column i. 
00232                        See function:
00233                         SUMA_GetColRange.
00234          TypeCol_'i': Type of data in column i.
00235                       See functions:
00236                         SUMA_Col_Type  
00237                         SUMA_Col_Type_Name
00238                         SUMA_ColType2TypeCast 
00239                       and typedef:
00240                         SUMA_COL_TYPE             
00241          AttrCol_'i': Attributes specific to that column type.
00242                       At the moment, I don't use it much. But
00243                       think attributes to store with an f-stat
00244                       column for example and so on.
00245          RangeCol_, TypeCol_ and AttrCol_: are automatically 
00246                                            generated, see:
00247                                              SUMA_AddColAttr
00248                                              SUMA_AddGenColAttr
00249       
00250       nel structure contains the following fields:
00251          name: A string for the type of dataset.
00252                See functions:
00253                   SUMA_Dset_Type_Name
00254                   SUMA_Dset_Type
00255                and typedef:
00256                   SUMA_DSET_TYPE
00257          vec: A vector of pointers to the data columns. 
00258          vec_num: Number of columns in vec. So your columns
00259                   are vec[0] .. vec[vec_num - 1]
00260                   THINK SUB-BRICKS
00261          vec_len: Total number of rows in the dset. Think total
00262                   number of voxels.
00263          vec_filled: Number of rows (node data) filled in the dset.
00264                      You'd think this should be equal to vec_len,
00265                      but in instances where you may be receiving data for a 
00266                      varying number of nodes, it's a pain to have to destroy 
00267                      and recreate dsets. The trouble is not one of allocation 
00268                      but of multiple links and associated structures created
00269                      for each new dset. So, while the juice is only up to 
00270                      vec_filled, the allocation is for vec_len 
00271          NodeDef: A vector containing an explicit list of the node index
00272                   associated with each row of data.
00273                   ACTUALLY this is not a field of nel, but it is a column of 
00274                   data of the type SUMA_NODE_INDEX or "Node_Index". This
00275                   column may or may not exist. If it exist then NodeDef is
00276                   (int *)nel->vec[i_node_index] where i_node_index is the
00277                   index of the column containing node definitions. To 
00278                   find i_node_index, see function:
00279                      SUMA_GetColIndex
00280          
00281          Functions to read and write dsets:
00282             SUMA_LoadDset
00283             SUMA_Load1DDset
00284             SUMA_LoadNimlDset
00285             SUMA_WriteDset
00286             SUMA_RemoveDsetExtension
00287          Functions to form/access dsets and contents:
00288             SUMA_NewNel
00289             SUMA_AddNelCol
00290             SUMA_FillNelCol
00291             SUMA_GetColIndex
00292             SUMA_Col2Float
00293             SUMA_GetNodeDef
00294             SUMA_FreeDset
00295          Functions for debugging:   
00296             SUMA_ShowNel
00297             SUMA_DsetInfo
00298             SUMA_ShowMeSome
00299          Miscellaneous functions/tools:
00300             SUMA_Dset_Format 
00301             SUMA_Dset_Format_Name
00302             SUMA_AddNelHist
00303                     
00304          Sample Code: SUMA_Test_DSET_IO_STANDALONE
00305          */              
00306    #else   /* the post april 06 05 way */
00307    /* *** You can go crazy below */
00308    NI_group *ngr; /*!< This is now April 06 05, the container of the dataset, as opposed to the olde days where nel
00309                         contained everything. The reason that was done is to accomodate large sized attibutes that
00310                         do not fit nicely in ASCII forms tucked inside the header. 
00311                         What used to be called nel, is now called dnel (for data-part nel) and is nothing but a copy
00312                         of the pointer under ngr to the nel that contains the tabular dataset. 
00313                         
00314       ngr contains two types of attributes: 
00315          STRING attributes:
00316             filename: The filename
00317             label: A short text label identifying the data set.
00318                    Typically, a short version of the filename                          
00319             idcode_str: Unique identifier for the data set
00320             MeshParent_idcode: Unique identifier of the surface containing the mesh  
00321                                over which this set is defined
00322             GeomParent_idcode: Unique identifier of the surface containing the 
00323                                coordinates of the nodes whose attributes 
00324                                (values) are in this set.
00325             sorted_node_def: flag indicating that nodes in NodeDef are sorted
00326                              see NodeDef below.
00327 
00328          ELEMENT (data) attributes
00329             ColumnRange
00330             ColumnType
00331             ColumnLabel
00332             ColumnAttribute
00333             History
00334          */    
00335    NI_element *dnel; /*!< a copy of the NI_element pointer that contains the tabular data inside ngr. Do not free this
00336                            element separately, and make sure its value is changed in syncrony with the one in ngr. */
00337                               
00338    #endif     
00339 } SUMA_DSET;
00340 
00341 #define SUMA_COUNTER_SUFFIX(ic)  ( ((ic) == 1) ? "st" : ((ic) == 2) ? "nd" : ((ic) == 3) ? "rd" : "th" )
00342 #define SUMA_COUNTER_PLURAL(ic)  ( ((ic) == 1) ? "" : "s" )
00343 
00344 #define SUMA_SKIP_COMMON_OPTIONS(m_brk, m_kar) {\
00345    if (!m_brk &&                                     \
00346        ( (strcmp(argv[m_kar], "-memdbg") == 0) ||    \
00347          (strcmp(argv[m_kar], "-iodbg") == 0)  ||    \
00348          (strcmp(argv[m_kar], "-nomall") == 0) ||    \
00349          (strcmp(argv[m_kar], "-yesmall") == 0) ||   \
00350          (strcmp(argv[m_kar], "-trace") == 0) ||     \
00351          (strcmp(argv[m_kar], "-novolreg") == 0) ||   \
00352          (strcmp(argv[m_kar], "-TRACE") == 0)) ) {   \
00353                 /* valid options, but already taken care of */  \
00354                 m_brk = YUP;                                   \
00355         }                                               \
00356 }
00357       
00358 /*!
00359    Convenience function for SUMA_StringAppend cleanup
00360 */
00361 #define SUMA_SS2S(SS, stmp)  {\
00362    if (SS)  {  \
00363       SS = SUMA_StringAppend(SS, NULL);   \
00364       stmp = SS->s;  \
00365       SUMA_free(SS); SS = NULL;   } \
00366 }
00367 /*!
00368    Frees so, if not NULL
00369    copies sn into so, takes care of so's allocation
00370    Does not free sn
00371 */
00372 #define SUMA_STRING_REPLACE(so, sn) {  \
00373    if (so) SUMA_free(so);  \
00374    so = SUMA_copy_string(sn); \
00375 }
00376 
00377 #define SUMA_TO_LOWER(s) { \
00378    int m_i; \
00379    if (s) { \
00380       for (m_i=0; m_i < strlen(s); ++m_i) { \
00381          if (s[m_i] >= 'A' && s[m_i] <= 'Z') s[m_i] = s[m_i] + 'a' - 'A';  \
00382       }   \
00383    }  \
00384 }  
00385 
00386 /*!
00387    Is this attribute string empty ?
00388 */
00389 #define SUMA_IS_EMPTY_STR_ATTR(str)  ( (!(str) || !strcmp((str),SUMA_EMPTY_ATTR)) ? 1 : 0 )
00390 
00391 
00392 /*!
00393    \brief Macros to access dataset elements 
00394    Almost all of them involve a function call
00395    so don't use them in loops where the returned
00396    value is not expected to change
00397 */
00398 #ifdef OLD_DSET
00399    #define SDSET_FILENAME(dset) NI_get_attribute(dset->nel,"filename")
00400    #define SDSET_LABEL(dset) NI_get_attribute(dset->nel,"label")
00401    #define SDSET_ID(dset) SUMA_sdset_id(dset) 
00402    #define SDSET_IDGDOM(dset) NI_get_attribute(dset->nel,"GeomParent_idcode") 
00403    #define SDSET_IDMDOM(dset) SUMA_sdset_idmdom(dset)
00404    #define SDSET_SORTED(dset) NI_get_attribute(dset->nel,"sorted_node_def") 
00405    #define SDSET_TYPE_NAME(dset) dset->nel->name
00406    #define SDSET_TYPE(dset) SUMA_Dset_Type(dset->nel->name)
00407    #define SDEST_VECLEN(dset) dset->nel->vec_len
00408 #else
00409    #define SDSET_FILENAME(dset) NI_get_attribute(dset->ngr,"filename")
00410    #define SDSET_LABEL(dset) NI_get_attribute(dset->ngr,"label")
00411    #define SDSET_ID(dset) SUMA_sdset_id(dset) 
00412    #define SDSET_IDGDOM(dset) NI_get_attribute(dset->ngr,"GeomParent_idcode") 
00413    #define SDSET_IDMDOM(dset) SUMA_sdset_idmdom(dset)
00414    #define SDSET_SORTED(dset) NI_get_attribute(dset->ngr,"sorted_node_def") 
00415    #define SDSET_TYPE_NAME(dset) dset->ngr->name
00416    #define SDSET_TYPE(dset) SUMA_Dset_Type(dset->ngr->name)
00417    #define SDEST_VECLEN(dset) dset->dnel->vec_len
00418 
00419 #endif
00420 /*!
00421    \brief Macros to access commonly used colorplane parameters
00422    DO NOT USE COLP_NODEDEF macro inside a loop where the returned
00423    value is not to change because it involves a function call (SLOW)
00424 */
00425 /* Pre March 29 04. 
00426 #define COLP_NODEDEF(cop) SUMA_GetNodeDef(cop->dset_link)
00427 #define COLP_N_NODEDEF(cop) cop->dset_link->nel->vec_filled
00428 */
00429 /* Post March 29 04. You can't go frugal and use dset's fields
00430 NodeDef might be dynamically changed in the overlay plane */
00431 #define COLP_NODEDEF(cop) cop->NodeDef
00432 #define COLP_N_NODEDEF(cop) cop->N_NodeDef
00433 #ifdef OLD_DSET
00434    #define COLP_N_ALLOC(cop) cop->dset_link->nel->vec_len
00435 #else
00436    #define COLP_N_ALLOC(cop) cop->dset_link->dnel->vec_len
00437 #endif
00438 /* #define DSET_(dset) NI_get_attribute(dset->nel,"") */
00439 
00440 /*!
00441    NEL_READ macro for reading a NI element from strm
00442    nel (NI_element *) to contain the deed (if null then read failed)
00443    frm the source such as: "file:Test_niml_file"
00444 */
00445 #define NEL_READ(nel, frm) { \
00446    NI_stream m_ns = NULL;  \
00447    int m_tt = NI_element_type((void*)nel) ; \
00448    if (m_tt == NI_GROUP_TYPE) {  SUMA_SL_Err ("Group, use DSET_READ"); }/* SHOULD USE DSET_WRITE_1D */   \
00449    else {   \
00450       nel = NULL; \
00451       m_ns = NI_stream_open( frm , "r" ) ;   \
00452       if( m_ns == NULL ) {    \
00453          SUMA_SL_Err ("Failed to open stream");  \
00454       } else { \
00455          /* read the element */   \
00456          if (!(nel = NI_read_element( m_ns , 1 )))  { \
00457             SUMA_SL_Err ("Failed to read element");  \
00458          }  \
00459       }  \
00460       /* close the stream */  \
00461       NI_stream_close( m_ns ) ; \
00462    }  \
00463 }
00464 
00465 #define DSET_READ(dset, frm) { \
00466    NI_stream m_ns = NULL;  \
00467    if (dset->ngr || dset->dnel) {   SUMA_SL_Err("dset elements not empty!\nNeed a clean dset"); }  \
00468    else {   \
00469       m_ns = NI_stream_open( frm , "r" ) ;   \
00470       if( m_ns == NULL ) {    \
00471          SUMA_SL_Err ("Failed to open stream");  \
00472       } else { \
00473          /* read the element */   \
00474          if (!(dset->ngr = NI_read_element( m_ns , 1 )))  { \
00475             SUMA_SL_Err ("Failed to read element");  \
00476          } else { \
00477             /* Look for the _data element */ \
00478             if (!(dset->dnel = SUMA_FindDsetDataAttributeElement(dset))) {  \
00479                SUMA_SL_Err("Cannot find data element!\nCleaning up.\n");   \
00480                NI_free_element (dset->ngr); dset->ngr = NULL;  \
00481             }  \
00482          }\
00483       }  \
00484       /* close the stream */  \
00485       NI_stream_close( m_ns ) ; \
00486    }  \
00487 }
00488 
00489 /*!
00490    NEL_WRITE_TX(nel, strm, suc)
00491    NEL_WRITE_BI(nel, strm, suc)
00492    NEL_WRITE_1D(nel, strm, suc)
00493    NEL_WRITE_1D_PURE(nel, strm, suc)
00494    macros for writing a NI element in  NI_TEXT_MODE, NI_BINARY_MODE  or
00495                                        NI_TEXT_MODE | NI_HEADERSHARP_FLAG which is a la 1D
00496    nel is the NI element
00497    frm is someting like:  "file:Test_write_asc_1D" (for a file output)
00498                            "fd:1" (for stdout)
00499    suc is a flag for success (1), failure (0)
00500 */
00501 #define NEL_WRITE_TX(nel, frm, suc) { \
00502    NI_stream m_ns = NULL;  \
00503    suc = 1; \
00504    m_ns = NI_stream_open( frm , "w" ) ;   \
00505    if( m_ns == NULL ) {    \
00506       SUMA_SL_Err ("Failed to open stream");  \
00507       suc = 0; \
00508    } else { \
00509       /* write out the element */   \
00510       if (NI_write_element( m_ns , nel , NI_TEXT_MODE ) < 0) { \
00511          SUMA_SL_Err ("Failed to write element");  \
00512          suc = 0; \
00513       }  \
00514    }  \
00515    /* close the stream */  \
00516    NI_stream_close( m_ns ) ; \
00517 }
00518 #define DSET_WRITE_1D(dset, frm, suc) { \
00519    NI_stream m_ns = NULL;  \
00520    int m_allnum;  \
00521    suc = 1; \
00522    m_allnum = SUMA_is_AllNumeric_dset(dset);   \
00523    if (!m_allnum) { \
00524       SUMA_SL_Err ("Element cannont be written to 1D format");    \
00525       suc = 0; \
00526    } else {   \
00527       m_ns = NI_stream_open( frm , "w" ) ;   \
00528       if( m_ns == NULL ) {    \
00529          SUMA_SL_Err ("Failed to open stream");  \
00530          suc = 0; \
00531       } else { \
00532          /* write out the element */   \
00533          if (NI_write_element( m_ns , dset->dnel , NI_TEXT_MODE | NI_HEADERSHARP_FLAG) < 0) { \
00534             SUMA_SL_Err ("Failed to write element");  \
00535             suc = 0; \
00536          }  \
00537       }  \
00538       /* close the stream */  \
00539       NI_stream_close( m_ns ) ; \
00540    }  \
00541 }
00542 #define DSET_WRITE_1D_PURE(dset, frm, suc) { \
00543    FILE *m_fid = NULL;  \
00544    int m_ind, m_ival;   \
00545    int m_allnum;  \
00546    suc = 1; \
00547    m_allnum = SUMA_is_AllNumeric_dset(dset);   \
00548    if (!m_allnum) { \
00549       SUMA_SL_Err ("Element cannont be written to 1D format");    \
00550       suc = 0; \
00551    } else {   \
00552       m_fid = fopen(frm,"w"); \
00553       if( m_fid == NULL ) {    \
00554          SUMA_SL_Err ("Failed to open file for output");  \
00555          suc = 0; \
00556       } else { \
00557          for (m_ival=0; m_ival<dset->dnel->vec_len; ++m_ival) { \
00558             for (m_ind=0; m_ind<dset->dnel->vec_num; ++m_ind) { \
00559                fprintf(m_fid,"%f   ", SUMA_GetDsetValInCol2(dset, m_ind, m_ival));  \
00560             }  \
00561             fprintf(m_fid,"\n"); \
00562          }  \
00563          fclose(m_fid); m_fid = NULL;  \
00564       }  \
00565    }\
00566 }
00567 
00568 #define NEL_WRITE_1D(nel, frm, suc) { \
00569    NI_stream m_ns = NULL;  \
00570    int m_tt = NI_element_type((void*)nel) ; \
00571    int m_allnum;  \
00572    suc = 1; \
00573    if (m_tt == NI_GROUP_TYPE) { m_allnum = 0; SUMA_SL_Err ("Group, use DSET_WRITE_1D_PURE"); }/* SHOULD USE DSET_WRITE_1D */   \
00574    else m_allnum = SUMA_is_AllNumeric_nel(nel);   \
00575    if (!m_allnum) { \
00576       SUMA_SL_Err ("Element cannont be written to 1D format");    \
00577       suc = 0; \
00578    } else {   \
00579       m_ns = NI_stream_open( frm , "w" ) ;   \
00580       if( m_ns == NULL ) {    \
00581          SUMA_SL_Err ("Failed to open stream");  \
00582          suc = 0; \
00583       } else { \
00584          /* write out the element */   \
00585          if (NI_write_element( m_ns , nel , NI_TEXT_MODE | NI_HEADERSHARP_FLAG) < 0) { \
00586             SUMA_SL_Err ("Failed to write element");  \
00587             suc = 0; \
00588          }  \
00589       }  \
00590       /* close the stream */  \
00591       NI_stream_close( m_ns ) ; \
00592    }  \
00593 }
00594 
00595 /*!
00596    NEL_WRITE* macros are left for the record, they should not be used 
00597 */
00598 #define NEL_WRITE_1D_PURE(nel, frm, suc) { \
00599    FILE *m_fid = NULL;  \
00600    int m_ind, m_ival;   \
00601    int m_tt = NI_element_type((void*)nel) ; \
00602    int m_allnum;  \
00603    suc = 1; \
00604    if (m_tt == NI_GROUP_TYPE) { m_allnum = 0;  SUMA_SL_Err ("Group, use DSET_WRITE_1D_PURE"); }   /* SHOULD USE DSET_WRITE_1D */  \
00605    else m_allnum = SUMA_is_AllNumeric_nel(nel);   \
00606    if (!m_allnum) { \
00607       SUMA_SL_Err ("Element cannont be written to 1D format");    \
00608       suc = 0; \
00609    } else {   \
00610       m_fid = fopen(frm,"w"); \
00611       if( m_fid == NULL ) {    \
00612          SUMA_SL_Err ("Failed to open file for output");  \
00613          suc = 0; \
00614       } else { \
00615          for (m_ival=0; m_ival<nel->vec_len; ++m_ival) { \
00616             for (m_ind=0; m_ind<nel->vec_num; ++m_ind) { \
00617                fprintf(m_fid,"%f   ", SUMA_GetValInCol2(nel, m_ind, m_ival));  \
00618             }  \
00619             fprintf(m_fid,"\n"); \
00620          }  \
00621          fclose(m_fid); m_fid = NULL;  \
00622       }  \
00623    }\
00624 }
00625 
00626 #define NEL_WRITE_BI(nel, frm, suc) { \
00627    NI_stream m_ns = NULL;  \
00628    suc = 1; \
00629    m_ns = NI_stream_open( frm , "w" ) ;   \
00630    if( m_ns == NULL ) {    \
00631       SUMA_SL_Err ("Failed to open stream");  \
00632       suc = 0; \
00633    } else { \
00634       /* write out the element */   \
00635       if (NI_write_element( m_ns , nel , NI_BINARY_MODE) < 0) { \
00636          SUMA_SL_Err ("Failed to write element");  \
00637          suc = 0; \
00638       }  \
00639    }  \
00640    /* close the stream */  \
00641    NI_stream_close( m_ns ) ; \
00642 }
00643 
00644 /*!
00645    get a string positioned in column col, row row in NI_element * nel.
00646    str is a copy of the pointer to that string and must not be freed
00647 */
00648 #define SUMA_NEL_GET_STRING(nel, row, col, str) {\
00649    char **m_rc;   \
00650    m_rc = (char **)(nel)->vec[(col)]; \
00651    str = m_rc[(row)];\
00652 }
00653 /*!
00654    replace a string positioned in column col, row row in NI_element * nel.
00655    str is a copy of the pointer to that string and must not be freed
00656 */
00657 #define SUMA_NEL_REPLACE_STRING(nel, row, col, str) {\
00658    char **m_rc;   \
00659    m_rc = (char **)(nel)->vec[(col)]; \
00660    if (m_rc[(row)]) NI_free(m_rc[(row)]); \
00661    m_rc[(row)] = NULL;\
00662    if (str) { \
00663       m_rc[(row)] = (char*)NI_malloc(char, (strlen((str))+1)*sizeof(char));\
00664       strcpy( m_rc[(row)], str );   \
00665    }  \
00666 }
00667 
00668 
00669 NI_element *SUMA_FindDsetDataAttributeElement(SUMA_DSET *dset);
00670 NI_element *SUMA_FindDsetAttributeElement(SUMA_DSET *dset, char *attname);
00671 NI_element *SUMA_FindNgrAttributeElement(NI_group *ngr, char *attname);
00672 float SUMA_LatestVersionNumber(void);
00673 char * SUMA_Dset_Type_Name (SUMA_DSET_TYPE tp);
00674 SUMA_DSET_TYPE SUMA_Dset_Type (char *Name);
00675 char * SUMA_Col_Type_Name (SUMA_COL_TYPE tp);
00676 SUMA_COL_TYPE SUMA_Col_Type (char *Name);
00677 char * SUMA_AttrOfDsetColNumb(SUMA_DSET *dset, int ind);
00678 SUMA_COL_TYPE SUMA_TypeOfDsetColNumb(SUMA_DSET *dset, int ind);
00679 SUMA_COL_TYPE SUMA_TypeOfColNumb(NI_element *nel, int ind) ;
00680 SUMA_VARTYPE SUMA_ColType2TypeCast (SUMA_COL_TYPE ctp); 
00681 int SUMA_ShowNel (NI_element *nel);
00682 void SUMA_allow_nel_use(int al);
00683 int SUMA_AddDsetNelCol ( SUMA_DSET *dset, char *col_label, 
00684                      SUMA_COL_TYPE ctp, void *col, 
00685                      void *col_attr, int stride);
00686 int SUMA_AddNelCol ( NI_element *nel, char *col_label,
00687                      SUMA_COL_TYPE ctp, void *col, 
00688                      void *col_attr, int stride);
00689 int SUMA_AddDsetColAttr (SUMA_DSET *dset, char *col_label, 
00690                      SUMA_COL_TYPE ctp, void *col_attr, int col_index);
00691 int SUMA_AddColAttr (NI_element *nel, char *col_label,
00692                      SUMA_COL_TYPE ctp, void *col_attr, int col_index);
00693 SUMA_Boolean SUMA_NewDsetGrp (SUMA_DSET *dset, SUMA_DSET_TYPE dtp, 
00694                            char* MeshParent_idcode, 
00695                           char * GeomParent_idcode, int N_el, 
00696                           char *filename, char *thisidcode);
00697 NI_element * SUMA_NewNel (SUMA_DSET_TYPE dtp, char* MeshParent_idcode, 
00698                           char * GeomParent_idcode, int N_el, 
00699                           char *name, char *thisidcode);
00700 SUMA_DSET_FORMAT SUMA_Dset_Format (char *Name);
00701 char * SUMA_Dset_Format_Name (SUMA_DSET_FORMAT fr);
00702 char *SUMA_HistString (char *CallingFunc, int N_arg, char **arg, char *sold);
00703 char * SUMA_GetNgrHist(NI_group *ngr);
00704 int SUMA_AddNgrHist(NI_group *ngr, char *CallingFunc, int N_arg, char **arg);
00705 int SUMA_AddNelHist(NI_element *nel, char *CallingFunc, int N_arg, char **arg);
00706 void SUMA_FreeDset(void *dset);
00707 SUMA_DSET * SUMA_FindDset (char *idcode_str, DList *DsetList);
00708 char *SUMA_DsetInfo (SUMA_DSET *dset, int detail);
00709 void SUMA_ShowDset (SUMA_DSET *dset, int detail, FILE *out);
00710 char *SUMA_ShowMeSome (void *dt, SUMA_VARTYPE tp, int N_dt, int mxshow);
00711 SUMA_DSET * SUMA_NewDsetPointer(void);
00712 SUMA_DSET * SUMA_CreateDsetPointer (  
00713                               char *name, 
00714                               SUMA_DSET_TYPE tp,
00715                               char *idcode_str,
00716                               char *domain_idcode_str,
00717                               int N_Alloc); 
00718 int SUMA_InsertDsetPointer (SUMA_DSET *dset, DList *DsetList);
00719 void * SUMA_GetCx(char *idcode_str, DList *DsetList, int ReturnDsetPointer) ;
00720 #if 0
00721 SUMA_DSET *SUMA_LinkToDset(SUMA_DSET *dset);
00722 SUMA_DSET *SUMA_UnlinkFromDset(SUMA_DSET *dset);
00723 #endif
00724 void *SUMA_LinkToPointer(void *ptr);
00725 void *SUMA_UnlinkFromPointer(void *ptr);
00726 int * SUMA_GetNodeDef(SUMA_DSET *dset);
00727 int SUMA_FillDsetNelCol (SUMA_DSET *dset, char *col_label,
00728                      SUMA_COL_TYPE ctp, void *col, 
00729                      void *col_attr, int stride); 
00730 int SUMA_FillNelCol (NI_element *nel, char *col_label,
00731                      SUMA_COL_TYPE ctp, void *col, 
00732                      void *col_attr, int stride); 
00733 int *SUMA_GetDsetColIndex (SUMA_DSET *dset, SUMA_COL_TYPE tp, int *N_i);
00734 int *SUMA_GetColIndex (NI_element *nel, SUMA_COL_TYPE tp, int *N_i);
00735 float * SUMA_DsetCol2Float (SUMA_DSET *dset, int ind, int FilledOnly);
00736 float * SUMA_Col2Float (NI_element *nel, int ind, int FilledOnly);
00737 int SUMA_GetDsetColRange(SUMA_DSET *dset, int col_index, float range[2], int loc[2]);
00738 int SUMA_GetColRange(NI_element *nel, int col_index, float range[2], int loc[2]);
00739 int SUMA_AddGenDsetColAttr (SUMA_DSET *dset, SUMA_COL_TYPE ctp, void *col, int stride, int col_index);
00740 int SUMA_AddGenColAttr (NI_element *nel, SUMA_COL_TYPE ctp, void *col, int stride, int col_index); 
00741 SUMA_DSET *SUMA_LoadNimlDset (char *Name, int verb);
00742 SUMA_DSET *SUMA_LoadDset (char *Name, SUMA_DSET_FORMAT *form, int verb);
00743 SUMA_DSET *SUMA_Load1DDset (char *Name, int verb);
00744 SUMA_DSET *SUMA_LoadDXDset (char *Name, int verb);
00745 char *SUMA_RemoveDsetExtension (char*Name, SUMA_DSET_FORMAT form);
00746 char * SUMA_WriteDset (char *Name, SUMA_DSET *dset, SUMA_DSET_FORMAT form, int overwrite, int verb); 
00747 SUMA_DSET * SUMA_far2dset( char *FullName, char *dset_id, char *dom_id, 
00748                                  float **farp, int vec_len, int vec_num, 
00749                                  int ptr_cpy);
00750 int SUMA_is_AllNumeric_dset(SUMA_DSET *dset); 
00751 int SUMA_is_AllNumeric_ngr(NI_group *ngr) ;
00752 int SUMA_is_AllNumeric_nel(NI_element *nel);
00753 SUMA_Boolean SUMA_NewDsetID (SUMA_DSET *dset);
00754 char *SUMA_DsetColLabelCopy(SUMA_DSET *dset, int i, int addcolnum);
00755 char *SUMA_ColLabelCopy(NI_element *nel, int i, int addcolnum);
00756 SUMA_DSET * SUMA_MaskedCopyofDset(SUMA_DSET *odset, byte *rowmask, byte *colmask, int masked_only, int keep_node_index);
00757 void *SUMA_Copy_Part_Column(void *col,  NI_rowtype *rt, int N_col, byte *rowmask, int masked_only, int *n_incopy);
00758 char* SUMA_sdset_id(SUMA_DSET *dset);
00759 char* SUMA_sdset_idmdom(SUMA_DSET *dset);
00760 NI_group *SUMA_oDsetNel2nDsetNgr(NI_element *nel); 
00761 void SUMA_SetParent_DsetToLoad(char *parent);
00762 /*********************** BEGIN Miscellaneous support functions **************************** */
00763 #ifdef SUMA_COMPILED
00764    #define SUMA_STANDALONE_INIT {   \
00765       /* install signal handler, shamelessly copied from AFNI) */ \
00766       signal(SIGINT ,SUMA_sigfunc) ;      \
00767       signal(SIGBUS ,SUMA_sigfunc) ;   \
00768       signal(SIGSEGV,SUMA_sigfunc) ;   \
00769       signal(SIGTERM,SUMA_sigfunc) ;   \
00770       SUMA_process_environ(); \
00771          SUMAg_CF = SUMA_Create_CommonFields ();   \
00772               if (SUMAg_CF == NULL) { \
00773                       fprintf(SUMA_STDERR,"Error %s: Failed in SUMA_Create_CommonFields\n", FuncName); \
00774                       exit(1); \
00775               }  \
00776          /* SUMAg_CF->scm = SUMA_Build_Color_maps();  require X connection*/\
00777       SUMA_ParseInput_basics (argv, argc);   \
00778    }
00779 #else
00780    #define SUMA_STANDALONE_INIT {   \
00781       /* install signal handler, shamelessly copied from AFNI) */ \
00782       signal(SIGINT ,SUMA_sigfunc) ;      \
00783       signal(SIGBUS ,SUMA_sigfunc) ;   \
00784       signal(SIGSEGV,SUMA_sigfunc) ;   \
00785       signal(SIGTERM,SUMA_sigfunc) ;   \
00786       SUMA_process_environ(); \
00787       SUMA_ParseInput_basics (argv, argc);   \
00788    }
00789 
00790 #endif   
00791 
00792 int SUMA_filexists (char *f_name);
00793 char *SUMA_help_basics();
00794 char *SUMA_help_talk();
00795 void SUMA_process_environ(void);
00796 void SUMA_ParseInput_basics (char *argv[], int argc); 
00797 SUMA_FileName SUMA_StripPath (char *FileName);
00798 SUMA_PARSED_NAME * SUMA_ParseFname (char *FileName);
00799 char *SUMA_Extension(char *filename, char *ext, SUMA_Boolean Remove);
00800 SUMA_DSET_FORMAT SUMA_GuessFormatFromExtension(char *Name);
00801 SUMA_Boolean SUMA_isExtension(char *filename, char *ext);
00802 void *SUMA_Free_Parsed_Name(SUMA_PARSED_NAME *Test);
00803 int SUMA_StringToNum (char *s, float *fv, int N);
00804 int SUMA_isNumString (char *s, void *p);
00805 char *SUMA_copy_string(char *buf);
00806 char * SUMA_append_string(char *s1, char *s2);
00807 char * SUMA_append_replace_string(  char *s1, char *s2, 
00808                                     char *Spc, int whichTofree);
00809 char * SUMA_truncate_string (char *s1, int length);
00810 char *SUMA_set_string_length(char *buf, char cp, int n);
00811 SUMA_STRING * SUMA_StringAppend (SUMA_STRING *SS, char *newstring);
00812 SUMA_STRING * SUMA_StringAppend_va (SUMA_STRING *SS, char *newstring, ... );
00813 void SUMA_sigfunc(int sig);
00814 char *SUMA_pad_string(char *buf, char cp, int n, int add2end);
00815 char * SUMA_GetDsetValInCol(SUMA_DSET *dset, int ind, int ival, double *dval) ;
00816 char * SUMA_GetValInCol(NI_element *nel, int ind, int ival, double *dval); 
00817 double SUMA_GetDsetValInCol2(SUMA_DSET *dset, int ind, int ival) ;
00818 double SUMA_GetValInCol2(NI_element *nel, int ind, int ival); 
00819 int SUMA_GetNodeRow_FromNodeIndex(SUMA_DSET *dset, int node, int N_Node);
00820 int SUMA_GetNodeIndex_FromNodeRow(SUMA_DSET *dset, int row, int N_Node);
00821 NI_str_array *SUMA_free_NI_str_array(NI_str_array *nisa);
00822 NI_str_array *SUMA_comp_str_2_NI_str_ar(char *s, char *sep);
00823 char *SUMA_NI_str_ar_2_comp_str (NI_str_array *nisa, char *sep);
00824 NI_str_array *SUMA_free_NI_str_array(NI_str_array *nisa);
00825 char *SUMA_Get_Sub_String(char *cs, char *sep, int ii);
00826 int SUMA_AddColAtt_CompString(NI_element *nel, int col, char *lbl, char *sep);
00827 NI_str_array * SUMA_NI_decode_string_list( char *ss , char *sep );
00828 char  * SUMA_NI_get_ith_string( char *ss , char *sep, int i );
00829 SUMA_VARTYPE SUMA_VarType2TypeCast (char *vt);
00830 SUMA_COL_TYPE SUMA_VarType2ColType (char *vt);
00831 int SUMA_SizeOf(SUMA_VARTYPE vt);
00832 void *SUMA_BinarySuck(char *fname, SUMA_VARTYPE data_type, int endian, int start, int end, int *nvals_read);
00833 void SUMA_swap_2(void *ppp);
00834 void SUMA_swap_4(void *ppp);
00835 void SUMA_swap_8(void *ppp);
00836 
00837 /*********************** END Miscellaneous support functions **************************** */
00838 
00839 
00840 #endif
 

Powered by Plone

This site conforms to the following standards: