00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 #include "vircam_mods.h"
00035 #include "vircam_utils.h"
00036 #include "vircam_mask.h"
00037 #include "vircam_stats.h"
00038 #include "vircam_fits.h"
00039
00042
00085
00086
00087 extern int vircam_mkconf(cpl_image *flat, char *flatfile, vir_mask *bpm,
00088 cpl_image **outconf, cpl_propertylist **drs,
00089 int *status) {
00090 int i,*odata,nx,ny;
00091 long npts;
00092 unsigned char *bdata;
00093 float *fdata,mean;
00094 const char *fctid = "vircam_mkconf";
00095
00096
00097
00098 if (*status != VIR_OK)
00099 return(*status);
00100
00101
00102
00103 nx = cpl_image_get_size_x(flat);
00104 ny = cpl_image_get_size_y(flat);
00105 npts = nx*ny;
00106 if (vircam_mask_get_size_x(bpm)*vircam_mask_get_size_y(bpm) != npts) {
00107 cpl_msg_error(fctid,"Input image sizes don't match!");
00108 FATAL_ERROR
00109 }
00110
00111
00112
00113 if ((fdata = cpl_image_get_data_float(flat)) == NULL) {
00114 cpl_msg_error(fctid,"Unable to map flat data!");
00115 FATAL_ERROR
00116 }
00117 bdata = vircam_mask_get_data(bpm);
00118
00119
00120
00121 odata = cpl_malloc(npts*sizeof(*odata));
00122
00123
00124
00125
00126 mean = vircam_mean(fdata,bdata,npts);
00127
00128
00129
00130 for (i = 0; i < npts; i++) {
00131 if (bdata[i] != 1)
00132 odata[i] = min(110,(int)(100.0*fdata[i]/mean + 0.5));
00133 else
00134 odata[i] = 0;
00135 }
00136
00137
00138
00139 *outconf = cpl_image_wrap_int(nx,ny,odata);
00140
00141
00142
00143 *drs = cpl_propertylist_new();
00144 cpl_propertylist_update_string(*drs,"ESO DRS FLATIN",flatfile);
00145 cpl_propertylist_set_comment(*drs,"ESO DRS FLATIN",
00146 "Flat used to create this conf map");
00147 if (vircam_mask_get_type(bpm) != MASK_NONE)
00148 cpl_propertylist_update_string(*drs,"ESO DRS BPMIN",
00149 vircam_fits_get_fullname(vircam_mask_get_fits(bpm)));
00150 else
00151 cpl_propertylist_update_string(*drs,"ESO DRS BPMIN","None available");
00152 cpl_propertylist_set_comment(*drs,"ESO DRS BPMIN",
00153 "BPM used to create this conf map");
00154
00155
00156
00157 GOOD_STATUS
00158 }
00159
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199