/* @(#)tbread.c 17.1.1.1 (ES0-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 Massachusetss Ave, Cambridge, MA 02139, USA. Corresponding 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 tbread.c .LANGUAGE C .AUTHOR IPG-ESO Garching .CATEGORY table utilities .COMMENTS This module implements the following Midas commands: \begin{TeX} \begin{enumerate} \item {\tt READ/TABLE} table {\em [column\_selection [line\_selection ]} {\em [format\_file]} \end{enumerate} \end{TeX} .VERSION 1.0 25-Mar-1989 Definition J.D. Ponz .VERSION 1.1 09-Jun-1990 Include option Format file M.Peron .VERSION 3.0 05-Jul-1990 New version with column arrays F.O. .VERSION 3.1 04-Apr-1991 New version for PRINT with format file M.P .VERSION 3.2 27-Jul-1992 doesn't take care of width of screen , use new parameter MP ------------------------------------------------------------*/ #include #include #include /* To know the width of Terminal */ #include /* String Handling Functions */ #include #include #define PARLEN 80 #define COLS 256 /* Max number of Columns */ #define EDCOLS 256 /* Max number of Edited Columns */ #define RANGES 256 /* Max number of Ranges */ #define STRINGLEN 256 #define MAXCHAR 4096 char *osmmget(), *osmmexp(), *osmsg(); tbl_read() /*++++++++++++++++++ .PURPOSE READ/TABLE table [columns_selection] [rows_selection] [format-file] .RETURNS Status ------------------*/ { char table[PARLEN], msg[100]; char form[TBL_FORLEN+1], unit[TBL_UNILEN+1], label[1+TBL_LABLEN]; char *formfile,action[1]; int kuni; int icol[COLS], fcol[COLS], lrange[RANGES], urange[RANGES], found; int outcol[EDCOLS], colen[EDCOLS], nulls[EDCOLS]; int status, tid, ncol, nr,log1[12],log2; int nctable, nrtable, nsc, nar, npar, nac; int dtype, pos[2], sel, dummy, nch; int i, j, k, ic, nc, ibase, len, check_sel, header; i = 1; ncol = nr = 0; header = 1; nch = 0; formfile = (char *)0; /* read parameters */ npar = tbl_argc(); status = tbl_getarg(1, PARLEN, table); /* get table information */ if (status = TCTOPN(table,F_I_MODE,&tid)) { return(status); } if (status = TCIGET(tid,&nctable,&nrtable,&nsc,&nac,&nar)) { goto error; } if (nctable >= COLS) { nctable = COLS-1; } for (i=2; i<=npar; i++) { tbl_getarg(i, PARLEN, msg); if (i==8 && msg[strloc(msg,' ')]) { msg[strloc(msg,' ')] = '\0'; SCTPUT ("***Warning*** Command Line truncated to 8 parameters"); SCTPUT("Check Help READ/TABLE for more info"); } switch (msg[0]) { case ':': case '#': /* it is a new column */ if (status = TCCSEL(tid, msg, COLS-ncol, &icol[ncol], &fcol[ncol], &found)) { goto error; } ncol += found; break; case '@': /* it is range definition */ if (status = TCRSEL(tid, msg, RANGES-nr, &lrange[nr], &urange[nr], &found)) { goto error; } if ( (nr == 1) && (found == 1) && (lrange[0] == urange[0]) && (lrange[1] == urange[1])) /* Backwards compatibility */ { urange[0] = lrange[1]; } else nr += found; for (j=0; jnar || urange[j]<1 || urange[j]>nar) { status = ERR_TBLROW; sprintf (msg, "Row selection outside range[1..%d]",nar); SCTPUT(msg); break; } } break; case '?': break; case 'N': case 'n': if ( (!msg[1])) { header = 0; break; } default: /* Assume a Format File */ if (isdigit(msg[0])) { nch = atol(msg); } else if (formfile) { sprintf (msg, "****Format file is: %s", formfile); SCTPUT(msg); status = ERR_FILBAD; } else { formfile = strsave(msg); if (osfsize(osfsupply(formfile,".fmt")) <0 ) { sprintf(msg," Error opening Format file: %s \n", formfile); SCTPUT(msg); TCTCLO(tid); SCSEPI(); } } break; } } if (status != ERR_NORMAL) goto error; if (ncol == 0) { /* default columns to all */ ncol = nctable; for (i=0; i= width) break; outcol[nc] = icol[ic]; colen[nc] = len; ibase += len; } if (nc < 2) { outcol[nc] = icol[ic]; colen[nc] = len; ibase += len; nc++, ic++; line = osmmexp(line, ibase+2); title = osmmexp(title, ibase+2); } k = 0; /* Edit Titles */ if (header) { for (i=0; i < nc; i++) { TCLGET(tid, outcol[i], label); /*Reads column label*/ title[k++] = ' '; for (j=0; label[j] && (j < colen[i]); j++) { title[k++] = label[j]; } for (; j < colen[i]; j++) { title[k++] = ' '; } } title[k] = '\0'; SCTPUT(title); /* display title on terminal screen */ k = 0; for (i=0; i < nc; i++) { title[k++] = ' '; for (j = colen[i]; --j >= 0; ) { title[k++] = '-'; } } title[k] = '\0'; SCTPUT(title); /* displays separating dashed line on screen */ } /* list table values */ for (j = 0; j < nr; j++) { for (i=lrange[j]; i<=urange[j]; i++) { if (check_sel) { TCSGET(tid,i,&sel); /*reads row selection flag*/ } else { sel = 1; } if (sel) { /*reads table row as character string */ TCRRDC(tid,i, nc, outcol, line, nulls); SCTPUT(line); } } } if (header) { SCTPUT(title); /*plots again dashed lines*/ } } osmmfree(title); osmmfree(line); return(status); }