/* @(#)tbmerge.c 17.1.1.1 (ESO-DMD) 01/25/02 17:47:12 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. Correspondence concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .TYPE Module .NAME tbmerge.c .LANGUAGE C .AUTHOR IPG-ESO Garching .CATEGORY table utilities .COMMENTS This module implements the following Midas commands: \begin{TeX} \begin{enumerate} \item {\tt MERGE/TABLE} intable {\em [intable ...]} outable \item {\tt COPY/TABLE} intable outable \end{enumerate} \end{TeX} .VERSION 1.0 25-Mar-1989 Definition J.D. Ponz .VERSION 3.0 05-Jul-1990 New version with column arrays F.O. .VERSION 3.1 18-Apr-1991 Copy non standard descriptors MP ------------------------------------------------------------*/ #include #include #include #define PARLEN 80 #define TABLES 7 tbl_merge() /*++++++++++++++++++ .PURPOSE Merge several tables into one new output table. Or copy one to another .RETURNS Status ------------------*/ { char intable[PARLEN], outable[PARLEN], field[PARLEN]; char nhform[PARLEN],fname[PARLEN]; char label[1+TBL_LABLEN], form[10], unit[11+TBL_UNILEN]; char linesel[77+PARLEN],line[65],command[8],action[1]; int kuni; int table[TABLES], nc[TABLES], nr[TABLES]; int tid, nac, nar, phform; int nsel, ntot, npar, nstart,len,ii; int ncol, nrow; int status, i, j, nout, oc, type, items; int tid1, tid2; int dummy,bytes; npar = tbl_argc(); /* open main input tables */ status = tbl_getarg(1, PARLEN, intable); status = TCTOPN(intable,F_I_MODE,&tid); if (status != ERR_NORMAL) { SCTPUT("Error opening input table"); return (status); } /* read table size information: */ status = TCIGET(tid,&ncol,&nrow,&dummy,&nac,&nar); /* read storage foramt F_TRANS or F_RECORD: */ status = TCDGET(tid,&phform); /* count selected rows: */ status = TCSCNT(tid,&nsel); table[0] = tid; /* ID of input table */ nc[0] = ncol; /* number of columns in input table */ nr[0] = nrow; /* number of rows in input table */ ntot = nsel; /* number of selected rows */ (void) SCKRDC("ACTION",1,1,1,&dummy,action,&kuni,&dummy); /* count input rows */ if ((action[0] == 'M')) /* only for merge/table */ { for (i=2; i80) { ii = 0; while (linesel[ii]) { linesel[ii] = linesel[ii+80]; ii++; } (void) SCDWRC(tid1,"HISTORY",1,linesel,-1,80,&kuni); len -= 80; } } } else /* if not COPY/TABLE ===> for MERGE/TABLE*/ { for (j=1; j80) { ii = 0; while (linesel[ii]) { linesel[ii] = linesel[ii+80]; ii++; } (void) SCDWRC(tid1,"HISTORY",1,linesel,-1,80,&kuni); len -= 80; } } } } if (status == ERR_NORMAL) { /*copy all descriptors and append to HISTORY*/ CGN_DSCUPD(tid1,tid1," "); /* blank -> get HISTORY from keyword HISTORY and keys P1, P2, ... */ } TCTCLO(tid); TCTCLO(tid1); return (status); }