public software.sextractor

[/] [branches/] [multi/] [src/] [catout.c] - Blame information for rev 285

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 bertin
/*
2 233 bertin
*                               catout.c
3 2 bertin
*
4 233 bertin
* Functions related to catalogue output.
5 2 bertin
*
6 233 bertin
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 2 bertin
*
8 233 bertin
*       This file part of:      SExtractor
9 2 bertin
*
10 281 bertin
*       Copyright:              (C) 1993-2012 Emmanuel Bertin -- IAP/CNRS/UPMC
11 2 bertin
*
12 233 bertin
*       License:                GNU General Public License
13
*
14
*       SExtractor is free software: you can redistribute it and/or modify
15
*       it under the terms of the GNU General Public License as published by
16
*       the Free Software Foundation, either version 3 of the License, or
17
*       (at your option) any later version.
18
*       SExtractor is distributed in the hope that it will be useful,
19
*       but WITHOUT ANY WARRANTY; without even the implied warranty of
20
*       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
*       GNU General Public License for more details.
22
*       You should have received a copy of the GNU General Public License
23
*       along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
24
*
25 282 bertin
*       Last modified:          20/03/2012
26 233 bertin
*
27
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
28
 
29 2 bertin
#ifdef HAVE_CONFIG_H
30
#include        "config.h"
31
#endif
32
 
33
#include        <math.h>
34
#include        <stdio.h>
35
#include        <stdlib.h>
36
#include        <string.h>
37
 
38
#include        "define.h"
39
#include        "globals.h"
40 252 bertin
#include        "catout.h"
41 2 bertin
#include        "prefs.h"
42
#include        "fits/fitscat.h"
43
#include        "param.h"
44
#include        "sexhead.h"
45
#include        "sexhead1.h"
46
#include        "sexheadsc.h"
47 15 bertin
#include        "xml.h"
48 2 bertin
 
49
catstruct       *fitscat;
50 17 bertin
tabstruct       *objtab = NULL;
51 2 bertin
FILE            *ascfile;
52
char            *buf;
53 16 bertin
int             catopen_flag = 0;
54 2 bertin
 
55 252 bertin
/****** catout_readparams ****************************************************
56 282 bertin
PROTO   obj2liststruct *catout_readparams(char **paramlist, int nparam,
57 252 bertin
                                                int nobj2)
58
PURPOSE Read user's choice of catalog parameters and initialize obj2 list.
59
INPUT   Array of pointers to strings containing the measurement parameters,
60
        number of parameters,
61
        number of obj2list members.
62
OUTPUT  Pointer to the allocated obj2list.
63 272 bertin
NOTES   Requires access to the objtab and obj2key static pointers.
64 252 bertin
AUTHOR  E. Bertin (IAP)
65 281 bertin
VERSION 15/02/2012
66 252 bertin
 ***/
67
obj2liststruct  *catout_readparams(char **paramlist, int nparam, int nobj2)
68 2 bertin
  {
69 251 bertin
   obj2liststruct       *obj2list;
70 267 bertin
   obj2struct           *obj2, *prevobj2;
71 251 bertin
   keystruct            *key, *tabkey;
72 252 bertin
   char                 *keyword, *str;
73 275 bertin
   int                  naxisn[MAXNPARAMAXIS],
74 273 bertin
                        i,k,o,p, size, nkeys, ntaxis;
75 2 bertin
 
76
/* Prepare the OBJECTS tables*/
77
  objtab = new_tab("OBJECTS");
78
 
79
/* Scan the catalog config file*/
80 251 bertin
  nkeys = 0;
81 252 bertin
  for (p=0; p<nparam; p++)
82 2 bertin
    {
83 252 bertin
    str = paramlist[p];
84
    if (*str!=(char)'#' && *str!=(char)'\n')
85 2 bertin
      {
86 252 bertin
      keyword = strtok(str, " \t{[(\n\r");
87 2 bertin
      if (keyword &&
88 272 bertin
        (k = findkey(keyword,(char *)obj2key,sizeof(keystruct)))!=RETURN_ERROR)
89 2 bertin
        {
90 272 bertin
        key = obj2key+k;
91 2 bertin
        add_key(key, objtab, 0);
92
        *((char *)key->ptr) = (char)'\1';
93 268 bertin
        size=t_size[key->ttype];
94 251 bertin
        nkeys++;
95 2 bertin
        if (key->naxis)
96
          {
97 273 bertin
          ntaxis = 0;
98 2 bertin
          for (i=0; i<key->naxis; i++)
99
            {
100 273 bertin
            naxisn[i] = 0;
101
            if (!key->naxisn[i])
102
              ntaxis++;
103 2 bertin
            }
104 273 bertin
          if (ntaxis)
105
/*---------- Read only axis sizes that are not already set */
106
            for (i=0; (str = strtok(NULL, " \t,;.)]}\r")) && *str!=(char)'#'
107
                && *str!=(char)'\n'; i++)
108
              {
109
              naxisn[i] = 1;
110
              if (i>=ntaxis)
111
                error(EXIT_FAILURE,
112
                        "*Error*: too many dimensions for keyword ", keyword);
113
              if (!(size*=(naxisn[i]=atoi(str))))
114
                    error(EXIT_FAILURE,
115
                        "*Error*: wrong array syntax for keyword ", keyword);
116
              }
117
          for (i=0; i<key->naxis; i++)
118
            if (!key->naxisn[i])
119 275 bertin
              size *= (key->naxisn[i] = naxisn[i]? naxisn[i] : 1);
120 2 bertin
          }
121 268 bertin
        key->nbytes = size;
122 2 bertin
        }
123
      else
124
        warning(keyword, " catalog parameter unknown");
125
      }
126
    }
127
 
128 251 bertin
/* Allocate memory for the obj2list */
129
  QMALLOC(obj2list, obj2liststruct, 1);
130 267 bertin
  obj2list->nobj2 = nobj2;
131 251 bertin
  obj2list->nkeys = nkeys;
132 267 bertin
  QCALLOC(obj2list->obj2, obj2struct, nobj2);
133 2 bertin
 
134 251 bertin
/* Create key arrays for the catalog buffer, with the right pointers */
135 267 bertin
/* And initialize the free obj2 linked list */
136
  obj2list->freeobj2 = obj2list->obj2;
137
  prevobj2 = NULL;
138
  for (o=0; o<nobj2; o++)
139
    {
140
    obj2 = &obj2list->obj2[o];
141
    obj2->prevobj2 = prevobj2;
142
    if (prevobj2)
143
      prevobj2->nextobj2 = obj2;
144
    if (nkeys)
145 251 bertin
      {
146 260 bertin
      QMALLOC(obj2->keys, keystruct, nkeys);
147
      key = obj2->keys;
148 251 bertin
      tabkey = objtab->key;
149
      for (k=nkeys; k--; key++)
150
        {
151
        *key = *tabkey;
152
        key->prevkey = key-1;
153
        key->nextkey = key+1;
154 272 bertin
        key->ptr = (char *)obj2 + ((char *)tabkey->ptr - (char *)&flagobj2);
155 251 bertin
        tabkey = tabkey->nextkey;
156
        }
157 260 bertin
      obj2->keys[0].prevkey = obj2->keys + nkeys-1;
158
      obj2->keys[nkeys-1].nextkey = obj2->keys;
159 251 bertin
      }
160 267 bertin
    prevobj2 = obj2;
161
    }
162 251 bertin
 
163 252 bertin
  catout_updateparamflags();
164 2 bertin
 
165 251 bertin
  return obj2list;
166
  }
167
 
168
 
169 252 bertin
/****** catout_changeparamsize *********************************************
170 282 bertin
PROTO   void catout_changeparamsize(char *keyword, int *axisn, int naxis)
171 252 bertin
PURPOSE Change the size of a multidimensional measurement parameter.
172
INPUT   keyword string,
173
        array of sizes,
174
        number of dimensions.
175
OUTPUT  -.
176 272 bertin
NOTES   Requires access to the obj2key static pointer.
177 252 bertin
AUTHOR  E. Bertin (IAP)
178 281 bertin
VERSION 15/02/2012
179 252 bertin
 ***/
180
void    catout_changeparamsize(char *keyword, int *axisn, int naxis)
181 251 bertin
  {
182
   keystruct    *key;
183 281 bertin
   int          i,k;
184 251 bertin
 
185 272 bertin
  if ((k = findkey(keyword,(char *)obj2key,sizeof(keystruct)))!=RETURN_ERROR)
186 251 bertin
    {
187 272 bertin
    key = obj2key+k;
188 251 bertin
    if (key->naxis)
189
      {
190
      key->naxis = naxis;
191
      for (i=0; i<naxis; i++)
192 281 bertin
        key->naxisn[i]=axisn[i];
193 251 bertin
      }
194 267 bertin
    }
195 251 bertin
 
196 173 bertin
  return;
197
  }
198
 
199
 
200 252 bertin
/****** catout_allocparams *************************************************
201 282 bertin
PROTO   void catout_allocparams(obj2liststruct *obj2list)
202 252 bertin
PURPOSE Allocate arrays for all multidimensional measurement parameters.
203
INPUT   Pointer to the obj2list.
204
OUTPUT  -.
205 272 bertin
NOTES   Requires access to the obj2key static pointer.
206 252 bertin
AUTHOR  E. Bertin (IAP)
207 281 bertin
VERSION 15/02/2012
208 252 bertin
 ***/
