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 */
11
POSR/R/1/3 : positions of objects/sky to be added/deleted/changed
12
PATH/I/1/2 : Action to be taken:
20
.VERSION 1.0 Creation 18-JAN-1994
23
-------------------------------------------------------
27
#include <midas_def.h>
37
int min_dist,min_sky,tidwin, wrow, kunit, knul;
38
int os_col, o1_col, o2_col, s1_col, s2_col, ss_col;
42
int check_sky(float [], int [], int []);
43
int check_slit(float [], int [], int [], int);
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];
71
/* Read action from keyword PATH */
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);
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);
90
for (i=1;i<=nslits;i++)
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 */
101
/* read table WINDOWS */
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++)
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);
124
case (1): /* delete object */
127
for (i = 0; i <= wrow-1; i++)
129
if (obj1[i] <= posr[0] && obj2[i] >= posr[0])
131
TCEDEL(tidwin, i+1, os_col);
132
TCEDEL(tidwin, i+1, o1_col);
133
TCEDEL(tidwin, i+1, o2_col);
139
sprintf(text, "There is no object");
145
case (2): /* add object */
147
/* check whether object is within slitlet */
148
lim = check_slit(posr, lower, upper, slitrow[slitnum]);
151
/* adapt sky limits for new object */
152
check_obj(posr, sky1, sky2, slitsky);
154
/* write new object */
155
SCDRDI(tidwin, "NOBJ", 1, 1, &actvals, &nobj, &kunit, &knul);
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);
167
case (3): /* delete sky */
169
for (i = 0; i <= wrow-1; i++)
171
if (sky1[i] <= posr[0] && sky2[i] >= posr[0])
173
TCEDEL(tidwin, i+1, s1_col);
174
TCEDEL(tidwin, i+1, s2_col);
175
TCEDEL(tidwin, i+1, ss_col);
181
sprintf(text, "There is no sky");
187
case (4): /* add sky */
189
found = check_sky(posr, obj1, obj2);
192
/* check whether sky is within slitlet */
193
lim = check_slit(posr, lower, upper, slitrow[slitnum]);
198
posi[0] = (int) posr[0];
199
posi[1] = (int) posr[1];
200
SCDRDI(tidwin, "NSKY", 1, 1, &actvals, &nsky, &kunit, &knul);
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);
211
case (5): /* change object */
213
/* find out which object shall be changed */
215
for (i=0; i<=wrow-1; i++)
217
if (obj1[i] < posr[2] && obj2[i] > posr[2])
222
sprintf(text, "There is no object");
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];
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)
233
/* adapt sky for changed object */
234
check_obj(posr, sky1, sky2, slitsky);
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]);
245
case (6): /* change sky */
247
/* find out which sky shall be changed */
249
for (i=0; i<=wrow-1; i++)
251
if (sky1[i] < posr[2] && sky2[i] > posr[2])
256
sprintf(text, "There is no sky");
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];
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)
267
/* check whether sky is within slitlet */
268
lim = check_slit(posr, lower, upper, slitrow[slitnum]);
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]);
282
sprintf(text, "Wrong number - there is no action for this number");
291
/*--------------------------------------------------------------------*/
293
void check_obj(float rpos[], int sky_strt[], int sky_end[], int sky_slit[])
295
void check_obj(rpos, sky_strt, sky_end, sky_slit)
297
int sky_strt[],sky_end[],sky_slit[];
301
int actvals, nsky, i;
303
for (i = 0; i <= wrow-1; i++)
305
/* check whether object is completely within sky */
306
if (sky_strt[i] <= rpos[0]-min_dist && sky_end[i] >= rpos[1]+min_dist)
308
/* sprintf(text, "new object within sky\n");
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)
316
/* sprintf(text,"left sky too small \n");
318
TCEDEL(tidwin, i+1, s1_col);
319
TCEDEL(tidwin, i+1, s2_col);
320
TCEDEL(tidwin, i+1, ss_col);
322
else TCEWRI(tidwin, i+1, s2_col, &sky_end[i]);
324
if ((sky_end[nsky+1]-sky_strt[nsky+1]) <= min_sky-1)
326
/* sprintf(text, "right sky too small \n");
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);
339
/* check whether right part of object is within sky */
341
if (sky_strt[i] > rpos[0]-min_dist && sky_strt[i] < rpos[1]+min_dist && sky_end[i] > rpos[1]+min_dist)
343
/* sprintf(text, "new object within sky\n");
345
sky_strt[i] = rpos[1]+min_dist;
346
if ((sky_end[i]-sky_strt[i]) <= min_sky-1)
348
/* sprintf(text,"rest sky too small \n");
350
TCEDEL(tidwin, i+1, s1_col);
351
TCEDEL(tidwin, i+1, s2_col);
352
TCEDEL(tidwin, i+1, ss_col);
355
TCEWRI(tidwin, i+1, s1_col, &sky_strt[i]);
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)
360
/* sprintf(text, "new object within sky\n");
362
sky_end[i] = rpos[0]-min_dist;
363
if ((sky_end[i]-sky_strt[i]) <= min_sky)
365
/* sprintf(text,"rest sky too small \n");
367
TCEDEL(tidwin, i+1, s1_col);
368
TCEDEL(tidwin, i+1, s2_col);
369
TCEDEL(tidwin, i+1, ss_col);
371
else TCEWRI(tidwin, i+1, s2_col, &sky_end[i]);
374
/* check whether object covers sky region */
375
if (sky_strt[i] >= rpos[0]-min_dist && sky_end[i] <= rpos[1]+min_dist)
377
/* sprintf(text, "new object covers sky region\n");
379
TCEDEL(tidwin, i+1, s1_col);
380
TCEDEL(tidwin, i+1, s2_col);
381
TCEDEL(tidwin, i+1, ss_col);
385
/*-------------------------------------------------------------------*/
387
int check_sky (float rpos[], int obj_strt[], int obj_end[])
389
int check_sky (rpos, obj_strt, obj_end)
391
int obj_strt[],obj_end[];
399
for (i = 0; i <= wrow-1; i++)
401
if (rpos[0] <= obj_strt[i] && rpos[1] >= obj_end[i])
403
sprintf(text,"There is an object within the new sky region!");
405
sprintf(text,"Delete/change object first and then add sky");
409
if (rpos[0] >= obj_strt[i] && rpos[1] <= obj_end[i])
411
sprintf(text,"The new sky region lies within an object's region!");
413
sprintf(text,"Delete object first and then add sky");
417
if (rpos[0] > obj_strt[i] && rpos[0] <= obj_end[i] && rpos[1] >= obj_end[i])
419
sprintf(text,"The new sky region overlaps with an object's region!");
421
sprintf(text,"Delete object first and then add sky");
425
if (rpos[0] <= obj_strt[i] && rpos[1] < obj_end[i] && rpos[1] >= obj_strt[i])
427
sprintf(text,"The new sky region overlaps with an object's region!");
429
sprintf(text,"Delete object first and then add sky");
433
if (rpos[0] > obj_end[i] && rpos[0] < obj_end[i]+min_dist)
435
sprintf(text, "There are less than %d pixels between sky and adjacent object", min_dist);
438
if (rpos[1] < obj_strt[i] && rpos[1] > obj_strt[i]-min_dist)
440
sprintf(text, "There are less than %d pixels between sky and adjacent object", min_dist);
446
/*--------------------------------------------------------------------------*/
448
int check_slit (float rpos[], int slit_strt[], int slit_end[], int numslit)
450
int check_slit (rpos, slit_strt, slit_end, numslit)
452
int slit_strt[],slit_end[],numslit;
459
if (rpos[0] < slit_strt[numslit] || rpos[0] >= slit_end[numslit])
461
sprintf(text,"Lower limit outside slitlet - no change");
465
if (rpos[1] <= slit_strt[numslit] || rpos[1] > slit_end[numslit])
467
sprintf(text,"Upper limit outside slitlet - no change");