~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/table/src/bdf3tbl.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
6
.VERSION
 
7
 100826         creation
 
8
 
 
9
 111205         last modif
 
10
------------------------------------------------------ */
 
11
 
 
12
#include        <stdlib.h>
 
13
#include        <stdio.h>
 
14
#include        "midas_def.h"
 
15
 
 
16
 
 
17
#define MAXDIM  2
 
18
 
 
19
 
 
20
int main()
 
21
 
 
22
{
 
23
char    fname[82], tname[82], colref[26];
 
24
char    cunit[49], ident[74], format_str[24];
 
25
char    *pntr;
 
26
 
 
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];
 
32
 
 
33
double  *dpntr, start[MAXDIM], step[MAXDIM];
 
34
 
 
35
float   *fpntr;
 
36
 
 
37
 
 
38
 
 
39
/*
 
40
COPY/IMT3  image  table  colref,rowno  1st-el,noelem  update/alloc-rows
 
41
*/
 
42
 
 
43
 
 
44
(void) SCSPRO("BDF3TBL");
 
45
(void) SCKGETC("IN_A", 1, 80, &iva, fname);     /* input image */
 
46
 
 
47
 
 
48
/* get column ref. and starting row no. */
 
49
 
 
50
row_no = 1;                                     /* the default values */
 
51
(void) strcpy(colref,":Values");
 
52
(void) SCKGETC("INPUTC", 1, 24, &iva, ident);
 
53
 
 
54
if (ident[0] != '*')
 
55
   {
 
56
   n = CGN_INDEXC(ident,',');
 
57
   if (n < 0)
 
58
      {                                 /* input was: colref */
 
59
      (void) strcpy(colref,ident);
 
60
      }
 
61
   else
 
62
      {
 
63
      ident[n++] = '\0';
 
64
      if (n == 1)                       /* input was: ,row_no. */
 
65
         {
 
66
         ;
 
67
         }
 
68
      else
 
69
         {
 
70
         (void) strcpy(colref,ident);
 
71
         }
 
72
      if (ident[n] == '@') n++;         /* @row => row */
 
73
 
 
74
      if (ident[n] != '\0') 
 
75
         {
 
76
         m = -1;
 
77
         m = atoi(ident+n); 
 
78
         if (m != -1) 
 
79
            row_no = m;
 
80
         else
 
81
            SCETER(6,"invalid row no. entered");
 
82
         }
 
83
      }
 
84
   }
 
85
 
 
86
if (row_no < 1) 
 
87
   SCETER(6,"invalid row no. entered");
 
88
 
 
89
 
 
90
/* read name of output table */
 
91
 
 
92
(void) SCKGETC("OUT_A",1,64,&iva,tname);
 
93
 
 
94
      
 
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 */
 
97
 
 
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");
 
102
else
 
103
   {
 
104
   (void) strcpy(format_str,"I10");
 
105
   df = D_I4_FORMAT;
 
106
   }
 
107
 
 
108
(void) SCIGET(fname,df,F_I_MODE,F_IMA_TYPE,MAXDIM,
 
109
              &naxis,npix,start,step,ident,cunit,&pntr,&imno);
 
110
 
 
111
 
 
112
/* determine the no. of rows to write */
 
113
 
 
114
if (naxis == 1)
 
115
   nr = 1;                      /* single line */
 
116
else
 
117
   nr = npix[1];                /* no of lines in 2dim image */
 
118
 
 
119
 
 
120
/* get 1st element and no. of elements to write in array column */
 
121
 
 
122
(void) SCKGETC("INPUTC",31, 20, &iva, ident);   /* opt. 1st_element,noelem */
 
123
 
 
124
felem = 1;                              /* the default values */
 
125
noelem = npix[0];
 
126
if (ident[0] != '*')
 
