コード例 #1
0
ファイル: image.c プロジェクト: jobovy/nemo
int sub_image (imageptr iptr, regionptr rptr, imageptr *optr)
{
  int nx,ny,nz, nx1,ny1,nz1, ix,iy,iz, ix0,iy0,iz0;
  size_t np, np1;

  nx  = Nx(iptr);
  ny  = Ny(iptr);
  nz  = Nz(iptr);
  np = nx*ny*nz;
  /* grab the bounding box */
  ix0 = BLC(rptr)[0];
  iy0 = BLC(rptr)[1];
  iz0 = BLC(rptr)[2];
  nx1 = TRC(rptr)[0] - ix0;
  ny1 = TRC(rptr)[1] - iy0;
  nz1 = TRC(rptr)[2] - iz0;
  np1 = nx1*ny1*nz1;

  *optr = (imageptr ) allocate(sizeof(image));
  dprintf (DLEV,"copy_image:Allocated image @ %d size=%d * %d * %d",*optr,nx1,ny1,nz1);
    	
  Frame(*optr) = (real *) allocate(np1*sizeof(real));	
  dprintf (DLEV,"Frame allocated @ %d ",Frame(*optr));
  Nx(*optr) = nx1;
  Ny(*optr) = ny1;
  Nz(*optr) = nz1;
  Xmin(*optr) = Xmin(iptr) + ix0*Dx(iptr);
  Ymin(*optr) = Ymin(iptr) + iy0*Dy(iptr);
  Zmin(*optr) = Zmin(iptr) + iz0*Dz(iptr);
  Dx(*optr) = Dx(iptr);
  Dy(*optr) = Dy(iptr);
  Dz(*optr) = Dz(iptr);
  Namex(*optr) = mystrcpy(Namex(iptr));
  Namey(*optr) = mystrcpy(Namey(iptr));
  Namez(*optr) = mystrcpy(Namez(iptr));
  Xref(*optr) = Xref(iptr) + ix0;
  Yref(*optr) = Yref(iptr) + iy0;
  Zref(*optr) = Zref(iptr) + iz0;
  for (iz=0; iz<nz1; iz++)
    for (iy=0; iy<ny1; iy++)
      for (ix=0; ix<nx1; ix++)
	CubeValue(*optr,ix,iy,iz) = CubeValue(iptr,ix-ix0,iy-iy0,iz-iy0);
  Storage(*optr) = matdef[idef];
  Axis(*optr) = Axis(iptr);
  set_iarray(*optr);
  
  return 1;		/* succes return code  */
}
コード例 #2
0
ファイル: ccdgen.c プロジェクト: Milkyway-at-home/nemo
local void object_ferrers(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  int l, lmax;
  real A = 1.0;   /* peak */
  real h = 1.0;   /* size */
  real e = 0.0;   /* 1-b/a */
  real b = 0.0;   /* phi */
  real p = 1.0;   /* power factor */
  real x1,y1,x2,y2,x3,y3,r,arg,value;
  real amp,phi,sum;
  real sinb,cosb;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  if (npar > 2) e = pars[2];
  if (npar > 3) b = pars[3];
  if (npar > 4) p = pars[4];
  dprintf(0,"ferrers: %g %g %g %g %g\n",A,h,e,b,p);

  if (A==0) return;

  lmax = Qtotflux ? 2 : 1;

  sinb = sin(b*PI/180.0);
  cosb = cos(b*PI/180.0);

  for (l=0; l<lmax; l++) {     /* 1st loop: sum up the flux   if in 2nd loop: normalize */
    if (l==0) 
      sum = 0.0;
    else {
      A /= sum;
      dprintf(0,"ferrers: A->%g\n",A);
    } 
    for (j=0; j<ny; j++) {
      y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
      for (i=0; i<nx; i++) {
	x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);
	
	x2 =  -x1*sinp - y1*cosp;
	y2 =  (x1*cosp - y1*sinp)/cosi;

	x3 =   x2*cosb - y2*sinb;
	y3 = (x2*sinb  + y2*cosb)/(1-e);

	r = (x3*x3+y3*y3)/(h*h);
	value = r < 1 ? A * pow(1.0-r, p) : 0.0;

	if (Qtotflux) {   
	  if (l==0) 
	    sum += value;
	  else
	    MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
	} else
	  MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
      } /* i */
    } /* j */
  } /* k */
}
コード例 #3
0
ファイル: ccdgen.c プロジェクト: Milkyway-at-home/nemo
local void object_gauss(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  real A = 1.0;
  real h = 1.0;
  real x1,y1,x2,y2,r,arg,value;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  dprintf(0,"gauss: %g %g\n",A,h);

  if (A==0) return;

  if (Qtotflux) {
    A /= (PI*h*h/surface);
    dprintf(0,"gauss: A->%g\n",A);
  }

  for (j=0; j<ny; j++) {
    y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
    for (i=0; i<nx; i++) {
      x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);
      x2 =  -x1*sinp - y1*cosp;
      y2 =   x1*cosp - y1*sinp;
      r = sqrt(x2*x2 + sqr(y2/cosi));
      arg = r/h;
      dprintf(2,"%d %d : %g %g %g %g   %g\n",i,j,x1,y1,x2,y2,arg);
      value = (arg < 13) ?  A * exp(-0.5*arg*arg) : 0.0;
      MapValue(iptr,i,j)  = factor*MapValue(iptr,i,j) + value;
    }
  }
}
コード例 #4
0
ファイル: image.c プロジェクト: jobovy/nemo
void ini_matrix(imageptr *iptr, int nx, int ny)
{
  int ix,iy;
	
  printf ("iptr @ %d    (sizeof = %d)\n",*iptr,sizeof(image));
	
  if (*iptr==0) {
    *iptr = (imageptr ) allocate((sizeof(image)));
    printf ("allocated image 'iptr' @ %d\n",*iptr);
    Frame(*iptr) = (real *) allocate (nx*ny*sizeof(real));
    printf ("Allocated frame @ %d\n",Frame(*iptr));
  } else {
    printf ("Image already allocated @ %d\n",*iptr);
    printf ("with Frame @ %d\n",Frame(*iptr));
  }
  Nx(*iptr) = nx;
  Ny(*iptr) = ny;
  Nz(*iptr) = 1;
  Xmin(*iptr) = 1.0;
  Ymin(*iptr) = 2.0;
  Zmin(*iptr) = 3.0;
  Dx(*iptr) = 0.1;
  Dy(*iptr) = 0.1;
  Dz(*iptr) = 0.1;
  Namex(*iptr) = NULL;        /* no axis names */
  Namey(*iptr) = NULL;
  Namez(*iptr) = NULL;
  Unit(*iptr)  = NULL;        /* no units */
  Mask(*iptr)  = NULL;

  set_iarray(*iptr);
  for (ix=0; ix<nx; ix++)
    for (iy=0; iy<ny; iy++)
      MapValue(*iptr,ix,iy)  = (ix*ny+iy)*0.1;
}
コード例 #5
0
ファイル: ccdplot.c プロジェクト: Milkyway-at-home/nemo
nemo_main()
{
  int n = 0;
  setparams();                    /* set globals */

  instr = stropen (infile, "r");
  plinit ("***", 0.0, 20.0, 0.0, 20.0);       /* init yapp */
  while (read_image(instr,&iptr)) {   /* loop while more images found */
    dprintf(1,"Time= %g MinMax= %g %g\n",Time(iptr),MapMin(iptr),MapMax(iptr));
    nx=Nx(iptr);			
    ny=Ny(iptr);
    nz=Nz(iptr);
    if (nz > 1) error("Cannot handle 3D images [%d,%d,%d]",nx,ny,nz);
    xmin=Xmin(iptr);
    ymin=Ymin(iptr);
    dx=Dx(iptr);
    dy=Dy(iptr);
    xsize = nx * dx;
    ysize = ny * dy;
    if (n>0) {
      sleep(1);
      plframe();
    }
    plot_map();                                 /* plot the map */
    n++;
  }
  plstop();                                   /* end of yapp */
  strclose(instr);
}
コード例 #6
0
ファイル: ccdsmooth.c プロジェクト: jobovy/nemo
void nemo_main ()
{
    setparams();			/* set par's in globals */

    instr = stropen (infile, "r");
    read_image (instr,&iptr);
				/* set some global paramters */
    nx = Nx(iptr);	
    ny = Ny(iptr);
    nz = Nz(iptr);
    xmin = Xmin(iptr);
    ymin = Ymin(iptr);
    zmin = Zmin(iptr);
    dx = Dx(iptr);
    dy = Dy(iptr);
    dz = Dz(iptr);

    if(hasvalue("gauss"))
        make_gauss_beam(getparam("dir"));

    outstr = stropen (outfile,"w");
    if (hasvalue("wiener"))
      wiener();
    else
      smooth_it();
    write_image (outstr,iptr);

    strclose(instr);
    strclose(outstr);
}
コード例 #7
0
ファイル: ccdgen.c プロジェクト: Milkyway-at-home/nemo
local void object_isothermal(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  int l, lmax;
  real A = 1.0;   /* peak */
  real h = 1.0;   /* size */
  real p = -0.5;  /* power factor */
  real x1,y1,x2,y2,x3,y3,r,arg,value;
  real amp,phi,sum;
  real sinb,cosb;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  if (npar > 2) p = pars[2];
  dprintf(0,"isothermal: %g %g %g \n",A,h,p);

  if (A==0) return;

  lmax = Qtotflux ? 2 : 1;

  for (l=0; l<lmax; l++) {     /* 1st loop: sum up the flux   if in 2nd loop: normalize */
    if (l==0) 
      sum = 0.0;
    else {
      A /= sum;
      dprintf(0,"isothermal: A->%g\n",A);
    } 
    for (j=0; j<ny; j++) {
      y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
      for (i=0; i<nx; i++) {
	x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);
	
	x2 =  -x1*sinp - y1*cosp;
	y2 =  (x1*cosp - y1*sinp)/cosi;

	r = (x2*x2+y2*y2)/(h*h);
	value = A * pow(1.0+r, p);

	if (Qtotflux) {   
	  if (l==0) 
	    sum += value;
	  else
	    MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
	} else
	  MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
      } /* i */
    } /* j */
  } /* k */
}
コード例 #8
0
ファイル: image.c プロジェクト: jobovy/nemo
int copy_image (imageptr iptr, imageptr *optr)
{
  int nx,ny,nz;
  size_t np;
  nx = Nx(iptr);
  ny = Ny(iptr);
  nz = Nz(iptr);
  np = nx*ny*nz;
  

  *optr = (imageptr ) allocate(sizeof(image));
  dprintf (DLEV,"copy_image:Allocated image @ %d size=%d * %d * %d",*optr,nx,ny,nz);
    	
  Frame(*optr) = (real *) allocate(np*sizeof(real));	
  dprintf (DLEV,"Frame allocated @ %d ",Frame(*optr));
  Nx(*optr) = nx;
  Ny(*optr) = ny;
  Nz(*optr) = nz;
  Xmin(*optr) = Xmin(iptr);
  Ymin(*optr) = Ymin(iptr);
  Zmin(*optr) = Zmin(iptr);
  Dx(*optr) = Dx(iptr);
  Dy(*optr) = Dy(iptr);
  Dz(*optr) = Dz(iptr);
  Namex(*optr) = mystrcpy(Namex(iptr));
  Namey(*optr) = mystrcpy(Namey(iptr));
  Namez(*optr) = mystrcpy(Namez(iptr));
  Xref(*optr) = Xref(iptr);
  Yref(*optr) = Yref(iptr);
  Zref(*optr) = Zref(iptr);
  Storage(*optr) = matdef[idef];
  Axis(*optr) = Axis(iptr);
  set_iarray(*optr);
  
  return 1;		/* succes return code  */
}
コード例 #9
0
ファイル: lacze_do_gnuplota.cpp プロジェクト: pmjoniak/zamp
std::string LaczeDoGNUPlota::ZapiszUstawienieZakresu(char Os) const
{
  ostringstream strm;
  float Min, Max;

  switch (Os) {
   case 'x':  Min = Xmin();  Max = Xmax();  break;
   case 'y':  Min = Ymin();  Max = Ymax();  break;
   case 'z':  Min = Zmin();  Max = Zmax();  break;
   default: cerr << "!!! Blad w 'ZapiszUstawienieZakresu' niedozwolony"
                    " znak: " << Os << endl;
            return "";
  }
  strm << "set " << Os << "range [" <<  Min << ":" << Max << "]\n";
  return strm.str();
}
コード例 #10
0
ファイル: image.c プロジェクト: jobovy/nemo
int write_image (stream outstr, imageptr iptr)
{
  put_history(outstr);
  put_set (outstr,ImageTag);
    put_set (outstr,ParametersTag);
      put_data (outstr,NxTag,  IntType,  &(Nx(iptr)),   0);
      put_data (outstr,NyTag,  IntType,  &(Ny(iptr)),   0);
      put_data (outstr,NzTag,  IntType,  &(Nz(iptr)),   0);
      put_data (outstr,XminTag,RealType, &(Xmin(iptr)), 0);
      put_data (outstr,YminTag,RealType, &(Ymin(iptr)), 0);
      put_data (outstr,ZminTag,RealType, &(Zmin(iptr)), 0);
      put_data (outstr,DxTag,  RealType, &(Dx(iptr)),   0);
      put_data (outstr,DyTag,  RealType, &(Dy(iptr)),   0);
      put_data (outstr,DzTag,  RealType, &(Dz(iptr)),   0);
      put_data (outstr,XrefTag,RealType, &(Xref(iptr)), 0);
      put_data (outstr,YrefTag,RealType, &(Yref(iptr)), 0);
      put_data (outstr,ZrefTag,RealType, &(Zref(iptr)), 0);
      put_data (outstr,MapMinTag, RealType, &(MapMin(iptr)), 0);
      put_data (outstr,MapMaxTag, RealType, &(MapMax(iptr)), 0);
      put_data (outstr,BeamTypeTag, IntType, &(BeamType(iptr)), 0);
      put_data (outstr,BeamxTag, RealType, &(Beamx(iptr)), 0);
      put_data (outstr,BeamyTag, RealType, &(Beamy(iptr)), 0);
      put_data (outstr,BeamzTag, RealType, &(Beamz(iptr)), 0);
      if (Namex(iptr))
         put_string (outstr,NamexTag,Namex(iptr));
      if (Namey(iptr))
         put_string (outstr,NameyTag,Namey(iptr));
      if (Namez(iptr))
         put_string (outstr,NamezTag,Namez(iptr));
      if (Unit(iptr))
         put_string (outstr,UnitTag,Unit(iptr));
      put_data (outstr,TimeTag,  RealType, &(Time(iptr)), 0);
      put_string(outstr,StorageTag,matdef[idef]);
      put_data (outstr,AxisTag,  IntType, &(Axis(iptr)), 0);
    put_tes (outstr, ParametersTag);
         
    put_set (outstr,MapTag);
    if (Nz(iptr)==1)
      put_data (outstr,MapValuesTag,RealType,
		Frame(iptr),Nx(iptr),Ny(iptr),0);
    else
      put_data (outstr,MapValuesTag,RealType,
		Frame(iptr),Nx(iptr),Ny(iptr),Nz(iptr),0);
    put_tes (outstr, MapTag);
  put_tes (outstr, ImageTag);
  return 1;
}
コード例 #11
0
ファイル: ccdgen.c プロジェクト: Milkyway-at-home/nemo
local void object_bar(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  real A = 1.0;
  real h = 1.0;
  real e = 0.0;
  real b = 0.0;
  real x1,y1,x2,y2,x3,y3,r,arg,value;
  real sinb,cosb,omba;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  if (npar > 2) e = pars[2];
  if (npar > 3) b = pars[3];
  dprintf(0,"bar: %g %g %g %g\n",A,h,e,b);

  sinb = sin(b*PI/180.0);
  cosb = cos(b*PI/180.0);

  if (A==0) return;

  if (Qtotflux) {
    A /= (PI*h*h*(1-e)/surface);
    dprintf(0,"bar: A->%g\n",A);
  }
  dprintf(1,"bar b=%g\n",b);

  for (j=0; j<ny; j++) {
    y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
    for (i=0; i<nx; i++) {
      x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);

      x2 =  -x1*sinp - y1*cosp;
      y2 =   (x1*cosp - y1*sinp)/cosi;

      x3 =   x2*cosb - y2*sinb;
      y3 = (x2*sinb  + y2*cosb)/(1-e);

      r = sqrt(x3*x3+y3*y3);
      arg = r/h;
      value = (arg < 100) ? A * exp(-arg) : 0.0;
      MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
    }
  }
}
コード例 #12
0
ファイル: snappat.c プロジェクト: Milkyway-at-home/nemo
void fixheader(imageptr iptr, string options, real t0, real dt)
{
  char *ap = allocate(sizeof(options) + sizeof("Attribute") + 10);
  sprintf(ap,"Attribute: %s",options);

  Namex(iptr) = strdup("Particle");
  Xmin(iptr)  = 0.0;
  Dx(iptr)    = 1.0;

  Namey(iptr) = strdup(ap);
  Ymin(iptr)  = 0.0;
  Dy(iptr)    = 1.0;

  Namez(iptr) = strdup("Time");
  Zmin(iptr)  = t0;
  Dz(iptr)    = dt;

  free(ap);
}
コード例 #13
0
ファイル: image.c プロジェクト: jobovy/nemo
/*
 * CREATE_CUBE: create a blank cube Nx by Ny by Nz in size
 */