209
void    catout_allocparams(obj2liststruct *obj2list)
210 173 bertin
  {
211 270 bertin
   obj2struct   *obj2;
212 272 bertin
   keystruct    *key, *key2;
213 267 bertin
   char         **ptr;
214 281 bertin
   int          i,k,o, nkeys, ptroffset, size;
215 173 bertin
 
216 251 bertin
/* Allocate arrays for multidimensional measurement parameters */
217 260 bertin
/* Note that they do not need to be selected for catalog output */
218 272 bertin
  nkeys = obj2list->nkeys;
219
  for (key=obj2key; *key->name; key++)
220 267 bertin
    if (key->naxis && *((char *)key->ptr))
221 251 bertin
      {
222 281 bertin
      size=t_size[key->ttype];
223
      for (i=0; i<key->naxis; i++)
224
        size *= key->naxisn[i];
225
      key->nbytes = size;
226 272 bertin
      ptroffset = (char *)key->ptr-(char *)&flagobj2;
227 270 bertin
      obj2 = obj2list->obj2;
228
      for (o=obj2list->nobj2; o--; obj2++)
229 2 bertin
        {
230 272 bertin
        ptr = (char **)((char *)obj2 + ptroffset);
231 281 bertin
        QCALLOC(*ptr, char, size);
232 272 bertin
/*------ Now the tricky part: we replace the pointer to the array pointer */
233 281 bertin
/*------ with the array pointer itself when applicable */
234 272 bertin
        key2=obj2->keys;
235
        for (k=nkeys; k--; key2++)
236
          if (key2->ptr == ptr)
237 281 bertin
            {
238 272 bertin
            key2->ptr = *ptr;
239 281 bertin
            key2->nbytes = size;
240
            }
241 2 bertin
        }
242 251 bertin
      }
243 2 bertin
 
244
  return;
245
  }
246
 
247 251 bertin
 
248 252 bertin
/****** catout_freeparams *************************************************
249 282 bertin
PROTO   void catout_freeparams(obj2liststruct *obj2list)
250 252 bertin
PURPOSE Free memory for all multidimensional measurement parameters.
251
INPUT   Pointer to the obj2list.
252
OUTPUT  -.
253 272 bertin
NOTES   Requires access to the obj2key static pointer.
254 252 bertin
AUTHOR  E. Bertin (IAP)
255 281 bertin
VERSION 15/02/2012
256 252 bertin
 ***/
257
void    catout_freeparams(obj2liststruct *obj2list)
258 173 bertin
  {
259 270 bertin
   obj2struct   *obj2;
260 173 bertin
   keystruct    *key;
261 267 bertin
   char         **ptr;
262 270 bertin
   int          o, ptroffset;
263 2 bertin
 
264 270 bertin
/* Free arrays allocated for multidimensional measurement parameters */
265 272 bertin
  for (key=obj2key; *key->name; key++)
266 267 bertin
    if (key->naxis && *((char *)key->ptr))
267 251 bertin
      {
268 272 bertin
      ptroffset = (char *)key->ptr-(char *)&flagobj2;
269 270 bertin
      obj2 = obj2list->obj2;
270
      for (o=obj2list->nobj2; o--; obj2++)
271 173 bertin
        {
272 281 bertin
        ptr = (char **)((char *)obj2 + ptroffset);
273 270 bertin
        free(*ptr);
274 173 bertin
        }
275 251 bertin
      }
276 173 bertin
 
277
  return;
278
  }
279
 
280 251 bertin
 
281 281 bertin
/****** catout_allocother *************************************************
282 282 bertin
PROTO   int catout_allocother(obj2liststruct *obj2list, void *flagobj2elem,
283 281 bertin
                                int nbytes)
284
PURPOSE Allocate an array in the obj2 structure that does not correspond
285
        to a measurement parameter.
286
INPUT   Pointer to the obj2list,
287
        pointer to the flagobj2 element pointer which must be allocated.
288
        number of bytes to be allocated
289
OUTPUT  RETURN_OK if pointers were not already allocated, or RETURN_ERROR
290
        otherwise.
291
NOTES   -.
292
AUTHOR  E. Bertin (IAP)
293
VERSION 14/02/2012
294
 ***/
295
int     catout_allocother(obj2liststruct *obj2list, void *flagobj2elem,
296
                                int nbytes)
297
  {
298
   obj2struct   *obj2;
299
   char         **ptr;
300
   int          o, ptroffset;
301
 
302
   if (*(char *)flagobj2elem)
303
     return RETURN_ERROR;
304
 
305
   ptroffset = (char *)flagobj2elem - (char *)&flagobj2;
306
   obj2 = obj2list->obj2;
307
   for (o=obj2list->nobj2; o--; obj2++)
308
     {
309
     ptr = (char **)((char *)obj2 + ptroffset);
310
     QCALLOC(*ptr, char, nbytes);
311
     }
312
 
313
  *(char *)flagobj2elem = 1;
314
 
315
  return RETURN_OK;
316
  }
317
 
318
 
319
/****** catout_freeother *************************************************
320 282 bertin
PROTO   int catout_freeother(obj2liststruct *obj2list, void *flagobj2elem)
321 281 bertin
PURPOSE Free an array in the obj2 structure that does not correspond
322
        to a measurement parameter.
323
INPUT   Pointer to the obj2list,
324
        pointer to the flagobj2 element pointer which must be free'ed.
325
OUTPUT  RETURN_OK if pointers were already allocated, or RETURN_ERROR otherwise.
326
NOTES   -.
327
AUTHOR  E. Bertin (IAP)
328
VERSION 15/02/2012
329
 ***/
330
int     catout_freeother(obj2liststruct *obj2list, void *flagobj2elem)
331
  {
332
   obj2struct   *obj2;
333
   char         **ptr;
334
   int          o, ptroffset;
335
 
336
  if (!*(char *)flagobj2elem)
337
    return RETURN_ERROR;
338
 
339
/* Free arrays allocated for multidimensional measurement parameters */
340
  ptroffset = (char *)flagobj2elem - (char *)&flagobj2;
341
  obj2 = obj2list->obj2;
342
  for (o=obj2list->nobj2; o--; obj2++)
343
    {
344
    ptr = (char **)((char *)obj2 + ptroffset);
345
    free(*ptr);
346
    }
347
 
348
  *(char *)flagobj2elem = 0;
349
 
350
  return RETURN_OK;
351
  }
352
 
353
 
354 252 bertin
/****** catout_updateparamflags **********************************************
355 282 bertin
PROTO   void catout_updateparamflags(void)
356 252 bertin
PURPOSE Update parameter flags according to their mutual dependencies.
357
INPUT   Pointer to the obj2list.
358
OUTPUT  -.
359
NOTES   Requires access to the flagobj2 static pointer.
360
AUTHOR  E. Bertin (IAP)
361 285 bertin
VERSION 06/05/2012
362 252 bertin
 ***/
363
void    catout_updateparamflags(void)
364 2 bertin
 
