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

« back to all changes in this revision

Viewing changes to stdred/mos/src/changedef.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) 1994-2009 European Southern Observatory     */
 
3
/* .IDENT       changedef.c                                */
 
4
/* .AUTHORS     Sabine Moehler   (LSW)                     */
 
5
/* .KEYWORDS    Spectroscopy, Long-Slit, MOS               */
 
6
/* .PURPOSE     Change of sky resp. objects definitions    */
 
7
/*              for MOS spectra                            */
 
8
/*                                                         */
 
9
/*
 
10
   .INPUT/OUTPUT:
 
11
       POSR/R/1/3   :  positions of objects/sky to be added/deleted/changed
 
12
       PATH/I/1/2   :  Action to be taken:
 
13
                       1: delete object
 
14
                       2: add object
 
15
                       3: delete sky
 
16
                       4: add sky
 
17
                       5: change sky
 
18
                       Number of slitlet
 
19
 
 
20
.VERSION     1.0  Creation  18-JAN-1994  
 
21
 
 
22
 090804         last modif
 
23
   -------------------------------------------------------
 
24
*/
 
25
 
 
26
#include <tbldef.h>
 
27
#include <midas_def.h>
 
28
#include <ok.h>
 
29
 
 
30
#include <stdio.h>
 
31
 
 
32
 
 
33
 
 
34
#define MAXSLITS 100
 
35
#define MAXNUM 500
 
36
 
 
37
int   min_dist,min_sky,tidwin, wrow, kunit, knul; 
 
38
int   os_col, o1_col, o2_col, s1_col, s2_col, ss_col;
 
39
char  text[120];
 
40
 
 
41
#ifdef __STDC__
 
42
int check_sky(float [], int [], int []);
 
43
int check_slit(float [], int [], int [], int);
 
44
#else
 
45
int check_sky();
 
46
int check_slit();
 
47
#endif
 
48
 
 
49
void check_obj();
 
50
 
 
51
 
 
52
 
 
53
int main()
 
