source: PSPA/madxPSPA/src/mad_sdds.c @ 430

Last change on this file since 430 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 22.5 KB
Line 
1#include "madx.h"
2
3#ifdef _ONLINE
4
5#include "SDDS.h"
6
7static int
8head_split(char* buf, struct char_p_array* list)
9{
10  /* splits header information into tokens */
11  int j;
12  char* p;
13  if ((p =strtok(buf, " \n")) == NULL) return 0;
14  list->curr = 0;
15  list->p[list->curr++] = p;
16  while ((p = strtok(NULL, " \n")) != NULL)
17  {
18    if (list->curr == list->max) grow_char_p_array(list);
19    list->p[list->curr++] = p;
20  }
21  /* remove '@' in strings */
22  for (j = 0; j < list->curr; j++)
23    if(*list->p[j] == '\"' || *list->p[j] == '\'') /* quote */
24      replace(list->p[j], '@', ' ');
25  return list->curr;
26}
27                                                                                                     
28static int
29sdds_get_parm(SDDS_TABLE *SDDS_table, struct table *tfs_table)
30{
31  PARAMETER_DEFINITION *pardef;
32  void    *parval;
33  long    *parvall;
34  short   *parvals;
35  double  *parvald;
36  float   *parvalf;
37  char    **parvalstr;
38
39  int     h_length;
40  char    s_dum[1000];
41
42  char    **cpar;
43
44  int   i2, npar;
45
46      /* access parameter data  SDDS_GetParameter(...) */
47      /*   */
48      cpar = SDDS_GetParameterNames(SDDS_table,(int32_t *)&npar);
49      h_length = npar;
50       if (tfs_table->header == NULL)  tfs_table->header = new_char_p_array(h_length);
51      for(i2=0;i2<npar;i2++) {
52         pardef = SDDS_GetParameterDefinition(SDDS_table,cpar[i2]);
53
54         parval = NULL;
55         parval = SDDS_GetParameter(SDDS_table,cpar[i2],NULL);
56
57         if(pardef->type == SDDS_LONG) {
58           parvall = (long *)parval;
59           if (get_option("debug")) printf("Parameter: %s, value: %ld\n",cpar[i2],*parvall);
60           sprintf(s_dum, v_format("@ %-16s %%ld  %ld"), cpar[i2],*parvall);
61           tfs_table->header->p[tfs_table->header->curr++] = tmpbuff(s_dum);
62         }
63         if(pardef->type == SDDS_SHORT) {
64           parvals = (short *)parval;
65           if (get_option("debug")) printf("Parameter: %s, value: %ld\n",cpar[i2],(long)*parvals);
66           sprintf(s_dum, v_format("@ %-16s %%ld  %ld"), cpar[i2],(long)*parvals);
67           tfs_table->header->p[tfs_table->header->curr++] = tmpbuff(s_dum);
68         }
69         if(pardef->type == SDDS_FLOAT) {
70           parvalf = (float *)parval;
71           if (get_option("debug")) printf("Parameter: %s, value: %e\n",cpar[i2],(double)*parvalf);
72           sprintf(s_dum, v_format("@ %-16s %%e  %e"), cpar[i2],(double)*parvalf);
73           tfs_table->header->p[tfs_table->header->curr++] = tmpbuff(s_dum);
74         }
75         if(pardef->type == SDDS_DOUBLE) {
76           parvald = (double *)parval;
77           if (get_option("debug")) printf("Parameter: %s, value: %e\n",cpar[i2],*parvald);
78           sprintf(s_dum, v_format("@ %-16s %%le  %le"), cpar[i2],*parvald);
79           tfs_table->header->p[tfs_table->header->curr++] = tmpbuff(s_dum);
80         }
81         if(pardef->type == SDDS_STRING) {
82           parvalstr = SDDS_GetParameter(SDDS_table,cpar[i2],NULL);
83           if (get_option("debug")) printf("Parameter: %s, value: %s \n",cpar[i2],*parvalstr);
84           sprintf(s_dum, v_format("@ %-16s %%%02ds \"%s\""), cpar[i2],strlen(*parvalstr),*parvalstr);
85           tfs_table->header->p[tfs_table->header->curr++] = tmpbuff(s_dum);
86         }
87
88      }
89
90  return(npar);
91}
92
93static int
94sdds_readt(char *filename, char *tfsname)
95{
96  int     i1, i2, i3; // i5; not used
97  int     j1, j2;
98
99//  long    lb; // not used
100  long    narr, nall;
101  long    arrdim[MAX_TFS_COL];
102  long    arrtyp[MAX_TFS_COL];
103  long    arrele[MAX_TFS_COL];
104
105  double  *datmp;
106  float   *datmpf;
107  long    *datmpl;
108  short   *datmps;
109  double  *datd[MAX_TFS_COL];
110  char    **datstr[MAX_TFS_COL];
111
112  char    **c0;
113  char    *c1[MAX_TFS_COL];
114
115
116  SDDS_TABLE SDDS_table;
117
118  SDDS_ARRAY *arr=0;
119
120  char*   tfs_table_cols[500];
121
122  int     tfs_table_types[MAX_TFS_COL];
123
124  struct  table  *tfstab;
125
126  /* convert SDDS to TFS types */
127  int tfs_sdds_types[] =
128  {
129    -1, MADX_DOUBLE, MADX_DOUBLE, MADX_LONG, MADX_LONG, MADX_LONG, MADX_LONG, MADX_STRING
130  };
131
132  if(sdds_pat != NULL) {
133       for(i2=0; i2<sdds_pat->curr; i2++) {
134          if (get_option("debug")) printf("my selected pattern: %d %s\n",i2,sdds_pat->p[i2]);
135       }
136  }
137
138  /* open the file and read the SDDS header */ 
139  if(SDDS_InitializeInput(&SDDS_table, filename) != 1) {
140     SDDS_PrintErrors(stdout,SDDS_VERBOSE_PrintErrors);
141  }
142
143  /* read and process each data table in the data set */ 
144  while (SDDS_ReadTable(&SDDS_table) > 0) { // (lb = not used
145      /* set all rows and all columns to initially be "of interest" */ 
146      SDDS_SetColumnFlags(&SDDS_table, 1); 
147      SDDS_SetRowFlags(&SDDS_table, 1);
148
149  }
150
151      /* access array data  SDDS_GetArray(...) */
152      /* */
153      {
154        int32_t nall32 = 0;
155        c0 = SDDS_GetArrayNames(&SDDS_table,&nall32);
156        nall = nall32;
157      }
158
159      if (get_option("debug")) printf("Found %ld arrays in total\n",nall);
160
161      narr = 0;
162
163        for(i1=0;i1<nall;i1++){ 
164           if(sdds_pat != NULL) {
165             if (get_option("debug")) printf("Check %d patterns\n",sdds_pat->curr);
166             for(i2=0; i2 < sdds_pat->curr; i2++) {
167               if (get_option("debug")) printf("Check pattern %s %s\n",sdds_pat->p[i2],c0[i1]);
168               if(myregex(sdds_pat->p[i2],c0[i1]) == 0) {
169                  if (get_option("debug")) printf("found now %s %s %ld\n",sdds_pat->p[i2],c0[i1],narr);
170                  c1[narr++] = c0[i1];
171                  if (get_option("debug")) printf("found now %s %s %ld\n",sdds_pat->p[i2],c0[i1],narr);
172               }
173             }
174           } else {
175                  if (get_option("debug")) printf("no check, use %s %ld\n",c0[i1],narr);
176                  c1[narr++] = c0[i1];
177           }
178        }
179
180      for(i1=0;i1<narr;i1++){ 
181        if ((SDDS_CheckArray(&SDDS_table, c1[i1], NULL, 
182                      0, stderr)) != SDDS_CHECK_OKAY) {
183           fprintf(stderr, "array %s is not in the data file",c1[i1]); 
184           exit(1); 
185        } 
186
187        arr = SDDS_GetArray(&SDDS_table, c1[i1], NULL);
188        arrdim[i1] = (long)arr->definition->dimensions;
189        arrtyp[i1] = (long)arr->definition->type;
190        arrele[i1] = (long)arr->elements;         
191                                                                                                           
192  /* check whether type is valid and compatible with TFS */
193        if((arrtyp[i1] < 1) || (arrtyp[i1] > SDDS_STRING))     {
194           fatal_error("Type not valid or compatible for: ",c1[i1]);
195        }
196                                                                                                           
197  /* check whether array dimension and size is compatible with TFS */
198        if(arrdim[i1] != 1 )     {
199           fatal_error("Array is 2-Dimensional: ",c1[i1]);
200        }
201        if(i1 > 0) {
202           if (get_option("debug")) printf("===> %d %ld %ld\n",i1,arrele[i1],arrele[i1-1]);
203           if(arrele[i1] != arrele[i1-1]) {
204              printf("found two arrays with different lengths: %ld %ld\n",arrele[i1-1],arrele[i1]);
205              fatal_error("Two arrays with different length, ", "conversion aborted");
206           }
207        }
208
209        datd[i1] = (double *)mycalloc("double ptr buffer for SDDS",arrele[i1]+8,sizeof(double));
210        if(arrtyp[i1] == SDDS_STRING) datstr[i1] = (char **)arr->data;
211
212        for(i3=0;i3<arr->elements;i3++){
213           datmp = (double *)arr->data;   
214           datmpl = (long *)arr->data;   
215           datmps = (short *)arr->data;   
216           datmpf = (float *)arr->data;   
217           if (get_option("debug")) {
218             if(arrtyp[i1] != SDDS_STRING) printf("data: %e %e \n",(double)datmp[i3],datmp[i3]);
219             if(arrtyp[i1] == SDDS_STRING) printf("data: %s \n",datstr[i1][i3]);
220           }
221           if(arrtyp[i1] == SDDS_DOUBLE) datd[i1][i3] = (double)datmp[i3];     
222           /* for float data: convert to double float */
223           if(arrtyp[i1] == SDDS_FLOAT)  datd[i1][i3] = datmpf[i3];     
224           /* for integer data: convert to double float */
225           if(arrtyp[i1] == SDDS_LONG)   datd[i1][i3] = datmpl[i3];     
226           if(arrtyp[i1] == SDDS_SHORT)  datd[i1][i3] = datmps[i3];     
227        }
228        if (get_option("debug")) {
229           printf("For TFS table: %s %ld %ld %d\n",c1[i1],arrdim[i1],arrtyp[i1],tfs_sdds_types[arrtyp[i1]]);
230        }
231        if(arrdim[i1] != 1 )     {
232           warning("Array is 2-Dimensional",c1[i1]);
233        }
234  /*
235  */
236        tfs_table_cols[i1] = stolower(c1[i1]);
237        tfs_table_types[i1] = tfs_sdds_types[arrtyp[i1]];
238       }
239
240       c1[narr] = " ";
241       tfs_table_cols[narr] = c1[narr];
242  /*
243       c1[3] = " ";
244       tfs_table_cols[3] = c1[3];
245       strcpy(&tfs_table_cols[narr]," ");
246  */
247       
248       tfstab = make_table(tfsname, tfsname, tfs_table_cols, tfs_table_types, 5000);
249       add_to_table_list(tfstab, table_register);
250
251       sdds_get_parm(&SDDS_table, tfstab); // i5 = not used
252
253       if (get_option("debug")) {
254           for(j1=0;j1<narr; j1++){
255              for(j2=0;j2<arr->elements; j2++){
256                 printf("data: %d %d %e\n",j1,j2,datd[j1][j2]);
257              }
258           }
259       }
260
261           for(i2=0;i2<arr->elements; i2++) {
262                   for(i1=0;i1<narr;i1++) {
263                     if((arrtyp[i1] >= 1) && (arrtyp[i1] < SDDS_STRING)) {
264                        double_to_table_curr(tfsname,c1[i1],&datd[i1][i2]);
265                     } else if(arrtyp[i1] == SDDS_STRING)                {
266                        string_to_table_curr(tfsname,c1[i1],datstr[i1][i2]);
267                     } else {
268                        fatal_error("Type not valid or compatible for: ",c1[i1]);
269                     }
270                   }
271  /*
272  */
273                   augment_count(tfsname);
274           }
275                                                                                                           
276
277
278       if (get_option("debug")) printf("--> %d %d\n",tfstab->curr,tfstab->num_cols);
279
280       if (get_option("debug")) out_table(tfsname,tfstab,"outtfs.1");
281
282  /* free all allocated space ....  */
283       for(i1=0; i1 < narr; i1++) {
284         if(datd[i1] != NULL) myfree("free double array",datd[i1]);
285            datd[i1] = NULL;
286       }
287
288  return(narr);
289}
290
291static int
292treat_tfs_header_set(SDDS_TABLE *SDDS_table, struct table* t)
293{
294  struct char_p_array* head_buf;
295  int j, k; // i, not used
296  char  dumc[1000];
297
298  double  dbuf;
299  long    lbuf;
300
301  head_buf = new_char_p_array(1000);
302
303  printf("number of headers: %d\n",t->header->curr);
304  for(j=0; j < t->header->curr; j++) {
305    if (get_option("debug")) printf("for set header: %s\n", t->header->p[j]);
306    if (get_option("debug")) printf("header: %s\n", t->header->p[j]);
307    pre_split(t->header->p[j], l_wrk, 0);
308    head_split(l_wrk->c,head_buf); // i = not used
309    if (get_option("debug")) printf("for set curr: %d\n",head_buf->curr);
310    if (get_option("debug")) printf("curr: %d\n",head_buf->curr);
311
312    if(head_buf->curr > 0) {
313      for(k=0; k < head_buf->curr; k++) {
314        if (get_option("debug")) printf("for set header: %d %s ", k,  head_buf->p[k]);
315
316        if(strcmp(head_buf->p[2],"%ld") == 0) {
317          sscanf(head_buf->p[3],"%ld",&lbuf);
318          if (!SDDS_SetParameters(SDDS_table, SDDS_SET_BY_NAME|SDDS_PASS_BY_VALUE, 
319                               head_buf->p[1], lbuf, NULL)) {
320             SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
321             exit(1);
322          }
323        } else if(strcmp(head_buf->p[2],"%le") == 0) {
324          sscanf(head_buf->p[3],"%le",&dbuf);
325          if (!SDDS_SetParameters(SDDS_table, SDDS_SET_BY_NAME|SDDS_PASS_BY_VALUE, 
326                               head_buf->p[1], dbuf, NULL)) {
327             SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
328             exit(1);
329          }
330        } else  {
331          strcpy(dumc,head_buf->p[3]);
332          replace(dumc, '\"', ' ');
333          if (!SDDS_SetParameters(SDDS_table, SDDS_SET_BY_NAME|SDDS_PASS_BY_VALUE,     
334                               head_buf->p[1], dumc, NULL)) {
335             SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
336             exit(1);
337          }
338        }
339
340      }
341    }
342  }
343
344  return(head_buf->curr);
345}
346
347static int
348treat_tfs_header_define(SDDS_TABLE *SDDS_table, struct table* t)
349{
350  struct char_p_array* head_buf;
351  int j, k; // i, not used
352
353  head_buf = new_char_p_array(1000);
354
355  if (get_option("debug")) printf("number of headers: %d\n",t->header->curr);
356  for(j=0; j < t->header->curr; j++) {
357    if (get_option("debug")) printf("header: %s\n", t->header->p[j]);
358    pre_split(t->header->p[j], l_wrk, 0);
359    head_split(l_wrk->c,head_buf); // i = not used
360    if (get_option("debug")) printf("curr: %d\n",head_buf->curr);
361
362    if(head_buf->curr > 0) {
363      for(k=0; k < head_buf->curr; k++) {
364  /*
365        SDDS_DefineParameter(SDDS_table, head_buf->p[1], NULL, NULL, NULL, NULL, SDDS_STRING, head_buf->p[3]);
366  */
367        if(strcmp(head_buf->p[2],"%le") == 0) {
368        SDDS_DefineParameter(SDDS_table, head_buf->p[1], NULL, NULL, NULL, NULL, SDDS_DOUBLE, NULL);
369        } else if(strcmp(head_buf->p[2],"%ld") == 0) {
370        SDDS_DefineParameter(SDDS_table, head_buf->p[1], NULL, NULL, NULL, NULL, SDDS_LONG, NULL);
371        } else {
372        SDDS_DefineParameter(SDDS_table, head_buf->p[1], NULL, NULL, NULL, NULL, SDDS_STRING, NULL);
373        }
374      }
375    }
376  }
377
378  return(head_buf->curr);
379}
380                                                                                                   
381static int
382sdds_writet_sel(char *filename, struct table *tfstab)
383{
384//  int     i1;
385  int     j1, j2;
386
387  double  **da1;
388  char    ***sa1;
389
390  int     pos[1000];
391
392  long    *pl;
393
394  SDDS_TABLE SDDS_table;
395
396  struct int_array* col = tfstab->col_out;
397  struct int_array* row = tfstab->row_out;
398
399  /* convert TFS to SDDS types */
400  int sdds_tfs_types[] =
401  {
402    -1, SDDS_LONG, SDDS_DOUBLE, SDDS_STRING
403  };
404                                                                                                           
405  /* set up to put data into file "atest.out" */
406    if (!SDDS_InitializeOutput(&SDDS_table, SDDS_ASCII, 1, NULL, NULL, filename)) {
407      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
408      exit(1);
409    }
410     
411
412  /*     */ 
413  if (get_option("debug")) {
414    printf("tfs table with %d columns \n",tfstab->num_cols);
415    printf("tfs table with %d rows    \n",tfstab->curr    );
416    printf("tfs table with %d selected cols    \n",col->curr    );
417    printf("tfs table with %d selected rows    \n",row->curr    );
418  }
419
420    da1 = tfstab->d_cols;
421    sa1 = tfstab->s_cols;
422
423    for(j1=0; j1<col->curr; j1++) {
424       /* define data arrays from TFS columns*/
425       if (SDDS_DefineArray(&SDDS_table, tfstab->columns->names[col->i[j1]], 
426                            NULL, NULL, NULL, NULL, 
427                            sdds_tfs_types[tfstab->columns->inform[col->i[j1]]], 0, 1, NULL)<0)   { 
428         SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
429         exit(1);
430       }
431      if (get_option("debug")) printf("column: %s  type: %d\n",tfstab->columns->names[col->i[j1]],
432                                                               tfstab->columns->inform[col->i[j1]]);
433      pos[j1] = name_list_pos(tfstab->columns->names[col->i[j1]],tfstab->columns);
434      if (get_option("debug")) printf("position: %d %d\n",j1,pos[j1]);
435    }
436
437
438    /* define parameters from TFS table header */
439    if(tfstab->header != NULL) {
440      if (get_option("debug")) printf("c ==> %d\n",tfstab->header->curr);
441     treat_tfs_header_define(&SDDS_table, tfstab); // i1 = not used
442    }
443
444    if (!SDDS_SaveLayout(&SDDS_table)) {
445      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
446      exit(1);
447    }
448    if (!SDDS_WriteLayout(&SDDS_table)) {
449      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
450      exit(1);
451    }
452    if (!SDDS_StartTable(&SDDS_table,1000)) {
453      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
454      exit(1);
455    }
456
457  /* set parameters from TFS table header */
458    if(tfstab->header != NULL) {
459      if (get_option("debug")) printf("cc ==> %d\n",tfstab->header->curr);
460     treat_tfs_header_set(&SDDS_table, tfstab); // i1 = not used
461    }
462
463  /* fill SDDS table with data */
464    for(j1=0; j1<col->curr; j1++) {
465      if (get_option("debug")) printf("column: %s  type: %d\n",tfstab->columns->names[col->i[j1]],
466                                                               tfstab->columns->inform[col->i[j1]]);
467      pos[j1] = name_list_pos(tfstab->columns->names[col->i[j1]],tfstab->columns);
468      if (get_option("debug")) printf("position: %d %d\n",j1,pos[j1]);
469
470      if(tfstab->columns->inform[col->i[j1]] == 1) {
471          /* need a long buffer for double to long conversion */
472          pl = (long *)mycalloc("long buffer for SDDS",tfstab->curr,sizeof(long));
473          for(j2=0;j2<tfstab->curr; j2++) {
474            /* convert from double to long */
475            pl[j2] = da1[pos[j1]][j2];
476            if (get_option("debug")) printf(" %ld\n",pl[j2]);
477          }
478          if (!SDDS_SetArrayVararg(&SDDS_table, tfstab->columns->names[col->i[j1]], 
479               SDDS_POINTER_ARRAY, pl,tfstab->curr)) {
480               SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
481               exit(1);
482          }
483          if(pl != NULL) myfree("write sdds",pl);
484      }
485
486      if(tfstab->columns->inform[col->i[j1]] == 2) {
487          /* pd = (double *)da1[pos[j1]]; */
488          for(j2=0;j2<tfstab->curr; j2++) {
489            if (get_option("debug")) {
490                 printf(" %e\n",da1[pos[j1]][j2]);
491                 printf("FILLING ? %s %d %e\n",sa1[pos[0]][j2],row->i[j2],da1[pos[j1]][j2]);
492            }
493            /* for row->i[j2] == 1  ==> row is selected, not implemented */
494          }
495          if (!SDDS_SetArrayVararg(&SDDS_table, tfstab->columns->names[col->i[j1]], 
496               SDDS_POINTER_ARRAY, &da1[pos[j1]][0],tfstab->curr)) {
497               SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
498               exit(1);
499          }
500      }
501
502      if(tfstab->columns->inform[col->i[j1]] == 3) {
503          for(j2=0;j2<tfstab->curr; j2++) {
504            if (get_option("debug")) printf(" %s\n",tfstab->s_cols[pos[j1]][j2]);
505          }
506          if (!SDDS_SetArrayVararg(&SDDS_table, tfstab->columns->names[col->i[j1]], 
507               SDDS_POINTER_ARRAY, &sa1[pos[j1]][0],tfstab->curr)) {
508               SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
509               exit(1);
510          }
511      }
512
513    }
514  /*                           */
515    if (!SDDS_WriteTable(&SDDS_table)) {
516      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
517      exit(1);
518    }
519    if (!SDDS_Terminate(&SDDS_table)) {
520      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
521      exit(1);
522    }
523   
524  return(0);
525}
526
527static int
528pass_select_tab(char* name, struct command* sc)
529  /* checks name against class (if element) and pattern that may
530     (but need not) be contained in command sc;
531     0: does not pass, 1: passes */
532{
533  struct name_list* nl = sc->par_names;
534  struct command_parameter_list* pl = sc->par;
535  struct element* el = find_element(strip(name), element_list);
536  int pos, in = 0, any = 0;
537  char *class, *pattern;
538  pos = name_list_pos("class", nl);
539  if (pos > -1 && nl->inform[pos])  /* parameter has been read */
540  {
541    el = find_element(strip(name), element_list);
542    if (el != NULL)
543    {
544      class = pl->parameters[pos]->string;
545      in = belongs_to_class(el, class);
546      if (in == 0) return 0;
547    }
548  }
549  any = in = 0;
550  pos = name_list_pos("pattern", nl);
551  if (pos > -1 && nl->inform[pos])  /* parameter has been read */
552  {
553    any = 1;
554    pattern = stolower(pl->parameters[pos]->string);
555    if(myregex(pattern, strip(name)) == 0)  in = 1;
556  }
557  if (any == 0) return 1;
558  else return in;
559}
560
561static void
562set_selected_rows_tab(struct table* t, struct command_list* select, struct command_list* deselect)
563{
564  int i, j, n = 0;
565  if (select != 0)
566  {
567    for (j = 0; j < t->curr; j++)  t->row_out->i[j] = 0;
568       t->row_out->curr = 0;
569    for (i = 0; i < select->curr; i++)
570    {
571      for (j = 0; j < t->curr; j++)
572      {
573        if (t->row_out->i[j] == 0) t->row_out->i[j]
574                                     = pass_select_tab(t->s_cols[0][j], select->commands[i]);
575        if (t->row_out->i[j] == 1) n++;
576      }
577    }
578  }
579  if (deselect != NULL)
580  {
581    for (i = 0; i < deselect->curr; i++)
582    {
583      for (j = 0; j < t->curr; j++)
584      {
585        if (t->row_out->i[j] == 1) t->row_out->i[j]
586                                     = 1 - pass_select_tab(t->s_cols[0][j], deselect->commands[i]);
587        if (t->row_out->i[j] == 1) n++;
588      }
589    }
590  }
591  t->row_out->curr = n;
592}
593
594static void
595sel_table(char* tname, struct table* t)
596  /* output of a table */
597{
598  int j;
599  struct command_list* scl = find_command_list(tname, table_select);
600  struct command_list* dscl = find_command_list(tname, table_deselect);
601  while (t->num_cols > t->col_out->max)
602    grow_int_array(t->col_out);
603  while (t->curr > t->row_out->max)
604    grow_int_array(t->row_out);
605  t->row_out->curr = t->curr;
606  if (par_present("full", NULL, scl))
607    put_info("obsolete option 'full'"," ignored on 'select'");
608  for (j = 0; j < t->curr; j++) t->row_out->i[j] = 1;
609  for (j = 0; j < t->num_cols; j++) t->col_out->i[j] = j;
610  t->col_out->curr = t->num_cols;
611  if ((scl != NULL && scl->curr > 0) || (dscl != NULL && dscl->curr > 0))
612  {
613    set_selected_columns(t, scl);
614    set_selected_rows_tab(t, scl, dscl);
615  }
616}
617                                                                                                         
618static int
619sdds_ior(struct in_cmd* cmd)
620{
621    char *sdds_table_file;
622    char *tfs_table_name;
623    int   i;
624
625    if((sdds_table_file = command_par_string("file",cmd->clone)) == NULL) {
626         fatal_error("No file name to read SDDS table ","\n");
627    }
628    if((tfs_table_name = command_par_string("table",cmd->clone)) == NULL) {
629         fatal_error("No table name to read SDDS table ","\n");
630    }
631    printf("access SDDS table: %s %s\n",sdds_table_file,tfs_table_name);
632    i = sdds_readt(sdds_table_file,tfs_table_name);
633    return(i);
634}
635
636static int 
637sdds_iow(struct in_cmd* cmd)
638{
639    char *sdds_table_file;
640    char *tfs_table_name;
641    struct table *tfs_table=0;
642    int   i, pos;
643    if((sdds_table_file = command_par_string("file",cmd->clone)) == NULL) {
644         fatal_error("No file name to write SDDS table ","\n");
645    }
646    if((tfs_table_name = command_par_string("table",cmd->clone)) == NULL) {
647         fatal_error("No table name to write SDDS table ","\n");
648    }
649
650    mycpy(c_dum->c, tfs_table_name);
651    if ((pos = name_list_pos(c_dum->c, table_register->names)) > -1) {
652      tfs_table = table_register->tables[pos];
653    }
654
655    printf("create SDDS table: %s %d\n",sdds_table_file,pos);
656    sel_table(tfs_table_name, tfs_table);
657    i = sdds_writet_sel(sdds_table_file,tfs_table);
658    return(i);
659}
660
661// public interface
662
663void
664pro_sdds(struct in_cmd* cmd)
665{
666  if (strcmp(cmd->tok_list->p[0], "sddsin") == 0)
667    sdds_ior(cmd);
668  else if (strcmp(cmd->tok_list->p[0], "sddsout") == 0)
669    sdds_iow(cmd);
670}
671
672#endif // _ONLINE
673
Note: See TracBrowser for help on using the repository browser.