127
   {
 
128
   n = CGN_INDEXC(ident,',');
 
129
   if (n < 0)
 
130
      {                                 /* input was: 1st_elem */
 
131
      m = -1;
 
132
      m = atoi(ident); 
 
133
      if (m != -1) 
 
134
         felem = m;
 
135
      else
 
136
         SCETER(7,"invalid 1st element entered");
 
137
      }      
 
138
   else
 
139
      {
 
140
      ident[n++] = '\0';        /* n is incremented after op... */
 
141
      if (n == 1)                       /* input was: ,noelem. */
 
142
         {
 
143
         ;
 
144
         }
 
145
      else                              /* get 1st element. */
 
146
         {
 
147
         m = -1;
 
148
         m = atoi(ident); 
 
149
         if (m != -1) 
 
150
            felem = m;
 
151
         else
 
152
            SCETER(7,"invalid 1st element entered");
 
153
         }
 
154
 
 
155
      if (ident[n] != '\0')     /* get noelem */
 
156
         {
 
157
         m = -1;
 
158
         m = atoi(ident+n); 
 
159
         if (m != -1) 
 
160
            noelem = m;
 
161
         else
 
162
            SCETER(8,"invalid no. of elements entered");
 
163
         }
 
164
      }
 
165
   }
 
166
 
 
167
if ((felem < 1) || (felem > npix[0]))
 
168
   SCETER(7,"invalid 1st element entered");
 
169
if (noelem < 1) 
 
170
   SCETER(8,"invalid no. of elements entered");
 
171
 
 
172
m = npix[0] - felem + 1;                /* = max. possible no. of elements */
 
173
if (noelem > m) noelem = m;
 
174
 
 
175
 
 
176
(void) SCKGETC("INPUTC", 26, 1, &iva, ident);   /* update or alloc rows */
 
177
upda = 0;
 
178
allrow = 1;
 
179
if (ident[0] == 'X')
 
180
   {                            /* allocate more rows for new table */
 
181
   int  knull=-1;
 
182
   SCKRDI("INPUTI",1,1,&iva,&allrow,&iva,&knull);
 
183
   if (allrow < 1) 
 
184
      SCETER(9,"invalid no_rows_to_allocate entered");
 
185
   }
 
186
else if (ident[0] == 'U') 
 
187
   upda = 1;                    /* table for updating stuff exists */
 
188
 
 
189
/*
 
190
printf("colref = %s, row no = %d, nr = %d\n",colref,row_no,nr);
 
191
printf("upda = %d\n",upda);
 
192
*/
 
193
 
 
194
 
 
195
/* and create or open this table */
 
196
 
 
197
na = 1;                                 /* 1 new column */
 
198
lastrow = row_no + nr - 1;              /* last row to fill */
 
199
if (lastrow < allrow) lastrow = allrow;
 
200
 
 
201
if (upda == 0)
 
202
   {
 
203
   (void) TCTINI(tname, F_TRANS, F_O_MODE, na, lastrow, &tno);
 
204
   (void) TCCINI(tno,df,noelem,format_str,"intensity",colref,&ncol);
 
205
   }
 
206
else
 
207
   {
 
208
   (void) TCTOPN(tname,F_IO_MODE,&tno);
 
209
   (void) TCIGET(tno,&n,&n,&n,&allcol,&allrow);
 
210
   if (allrow < lastrow)
 
211
      {
 
212
      m = sprintf(tname,"last row (%d) to fill exceeds allocated %d rows",
 
213
                     lastrow,allrow);
 
214
      nr = allrow - row_no + 1;
 
215
      if (nr < 1)
 
216
         {
 
217
         SCTPUT(tname);
 
218
         SCETER(33,"no row can be be written");
 
219
         }
 
220
      else
 
221
         {
 
222
         (void) sprintf(tname+m,", only %d rows will be written",nr);
 
223
         SCTPUT(tname);
 
224
         }
 
225
      }
 
226
   (void) TCCSER(tno,colref,&ncol);
 
227
   if (ncol < 1)
 
228
      {                 /* create new column */
 
229
      (void) TCCINI(tno,df,noelem,format_str,"intensity",colref,&ncol);
 
230
      }
 
231
   else                 /* column found - check data type */
 
232
      {
 
233
      (void) TCFGET(tno,ncol,ident,&n,&iva);
 
234
      if (iva != df)            /* column, image data type don't match */
 
235
         {
 
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);
 
240
         df = iva;
 
241
         SCFCLO(imno);
 
242
         (void) SCIGET(fname,df,F_I_MODE,F_IMA_TYPE,MAXDIM,
 
243
                       &naxis,npix,start,step,ident,cunit,&pntr,&imno);
 
244
         }
 
245
      }
 