54
 
 
55
{
 
56
 
 
57
   int   i_sky, i_obj, lim, found, i, tidmos, actvals;
 
58
   int   action, col, nslits, acol, arow, nsort;
 
59
   int   wcol, awcol, awrow, wsort;
 
60
   int   obj1[MAXNUM], obj2[MAXNUM], slitobj[MAXNUM]; 
 
61
   int   sky1[MAXNUM], sky2[MAXNUM], slitsky[MAXNUM];
 
62
   int   null, posi[2], path[2], slitnum, nsky, nobj;
 
63
   int   sl_col, up_col, lo_col;
 
64
   int   slitrow[MAXSLITS], upper[MAXSLITS], lower[MAXSLITS], slit; 
 
65
   char  mos_table[60], window_table[60];
 
66
   float posr[3];
 
67
   
 
68
 
 
69
   SCSPRO("changedef");
 
70
 
 
71
/* Read action from keyword PATH  */
 
72
 
 
73
   SCKRDR("POSR",  1,  3, &actvals, posr, &kunit, &knul);
 
74
   SCKRDI("PATH",  1,  2, &actvals, path, &kunit, &knul);
 
75
   SCKRDI("MIN_DIST",  1,  1, &actvals, &min_dist, &kunit, &knul);
 
76
   SCKRDI("MIN_SKY",  1,  1, &actvals, &min_sky, &kunit, &knul);
 
77
   SCKGETC("IN_B", 1, 60, &actvals, mos_table); 
 
78
   SCKGETC("OUT_A",1, 60, &actvals, window_table);
 
79
   action = path[0];
 
80
   slitnum = path[1];
 
81
 
 
82
/*           read table MOS                            */
 
83
 
 
84
   TCTOPN(mos_table,F_I_MODE,&tidmos);
 
85
   TCIGET(tidmos,&col,&nslits,&nsort,&acol,&arow);
 
86
   TCLSER(tidmos, "slit", &sl_col);
 
87
   TCLSER(tidmos, "ystart", &lo_col);
 
88
   TCLSER(tidmos, "yend", &up_col);
 
89
 
 
90
   for (i=1;i<=nslits;i++) 
 
91
     {
 
92
      TCERDI(tidmos, i, sl_col, &slit, &null);
 
93
      TCERDI(tidmos, i, lo_col, &lower[i-1], &null);
 
94
      TCERDI(tidmos, i, up_col, &upper[i-1], &null);
 
95
/* table row for a given slit number */
 
96
      slitrow[slit] = i-1;
 
97
     }
 
98
 
 
99
   TCTCLO(tidmos);
 
100
 
 
101
/* read table WINDOWS */
 
102
 
 
103
   TCTOPN(window_table,F_IO_MODE,&tidwin);
 
104
   TCIGET(tidwin,&wcol,&wrow,&wsort,&awcol,&awrow);
 
105
   TCLSER(tidwin, "Obj_Slit", &os_col);
 
106
   TCLSER(tidwin, "Obj_Strt", &o1_col);
 
107
   TCLSER(tidwin, "Obj_End", &o2_col);
 
108
   TCLSER(tidwin, "Sky_Strt", &s1_col);
 
109
   TCLSER(tidwin, "Sky_End", &s2_col);
 
110
   TCLSER(tidwin, "Sky_Slit", &ss_col);
 
111
   for (i=1;i<=wrow;i++) 
 
112
     {
 
113
      TCERDI(tidwin, i, os_col, &slitobj[i-1], &null); 
 
114
      TCERDI(tidwin, i, o1_col, &obj1[i-1], &null); 
 
115
      TCERDI(tidwin, i, o2_col, &obj2[i-1], &null); 
 
116
      TCERDI(tidwin, i, s1_col, &sky1[i-1], &null); 
 
117
      TCERDI(tidwin, i, s2_col, &sky2[i-1], &null);
 
118
      TCERDI(tidwin, i, ss_col, &slitsky[i-1], &null);  
 
119
     }
 
120
   found = 0;
 
121
   lim = 0;
 
122
   switch (action)  
 
123
     {
 
124
      case (1):   /* delete object */
 
125
        {
 
126
         found = 0;
 
127
         for (i = 0; i <= wrow-1; i++)
 
128
           {
 
129
            if (obj1[i] <=  posr[0] && obj2[i] >= posr[0])
 
130
              {
 
131
               TCEDEL(tidwin, i+1, os_col);   
 
132
               TCEDEL(tidwin, i+1, o1_col);
 
133
               TCEDEL(tidwin, i+1, o2_col);
 
134
               found = 1;
 
135
              }
 
136
           } 
 
137
         if (found == 0)
 
138
           {
 
139
            sprintf(text, "There is no object");
 
140
            SCTPUT(text);
 
141
           }
 
142
         break;
 
143
        }  
 
144
 
 
145
      case (2):   /* add object */
 
146
        {
 
147
/* check whether object is within slitlet  */
 
148
         lim = check_slit(posr, lower, upper, slitrow[slitnum]); 
 
149
         if (lim == 0)
 
150
           {
 
151
/* adapt sky limits for new object  */
 
152
            check_obj(posr, sky1, sky2, slitsky);
 
153
 
 
154
/* write new object */
 
155
            SCDRDI(tidwin, "NOBJ", 1, 1, &actvals, &nobj, &kunit, &knul);
 
156
            nobj++;
 
157
            TCEWRI(tidwin, nobj, os_col, &slitnum);
 
158
            posi[0] = (int) posr[0];
 
159
            posi[1] = (int) posr[1];
 
160
            TCEWRI(tidwin, nobj, o1_col, &posi[0]);
 
161
            TCEWRI(tidwin, nobj, o2_col, &posi[1]);
 
162
            SCDWRI(tidwin, "NOBJ", &nobj, 1, 1, &kunit); 
 
163
           }
 
164
         break;
 
165
        }  
 
166
 
 
167
      case (3):   /* delete sky */
 
168
        {
 
169
         for (i = 0; i <= wrow-1; i++)
 
170
           {
 
171
            if (sky1[i] <=  posr[0] && sky2[i] >= posr[0])
 
172
              {
 
173
               TCEDEL(tidwin, i+1, s1_col);   
 
174
               TCEDEL(tidwin, i+1, s2_col);
 
175
               TCEDEL(tidwin, i+1, ss_col);
 
176
               found = 1;
 
177
              }
 
178
           }
 
179
         if (found == 0)
 
180
           {
 
181
            sprintf(text, "There is no sky");
 
182
            SCTPUT(text);
 
183
           }
 
184
         break;
 
185
        }  
 
186
 
 
187
      case (4):   /* add sky */
 
188
        {
 
189
         found = check_sky(posr, obj1, obj2); 
 
190
         if (found == 0)
 
191
           {
 
192
/* check whether sky is within slitlet  */
 
193
            lim = check_slit(posr, lower, upper, slitrow[slitnum]); 
 
194
             
 
195
/* write new sky */
 
196
            if (lim == 0)
 
197
              {   
 
198
               posi[0] = (int) posr[0];
 
199
               posi[1] = (int) posr[1];
 
200
               SCDRDI(tidwin, "NSKY", 1, 1, &actvals, &nsky, &kunit, &knul);
 
201
               nsky++;
 
202
               TCEWRI(tidwin, nsky, s1_col, &posi[0]);
 
203
               TCEWRI(tidwin, nsky, s2_col, &posi[1]);
 
204
               TCEWRI(tidwin, nsky, ss_col, &slitnum);
 
205
               SCDWRI(tidwin, "NSKY", &nsky, 1, 1, &kunit); 
 
206
              }
 
207
           }
 
208
         break;
 
209
        }  
 
210
 
 
211
      case (5):   /* change object */
 
212
        {
 
213
/* find out which object shall be changed */
 
214
         i_obj = -1;
 
215
         for (i=0; i<=wrow-1; i++)
 
216
           {
 
217
            if (obj1[i] < posr[2] && obj2[i] > posr[2])
 
218
               i_obj = i;
 
219
           }
 
220
         if (i_obj < 0)
 
221
           {
 
222
            sprintf(text, "There is no object");
 
223
            SCTPUT(text);
 
224
           } 
 
225
/* check if only one limit shall be changed and adjust posr */
 
226
         if (posr[0] <= -9999.9) posr[0] = obj1[i_obj];
 
227
         if (posr[1] <= -9999.9) posr[1] = obj2[i_obj];
 
228
 
 
229
/* check whether object is within slitlet  */
 
230
         if (i_obj >= 0) lim = check_slit(posr, lower, upper, slitrow[slitnum]); 
 
231
         if (lim == 0 && i_obj >= 0)
 
232
           {
 
233
/* adapt sky for changed object */
 
234
            check_obj(posr, sky1, sky2, slitsky);
 
235
 
 
236
/* write changed object */
 
237
            posi[0] = (int) posr[0];
 
238
            posi[1] = (int) posr[1];
 
239
            TCEWRI(tidwin, i_obj+1, o1_col, &posi[0]);
 
240
            TCEWRI(tidwin, i_obj+1, o2_col, &posi[1]);
 
241
           }
 
242
         break;
 
243
        }  
 
244
 
 
245
      case (6):   /* change sky */
 
246
        {
 
247
/* find out which sky shall be changed */
 
248
         i_sky = -1;
 
249
         for (i=0; i<=wrow-1; i++)
 
250
           {
 
251
            if (sky1[i] < posr[2] && sky2[i] > posr[2])
 
252
            i_sky = i;
 
253
           }
 
254
         if (i_sky < 0)
 
255
           {
 
256
            sprintf(text, "There is no sky");
 
257
            SCTPUT(text);
 
258
           } 
 
259
/* check if only one limit shall be changed and adjust posr */
 
260
         if (posr[0] <= -9999.9) posr[0] = sky1[i_sky];
 
261
         if (posr[1] <= -9999.9) posr[1] = sky2[i_sky];
 
262
 
 
263
/* check that there is no object within changed sky   */
 
264
         if (i_sky >= 0) found = check_sky(posr, obj1, obj2); 
 
265
         if (found == 0 && i_sky >= 0)
 
266
           {
 
267
/* check whether sky is within slitlet  */
 
268
            lim = check_slit(posr, lower, upper, slitrow[slitnum]); 
 
269
            if (lim == 0)
 
270
              {   
 
271
/* write changed sky */
 
272
               posi[0] = (int) posr[0];
 
273
               posi[1] = (int) posr[1];
 
274
               TCEWRI(tidwin, i_sky+1, s1_col, &posi[0]);
 
275
               TCEWRI(tidwin, i_sky+1, s2_col, &posi[1]);
 
276
              }
 
277
           }
 
278
         break;
 
279
        }  
 
280
      default:
 
281
        {
 
282
         sprintf(text, "Wrong number - there is no action for this number");
 
283
         SCTPUT(text);
 
284
         break;
 
285
        }
 
286
     } 
 
287
   TCTCLO(tidwin);
 
288
   SCSEPI();
 
289
return 0;
 
290
}
 
