1
/*===========================================================================
2
Copyright (C) 1993-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
.AUTHOR IPG-ESO Garching
33
.CATEGORY Data Organizer utilities
34
.COMMENTS This module implements the following Midas commands:
37
\item {\tt CLASSIFY/IMAGE} table rule column outchar
41
.VERSION 1.0 15-Mar-1993 Definition M. Peron
44
-----------------------------------------------------------------------*/
50
#include <midas_def.h>
57
#define issign(c) ((c == '+') || (c == '-'))
58
#define BUFM 30 /* synchronize with tbcomsel !! */
63
extern int get_token();
65
extern int tbl_hist();
71
double tdtrue,tdfalse;
72
int token_type,first,nochar,refrow,action,exist;
73
int tmno[BUFM],tmnoc[BUFM];
74
char *stringstar[MAXS];
75
int occ[PARLEN],ocp[PARLEN],principal;
81
void classify(intable,assod,column,mycval)
82
char intable[60],column[1+TBL_LABLEN],assod[256],*mycval;
85
int null, dummy, type;
86
int col,cstar[PARLEN],nstar,nstring,pnull[PARLEN];
87
int i,j,*index, lola,k,pos,pos1,pos2,ntimes,itimes,tidass,nline,ntoken ;
88
int coldescr,colout,colchar,meth,selass,mylen;
89
int ibuf[BUFM],nconst[BUFM], unit;
91
char colstar[1+TBL_LABLEN];
93
char *final,*stringtok[MAXS];
94
char descr[256], *cval;
95
double *data[BUFM],consta[BUFM];
96
char *string[BUFM],*cdata[BUFM];
102
cval = osmmget(MAXLEN+1);
103
line = osmmget(PARLEN);
104
token = osmmget(PARLEN);
105
TCMCON(&tblsel,&tdtrue,&tdfalse);
106
for (i=0; i<MAXS; i++) {
107
stringstar[i] = (char *)0;
108
stringtok[i] = (char *)0;
111
selecrit = osmmget(PARLEN+1);
112
for (i=0 ; i<BUFM; i++) {
113
data[i] = (double *)0;
114
cdata[i] = (char *)0;
115
string[i] = (char *)0;
119
if (assod[strindex(assod,".tbl")]) {
121
TCTOPN(assod,F_I_MODE,&tidass);
122
TCIGET(tidass,&dummy,&ntimes,&dummy,&dummy,&dummy);
123
TCLSER(tidass,"DESCR",&coldescr);
124
if (coldescr <= 0 ) {
125
SCTPUT("Column DESCR not found");
128
TCLSER(tidass,"OUTCOL",&colout);
130
SCTPUT("Column OUTCOL not found");
133
TCLSER(tidass,"OUTCHAR",&colchar);
135
SCTPUT("Column OUTCHAR not found");
143
tid = TCTID(intable);
145
status = TCTOPN(intable,F_IO_MODE,&tid);
146
status = TCIGET(tid,&dummy,&nrow,&dummy,&dummy,&dummy);
147
for (itimes=1; itimes<=ntimes; itimes++) {
148
if (!assod[strindex(assod,".tbl")]) {
153
TCSGET(tidass,itimes,&selass);
154
if (!selass) continue;
155
TCERDC(tidass,itimes,coldescr,descr,&null);
156
TCERDC(tidass,itimes,colout,column,&null);
157
TCERDC(tidass,itimes,colchar,cval,&null);
159
status = TCCSER(tid,column,&col);
160
if (col == -1) TCCINI(tid,D_C_FORMAT,32L,"A16"," ",column,&col);
162
for (i=0; i<PARLEN; i++) selecrit[i] = '\0';
163
if (assod[strindex(assod,":")]) strcpy(selecrit,descr);
164
else status = SCDRDC(tid,descr,1,1,255,&dummy,selecrit,&unit,&null);
171
strcpy(line,selecrit);
172
nline = strlen(line);
174
level00(ibuf,data,cdata,consta,nconst,string);
176
for (i=0; i<PARLEN; i++) *(line+i) = '\0';
177
for (i=0; i<PARLEN; i++) ocp[i] = 0;
178
strncpy(line,selecrit,256L);
182
mylen = strlen(cval);
183
while (cval[0] != '\0') {
184
pos1 = strscans(cval,"[&");
185
if (!cval[pos1]) break;
187
pos2 = strloc(cval,'[');
189
pos1 = strloc(cval,'&');
191
if (!stringstar[*index]) stringstar[*index] = osmmget(MAXLEN);
192
oscfill(stringstar[*index],MAXLEN,'\0');
193
strncpy(stringstar[*index],cval,pos1);
194
while (pos1--) cval++;
196
occ[*index] = atoi(cval);
198
while (isdigit(*cval)) cval++;
201
if (!stringstar[*index]) stringstar[*index] = osmmget(MAXLEN);
202
oscfill(stringstar[*index],MAXLEN,'\0');
203
strncpy(stringstar[*index],cval,pos1);
214
if (type ==1 )cval -= mylen;
221
if (token_type == 2) strcpy(colstar,token);
222
if (token_type ==6 ) {
223
ntoken = strlen(token);
224
pos = strloc(token,'*');
226
if (!stringtok[nstar]) stringtok[nstar] = osmmget(MAXLEN);
227
oscfill(stringtok[nstar],MAXLEN,'\0');
228
strncpy(stringtok[nstar],token,MAXLEN);
229
TCCSER(tid,colstar,&cstar[nstar]);
231
token = token + pos +1;
232
while(token[strloc(token,'*')]) {
233
pos = strloc(token,'*');
234
*(stringtok[nstar-1] + pos + 1 ) = '\0';
235
if (!stringtok[nstar]) stringtok[nstar] = osmmget(MAXLEN);
236
oscfill(stringtok[nstar],MAXLEN,'\0');
237
strncpy(stringtok[nstar],token,MAXLEN);
238
TCCSER(tid,colstar,&cstar[nstar]);
240
token = token + pos +1;
243
token = token - ntoken;
248
for (i=0; i<nrow; i++) {
249
if (*(data[0] + i)) status = TCEWRC(tid,i+1,col,cval);
253
if (!final) final = osmmget(PARLEN);
254
for (i=0; i<PARLEN; i++) {
258
for (i=0; i<nrow; i++) {
260
for (j=0; j<PARLEN; j++) final[j] = '\0';
261
for (j=0; j<nstring; j++) {
262
if (occ[j] == 0) strcat(final,stringstar[j]);
263
else if (occ[j] > 0) {
264
status = TCERDC(tid,i+1,cstar[occ[j]-1],cval,&pnull[j]);
266
if (ocp[j] && final[0] != 0) strcat(final,"+");
267
if (*stringtok[occ[j]-1] == '*') {
268
strcat(final,stringstar[j]);
269
kk = strskip(cval,' ');
270
k = strbskip(cval+kk,' ');
271
if (cval[k+kk+1]) cval[k+kk+1] = '\0';
272
k = strlen(cval)-strlen(stringtok[occ[j]-1])+1;
274
strcat(final,cval+strskip(cval,' '));
277
strcat(final,stringstar[j]);
278
kk = strskip(cval,' ');
279
k = strloc(cval+kk,' ');
280
if (cval[k+kk]) cval[k+kk] = '\0';
281
strcat(final,cval+strlen(stringtok[occ[j]-1])-1+strskip(cval,' '));
286
if (pnull[-occ[j]-1] == 0) strcat(final,stringstar[j]);
288
TCEWRC(tid,i+1,col,final);
292
/*for (i=0; i<BUFM; i++) if (data[i]) osmmfree((char *)data[i]);
293
for (i=0; i<BUFM; i++) if (cdata[i]) osmmfree(cdata[i]);*/
295
for (i=0; i<BUFM;i++) {
296
if (tmno[i] != -1) SCFCLO(tmno[i]);
297
if (tmnoc[i] != -1 ) SCFCLO(tmnoc[i]);
299
for (i=0; i<BUFM; i++) if (string[i]) osmmfree(string[i]);
300
for (i=0; i<BUFM; i++) {
301
data[i] = (double *)0;
302
cdata[i] = (char *)0;
303
string[i] = (char *)0;
309
if (type == 1) line = line-nline;
315
if(final) osmmfree(final);
316
status = tbl_hist(tid);
317
if (meth==1) TCTCLO(tidass);
318
status = TCTCLO(tid);
325
void deco(index,flag,decval)
332
pos1 = strloc(mydecval,'[');
334
if (!stringstar[*index]) stringstar[*index] = osmmget(MAXLEN);
335
oscfill(stringstar[*index],MAXLEN,'\0');
336
strncpy(stringstar[*index],mydecval,pos1);
337
while (pos1--) mydecval++;
342
pos1 = strloc(mydecval,'[');
343
pos2 = strloc(mydecval,']');
345
pos1 = strloc(mydecval,'&');
346
if (!stringstar[*index]) stringstar[*index] = osmmget(MAXLEN);
347
oscfill(stringstar[*index],MAXLEN,'\0');
348
strncpy(stringstar[*index],mydecval,pos1);
349
while (pos1--) mydecval++;
351
occ[*index] = atoi(mydecval);
352
if (flag == 1) ocp[*index] = 1;
354
while(isdigit(*mydecval)) mydecval++;
355
if (*mydecval == ']') mydecval++;
359
pos2 = strloc(mydecval,'[');
361
pos1 = strloc(mydecval,'&');
362
if (mydecval[pos1] && (pos1 < pos2)) {
363
if (!stringstar[*index]) stringstar[*index] = osmmget(MAXLEN);
364
oscfill(stringstar[*index],MAXLEN,'\0');
365
strncpy(stringstar[*index],mydecval,pos1);
366
while (pos1--) {mydecval++;pos2--;}
368
occ[*index] = atoi(mydecval);
369
if (flag == 1) ocp[*index] = 1;
372
while (isdigit(*mydecval)) {mydecval++; pos2--;}
375
if (!stringstar[*index]) stringstar[*index] = osmmget(MAXLEN);
376
oscfill(stringstar[*index],MAXLEN,'\0');
377
strncpy(stringstar[*index],mydecval,pos2);
380
occ[*index] = -principal -1 ;
381
/* ocp[*index] = 1; */
386
deco(index,0,decval);
388
pos1 = strloc(mydecval,']');
390
if (!stringstar[*index]) stringstar[*index] = osmmget(MAXLEN);
391
oscfill(stringstar[*index],MAXLEN,'\0');
392
strncpy(stringstar[*index],mydecval,pos1);
393
while (pos1--) mydecval++;
394
occ[*index] = -1- principal;
397
if (*mydecval == ']') mydecval++;