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 Massachusetss Ave, Cambridge,
19
Corresponding 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 table utilities
34
.COMMENTS This module implements the following Midas commands:
37
\item {\tt GROUP/ROW} table incol outcol flag
41
.VERSION 1.0 15-Mar-1993 Definition M. Peron
44
----------------------------------------------------------*/
49
#include <midas_def.h>
51
#include <proto_tbl.h>
54
#define issign(c) ((c == '+') || (c == '-'))
58
extern int tbl_hist();
81
int tid,gnum,icol,ocol,ncol,incol[256];
92
char icolumn[PARLEN],ocolumn[PARLEN];
93
char form[1+TBL_FORLEN];
94
char intab[60], action[2];
97
struct treec *s1dtreec();
98
struct treei *s1dtreei();
102
SCKGETC("IN_A",1L,60L,&dummy,intab);
103
SCKGETC("INPUTC",1L,80L,&dummy,icolumn);
104
SCKGETC("OUTPUTC",1L,80L,&dummy,ocolumn);
105
SCKGETC("ACTION",1L,1L,&dummy,action);
106
status = TCTOPN(intab,F_IO_MODE,&tid);
107
if (status != ERR_NORMAL) {
108
SCTPUT("Error opening input data table");
111
TCIGET(tid,&ncol,&nrow,&dummy,&dummy,&dummy);
112
TCCSER(tid,icolumn,&icol);
114
SCTPUT("Input column not found");
117
TCFGET(tid,icol,form,&len,&dtype);
118
TCCSER(tid,ocolumn,&ocol);
119
if (ocol <= 0) TCCINI(tid,D_I4_FORMAT,1,"I3"," ",ocolumn,&ocol);
121
if (dtype == D_C_FORMAT) {
122
for (i=1; i<=nrow; i++) {
125
TCERDC(tid,i,icol,cval,&null);
127
if (!headc) headc = s1dtreec(headc,headc,cval,i,nrow);
128
else s1dtreec(headc,headc,cval,i,nrow,gnum);
132
for (i=1; i<=ncol; i++) if (i != icol) {
136
if (toupper(*action) == 'R') readtreec(headc);
139
for (i=1; i<=nrow; i++) {
142
TCERDD(tid,i,icol,&dval,&null);
145
if (!headi) headi = s1dtreei(headi,headi,ival,i,nrow);
146
else s1dtreei(headi,headi,ival,i,nrow,gnum);
150
for (i=1; i<=ncol; i++) if (i != icol) {
155
if (toupper(*action) == 'R') readtreei(headi);
158
status = tbl_hist(tid);
163
struct treec *s1dtreec(root,r,cval,row,nrow)
170
r = (struct treec *)osmmget(sizeof(struct treec));
171
r->left = (struct treec *)0;
172
r->right = (struct treec *)0;
173
strcpy(r->name,cval);
174
r->seqnum = (int *) osmmget(sizeof(int)*nrow);
178
r->seqnum[r->noelem] = row;
180
TCEWRI(tid,row,ocol,r->seqnum);
183
if (strcmp(cval,root->name) < 0) {
185
TCEWRI(tid,row,ocol,r->seqnum);
187
else if (strcmp(cval,root->name) > 0) {
189
TCEWRI(tid,row,ocol,r->seqnum);
193
root->seqnum[root->noelem] = row;
194
TCEWRI(tid,row,ocol,r->seqnum);
198
if (strcmp(cval,r->name) < 0) s1dtreec(r,r->left,cval,row,nrow);
199
else if (strcmp(cval,r->name) > 0) s1dtreec(r,r->right,cval,row,nrow);
202
r->seqnum[r->noelem] = row;
203
TCEWRI(tid,row,ocol,r->seqnum);
214
if (head->left) readtreec(head->left);
215
TCRRDC(tid,head->seqnum[1],ncol,incol,line,nulls);
217
oscfill(line,len+1,' ');
218
for (i=2; i<= head->noelem;i++){
219
TCRRDC(tid,head->seqnum[i],ncol-1,&incol[1],line+len+1,nulls);
222
if (head->right) readtreec(head->right);
227
struct treei *s1dtreei(root,r,ival,row,nrow)
234
r = (struct treei *)osmmget(sizeof(struct treei));
235
r->left = (struct treei *)0;
236
r->right = (struct treei *)0;
238
r->seqnum = (int *) osmmget(sizeof(int)*nrow);
242
r->seqnum[r->noelem] = row;
244
TCEWRI(tid,row,ocol,r->seqnum);
247
if (ival < root->ival ) {
249
TCEWRI(tid,row,ocol,r->seqnum);
251
else if (ival > root->ival) {
253
TCEWRI(tid,row,ocol,r->seqnum);
257
root->seqnum[root->noelem] = row;
258
TCEWRI(tid,row,ocol,r->seqnum);
262
if (ival < r->ival) s1dtreei(r,r->left,ival,row,nrow);
263
else if (ival > r->ival) s1dtreei(r,r->right,ival,row,nrow);
266
r->seqnum[r->noelem] = row;
267
TCEWRI(tid,row,ocol,r->seqnum);
280
if (head->left) readtreei(head->left);
281
TCRRDC(tid,head->seqnum[1],ncol,incol,line,nulls);
283
oscfill(line,len+1,' ');
284
for (i=2; i<= head->noelem;i++){
285
TCRRDC(tid,head->seqnum[i],ncol-1,&incol[1],line+len+1,nulls);
288
if (head->right) readtreei(head->right);