365
  {
366
   int  i;
367
 
368 282 bertin
 
369
/*---------------------------- Always required ------------------------------*/
370
 
371
  FLAG(obj2.bkg) = 1;                   /* Sky background */
372
 
373 173 bertin
/*----------------------------- Model-fitting -----------------------------*/
374
 
375
  prefs.pattern_flag |= FLAG(obj2.prof_disk_patternvector)
376
                        | FLAG(obj2.prof_disk_patternmodvector)
377
                        | FLAG(obj2.prof_disk_patternargvector)
378
                        | FLAG(obj2.prof_disk_patternspiral);
379
  FLAG(obj2.prof_disk_scale) |= prefs.pattern_flag;
380
 
381 209 bertin
  FLAG(obj2.prof_concentration) |= FLAG(obj2.prof_concentrationerr);
382 245 bertin
  FLAG(obj2.fluxcorerr_prof) |= FLAG(obj2.magcorerr_prof);
383
  FLAG(obj2.fluxcor_prof) |= FLAG(obj2.magcor_prof)
384
                        | FLAG(obj2.fluxcorerr_prof);
385
  FLAG(obj2.fluxerr_prof) |= FLAG(obj2.magerr_prof)
386
                        | FLAG(obj2.prof_concentrationerr)
387
                        | FLAG(obj2.fluxcorerr_prof);
388
  FLAG(obj2.flux_prof) |= FLAG(obj2.mag_prof)
389
                        | FLAG(obj2.fluxerr_prof)
390
                        | FLAG(obj2.fluxcor_prof);
391
 
392
 
393 173 bertin
  FLAG(obj2.poserraw_prof) |= FLAG(obj2.poserrbw_prof);
394
  FLAG(obj2.poserrcxxw_prof) |= FLAG(obj2.poserrcyyw_prof)
395
                        | FLAG(obj2.poserrcxyw_prof);
396
  FLAG(obj2.poserrthetas_prof) |= FLAG(obj2.poserrtheta1950_prof)
397
                                | FLAG(obj2.poserrtheta2000_prof);
398
  FLAG(obj2.poserrthetaw_prof) |= FLAG(obj2.poserrthetas_prof);
399
 
400
  FLAG(obj2.poserrmx2w_prof) |= FLAG(obj2.poserrmy2w_prof)
401
                        | FLAG(obj2.poserrmxyw_prof)
402
                        | FLAG(obj2.poserrthetaw_prof)|FLAG(obj2.poserraw_prof)
403
                        | FLAG(obj2.poserrcxxw_prof);
404
 
405
  FLAG(obj2.poserra_prof) |= FLAG(obj2.poserrb_prof)
406
                        | FLAG(obj2.poserrtheta_prof)
407
                        | FLAG(obj2.poserraw_prof);
408
  FLAG(obj2.poserrcxx_prof) |= FLAG(obj2.poserrcyy_prof)
409
                        | FLAG(obj2.poserrcxy_prof);
410 221 bertin
  FLAG(obj2.poserrmx2_prof) |= FLAG(obj2.poserrmy2_prof)
411
                        | FLAG(obj2.poserrmxy_prof)
412
                        | FLAG(obj2.poserrmx2w_prof);
413 173 bertin
  FLAG(obj2.alpha1950_prof) |= FLAG(obj2.delta1950_prof)
414
                        | FLAG(obj2.poserrtheta1950_prof);
415
  FLAG(obj2.alpha2000_prof) |= FLAG(obj2.delta2000_prof)
416
                        | FLAG(obj2.alpha1950_prof)
417
                        | FLAG(obj2.poserrtheta2000_prof);
418
  FLAG(obj2.alphas_prof) |= FLAG(obj2.deltas_prof)
419
                        | FLAG(obj2.alpha2000_prof);
420
  FLAG(obj2.xw_prof) |= FLAG(obj2.yw_prof)
421
                        | FLAG(obj2.alphas_prof);
422 199 bertin
  FLAG(obj2.xf_prof) |= FLAG(obj2.yf_prof);
423 173 bertin
  FLAG(obj2.x_prof) |= FLAG(obj2.y_prof)
424
                        | FLAG(obj2.xw_prof)
425 199 bertin
                        | FLAG(obj2.xf_prof)
426 173 bertin
                        | FLAG(obj2.poserra_prof)
427 179 bertin
                        | FLAG(obj2.poserrcxx_prof)
428 221 bertin
                        | FLAG(obj2.poserrmx2_prof)
429 179 bertin
                        | FLAG(obj2.prof_concentration)
430 245 bertin
                        | FLAG(obj2.prof_class_star)
431
                        | FLAG(obj2.fluxcor_prof);
432 199 bertin
 
433 233 bertin
  FLAG(obj2.prof_dirac_mag) |= FLAG(obj2.prof_dirac_magerr);
434 173 bertin
  FLAG(obj2.prof_spheroid_mag) |= FLAG(obj2.prof_spheroid_magerr);
435
  FLAG(obj2.prof_spheroid_reff) |= FLAG(obj2.prof_spheroid_refferr);
436
  FLAG(obj2.prof_spheroid_aspect) |= FLAG(obj2.prof_spheroid_aspecterr);
437
  FLAG(obj2.prof_spheroid_theta) |= FLAG(obj2.prof_spheroid_thetaerr);
438
  FLAG(obj2.prof_spheroid_sersicn) |= FLAG(obj2.prof_spheroid_sersicnerr);
439
  FLAG(obj2.prof_disk_mag) |= FLAG(obj2.prof_disk_magerr);
440
  FLAG(obj2.prof_disk_scale) |= FLAG(obj2.prof_disk_scaleerr);
441
  FLAG(obj2.prof_disk_aspect) |= FLAG(obj2.prof_disk_aspecterr);
442
  FLAG(obj2.prof_disk_inclination) |= FLAG(obj2.prof_disk_inclinationerr);
443
  FLAG(obj2.prof_disk_theta) |= FLAG(obj2.prof_disk_thetaerr);
444
  FLAG(obj2.prof_bar_mag) |= FLAG(obj2.prof_bar_magerr);
445
  FLAG(obj2.prof_bar_length) |= FLAG(obj2.prof_bar_lengtherr);
446
  FLAG(obj2.prof_bar_aspect) |= FLAG(obj2.prof_bar_aspecterr);
447
  FLAG(obj2.prof_bar_theta) |= FLAG(obj2.prof_bar_thetaerr);
448
  FLAG(obj2.prof_arms_mag) |= FLAG(obj2.prof_arms_magerr);
449 226 bertin
  FLAG(obj2.prof_e1errw) |= FLAG(obj2.prof_e2errw) | FLAG(obj2.prof_e12corrw);
450
  FLAG(obj2.prof_e1w) |= FLAG(obj2.prof_e2w) | FLAG(obj2.prof_e1errw);
451
  FLAG(obj2.prof_pol1errw) |= FLAG(obj2.prof_pol2errw)
452
                        | FLAG(obj2.prof_pol12corrw);
453
  FLAG(obj2.prof_pol1w) |= FLAG(obj2.prof_pol2w) | FLAG(obj2.prof_pol1errw);
454 206 bertin
  FLAG(obj2.prof_aw) |= FLAG(obj2.prof_bw);
455
  FLAG(obj2.prof_cxxw) |= FLAG(obj2.prof_cyyw) | FLAG(obj2.prof_cxyw);
456
  FLAG(obj2.prof_thetas) |= FLAG(obj2.prof_theta1950)
457
                        | FLAG(obj2.prof_theta2000);
458
  FLAG(obj2.prof_thetaw) |= FLAG(obj2.prof_thetas);
459
 
460
  FLAG(obj2.prof_mx2w) |= FLAG(obj2.prof_my2w)
461
                        | FLAG(obj2.prof_mxyw)
462
                        | FLAG(obj2.prof_thetaw) | FLAG(obj2.prof_aw)
463
                        | FLAG(obj2.prof_cxxw)
464 225 bertin
                        | FLAG(obj2.prof_e1w) | FLAG(obj2.prof_pol1w);
465 206 bertin
 
466
  FLAG(obj2.dtheta1950) |= FLAG(obj2.prof_theta1950)
467
                        | FLAG(obj2.prof_spheroid_theta1950)
468 173 bertin
                        | FLAG(obj2.prof_disk_theta1950)
469
//                      | FLAG(obj2.prof_arms_theta1950)
470
                        | FLAG(obj2.prof_bar_theta1950)
471
                        | FLAG(obj2.poserrtheta1950_psf)
472
                        | FLAG(obj2.win_theta1950)
473
                        | FLAG(obj2.winposerr_theta1950)
474
                        | FLAG(obj2.poserr_theta1950)
475
                        | FLAG(obj2.theta1950)
476
                        | FLAG(obj2.poserrtheta1950_prof);
477 206 bertin
  FLAG(obj2.dtheta2000) |= FLAG(obj2.prof_theta2000)
478
                        | FLAG(obj2.prof_spheroid_theta2000)
479 173 bertin
                        | FLAG(obj2.prof_disk_theta2000)
480
//                      | FLAG(obj2.prof_arms_theta2000)
481
                        | FLAG(obj2.prof_bar_theta2000)
482
                        | FLAG(obj2.poserrtheta2000_psf)
483
                        | FLAG(obj2.win_theta2000)
484
                        | FLAG(obj2.winposerr_theta2000)
485
                        | FLAG(obj2.poserr_theta2000)
486
                        | FLAG(obj2.theta2000)
487
                        | FLAG(obj2.poserrtheta2000_prof);
488
 
489
 
490
  FLAG(obj2.prof_spheroid_thetas) |= FLAG(obj2.prof_spheroid_theta2000)
491
                        | FLAG(obj2.prof_spheroid_theta1950);
492
  FLAG(obj2.prof_spheroid_thetaw) |= FLAG(obj2.prof_spheroid_thetas);
493
  FLAG(obj2.prof_disk_thetas) |= FLAG(obj2.prof_disk_theta2000)
494
                        | FLAG(obj2.prof_disk_theta1950);
495
  FLAG(obj2.prof_disk_thetaw) |= FLAG(obj2.prof_disk_thetas);
496
  FLAG(obj2.prof_bar_thetas) |= FLAG(obj2.prof_bar_theta2000)
497
                        | FLAG(obj2.prof_bar_theta1950);
498
  FLAG(obj2.prof_bar_thetaw) |= FLAG(obj2.prof_bar_thetas);
499
/*
500
  FLAG(obj2.prof_arms_thetaw) |= FLAG(obj2.prof_arms_thetas)
501
                        | FLAG(obj2.prof_arms_theta2000)
502
                        | FLAG(obj2.prof_arms_theta1950);
503
*/
504
  FLAG(obj2.prof_arms_scalew) |= FLAG(obj2.prof_arms_startw)
505
                        | FLAG(obj2.prof_arms_scaleerrw)
506
                        | FLAG(obj2.prof_arms_starterrw);
507
 
508
  FLAG(obj2.prof_bar_lengthw) |= FLAG(obj2.prof_bar_aspectw)
509
                        | FLAG(obj2.prof_bar_thetaw)
510
                        | FLAG(obj2.prof_bar_lengtherrw)
511
                        | FLAG(obj2.prof_bar_aspecterrw)
512
                        | FLAG(obj2.prof_bar_thetaerrw);
513
 
514
  FLAG(obj2.prof_disk_scalew) |= FLAG(obj2.prof_disk_aspectw)
515
                        | FLAG(obj2.prof_disk_thetaw)
516
                        | FLAG(obj2.prof_disk_scaleerrw)
517
                        | FLAG(obj2.prof_disk_aspecterrw)
518
                        | FLAG(obj2.prof_disk_thetaerrw)
519
                        | FLAG(obj2.prof_arms_scalew);
520 207 bertin
  FLAG(obj2.prof_disk_fluxmean) |= FLAG(obj2.prof_disk_mumean);
521 206 bertin
  FLAG(obj2.prof_disk_fluxeff) |= FLAG(obj2.prof_disk_mueff);
522
  FLAG(obj2.prof_disk_peak) |= FLAG(obj2.prof_disk_mumax)
523 207 bertin
                                | FLAG(obj2.prof_disk_fluxeff)
524
                                | FLAG(obj2.prof_disk_fluxmean);
525 173 bertin
 
526
  FLAG(obj2.prof_spheroid_reffw) |= FLAG(obj2.prof_spheroid_aspectw)
527
                        | FLAG(obj2.prof_spheroid_thetaw)
528
                        | FLAG(obj2.prof_spheroid_refferrw)
529
                        | FLAG(obj2.prof_spheroid_aspecterrw)
530
                        | FLAG(obj2.prof_spheroid_thetaerrw);
531
 
532 207 bertin
  FLAG(obj2.prof_spheroid_fluxmean) |= FLAG(obj2.prof_spheroid_mumean);
533 206 bertin
  FLAG(obj2.prof_spheroid_fluxeff) |= FLAG(obj2.prof_spheroid_mueff);
534
  FLAG(obj2.prof_spheroid_peak) |= FLAG(obj2.prof_spheroid_mumax)
535 207 bertin
                                | FLAG(obj2.prof_spheroid_fluxeff)
536
                                | FLAG(obj2.prof_spheroid_fluxmean);
537 206 bertin
 
538 173 bertin
  FLAG(obj2.prof_flagw) |= FLAG(obj2.prof_spheroid_reffw)
539
                        | FLAG(obj2.prof_disk_scalew)
540
                        | FLAG(obj2.prof_bar_lengthw)
541 206 bertin
                        | FLAG(obj2.prof_arms_scalew)
542
                        | FLAG(obj2.prof_mx2w);
543 225 bertin
 
544 226 bertin
  FLAG(obj2.prof_e1err) |= FLAG(obj2.prof_e2err) | FLAG(obj2.prof_e12corr)
545
                        | FLAG(obj2.prof_e1errw);
546 173 bertin
 
547 206 bertin
  FLAG(obj2.prof_e1) |= FLAG(obj2.prof_e2)
548 226 bertin
                        | FLAG(obj2.prof_e1err) | FLAG(obj2.prof_e1w);
549
  FLAG(obj2.prof_pol1err) |= FLAG(obj2.prof_pol2err)
550
                        | FLAG(obj2.prof_pol12corr) | FLAG(obj2.prof_pol1errw);
551 225 bertin
  FLAG(obj2.prof_pol1) |= FLAG(obj2.prof_pol2)
552 226 bertin
                        | FLAG(obj2.prof_pol1err) | FLAG(obj2.prof_pol1w);
553 206 bertin
  FLAG(obj2.prof_a) |= FLAG(obj2.prof_b) | FLAG(obj2.prof_theta)
554
                        | FLAG(obj2.prof_aw);
555
  FLAG(obj2.prof_cxx) |= FLAG(obj2.prof_cyy)
556
                        | FLAG(obj2.prof_cxy) | FLAG(obj2.prof_cxxw);
557 173 bertin
  FLAG(obj2.prof_mx2) |= FLAG(obj2.prof_my2) | FLAG(obj2.prof_mxy)
558 225 bertin
                        | FLAG(obj2.prof_e1) | FLAG(obj2.prof_pol1)
559 206 bertin
                        | FLAG(obj2.prof_a) | FLAG(obj2.prof_cxx)
560
                        | FLAG(obj2.prof_mx2w);
561 245 bertin
  FLAG(obj2.prof_conva) |= FLAG(obj2.prof_convb) | FLAG(obj2.prof_convtheta);
562
  FLAG(obj2.prof_convcxx) |= FLAG(obj2.prof_convcyy)
563
                        /*| FLAG(obj2.fluxcor_prof) */;
564
  FLAG(obj2.prof_convmx2) |= FLAG(obj2.prof_convcxx) | FLAG(obj2.prof_conva);
565 207 bertin
  FLAG(obj2.fluxmean_prof) |= FLAG(obj2.mumean_prof);
566 266 bertin
  FLAG(obj2.peak_prof) |= FLAG(obj2.mumax_prof);
567 207 bertin
  FLAG(obj2.fluxeff_prof) |= FLAG(obj2.mueff_prof)
568 266 bertin
                        | FLAG(obj2.fluxmean_prof) | FLAG(obj2.peak_prof);
569 206 bertin
 
570 173 bertin
  FLAG(obj2.prof_arms_flux) |= FLAG(obj2.prof_arms_fluxerr)
571
                        | FLAG(obj2.prof_arms_mag)
572
                        | FLAG(obj2.prof_arms_scalew)
573
                        | FLAG(obj2.prof_arms_scale)
574
                        | FLAG(obj2.prof_arms_posang)
575
                        | FLAG(obj2.prof_arms_pitch)
576
                        | FLAG(obj2.prof_arms_start)
577
                        | FLAG(obj2.prof_arms_quadfrac);
578
  FLAG(obj2.prof_bar_theta) |= FLAG(obj2.prof_bar_lengthw);
579
  FLAG(obj2.prof_bar_flux) |= FLAG(obj2.prof_bar_fluxerr)
580
                        | FLAG(obj2.prof_bar_mag)
581
                        | FLAG(obj2.prof_bar_lengthw)
582
                        | FLAG(obj2.prof_bar_length)
583
                        | FLAG(obj2.prof_bar_aspect)
584
                        | FLAG(obj2.prof_bar_posang)
585
                        | FLAG(obj2.prof_bar_theta)
586
                        | FLAG(obj2.prof_arms_flux);
587
  FLAG(obj2.prof_disk_flux) |= FLAG(obj2.prof_disk_fluxerr)
588
                        | FLAG(obj2.prof_disk_mag)
589
                        | FLAG(obj2.prof_disk_scalew)
590
                        | FLAG(obj2.prof_disk_scale)
591
                        | FLAG(obj2.prof_disk_aspect)
592
                        | FLAG(obj2.prof_disk_inclination)
593
                        | FLAG(obj2.prof_disk_theta)
594 206 bertin
                        | FLAG(obj2.prof_disk_peak)
595 173 bertin
                        | FLAG(obj2.prof_bar_flux);
596
  FLAG(obj2.prof_spheroid_flux) |= FLAG(obj2.prof_spheroid_fluxerr)
597
                        | FLAG(obj2.prof_spheroid_mag)
598
                        | FLAG(obj2.prof_spheroid_reffw)
599
                        | FLAG(obj2.prof_spheroid_reff)
600
                        | FLAG(obj2.prof_spheroid_aspect)
601
                        | FLAG(obj2.prof_spheroid_theta)
602 206 bertin
                        | FLAG(obj2.prof_spheroid_sersicn)
603
                        | FLAG(obj2.prof_spheroid_peak);
604 233 bertin
  FLAG(obj2.prof_dirac_flux) |= FLAG(obj2.prof_dirac_fluxerr)
605
                        | FLAG(obj2.prof_dirac_mag);
606
  FLAG(obj2.prof_offset_flux) |= FLAG(obj2.prof_offset_fluxerr);
607 173 bertin
  prefs.prof_flag |= FLAG(obj2.prof_chi2) | FLAG(obj2.prof_niter)
608
                        | FLAG(obj2.prof_vector) | FLAG(obj2.prof_errvector)
609 208 bertin
                        | FLAG(obj2.prof_errmatrix)
610 173 bertin
                        | FLAG(obj2.x_prof) | FLAG(obj2.y_prof)
611 211 bertin
                        | FLAG(obj2.prof_flag)
612
                        | FLAG(obj2.flux_prof)
613 173 bertin
                        | FLAG(obj2.prof_mx2)
614 266 bertin
                        | FLAG(obj2.fluxeff_prof)
615 173 bertin
                        | FLAG(obj2.prof_disk_flux)
616 233 bertin
                        | FLAG(obj2.prof_spheroid_flux)
617
                        | FLAG(obj2.prof_dirac_flux)
618
                        | FLAG(obj2.prof_offset_flux);
619 173 bertin
 
620
 
621
/* If only global parameters are requested, fit a Sersic model */
622
  if (prefs.prof_flag && !(FLAG(obj2.prof_spheroid_flux)
623 233 bertin
                        | FLAG(obj2.prof_disk_flux)
624
                        | FLAG(obj2.prof_dirac_flux)
625
                        | FLAG(obj2.prof_offset_flux)))
626 173 bertin
    {
627
    FLAG(obj2.prof_spheroid_flux) |= prefs.prof_flag;
628
    FLAG(obj2.prof_spheroid_sersicn) |= prefs.prof_flag;
629
    }
630
 
631 2 bertin
/*------------------------------ Astrometry ---------------------------------*/
632 281 bertin
  FLAG(obj2.posx) = FLAG(obj2.posy) = 1;        /* Always required! */
633 2 bertin
  FLAG(obj2.win_aw) |= FLAG(obj2.win_bw) | FLAG(obj2.win_polarw);
634
  FLAG(obj2.win_cxxw) |= FLAG(obj2.win_cyyw) | FLAG(obj2.win_cxyw);
635
  FLAG(obj2.win_thetas) |= FLAG(obj2.win_theta1950)
636
                        | FLAG(obj2.win_theta2000);
637
  FLAG(obj2.win_thetaw) |= FLAG(obj2.win_thetas);
638
 
639
  FLAG(obj2.win_mx2w) |= FLAG(obj2.win_my2w)
640
                        | FLAG(obj2.win_mxyw)
641
                        | FLAG(obj2.win_thetaw) | FLAG(obj2.win_aw)
642
                        | FLAG(obj2.win_cxxw);
643
 
644
  FLAG(obj2.win_a) |= FLAG(obj2.win_b) | FLAG(obj2.win_theta)
645 3 bertin
                        | FLAG(obj2.win_polar) | FLAG(obj2.win_aw);
646 2 bertin
  FLAG(obj2.win_cxx) |= FLAG(obj2.win_cyy)
647 3 bertin
                        | FLAG(obj2.win_cxy) | FLAG(obj2.win_cxxw);
648 2 bertin
  FLAG(obj2.win_mx2) |= FLAG(obj2.win_my2)
649
                        | FLAG(obj2.win_mxy)
650
                        | FLAG(obj2.win_a) | FLAG(obj2.win_cxx)
651
                        | FLAG(obj2.win_mx2w);
652
 
653
  FLAG(obj2.winposerr_aw) |= FLAG(obj2.winposerr_bw);
654
  FLAG(obj2.winposerr_cxxw) |= FLAG(obj2.winposerr_cyyw)
655
                        | FLAG(obj2.winposerr_cxyw);
656
  FLAG(obj2.winposerr_thetas) |= FLAG(obj2.winposerr_theta1950)
657
                        | FLAG(obj2.winposerr_theta2000);
658
  FLAG(obj2.winposerr_thetaw) |= FLAG(obj2.winposerr_thetas);
659
 
660
  FLAG(obj2.winposerr_mx2w) |= FLAG(obj2.winposerr_my2w)
661
                        | FLAG(obj2.winposerr_mxyw)
662
                        | FLAG(obj2.winposerr_thetaw) | FLAG(obj2.winposerr_aw)
663
                        | FLAG(obj2.winposerr_cxxw);
664
 
665
  FLAG(obj2.winposerr_a) |= FLAG(obj2.winposerr_b) | FLAG(obj2.winposerr_theta);
666
  FLAG(obj2.winposerr_cxx) |= FLAG(obj2.winposerr_cyy)
667
                        | FLAG(obj2.winposerr_cxy);
668
  FLAG(obj2.winposerr_mx2) |= FLAG(obj2.winposerr_my2)
669
                        | FLAG(obj2.winposerr_mxy)
670
                        | FLAG(obj2.winposerr_a) | FLAG(obj2.winposerr_cxx)
671 245 bertin
                        | FLAG(obj2.winposerr_mx2w);
672 2 bertin
 
673
  FLAG(obj2.winpos_alpha1950) |= FLAG(obj2.winpos_delta1950)
674
                        | FLAG(obj2.win_theta1950)
675
                        | FLAG(obj2.winposerr_theta1950);
676
  FLAG(obj2.winpos_alpha2000) |= FLAG(obj2.winpos_delta2000)
677
                        | FLAG(obj2.winpos_alpha1950)
678
                        | FLAG(obj2.win_theta2000)
679
                        | FLAG(obj2.winposerr_theta2000);
680
  FLAG(obj2.winpos_alphas) |= FLAG(obj2.winpos_deltas)
681
                        | FLAG(obj2.winpos_alpha2000);
682 199 bertin
  FLAG(obj2.winpos_xf) |= FLAG(obj2.winpos_yf);
683 2 bertin
  FLAG(obj2.winpos_xw) |= FLAG(obj2.winpos_yw)
684
                        | FLAG(obj2.winpos_alphas);
685
 
686
  FLAG(obj2.poserr_aw) |= FLAG(obj2.poserr_bw);
687
  FLAG(obj2.poserr_cxxw) |= FLAG(obj2.poserr_cyyw) | FLAG(obj2.poserr_cxyw);
688
  FLAG(obj2.poserr_thetas) |= FLAG(obj2.poserr_theta1950)
689
                                | FLAG(obj2.poserr_theta2000);
690
  FLAG(obj2.poserr_thetaw) |= FLAG(obj2.poserr_thetas);
691
 
692
  FLAG(obj2.poserr_mx2w) |= FLAG(obj2.poserr_my2w) | FLAG(obj2.poserr_mxyw)
693
                        | FLAG(obj2.poserr_thetaw) | FLAG(obj2.poserr_aw)
694
                        | FLAG(obj2.poserr_cxxw);
695
 
696 3 bertin
  FLAG(obj2.poserr_a) |= FLAG(obj2.poserr_b) | FLAG(obj2.poserr_theta)
697
                        | FLAG(obj2.winposerr_a);
698 2 bertin
  FLAG(obj2.poserr_cxx) |= FLAG(obj2.poserr_cyy) | FLAG(obj2.poserr_cxy);
699 272 bertin
  FLAG(obj2.poserr_mx2) |= FLAG(obj2.poserr_my2) | FLAG(obj2.poserr_mxy)
700 2 bertin
                        | FLAG(obj2.poserr_a) | FLAG(obj2.poserr_cxx)
701 3 bertin
                        | FLAG(obj2.poserr_mx2w) | FLAG(obj2.winposerr_mx2);
702 2 bertin
 
703
  FLAG(obj2.peakalpha1950) |= FLAG(obj2.peakdelta1950);
704
  FLAG(obj2.alpha1950) |= FLAG(obj2.delta1950) |  FLAG(obj2.theta1950)
705 173 bertin
                        | FLAG(obj2.poserr_theta1950) | FLAG(obj2.dtheta1950);
706
;
707 2 bertin
  FLAG(obj2.peakalpha2000) |= FLAG(obj2.peakdelta2000)
708
                        | FLAG(obj2.peakalpha1950);
709
  FLAG(obj2.alpha2000) |= FLAG(obj2.delta2000) | FLAG(obj2.alpha1950)
710 173 bertin
                        | FLAG(obj2.dtheta2000);
711 2 bertin
  FLAG(obj2.peakalphas) |= FLAG(obj2.peakdeltas) | FLAG(obj2.peakalpha2000);
712
  FLAG(obj2.alphas) |= FLAG(obj2.deltas) | FLAG(obj2.alpha2000);
713
  FLAG(obj2.thetas) |= FLAG(obj2.theta1950) | FLAG(obj2.theta2000);
714
  FLAG(obj2.thetaw) |= FLAG(obj2.thetas);
715
  FLAG(obj2.aw) |= FLAG(obj2.bw) | FLAG(obj2.polarw);
716
  FLAG(obj2.cxxw) |= FLAG(obj2.cyyw) | FLAG(obj2.cxyw);
717
 
718
  FLAG(obj2.mx2w) |= FLAG(obj2.my2w) | FLAG(obj2.mxyw)
719 206 bertin
                        | FLAG(obj2.thetaw) | FLAG(obj2.aw) | FLAG(obj2.cxxw);
720 2 bertin
 
721 199 bertin
  FLAG(obj2.peakxw) |= FLAG(obj2.peakyf);
722 2 bertin
  FLAG(obj2.peakxw) |= FLAG(obj2.peakyw) | FLAG(obj2.peakalphas);
723 272 bertin
  FLAG(obj2.peakx) |= FLAG(obj2.peaky) | FLAG(obj2.peakxw) | FLAG(obj2.peakxf);
724 2 bertin
 
725 278 bertin
  FLAG(obj2.posxf) |= FLAG(obj2.posyf);
726 199 bertin
 
727 278 bertin
  FLAG(obj2.posxw) |= FLAG(obj2.posyw) | FLAG(obj2.mx2w) | FLAG(obj2.alphas)
728 2 bertin
                | FLAG(obj2.poserr_mx2w);
729
  FLAG(obj2.mamaposx) |= FLAG(obj2.mamaposy);
730 245 bertin
  FLAG(obj2.fluxerr_win) |= FLAG(obj2.snr_win);
731 2 bertin
  FLAG(obj2.flux_win) |= FLAG(obj2.mag_win)|FLAG(obj2.magerr_win)
732 245 bertin
                        | FLAG(obj2.flux_win) | FLAG(obj2.fluxerr_win);
733 2 bertin
  FLAG(obj2.winpos_x) |= FLAG(obj2.winpos_y)
734
                        | FLAG(obj2.winposerr_mx2) | FLAG(obj2.win_mx2)
735 199 bertin
                        | FLAG(obj2.winpos_xw) | FLAG(obj2.winpos_xf)
736 282 bertin
                        | FLAG(obj2.win_flags)
737
                        | FLAG(obj2.flux_win) | FLAG(obj2.winpos_niter);
738
  prefs.win_flag = FLAG(obj2.winpos_x);
739 2 bertin
 
740 206 bertin
  FLAG(obj2.area_flagw) |= FLAG(obj2.npixw) | FLAG(obj2.fdnpixw)
741
                        | FLAG(obj2.fwhmw)
742
                        | FLAG(obj2.maxmu) | FLAG(obj2.threshmu)
743
                        | FLAG(obj2.prof_spheroid_mumax)
744 207 bertin
                        | FLAG(obj2.prof_disk_mumax)
745
                        | FLAG(obj2.mumax_prof);
746 206 bertin
 
747 278 bertin
  prefs.world_flag = FLAG(obj2.posxw) || FLAG(obj2.mamaposx)
748 274 bertin
                || FLAG(obj2.peakxw) || FLAG(obj2.winpos_xw)
749
                || FLAG(obj2.mx2w) || FLAG(obj2.win_mx2w)
750
                || FLAG(obj2.xw_prof) || FLAG(obj2.poserrmx2w_prof)
751
                || FLAG(obj2.poserr_mx2w) || FLAG(obj2.winposerr_mx2w)
752
                || FLAG(obj2.area_flagw) || FLAG(obj2.prof_flagw)
753
                || FLAG(obj2.fwhmw_psf);
754
 
755 2 bertin
/*------------------------------ Photometry ---------------------------------*/
756
  FLAG(obj2.fluxerr_best) |= FLAG(obj2.magerr_best);
757
 
758
  FLAG(obj2.flux_best) |= FLAG(obj2.mag_best) | FLAG(obj2.fluxerr_best);
759
 
760 173 bertin
  FLAG(obj2.hl_radius) |= FLAG(obj2.winpos_x) | prefs.prof_flag;
761 2 bertin
 
762 285 bertin
  FLAG(obj2.fluxerr_auto) |= prefs.prof_flag;
763
 
764 282 bertin
  FLAG(obj2.flux_auto) = FLAG(obj2.flux_best)
765 2 bertin
                        | FLAG(obj2.flux_radius)
766 235 bertin
                        | FLAG(obj2.hl_radius)
767
                        | FLAG(obj2.fluxcor_prof);
768 282 bertin
  prefs.auto_flag = FLAG(obj2.flux_auto)
769
                        | FLAG(obj2.fluxerr_auto)
770
                        | FLAG(obj2.mag_auto)
771
                        | FLAG(obj2.magerr_auto)
772
                        | FLAG(obj2.auto_flags)
773
                        | FLAG(obj2.auto_kronfactor);
774 2 bertin
  FLAG(obj2.flux_petro) |= FLAG(obj2.mag_petro) | FLAG(obj2.magerr_petro)
775
                        | FLAG(obj2.fluxerr_petro)
776
                        | FLAG(obj2.petrofactor);
777
 
778
  FLAG(obj2.fluxerr_isocor) |= FLAG(obj2.magerr_isocor)
779
                                | FLAG(obj2.fluxerr_best);
780
 
781
  FLAG(obj2.flux_isocor) |= FLAG(obj2.mag_isocor) | FLAG(obj2.fluxerr_isocor)
782
                         | FLAG(obj2.flux_best);
783
 
784
  FLAG(obj2.flux_aper) |= FLAG(obj2.mag_aper)|FLAG(obj2.magerr_aper)
785
                            | FLAG(obj2.fluxerr_aper);
786
 
787 274 bertin
/*------------------------------ Growth-curves ----------------------------- */
788
  if (FLAG(obj2.flux_growth)
789
        || FLAG(obj2.mag_growth)
790
        || FLAG(obj2.flux_radius)
791
        || FLAG(obj2.hl_radius)
792 275 bertin
        || FLAG(obj2.flux_growth_step)
793
        || FLAG(obj2.mag_growth_step))
794 274 bertin
    prefs.growth_flag = 1;
795
 
796 2 bertin
/*---------------------------- External flags -------------------------------*/
797 282 bertin
  prefs.imaflags_flag = FLAG(obj2.imaflags)
798
                        | FLAG(obj2.imanflags);
799 2 bertin
 
800
/*------------------------------ PSF-fitting --------------------------------*/
801 247 bertin
  FLAG(obj2.fwhm_psf) |= FLAG(obj2.fwhmw_psf);
802 2 bertin
  FLAG(obj2.poserraw_psf) |= FLAG(obj2.poserrbw_psf);
803
  FLAG(obj2.poserrcxxw_psf) |= FLAG(obj2.poserrcyyw_psf)
804
                        | FLAG(obj2.poserrcxyw_psf);
805
  FLAG(obj2.poserrthetas_psf) |= FLAG(obj2.poserrtheta1950_psf)
806
                                | FLAG(obj2.poserrtheta2000_psf);
807
  FLAG(obj2.poserrthetaw_psf) |= FLAG(obj2.poserrthetas_psf);
808
 
809
  FLAG(obj2.poserrmx2w_psf) |= FLAG(obj2.poserrmy2w_psf)
810
                        | FLAG(obj2.poserrmxyw_psf)
811
                        | FLAG(obj2.poserrthetaw_psf) | FLAG(obj2.poserraw_psf)
812
                        | FLAG(obj2.poserrcxxw_psf);
813
 
814
  FLAG(obj2.poserra_psf) |= FLAG(obj2.poserrb_psf)
815
                        | FLAG(obj2.poserrtheta_psf);
816
  FLAG(obj2.poserrcxx_psf) |= FLAG(obj2.poserrcyy_psf)
817
                        | FLAG(obj2.poserrcxy_psf);
818
  FLAG(obj2.poserrmx2_psf) |= FLAG(obj2.poserrmy2_psf)
819
                        | FLAG(obj2.poserrmxy_psf)
820
                        | FLAG(obj2.poserra_psf) | FLAG(obj2.poserrcxx_psf)
821
                        | FLAG(obj2.poserrmx2w_psf);
822
 
823
  FLAG(obj2.alpha1950_psf) |= FLAG(obj2.delta1950_psf)
824
                        | FLAG(obj2.poserrtheta1950_psf);
825
  FLAG(obj2.alpha2000_psf) |= FLAG(obj2.delta2000_psf)
826
                        | FLAG(obj2.alpha1950_psf)
827
                        | FLAG(obj2.poserrtheta2000_psf);
828
  FLAG(obj2.alphas_psf) |= FLAG(obj2.deltas_psf) | FLAG(obj2.alpha2000_psf);
829
 
830
  FLAG(obj2.xw_psf) |= FLAG(obj2.yw_psf) | FLAG(obj2.poserrmx2w_psf)
831
                        | FLAG(obj2.alphas_psf);
832
 
833
  FLAG(obj2.fluxerr_psf) |= FLAG(obj2.poserrmx2_psf) | FLAG(obj2.magerr_psf);
834
 
835
  FLAG(obj2.flux_psf) |= FLAG(obj2.mag_psf) | FLAG(obj2.x_psf)
836
                        | FLAG(obj2.y_psf) | FLAG(obj2.xw_psf)
837
                        | FLAG(obj2.fluxerr_psf)
838
                        | FLAG(obj2.niter_psf)
839 267 bertin
                        | FLAG(obj2.chi2_psf);
840 2 bertin
 
841 274 bertin
  if (FLAG(obj2.flux_psf))
842
    prefs.psffit_flag = 1;
843
 
844
/*--------------------------------- ASSOC ----------------------------------*/
845
  prefs.assoc_flag = FLAG(obj2.assoc) || FLAG(obj2.assoc_number);
846
 
847
/*----------------------------- SOM-fitting --------------------------------*/
848
  prefs.somfit_flag = FLAG(obj2.flux_somfit);
849
 
850 2 bertin
/*-------------------------------- Others -----------------------------------*/
851 272 bertin
  FLAG(obj2.fwhm) |= FLAG(obj2.fwhmw);
852 2 bertin
 
853 272 bertin
  FLAG(obj2.iso[0]) |= FLAG(obj2.sprob);
854 2 bertin
  for (i=0; i<NISO; i++)
855 272 bertin
    FLAG(obj2.iso[0]) |= FLAG(obj2.iso[i]);
856 2 bertin
 
857 272 bertin
  FLAG(obj2.wflag) |= FLAG(obj2.nzwpix) | FLAG(obj2.nzdwpix);
858 210 bertin
 
859 2 bertin
  return;
860
  }
