public software.sextractor

[/] [trunk/] [src/] [makeit.c] - Blame information for rev 235

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 bertin
/*
2 233 bertin
*                               makeit.c
3 2 bertin
*
4 233 bertin
* Main program.
5 2 bertin
*
6 233 bertin
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 2 bertin
*
8 233 bertin
*       This file part of:      SExtractor
9 2 bertin
*
10 235 bertin
*       Copyright:              (C) 1993-2010 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 234 bertin
*       Last modified:          14/10/2010
26 233 bertin
*
27
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
28 2 bertin
 
29
#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
#include        <time.h>
38
 
39
#include        "define.h"
40
#include        "globals.h"
41
#include        "prefs.h"
42
#include        "fits/fitscat.h"
43
#include        "assoc.h"
44
#include        "back.h"
45
#include        "check.h"
46 173 bertin
#include        "fft.h"
47 2 bertin
#include        "field.h"
48
#include        "filter.h"
49
#include        "growth.h"
50
#include        "interpolate.h"
51 173 bertin
#include        "pattern.h"
52 2 bertin
#include        "psf.h"
53 173 bertin
#include        "profit.h"
54 2 bertin
#include        "som.h"
55
#include        "weight.h"
56 8 bertin
#include        "xml.h"
57 2 bertin
 
58 173 bertin
static int              selectext(char *filename);
59
time_t                  thetimet, thetimet2;
60
extern profitstruct     *theprofit;
61
extern char             profname[][32];
62 219 bertin
double                  dtime;
63 11 bertin
 
64 2 bertin
/******************************** makeit *************************************/
65
/*
66
Manage the whole stuff.
67
*/
68
void    makeit()
69
 
