Doxygen Source Code Documentation
niml_dtable.c File Reference
#include "niml_private.h"#include <math.h>Go to the source code of this file.
Functions | |
| Dtable * | new_Dtable (int len) |
| void | destroy_Dtable (Dtable *dt) |
| void | addto_Dtable (char *str_a, char *str_b, Dtable *dt) |
| char * | findin_Dtable_a (char *str_a, Dtable *dt) |
| char * | findin_Dtable_b (char *str_b, Dtable *dt) |
| void | removefrom_Dtable_a (char *str_a, Dtable *dt) |
| void | removefrom_Dtable_b (char *str_b, Dtable *dt) |
| int | listize_Dtable (Dtable *dt, char ***list_a, char ***list_b) |
| char * | Dtable_to_nimlstring (Dtable *dt, char *name) |
| Dtable * | Dtable_from_nimlstring (char *nstr) |
Function Documentation
|
||||||||||||||||
|
Insert string pair str_a,str_b into the Dtable. Copies of the strings are made. ------------------------------------------------------------------- Definition at line 40 of file niml_dtable.c. References addto_Htable(), dt, Dtable::hta, Dtable::htb, and sb. Referenced by DRAW_label_CB(), and Dtable_from_nimlstring().
00041 {
00042 char *sa , *sb ;
00043 if( dt == NULL || str_a == NULL || str_b == NULL ) return ;
00044 sa = strdup(str_a) ; sb = strdup(str_b) ;
00045 addto_Htable( sa , (void *)sb , dt->hta ) ;
00046 addto_Htable( sb , (void *)sa , dt->htb ) ;
00047 return ;
00048 }
|
|
|
Death and destruction of a Dtable. ------------------------------------------------------------------- Definition at line 25 of file niml_dtable.c. References destroy_Htable(), dt, Dtable::hta, Htable_set_vtkill(), and Dtable::htb. Referenced by DRAW_finalize_dset_CB(), DRAW_label_getfile(), and DRAW_main().
00026 {
00027 if( dt == NULL ) return ;
00028 Htable_set_vtkill(1) ;
00029 destroy_Htable( dt->hta ) ;
00030 destroy_Htable( dt->htb ) ;
00031 Htable_set_vtkill(0) ; ;
00032 return ;
00033 }
|
|
|
Definition at line 164 of file niml_dtable.c. References addto_Dtable(), dt, l, new_Dtable(), NI_ELEMENT_TYPE, NI_element_type(), NI_free_element(), NI_read_element(), NI_stream_close(), NI_stream_open(), NI_stream_setbuf(), NI_STRING, NI_element::vec, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by DRAW_finalize_dset_CB(), and DRAW_label_getfile().
00165 {
00166 NI_stream ns ;
00167 NI_element *nel ;
00168 int nn , ii ;
00169 Dtable *dt ;
00170 char **la , **lb ;
00171
00172 if( nstr == NULL || *nstr == '\0' ) return NULL ;
00173
00174 /* convert string to a NIML element */
00175
00176 ns = NI_stream_open( "str:" , "r" ) ;
00177 NI_stream_setbuf( ns , nstr ) ;
00178 nel = (NI_element *)NI_read_element( ns , 1 ) ;
00179 NI_stream_close( ns ) ;
00180 if( nel == NULL ) return NULL ;
00181
00182 /* see if element is OK for this purpose */
00183
00184 if( NI_element_type(nel) != NI_ELEMENT_TYPE ){
00185 NI_free_element(nel) ; return NULL ;
00186 }
00187
00188 if( nel->vec_len < 1 || /* empty element? */
00189 nel->vec_filled < 1 || /* no data was filled in? */
00190 nel->vec_num < 2 || /* less than 4 columns? */
00191 nel->vec_typ[0] != NI_STRING || /* must be String, String */
00192 nel->vec_typ[1] != NI_STRING ){
00193
00194 NI_free_element(nel) ; return NULL ;
00195 }
00196
00197 la = (char **) nel->vec[0] ; /* first column of String */
00198 lb = (char **) nel->vec[1] ; /* second column of String */
00199
00200 nn = nel->vec_filled ;
00201 ii = rint(sqrt(2*nn+1.0l)) ;
00202 if( ii < 7 ) ii = 7 ; else if( ii%2 == 0 ) ii++ ;
00203
00204 /* make table, insert strings */
00205
00206 dt = new_Dtable( ii ) ;
00207 for( ii=0 ; ii < nn ; ii++ )
00208 addto_Dtable( la[ii] , lb[ii] , dt ) ;
00209
00210 NI_free_element(nel) ; return dt ;
00211 }
|
|
||||||||||||
|
Definition at line 134 of file niml_dtable.c. References dt, free, listize_Dtable(), name, NI_add_column(), NI_free_element(), NI_new_data_element(), NI_stream_close(), NI_stream_getbuf(), NI_stream_open(), NI_STRING, NI_TEXT_MODE, and NI_write_element(). Referenced by DRAW_attach_dtable(), and dump_vallab().
00135 {
00136 int nn , ii ;
00137 char **la , **lb , *stout ;
00138 NI_element *nel ;
00139 NI_stream ns ;
00140
00141 nn = listize_Dtable( dt , &la , &lb ) ;
00142 if( nn == 0 || la == NULL || lb == NULL ) return (char *)NULL ;
00143
00144 if( name == NULL || *name == '\0' ) name = "Dtable" ;
00145
00146 nel = NI_new_data_element( name , nn ) ;
00147 NI_add_column( nel , NI_STRING , la ) ;
00148 NI_add_column( nel , NI_STRING , lb ) ;
00149 free(la) ; free(lb) ;
00150
00151 ns = NI_stream_open( "str:" , "w" ) ;
00152 (void) NI_write_element( ns , nel , NI_TEXT_MODE ) ;
00153 NI_free_element( nel ) ;
00154 stout = strdup( NI_stream_getbuf(ns) ) ;
00155 NI_stream_close( ns ) ;
00156 nn = strlen(stout) ;
00157 for( ii=nn-1 ; ii > 0 && isspace(stout[ii]) ; ii-- ) ; /* trailing blanks */
00158 stout[ii+1] = '\0' ;
00159 return stout ;
00160 }
|
|
||||||||||||
|
Definition at line 52 of file niml_dtable.c. References dt, findin_Htable(), and Dtable::hta. Referenced by DRAW_label_CB(), and DRAW_set_value_label().
00053 {
00054 if( dt == NULL || str_a == NULL ) return NULL ;
00055 return (char *)findin_Htable( str_a , dt->hta ) ;
00056 }
|
|
||||||||||||
|
Definition at line 60 of file niml_dtable.c. References dt, findin_Htable(), and Dtable::htb. Referenced by DRAW_label_CB().
00061 {
00062 if( dt == NULL || str_b == NULL ) return NULL ;
00063 return (char *)findin_Htable( str_b , dt->htb ) ;
00064 }
|
|
||||||||||||||||
|
Definition at line 107 of file niml_dtable.c. References Htable::ctab, dt, Dtable::hta, Htable::len, Htable::ntab, realloc, sb, and Htable::vtab. Referenced by DRAW_label_EV(), and Dtable_to_nimlstring().
00108 {
00109 char **la=NULL , **lb=NULL , *sa,*sb ;
00110 int jj,kk,nn ;
00111 Htable *ht ;
00112
00113 if( dt == NULL || list_a == NULL || list_b == NULL ) return 0 ;
00114
00115 ht = dt->hta ;
00116
00117 for( nn=jj=0 ; jj < ht->len ; jj++ ){
00118 if( ht->vtab[jj] == NULL ) continue ;
00119 for( kk=0 ; kk < ht->ntab[jj] ; kk++ ){
00120 sa = (char *) ht->ctab[jj][kk] ; if( sa == NULL ) continue ;
00121 sb = (char *) ht->vtab[jj][kk] ; if( sb == NULL ) continue ;
00122 la = (char **) realloc( (void *)la , sizeof(char *)*(nn+1) ) ;
00123 lb = (char **) realloc( (void *)lb , sizeof(char *)*(nn+1) ) ;
00124 la[nn] = sa ; lb[nn] = sb ; nn++ ;
00125 }
00126 }
00127 *list_a = la ; *list_b = lb ; return nn ;
00128 }
|
|
|
Create a Dtable with len slots. ------------------------------------------------------------------- Definition at line 12 of file niml_dtable.c. References calloc, dt, Dtable::hta, Dtable::htb, and new_Htable(). Referenced by DRAW_label_CB(), and Dtable_from_nimlstring().
00013 {
00014 Dtable *dt ;
00015 dt = (Dtable *) calloc( 1 , sizeof(Dtable) ) ;
00016 dt->hta = new_Htable( len ) ;
00017 dt->htb = new_Htable( len ) ;
00018 return dt ;
00019 }
|
|
||||||||||||
|
Definition at line 68 of file niml_dtable.c. References dt, findin_Htable(), free, Dtable::hta, Dtable::htb, and removefrom_Htable(). Referenced by DRAW_label_CB().
00069 {
00070 char *str_bb , *str_aa ;
00071 if( dt == NULL ) return ;
00072 str_bb = (char *)findin_Htable( str_a , dt->hta ) ;
00073 if( str_bb == NULL ) return ;
00074 str_aa = (char *)findin_Htable( str_bb, dt->htb ) ;
00075 removefrom_Htable( str_a , dt->hta ) ;
00076 removefrom_Htable( str_bb, dt->htb ) ;
00077
00078 /* must also remove dangling targets from each Htable */
00079
00080 free((void *)str_bb) ; if( str_aa != NULL ) free((void *)str_aa) ;
00081 return ;
00082 }
|
|
||||||||||||
|
Definition at line 86 of file niml_dtable.c. References dt, findin_Htable(), free, Dtable::hta, Dtable::htb, and removefrom_Htable().
00087 {
00088 char *str_aa , *str_bb ;
00089 if( dt == NULL ) return ;
00090 str_aa = (char *)findin_Htable( str_b , dt->htb ) ;
00091 if( str_aa == NULL ) return ;
00092 str_bb = (char *)findin_Htable( str_aa, dt->hta ) ;
00093 removefrom_Htable( str_b , dt->htb ) ;
00094 removefrom_Htable( str_aa, dt->hta ) ;
00095
00096 free((void *)str_aa) ; if( str_bb != NULL ) free((void *)str_bb) ;
00097 return ;
00098 }
|