Esempio n. 1
0
void set_refmap(string name)
{
  FITS *fitsfile;
  FLOAT tmpr, defval;
  int ndim = 3;
  int naxis[3], tmpi;
  int wcsaxes = -1;

  fitsfile = fitopen(name,"old",ndim,naxis);
  dprintf(0,"[Reading reference map %s [%d,%d,%d]\n",name,naxis[0],naxis[1],naxis[2]);

  /* set defaults according to Greisen & Calabretta 2002 WCS paper-I */
  defval = 1.0;
  fitrdhdr(fitsfile,"CDELT1",&ref_cdelt[0], defval);
  fitrdhdr(fitsfile,"CDELT2",&ref_cdelt[1], defval);
  fitrdhdr(fitsfile,"CDELT3",&ref_cdelt[2], defval);
  /* ieck; what if no CDELT's present, but all in CD matrix */

  defval = 0.0;
  fitrdhdr(fitsfile,"CRPIX1",&ref_crpix[0], defval);
  fitrdhdr(fitsfile,"CRPIX2",&ref_crpix[1], defval);
  fitrdhdr(fitsfile,"CRPIX3",&ref_crpix[2], defval);

  defval = 0.0;
  fitrdhdr(fitsfile,"CRVAL1",&ref_crval[0], defval);
  fitrdhdr(fitsfile,"CRVAL2",&ref_crval[1], defval);
  fitrdhdr(fitsfile,"CRVAL3",&ref_crval[2], defval);

  fitrdhda(fitsfile,"CTYPE1",ref_ctype[0],"");
  fitrdhda(fitsfile,"CTYPE2",ref_ctype[1],"");
  fitrdhda(fitsfile,"CTYPE3",ref_ctype[2],"");

  fitrdhda(fitsfile,"CUNIT1",ref_cunit[0],"");
  fitrdhda(fitsfile,"CUNIT2",ref_cunit[1],"");
  fitrdhda(fitsfile,"CUNUT3",ref_cunit[2],"");

  fitrdhdi(fitsfile,"WCSAXES",&wcsaxes, -1);
  if (wcsaxes != -1) warning("WCSAXES = %d\n",wcsaxes);

  fitclose(fitsfile);


}
Esempio n. 2
0
void make_fitheader(FITS *fitsfile, imageptr iptr, bool Qrel, bool Qout, int axistype,
		    FLOAT *data_min, FLOAT *data_max)
{
    int nz, tmpi, i, j;
    real crpix1, crpix2, crpix3;
    FLOAT tmpr, cd[3][3];
    char cdname[10], ctype[32];

    nz = Nz(iptr);

    fitrdhdr(fitsfile,"CRVAL1",&tmpr,0.0); Xmin(iptr) = tmpr;
    fitrdhdr(fitsfile,"CRVAL2",&tmpr,0.0); Ymin(iptr) = tmpr;
    fitrdhdr(fitsfile,"CRVAL3",&tmpr,0.0); Zmin(iptr) = tmpr;
    if (Qrel) {
      Xmin(iptr) = Ymin(iptr) = Zmin(iptr) = 0.0;
    }

    fitrdhdr(fitsfile,"CDELT1",&tmpr,1.0); Dx(iptr)=tmpr;
    fitrdhdr(fitsfile,"CDELT2",&tmpr,1.0); Dy(iptr)=tmpr;
    fitrdhdr(fitsfile,"CDELT3",&tmpr,1.0); Dz(iptr)=tmpr;
    for (i=1; i<=3; i++)
      for (j=1; j<=3; j++) {
	sprintf(cdname,"CD%d_%d",i,j);
	fitrdhdr(fitsfile,cdname,&tmpr, (i==j ? 1.0 : 0.0));
	dprintf(1,"%s: %g\n",cdname,tmpr); 
	cd[i-1][j-1] = tmpr;
      }
    if (fitexhd(fitsfile,"CD1_1")) {
      if (fitexhd(fitsfile,"CDELT1"))
	  warning("CDELT1 as well as CD_1_1 have been specified - using CD");
      Dx(iptr) = cd[0][0];      
      Dy(iptr) = cd[1][1];
      Dz(iptr) = cd[2][2];
    }
	
    fitrdhdr(fitsfile,"CRPIX1",&tmpr,1.0); crpix1 = tmpr;
    fitrdhdr(fitsfile,"CRPIX2",&tmpr,1.0); crpix2 = tmpr;
    if (nz>1) {
      fitrdhdr(fitsfile,"CRPIX3",&tmpr,1.0); crpix3 = tmpr;
    } else
      crpix3 = 0.0;

    if (!Qout) {
      print_axis(1, Nx(iptr), crpix1, Xmin(iptr), Dx(iptr));
      print_axis(2, Ny(iptr), crpix2, Ymin(iptr), Dy(iptr));
      print_axis(3, Nz(iptr), crpix3, Zmin(iptr), Dz(iptr));
      return;
    }

    if (axistype==0) {
      Axis(iptr) = 0;
      if (crpix1 != 1.0)
        Xmin(iptr) -= (crpix1-1.0)*Dx(iptr);
      if (crpix2 != 1.0)
        Ymin(iptr) -= (crpix2-1.0)*Dy(iptr);
      if (nz>1 && crpix3 != 1.0)
        Zmin(iptr) -= (crpix3-1.0)*Dz(iptr);
    } else if (axistype==1) {
      Axis(iptr) = 1;
      Xref(iptr) = crpix1-1;
      Yref(iptr) = crpix2-1;
      Zref(iptr) = crpix3-1;
    } else
      error("Illegal axistype=%d",axistype);

    fitrdhda(fitsfile,"CTYPE1",ctype,"");
    Namex(iptr) = scopy(ctype);

    fitrdhda(fitsfile,"CTYPE2",ctype,"");
    Namey(iptr) = scopy(ctype);

    if (nz>1) {
           fitrdhda(fitsfile,"CTYPE3",ctype,"");
	   Namez(iptr) = scopy(ctype);
    }


    fitrdhdr(fitsfile,"DATAMIN",&tmpr,0.0); 
    MapMin(iptr) = *data_min = tmpr;
    dprintf(1,"DATAMIN: %g %g\n",*data_min,MapMin(iptr));
    fitrdhdr(fitsfile,"DATAMAX",&tmpr,0.0); 
    MapMax(iptr) = *data_max = tmpr;
    dprintf(1,"DATAMAX: %g %g\n",*data_max,MapMax(iptr));
    if (fitexhd(fitsfile,"BLANK")) {
        dprintf(1,"BLANK keyword exists\n");
        fitrdhdi(fitsfile,"BITPIX",&tmpi,-1);
        if (tmpi<0) {
            warning("FITS keyword BLANK not interpreted - BITPIX<0");
        } else {
            fitrdhdi(fitsfile,"BLANK",&tmpi,0);
            dprintf(1,"BLANK = %d\n",tmpi);
        }
    }
}