70
  {
71
   checkstruct          *check;
72
   picstruct            *dfield, *field,*pffield[MAXFLAG], *wfield,*dwfield;
73
   catstruct            *imacat;
74
   tabstruct            *imatab;
75 173 bertin
   patternstruct        *pattern;
76 2 bertin
   static time_t        thetime1, thetime2;
77 8 bertin
   struct tm            *tm;
78 208 bertin
   int                  nflag[MAXFLAG], nparam2[2],
79 173 bertin
                        i, nok, ntab, next, ntabmax, forcextflag,
80
                        nima0,nima1, nweight0,nweight1, npat;
81 2 bertin
 
82 11 bertin
/* Install error logging */
83 16 bertin
  error_installfunc(write_error);
84 11 bertin
 
85 8 bertin
/* Processing start date and time */
86 219 bertin
  dtime = counter_seconds();
87 8 bertin
  thetimet = time(NULL);
88
  tm = localtime(&thetimet);
89
  sprintf(prefs.sdate_start,"%04d-%02d-%02d",
90
        tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
91
  sprintf(prefs.stime_start,"%02d:%02d:%02d",
92
        tm->tm_hour, tm->tm_min, tm->tm_sec);
93
 
94
  NFPRINTF(OUTPUT, "");
95
  QPRINTF(OUTPUT, "----- %s %s started on %s at %s with %d thread%s\n\n",
96
                BANNER,
97
                MYVERSION,
98
                prefs.sdate_start,
99
                prefs.stime_start,
100
                prefs.nthreads,
101
                prefs.nthreads>1? "s":"");
102
 
103 2 bertin
/* Initialize globals variables */
104
  initglob();
105
 
106
  NFPRINTF(OUTPUT, "Setting catalog parameters");
107
  readcatparams(prefs.param_name);
108
  useprefs();                   /* update things accor. to prefs parameters */
109
 
110 234 bertin
  if (prefs.psf_flag)
111 2 bertin
    {
112
    NFPRINTF(OUTPUT, "Reading PSF information");
113 5 bertin
    thepsf = psf_load(prefs.psf_name[0]);
114
    if (prefs.dpsf_flag)
115
      ppsf = psf_load(prefs.psf_name[1]);
116 2 bertin
 /*-- Need to check things up because of PSF context parameters */
117
    updateparamflags();
118
    useprefs();
119
    }
120
 
121 173 bertin
  if (prefs.prof_flag)
122
    {
123 227 bertin
#ifdef USE_MODEL
124 194 bertin
    fft_init(prefs.nthreads);
125 173 bertin
/* Create profiles at full resolution */
126
    NFPRINTF(OUTPUT, "Preparing profile models");
127
    theprofit = profit_init(thepsf);
128 208 bertin
    changecatparamarrays("VECTOR_MODEL", &theprofit->nparam, 1);
129
    changecatparamarrays("VECTOR_MODELERR", &theprofit->nparam, 1);
130
    nparam2[0] = nparam2[1] = theprofit->nparam;
131 209 bertin
    changecatparamarrays("MATRIX_MODELERR", nparam2, 2);
132 173 bertin
    if (prefs.pattern_flag)
133
      {
134
      npat = prefs.prof_disk_patternvectorsize;
135
      if (npat<prefs.prof_disk_patternmodvectorsize)
136
        npat = prefs.prof_disk_patternmodvectorsize;
137
      if (npat<prefs.prof_disk_patternargvectorsize)
138
        npat = prefs.prof_disk_patternargvectorsize;
139
/*---- Do a copy of the original number of pattern components */
140
      prefs.prof_disk_patternncomp = npat;
141
      pattern = pattern_init(theprofit, prefs.pattern_type, npat);
142
      if (FLAG(obj2.prof_disk_patternvector))
143
        {
144
        npat = pattern->size[2];
145
        changecatparamarrays("DISK_PATTERN_VECTOR", &npat, 1);
146
        }
147
      if (FLAG(obj2.prof_disk_patternmodvector))
148
        {
149
        npat = pattern->ncomp*pattern->nfreq;
150
        changecatparamarrays("DISK_PATTERNMOD_VECTOR", &npat, 1);
151
        }
152
      if (FLAG(obj2.prof_disk_patternargvector))
153
        {
154
        npat = pattern->ncomp*pattern->nfreq;
155
        changecatparamarrays("DISK_PATTERNARG_VECTOR", &npat, 1);
156
        }
157
      pattern_end(pattern);
158
      }
159
    QPRINTF(OUTPUT, "Fitting model: ");
160
    for (i=0; i<theprofit->nprof; i++)
161
      {
162
      if (i)
163
        QPRINTF(OUTPUT, "+");
164
      QPRINTF(OUTPUT, "%s", profname[theprofit->prof[i]->code]);
165
      }
166
    QPRINTF(OUTPUT, "\n");
167 227 bertin
#else
168
    error(EXIT_FAILURE,
169
                "*Error*: model-fitting is not supported in this build.\n",
170
                        " Please check your configure options");
171
#endif
172 173 bertin
    }
173
 
174 2 bertin
  if (prefs.filter_flag)
175
    {
176
    NFPRINTF(OUTPUT, "Reading detection filter");
177
    getfilter(prefs.filter_name);       /* get the detection filter */
178
    }
179
 
180
  if (FLAG(obj2.sprob))
181
    {
182
    NFPRINTF(OUTPUT, "Initializing Neural Network");
183
    neurinit();
184
    NFPRINTF(OUTPUT, "Reading Neural Network Weights");
185
    getnnw();
186
    }
187
 
188
  if (prefs.somfit_flag)
189
    {
190
     int        margin;
191
 
192
    thesom = som_load(prefs.som_name);
193
    if ((margin=(thesom->inputsize[1]+1)/2) > prefs.cleanmargin)
194
      prefs.cleanmargin = margin;
195
    if (prefs.somfit_vectorsize>thesom->neurdim)
196
      {
197
      prefs.somfit_vectorsize = thesom->neurdim;
198
      sprintf(gstr,"%d", prefs.somfit_vectorsize);
199
      warning("Dimensionality of the SOM-fit vector limited to ", gstr);
200
      }
201
    }
202
 
203
/* Prepare growth-curve buffer */
204
  if (prefs.growth_flag)
205
    initgrowth();
206
 
207 173 bertin
/* Allocate memory for multidimensional catalog parameter arrays */
208
  alloccatparams();
209
  useprefs();
210
 
211
/* Check if a specific extension should be loaded */
212
  if ((nima0=selectext(prefs.image_name[0])) != RETURN_ERROR)
213
    {
214
    forcextflag = 1;
215
    ntabmax = next = 1;
216
    }
217
  else
218
    forcextflag = 0;
219
 
220 2 bertin
  if (!(imacat = read_cat(prefs.image_name[0])))
221
    error(EXIT_FAILURE, "*Error*: cannot open ", prefs.image_name[0]);
222
  close_cat(imacat);
223
  imatab = imacat->tab;
224 173 bertin
 
225
  if (!forcextflag)
226 2 bertin
    {
227 173 bertin
    ntabmax = imacat->ntab;
228
/*-- Compute the number of valid input extensions */
229
    next = 0;
230
    for (ntab = 0 ; ntab<imacat->ntab; ntab++, imatab = imatab->nexttab)
231
      {
232
/*---- Check for the next valid image extension */
233
      if ((imatab->naxis < 2)
234 2 bertin
        || !strncmp(imatab->xtension, "BINTABLE", 8)
235
        || !strncmp(imatab->xtension, "ASCTABLE", 8))
236 173 bertin
        continue;
237
      next++;
238
      }
239 2 bertin
    }
240 173 bertin
 
241
/* Do the same for other data (but do not force single extension mode) */
242
  nima1 = selectext(prefs.image_name[1]);
243
  nweight0 = selectext(prefs.wimage_name[0]);
244
  nweight1 = selectext(prefs.wimage_name[1]);
245
  for (i=0; i<prefs.nfimage_name; i++)
246
    nflag[i] = selectext(prefs.fimage_name[i]);
247
 
248 2 bertin
  thecat.next = next;
249
 
250
/*-- Init the CHECK-images */
251
  if (prefs.check_flag)
252
    {
253
     checkenum  c;
254
 
255
    NFPRINTF(OUTPUT, "Initializing check-image(s)");
256
    for (i=0; i<prefs.ncheck_type; i++)
257 173 bertin
      if ((c=prefs.check_type[i]) != CHECK_NONE)
258
        {
259
        if (prefs.check[c])
260
           error(EXIT_FAILURE,"*Error*: 2 CHECK_IMAGEs cannot have the same ",
261 2 bertin
                        " CHECK_IMAGE_TYPE");
262 173 bertin
        prefs.check[c] = initcheck(prefs.check_name[i], prefs.check_type[i],
263 2 bertin
                        next);
264 173 bertin
        }
265 2 bertin
    }
266
 
267
  NFPRINTF(OUTPUT, "Initializing catalog");
268
  initcat();
269
 
270 8 bertin
/* Initialize XML data */
271 15 bertin
  if (prefs.xml_flag || prefs.cat_type==ASCII_VO)
272 8 bertin
    init_xml(next);
273 2 bertin
 
274
/* Go through all images */
275
  nok = -1;
276 173 bertin
  for (ntab = 0 ; ntab<ntabmax; ntab++, imatab = imatab->nexttab)
277 2 bertin
    {
278
/*--  Check for the next valid image extension */
279 173 bertin
    if (!forcextflag && ((imatab->naxis < 2)
280 2 bertin
        || !strncmp(imatab->xtension, "BINTABLE", 8)
281 173 bertin
        || !strncmp(imatab->xtension, "ASCTABLE", 8)))
282 2 bertin
      continue;
283
    nok++;
284
 
285
/*-- Initial time measurement*/
286
    time(&thetime1);
287
    thecat.currext = nok+1;
288
 
289
    dfield = field = wfield = dwfield = NULL;
290
 
291
    if (prefs.dimage_flag)
292
      {
293
/*---- Init the Detection and Measurement-images */
294 173 bertin
      dfield = newfield(prefs.image_name[0], DETECT_FIELD,
295
        nima0<0? nok:nima0);
296
      field = newfield(prefs.image_name[1], MEASURE_FIELD,
297
        nima1<0? nok:nima1);
298 2 bertin
      if ((field->width!=dfield->width) || (field->height!=dfield->height))
299
        error(EXIT_FAILURE, "*Error*: Frames have different sizes","");
300
/*---- Prepare interpolation */
301
      if (prefs.dweight_flag && prefs.interp_type[0] == INTERP_ALL)
302
        init_interpolate(dfield, -1, -1);
303
      if (prefs.interp_type[1] == INTERP_ALL)
304
        init_interpolate(field, -1, -1);
305
      }
306
    else
307
      {
308 173 bertin
      field = newfield(prefs.image_name[0], DETECT_FIELD | MEASURE_FIELD,
309
                nima0<0? nok:nima0);
310
 
311 2 bertin
/*-- Prepare interpolation */
312
      if ((prefs.dweight_flag || prefs.weight_flag)
313
        && prefs.interp_type[0] == INTERP_ALL)
314
      init_interpolate(field, -1, -1);       /* 0.0 or anything else */
315
      }
316
 
317
/*-- Init the WEIGHT-images */
318
    if (prefs.dweight_flag || prefs.weight_flag)
319
      {
320
       weightenum       wtype;
321
       PIXTYPE  interpthresh;
322
 
323
      if (prefs.nweight_type>1)
324
        {
325
/*------ Double-weight-map mode */
326
        if (prefs.weight_type[1] != WEIGHT_NONE)
327
          {
328
/*-------- First: the "measurement" weights */
329
          wfield = newweight(prefs.wimage_name[1],field,prefs.weight_type[1],
330 173 bertin
                nweight1<0? nok:nweight1);
331 2 bertin
          wtype = prefs.weight_type[1];
332
          interpthresh = prefs.weight_thresh[1];
333
/*-------- Convert the interpolation threshold to variance units */
334
          weight_to_var(wfield, &interpthresh, 1);
335
          wfield->weight_thresh = interpthresh;
336
          if (prefs.interp_type[1] != INTERP_NONE)
337
            init_interpolate(wfield,
338
                prefs.interp_xtimeout[1], prefs.interp_ytimeout[1]);
339
          }
340
/*------ The "detection" weights */
341
        if (prefs.weight_type[0] != WEIGHT_NONE)
342
          {
343
          interpthresh = prefs.weight_thresh[0];
344
          if (prefs.weight_type[0] == WEIGHT_FROMINTERP)
345
            {
346
            dwfield=newweight(prefs.wimage_name[0],wfield,prefs.weight_type[0],
347 173 bertin
                nweight0<0? nok:nweight0);
348 2 bertin
            weight_to_var(wfield, &interpthresh, 1);
349
            }
350
          else
351
            {
352
            dwfield = newweight(prefs.wimage_name[0], dfield?dfield:field,
353 173 bertin
                prefs.weight_type[0], nweight0<0? nok:nweight0);
354 2 bertin
            weight_to_var(dwfield, &interpthresh, 1);
355
            }
356
          dwfield->weight_thresh = interpthresh;
357
          if (prefs.interp_type[0] != INTERP_NONE)
358
            init_interpolate(dwfield,
359
                prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]);
360
          }
361
        }
362
      else
363
        {
364
/*------ Single-weight-map mode */
365
        wfield = newweight(prefs.wimage_name[0], dfield?dfield:field,
366 173 bertin
                        prefs.weight_type[0], nweight0<0? nok:nweight0);
367 2 bertin
        wtype = prefs.weight_type[0];
368
        interpthresh = prefs.weight_thresh[0];
369
/*------ Convert the interpolation threshold to variance units */
370
        weight_to_var(wfield, &interpthresh, 1);
371
        wfield->weight_thresh = interpthresh;
372
        if (prefs.interp_type[0] != INTERP_NONE)
373
          init_interpolate(wfield,
374
                prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]);
375
        }
376
      }
377
 
378
/*-- Init the FLAG-images */
379
    for (i=0; i<prefs.nimaflag; i++)
380
      {
381 173 bertin
      pffield[i] = newfield(prefs.fimage_name[i], FLAG_FIELD,
382
                nflag[i]<0? nok:nflag[i]);
383 2 bertin
      if ((pffield[i]->width!=field->width)
384
        || (pffield[i]->height!=field->height))
385
        error(EXIT_FAILURE,
386
        "*Error*: Incompatible FLAG-map size in ", prefs.fimage_name[i]);
387
      }
388
 
389
/*-- Compute background maps for `standard' fields */
390
    QPRINTF(OUTPUT, dfield? "Measurement image:"
391
                        : "Detection+Measurement image: ");
392
    makeback(field, wfield);
393
    QPRINTF(OUTPUT, (dfield || (dwfield&&dwfield->flags^INTERP_FIELD))? "(M)   "
394
                "Background: %-10g RMS: %-10g / Threshold: %-10g \n"
395
                : "(M+D) "
396
                "Background: %-10g RMS: %-10g / Threshold: %-10g \n",
397
        field->backmean, field->backsig, (field->flags & DETECT_FIELD)?
398
        field->dthresh: field->thresh);
399
    if (dfield)
400 234 bertin
      {
401 2 bertin
      QPRINTF(OUTPUT, "Detection image: ");
402
      makeback(dfield, dwfield? dwfield
403
                        : (prefs.weight_type[0] == WEIGHT_NONE?NULL:wfield));
404
      QPRINTF(OUTPUT, "(D)   "
405
                "Background: %-10g RMS: %-10g / Threshold: %-10g \n",
406
        dfield->backmean, dfield->backsig, dfield->dthresh);
407
      }
408
    else if (dwfield && dwfield->flags^INTERP_FIELD)
409
      {
410
      makeback(field, dwfield);
411
      QPRINTF(OUTPUT, "(D)   "
412
                "Background: %-10g RMS: %-10g / Threshold: %-10g \n",
413
        field->backmean, field->backsig, field->dthresh);
414
      }
415
 
416
/*-- For interpolated weight-maps, copy the background structure */
417
    if (dwfield && dwfield->flags&(INTERP_FIELD|BACKRMS_FIELD))
418
      copyback(dwfield->reffield, dwfield);
419
    if (wfield && wfield->flags&(INTERP_FIELD|BACKRMS_FIELD))
420
      copyback(wfield->reffield, wfield);
421
 
422
/*-- Prepare learn and/or associations */
423
    if (prefs.assoc_flag)
424
      init_assoc(field);                  /* initialize assoc tasks */
425
 
426
/*-- Update the CHECK-images */
427
    if (prefs.check_flag)
428
      for (i=0; i<MAXCHECK; i++)
429
        if ((check=prefs.check[i]))
430
          reinitcheck(field, check);
431
 
432
/*-- Initialize PSF contexts and workspace */
433
    if (prefs.psf_flag)
434
      {
435
      psf_readcontext(thepsf, field);
436
      psf_init(thepsf);
437 5 bertin
      if (prefs.dpsf_flag)
438
        {
439
        psf_readcontext(thepsf, dfield);
440
        psf_init(thepsf); /*?*/
441
        }
442 2 bertin
      }
443
 
444
/*-- Copy field structures to static ones (for catalog info) */
445
    if (dfield)
446
      {
447
      thefield1 = *field;
448
      thefield2 = *dfield;
449
      }
450
    else
451
      thefield1 = thefield2 = *field;
452
 
453
    if (wfield)
454
      {
455
      thewfield1 = *wfield;
456
      thewfield2 = dwfield? *dwfield: *wfield;
457
      }
458
    else if (dwfield)
459
      thewfield2 = *dwfield;
460
 
461
    reinitcat(field);
462
 
463
/*-- Start the extraction pipeline */
464
    NFPRINTF(OUTPUT, "Scanning image");
465
    scanimage(field, dfield, pffield, prefs.nimaflag, wfield, dwfield);
466
 
467
/*-- Finish the current CHECK-image processing */
468
    if (prefs.check_flag)
469
      for (i=0; i<MAXCHECK; i++)
470
        if ((check=prefs.check[i]))
471
          reendcheck(field, check);
472
 
473
/*-- Final time measurements*/
474
    if (time(&thetime2)!=-1)
475
      {
476
      if (!strftime(thecat.ext_date, 12, "%d/%m/%Y", localtime(&thetime2)))
477
        error(EXIT_FAILURE, "*Internal Error*: Date string too long ","");
478
      if (!strftime(thecat.ext_time, 10, "%H:%M:%S", localtime(&thetime2)))
479
        error(EXIT_FAILURE, "*Internal Error*: Time/date string too long ","");
480
      thecat.ext_elapsed = difftime(thetime2, thetime1);
481
      }
482
 
483
    reendcat();
484
 
485 8 bertin
/* Update XML data */
486 15 bertin
  if (prefs.xml_flag || prefs.cat_type==ASCII_VO)
487 9 bertin
    update_xml(&thecat, dfield? dfield:field, field,
488
        dwfield? dwfield:wfield, wfield);
489 8 bertin
 
490
 
491 2 bertin
/*-- Close ASSOC routines */
492
    end_assoc(field);
493
 
494
    for (i=0; i<prefs.nimaflag; i++)
495
      endfield(pffield[i]);
496
    endfield(field);
497
    if (dfield)
498
      endfield(dfield);
499
    if (wfield)
500
      endfield(wfield);
501
    if (dwfield)
502
      endfield(dwfield);
503
 
504 220 bertin
    QPRINTF(OUTPUT, "      Objects: detected %-8d / sextracted %-8d        \n\n",
505 2 bertin
        thecat.ndetect, thecat.ntotal);
506
    }
