Doxygen Source Code Documentation
suma_niml.c File Reference
#include "niml.h"
#include "suma_types.h"
Go to the source code of this file.
Functions | |
NI_element * | SUMA_ixyz_to_NIML (int num_ixyz, SUMA_ixyz *ixyz) |
int | NIML_to_SUMA_ixyz (NI_element *nel, SUMA_ixyz **ixyz) |
Function Documentation
|
Unload a <SUMA_ixyz> NI_element into an array of newly malloc()-ed SUMA_ixyz structs. Return value is number of structs (will be 0 inputs are bad). ixyz will point to the output array if the number of structs is positive. This array will be newly malloc()-ed. Example:
Definition at line 73 of file suma_niml.c. References SUMA_ixyz::id, NI_FLOAT, NI_INT, NI_malloc, NI_element::vec, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, NI_element::vec_typ, SUMA_ixyz::x, xc, SUMA_ixyz::y, yc, and SUMA_ixyz::z.
00074 { 00075 int num_ixyz ; /* return value */ 00076 SUMA_ixyz *myixyz ; /* output array of structs */ 00077 int *ic , ii ; 00078 float *xc, *yc, *zc ; 00079 00080 /* check element for correctness */ 00081 00082 if( nel == 0 || /* no data element? */ 00083 nel->vec_len < 1 || /* empty element? */ 00084 nel->vec_filled < 1 || /* no data was filled in? */ 00085 nel->vec_num < 4 || /* less than 4 columns? */ 00086 nel->vec_typ[0] != NI_INT || /* must be int,float,float,float */ 00087 nel->vec_typ[1] != NI_FLOAT || 00088 nel->vec_typ[2] != NI_FLOAT || 00089 nel->vec_typ[3] != NI_FLOAT ) return 0 ; /* bad bad bad */ 00090 00091 /* number of structs is number of completely filled rows */ 00092 00093 num_ixyz = nel->vec_filled ; 00094 00095 /* make space for the new structs */ 00096 00097 myixyz = NI_malloc(SUMA_ixyz, sizeof(SUMA_ixyz) * num_ixyz ) ; 00098 00099 /* pointers to the data columns in the NI_element */ 00100 00101 ic = (int *) nel->vec[0] ; 00102 xc = (float *) nel->vec[1] ; 00103 yc = (float *) nel->vec[2] ; 00104 zc = (float *) nel->vec[3] ; 00105 00106 /* load the values from the element */ 00107 00108 for( ii=0 ; ii < num_ixyz ; ii++ ){ 00109 myixyz[ii].id = ic[ii] ; 00110 myixyz[ii].x = xc[ii] ; 00111 myixyz[ii].y = yc[ii] ; 00112 myixyz[ii].z = zc[ii] ; 00113 } 00114 00115 /* we is done */ 00116 00117 *ixyz = myixyz ; return num_ixyz ; 00118 } |
|
Make a NIML data element from an array of SUMA_ixyz structs. Return value is NULL if you input stupid values. Otherwise, will return a populated element. Example:
Definition at line 18 of file suma_niml.c. References free, SUMA_ixyz::id, NI_add_column(), NI_FLOAT, NI_INT, NI_malloc, NI_new_data_element(), SUMA_ixyz::x, xc, SUMA_ixyz::y, yc, and SUMA_ixyz::z.
00019 { 00020 NI_element *nel ; 00021 int ii , *ic ; 00022 float *xc,*yc,*zc ; 00023 00024 /* check inputs for sanity */ 00025 00026 if( num_ixyz < 1 || ixyz == NULL ) return NULL ; /* stupid caller */ 00027 00028 /* make a new data element, to be filled by columns */ 00029 00030 nel = NI_new_data_element( "SUMA_ixyz" , num_ixyz ) ; 00031 00032 /* make the temp columns to be put in the element */ 00033 00034 ic = NI_malloc(int, sizeof(int) * num_ixyz ) ; 00035 xc = NI_malloc(float, sizeof(float) * num_ixyz ) ; 00036 yc = NI_malloc(float, sizeof(float) * num_ixyz ) ; 00037 zc = NI_malloc(float, sizeof(float) * num_ixyz ) ; 00038 00039 /* load these columns from the struct array */ 00040 00041 for( ii=0 ; ii < num_ixyz ; ii++ ){ 00042 ic[ii] = ixyz[ii].id ; 00043 xc[ii] = ixyz[ii].x ; 00044 yc[ii] = ixyz[ii].y ; 00045 zc[ii] = ixyz[ii].z ; 00046 } 00047 00048 /* copy columns into NI_element, freeing them when done */ 00049 00050 NI_add_column( nel , NI_INT , ic ) ; free(ic) ; 00051 NI_add_column( nel , NI_FLOAT , xc ) ; free(xc) ; 00052 NI_add_column( nel , NI_FLOAT , yc ) ; free(yc) ; 00053 NI_add_column( nel , NI_FLOAT , zc ) ; free(zc) ; 00054 00055 return nel ; 00056 } |