246
   }
 
247
 
 
248
/*
 
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);
 
253
*/
 
254
 
 
255
 
 
256
if (df == D_R4_FORMAT)
 
257
   {
 
258
   kpntr = (int *) 0;
 
259
   fpntr = (float *) pntr;
 
260
   dpntr = (double *) 0;
 
261
   }
 
262
else if (df == D_R8_FORMAT)
 
263
   {
 
264
   kpntr = (int *) 0;
 
265
   fpntr = (float *) 0;
 
266
   dpntr = (double *) pntr;
 
267
   }
 
268
else                            /* only D_I4_FORMAT left */
 
269
   {
 
270
   kpntr = (int *) pntr;
 
271
   fpntr = (float *) 0;
 
272
   dpntr = (double *) 0;
 
273
   }
 
274
 
 
275
m = row_no;                     /* starting row no. */
 
276
iva = 1;
 
277
 
 
278
if (nr == 1)                    /* fill only 1 row */
 
279
   {
 
280
   if (df == D_R4_FORMAT)
 
281
      {
 
282
      (void) TCAWRR(tno,m,ncol,felem,noelem,fpntr);
 
283
      }
 
284
   else if (df == D_R8_FORMAT)
 
285
      {
 
286
      (void) TCAWRD(tno,m,ncol,felem,noelem,dpntr);
 
287
      }
 
288
   else
 
289
      {
 
290
      (void) TCAWRI(tno,m,ncol,felem,noelem,kpntr);
 
291
      }
 
292
   (void) TCSPUT(tno,m,&iva);
 
293
   }
 
294
else                            /* fill nr rows (nr may also be just 1) */
 
295
   {
 
296
   if (df == D_R4_FORMAT)
 
297
      {
 
298
      for (n=0; n<nr; n++)
 
299
         {
 
300
         (void) TCAWRR(tno,m,ncol,felem,noelem,fpntr);
 
301
         (void) TCSPUT(tno,m,&iva);
 
302
         fpntr += npix[0];
 
303
         m++;
 
304
         }
 
305
      }
 
306
   else if (df == D_R8_FORMAT)
 
307
      {
 
308
      for (n=0; n<nr; n++)
 
309
         {
 
310
         (void) TCAWRD(tno,m,ncol,felem,noelem,dpntr);
 
311
         (void) TCSPUT(tno,m,&iva);
 
312
         dpntr += npix[0];
 
313
         m++;
 
314
         }
 
315
      }
 
316
   else 
 
317
      {
 
318
      for (n=0; n<nr; n++)
 
319
         {
 
320
         (void) TCAWRI(tno,m,ncol,felem,noelem,kpntr);
 
321
         (void) TCSPUT(tno,m,&iva);
 
322
         kpntr += npix[0];
 
323
         m++;
 
324
         }
 
325
      }
 
326
   }
 
327
 
 
328
 
 
329
/* append keyword HISTORY to descr. HISTORY of table */
 
330
 
 
331
(void) SCKGETC("HISTORY",1, 80, &iva, tname);   
 
332
(void) SCDWRC(tno,"HISTORY",1,tname,-1,80,&iva);
 
333
TCTCLO(tno);
 
334
 
 
335
SCSEPI();
 
336
exit(0);
 
337
}