507
 
508
  if (nok<0)
509
    error(EXIT_FAILURE, "Not enough valid FITS image extensions in ",
510
        prefs.image_name[0]);
511
  free_cat(&imacat, 1);
512
 
513
  NFPRINTF(OUTPUT, "Closing files");
514
 
515
/* End CHECK-image processing */
516
  if (prefs.check_flag)
517
    for (i=0; i<MAXCHECK; i++)
518
      {
519
      if ((check=prefs.check[i]))
520
        endcheck(check);
521
      prefs.check[i] = NULL;
522
      }
523
 
524
  if (prefs.filter_flag)
525
    endfilter();
526
 
527
  if (prefs.somfit_flag)
528
    som_end(thesom);
529
 
530
  if (prefs.growth_flag)
531
    endgrowth();
532
 
533 227 bertin
#ifdef USE_MODEL
534 173 bertin
  if (prefs.prof_flag)
535
    {
536
    profit_end(theprofit);
537
    fft_end();
538
    }
539 227 bertin
#endif
540 173 bertin
 
541 234 bertin
  if (prefs.psf_flag)
542 5 bertin
    psf_end(thepsf,thepsfit); /*?*/
543 2 bertin
 
544 5 bertin
  if (prefs.dpsf_flag)
545
    psf_end(ppsf,ppsfit);
546
 
547 2 bertin
  if (FLAG(obj2.sprob))
548
    neurclose();
549
 
550 8 bertin
/* Processing end date and time */
551
  thetimet2 = time(NULL);
552
  tm = localtime(&thetimet2);
553
  sprintf(prefs.sdate_end,"%04d-%02d-%02d",
554
        tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
555
  sprintf(prefs.stime_end,"%02d:%02d:%02d",
556
        tm->tm_hour, tm->tm_min, tm->tm_sec);
557 219 bertin
  prefs.time_diff = counter_seconds() - dtime;
558 8 bertin
 
559
/* Write XML */
560 17 bertin
  if (prefs.xml_flag)
561
    write_xml(prefs.xml_name);
562 16 bertin
 
563 17 bertin
  endcat((char *)NULL);
564
 
565 15 bertin
  if (prefs.xml_flag || prefs.cat_type==ASCII_VO)
566
    end_xml();
567 8 bertin
 
568 2 bertin
  return;
569
  }
570
 
571
 
572
/******************************** initglob ***********************************/
573
/*
574
Initialize a few global variables
575
*/
576
void    initglob()
577
  {
578
   int  i;
579
 
580
  for (i=0; i<37; i++)
581
    {
582
    ctg[i] = cos(i*PI/18);
583
    stg[i] = sin(i*PI/18);
584
    }
585
 
586
 
587
  return;
588
  }
589
 
590
 
591 173 bertin
/****** selectext ************************************************************
592
PROTO   int selectext(char *filename)
593
PURPOSE Return the user-selected extension number [%d] from the file name.
594
INPUT   Filename character string.
595
OUTPUT  Extension number, or RETURN_ERROR if nos extension specified.
596
NOTES   The bracket and its extension number are removed from the filename if
597
        found.
598
AUTHOR  E. Bertin (IAP)
599
VERSION 08/10/2007
600
 ***/
601
static int      selectext(char *filename)
602
  {
603
   char *bracl,*bracr;
604
   int  next;
605
 
606
  if (filename && (bracl=strrchr(filename, '[')))
607
    {
608
    *bracl = '\0';
609
    if ((bracr=strrchr(bracl+1, ']')))
610
      *bracr = '\0';
611
    next = strtol(bracl+1, NULL, 0);
612
    return next;
613
    }
614
 
615
  return RETURN_ERROR;
616
  }
617
 
618
 
619 16 bertin
/****** write_error ********************************************************
620
PROTO   int     write_error(char *msg1, char *msg2)
621
PURPOSE Manage files in case of a catched error
622
INPUT   a character string,
623
        another character string
624
OUTPUT  RETURN_OK if everything went fine, RETURN_ERROR otherwise.
625
NOTES   -.
626
AUTHOR  E. Bertin (IAP)
627 17 bertin
VERSION 14/07/2006
628 16 bertin
 ***/
629
void    write_error(char *msg1, char *msg2)
630
  {
631
   char                 error[MAXCHAR];
632
 
633
  sprintf(error, "%s%s", msg1,msg2);
634
  if (prefs.xml_flag)
635
    write_xmlerror(prefs.xml_name, error);
636
 
637
/* Also close existing catalog */
638
  endcat(error);
639
 
640
  end_xml();
641
 
642
  return;
643
  }
644
 
645 219 bertin