861
 
862
 
863 252 bertin
/****** catout_dumpparams ****************************************************
864 282 bertin
PROTO   void catout_dumpparams(void)
865 252 bertin
PURPOSE Dump the complete list of catalog parameters to standard output.
866
INPUT   -.
867
OUTPUT  -.
868 272 bertin
NOTES   Requires access to the obj2key static pointer.
869 252 bertin
AUTHOR  E. Bertin (IAP)
870
VERSION 18/07/2011
871
 ***/
872
void    catout_dumpparams(void)
873 173 bertin
  {
874
   int          i;
875
 
876 272 bertin
  for (i=0; *obj2key[i].name ; i++)
877
    if (*obj2key[i].unit)
878 209 bertin
      printf("#%-24.24s %-57.57s [%s]\n",
879 272 bertin
                obj2key[i].name, obj2key[i].comment, obj2key[i].unit);
880 173 bertin
    else
881 209 bertin
      printf("#%-24.24s %-57.57s\n",
882 272 bertin
                obj2key[i].name, obj2key[i].comment);
883 173 bertin
 
884
  return;
885
  }
886
 
887
 
888 252 bertin
/****** catout_init *********************************************************
889 282 bertin
PROTO   void catout_init(void)
890 252 bertin
PURPOSE Initialize the catalog output.
891
INPUT   -.
892
OUTPUT  -.
893 272 bertin
NOTES   Requires access to global prefs and the obj2key static pointer.
894 252 bertin
AUTHOR  E. Bertin (IAP)
895 282 bertin
VERSION 24/02/2012
896 252 bertin
 ***/