291
/*--------------------------------------------------------------------*/
 
292
#ifdef __STDC__
 
293
void check_obj(float rpos[], int sky_strt[], int sky_end[], int sky_slit[])
 
294
#else
 
295
void check_obj(rpos, sky_strt, sky_end, sky_slit)
 
296
float rpos[];
 
297
int sky_strt[],sky_end[],sky_slit[];
 
298
#endif
 
299
 
 
300
{
 
301
  int   actvals, nsky, i;
 
302
  
 
303
  for (i = 0; i <= wrow-1; i++)  
 
304
     {
 
305
/* check whether object is completely within sky    */
 
306
      if (sky_strt[i] <=  rpos[0]-min_dist && sky_end[i] >= rpos[1]+min_dist)
 
307
        {
 
308
         /* sprintf(text, "new object within sky\n");
 
309
         SCTPUT(text); */
 
310
         SCDRDI(tidwin, "NSKY", 1, 1, &actvals, &nsky, &kunit, &knul);
 
311
         sky_end[i] = rpos[0]-min_dist;
 
312
         sky_strt[nsky+1] = rpos[1]+min_dist;
 
313
         sky_end[nsky+1] = sky_end[i]; 
 
314
         if ((sky_end[i]-sky_strt[i]) <= min_sky-1) 
 
315
           {
 
316
            /* sprintf(text,"left sky too small   \n");
 
317
            SCTPUT(text); */
 
318
            TCEDEL(tidwin, i+1, s1_col);
 
319
            TCEDEL(tidwin, i+1, s2_col);
 
320
            TCEDEL(tidwin, i+1, ss_col);
 
321
           }
 
322
         else TCEWRI(tidwin, i+1, s2_col, &sky_end[i]);   
 
323
           
 
324
         if ((sky_end[nsky+1]-sky_strt[nsky+1]) <= min_sky-1) 
 
325
           {
 
326
            /* sprintf(text, "right sky too small   \n");
 
327
            SCTPUT(text); */
 
328
           }
 
329
         else
 
330
           {
 
331
            nsky++;
 
332
            TCEWRI(tidwin, nsky, s1_col, &sky_strt[nsky]);
 
333
            TCEWRI(tidwin, nsky, s2_col, &sky_end[nsky]);
 
334
            TCEWRI(tidwin, nsky, ss_col, &sky_slit[i]); 
 
335
            SCDWRI(tidwin, "NSKY", &nsky, 1, 1, &kunit); 
 
336
           }
 
337
        }
 
338
 
 
339
/* check whether right part of object is within sky     */
 
340
 
 
341
      if (sky_strt[i] > rpos[0]-min_dist && sky_strt[i] < rpos[1]+min_dist && sky_end[i] > rpos[1]+min_dist)
 
342
        {
 
343
         /* sprintf(text, "new object within sky\n");
 
344
         SCTPUT(text); */
 
345
         sky_strt[i] = rpos[1]+min_dist;
 
346
         if ((sky_end[i]-sky_strt[i]) <= min_sky-1) 
 
347
           {
 
348
            /* sprintf(text,"rest sky too small   \n");
 
349
            SCTPUT(text); */
 
350
            TCEDEL(tidwin, i+1, s1_col);
 
351
            TCEDEL(tidwin, i+1, s2_col);
 
352
            TCEDEL(tidwin, i+1, ss_col);   
 
353
           }
 
354
         else 
 
355
           TCEWRI(tidwin, i+1, s1_col, &sky_strt[i]);  
 
356
        }  
 
357
/*    check whether left part of object is within sky     */
 
358
      if (sky_end[i] < rpos[1]+min_dist && sky_end[i] > rpos[0]-min_dist && sky_strt[i] < rpos[0]-min_dist)
 
359
        {
 
360
         /* sprintf(text, "new object within sky\n");
 
361
         SCTPUT(text); */
 
362
         sky_end[i] = rpos[0]-min_dist;
 
363
         if ((sky_end[i]-sky_strt[i]) <= min_sky) 
 
364
           {
 
365
            /* sprintf(text,"rest sky too small   \n");
 
366
            SCTPUT(text);  */
 
367
            TCEDEL(tidwin, i+1, s1_col);
 
368
            TCEDEL(tidwin, i+1, s2_col);
 
369
            TCEDEL(tidwin, i+1, ss_col);
 
370
           }
 
371
         else TCEWRI(tidwin, i+1, s2_col, &sky_end[i]);  
 
372
        }
 
373
 
 
374
/*    check whether object covers sky region      */
 
375
      if (sky_strt[i] >=  rpos[0]-min_dist && sky_end[i] <= rpos[1]+min_dist)
 
376
        {
 
377
         /* sprintf(text, "new object covers sky region\n");
 
378
         SCTPUT(text); */
 
379
         TCEDEL(tidwin, i+1, s1_col);
 
380
         TCEDEL(tidwin, i+1, s2_col);
 
381
         TCEDEL(tidwin, i+1, ss_col);
 
382
        }
 
383
     }
 
384
}
 
