1
/* @(#)tbfhand.c 19.1 (ESO-DMD) 02/25/03 14:18:06 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
20
Correspondence concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
30
===========================================================================*/
36
#include <midas_def.h>
39
#include <proto_tbl.h>
48
int status,tid,nrow,kcol,nocat,otid,no,ormf ;
49
int *create, imno, noelem[256], noelembis,ocol[256],colf;
50
int *keyival[256], *ipos,ontype;
53
float *keyrval[256],ms[2];
54
double *keydval[256],start[3],step[3];
55
char incata[60],intable[60],outable[60],filename[60];
56
char *cdummy, type,*keycval[256];
57
char form[1+TBL_FORLEN],*temp, *otype;
58
char *keyname,*label,*area,defaul[5];
59
char *keyword = "descr_iname";
60
status = SCSPRO("TDATABASE");
61
status = SCKGETC("IN_A",1,60,&dummy,incata);
62
status = SCKGETC("IN_B",1,60,&dummy,intable);
63
status = SCKGETC("OUT_A",1,60,&dummy,outable);
65
/*open table containing keywords names */
66
status = TCTOPN(intable,F_I_MODE,&tid) ;
67
status = TCIGET(tid,&dummy,&nrow,&dummy,&dummy,&dummy);
68
status = SCCSHO(incata,&nocat,&dummy);
70
status = TCTINI(outable,F_TRANS,F_IO_MODE,nrow,nocat,&otid);
71
status = TCCINI(otid,D_C_FORMAT,60L,"A16"," ","FILENAME",&colf);
72
status = TCCSER(tid,keyword,&kcol);
73
keyname = osmmget(NM*nrow);
74
otype = osmmget(NT*nrow);
76
label = osmmget(nl*nocat);
77
ipos = (int *)osmmget(nrow*sizeof(int));
78
create = (int *)osmmget((nrow+2)*sizeof(int));
79
for (i=0; i<nrow; i++) {
80
TCERDC(tid,i+1,kcol,keyname+i*NM,&null);
81
if (null) *(keyname+i*NM) = '\0';
82
TCERDC(tid,i+1,4L,otype+i*NT,&null);
83
if (null) *(otype+i*NT) = '\0';
85
temp = otype+i*NT + strskip(otype+i*NT,' ');
87
if ((temp[0] == 'C') || (temp[0] == 'c'))
88
if (temp[1] == '*') noelem[i] = atoi(temp+2);
90
TCERDI(tid,i+1,2L,ipos+i,&null);
91
if (null) *(ipos+i) = 1;
92
TCERDC(tid,i+1,3L,label+i*nl,&null);
93
if (null) *(label+i*nl) = '\0';
99
sprintf(form,"A%d",noelem[i]);
100
keycval[i] = osmmget(noelem[i]);
103
ontype = D_I4_FORMAT;
105
/* keyival[i] = (int *)osmmget(sizeof(int)); */
108
ontype = D_R4_FORMAT;
109
strcpy(form,"E12.6");
110
/* keyrval[i] = (float *)osmmget(sizeof(float)); */
113
ontype = D_R8_FORMAT;
114
strcpy(form,"D24.17");
115
/* keydval[i] = (double *)osmmget(sizeof(double)); */
118
if (!*(label+i*nl)) strncpy(label+i*nl,keyname+i*NM,nl);
119
TCCINI(otid,ontype,noelem[i],form," ",label+i*nl,&ocol[i]);
127
for (j=0; j<nocat; j++) {
128
status = SCCGET(incata,0,filename,cdummy,&no);
129
if (filename[0] != ' ') {
130
ormf = MAX(ormf,strlen(filename));
131
SCFOPN(filename,D_R4_FORMAT,F_I_MODE,F_IMA_TYPE,&imno);
133
TCEWRC(otid,l,colf,filename);
134
for (i=0; i<nrow; i++) {
135
SCDFND(imno,keyname+i*NM,&type,&noelembis,&dummy);
136
if (!*(label+i*nl)) strncmp(label+i*nl,keyname+i*NM,nl);
139
if (*(create+i) == 0) {
140
sprintf(form,"A%d",noelembis);
141
TCCINI(otid,D_C_FORMAT,noelembis,form," ",label+i*nl,&ocol[i]);
143
keycval[i] = osmmget(noelembis);
145
SCDRDC(imno,keyname+i*NM,1L,1L,noelem[i],&dummy,
146
keycval[i],&unit,&null);
147
TCEWRC(otid,l,ocol[i],keycval[i]);
150
if (*(create+i) == 0) {
151
TCCINI(otid,D_I4_FORMAT,1,"I8"," ",label+i*nl,&ocol[i]);
154
keyival[i] = (int *)osmmget(sizeof(int));
155
SCDRDI(imno,keyname+i*NM,*(ipos+i),1L,&dummy,keyival[i],&unit,&null);
156
TCEWRI(otid,l,ocol[i],keyival[i]);
159
if (*(create+i) == 0) {
160
TCCINI(otid,D_R4_FORMAT,1,"E12.6"," ",label+i*nl,&ocol[i]);
163
keyrval[i] = (float *)osmmget(sizeof(float));
164
SCDRDR(imno,keyname+i*NM,*(ipos+i),1L,&dummy,keyrval[i],&unit,&null);
165
TCEWRR(otid,l,ocol[i],keyrval[i]);
168
if (*(create+i) == 0) {
169
TCCINI(otid,D_R8_FORMAT,1,"D24.17"," ",label+i*nl,&ocol[i]);
172
keydval[i] = (double *)osmmget(sizeof(double));
173
SCDRDD(imno,keyname+i*NM,*(ipos+i),1L,&dummy,keydval[i],&unit,&null);
174
TCEWRD(otid,l,ocol[i],keydval[i]);
177
if (*(create+i) != 0) TCEDEL(otid,l,ocol[i]);
181
if (*(create+nrow) == 0) {
182
TCCINI(otid,D_R4_FORMAT,1,"E15.6"," ","MEAN",&ocol[nrow]);
183
TCCINI(otid,D_R4_FORMAT,1,"E15.6"," ","SIGMA",&ocol[nrow+1]);
186
strcpy(defaul,"YNSNY");
187
SCDRDI(imno,"NAXIS",1L,1L,&dummy,&naxis,&unit,&null);
188
SCDRDI(imno,"NPIX",1L,naxis,&dummy,npix,&unit,&null);
189
/* measig(imno,area,naxis,npix,start,step,defaul,&ms[0],&ms[1]); */
190
TCEWRR(otid,l,ocol[nrow],&ms[0]);
191
TCEWRR(otid,l,ocol[nrow+1],&ms[1]);
194
sprintf(form,"A%d",ormf);
195
status = TCFPUT(otid,colf,form);