897
void    catout_init(void)
898 2 bertin
  {
899
   keystruct    *key;
900 17 bertin
   int          i, n;
901 2 bertin
 
902
  if (prefs.cat_type == CAT_NONE)
903
    return;
904
 
905 17 bertin
  update_tab(objtab);
906 11 bertin
  if (prefs.cat_type == ASCII_HEAD || prefs.cat_type == ASCII ||
907
        prefs.cat_type == ASCII_SKYCAT || prefs.cat_type == ASCII_VO)
908 2 bertin
    {
909
    if (prefs.pipe_flag)
910
      ascfile = stdout;
911
    else
912
      if (!(ascfile = fopen(prefs.cat_name, "w+")))
913
        error(EXIT_FAILURE,"*Error*: cannot open ", prefs.cat_name);
914 206 bertin
//  setlinebuf(ascfile);
915 2 bertin
    if (prefs.cat_type == ASCII_HEAD && (key = objtab->key))
916
      for (i=0,n=1; i++<objtab->nkey; key=key->nextkey)
917
        {
918
        if (*key->unit)
919 173 bertin
          fprintf(ascfile, "# %3d %-22.22s %-58.58s [%s]\n",
920 2 bertin
                n, key->name,key->comment, key->unit);
921
        else
922 173 bertin
          fprintf(ascfile, "# %3d %-22.22s %-58.58s\n",
923 2 bertin
                n, key->name,key->comment);
924
        n += key->nbytes/t_size[key->ttype];
925
        }
926
    else if (prefs.cat_type == ASCII_SKYCAT && (key = objtab->key))
927
      {
928
      if (objtab->nkey<3)
929
        error(EXIT_FAILURE,"The SkyCat format requires at least 4 parameters:",
930
              " Id Ra Dec Mag");
931
/*--- We add a tab between rows, as required by Skycat */
932
      fprintf(ascfile, skycathead, 8.0);
933
      for (i=1,key=key->nextkey; i++<objtab->nkey; key=key->nextkey)
934
        {
935
        if (i>4)
936
          fprintf(ascfile, "\t%s", key->name);
937
        sprintf(gstr, "\t%s", key->printf);
938
        strcpy(key->printf, gstr);
939
        }
940
      fprintf(ascfile, "\n------------------\n");
941
      }
942 17 bertin
    else if (prefs.cat_type == ASCII_VO && objtab->key)
943
      {
944 282 bertin
      xml_write_header(ascfile);
945 267 bertin
      catout_writevofields(ascfile);
946 17 bertin
      fprintf(ascfile, "   <DATA><TABLEDATA>\n");
947
      }
948 2 bertin
    }
949
  else
950
    {
951
    fitscat = new_cat(1);
952
    init_cat(fitscat);
953
    strcpy(fitscat->filename, prefs.cat_name);
954
    if (open_cat(fitscat, WRITE_ONLY) != RETURN_OK)
955
      error(EXIT_FAILURE,"*Error*: cannot open for writing ",prefs.cat_name);
956
    switch(prefs.cat_type)
957
      {
958
      case FITS_LDAC:
959
      case FITS_TPX:
960
/*------ Save a "pure" primary HDU */
961
        save_tab(fitscat, fitscat->tab);
962
        break;
963
 
964
      case FITS_10:
965
/*------ Add to the primary HDU extraction parameters */
966
        key = headkey1;
967
        while (*key->name)
968
          addkeyto_head(fitscat->tab, key++);
969
        save_tab(fitscat, fitscat->tab);
970
        break;
971
      default:
972
        error (EXIT_FAILURE, "*Internal Error*: Unknown FITS type in ",
973 252 bertin
                "catout_init()");
974 2 bertin
      }
975
    }
976
 
977 16 bertin
  catopen_flag = 1;
978
 
979 2 bertin
  return;
980
  }