int create_cube (imageptr *iptr, int nx, int ny, int nz)
{
    *iptr = (imageptr ) allocate(sizeof(image));
    dprintf (DLEV,"CREATE_CUBE: Allocated image @ cube %d size=%d * %d * %d",
		*iptr,nx,ny,nz);
    if (*iptr == NULL)
	return 0;	/* no memory available */
    	
    Frame(*iptr) = (real *) allocate(nx*ny*nz*sizeof(real));	
    dprintf (DLEV,"Frame allocated @ %d ",Frame(*iptr));
    Nx(*iptr) = nx;             /* cube dimension */
    Ny(*iptr) = ny;
    Nz(*iptr) = nz;
    Xmin(*iptr) = 0.0;          /* start lower left corner at 0.0 */
    Ymin(*iptr) = 0.0;
    Zmin(*iptr) = 0.0;
    Xref(*iptr) = 0.0;
    Yref(*iptr) = 0.0;
    Zref(*iptr) = 0.0;
    Dx(*iptr) = 1.0;            /* unity pixels */
    Dy(*iptr) = 1.0;
    Dz(*iptr) = 1.0;
    MapMin(*iptr) = 0.0;
    MapMax(*iptr) = 0.0;
    BeamType(*iptr) = 0;
    Beamx(*iptr) = 0.0;         /* name beams */
    Beamy(*iptr) = 0.0;
    Beamz(*iptr) = 0.0;
    Namex(*iptr) = NULL;        /* no axis names yet */
    Namey(*iptr) = NULL;
    Namez(*iptr) = NULL;
    Unit(*iptr)  = NULL;        /* no units */
    Time(*iptr)  = 0.0;
    Storage(*iptr) = matdef[idef];
    Axis(*iptr) = 0;
    Mask(*iptr) = NULL;
    set_iarray(*iptr);
    
    return 1;		/* succes return code  */
}
コード例 #14
0
ファイル: image.c プロジェクト: jobovy/nemo
int create_image (imageptr *iptr, int nx, int ny)
{
    *iptr = (imageptr ) allocate(sizeof(image));
    dprintf (DLEV,"create_image:Allocated image @ %d size=%d * %d",*iptr,nx,ny);
    Frame(*iptr) = (real *) allocate(nx*ny*sizeof(real));	
    dprintf (DLEV,"Frame allocated @ %d ",Frame(*iptr));
    Axis(*iptr) = 0;            /* old style axis with no reference pixel */
    Nx(*iptr) = nx;             /* old style ONE map, no cube */
    Ny(*iptr) = ny;
    Nz(*iptr) = 1;
    Xmin(*iptr) = 0.0;          /* start lower left corner at 0.0 */
    Ymin(*iptr) = 0.0;
    Zmin(*iptr) = 0.0;
    Dx(*iptr) = 1.0;            /* unity pixels */
    Dy(*iptr) = 1.0;
    Dz(*iptr) = 1.0;
    Xref(*iptr) = 0.0;
    Yref(*iptr) = 0.0;
    Zref(*iptr) = 0.0;
    MapMin(*iptr) = 0.0;
    MapMax(*iptr) = 0.0;
    BeamType(*iptr) = 0;
    Beamx(*iptr) = 0.0;         /* name beams */
    Beamy(*iptr) = 0.0;
    Beamz(*iptr) = 0.0;
    Namex(*iptr) = NULL;        /* no axis names */
    Namey(*iptr) = NULL;
    Namez(*iptr) = NULL;
    Unit(*iptr)  = NULL;        /* no units */
    Time(*iptr)  = 0.0;
    Storage(*iptr) = matdef[idef];
    Axis(*iptr) = 0;
    Mask(*iptr) = NULL;
    set_iarray((*iptr));

    return 1;		/* succes return code  */
}
コード例 #15
0
ファイル: fitsccd.c プロジェクト: sussea/NEMO_caustics
void make_rawheader(FITS *fitsfile, imageptr iptr, bool Qrel)
{
    int ndim, n;
    double tmpr[3];
    
    ndim = (Nz(iptr) > 1) ? 3 : 2;

    n = nemoinpd(getparam("cdelt"),tmpr,3);
    if (n == 0) {
        Dx(iptr) = 2.0/Nx(iptr);
        Dy(iptr) = 2.0/Ny(iptr);
        Dz(iptr) = 2.0/Nz(iptr);
    } else if (n == 3) {
        Dx(iptr) = tmpr[0];
        Dy(iptr) = tmpr[1];
        Dz(iptr) = tmpr[2];
    } else
        error("cdelt= needs either 3 or 0 entries");

    Xmin(iptr) = 0.0;
    Ymin(iptr) = 0.0;
    Zmin(iptr) = 0.0;

}
コード例 #16
0
ファイル: ccdplot.c プロジェクト: Milkyway-at-home/nemo
plot_map ()
{
    real m_range, brightness, dcm;
    real m_min, m_max;
    int    i, ix, iy;
    int    cnt;		/* counter of pixels */

    nsize = Nx(iptr);  /* old method forced square .. */			
    cell = Dx(iptr);   /* and forced so for gray scale due to LW mem-problems */
    size = nsize*cell;
    
    m_min = MapMin(iptr);	/* get min- and max from header */
    m_max = MapMax(iptr);
    dprintf (1,"Min and max in map from map-header are: %f %f\n",m_min,m_max);
 
    if (mmax==UNDEF)	/* reset default autoscales to user supplied if necessary */
	mmax=m_max;
    if (mmin==UNDEF)
    	mmin=m_min;
    m_range = mmax-mmin;
    if (m_range==0) {
    	mmax=mmin+1.0;
	if (gray) warning("%g; Plot-range was zero, mmax increased by 1",mmin);
    }
        
    dprintf (1,"User reset Min and max are: %f %f\n",mmin,mmax);

    
    sprintf (plabel,"File: %s",infile);			/* filename */
    sprintf (clabel,"Contours: %s",cntstr);             /* contour levels */
    sprintf (glabel,"Gray MinMax: %g %g",mmin,mmax);    /* grey scale minmax */
    sprintf (tlabel,"Time: %g",Time(iptr));             /* time of orig snapshot */

	/* set scales and labels along axes */
    if (xplot[0]==UNDEF || xplot[1]==UNDEF) {
    	xplot[0] = Xmin(iptr) - 0.5*Dx(iptr);
    	xplot[1] = xplot[0] + Nx(iptr)*Dx(iptr);
    }
    if (Namex(iptr))
        strncpy(xlabel,Namex(iptr),80);
    else
        strcpy (xlabel,"");

    if (yplot[0]==UNDEF || yplot[1]==UNDEF) {
    	yplot[0] = Ymin(iptr) - 0.5*Dy(iptr);
    	yplot[1] = yplot[0] + Ny(iptr)*Dy(iptr);
    }
    if (Namey(iptr))
        strncpy(ylabel,Namey(iptr),80);
    else
        strcpy (ylabel,"");
	
    dprintf (1,"Plotting area x=%f:%f y=%f:%f\n",
    	xplot[0], xplot[1], yplot[0], yplot[1]);

    if (gray) {		
				/* gray-scale */
       dcm = Dx(iptr) / (xplot[1]-xplot[0]) * 16.0;
       pl_matrix (Frame(iptr), nx, ny, 
		  xtrans(Xmin(iptr)), ytrans(Ymin(iptr)), dcm , mmin, mmax, power, blankval);
           /*  color_bar (100.0,500.0,32);  */
     } 
     		/* OLD ROUTINE, has to call relocate/frame ---> plcontour */
     plltype(lwidth,ltype);
     if (cmode==0) 
        contour (Frame(iptr),nx,ny,cntval,ncntval,
		Xmin(iptr), 
		Ymin(iptr), 
		Xmin(iptr)+(Nx(iptr)-1)*Dx(iptr),
		Ymin(iptr)+(Ny(iptr)-1)*Dy(iptr), lineto);
    
     else if (cmode==1)
         pl_contour (Frame(iptr),nx,ny,ncntval,cntval);
     plltype(1,1);

	/* draw axes and their labels */
    xaxis ( 2.0, 2.0, 16.0, xplot, -7, xtrans,  xlabel);
    xaxis ( 2.0,18.0, 16.0, xplot, -7, xtrans,  NULL);
    yaxis ( 2.0, 2.0, 16.0, yplot, -7, ytrans, ylabel);
    yaxis (18.0, 2.0, 16.0, yplot, -7, ytrans, NULL);

    pltext (plabel,2.0,18.4, 0.32, 0.0);	/* plot header with file name */
    pltext (clabel,2.0,19.0, 0.32, 0.0);        /* plot header with contour levels */
    pltext (glabel,2.0,19.6, 0.32, 0.0);        /* plot header with greyscale info */
    pltext (tlabel,10.0,19.6,0.32, 0.0);        /* time info */

    pljust(1);
    pltext (headline,10.0,18.4, 0.26, 0.0);     /* plot extra user suplied header */
    pljust(-1);
}
コード例 #17
0
ファイル: ccdmerge.c プロジェクト: Milkyway-at-home/nemo
void nemo_main()
{
    stream  instr, outstr;
    int     nx, ny, nz;        /* size of scratch map */
    int     nx1, ny1, nz1, nz2;
    int     ni, i, ix, iy, iz, iz1;
    real    dmin, dmax;
    imageptr iptr[MAXIM], optr;        /* pointer to image */
    string  flipmode;

    instr = stropen(getparam("in"), "r");
    outstr = stropen(getparam("out"), "w");

    for (i=0; i<MAXIM; i++) {               /* loop over all to gather data */
      iptr[i] = 0;
      if (read_image( instr, &iptr[i]) == 0) break;
      nx1 = Nx(iptr[i]);	
      ny1 = Ny(iptr[i]);
      nz1 = Nz(iptr[i]);
      dprintf(1,"Image %d: %d x %d x %d\n",i,nx1,ny1,nz1);
      if (i==0) {
	nx = nx1;
	ny = ny1;
	nz = nz1;
	dmin = MapMin(iptr[i]);
	dmax = MapMax(iptr[i]);
      } else {
	if (nx != nx1) error("size nx: %d != %d",nx,nx1);
	if (ny != ny1) error("size ny: %d != %d",ny,ny1);
	nz += nz1;
	dmin = MIN(dmin,MapMin(iptr[i]));
	dmax = MAX(dmax,MapMax(iptr[i]));
      }
    }
    ni = i;
    dprintf(0,"Final cube: %d x %d x %d\n",nx,ny,nz);
    dprintf(0,"Data min/max: %g %g\n",dmin,dmax);
    create_cube(&optr,nx,ny,nz);
    MapMin(optr) = dmin;
    MapMax(optr) = dmax;
    Xmin(optr) = Xmin(iptr[0]);
    Ymin(optr) = Ymin(iptr[0]);
    Zmin(optr) = Zmin(iptr[0]);
    Xref(optr) = Xref(iptr[0]);
    Yref(optr) = Yref(iptr[0]);
    Zref(optr) = Zref(iptr[0]);
    Dx(optr) = Dx(iptr[0]);
    Dy(optr) = Dy(iptr[0]);
    Dz(optr) = Dz(iptr[0]);

    for (i=0, iz=0; i<ni; i++) {       /* grab all data in output cube */
      nz1 = Nz(iptr[i]);
      for (iz1=0; iz1< nz1; iz1++, iz++) {
	for (iy=0; iy<ny; iy++) {
	  for (ix=0; ix<nx; ix++) {
	    CubeValue(optr,ix,iy,iz) = CubeValue(iptr[i],ix,iy,iz1);
	  }
	}
      }
    }

    write_image(outstr, optr);
}
コード例 #18
0
ファイル: fitsccd.c プロジェクト: sussea/NEMO_caustics
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);
        }
    }
}
コード例 #19
0
ファイル: velcube.c プロジェクト: Milkyway-at-home/nemo
/*
 * create a velocity field (GIPSY method)
 *              0..nx-1 and 0..ny-1 
 *      start from pixel, work back to gal plane and interpolate
 *      (a.k.a. retracing method)
 *
 */
