File: flames_multimatch.c

package info (click to toggle)
cpl-plugin-uves 6.1.3+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 23,128 kB
  • sloc: ansic: 171,056; sh: 4,359; python: 3,002; makefile: 1,322
file content (166 lines) | stat: -rw-r--r-- 7,074 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* @(#)multimatch    */
/*===========================================================================
  Copyright (C) 2001 European Southern Observatory (ESO)

  This program is free software; you can redistribute it and/or 
  modify it under the terms of the GNU General Public License as 
  published by the Free Software Foundation; either version 2 of 
  the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public 
  License along with this program; if not, write to the Free 
  Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, 
  MA 02139, USA.

  Corresponding concerning ESO-MIDAS should be addressed as follows:
    Internet e-mail: midas@eso.org
    Postal address: European Southern Observatory
            Data Management Division 
            Karl-Schwarzschild-Strasse 2
            D 85748 Garching bei Muenchen 
            GERMANY
===========================================================================*/
/* Program  : multimatch.c                                                 */
/* Author   : I. Porceddu  -  ITAL_FLAMES Consortium                       */
/* Date     :                                                              */
/*                                                                         */
/* Purpose  :                                                              */
/*                                                                         */
/* Input    :                                                              */
/*      ORDTAB                                                             */
/*      Table originated by HOUGH/ECHELLE. Threee further columns have     */
/*      been added                                                         */
/*    Now rmiddummr.tbl                                                  */
/*      DEFPOL     Degree in x and m domain as computed during format      */
/*                 check loop                                              */
/*                                                                         */
/*      COEFFD     A descriptor containing the coeffs of the bivariate     */
/*                 poly as extracted from the format check application     */
/*                                                                         */
/*      ECHORD   Number of the first guess detected orders                 */
/*                                                                         */
/* Output:                                                           */
/*      OUTTAB     rmiddummr.tbl with :NEWORD and :FIBRE filled            */ 
/*                                                                         */
/* SEQUENCE:
   - flames_preordpos (preordpos.c) 
       creates rmiddumm table 
   - flames_ordpos (hough/echelle - matchorders.c - tracing.c - fitting.c )
       hough/echelle: creates middummr table and clone it into rmiddummr table
       matchorders: adds :NEWORD and :FIBRE values to rmiddummr table
 */
/*                                                                         */
/* DRS Functions called:                                                   */
/* none                                                                    */ 
/*                                                                         */ 
/* Pseudocode:                                                             */
/* Missing                                                                 */ 
/*                                                                         */ 
/* Version  :                                                              */
/* Last modification date: 2002/08/05                                      */
/* Who     When        Why                Where                            */
/* AMo     02-08-05   Add header         header                            */
/*-------------------------------------------------------------------------*/
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <flames_multimatch.h>

#include <flames_uves.h>
#include <flames_newmatrix.h>
#include <flames_midas_tblsys.h>
#include <flames_midas_tblerr.h>
#include <flames_midas_tbldef.h>
#include <flames_midas_macrogen.h>
#include <flames_midas_atype.h>
#include <flames_midas_def.h>
#include <flames_def_drs_par.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int flames_multimatch(cpl_frameset *CATNAME,
                      char *ALLFRAME,
                      int *LENGTH)                      
{
    int null=0;
    int actvals=0;
    int unit=0;
    int entries=0;
    int i=0;
    int last_entry=0;
    int seq=0;
    int status=0;
    int *length=0;
    int total_length=0;
    int maxfibres=0;
    //char ffcat[60];
    cpl_frameset *ffcat;
    char text[60];
    char frame_name[CATREC_LEN];
    char *frames;

    /* let's make sure frames is a null string, otherwise this may wreak havoc
     at concatenation time */
    //  memset(ffcat, '\0', 60);
    memset(text, '\0', 60);
    memset(frame_name, '\0', CATREC_LEN);

    /* === interface to MIDAS ================================================= */

    /*Let's initialize the MIDAS environment */
    SCSPRO("multimatch");

    /* initialise MAXFIBRES from keyword */
    if (SCKRDI(&MAXFIBRES, 1, 1, &actvals, &maxfibres, &unit, &null) != 0) {
        /* problems reading MAXFIBRES */
        SCTPUT("Error reading the MAXFIBRES keyword");
        return flames_midas_fail();
    }
    frames = calloc(CATREC_LEN*maxfibres, sizeof(char));
    memset(frames, '\0', CATREC_LEN*maxfibres);

    /* Let's open the catalog containing the frames to be processed
     The keyword CATNAME does contain the catalog's name */

    /* Catalog name */
    //  SCKGETC(CATNAME,1,60,&actvals,ffcat);
    ffcat = CATNAME;
    /* Display information line */
    //  sprintf (text,"Catalog file is %s\n",ffcat);
    //  SCTPUT  (text);
    /* Catalog info */
    SCCSHO(ffcat,&entries,&last_entry);
    length = ivector(1, entries);
    for (i=1; i<=entries; i++) {
        length[i] = 0;
    }
    for( seq = 1; seq <= entries; seq++) {
        if ((status = SCCFND(ffcat, seq, frame_name)) != 0) {
            /* no catalogue entry */
            /* Display information line */
            //      sprintf (text,"Catalog file %s does not contain more frames \n", ffcat);
            sprintf (text,"Catalog does not contain more frames \n");
        }
        strncat(&frames[0],frame_name,CATREC_LEN);
        length[seq] = strlen(frame_name);
        total_length += length[seq];
    }
    length[0] = entries;
    SCKWRC(ALLFRAME,1,frames,1,total_length,&null);
    SCKWRI(LENGTH,length,1,entries+1,&null);
    /*printf("%s %d \n ",frames,strlen(frames)); */

    free(frames);
    free_ivector(length,1,entries);

    return SCSEPI();

}