981
 
982
 
983 252 bertin
/****** catout_writevofields *************************************************
984 282 bertin
PROTO   int catout_writevofields(FILE *file)
985 17 bertin
PURPOSE Write the list of columns to an XML-VOTable file or stream
986
INPUT   Pointer to the output file (or stream).
987
OUTPUT  -.
988 252 bertin
NOTES   Requires access to global prefs and the objtab static pointer.
989 17 bertin
AUTHOR  E. Bertin (IAP)
990 252 bertin
VERSION 18/07/2011
991 17 bertin
 ***/
992 252 bertin
void    catout_writevofields(FILE *file)
993 17 bertin
  {
994
   keystruct    *key;
995
   char         datatype[40], arraysize[40], str[40];
996
   int          i, d;
997
 
998
  if (!objtab || !objtab->key)
999
    return;
1000
  key=objtab->key;
1001
  for (i=0; i++<objtab->nkey; key=key->nextkey)
1002
    {
1003
/*--- indicate datatype, arraysize, width and precision attributes */
1004
/*--- Handle multidimensional arrays */
1005
    arraysize[0] = '\0';
1006
    if (key->naxis>1)
1007
      {
1008
      for (d=0; d<key->naxis; d++)
1009
        {
1010
        sprintf(str, "%s%d", d?"x":" arraysize=\"", key->naxisn[d]);
1011
        strcat(arraysize, str);
1012
        }
1013
      strcat(arraysize, "\"");
1014
      }
1015
    switch(key->ttype)
1016
      {
1017
      case T_BYTE:      strcpy(datatype, "unsignedByte"); break;
1018
      case T_SHORT:     strcpy(datatype, "short"); break;
1019
      case T_LONG:      strcpy(datatype, "int"); break;
1020
      case T_FLOAT:     strcpy(datatype, "float"); break;
1021
      case T_DOUBLE:    strcpy(datatype, "double"); break;
1022
      default:          error(EXIT_FAILURE,
1023
                        "*Internal Error*: Unknown datatype in ",
1024
                        "initcat()");
1025
      }
1026
    fprintf(file,
1027
        "  <FIELD name=\"%s\" ucd=\"%s\" datatype=\"%s\" unit=\"%s\"%s>\n",
1028
        key->name, key->voucd, datatype,key->vounit, arraysize);
1029
    fprintf(file, "   <DESCRIPTION>%s</DESCRIPTION>\n", key->comment);
1030
    fprintf(file, "  </FIELD>\n");
1031
    }
1032
 
1033
  return;
1034
  }
