Doxygen Source Code Documentation
nisurf.c File Reference
#include "niml.h"Go to the source code of this file.
Data Structures | |
| struct | AGNI_nod |
Functions | |
| NI_element * | AGNI_nod_to_NIML_col (int num_nod, AGNI_nod *nod) |
| NI_element * | AGNI_nod_to_NIML_row (int num_nod, AGNI_nod *nod) |
| NI_element * | AGNI_nod_to_NIML_rows (int num_nod, AGNI_nod *nod) |
| int | main (int argc, char *argv[]) |
| int | NIML_to_AGNI_nod (NI_element *nel, AGNI_nod **nod) |
Function Documentation
|
||||||||||||
|
Make a NIML data element from an array of AGNI_nod structs. Return value is NULL if you input stupid values. -------------------------------------------------------------------- Definition at line 173 of file nisurf.c. References free, AGNI_nod::id, malloc, NI_add_column(), NI_FLOAT, NI_INT, NI_new_data_element(), AGNI_nod::x, xc, AGNI_nod::y, yc, and AGNI_nod::z. Referenced by main().
00174 {
00175 NI_element *nel ;
00176 int ii ;
00177 int *ic ; float *xc,*yc,*zc ;
00178
00179 /* check inputs for sanity */
00180
00181 if( num_nod < 1 || nod == NULL ) return NULL ;
00182
00183 /* make a new data element, to be filled by columns */
00184
00185 nel = NI_new_data_element( "surfixyz_col" , num_nod ) ;
00186
00187 /* make the columns to be put in the element */
00188
00189 ic = (int *) malloc( sizeof(int) * num_nod ) ;
00190 xc = (float *) malloc( sizeof(float) * num_nod ) ;
00191 yc = (float *) malloc( sizeof(float) * num_nod ) ;
00192 zc = (float *) malloc( sizeof(float) * num_nod ) ;
00193
00194 /* load the columns from the struct array */
00195
00196 for( ii=0 ; ii < num_nod ; ii++ ){
00197 ic[ii] = nod[ii].id ;
00198 xc[ii] = nod[ii].x ;
00199 yc[ii] = nod[ii].y ;
00200 zc[ii] = nod[ii].z ;
00201 }
00202
00203 /* put columns into element */
00204
00205 NI_add_column( nel , NI_INT , ic ) ; free(ic) ;
00206 NI_add_column( nel , NI_FLOAT , xc ) ; free(xc) ;
00207 NI_add_column( nel , NI_FLOAT , yc ) ; free(yc) ;
00208 NI_add_column( nel , NI_FLOAT , zc ) ; free(zc) ;
00209
00210 return nel ;
00211 }
|
|
||||||||||||
|
Make a NIML data element from an array of AGNI_nod structs. Return value is NULL if you input stupid values. -------------------------------------------------------------------- Definition at line 104 of file nisurf.c. References NI_FLOAT, NI_INT, NI_new_data_element(), and offsetof. Referenced by main().
00105 {
00106 NI_element *nel ;
00107 int ii ;
00108
00109 /* check inputs for sanity */
00110
00111 if( num_nod < 1 || nod == NULL ) return NULL ;
00112
00113 /* make a new data element, to be filled by rows */
00114
00115 nel = NI_new_data_element( "surfixyz_row" , -1 ) ;
00116
00117 /* define the mapping from struct components to element columns */
00118
00119 NI_define_rowmap_VA( nel ,
00120 NI_INT , offsetof(AGNI_nod,id) ,
00121 NI_FLOAT , offsetof(AGNI_nod,x) ,
00122 NI_FLOAT , offsetof(AGNI_nod,y) ,
00123 NI_FLOAT , offsetof(AGNI_nod,z) ,
00124 -1 ) ;
00125
00126 /* load the structs, one row at a time */
00127
00128 for( ii=0 ; ii < num_nod ; ii++ )
00129 NI_add_row( nel , nod+ii ) ;
00130
00131 return nel ;
00132 }
|
|
||||||||||||
|
Make a NIML data element from an array of AGNI_nod structs. Return value is NULL if you input stupid values. -------------------------------------------------------------------- Definition at line 139 of file nisurf.c. References NI_FLOAT, NI_INT, NI_new_data_element(), offsetof, xc, and yc. Referenced by main().
00140 {
00141 NI_element *nel ;
00142 int ii ;
00143 int *ic ; float *xc,*yc,*zc ;
00144
00145 /* check inputs for sanity */
00146
00147 if( num_nod < 1 || nod == NULL ) return NULL ;
00148
00149 /* make a new data element, to be filled by rows */
00150
00151 nel = NI_new_data_element( "surfixyz_rows" , -1 ) ;
00152
00153 /* define the mapping from struct components to element columns */
00154
00155 NI_define_rowmap_VA( nel ,
00156 NI_INT , offsetof(AGNI_nod,id) ,
00157 NI_FLOAT , offsetof(AGNI_nod,x) ,
00158 NI_FLOAT , offsetof(AGNI_nod,y) ,
00159 NI_FLOAT , offsetof(AGNI_nod,z) , -1 ) ;
00160
00161 /* load all the rows at once */
00162
00163 NI_add_many_rows( nel , num_nod , sizeof(AGNI_nod) , nod ) ;
00164
00165 return nel ;
00166 }
|
|
||||||||||||
|
\** File : SUMA.c
Input paramters :
Definition at line 23 of file nisurf.c. References AGNI_nod_to_NIML_col(), AGNI_nod_to_NIML_row(), AGNI_nod_to_NIML_rows(), argc, AGNI_nod::id, NI_add_to_group(), NI_BASE64_MODE, NI_clock_time(), NI_free_element(), NI_malloc, NI_new_group_element(), NI_stream_open(), NI_TEXT_MODE, NI_write_element(), AGNI_nod::x, AGNI_nod::y, and AGNI_nod::z.
00024 {
00025 int ii, nn, ct, nb ;
00026 AGNI_nod *nod ;
00027 NI_element *nel1, *nel2, *nel3 ;
00028 NI_stream ns ;
00029
00030 if( argc < 2 ){ printf("Usage: nisurf n\n"); exit(0); }
00031
00032 nn = strtol(argv[1],NULL,10) ;
00033 if( nn < 1 ) exit(1) ;
00034
00035 /* make up some fake nodes */
00036
00037 nod = NI_malloc(AGNI_nod, sizeof(AGNI_nod)*nn ) ;
00038 for( ii=0 ; ii < nn ; ii++ ){
00039 nod[ii].id = ii ;
00040 nod[ii].x = 1.1*ii ;
00041 nod[ii].y = 2.2*ii ;
00042 nod[ii].z = 3.3*ii ;
00043 }
00044
00045 /* put nodes into a NIML data element: one row at a time */
00046
00047 ct = NI_clock_time() ; /* start timer */
00048 nel1 = AGNI_nod_to_NIML_row( nn , nod ) ; /* create element by row */
00049 fprintf(stderr,"Clock time for %d nodes by row = %d ms\n",
00050 nn,NI_clock_time()-ct) ;
00051 if( nn < 10 ){ /* print element */
00052 ns = NI_stream_open( "fd:1" , "w" ) ;
00053 if( ns == NULL ){ fprintf(stderr,"Can't open fd:1\n"); exit(1); }
00054 nb = NI_write_element( ns , nel1 , NI_TEXT_MODE ) ;
00055 fprintf(stderr,"num bytes=%d\n\n",nb) ;
00056 }
00057 /* NI_free_element(nel1) ; */ /* free element */
00058
00059 /* put nodes into a NIML data element: all rows at once */
00060
00061 ct = NI_clock_time() ;
00062 nel2 = AGNI_nod_to_NIML_rows( nn , nod ) ;
00063 fprintf(stderr,"Clock time for %d nodes by rows = %d ms\n",
00064 nn,NI_clock_time()-ct) ;
00065 if( nn < 10 ){
00066 nb = NI_write_element( ns , nel2 , NI_TEXT_MODE ) ;
00067 fprintf(stderr,"num bytes=%d\n\n",nb) ;
00068 }
00069 /* NI_free_element(nel2) ; */
00070
00071 /* put nodes into a NIML data element: by columns */
00072
00073 ct = NI_clock_time() ;
00074 nel3 = AGNI_nod_to_NIML_col( nn , nod ) ;
00075 fprintf(stderr,"Clock time for %d nodes by col = %d ms\n",
00076 nn,NI_clock_time()-ct) ;
00077 if( nn < 10 ){
00078 nb = NI_write_element( ns , nel3 , NI_TEXT_MODE ) ;
00079 fprintf(stderr,"num bytes=%d\n\n",nb) ;
00080 }
00081 /* NI_free_element(nel3) ; */
00082
00083 /* play with ni_group */
00084
00085 if( nn < 5 ){
00086 NI_group *ngr = NI_new_group_element() ;
00087 NI_add_to_group( ngr , nel1 ) ;
00088 NI_add_to_group( ngr , nel2 ) ;
00089 NI_add_to_group( ngr , nel3 ) ;
00090 nb = NI_write_element( ns , ngr , NI_BASE64_MODE ) ;
00091 fprintf(stderr,"num bytes=%d\n\n",nb) ;
00092 NI_free_element(ngr) ;
00093 }
00094
00095 fprintf(stderr,"\n*** That's all folks ***\n") ;
00096 exit(0) ;
00097 }
|
|
||||||||||||
|
Unload a <surfixyz> NI_element into an array of newly malloc()-ed AGNI_nod. Return value is number of nodes (will be 0 if an error occurs). nod will point to the output array if the number of nodes is positive. -------------------------------------------------------------------- Definition at line 221 of file nisurf.c. References malloc, NI_FLOAT, NI_INT, offsetof, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ.
00222 {
00223 int num_nod , ii ;
00224 AGNI_nod *mynod ;
00225
00226 /* check element for correctness */
00227
00228 if( nel == 0 || /* no data element? */
00229 nel->vec_len < 1 || /* empty element? */
00230 nel->vec_filled < 1 || /* no data was filled in? */
00231 nel->vec_num < 4 || /* less than 4 columns? */
00232 nel->vec_typ[0] != NI_INT || /* must be int,float,float,float */
00233 nel->vec_typ[1] != NI_FLOAT ||
00234 nel->vec_typ[2] != NI_FLOAT ||
00235 nel->vec_typ[3] != NI_FLOAT ) return 0 ;
00236
00237 /* number of nodes is number of completely filled rows */
00238
00239 num_nod = nel->vec_filled ;
00240
00241 /* make space for the structs */
00242
00243 mynod = (AGNI_nod *) malloc( sizeof(AGNI_nod) * num_nod ) ;
00244
00245 /* define the mapping from struct components to element columns */
00246
00247 NI_define_rowmap_VA( nel ,
00248 NI_INT , offsetof(AGNI_nod,id) ,
00249 NI_FLOAT , offsetof(AGNI_nod,x) ,
00250 NI_FLOAT , offsetof(AGNI_nod,y) ,
00251 NI_FLOAT , offsetof(AGNI_nod,z) ,
00252 -1 ) ;
00253
00254 /* load data from NIML element to the structs */
00255
00256 for( ii=0 ; ii < num_nod ; ii++ )
00257 NI_get_row( nel , ii , mynod+ii ) ;
00258
00259 /* we is done */
00260
00261 *nod = mynod ; return num_nod ;
00262 }
|