File: flames_initemplate.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 (279 lines) | stat: -rw-r--r-- 8,327 bytes parent folder | download | duplicates (2)
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*===========================================================================
  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
  ===========================================================================*/
/*-------------------------------------------------------------------------*/
/**
 * @defgroup flames_initemplate   Substep: initialize frm
 *
 */
/*-------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
  Includes
  --------------------------------------------------------------------------*/
/**@{*/

/*---------------------------------------------------------------------------
  Implementation
  ---------------------------------------------------------------------------*/


#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <flames_midas_def.h>
#include <flames_uves.h>
#include <flames_newmatrix.h>
#include <flames_initemplate.h>
#include <uves_msg.h>
#include <flames_alloctemplate.h>

/**
   @name  flames_initemplate()  
   @short  initialize frm
   @author G. Mulas  -  ITAL_FLAMES Consortium. Ported to CPL by A. Modigliani

   @param frameid
   @param slitflats

   @return success or failure code

   DRS Functions called:          
   none                                         

   Pseudocode:                                                             
   check several MIDAS descriptors                                     

   @note
 */

flames_err 
initemplate(flames_frame *myframe, 
            char *filename,
            const char *H_RON_L,
            const char *H_RON_U,
            const char *H_GAIN_L,
            const char *H_GAIN_U)
{
    char chipchoice='\0';

    char h_ron_l[17];
    char h_ron_u[17];

    char h_gain_l[18];
    char h_gain_u[18];

    int status=0;
    int fileid=0;
    int actvals=0;
    int unit=0;
    int null=0;
    int naxis=0;
    int maxfibres=0;
    double ron=0;
    double gain=0;
    int32_t ix=0;
    int32_t iyixlimit=0;
    double start[2]={0,0};
    double step[2]={0,0};
    int npix[2]={0,0};
    frame_mask *fmvecbuf1=0;

    memset(h_ron_l, 0, 17);
    memset(h_ron_u, 0, 17);

    memset(h_gain_l, 0, 18);
    memset(h_gain_u, 0, 18);
    /* try to open the frame */
    if (0 != SCFOPN(filename, FLAMESDATATYPE, 0, F_IMA_TYPE, &fileid)) {
        /* I could not open the frame */
        return(MAREMMA);
    }
    /* is it a 2D image? */
    if (0 != SCDRDI(fileid, "NAXIS", 1, 1, &actvals, &naxis, &unit, &null)) {
        /* something went wrong in SCDRDI */
        return(MAREMMA);
    }
    if (naxis != 2) {
        /* wrong dimensions, wrong frames, I suppose... */
        return(MAREMMA);
    }

    /* read all relevant scalar descriptors */
    /* read start, step and npix from the frame */
    if (0 != SCDRDD(fileid, "START", 1, naxis, &actvals, start, &unit, &null)) {
        /* something went wrong in SCDRDD */
        return(status);
    }
    if (0 != SCDRDD(fileid, "STEP", 1, naxis, &actvals, step, &unit, &null)) {
        /* something went wrong in SCDRDD */
        return(status);
    }
    if (0 != SCDRDI(fileid, "NPIX", 1, naxis, &actvals, npix, &unit, &null)) {
        /* something went wrong in SCDRDI */
        return(status);
    }
    /* Where should the maxfibres information be stored? The most sensible
     way would perhaps be a frame descriptor in the ESO.* hierarchy.
     Remember to talk to amodigli about this */
    if (0 != SCDRDC(fileid, "CHIPCHOICE", 1, 1, 1, &actvals, &chipchoice, &unit,
    		&null)) {
        /* something went wrong in SCDRDC */
        return(status);
    }




    if (0 != SCKRDC(H_RON_L,16,1,1,&actvals, h_ron_l, &unit, &null)) {
        /* something went wrong in SCDRDC */
        return(status);
    }
    if ( 0 != SCKRDC(H_RON_U,16,1,1,&actvals, h_ron_u, &unit, &null)) {
        /* something went wrong in SCDRDC */
        return(status);
    }


    if (0 != SCKRDC(H_GAIN_L,17,1,1,&actvals, h_gain_l, &unit, &null)) {
        /* something went wrong in SCDRDC */
        return(status);
    }

    if (0 != SCKRDC(H_GAIN_U,17,1,1,&actvals, h_gain_u, &unit, &null)) {
        /* something went wrong in SCDRDC */
        return(status);
    }

    switch(chipchoice) {
    case 'u':
        /* upper chip, read the corresponding data */
        if (0 !=SCDRDD(fileid, h_ron_l, 1, 1, &actvals, &ron, &unit, &null)) {
            /* something went wrong in SCDRDD */
            return(status);
        }
        if (0 !=SCDRDD(fileid, h_gain_l, 1, 1, &actvals, &gain, &unit, &null)) {
            /* something went wrong in SCDRDD */
            return(status);
        }
        break;

    case 'l':
        /* lower chip, read the corresponding data */
        /* why h_ron_u=OUT4 is used in lower chip case */
        if (0 !=SCDRDD(fileid, h_ron_u, 1, 1, &actvals, &ron, &unit, &null)) {
            /* something went wrong in SCDRDD */
            return(status);
        }
        /* why h_gain_u=OUT4 is used in lower chip case */
        if (0 !=SCDRDD(fileid, h_gain_u, 1, 1, &actvals, &gain, &unit, &null)) {
            /* something went wrong in SCDRDD */
            return(status);
        }
        break;
    default:
        /* nothing to do here, actually the switch must have one of the
       above 2 values, if it doesn't just complain and quit */
        return(MAREMMA);
        break;
    }
    if (0 !=SCDRDI(fileid, "MAXFIBRES", 1, 1, &actvals, &maxfibres, &unit,
                    &null)) {
        /* something went wrong in SCDRDI */
        return(status);
    }
    /* set up scalar member values in myframe */
    myframe->subcols = (int32_t) npix[0];
    myframe->subrows = (int32_t) npix[1];
    myframe->maxfibres = maxfibres; /* dummy value */
    myframe->chipchoice = chipchoice;
    myframe->substartx = start[0];
    myframe->substarty = start[1];
    myframe->substepx = step[0];
    myframe->substepy = step[1];
    myframe->ron = ron;
    myframe->gain = gain;
    uves_msg("subcols=%d subrows=%d maxfibres=%d chipchoice=%c substartx=%f substarty=%f substepx=%f substepy=%f ron=%f gain=%f",
             myframe->subcols,
             myframe->subrows,
             myframe->maxfibres,
             myframe->chipchoice,
             myframe->substartx,
             myframe->substarty,
             myframe->substepx,
             myframe->substepy,
             myframe->ron,
             myframe->gain);

    /* these will be set up during the reduction, they are still
     undefined here */
    myframe->firstorder = 0;
    myframe->lastorder = 0;
    myframe->tab_io_oshift = 0;
    myframe->nflats = 0;
    myframe->back.Window_Number = 0;

    /* allocate dynamic submembers here */
    if (NOERR != alloctemplate(myframe)) {
        /* alloctemplate returned an error */
        return(MAREMMA);
    }

    /* fill the bad pixel mask with zeros */
    iyixlimit = (myframe->subrows*myframe->subcols)-1;
    fmvecbuf1 = myframe->badpixel[0];
    for (ix=0; ix<=iyixlimit; ix++) {
        fmvecbuf1[ix] = 0;
    }

    /* close image frame */
    if (0 != SCFCLO(fileid)) {
        /* error closing image file */
        return(MAREMMA);
    }

    /* template frame successfully setup from image frame */

    return(NOERR);

}
/**@}*/