1035
 
1036
 
1037 252 bertin
/****** catout_initext ********************************************************
1038 282 bertin
PROTO   void catout_initext(fieldstruct *field)
1039 252 bertin
PURPOSE Initialize the catalog header for the current extension.
1040 276 bertin
INPUT   Pointer to image field.
1041 252 bertin
OUTPUT  -.
1042
NOTES   Requires access to global prefs and the objtab static pointer.
1043
AUTHOR  E. Bertin (IAP)
1044 276 bertin
VERSION 08/12/2011
1045 252 bertin
 ***/
1046 275 bertin
void    catout_initext(fieldstruct *field)
1047 2 bertin
  {
1048
   tabstruct    *tab, *asctab;
1049
   keystruct    *key;
1050
 
1051
  if (prefs.cat_type == CAT_NONE)
1052
    return;
1053
 
1054 11 bertin
  if (prefs.cat_type != ASCII_HEAD && prefs.cat_type != ASCII &&
1055
        prefs.cat_type != ASCII_SKYCAT && prefs.cat_type != ASCII_VO)
1056 2 bertin
    {
1057
    update_tab(objtab);
1058
    switch(prefs.cat_type)
1059
      {
1060
      case FITS_LDAC:
1061
/*------ We create a dummy table (only used through its header) */
1062
        QCALLOC(asctab, tabstruct, 1);
1063 173 bertin
        asctab->headnblock = field->tab->headnblock;
1064
        QMEMCPY(field->tab->headbuf, asctab->headbuf, char,
1065
                asctab->headnblock*FBSIZE);
1066 2 bertin
        key = headkey;
1067
        while (*key->name)
1068
          addkeyto_head(asctab, key++);
1069
        tab = new_tab("LDAC_IMHEAD");
1070
        add_tab(tab, fitscat, 0);
1071
        key = new_key("Field Header Card");
1072
        key->ptr = asctab->headbuf;
1073
        asctab->headbuf = NULL;
1074
        free_tab(asctab);
1075
        key->htype = H_STRING;
1076
        key->ttype = T_STRING;
1077
        key->nobj = 1;
1078
        key->nbytes = 80*(fitsfind(key->ptr, "END     ")+1);
1079
        key->naxis = 2;
1080 267 bertin
        QMALLOC(key->naxisn, int, key->naxis);
1081 2 bertin
        key->naxisn[0] = 80;
1082
        key->naxisn[1] = key->nbytes/80;
1083
        add_key(key, tab, 0);
1084
        save_tab(fitscat, tab);
1085
        strcpy(objtab->extname, "LDAC_OBJECTS");
1086
        break;
1087
 
1088
      case FITS_TPX:
1089
/*------ We create a dummy table (only used through its header) */
1090
        QCALLOC(asctab, tabstruct, 1);
1091 173 bertin
        asctab->headnblock = field->tab->headnblock;
1092
        QMEMCPY(field->tab->headbuf, asctab->headbuf, char,
1093
                asctab->headnblock*FBSIZE);
1094 2 bertin
        key = headkey;
1095
        while (*key->name)
1096
          addkeyto_head(asctab, key++);
1097
        tab = new_tab("TPX_IMHEAD");
1098
        add_tab(tab, fitscat, 0);
1099
        key = new_key("Field Header Card");
1100
        key->ptr = asctab->headbuf;
1101
        asctab->headbuf = NULL;
1102
        free_tab(asctab);
1103
        key->htype = H_STRING;
1104
        key->ttype = T_STRING;
1105
        key->nobj = fitsfind(key->ptr, "END     ")+1;
1106
        key->nbytes = 80;
1107
        key->naxis = 1;
1108 267 bertin
        QMALLOC(key->naxisn, int, key->naxis);
1109 2 bertin
        key->naxisn[0] = 80;
1110
        add_key(key, tab, 0);
1111
        save_tab(fitscat, tab);
1112
        strcpy(objtab->extname, "TPX_OBJECTS");
1113
        break;
1114
 
1115
      case FITS_10:
1116
/*------ Add to the primary HDU extraction parameters */
1117
/*
1118
        key = headkey1;
1119
        while (*key->name)
1120
          addkeyto_head(fitscat->tab, key++);
1121
        save_tab(fitscat, fitscat->tab);
1122
*/
1123
        break;
1124
 
1125
      default:
1126
        error (EXIT_FAILURE, "*Internal Error*: Unknown FITS type in ",
1127 252 bertin
                "catout_initext()");
1128 2 bertin
      }
1129
 
1130
    objtab->cat = fitscat;
1131
    init_writeobj(fitscat, objtab, &buf);
1132
    }
1133
 
1134
  return;
1135
  }
1136
 
1137
 
1138 252 bertin
/****** catout_writeobj ******************************************************
1139 282 bertin
PROTO   void catout_writeobj(obj2struct *obj2)
1140 252 bertin
PURPOSE Write one object in the output catalog.
1141
INPUT   Pointer to the current obj2 structure.
1142
OUTPUT  -.
1143
NOTES   Requires access to global prefs and the objtab static pointer.
1144
AUTHOR  E. Bertin (IAP)
1145 267 bertin
VERSION 03/10/2011
1146 252 bertin
 ***/
1147 260 bertin
void    catout_writeobj(obj2struct *obj2)
1148 2 bertin
  {
1149 252 bertin
   keystruct    *keystore;
1150
 
1151
/* We temporarily replace the objtab key sequence with that from the list */
1152
  keystore = objtab->key;
1153 260 bertin
  objtab->key = obj2->keys;
1154 268 bertin
 
1155 2 bertin
  switch(prefs.cat_type)
1156
    {
1157
    case FITS_10:
1158
    case FITS_LDAC:
1159
    case FITS_TPX:
1160
      write_obj(objtab, buf);
1161
      break;
1162
 
1163
    case ASCII:
1164
    case ASCII_HEAD:
1165
    case ASCII_SKYCAT:
1166
      print_obj(ascfile, objtab);
1167
      break;
1168 11 bertin
    case ASCII_VO:
1169
      voprint_obj(ascfile, objtab);
1170
      break;
1171 2 bertin
 
1172
    case CAT_NONE:
1173
      break;
1174
 
1175
    default:
1176
      error (EXIT_FAILURE, "*Internal Error*: Unknown catalog type", "");
1177
    }
1178
 
1179 252 bertin
/* Put the "legacy" key structure back in place */
1180
  objtab->key = keystore;
1181
 
1182 2 bertin
  return;
1183
  }
1184
 
1185
 
1186 252 bertin
/****** catout_endext ********************************************************
1187 282 bertin
PROTO   void catout_endext(void)
1188 252 bertin
PURPOSE End catalog output for the current extension.
1189
INPUT   -.
1190
OUTPUT  -.
1191
NOTES   Requires access to global prefs and the objtab static pointer.
1192
AUTHOR  E. Bertin (IAP)
1193
VERSION 18/07/2011
1194
 ***/
1195
void    catout_endext(void)
1196 2 bertin
  {
1197
   keystruct    *key;
1198 252 bertin
   tabstruct    *tab;
1199
   OFF_T        pos;
1200
   char         *head;
1201
 
1202
  switch(prefs.cat_type)
1203
    {
1204
    case ASCII:
1205
    case ASCII_HEAD:
1206
    case ASCII_SKYCAT:
1207
    case ASCII_VO:
1208
      break;
1209
 
1210
    case FITS_LDAC:
1211
    case FITS_TPX:
1212
      end_writeobj(fitscat, objtab, buf);
1213
      key = NULL;
1214
      if (!(tab=fitscat->tab->prevtab)
1215
        || !(key=name_to_key(tab, "Field Header Card")))
1216
        error(EXIT_FAILURE,"*Error*: cannot update table ", "ASCFIELD");
1217
      head = key->ptr;
1218
      fitswrite(head, "SEXNDET ", &thecat.ndetect,H_INT,T_LONG);
1219
      fitswrite(head, "SEXNFIN ", &thecat.ntotal, H_INT,T_LONG);
1220
      fitswrite(head, "SEXDATE ", thecat.ext_date, H_STRING, T_STRING);
1221
      fitswrite(head, "SEXTIME ", thecat.ext_time, H_STRING, T_STRING);
1222
      fitswrite(head, "SEXELAPS", &thecat.ext_elapsed, H_FLOAT, T_DOUBLE);
1223
      QFTELL(fitscat->file, pos, fitscat->filename);
1224
      QFSEEK(fitscat->file, tab->headpos, SEEK_SET, fitscat->filename);
1225
      save_tab(fitscat, tab);
1226
      QFSEEK(fitscat->file, pos, SEEK_SET, fitscat->filename);
1227
      break;
1228
 
1229
    case FITS_10:
1230
      end_writeobj(fitscat, objtab, buf);
1231
      fitswrite(fitscat->tab->headbuf,"SEXNDET ",&thecat.ndetect,H_INT,T_LONG);
1232
      fitswrite(fitscat->tab->headbuf,"SEXNFIN ",&thecat.ntotal, H_INT,T_LONG);
1233
      QFTELL(fitscat->file, pos, fitscat->filename);
1234
      QFSEEK(fitscat->file, fitscat->tab->headpos, SEEK_SET,fitscat->filename);
1235
      save_tab(fitscat, fitscat->tab);
1236
      QFSEEK(fitscat->file, pos, SEEK_SET, fitscat->filename);
1237
      break;
1238
 
1239
    case CAT_NONE:
1240
      break;
1241
 
1242
    default:
1243
      break;
1244
    }
1245
 
1246
  return;
1247
  }
1248
 
1249
 
1250
/****** catout_end **********************************************************
1251 282 bertin
PROTO   void catout_end(char *error)
1252 252 bertin
PURPOSE End catalog output.
1253
INPUT   Error message character string (or NULL if no error).
1254
OUTPUT  -.
1255
NOTES   Requires access to global prefs and the objtab static pointer.
1256
AUTHOR  E. Bertin (IAP)
1257 282 bertin
VERSION 24/02/2012
1258 252 bertin
 ***/
1259
void    catout_end(char *error)
1260
  {
1261 253 bertin
   obj2liststruct       *obj2list;
1262
   int                  o;
1263 2 bertin
 
1264 16 bertin
  if (!catopen_flag)
1265
    {
1266
    if (prefs.cat_type == ASCII_VO)
1267 282 bertin
      xml_write_error(prefs.cat_name, error);
1268 17 bertin
    return;
1269 16 bertin
    }
1270 2 bertin
  switch(prefs.cat_type)
1271
    {
1272
    case ASCII:
1273
    case ASCII_HEAD:
1274
      if (!prefs.pipe_flag)
1275
        fclose(ascfile);
1276
      break;
1277
 
1278
    case ASCII_SKYCAT:
1279 11 bertin
      fprintf(ascfile, skycattail);
1280 2 bertin
      if (!prefs.pipe_flag)
1281
        fclose(ascfile);
1282
      break;
1283
 
1284 11 bertin
    case ASCII_VO:
1285 17 bertin
      fprintf(ascfile, "    </TABLEDATA></DATA>\n");
1286 11 bertin
      fprintf(ascfile, "  </TABLE>\n");
1287 15 bertin
/*---- Add configuration file meta-data */
1288 282 bertin
      xml_write_meta(ascfile, error);
1289 11 bertin
      fprintf(ascfile, "</RESOURCE>\n");
1290
      fprintf(ascfile, "</VOTABLE>\n");
1291
 
1292
      if (!prefs.pipe_flag)
1293
        fclose(ascfile);
1294
      break;
1295
 
1296 2 bertin
    case FITS_LDAC:
1297
    case FITS_TPX:
1298
    case FITS_10:
1299
      free_cat(&fitscat,1);
1300
      break;
1301
 
1302
    case CAT_NONE:
1303
      break;
1304
 
1305
    default:
1306
      break;
1307
    }
1308
 
1309 253 bertin
/* Free allocated memory for arrays and structures */
1310
  obj2list = thecat.obj2list;
1311 252 bertin
  catout_freeparams(obj2list);
1312 253 bertin
  if (obj2list->nkeys)
1313
    for (o=0; o<obj2list->nobj2; o++)
1314 267 bertin
      free(obj2list->obj2[o].keys);
1315 253 bertin
  free(obj2list->obj2);
1316
  free(obj2list);
1317 2 bertin
  objtab->key = NULL;
1318
  objtab->nkey = 0;
1319
  free_tab(objtab);
1320 17 bertin
  objtab = NULL;
1321 2 bertin
 
1322
  return;
1323
  }
1324
 
1325