385
/*-------------------------------------------------------------------*/
 
386
#ifdef __STDC__
 
387
int check_sky (float rpos[], int obj_strt[], int obj_end[])
 
388
#else
 
389
int check_sky (rpos, obj_strt, obj_end)
 
390
float rpos[];
 
391
int obj_strt[],obj_end[];
 
392
#endif
 
393
 
 
394
{
 
395
  int   i, found;
 
396
  
 
397
  found = 0;
 
398
  
 
399
  for (i = 0; i <= wrow-1; i++)
 
400
     {
 
401
      if (rpos[0] <= obj_strt[i] && rpos[1] >= obj_end[i])
 
402
        {
 
403
         sprintf(text,"There is an object within the new sky region!");
 
404
         SCTPUT(text);
 
405
         sprintf(text,"Delete/change object first and then add sky");
 
406
         SCTPUT(text);
 
407
         found = 1;
 
408
        }
 
409
      if (rpos[0] >= obj_strt[i] && rpos[1] <= obj_end[i])
 
410
        {
 
411
         sprintf(text,"The new sky region lies within an object's region!");
 
412
         SCTPUT(text);
 
413
         sprintf(text,"Delete object first and then add sky");
 
414
         SCTPUT(text);
 
415
         found = 1;
 
416
        }
 
417
      if (rpos[0] > obj_strt[i] && rpos[0] <= obj_end[i] && rpos[1] >= obj_end[i])
 
418
        {
 
419
         sprintf(text,"The new sky region overlaps with an object's region!");
 
420
         SCTPUT(text);
 
421
         sprintf(text,"Delete object first and then add sky");
 
422
         SCTPUT(text);
 
423
         found = 1;
 
424
        }
 
425
      if (rpos[0] <= obj_strt[i] && rpos[1] < obj_end[i] && rpos[1] >= obj_strt[i])
 
426
        {
 
427
         sprintf(text,"The new sky region overlaps with an object's region!");
 
428
         SCTPUT(text);
 
429
         sprintf(text,"Delete object first and then add sky");
 
430
         SCTPUT(text);
 
431
         found = 1;
 
432
        }
 
433
      if (rpos[0] > obj_end[i] && rpos[0] < obj_end[i]+min_dist)
 
434
        {
 
435
         sprintf(text, "There are less than %d pixels between sky and adjacent object", min_dist);
 
436
         SCTPUT(text);
 
437
        }
 
438
      if (rpos[1] < obj_strt[i] && rpos[1] > obj_strt[i]-min_dist)
 
439
        {
 
440
         sprintf(text, "There are less than %d pixels between sky and adjacent object", min_dist);
 
441
         SCTPUT(text);
 
442
        }
 
443
     }
 
444
   return found;
 
445
}
 
446
/*--------------------------------------------------------------------------*/
 
447
#ifdef __STDC__
 
448
int check_slit (float rpos[], int slit_strt[], int slit_end[], int numslit)
 
449
#else
 
450
int check_slit (rpos, slit_strt, slit_end, numslit)
 
451
float rpos[];
 
452
int slit_strt[],slit_end[],numslit;
 
453
#endif
 
454
 
 
455
{
 
456
   int limit;
 
457
 
 
458
   limit = 0;
 
459
   if (rpos[0] < slit_strt[numslit] || rpos[0] >= slit_end[numslit]) 
 
460
     {
 
461
      sprintf(text,"Lower limit outside slitlet - no change");
 
462
      SCTPUT(text);
 
463
      limit = 1;
 
464
     }
 
465
   if (rpos[1] <= slit_strt[numslit] || rpos[1] > slit_end[numslit])
 
466
     {
 
467
      sprintf(text,"Upper limit outside slitlet - no change");
 
468
      SCTPUT(text);
 
469
      limit = 1;
 
470
     }
 
471
   return limit;
 
472
}