Commit 30192305 authored by Johan Richard's avatar Johan Richard
Browse files

Added output option to cleanlens 2

parent ee5e9d9c
......@@ -455,6 +455,7 @@ void w_prop(int nprop, char propfile[]);
void wr_mass(char *name, double **map_xx, double **map_yy);
void wr_pot(char *name, double **map);
void w_sicat(struct galaxie ima[NFMAX][NIMAX], struct galaxie ss[NFMAX]);
void wrf_from_header(char *filein, char *filename, int nx, int ny, double **tabpix);
double zero(double c1, double c2, double (*f)(double));
double zero_t(double c1, double c2, double (*f)(double));
void zonemult();
......
......@@ -234,6 +234,7 @@ struct g_mode
int iclean;
double zclean;
int flux; //conserve surface brightness ? 1=True 0=False
int output; //writes models and residuals from shapemodel
/* center of multiple images file */
char centerfile[FILENAME_SIZE];
/* bayesys restart flag */
......
......@@ -817,3 +817,54 @@ int wrf_cube_fits_abs(char *filename, double ***cube, int nx,int ny, int nz,
return 0;
}
/* write output image based on known header */
void wrf_from_header(char *filein, char *filename, int nx, int ny, double **tabpix)
{
fitsfile *infptr;
fitsfile *outfptr;
int status;
int nkeys;
int fpixel;
int nelements;
float *p_ima;
int ii,jj,k;
int bitpix=FLOAT_IMG;
long naxes[2] = {nx,ny};
status = 0; /* initialize status before calling fitsio routines */
if( fits_open_file(&infptr, filein, READONLY, &status) )
printerror( status );
fpixel = 1;
nelements = nx*ny;
p_ima=(float *)malloc((unsigned) (nelements)*sizeof(float));
k=0;
for (jj=0;jj<ny;jj++)
for (ii=0;ii<nx;ii++)
{
p_ima[k]=(float)tabpix[jj][ii];
k++;
}
remove(filename); /* Delete old file if it already exists */
status = CREATE_DISK_FILE; /* initialize status before calling fitsio routines */
if (fits_create_file(&outfptr, filename, &status)) /* create new FITS file */
printerror( status ); /* call printerror if error occurs */
if ( fits_copy_header(infptr, outfptr, &status) )
printerror( status );
// if ( fits_create_img(outfptr, bitpix, 2, naxes, &status) )
// printerror( status );
if ( fits_write_img(outfptr, TFLOAT, fpixel, nelements, p_ima, &status) )
printerror( status );
if ( fits_close_file(infptr, &status) ) /* close the file */
printerror( status );
if ( fits_close_file(outfptr, &status) )
printerror(status);
free(p_ima);
}
......@@ -205,6 +205,15 @@ int o_chi_lhood0(double *chi_ext, double *lhood0_ext, double *np_b0)
M.verbose = verbose_save;
// mod jrichard output shapemodel
if(M.output)
{
fprintf(stderr, "Write output model with same header as input - smodel.fits\n");
wrf_from_header(imFrame.pixfile,"smodel.fits", imFrame.nx, imFrame.ny, ero);
}
if (wo != NULL)
{
// mod bclement shapemodel_contour
......@@ -237,6 +246,13 @@ int o_chi_lhood0(double *chi_ext, double *lhood0_ext, double *np_b0)
}
}
// mod jrichard output shapemodel
if(M.output)
{
fprintf(stderr, "Write output residuals with same header as input - residuals.fits\n");
wrf_from_header(imFrame.pixfile,"residuals.fits", imFrame.nx, imFrame.ny, ero);
}
// restore relative source positions
if( I.n_mult > 0 )
for( i = 0; i < S.ns; i++ )
......@@ -1848,3 +1864,4 @@ static void srcfitLinFit(double *chi2, double *lh0)
#endif
}
......@@ -158,6 +158,11 @@ void r_cleanlens(FILE *IN, FILE *OUT)
sscanf(third, "%lf", &ps.ymax);
fprintf(OUT, "\t%s\t%lf\n", second, ps.ymax);
}
else if (!strcmp(second, "output"))
{
sscanf(third, "%d", &M.output);
fprintf(OUT, "\t%s\t%d\n", second, M.output);
}
else if (!strcmp(second, "flux"))
{
sscanf(third, "%d", &M.flux);
......
......@@ -50,6 +50,7 @@ void set_default()
M.iclean = 0;
M.cube = 0;
M.flux = 0; //by default does not conserve surface brightness
M.output=0;
M.restart = 0;
M.restart_seed = -4321;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment