1
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++
2
.COPYRIGHT (c) 2010-2011 European Southern Observatory
3
.AUTHOR K. Banse ESO/SDD
4
.KEYWODS image, 3d table, vector columns
5
.PURPOSE Copy image(s) into a vector column of a 3d table.
10
------------------------------------------------------ */
14
#include "midas_def.h"
23
char fname[82], tname[82], colref[26];
24
char cunit[49], ident[74], format_str[24];
27
int *kpntr, imno, tno;
28
int row_no, upda, naxis, iva, df, n, m;
29
int felem, noelem, nr, na, ncol;
30
int allrow, allcol, lastrow;
31
int npix[MAXDIM], ibuf[5];
33
double *dpntr, start[MAXDIM], step[MAXDIM];
40
COPY/IMT3 image table colref,rowno 1st-el,noelem update/alloc-rows
44
(void) SCSPRO("BDF3TBL");
45
(void) SCKGETC("IN_A", 1, 80, &iva, fname); /* input image */
48
/* get column ref. and starting row no. */
50
row_no = 1; /* the default values */
51
(void) strcpy(colref,":Values");
52
(void) SCKGETC("INPUTC", 1, 24, &iva, ident);
56
n = CGN_INDEXC(ident,',');
58
{ /* input was: colref */
59
(void) strcpy(colref,ident);
64
if (n == 1) /* input was: ,row_no. */
70
(void) strcpy(colref,ident);
72
if (ident[n] == '@') n++; /* @row => row */
81
SCETER(6,"invalid row no. entered");
87
SCETER(6,"invalid row no. entered");
90
/* read name of output table */
92
(void) SCKGETC("OUT_A",1,64,&iva,tname);
95
/* all else integer data (I*1, I*2, I*4) are treated as I*4
96
get data type of input image via SCFINF */
98
(void) SCFINF(fname,4,ibuf);
99
df = ibuf[1]; /* data format in 2nd element of ibuf */
100
if ((df == D_R8_FORMAT) || (df == D_R4_FORMAT))
101
(void) strcpy(format_str,"F12.5");
104
(void) strcpy(format_str,"I10");
108
(void) SCIGET(fname,df,F_I_MODE,F_IMA_TYPE,MAXDIM,
109
&naxis,npix,start,step,ident,cunit,&pntr,&imno);
112
/* determine the no. of rows to write */
115
nr = 1; /* single line */
117
nr = npix[1]; /* no of lines in 2dim image */
120
/* get 1st element and no. of elements to write in array column */
122
(void) SCKGETC("INPUTC",31, 20, &iva, ident); /* opt. 1st_element,noelem */
124
felem = 1; /* the default values */
128
n = CGN_INDEXC(ident,',');
130
{ /* input was: 1st_elem */
136
SCETER(7,"invalid 1st element entered");
140
ident[n++] = '\0'; /* n is incremented after op... */
141
if (n == 1) /* input was: ,noelem. */
145
else /* get 1st element. */
152
SCETER(7,"invalid 1st element entered");
155
if (ident[n] != '\0') /* get noelem */
162
SCETER(8,"invalid no. of elements entered");
167
if ((felem < 1) || (felem > npix[0]))
168
SCETER(7,"invalid 1st element entered");
170
SCETER(8,"invalid no. of elements entered");
172
m = npix[0] - felem + 1; /* = max. possible no. of elements */
173
if (noelem > m) noelem = m;
176
(void) SCKGETC("INPUTC", 26, 1, &iva, ident); /* update or alloc rows */
180
{ /* allocate more rows for new table */
182
SCKRDI("INPUTI",1,1,&iva,&allrow,&iva,&knull);
184
SCETER(9,"invalid no_rows_to_allocate entered");
186
else if (ident[0] == 'U')
187
upda = 1; /* table for updating stuff exists */
190
printf("colref = %s, row no = %d, nr = %d\n",colref,row_no,nr);
191
printf("upda = %d\n",upda);
195
/* and create or open this table */
197
na = 1; /* 1 new column */
198
lastrow = row_no + nr - 1; /* last row to fill */
199
if (lastrow < allrow) lastrow = allrow;
203
(void) TCTINI(tname, F_TRANS, F_O_MODE, na, lastrow, &tno);
204
(void) TCCINI(tno,df,noelem,format_str,"intensity",colref,&ncol);
208
(void) TCTOPN(tname,F_IO_MODE,&tno);
209
(void) TCIGET(tno,&n,&n,&n,&allcol,&allrow);
210
if (allrow < lastrow)
212
m = sprintf(tname,"last row (%d) to fill exceeds allocated %d rows",
214
nr = allrow - row_no + 1;
218
SCETER(33,"no row can be be written");
222
(void) sprintf(tname+m,", only %d rows will be written",nr);
226
(void) TCCSER(tno,colref,&ncol);
228
{ /* create new column */
229
(void) TCCINI(tno,df,noelem,format_str,"intensity",colref,&ncol);
231
else /* column found - check data type */
233
(void) TCFGET(tno,ncol,ident,&n,&iva);
234
if (iva != df) /* column, image data type don't match */
236
(void) sprintf(tname,"image and colum type do not match...");
237
(void) SCTPUT(tname);
238
(void) sprintf(tname,"we reopen image with column data type ");
239
(void) SCTPUT(tname);
242
(void) SCIGET(fname,df,F_I_MODE,F_IMA_TYPE,MAXDIM,
243
&naxis,npix,start,step,ident,cunit,&pntr,&imno);
249
(void) TCFGET(tno,ncol,ident,&n,&iva);
250
printf("column #%d -> form = %s, len = %d, type = %d\n",ncol,ident,n,iva);
251
(void) TCBGET(tno,ncol,&iva,&m,&n);
252
printf("column #%d -> type = %d, items = %d, bytes = %d\n",ncol,iva,m,n);
256
if (df == D_R4_FORMAT)
259
fpntr = (float *) pntr;
260
dpntr = (double *) 0;
262
else if (df == D_R8_FORMAT)
266
dpntr = (double *) pntr;
268
else /* only D_I4_FORMAT left */
270
kpntr = (int *) pntr;
272
dpntr = (double *) 0;
275
m = row_no; /* starting row no. */
278
if (nr == 1) /* fill only 1 row */
280
if (df == D_R4_FORMAT)
282
(void) TCAWRR(tno,m,ncol,felem,noelem,fpntr);
284
else if (df == D_R8_FORMAT)
286
(void) TCAWRD(tno,m,ncol,felem,noelem,dpntr);
290
(void) TCAWRI(tno,m,ncol,felem,noelem,kpntr);
292
(void) TCSPUT(tno,m,&iva);
294
else /* fill nr rows (nr may also be just 1) */
296
if (df == D_R4_FORMAT)
300
(void) TCAWRR(tno,m,ncol,felem,noelem,fpntr);
301
(void) TCSPUT(tno,m,&iva);
306
else if (df == D_R8_FORMAT)
310
(void) TCAWRD(tno,m,ncol,felem,noelem,dpntr);
311
(void) TCSPUT(tno,m,&iva);
320
(void) TCAWRI(tno,m,ncol,felem,noelem,kpntr);
321
(void) TCSPUT(tno,m,&iva);
329
/* append keyword HISTORY to descr. HISTORY of table */
331
(void) SCKGETC("HISTORY",1, 80, &iva, tname);
332
(void) SCDWRC(tno,"HISTORY",1,tname,-1,80,&iva);