local void cube_create(stream outstr)
{
  int  i, j, k, n, nx, ny;
  real m_min, m_max, sum;
  real den, vel, sig, velk, x;
  imageptr vptr;
  real f = 4.0;
  
  m_min = HUGE; m_max = -HUGE;
  nx = Nx(velptr);
  ny = Ny(velptr);
  
  if (!create_cube(&vptr, nx, ny, nz))   /* output data cube */
    error("Could not create cube from scratch");
  
  for (j=0; j<ny; j++)            /* Loop over all pixels */
    for (i=0; i<nx; i++) {
      for (k=0; k<nz; k++)
	CubeValue(vptr,i,j,k) = undef;       /* first set all to 'undefined' */
      sum = 0.0;
      vel = MapValue(velptr,i,j);

      if (denptr) {
	den = MapValue(denptr,i,j);
	if (den <= 0.0) continue;
      } else
	den = 1.0;

      if (sigptr) {
	sig = MapValue(sigptr,i,j);
	if (sig < 0.0) continue;
      } else
	sig = sigdef;
      if (sig == 0.0) {      /* special case, only populate 1 cell */
	k = (int) floor(    (vel-zrange[0])/zrange[2]   );
	if (k<0 || k>nz-1) continue;
	CubeValue(vptr,i,j,k) = den;
	sum = den;
      } else {               /* else use a gaussian profile */
	for (k=0, velk=zrange[0]+0.5*zrange[2]; k<nz; k++, velk += zrange[2]) {
	  x = (velk-vel)/sig;
	  x = ABS(x);
	  if (x > f) continue;
	  CubeValue(vptr,i,j,k) = den * exp(-0.5*x*x);
	  sum += CubeValue(vptr,i,j,k);
	}
      }
      sum = den/sum;              /* now normalize the spectrum so the sum is 'den' */
      for (k=0; k<nz; k++) {
	if (CubeValue(vptr,i,j,k) != undef)
	  CubeValue(vptr,i,j,k) *= sum;
      }
    }
      
  n=0;
  for (k=0; k<nz; k++)        /* get min and max in map */
    for (j=0; j<ny; j++)
      for (i=0; i<nx; i++) 
	if (CubeValue(vptr,i,j,k) != undef) {
	  m_min = MIN(CubeValue(vptr,i,j,k),m_min);
	  m_max = MAX(CubeValue(vptr,i,j,k),m_max);
	} else
	  n++;
  MapMin(vptr) = m_min;
  MapMax(vptr) = m_max;
  Dx(vptr) = Dx(velptr);
  Dy(vptr) = Dy(velptr);
  Dz(vptr) = zrange[2];
  Xmin(vptr) = Xmin(velptr);
  Ymin(vptr) = Ymin(velptr);
  Zmin(vptr) = zrange[0];
  
  if (n>0) warning("%d/%d cells with no signal",n,nx*ny*nz);
  printf("Min and max in map: %g %g\n",m_min,m_max);
  write_image (outstr,vptr);  
}
コード例 #20
0
ファイル: ccdrt.c プロジェクト: jobovy/nemo
void nemo_main()
{
    stream  instr, outstr;
    int     nx, ny, nz, nx1, ny1, nz1;
    int     axis, mom;
    int     i,j,k, apeak, cnt;
    imageptr iptr=NULL, iptr1=NULL, iptr2=NULL;      /* pointer to images */
    real    tmp0, tmp1, tmp2, tmp00, newvalue, peakvalue, scale, offset;
    bool    Qpeak;

    instr = stropen(getparam("in"), "r");
    mom = 0;
    axis = 3;
    Qpeak = getbparam("peak");

    read_image( instr, &iptr);

    nx1 = nx = Nx(iptr);	
    ny1 = ny = Ny(iptr);
    nz1 = 1;
    nz  = Nz(iptr);

    outstr = stropen(getparam("out"), "w");

    create_cube(&iptr1,nx1,ny1,nz1);
    create_cube(&iptr2,nx1,ny1,nz1);


    scale = Dz(iptr);
    offset = Zmin(iptr);
    for(j=0; j<ny; j++)
      for(i=0; i<nx; i++) {
	tmp0 = tmp00 = tmp1 = tmp2 = 0.0;
	cnt = 0;
	peakvalue = CubeValue(iptr,i,j,0);
	for(k=0; k<nz; k++) {
	  if (out_of_range(CubeValue(iptr,i,j,k))) continue;
	  cnt++;
	  tmp0 += CubeValue(iptr,i,j,k);
	  tmp00 += sqr(CubeValue(iptr,i,j,k));
	  if (CubeValue(iptr,i,j,k) > peakvalue) {
	    apeak = k;
	    peakvalue = CubeValue(iptr,i,j,k);
	  }
	}
	if (cnt==0 || tmp0==0.0) {
	  newvalue = 0.0;
	} else {
	  if (Qpeak) 
	    newvalue = peakvalue;
	  else
	    newvalue = tmp0;
	}
	CubeValue(iptr1,i,j,1) = newvalue;
      }
    
     
    Xmin(iptr1) = Xmin(iptr);
    Ymin(iptr1) = Ymin(iptr);
    Zmin(iptr1) = Zmin(iptr) + 0.5*(nz-1)*Dz(iptr);
    Dx(iptr1) = Dx(iptr);
    Dy(iptr1) = Dy(iptr);
    Dz(iptr1) = nz * Dz(iptr);
    
    Namex(iptr1) = Namex(iptr); /* care: we're passing a pointer */
    Namey(iptr1) = Namey(iptr);
    Namez(iptr1) = Namez(iptr);
    
    write_image(outstr, iptr1);
}
コード例 #21
0
ファイル: condinit.c プロジェクト: adamdempsey90/fargo3d
void InitVazimPlanet() {

  int i,j,k;
  real *field;
  real dr, dz;
  real r, z, H, r0, rho_o, t;
  real rho;
  FILE *fo;
  real vt, omega;
  real *vr;
  real *cs;
  real md0,nuind,nu0;
  real vr0, fac1, fac2;
  field = Vx->field_cpu;
  vr = Vy->field_cpu;
  cs = Energy->field_cpu;

  boolean GhostInclude = TRUE;
  nuind = 0.5+2*FLARINGINDEX;
  nu0 = ALPHA*ASPECTRATIO*ASPECTRATIO;

  int begin_k =(GhostInclude ? 0 : NGHZ);
  int end_k = Nz+2*NGHZ-begin_k;
  int begin_j =(GhostInclude ? 0 : NGHY);
  int end_j = Ny+2*NGHY-begin_j;
  int begin_i = (GhostInclude ? 0 : NGHX);
  int end_i = Nx+2*NGHX-begin_i;

  for (k = begin_k; k<end_k; k++) {
    for (j = begin_j; j<end_j; j++) {
       r = Ymed(j);

   //     vr0=-1.5*nu0*pow(r,nuind);
   //     fac1 = pow(YMAX,.5-nuind)*SIGMAIN*YMIN-pow(YMIN,.5-nuind)*SIGMAOUT*YMAX;
   //
   //     fac2 = fac1 + (-pow(YMAX,1-nuind)*SIGMAIN*YMIN+pow(YMIN,1-nuind)*SIGMAOUT*YMAX)/sqrt(r);


//        fac1=SIGMAOUT*YMAX/r-SIGMAIN*YMIN/r;
//        fac1 /= (sqrt(YMAX) - sqrt(YMIN));
//        fac2 = SIGMAIN*YMIN/r + fac1*(sqrt(r)-sqrt(YMIN));
//        md0 = 1.5*nu0*fac1;

        fac1 = -1.5 * nu0 * pow(r,nuind-1);

      for (i = begin_i; i<end_i; i++) {

	omega = sqrt(G*MSTAR/r/r/r);
	vt = omega*r*sqrt(1.0+pow(ASPECTRATIO,2)*pow(r/R0,2*FLARINGINDEX)*
			  (2.0*FLARINGINDEX - 1.0 - SIGMASLOPE));

	vt -= OMEGAFRAME*r;

	field[l] = vt*(1.+ASPECTRATIO*NOISE*(drand48()-.5));
	//vr[l] = r*omega*ASPECTRATIO*NOISE*(drand48()-.5);
//    vr[l] = -1.5*ALPHA*ASPECTRATIO*ASPECTRATIO*pow(r,-0.5+2*FLARINGINDEX);
    vr[l] = -1.5 * ALPHA*ASPECTRATIO*ASPECTRATIO*pow(Ymin(j),2*FLARINGINDEX-0.5);
      }
    }
  }
}
コード例 #22
0
ファイル: xyio.c プロジェクト: jobovy/nemo
image *xyopen(int *handle, string name, string status, int naxis, int *axes)
{
    int i, access;
    string read_matdef;
    image *iptr;
    stream str;

    if(naxis>MAXNAXIS) 
        error("naxis=%d not supported: MAXNAXIS=%d",naxis, MAXNAXIS);

    if (first) xy_init();

    str = stropen(name,status);                       /* open file */
    switch (*status) {
        case 'r':               /* "r", "old" */
        case 'o':
            access = GET;
            break;
        case 'w':               /* "w", "new" */
        case 'n':
            access = PUT;
            break;
        default:
            error("xyopen: Unsupported mode %s",status);
    }
    iptr = (imageptr )allocate(sizeof(image));  /* new image */

    if(access == GET){
      get_history(str);
      get_set (str,ImageTag);
        get_set (str,ParametersTag);
          get_data (str,NxTag,IntType, &(Nx(iptr)), 0);
          get_data (str,NyTag,IntType, &(Ny(iptr)), 0);
          get_data (str,NzTag,IntType, &(Nz(iptr)), 0);
          get_data_coerced (str,XminTag,RealType, &(Xmin(iptr)), 0);
          get_data_coerced (str,YminTag,RealType, &(Ymin(iptr)), 0);
          get_data_coerced (str,ZminTag,RealType, &(Zmin(iptr)), 0);
          get_data_coerced (str,DxTag,RealType, &(Dx(iptr)), 0);
          get_data_coerced (str,DyTag,RealType, &(Dy(iptr)), 0);
          get_data_coerced (str,DzTag,RealType, &(Dz(iptr)), 0);
	  get_data_coerced (str,MapMinTag, RealType, &(MapMin(iptr)), 0);
	  get_data_coerced (str,MapMaxTag, RealType, &(MapMax(iptr)), 0);
	  get_data (str,BeamTypeTag, IntType, &(BeamType(iptr)), 0);
	  get_data_coerced (str,BeamxTag, RealType, &(Beamx(iptr)), 0);
	  get_data_coerced (str,BeamyTag, RealType, &(Beamy(iptr)), 0);
	  get_data_coerced (str,BeamzTag, RealType, &(Beamz(iptr)), 0);
          if (get_tag_ok(str,NamexTag))             /* X-axis name */
            Namex(iptr) = get_string(str,NamexTag);
          else
            Namex(iptr) = NULL;
          if (get_tag_ok(str,NameyTag))             /* Y-axis name */
            Namey(iptr) = get_string(str,NameyTag);
          else
            Namey(iptr) = NULL;
          if (get_tag_ok(str,NamezTag))             /* Z-axis name */
            Namez(iptr) = get_string(str,NamezTag);
          else
            Namez(iptr) = NULL;
          if (get_tag_ok(str,UnitTag))             /* units  */
            Unit(iptr) = get_string(str,UnitTag);
          else
            Unit(iptr) = NULL;
          read_matdef = get_string(str,StorageTag);
	  if (!streq(read_matdef,matdef[idef]))
             dprintf(0,"read_image: StorageTag = %s, compiled with %s\n",
		        read_matdef, matdef[idef]);
        get_tes(str,ParametersTag);
        get_set(str,MapTag);
        if(Nz(iptr)<=1)
            get_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),0);
        else
            get_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),Nz(iptr),0);
        for (i=0; i<naxis; i++) axes[i] = 1;
        axes[0] = Nx(iptr); axes[1] = Ny(iptr); axes[2] = Nz(iptr);
    } else { /* PUT */
      Nx(iptr) = Ny(iptr) = Nz(iptr) = 1;
      if (naxis>0) Nx(iptr)  = axes[0];
      if (naxis>1) Ny(iptr)  = axes[1];
      if (naxis>2) Nz(iptr)  = axes[2];

      put_history(str);
      put_set (str,ImageTag);
        put_set (str,ParametersTag);
          put_data (str,NxTag,  IntType,  &(Nx(iptr)),   0);
          put_data (str,NyTag,  IntType,  &(Ny(iptr)),   0);
          put_data (str,NzTag,  IntType,  &(Nz(iptr)),   0);
          put_data (str,XminTag,RealType, &(Xmin(iptr)), 0);
          put_data (str,YminTag,RealType, &(Ymin(iptr)), 0);
          put_data (str,ZminTag,RealType, &(Zmin(iptr)), 0);
          put_data (str,DxTag,  RealType, &(Dx(iptr)),   0);
          put_data (str,DyTag,  RealType, &(Dy(iptr)),   0);
          put_data (str,DzTag,  RealType, &(Dz(iptr)),   0);
          put_data (str,MapMinTag, RealType, &(MapMin(iptr)), 0);
          put_data (str,MapMaxTag, RealType, &(MapMax(iptr)), 0);
          put_data (str,BeamTypeTag, IntType, &(BeamType(iptr)), 0);
          put_data (str,BeamxTag, RealType, &(Beamx(iptr)), 0);
          put_data (str,BeamyTag, RealType, &(Beamy(iptr)), 0);
          put_data (str,BeamzTag, RealType, &(Beamz(iptr)), 0);
          if (Namex(iptr))
            put_string (str,NamexTag,Namex(iptr));
          if (Namey(iptr))
            put_string (str,NameyTag,Namey(iptr));
          if (Namez(iptr))
            put_string (str,NamezTag,Namez(iptr));
      	  if (Unit(iptr))
            put_string (str,UnitTag,Unit(iptr));
          put_string(str,StorageTag,matdef[idef]);
        put_tes(str, ParametersTag);
        put_set(str, MapTag);
        if(Nz(iptr)<=1)
          put_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),0);
        else
          put_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),Nz(iptr),0);
    }

    *handle = -1;
    for(i=0; i<MAXOPEN; i++) {        /* look for a new table entry */
      if(images[i].str == NULL) *handle = i;
    }
    if(*handle < 0) 
        error("xyopen: No more free slots; too many open images");
    for (i=0; i<MAXNAXIS; i++)
        images[*handle].axes[i] = 1;

    images[*handle].str     = str;
    images[*handle].iptr    = iptr;
    images[*handle].offset  = 0;
    images[*handle].access  = access;
    images[*handle].naxis   = (Nz(iptr)<=1 ? 2 : 3);
    images[*handle].axes[0] = Nx(iptr);
    images[*handle].axes[1] = Ny(iptr);
    images[*handle].axes[2] = Nz(iptr);

    return iptr;
}
コード例 #23
0
ファイル: ccdfits.c プロジェクト: Milkyway-at-home/nemo
void write_fits(string name,imageptr iptr)
{
    FLOAT tmpr,xmin[3],xref[3],dx[3],mapmin,mapmax;   /* fitsio FLOAT !!! */
    FITS *fitsfile;
    char *cp, origin[80];
    string *hitem, axname[3];
    float *buffer, *bp;
    int i, j, k, axistype, bitpix, keepaxis[3], nx[3], p[3], nx_out[3], ndim=3;
    double bscale, bzero;
    
    if (hasvalue("ndim")) ndim = getiparam("ndim");
    nx[0] = Nx(iptr);
    nx[1] = Ny(iptr);
    nx[2] = Nz(iptr);   if (nx[2] <= 0) nx[2] = 1;
    xmin[0] = Xmin(iptr)*scale[0];
    xmin[1] = Ymin(iptr)*scale[1];
    xmin[2] = Zmin(iptr)*scale[2];
    dx[0] = Dx(iptr)*scale[0];
    dx[1] = Dy(iptr)*scale[1];
    dx[2] = Dz(iptr)*scale[2];
    xref[0] = Xref(iptr)+1.0;
    xref[1] = Yref(iptr)+1.0;
    xref[2] = Zref(iptr)+1.0;
    axistype = Axis(iptr);
    axname[0] = (Namex(iptr) ? Namex(iptr) : xyz[0]);
    axname[1] = (Namey(iptr) ? Namey(iptr) : xyz[1]);
    axname[2] = (Namez(iptr) ? Namez(iptr) : xyz[2]);
    mapmin = MapMin(iptr);
    mapmax = MapMax(iptr);
    if (Qdummy) 
      for (i=0; i<3; i++) p[i] = i;
    else {
      if (Qrefmap) warning("dummy=f and usage of refmap will result in bad headers");
      permute(nx,p,3);
      dprintf(0,"Reordering axes: %d %d %d\n",p[0],p[1],p[2]);
    }
#if 1
    for (i=0; i<3; i++)  nx_out[i] = nx[p[i]];
    /* fix this so CubeValue works */
    Nx(iptr) = nx_out[0];
    Ny(iptr) = nx_out[1];
    Nz(iptr) = nx_out[2];
#else
    for (i=0; i<3; i++)  nx_out[i] = nx[i];
#endif
    sprintf(origin,"NEMO ccdfits %s",getparam("VERSION"));

    dprintf(1,"NEMO Image file written to FITS disk file\n");
    dprintf(1,"%d %d %d   %f %f %f   %f %f %f  %f %f %f   %f %f \n",
	    nx[0],nx[1],nx[2],xmin[0],xmin[1],xmin[2],dx[0],dx[1],dx[2],xref[0],xref[1],xref[2],
	    mapmin,mapmax);
    dprintf(1,"keepaxis(%d,%d,%d)\n",keepaxis[0],keepaxis[1],keepaxis[2]);
    
    fit_setblocksize(2880*getiparam("blocking"));
    bitpix = getiparam("bitpix");
    fit_setbitpix(bitpix);
    if (bitpix == 16) {      /* scale from -2^(bitpix-1) .. 2^(bitpix-1)-1 */
        bscale = (mapmax - mapmin) / (2.0*32768.0 - 1.0);
        bzero = mapmax - bscale*32767.0;
        fit_setscale(bscale,bzero);
    } else if (bitpix == 32) {
        bscale = (mapmax - mapmin) / (2.0*2147483648.0 - 1.0);
        bzero = mapmax - bscale*2147483647.0;
        fit_setscale(bscale,bzero);
    } else if (bitpix == 8) {
    	bscale = (mapmax - mapmin) / (2.0*128.0 - 1.0);
    	bzero = mapmin;
    	fit_setscale(bscale,bzero);
    }
    dprintf(1,"bscale,bzero=%g %g\n",bscale,bzero);

    fitsfile = fitopen(name,"new",ndim,nx_out);
    if (fitsfile==NULL) error("Could not open fitsfile %s for writing\n",name);

    if (Qrefmap || Qcrpix) {
      fitwrhdr(fitsfile,"CRPIX1",ref_crpix[0]);       
      fitwrhdr(fitsfile,"CRPIX2",ref_crpix[1]);       
      if (ndim>2) fitwrhdr(fitsfile,"CRPIX3",ref_crpix[2]);
    } else {
      if (axistype==1) {
	fitwrhdr(fitsfile,"CRPIX1",xref[0]);      
	fitwrhdr(fitsfile,"CRPIX2",xref[1]);
	if (ndim>2) fitwrhdr(fitsfile,"CRPIX3",xref[2]);
      } else {
	fitwrhdr(fitsfile,"CRPIX1",1.0);        /* CRPIX = 1 by Nemo definition */
	fitwrhdr(fitsfile,"CRPIX2",1.0);
	if (ndim>2) fitwrhdr(fitsfile,"CRPIX3",1.0);
      }
    }
    if (Qrefmap || Qcrval) {
      fitwrhdr(fitsfile,"CRVAL1",ref_crval[0]);
      fitwrhdr(fitsfile,"CRVAL2",ref_crval[1]);
      if (ndim>2) fitwrhdr(fitsfile,"CRVAL3",ref_crval[2]);
    } else {
      fitwrhdr(fitsfile,"CRVAL1",xmin[p[0]]);
      fitwrhdr(fitsfile,"CRVAL2",xmin[p[1]]);
      if (ndim>2) fitwrhdr(fitsfile,"CRVAL3",xmin[p[2]]);
    }

    if (Qcdmatrix) {
      fitwrhdr(fitsfile,"CD1_1",dx[p[0]]);    
      fitwrhdr(fitsfile,"CD2_2",dx[p[1]]);    
      if (ndim>2) fitwrhdr(fitsfile,"CD3_3",dx[p[2]]);    
    } else {
      if (Qrefmap || Qcdelt) {
	fitwrhdr(fitsfile,"CDELT1",ref_cdelt[0]*scale[0]);
	fitwrhdr(fitsfile,"CDELT2",ref_cdelt[1]*scale[1]);
	if (ndim>2) fitwrhdr(fitsfile,"CDELT3",ref_cdelt[2]*scale[2]);
      } else {
	fitwrhdr(fitsfile,"CDELT1",dx[p[0]]);    
	fitwrhdr(fitsfile,"CDELT2",dx[p[1]]);    
	if (ndim>2) fitwrhdr(fitsfile,"CDELT3",dx[p[2]]);
      }
    }

    if (Qradecvel) {
      dprintf(0,"[Axes names written as %s, %s, %s\n",
	      radeve[p[0]],radeve[p[1]],radeve[p[2]]);
      fitwrhda(fitsfile,"CTYPE1",radeve[p[0]]);
      fitwrhda(fitsfile,"CTYPE2",radeve[p[1]]);
      if (ndim>2) fitwrhda(fitsfile,"CTYPE3",radeve[p[2]]);
    } else {
      if (Qrefmap) {
        fitwrhda(fitsfile,"CTYPE1",ref_ctype[0]);
        fitwrhda(fitsfile,"CTYPE2",ref_ctype[1]);
        if (ndim>2) fitwrhda(fitsfile,"CTYPE3",ref_ctype[2]);
      } else {
	fitwrhda(fitsfile,"CTYPE1",axname[p[0]]);
	fitwrhda(fitsfile,"CTYPE2",axname[p[1]]);
	if (ndim>2) fitwrhda(fitsfile,"CTYPE3",axname[p[2]]);
      }
    }

    fitwrhdr(fitsfile,"DATAMIN",mapmin);
    fitwrhdr(fitsfile,"DATAMAX",mapmax);
    fitwrhda(fitsfile,"ORIGIN",origin);

    cp = getenv("USER");                                /* AUTHOR */
    if (cp)
        fitwrhda(fitsfile,"AUTHOR",cp);
    else
        fitwrhda(fitsfile,"AUTHOR","NEMO");

    if (object)                                        /* OBJECT */
        fitwrhda(fitsfile,"OBJECT",object);

    if (comment)                                       /* COMMENT */
        stuffit(fitsfile,"COMMENT",comment);
    if (headline)
        stuffit(fitsfile,"COMMENT",headline);

    hitem = ask_history();                              /* HISTORY */
    fitwra(fitsfile,"HISTORY","NEMO: History in reversed order");
    for (i=0, cp=hitem[0]; cp != NULL; i++) {
    	stuffit(fitsfile,"HISTORY",cp);
        cp = hitem[i+1];
    }

    for(i=0; i<nfill; i++)   /* debugging header I/O */
        fitwra(fitsfile,"COMMENT","Dummy filler space");

    buffer = (float *) allocate(nx[p[0]]*sizeof(float));

    for (k=0; k<nx_out[2]; k++) {          /* loop over all planes */
        fitsetpl(fitsfile,1,&k);
        for (j=0; j<nx_out[1]; j++) {      /* loop over all rows */
            for (i=0, bp=buffer; i<nx_out[0]; i++, bp++)
                *bp =  iscale[0] * CubeValue(iptr,i,j,k) + iscale[1];
            fitwrite(fitsfile,j,buffer);
        }
    }
    free(buffer);
    fitclose(fitsfile);
}
コード例 #24
0
ファイル: ccdgen.c プロジェクト: Milkyway-at-home/nemo
local void object_spiral(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  int l, lmax;
  real A = 1.0;
  real h = 1.0;
  real k = 1.0;   /* wave number */
  real p = 1.0;   /* 1/2 power of cos */
  real r0 = 0.0;  /* starting radius */
  real p0 = 0.0;  /* starting angle */
  int m = 2;      /* number of arms */
  real x1,y1,x2,y2,x3,y3,r,arg,value;
  real amp,phi,sum;
  bool Qint, pint;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  if (npar > 2) k = pars[2];
  if (npar > 3) p = pars[3];
  if (npar > 4) m =  (int) pars[4];  /* note rounding ? */
  if (npar > 5) r0 = pars[5];
  if (npar > 6) p0 = pars[6];

  dprintf(0,"spiral: %g %g   %g %g %d   %g %g\n",A,h,k,p,m,r0,p0);

  if (A==0) return;

  p0 *= PI/180.0;  /* convert from degrees to radians */
  k *= TWO_PI;     /* angles are 2.PI.k.r , so absorb 2.PI.k in one */
  pint = (int) p;
  Qint = (p-pint == 0);
  if (Qint)
    warning("Integer power p = %d\n",pint);

  lmax = Qtotflux ? 2 : 1;

  for (l=0; l<lmax; l++) {     /* 1st loop: sum up the flux   if in 2nd loop: normalize */
    if (l==0) 
      sum = 0.0;
    else {
      A /= sum;
      dprintf(0,"spiral: A->%g\n",A);
    } 
    for (j=0; j<ny; j++) {
      y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
      for (i=0; i<nx; i++) {
	x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);
	
	x2 =  -x1*sinp - y1*cosp;
	y2 =  (x1*cosp - y1*sinp)/cosi;
	r = sqrt(x2*x2+y2*y2);
	if (r < r0) 
	  value = 0.0;
	else {
	  /* ? should match this up better so we can connect bar and spiral ? */
	  phi = atan2(y2,x2) + k*(r-r0) + p0;
	  if (Qint) {
	    amp = powi(cos(m*phi),pint);   /* these can come out negative for odd p's !! */
	  } else
	    amp = powd(cos(m*phi),(double)p);
	  arg = r/h;
	  value = (arg < 80) ? A * amp * exp(-arg) :  0.0;
	}
	if (Qtotflux) {   
	  if (l==0) 
	    sum += value;
	  else
	    MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
	} else
	  MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
      } /* i */
    } /* j */
  } /* k */
}
コード例 #25
0
ファイル: image.c プロジェクト: jobovy/nemo
int read_image (stream instr, imageptr *iptr)
{
    string read_matdef;
    int nx=0, ny=0, nz=0;
    size_t  nxyz;

    get_history(instr);         /* accumulate history */

    if (!get_tag_ok (instr,ImageTag))
        return 0;			/* not an image available */
        
    if (*iptr==NULL) {		/* allocate image if neccessary */
    	*iptr = (imageptr ) allocate(sizeof(image));
	dprintf (DLEV,"Allocated image @ %d ",*iptr);
    } else {
        nx = Nx(*iptr);
        ny = Ny(*iptr);
        nz = Nz(*iptr);
    	dprintf (DLEV,"Image %dx%dx%d already allocated @ %d\n",
		 nx,ny,nz,*iptr);
    }
    	
    get_set (instr,ImageTag);
        get_set (instr,ParametersTag);
            get_data (instr,NxTag,IntType, &(Nx(*iptr)), 0);
            get_data (instr,NyTag,IntType, &(Ny(*iptr)), 0);
            get_data (instr,NzTag,IntType, &(Nz(*iptr)), 0);
	    if ((nx>0 || ny>0 || nz>0) &&
		(nx != Nx(*iptr) || ny != Ny(*iptr) || nz != Nz(*iptr)))
	      error("Cannot read different sized images in old pointer yet");
	    if (get_tag_ok(instr,AxisTag))
	      get_data (instr,AxisTag,IntType, &(Axis(*iptr)), 0);
	    else
	      Axis(*iptr) = 0;
	    if (Axis(*iptr) == 1) {
	      get_data_coerced (instr,XrefTag,RealType, &(Xref(*iptr)), 0);
	      get_data_coerced (instr,YrefTag,RealType, &(Yref(*iptr)), 0);
	      get_data_coerced (instr,ZrefTag,RealType, &(Zref(*iptr)), 0);
	    } else {
	      Xref(*iptr) = 0.0;
	      Yref(*iptr) = 0.0;
	      Zref(*iptr) = 0.0;
	    }

            get_data_coerced (instr,XminTag,RealType, &(Xmin(*iptr)), 0);
            get_data_coerced (instr,YminTag,RealType, &(Ymin(*iptr)), 0);
            get_data_coerced (instr,ZminTag,RealType, &(Zmin(*iptr)), 0);
            get_data_coerced (instr,DxTag,RealType, &(Dx(*iptr)), 0);
            get_data_coerced (instr,DyTag,RealType, &(Dy(*iptr)), 0);
            get_data_coerced (instr,DzTag,RealType, &(Dz(*iptr)), 0);
	    get_data_coerced (instr,MapMinTag, RealType, &(MapMin(*iptr)), 0);
	    get_data_coerced (instr,MapMaxTag, RealType, &(MapMax(*iptr)), 0);
	    get_data (instr,BeamTypeTag, IntType, &(BeamType(*iptr)), 0);
	    get_data_coerced (instr,BeamxTag, RealType, &(Beamx(*iptr)), 0);
	    get_data_coerced (instr,BeamyTag, RealType, &(Beamy(*iptr)), 0);
	    get_data_coerced (instr,BeamzTag, RealType, &(Beamz(*iptr)), 0);
            if (get_tag_ok(instr,NamexTag))             /* X-axis name */
                Namex(*iptr) = get_string(instr,NamexTag);
            else
                Namex(*iptr) = NULL;
            if (get_tag_ok(instr,NameyTag))             /* Y-axis name */
                Namey(*iptr) = get_string(instr,NameyTag);
            else
                Namey(*iptr) = NULL;
            if (get_tag_ok(instr,NamezTag))             /* Z-axis name */
                Namez(*iptr) = get_string(instr,NamezTag);
            else
                Namez(*iptr) = NULL;
            if (get_tag_ok(instr,UnitTag))             /* units  */
                Unit(*iptr) = get_string(instr,UnitTag);
            else
                Unit(*iptr) = NULL;
            if (get_tag_ok(instr,TimeTag))             /* time  */
   	    	get_data_coerced (instr,TimeTag, RealType, &(Time(*iptr)), 0);
   	    else
   	    	Time(*iptr) = 0.0;
            read_matdef = get_string(instr,StorageTag);
	    if (!streq(read_matdef,matdef[idef]))
                dprintf(0,"read_image: StorageTag = %s, compiled with %s\n",
		        read_matdef, matdef[idef]);
         get_tes (instr,ParametersTag);

         get_set (instr,MapTag);
            if (Frame(*iptr)==NULL) {        /* check if allocated */
	        nxyz = Nx(*iptr)*Ny(*iptr)*Nz(*iptr);
                Frame(*iptr) = (real *) allocate(nxyz * sizeof(real));
                dprintf (DLEV,"Frame allocated @ %d ",Frame(*iptr));
            } else
                dprintf (DLEV,"Frame already allocated @ %d\n",Frame(*iptr));
	    if (Nz(*iptr)==1)
                get_data_coerced (instr,MapValuesTag,RealType, Frame(*iptr), 
                                Nx(*iptr), Ny(*iptr), 0);
            else
                get_data_coerced (instr,MapValuesTag,RealType, Frame(*iptr),
                                Nx(*iptr), Ny(*iptr), Nz(*iptr), 0);
         get_tes (instr,MapTag);
      get_tes (instr,ImageTag);

      set_iarray(*iptr);

      dprintf (DLEV,"Frame size %d * %d \n",Nx(*iptr), Ny(*iptr));
      
      return 1;		/* succes return code  */
}
コード例 #26
0
ファイル: velmap.c プロジェクト: Milkyway-at-home/nemo
nemo_main()
{
  stream denstr, velstr, outstr, tabstr;
  real center[2], cospa, sinpa, cosi, sini, cost, costmin, x, y, xt, yt, r, den;
  real vr, wt, frang, dx, dy, xmin, ymin, rmin, rmax, ave, tmp, rms;
  real sincosi, cos2i, tga, dmin, dmax, dval, dr, area, fsum1, fsum2;
  int i, j, k, nx, ny, ir, nring, nundf, nout, nang, nsum;
  string outmode;
  int mode = -1;

  velstr = stropen(getparam("in"),"r");

  read_image(velstr,&velptr);
  nx = Nx(velptr);
  ny = Ny(velptr);

  if (hasvalue("out")) {
    outmode = getparam("mode");
    mode = string_index(outmodes, outmode);
    if (mode < 0) error("Illegal mode=%s [%d], valid:",outmode,mode,outmodes);
    warning("New out= mode mode=%s [%d]",outmode,mode);
    Qout = TRUE;
    outstr = stropen(getparam("out"),"w");
    copy_image(velptr,&outptr);
  } 

  if (hasvalue("den")) {
    Qden = TRUE;
    denstr = stropen(getparam("den"),"r");
    read_image(denstr,&denptr);
  } else if (mode==2)
    error("Need den=");


  if (hasvalue("tab")) {
    Qtab = TRUE;
    tabstr = stropen(getparam("tab"),"w");
  } 

  nrad = nemoinpd(getparam("radii"),rad,MAXRING);
  if (nrad < 2) error("got no rings (%d), use radii=",nrad);
  nring = nrad-1;
  if (hasvalue("center")) {
    if (nemoinpd(getparam("center"),center,2) != 2)
      error("not enuf values for center=, need 2");
    xpos = center[0];
    ypos = center[1];
  } else {
    xpos = (Nx(velptr)-1.0)/2.0;
    ypos = (Ny(velptr)-1.0)/2.0;
  }
  pa    = getdparam("pa");
  inc   = getdparam("inc");
  vsys  = getdparam("vsys");
  undf  = getdparam("blank");
  frang = getdparam("frang");

  cospa   = cos(pa*PI/180.0);
  sinpa   = sin(pa*PI/180.0);
  sini    = sin(inc*PI/180.0);
  cosi    = cos(inc*PI/180.0);
  costmin = sin(frang*PI/180.0);
  sincosi = sini*cosi;
  cos2i   = cosi*cosi;
    
  for (i=0; i<nring; i++)
    pixe[i] = vsum[i] = vsqu[i] = wsum[i] = 0;
  nundf = nout = nang = 0;

  ymin = Ymin(velptr);
  xmin = Xmin(velptr);
  dx = Dx(velptr);       dx = ABS(dx);    dx = -dx;
  dy = Dy(velptr);       dy = ABS(dy);
  rmin = -nx*dx*10.0;
  rmax = 0.0;
  dprintf(0,"Map %d x %d pixels, size %g x %g\n",
	  Nx(velptr), Ny(velptr), -dx*Nx(velptr), dy*Ny(velptr));
  dprintf(0,"Pixel size: %g x %g\n",-dx, dy);

  dmin = dmax = vsys;

  /* loop over the map, accumulating data for fitting process */

  for (j=0; j<ny; j++) {
    y = (j-ypos)*dy;
    for (i=0; i<nx; i++) {
      if (MapValue(velptr,i,j) == undf) {
	nundf++;
	if (Qout) MapValue(outptr,i,j) = undf;
	continue;
      }
      x = (i-xpos)*dx;
      yt = x*sinpa + y*cospa;      /* major axis now along Y  */
      xt = x*cospa - y*sinpa;      /* minor axis along X      */
      xt /= cosi;                  /* deproject to the circle */
      r  = sqrt(xt*xt+yt*yt);      /* radius in the disk      */
      rmin = MIN(r,rmin);
      rmax = MAX(r,rmax);
      ir = ring_index(nrad,rad,r);
      dprintf(2,"r=%g ir=%d  (x,y)=%g,%g  (xt,yt)=%g,%g\n",
	      r,ir,x,y,xt,yt);
      if (ir < 0) {
	nout++;
	continue;
      }
      cost = yt/r;
      dval = MapValue(velptr,i,j);
      
      if (mode==1)
	dval /= r;
      else if (mode==2)
	dval *= MapValue(denptr,i,j) / r;

      if (outptr) {
	if  (ABS(cost) > costmin) {
	  MapValue(outptr,i,j) = dval;
	  if (dval > dmax) dmax = dval;
	  if (dval < dmin) dmin = dval;
	} else {
	  MapValue(outptr,i,j) = undf;
	}
      }

      /* now some ring accumulation, remnant of the velfit fitting */

      if (ABS(cost) > costmin) {
	pixe[ir] += 1;
	wsum[ir] += 1.0;
	vsum[ir] += dval;
	vsqu[ir] += dval*dval;
      } else
	nang++;
    } /* i */
  } /* j */

  /* write output map(s), if needed */
  if (Qout) {
    dprintf(0,"Data min/max = %g %g\n",dmin,dmax);    
    MapMin(outptr) = dmin;
    MapMax(outptr) = dmax;
    write_image(outstr,outptr);
  }

  /* report on the rings */

  if (Qtab) {
    fprintf(tabstr,"# r I rms I_sum1 I_sum2 i_ring Npoints\n");
    fsum1 = 0.0;  /* this will count rings with average values */
    fsum2 = 0.0;  /* this will count up flux whenever it fell in a ring */
    nsum = 0;
    for (i=0; i<nring; i++) {
      if (wsum[i] == 0.0) continue;
      nsum++;
      r = 0.5*(rad[i] + rad[i+1]);
      dr = rad[i+1] - rad[i];
      area = PI*(sqr(rad[i+1]) - sqr(rad[i]));
      ave = vsum[i]/wsum[i];
      rms = vsqu[i]/wsum[i]-ave*ave;
      if (rms <  0) rms=0.0;
      rms = sqrt(rms);
      fsum1 += ave*area;
      fsum2 += vsum[i];
      
      fprintf(tabstr,"%g %g %g  %g %g  %d %d\n",
	      r,ave,rms,fsum1,fsum2,i+1,pixe[i]);
    }
  }
  dprintf(0,"Nundf=%d/%d Nout=%d Nang=%d (sum=%d)\n",
	  nundf,nx*ny,nout,nang,nout+nundf+nang);
  dprintf(0,"Rmin/max = %g %g\n",rmin,rmax);

}
コード例 #27
0
ファイル: ccdsharp3.c プロジェクト: jobovy/nemo
void nemo_main()
{
  stream  instr, outstr;
  int     nx, ny, nz, mode;
  int     i,j,k;
  imageptr iptr1=NULL, iptr2=NULL, optr;      /* pointer to images */
  real    d1, d2, d3, d4, d5, d6, dx, dy, dz;
  bool    Qsym = TRUE;            /* symmetric derivates w.r.t. pixel point */
  
  match(getparam("mode"),valid_modes,&mode);
  if (mode==0) error("Not a valid mode; valid:%s",valid_modes);
  dprintf(0,"Image sharpening method #%d\n",mode);
  
  instr = stropen(getparam("in"), "r");
  read_image( instr, &iptr1);
  nx = Nx(iptr1);	
  ny = Ny(iptr1);
  nz = Nz(iptr1);
  dx = Dx(iptr1);
  dy = Dy(iptr1);
  dz = Dz(iptr1);
  if (mode & MODE_DIV || mode & MODE_VORT) {
    if (read_image(instr,&iptr2) == 0)
      error("No second image found in %s\n",getparam("in"));
    if (nx != Nx(iptr2))  
      error("Second image doesn't match in NX: %d <> %d\n",Nx(iptr2),nx);
    if (ny != Ny(iptr2))  
      error("Second image doesn't match in NY: %d <> %d\n",Ny(iptr2),ny);
    if (nz != Nz(iptr2))  
      error("Second image doesn't match in NZ: %d <> %d\n",Nz(iptr2),nz);
  }
  
  outstr = stropen(getparam("out"), "w");
  create_cube(&optr,nx,ny,nz);
  Dx(optr) = Dx(iptr1);
  Dy(optr) = Dy(iptr1);
  Dz(optr) = Dz(iptr1);
  Xmin(optr) = Xmin(iptr1);
  Ymin(optr) = Ymin(iptr1);
  Zmin(optr) = Zmin(iptr1);
  
  if (mode & MODE_LAPLACE) {
    for (k=1; k<nz-1; k++) {
      for (j=1; j<ny-1; j++) {
	for (i=1; i<nx-1; i++) {
	  d1 = CV1(i,j,k) - CV1(i-1,j,k);
	  d2 = CV1(i,j,k) - CV1(i+1,j,k);
	  d3 = CV1(i,j,k) - CV1(i,j-1,k);
	  d4 = CV1(i,j,k) - CV1(i,j+1,k);
	  d5 = CV1(i,j,k) - CV1(i,j,k-1);
	  d6 = CV1(i,j,k) - CV1(i,j,k+1);
	  CVO(i,j,k) = sqrt(d1*d1+d2*d2+d3*d3+d4*d4+d5*d5+d6*d6);
	}
	CVO(0,j,k)    = 0.0;
	CVO(nx-1,j,k) = 0.0;
      }
      for (i=0; i<nx; i++)
	CVO(i,0,k)    = CVO(i,ny-1,k) = 0.0;
    }
    for(j=0; j<ny; j++)
      for(i=0; i<nx; i++)
	CVO(i,j,0)    = CVO(i,j,nz-1) = 0.0;
  } else if (mode & MODE_DIV || mode & MODE_VORT) {
    warning("only 2D implemented");
    for (k=0; k<nz; k++) {
      for (j=0; j<ny-1; j++) {
	for (i=0; i<nx-1; i++) {
	  if (Qsym) {
	    if (i>0 && j>0) {
	      d1 = 0.5*(CV1(i+1,j,k) - CV1(i-1,j,k));         /* dv_x/dx */
	      d2 = 0.5*(CV1(i,j+1,k) - CV1(i,j-1,k));         /* dv_x/dy */
	      d3 = 0.5*(CV2(i+1,j,k) - CV2(i-1,j,k));         /* dv_y/dx */
	      d4 = 0.5*(CV2(i,j+1,k) - CV2(i,j-1,k));         /* dv_y/dy */
	    } else
	      d1 = d2 = d3 = d4 = 0.0;
	  } else {
	    d1 = CV1(i+1,j,k) - CV1(i,j,k);         /* dv_x/dx */
	    d2 = CV1(i,j+1,k) - CV1(i,j,k);         /* dv_x/dy */
	    d3 = CV2(i+1,j,k) - CV2(i,j,k);         /* dv_y/dx */
	    d4 = CV2(i,j+1,k) - CV2(i,j,k);         /* dv_y/dy */
	  }
	  if (mode&MODE_DIV)
	    CVO(i,j,k) = d1/dx + d4/dy;
	  else if (mode&MODE_VORT)
	    CVO(i,j,k) = d3/dx - d2/dy;
	}
	CVO(nx-1,j,k) = 0.0;
      }
      for (i=0; i<nx; i++) {
	CVO(i,ny-1,k) = 0.0;
      }
    }
  } else if (mode & MODE_AREGAN || mode & MODE_PREGAN) {
    warning("only 2D implemented");
    for (k=0; k<nz; k++) {
      for (j=0; j<ny-1; j++) {
	for (i=0; i<nx-1; i++) {
	  d1 = CV1(i,j,k)   - CV1(i+1,j,k);
	  d2 = CV1(i,j+1,k) - CV1(i+1,j+1,k);
	  d3 = CV1(i,j,k)   - CV1(i,j+1,k);
	  d4 = CV1(i+1,j,k) - CV1(i+1,j+1,k);
	  if (mode&MODE_AREGAN)
	    CVO(i,j,k) = sqrt(sqr(d1+d2)+sqr(d3+d4))/2;
	  else {
	    if (d3+d4==0.0 && d1+d2==0.0)
	      CVO(i,j,k) = 0.0;
	    else
	      CVO(i,j,k) = atan2(d3+d4,d1+d2) * 180 / PI;
	  }
	}
	CVO(nx-1,j,k) = 0.0;
      }
      for (i=0; i<nx; i++) {
	CVO(i,ny-1,k) = 0.0;
      }
    }
  }
  write_image(outstr, optr);
}
コード例 #28
0
ファイル: ccdflip.c プロジェクト: Milkyway-at-home/nemo
void nemo_main()
{
    stream  instr, outstr;
    int     nx, ny, nz;        /* size of scratch map */
    int     ix, iy, flip;
    imageptr iptr=NULL;        /* pointer to image */
    real    tmp, zzz;
    string  flipmode;

    flipmode = getparam("flip");
    if (streq(flipmode,"x"))
        flip = X;
    else if (streq(flipmode,"y"))
        flip = Y;
    else if (streq(flipmode,"xy"))
        flip = XY;
    else
        error("Illegal flip axis");

    instr = stropen(getparam("in"), "r");
    outstr = stropen(getparam("out"), "w");

    read_image( instr, &iptr);

    nx = Nx(iptr);	
    ny = Ny(iptr);
    nz = Nz(iptr);

    if(flip==X) {

      for (iy=0; iy<ny; iy++) {		    /* flip in x */
        for (ix=0; ix<nx/2; ix++) {
            tmp = MapValue(iptr,ix,iy);
            zzz = MapValue(iptr,nx-ix-1,iy);
            dprintf(1,"%d %d: %f %f\n",ix,iy,tmp,zzz);
            MapValue(iptr,ix,iy) = MapValue(iptr,nx-ix-1,iy);
            MapValue(iptr,nx-ix-1,iy) = tmp;
        }
      }
    } else if (flip==Y) {
      for (iy=0; iy<ny; iy++) {		    /* flip in y */
        for (ix=0; ix<nx/2; ix++) {
            tmp = MapValue(iptr,iy,ix);
            zzz = MapValue(iptr,iy,nx-ix-1);
            dprintf(1,"%d %d: %f %f\n",ix,iy,tmp,zzz);
            MapValue(iptr,iy,ix) = MapValue(iptr,iy,nx-ix-1);
            MapValue(iptr,iy,nx-ix-1) = tmp;
        }
      }
    } else if (flip==XY) {
      for (iy=0; iy<ny; iy++) {		    /* swap the x and y axes */
        for (ix=iy+1; ix<nx; ix++) {
            tmp = MapValue(iptr,ix,iy);
            dprintf(1,"%d %d: %f \n",ix,iy,tmp);
            MapValue(iptr,ix,iy) = MapValue(iptr,iy,ix);
            MapValue(iptr,iy,ix) = tmp;
        }
      }
      SWAPR(Xmin(iptr),  Ymin(iptr));
      SWAPR(Dx(iptr),    Dy(iptr));
      SWAPS(Namex(iptr), Namey(iptr));
    }
    write_image(outstr, iptr);
}
コード例 #29
0
ファイル: ccdmedian.c プロジェクト: jobovy/nemo
void nemo_main()
{
    stream  instr, outstr;
    int     nx, ny, nz;
    int     nstep,nstep1;
    int     i,j,k, n, n1, i1, j1, m;
    int     ix[2], iy[2];
    imageptr iptr=NULL, optr;      /* pointer to images */
    real    *vals, fraction;
    string  mode = getparam("mode");
    bool Qmedian = (*mode == 'm');
    bool Qmean = (*mode == 'a');

    nstep = getiparam("nstep");
    if (nstep%2 != 1) error("step size %d needs to be odd",nstep);
    nstep1 = (nstep-1)/2;

    n = getiparam("n");
    if (Qmedian)
      dprintf(1,"Median filter size %d\n",n);
    else if (Qmean) 
      dprintf(1,"Mean filter size %d\n",n);
    else
      dprintf(1,"Subtraction filter size %d\n",n);
    if (n%2 != 1) error("filter size %d needs to be odd",n);
    n1 = (n-1)/2;
    vals = (real *) allocate (sizeof(real) * (n*n + 1));

    instr = stropen(getparam("in"), "r");
    read_image( instr, &iptr);
    nx = Nx(iptr);	
    ny = Ny(iptr);
    nz = Nz(iptr);
    if (nz > 1) error("Cannot do 3D cubes properly; use 2D");

    if (hasvalue("x") && hasvalue("y")) {
      get_range("x",ix);
      get_range("y",iy);
    } else {
      ix[0] = 0;
      ix[1] = nx-1;
      iy[0] = 0;
      iy[1] = ny-1;
    }
    dprintf(1,"Xrange: %d - %d   Yrange: %d - %d\n",ix[0],ix[1],iy[0],iy[1]);
      
    outstr = stropen(getparam("out"), "w");
    create_cube(&optr,nx,ny,nz);
    Dx(optr) = Dx(iptr);
    Dy(optr) = Dy(iptr);
    Dz(optr) = Dz(iptr);
    Xmin(optr) = Xmin(iptr);
    Ymin(optr) = Ymin(iptr);
    Zmin(optr) = Zmin(iptr);

    if (nstep > 1) {
      warning("Cheat mode nstep=%d",nstep);

      for (j=nstep1; j<ny-nstep1; j+=nstep) {
	for (i=nstep1; i<nx-nstep1; i+=nstep) {
	  if (j<n1 || j >= ny-n1 || j < iy[0] || j > iy[1]) {
	    CVO(i,j) = CVI(i,j);
	    continue;
	  }
	  if (i<n1 || i >= nx-n1 || i < ix[0] || i > ix[1]) {
	    CVO(i,j) = CVI(i,j);
	    continue;
	  }
	  m = 0;
	  for (j1=j-n1; j1<=j+n1; j1++)
	    for (i1=i-n1; i1<=i+n1; i1++)
	      vals[m++] = CVI(i1,j1);
	  CVO(i,j) = median(m,vals,fraction);
	  for (j1=j-nstep1; j1<=j+nstep1; j1++)
	    for (i1=i-nstep1; i1<=i+nstep1; i1++)
	      CVO(i1,j1) = CVO(i,j);
	}
      }
    } else {

      for (j=0; j<ny; j++) {
	for (i=0; i<nx; i++) {
	  if (j<n1 || j >= ny-n1 || j < iy[0] || j > iy[1]) {
	    CVO(i,j) = CVI(i,j);
	    continue;
	  }
	  if (i<n1 || i >= nx-n1 || i < ix[0] || i > ix[1]) {
	    CVO(i,j) = CVI(i,j);
	    continue;
	  }
	  m = 0;
	  for (j1=j-n1; j1<=j+n1; j1++)
	    for (i1=i-n1; i1<=i+n1; i1++)
	      vals[m++] = CVI(i1,j1);

	  if (Qmedian)
	    CVO(i,j) = median(m,vals,fraction);
	  else if (Qmean)
	    CVO(i,j) = mean(m,vals,fraction);
	  else
	    CVO(i,j) = subtract(m,vals,fraction);
	}
      }

    }
    write_image(outstr, optr);
}
コード例 #30
0
ファイル: ccd.c プロジェクト: Milkyway-at-home/nemo
void inipotential (int *npar, double par[], char *name)
{
    int n;

    n = *npar;
    if (n>0)  omega = par[0];                /* standard pattern speed */
    if (n>1)  iscale = par[1];               /* scaling factor applied to potential */
    if (n>2)  {                              /* alternate definition of center pixel */
      xcen = par[2];
      if (n>3)  ycen = par[3];
      else ycen = xcen;
    }
    if (n>4)  {                              /* alternate definition of pixel size */
      dx = par[4];
      if (n>5)  dy = par[5];
      else dy = dx;
    }
    if (n>6)  warning("inipotential(ccd): npar=%d only 6 parameter accepted",n);

    /* set some easy to use booleans */
    Qcen = n>2;     /* if a new center was defined via parameters */
    Qdel = n>4;     /* if a new pixel size was defined via parameters */

    dprintf(1,"INIPOTENTIAL: %s: %s\n",CCD_VERSION,name);
    dprintf(1,"  Parameters:  Omega=%g iscale=%g xcen,ycen=%g,%g dx,dy=%g,%g\n",
	    omega,iscale,xcen,ycen,dx,dy);

    potstr = stropen (name, "r");          /* open the image */
    read_image (potstr,&iptr);              /* read the image */
    if (iscale != 1.0) {
      int i,j;
      for (j=0; j<Ny(iptr); j++)
      for (i=0; i<Nx(iptr); i++)
	MapValue(iptr,i,j) =  MapValue(iptr,i,j) * iscale;
    }

    nx = Nx(iptr);
    ny = Ny(iptr);
    if (!Qdel) {
      dx = Dx(iptr);
      dy = Dy(iptr);
    }
    idx = 1.0/dx;
    idy = 1.0/dy;
    if (!Qcen) {
      xmin = Xmin(iptr);
      ymin = Ymin(iptr);
    } else {
      xmin = -xcen*dx;
      ymin = -ycen*dy;
    }

    if (idx != idy) {
        if (idx == -idy && xmin == -ymin) {     /* try and patch it */
            idx = -idx;
            xmin = -xmin;
            warning("Astronomical coordinate convention assumed");
        } else
            warning("Possible bug when using dx != dy");
    }
    if (idx<0) warning("1/Dx=%f",idx);
    if (idy<0) warning("1/Dy=%f",idy);
    xmax = xmin + nx * dx;              /* pixel centers */
    ymax = ymin + ny * dy;
    dprintf(1,"Offset and scale factors: xmin,ymin,1/dx,1/dy=%f %f %f %f\n",
            xmin,ymin,idx,idy);
    dprintf(1,"Formal full pixel X-range: %g %g\n",xmin-0.5*dx,xmax+0.5*dx);
    dprintf(1,"Formal full pixel Y-range: %g %g\n",ymin-0.5*dy,ymax+0.5*dy);
    dprintf(1,"Ranges: %g %g %g %g\n",xmin,xmax,ymin,ymax);

    par[0] = omega;
}