Example #1
0
void yaxis(
    real x0,
    real y0,    		/* axis starting point */
    real yl,		        /* axis length */
    real tick[],		/* tick values or limits */
    int nticks,		        /* number of ticks */
    axis_proc ytrans,		/* plotting transformation */
    string label		/* label for axis */
)
{
    int i;
    real t, y;
    char val[32];

    plmove(x0, y0);
    plline(x0, y0 + yl);
    for (i = 0; i < abs(nticks); i++) {
	if (nticks > 0)
	    t = tick[i];
	else
	    t = tick[0] + (i + 1) * (tick[1] - tick[0]) / (1.0 - nticks);
	y = (*ytrans)(t);
	if (label != NULL) {
	    plmove(x0 + ytikrt, y);
	    plline(x0 - ytiklf, y);
	    sprintf(val, "%-.*f", nydig, t);
	    trimval(val);
	    if (! formalaxis) {
		pljust(0);
		pltext(val, x0 - ynumlf, y, ysznum, 90.0);
	    } else {
		pljust(1);
		pltext(val, x0 - ynumlf, y, ysznum, 0.0);
	    }
	} else {
	    plmove(x0 - ytikrt, y);
	    plline(x0 + ytiklf, y);
	}
    }
    if (label != NULL && *label != 0) {
	if (! formalaxis) {
	    pljust(0);
	    pltext(label, x0 - ylablf, y0 + yl / 2, yszlab, 90.0);
	} else {
	    pljust(1);
#ifdef FUDGEAXIS
	    pltext(label, x0 - ylablf, y0 + yl - yszlab/4.0, yszlab, 0.0);
#else
	    pltext(label, x0 - ylablf, y0 + yl - yszlab/2.0, yszlab, 0.0);
#endif
	}
    }
    pljust(-1);
}
Example #2
0
void xaxis(
    real x0, real y0,	    /* axis starting point */
    real xl,		    /* axis length */
    real tick[],	    /* tick values or limits */
    int nticks,		    /* number of ticks */
    axis_proc xtrans,	    /* plotting transformation */
    string label	    /* label for axis */
)
{
    int i;
    real t, x;
    char val[32];

    plmove(x0, y0);
    plline(x0 + xl, y0);
    for (i = 0; i < abs(nticks); i++) {
	if (nticks > 0)
	    t = tick[i];
	else
	    t = tick[0] + (i + 1) * (tick[1] - tick[0]) / (1.0 - nticks);
	x = (*xtrans)(t);
	if (label != NULL) {
	    plmove(x, y0 + xtikup);
	    plline(x, y0 - xtikdn);
	    sprintf(val, "%-.*f", nxdig, t);
	    trimval(val);
	    pljust(0);
	    pltext(val, x, y0 - xnumdn, xsznum, 0.0);
	} else {
	    plmove(x, y0 - xtikup);
	    plline(x, y0 + xtikdn);
	}
    }
    if (label != NULL && *label != 0) {
	if (! formalaxis) {
	    pljust(0);
	    pltext(label, x0 + xl / 2, y0 - xlabdn, xszlab, 0.0);
	} else {
	    pljust(1);
#ifdef FUDGEAXIS
	    pltext(label, x0 + xl, y0 - xlabdn + xszlab/4.0, xszlab, 0.0);
#else
	    pltext(label, x0 + xl, y0 - xlabdn, xszlab, 0.0);
#endif
	}
    }
    pljust(-1);
}
Example #3
0
void plot_path(orbitptr o, real tstart, real tend, int n)
{
	int i, plotfirst = 1;
	real x,y;

	for (i=0; i<(Nsteps(o)-n); i += n) {
	    if ((tstart<Torb(optr,i)) && (Torb(optr,i)<tend)) {
		x = xtrans(Posorb(o,i,xvar_idx));
		y = ytrans(Posorb(o,i,yvar_idx));
		if (plotfirst) {
		    plpoint (x,y);			/* mark first point */
	 	    plotfirst = 0;
		}
		plmove (x,y);
		x = xtrans(Posorb(o,i+n,xvar_idx));
		y = ytrans(Posorb(o,i+n,yvar_idx));
		plline (x,y);
	     }
	}
}
Example #4
0
int pl_hitpopup(Panel *g, Mouse *m){
	Panel *p;
	Point d;
	Popup *pp;

	pp=g->data;
	if(g->state==UP){
		switch(m->buttons&7){
		case 0: p=g->child; break;
		case 1:	p=pp->pop[0]; g->state=DOWN1; break;
		case 2: p=pp->pop[1]; g->state=DOWN2; break;
		case 4: p=pp->pop[2]; g->state=DOWN3; break;
		default: p=0; break;
		}
		if(p==0){
			p=g->child;
			g->state=DOWN;
		}
		else if(g->state!=UP){
			plpack(p, screen->clipr);
			if(p->lastmouse)
				d=subpt(m->xy, divpt(addpt(p->lastmouse->r.min,
						     p->lastmouse->r.max), 2));
			else
				d=subpt(m->xy, divpt(addpt(p->r.min, p->r.max), 2));
			if(p->r.min.x+d.x<g->r.min.x) d.x=g->r.min.x-p->r.min.x;
			if(p->r.max.x+d.x>g->r.max.x) d.x=g->r.max.x-p->r.max.x;
			if(p->r.min.y+d.y<g->r.min.y) d.y=g->r.min.y-p->r.min.y;
			if(p->r.max.y+d.y>g->r.max.y) d.y=g->r.max.y-p->r.max.y;
			plmove(p, d);
			pp->save=allocimage(display, p->r, g->b->chan, 0, DNofill);
			if(pp->save!=0) draw(pp->save, p->r, g->b, 0, p->r.min);
			pl_invis(p, 0);
			pldraw(p, g->b);
		}
	}
	else{
		switch(g->state){
		default: SET(p); break;			/* can't happen! */
		case DOWN1: p=pp->pop[0]; break;
		case DOWN2: p=pp->pop[1]; break;
		case DOWN3: p=pp->pop[2]; break;
		case DOWN:  p=g->child;  break;
		}
		if((m->buttons&7)==0){
			if(g->state!=DOWN){
				if(pp->save!=0){
					draw(g->b, p->r, pp->save, 0, p->r.min);
					flushimage(display, 1);
					freeimage(pp->save);
					pp->save=0;
				}
				pl_invis(p, 1);
			}
			g->state=UP;
		}
	}
	plmouse(p, m);
	if((m->buttons&7)==0)
		g->state=UP;
	return (m->buttons&7)!=0;
}
Example #5
0
out_slit()
{
    real xsky, ysky, vrad, inv_surden, sigma, mass;
    real xslit, yslit, xplt, yplt, sinpa, cospa;
    real m_max, v_min, v_max, s_max;	      /* local min/max */
    int    i, islit;
    Body *bp;

    for (islit=0; islit<nslit; islit++)     /* reset local variables */
	v0star[islit] = v1star[islit] = v2star[islit] = 0.0;
    m_max = v_min = v_max = s_max = 0.0;
    inv_surden = 1.0 / (slit_width*slit_cell);
    sinpa = sin(pa); cospa = cos(pa);

    for(bp=btab, i=0; i<nobj; bp++, i++) {      /* loop over all particles */
 	xsky = xvar(bp,tsnap,i);
 	ysky = yvar(bp,tsnap,i);
 	vrad = zvar(bp,tsnap,i);
 	mass = evar(bp,tsnap,i) * inv_surden;
 	
	xsky -= origin[0];			/* translate to slit origin */
	ysky -= origin[1];
	xslit = -cospa*ysky + sinpa*xsky;	/* and rotate to slit frame */
	yslit =  sinpa*ysky + cospa*xsky;	/* !!! check signs !!! */

	if (fabs(yslit) > 0.5*slit_width) 
	   continue;			/* not in slit */

	islit =  (xslit+0.5*slit_length)/slit_cell;
	if (islit<0 || islit>=nslit)
	   continue;			/* not in slit */

	v0star[islit] += mass;
	v1star[islit] += vrad * mass;
	v2star[islit] += sqr(vrad) * mass;
     } /*-- end particles loop --*/


     while (nsmooth-- > 0) {            	/* convolution */
     	dprintf (0,"Convolving with %d-length beam: ",lsmooth);
     	for (i=0; i<lsmooth; i++) 
            dprintf (0,"%f ",smooth[i]);
    	convolve (v0star, nslit, smooth, lsmooth);
    	convolve (v1star, nslit, smooth, lsmooth);
    	convolve (v2star, nslit, smooth, lsmooth);
     	dprintf (0,"\n");
    }
    	
    for (islit=0; islit<nslit; islit++) { /* moment analysis: M, MV and MV^2 */
	if (v0star[islit]==0.0)
	    continue;		/* no data - skip to next pixel */
	v1star[islit] /= v0star[islit];
	sigma = v2star[islit]/v0star[islit] - sqr(v1star[islit]);
	if (sigma<0.0) {        /* should never happen */
	    warning("islit=%d sigma^2=%e < 0 !!!\n",islit,sigma);
	    v2star[islit] = 0.0;
	    continue;		/* something really wrong */
	}
	v2star[islit] = sqrt(sigma);

	if (v0star[islit] > m_max)  m_max = v0star[islit];
	if (v1star[islit] < v_min)  v_min = v1star[islit];
	if (v1star[islit] > v_max)  v_max = v1star[islit];
	if (v2star[islit] > s_max)  s_max = v2star[islit];
	if (Qtab) {
	    xslit = islit*slit_cell;
	    printf ("%g %g %g %g\n",
			xslit,v0star[islit], v1star[islit], v2star[islit]);
	}
    } /* for(islit) */
 
    if (Qtab)
        return(0);

    plinit ("***", 0.0, 20.0, 0.0, 20.0);

	/* reset default autoscales to user supplied if necessary */
    if (mmax==0.0) mmax=m_max;
    if (vmin==0.0) vmin=v_min;
    if (vmax==0.0) vmax=v_max;
    if (smax==0.0) smax=s_max;
    dprintf (0,"mmax=%f vmin=%f vmax=%f smax=%f  reset to:\n",m_max,v_min,v_max,s_max);
    if (mmax==0) mmax=1;
    if (vmin==0 && vmax==0) vmax=1;
    if (smax==0) smax=1;
    dprintf (0,"mmax=%f vmin=%f vmax=%f smax=%f           \n",mmax, vmin, vmax, smax);
    
	/* general plot header */
    sprintf (plabel,"File: %s; var{%s,%s,%s,%s} slit{%s %s %s %s}",
		infile,getparam("xvar"),getparam("yvar"),
		getparam("zvar"),getparam("evar"),
		getparam("origin"),getparam("pa"),getparam("width"),
		getparam("length"),getparam("cell"));
		
    pltext (plabel,2.0,18.4, 0.32, 0.0);
#if 0
    if (*headline!=NULL)				/* identification */
	pltext (headline,2.0,19.0,0.25,0.0);
#endif

    xplot[0] = -0.5*slit_length;            /* PLOT1: upper panel */
    xplot[1] =  0.5*slit_length;
    sprintf(xlabel,"slit: {x=%s,y=%s}",getparam("xvar"),getparam("yvar"));

    yplot[0]=0.0; 
    yplot[1]=mmax;  
    strcpy (ylabel,"mass surface density");

    xaxis ( 2.0,12.0, 16.0, xplot, -7, xtrans,  NULL);
    xaxis ( 2.0,17.0, 16.0, xplot, -7, xtrans,  NULL);
    yaxis ( 2.0,12.0,  5.0, yplot, -3, ytransm, ylabel);
    yaxis (18.0,12.0,  5.0, yplot, -3, ytransm, NULL);

    for (islit=0; islit<nslit; islit++) {
	xplt = xtrans (-0.5*slit_length + (islit+0.5)*slit_cell);
	yplt = ytransm (v0star[islit]);
	plbox (xplt, yplt, SYMBOLSIZE);
    }
                                           
    yplot[0]=vmin;                      /* PLOT2: middle panel */
    yplot[1]=vmax;  
    strcpy (ylabel,"velocity");

    xaxis (2.0, 7.0, 16.0, xplot, -7, xtrans,   NULL);	/* line ?? */
    yaxis (2.0, 7.0,  5.0, yplot, -3, ytransv1, ylabel);
    yaxis (18.0,7.0,  5.0, yplot, -3, ytransv1, NULL);

    for (islit=0; islit<nslit; islit++) {
	xplt = xtrans (-0.5*slit_length + (islit+0.5)*slit_cell);
	yplt = ytransv1 (v1star[islit]);
	plcross (xplt, yplt, SYMBOLSIZE);
    }
    if (vmin<0.0 || vmax>0.0) {
       plltype (1,2);	/* dashed line at v=0 */
       plmove (xtrans(xplot[0]), ytransv1(0.0));
       plline (xtrans(xplot[1]), ytransv1(0.0));
       plltype (1,1);
    }

    yplot[0]=0.0;                       /* PLOT3: bottom panel */
    yplot[1]=smax; 
    strcpy (ylabel,"velocity dispersion");
    xaxis (2.0, 2.0, 16.0, xplot, -7, xtrans,   xlabel);
    yaxis (2.0, 2.0,  5.0, yplot, -3, ytransv2, ylabel);
    yaxis (18.0,2.0,  5.0, yplot, -3, ytransv2, NULL);

    for (islit=0; islit<nslit; islit++) {
	xplt = xtrans (-0.5*slit_length + (islit+0.5)*slit_cell);
	yplt = ytransv2 (v2star[islit]);
	plcross (xplt, yplt, -SYMBOLSIZE);
    }

    plstop();
}
Example #6
0
nemo_main()
{
    int i, j, np;
    string name, dumpfile;

    name = getparam("name");
    dumpfile = getparam("screendump");
    np = getiparam("pages");
    printf("Testing wth pages=%d\n",np);
    plinit(name, 0.0, 20.0, 0.0, 20.0);     /* open device */
    x_init_plobj();
    plmove(0.0, 0.0);
    plcolor(0);
    plline(20.0, 0.0);
    plcolor(1);
    plline(20.0, 20.0);
    plcolor(2);
    plline(0.0, 20.0);
    plcolor(3);
    plline(0.0, 0.0);
    plcolor(4);
    plline(20.0, 20.0);
    plmove(20.0, 0.0);
    plcolor(5);
    plline(0.0, 20.0);
    plltype(12, 0);
    plmove(4.0, 18.0);
    plcolor(6);
    plline(16.0, 18.0);
    plltype(-6, 0);
    plmove(6.0, 18.0);
    plcolor(7);
    plline(14.0, 18.0);
    
    for (i = 1; i <= 4; i++) {
	plcolor(8+i);
	plltype(i, 1);
        plmove(1.0, 13.0 - i);
        plline(3.0, 13.0 - i);
        plpoint(3.5, 13.0 - i);
	plltype(1, i);
	for (j = 1; j <= 4; j++) {
	    plmove(1.5, 13.0 - i - 0.2*j);
	    plline(1.5 + j, 13.0 - i - 0.2*j);
	}
    }
    plcolor(12);
    plltype(1, 1);
    plcircle(15.0, 9.0, -0.5);
    plcolor(13);
    plcircle(16.0, 9.0, 0.25);
    plcolor(14);
    plcircle(17.0, 9.0, 0.125);
    plcolor(15);
    plcircle(18.0, 9.0, 0.0625);
    plbox(16.0, 8.0, 0.4);
    plbox(17.0, 8.0, 0.2);
    plbox(18.0, 8.0, -0.2);
    plcross(16.0, 7.0, 0.4);
    plcross(17.0, 7.0, 0.2);
    plcross(18.0, 7.0, -0.2);
    plcolor(4);
    pltext("Foo Bar!", 8.0, 5.0, 0.5, 0.0);
    plcolor(5);
    pltext("Fum Bar!", 8.0, 3.0, 0.25, 0.0);
    plcolor(6);
    for (i = 0; i <= 4; i++)
	pltext(" testing angles", 16.0, 10.0, 0.2, 45.0*i);
    plmove(10.0, 8.5);
    plline(10.0, 11.5);
    pljust(-1);
    plcolor(3);
    pltext("left justified",  10.0,  9.0, 0.25, 0.0);
    plcolor(2);
    pljust(0);
    pltext("centered",        10.0, 10.0, 0.25, 0.0);
    plcolor(1);
    pljust(1);
    pltext("right justified", 10.0, 11.0, 0.25, 0.0);
    pljust(0);
    plcolor(7);
    pltext(getparam("headline"),10.0, 19.0, 0.5, 0.0);
    plcolor(1);
    plflush();
    if (*dumpfile)
        pl_screendump(dumpfile);
    if (np>1) {
        plflush();
        plframe();
        plmove(0.0, 0.0);
        plline(20.0, 0.0);
        plline(20.0, 20.0);
        plline(0.0, 20.0);
        plline(0.0, 0.0);

        pljust(0);
        pltext("This is page 2", 10.0,10.0,0.25,0.0);

#define IMAX 100
#define ISTEP 20.0/IMAX

        plmove (0.0,0.0);
        for (i=0; i<IMAX; i++)
           plline(i*ISTEP, i*ISTEP);
    }
    plstop();
}
Example #7
0
local void histogram(void)
{
  int i,j,k, l, kmin, kmax, lcount = 0;
  real count[MAXHIST], under, over;
  real xdat,ydat,xplt,yplt,dx,r,sum,sigma2, q, qmax;
  real mean, sigma, mad, skew, kurt, h3, h4, lmin, lmax, median;
  real rmean, rsigma, rrange[2];
  Moment m;
  
  dprintf (0,"read %d values\n",npt);
  dprintf (0,"min and max value in column(s)  %s: %g  %g\n",getparam("xcol"),xmin,xmax);
  if (!Qauto) {
    xmin = xrange[0];
    xmax = xrange[1];
    dprintf (0,"min and max value reset to : %g  %g\n",xmin,xmax);
    lmin = xmax;
    lmax = xmin;
    for (i=0; i<npt; i++) {
      if (x[i]>xmin && x[i]<=xmax) {
	lmin = MIN(lmin, x[i]);
	lmax = MAX(lmax, x[i]);
      }
    }
    dprintf (0,"min and max value in range : %g  %g\n",lmin,lmax);
  } 
  
  for (k=0; k<nsteps; k++)
    count[k] = 0;		/* init histogram */
  under = over = 0;
  
  ini_moment(&m, 4, Qrobust||Qmad ? npt : 0);
  for (i=0; i<npt; i++) {
    if (Qbin) {
      k=ring_index(nsteps,bins,x[i]);
    } else {
      if (xmax != xmin)
	k = (int) floor((x[i]-xmin)/(xmax-xmin)*nsteps);
      else
	k = 0;
      dprintf(2,"%d k=%d %g\n",i,k,x[i]);
    }
    if (k==nsteps && x[i]==xmax) k--;     /* include upper edge */
    if (k<0)       { under++; continue; }
    if (k>=nsteps) { over++;  continue; }
    count[k] = count[k] + 1;
    dprintf (4,"%d : %f %d\n",i,x[i],k);
    accum_moment(&m,x[i],1.0);
  }
  if (under > 0) error("bug: under = %d",under);
  if (over  > 0) error("bug: over = %d",over);
  under = Nunder;
  over  = Nover;

  mean = mean_moment(&m);
  sigma = sigma_moment(&m);
  skew = skewness_moment(&m);
  kurt = kurtosis_moment(&m);
  h3 = h3_moment(&m);
  h4 = h4_moment(&m);
  if (Qmad) mad = mad_moment(&m);

  if (nsigma > 0) {    /* remove outliers iteratively, starting from the largest */
    iq = (int *) allocate(npt*sizeof(int));
    for (i=0; i<npt; i++) {
#if 1
      iq[i] = x[i] < xmin  || x[i] > xmax;
#else
      iq[i] = 0;
#endif
    }
    lcount = 0;
    do {               /* loop to remove outliers one by one */
      qmax = -1.0;
      for (i=0, l=-1; i<npt; i++) {     /* find largest deviation from current mean */
	if (iq[i]) continue;            /* but skip previously flagged points */
	q = (x[i]-mean)/sigma;
	q = ABS(q);
	if (q > qmax) {
	  qmax = q;
	  l = i;
	}
      }
      if (qmax > nsigma) {
	lcount++;
	iq[l] = 1;
	decr_moment(&m,x[l],1.0);
	mean = mean_moment(&m);
	sigma = sigma_moment(&m);
	skew = skewness_moment(&m);
	kurt = kurtosis_moment(&m);
	h3 = h3_moment(&m);
	h4 = h4_moment(&m);
	if (Qmad) mad = mad_moment(&m);
	dprintf(1,"%d/%d: removing point %d, m/s=%g %g qmax=%g\n",
		lcount,npt,l,mean,sigma,qmax);
	if (sigma <= 0) {
	  /* RELATED TO presetting MINMAX */
	  warning("BUG");
	  accum_moment(&m,x[l],1.0);
	  mean = mean_moment(&m);
	  sigma = sigma_moment(&m);
	  skew = skewness_moment(&m);
	  kurt = kurtosis_moment(&m);
	  h3 = h3_moment(&m);
	  h4 = h4_moment(&m);
	  dprintf(1,"%d/%d: LAST removing point %d, m/s=%g %g qmax=%g\n",
		  lcount,npt,l,mean,sigma,qmax);
	  break;
	  
	}
	
      } else
	dprintf(1,"%d/%d: keeping point %d, m/s=%g %g qmax=%g\n",
		lcount,npt,l,mean,sigma,qmax);
      
      /* if (lcount > npt/2) break; */
    } while (qmax > nsigma);
    dprintf(0,"Removed %d/%d points for nsigma=%g\n",lcount,npt,nsigma);
    
    /* @algorithm      left shift array values from mask array */
    /* now shift all points into the array, decreasing npt */
    /* otherwise the median is not correctly computed */
    for (i=0, k=0; i<npt; i++) {
      dprintf(1,"iq->%d\n",iq[i]);
      if (iq[i]) k++;
      if (k==0) continue;  /* ?? */
      if (i-k < 0) continue;
      dprintf(1,"SHIFT: %d <= %d\n",i-k,i);
      x[i-k] = x[i];
    }
    npt -= lcount;   /* correct for outliers */
    free(iq);
  } /* nsigma > 0 */
  
  if (npt != n_moment(&m))
    error("Counting error, probably in removing outliers...");
  dprintf (0,"Number of points     : %d\n",npt);
  if (npt>1)
    dprintf (0,"Mean and dispersion  : %g %g %g\n",mean,sigma,sigma/sqrt(npt-1.0));
  else
    dprintf (0,"Mean and dispersion  : %g %g 0.0\n",mean,sigma);

  if (Qmad)  dprintf (0,"MAD                  : %g\n",mad);
  dprintf (0,"Skewness and kurtosis: %g %g\n",skew,kurt);
  dprintf (0,"h3 and h4            : %g %g\n", h3, h4);
  if (Qmedian) {
    
    if (npt % 2) 
      median = x[(npt-1)/2];
    else
      median = 0.5 * (x[npt/2] + x[npt/2-1]);
    dprintf (0,"Median               : %g\n",median);
  } else if (Qtorben) {
    median = median_torben(npt,x,xmin,xmax);
    dprintf (0,"Median_torben        : %g\n",median);
  }
  dprintf (0,"Sum                  : %g\n",show_moment(&m,1));
  if (Qrobust) {
    compute_robust_moment(&m);
    rmean  = mean_robust_moment(&m);
    rsigma = sigma_robust_moment(&m);
    robust_range(&m, rrange);
    dprintf (0,"Robust N             : %d\n",n_robust_moment(&m));
    dprintf (0,"Robust Mean Disp     : %g %g\n",rmean,rsigma);
    dprintf (0,"Robust Range         : %g %g\n",rrange[0],rrange[1]);
    if (outstr) {
      for (i=0; i<npt; i++) {
	if (x[i]<rrange[0] || x[i]>rrange[1]) continue;
	fprintf(outstr,"%g %d\n",x[i],i+1);
      }
    }
  }
  
  if (lcount > 0) {
    warning("Recompute histogram because of outlier removals");
    /* recompute histogram if we've lost some outliers */
    for (k=0; k<nsteps; k++)
      count[k] = 0;		/* init histogram */
    under = over = 0;
    for (i=0; i<npt; i++) {
      if (xmax != xmin)
	k = (int) floor((x[i]-xmin)/(xmax-xmin)*nsteps);
      else
	k = 0;
      if (k==nsteps && x[i]==xmax) k--;     /* include upper edge */
      if (k<0)       { under++; continue; }
      if (k>=nsteps) { over++;  continue; }
      count[k] = count[k] + 1;
      dprintf (4,"%d : %f %d\n",i,x[i],k);
    }
    if (under > 0 || over > 0) error("under=%d over=%d in recomputed histo",under,over);
  }
  
  dprintf (3,"Histogram values : \n");
  dx=(xmax-xmin)/nsteps;
  kmax=0;
  sum=0.0;
  for (k=0; k<nsteps; k++) {
    sum = sum + dx*count[k];
    if (ylog) {
      if (count[k]>0.0)
	count[k] = log10(count[k]);
      else
	count[k] = -1.0;
    }
    if (count[k]>kmax)
      kmax=count[k];
    dprintf (3,"%f ",count[k]);
    if (Qcumul) {
      if (k==0)
	count[k] += under;
      else
	count[k] += count[k-1];
    }
  }
  dprintf (3,"\n");
  sigma2 = 2.0 * sigma * sigma;	/* gaussian */
  sum /= sigma * sqrt(2*PI);	/* scaling factor for equal area gauss */
  
  if (ylog && over>0)  over =  log10(over);
  if (ylog && under>0) under = log10(under);
  
  kmax *= 1.1;		/* add 10% */
  if (Qcumul) kmax = npt;
  if (maxcount>0)		/* force scaling by user ? */
    kmax=maxcount;	
  
  if (Qtab) {
    maxcount = 0;
    for (k=0; k<nsteps; k++)
      maxcount = MAX(maxcount,count[k]);
    if (maxcount>0)
      r = 29.0/maxcount;
    else
      r = 1.0;
    printf("  Bin    Value          Number\n");
    printf("       Underflow   %d\n",Nunder);
    for (k=0; k<nsteps; k++) {
      j = (int) (r*count[k]) + 1;
      if (ylog) printf("%3d %13.6g %13.6g ", 
		       k+1, xmin+(k+0.5)*dx, count[k]);
      else printf("%3d %13.6g %8d ", 
		  k+1, xmin+(k+0.5)*dx, (int)count[k]);
      while (j-- > 0) printf("*");
      printf("\n");
    }
    printf("       Overflow    %d\n",Nover);
    stop(0);
  }
  
#ifdef YAPP
  /*	PLOTTING */	
  plinit("***",0.0,20.0,0.0,20.0);

  xplot[0] = xmin;
  xplot[1] = xmax;
  yplot[0] = 0.0;
  yplot[1] = (real) kmax;
  xaxis (2.0, 2.0, 16.0, xplot, -7, xtrans, xlab);
  xaxis (2.0, 18.0,16.0, xplot, -7, xtrans, NULL);
  yaxis (2.0, 2.0, 16.0, yplot, -7, ytrans, ylab);
  yaxis (18.0, 2.0, 16.0, yplot, -7, ytrans, NULL);
  
  pljust(-1);     /* set to left just */
  pltext(input,2.0,18.2,0.32,0.0);             /* filename */
  pljust(1);
  pltext(headline,18.0,18.2,0.24,0.0);         /* headline */
  pljust(-1);     /* return to left just */
  
  xdat=xmin;
  dx=(xmax-xmin)/nsteps;
  plmove(xtrans(xmin),ytrans(0.0));
  for (k=0; k<nsteps; k++) {	/* nsteps= */
    xplt = xtrans(xdat);
    yplt = ytrans((real)count[k]);
    plline (xplt,yplt);
    xdat += dx;
    xplt = xtrans(xdat);
    plline (xplt,yplt);	
  }
  plline(xplt,ytrans(0.0));
  
  for (i=0; i<nxcoord; i++) {
    plmove(xtrans(xcoord[i]),ytrans(yplot[0]));
    plline(xtrans(xcoord[i]),ytrans(yplot[1]));
  }
  
  if (Qgauss) {                   /* plot model and residuals */
    if (ylog)
      plmove(xtrans(xmin),ytrans(-1.0));
    else
      plmove(xtrans(xmin),ytrans(0.0));
    for (k=0; k<100; k++) {
      xdat = xmin + (k+0.5)*(xmax-xmin)/100.0;
      ydat = sum * exp( -sqr(xdat-mean)/sigma2);
      if (ylog) ydat = log10(ydat);
      plline(xtrans(xdat), ytrans(ydat));
    }
  }
  
  if (Qresid) {
    
    plltype(0,2);   /* dotted residuals */
    xdat = xmin+0.5*dx;
    dprintf(1,"# residuals from gauss\n");
    for (k=0; k<nsteps; k++, xdat +=dx) {
      ydat = sum * exp( -sqr(xdat-mean)/sigma2);
      dprintf(1,"%g %g %g\n",xdat,count[k],ydat);
      if (ylog) ydat = log10(ydat);
      ydat = count[k] - ydat;
      if (k==0)
	plmove(xtrans(xdat),ytrans(ydat));
      else
	plline(xtrans(xdat),ytrans(ydat));
    }
    plltype(0,1);   /* back to normal line type */
    
  }
  plstop();
#endif
}
Example #8
0
void nemo_main()
{
    int    i, dir, nrad, npots=0, ltype, ndim = NDIM, nx, ny, ns, ndat, nret;
    int    cols[4], n, idx, idx_max;
    real   pmax, symsize, rr, omk_max = 0.0, omk_rmax;
    real   rad[MAXPT], *vel, *vel1, *vel2, *vel3, *vel4, *curve;
    real   *ome, *kap, *opk, *omk, r0l[MAXPT+2], omega, *f;
    real   inrad[MAXPT], invel[MAXPT], inrade[MAXPT], invele[MAXPT];
    double pos[3], acc[3], pot, time = 0.0;
/*    char   *fmt, s[20], pfmt[256];    */
    char   headline[256], fmt1[80];
    string axis, mode, infile, plotlabel;
    stream instr;
    bool   Qtab, Qplot, Qome, Qvel, Qlv, Qin, QoILR;

    mode = getparam("mode");
    n = getiparam("n");
    plotlabel = getparam("headline");
    sprintf(fmt1,"%s ",getparam("format"));
    Qome = (*mode == 'o');      /*  options are: velocity|omega|lv */
    Qlv = (*mode == 'l');
    Qvel = (*mode == 'v');
    Qtab = getbparam("tab");
    Qplot = getbparam("plot");
    infile = getparam("in");
    Qin =  (*infile != 0);
    if (Qin) {
        nret = nemoinpi(getparam("cols"),cols,4);
        if (nret<0 || nret > 4) error("cols= requires 4 numbers");
        for (i=nret; i<4; i++)
            cols[i] = 0;
        instr = stropen(infile,"r");
        ndat = read_table(instr,MAXPT,inrad,invel,inrade,invele,cols);
        strclose(instr);
    }
    
    mypot1 = get_potential(getparam("name1"),getparam("pars1"),getparam("file1"));
    omega = get_pattern();
    dprintf(0,"Pattern speed: %f\n",omega);
    mypot2 = get_potential(getparam("name2"),getparam("pars2"),getparam("file2"));
    mypot3 = get_potential(getparam("name3"),getparam("pars3"),getparam("file3"));
    mypot4 = get_potential(getparam("name4"),getparam("pars4"),getparam("file4"));
    headline[0] = '\0';         /* accumulate headline */
    if (mypot1) {
        strcat(headline,getparam("name1"));
        strcat(headline,"(");
        strcat(headline,getparam("pars1"));
        strcat(headline,")");
        npots++;
    } 
    if (mypot2) {
        strcat(headline,getparam("name2"));
        strcat(headline,"(");
        strcat(headline,getparam("pars2"));
        strcat(headline,") ");
        npots++;
    }
    if (mypot3) {
        strcat(headline,getparam("name3"));
        strcat(headline,"(");
        strcat(headline,getparam("pars3"));
        strcat(headline,") ");
        npots++;
    }
    if (mypot4) {
        strcat(headline,getparam("name4"));
        strcat(headline,"(");
        strcat(headline,getparam("pars4"));
        strcat(headline,")");
        npots++;
    }

    nrad = nemoinpr(getparam("radii"),rad,MAXPT);   /* get radii */
    if (nrad <= 0)
        warning("Using %d radii is not very productive",nrad);
    vel  = (real *) allocate(sizeof(real) * nrad);  /* allocate stuff */
    vel1 = (real *) allocate(sizeof(real) * nrad);
    vel2 = (real *) allocate(sizeof(real) * nrad);
    vel3 = (real *) allocate(sizeof(real) * nrad);
    vel4 = (real *) allocate(sizeof(real) * nrad);
    if (Qome) {
        ome = (real *) allocate(4 * sizeof(real) * nrad);  /* plus spline */
        kap = (real *) allocate(sizeof(real) * nrad);
        opk = (real *) allocate(sizeof(real) * nrad);
        omk = (real *) allocate(sizeof(real) * nrad);
    } 

    axis = getparam("axis");
    dir = 0;
    if (*axis == 'x') dir=0;
    if (*axis == 'y') dir=1;
    if (*axis == 'z') dir=2;
    if (dir>NDIM) error("Axis %s not supported in NDIM=%d",axis,NDIM);

    pmax = 0.0;

    for (i=0; i<nrad; i++) {            /* loop to compute */
        CLRV(pos);                      /* clear positions */
        pos[dir] = rad[i];              /* set the right axis */
        vel[i] = 0.0;
        if (mypot1) {
            CLRV(acc);
            (*mypot1) (&ndim,pos,acc,&pot,&time);
            vel1[i] = -rad[i] * acc[dir];
            vel[i] += vel1[i];
            vel1[i] = sqrt(vel1[i]);        
        }
        if (mypot2) {
            CLRV(acc);
            (*mypot2) (&ndim,pos,acc,&pot,&time);
            vel2[i] = -rad[i] * acc[dir];
            vel[i] += vel2[i];
	    vel2[i] = sqrt(vel2[i]);        
        }
        if (mypot3) {
            CLRV(acc);
            (*mypot3) (&ndim,pos,acc,&pot,&time);
            vel3[i] = -rad[i] * acc[dir];
            vel[i] += vel3[i];
	    vel3[i] = sqrt(vel3[i]);        
        }
        if (mypot4) {
            CLRV(acc);
            (*mypot4) (&ndim,pos,acc,&pot,&time);
            vel4[i] = -rad[i] * acc[dir];
            vel[i] += vel4[i];
            vel4[i] = sqrt(vel4[i]);        
        }
        vel[i]  = sqrt(vel[i]);        
    }
    if (Qome) {
	lindblad(nrad,rad,vel,ome,kap,opk,omk,n);
        if (omega> 0.0) {                               /* compute resonances */
            f = opk;
            idx = nrad-1;
            if (omega < f[idx]) {
                warning("Radii not far enough out for OLR: %g",f[idx]);
                f = ome;
                if (omega < f[idx]) {
                    warning("Radii not far enough out for CR: %g",f[idx]);
                    f = omk;
                }
            }
            QoILR = FALSE;
            for(; idx>0; idx--) {
                if (omk[idx] > omk_max) {
                    idx_max = idx;
                    omk_max = omk[idx];
                }
                if (f==omk) {
                    if (QoILR) {
                        if (omega < f[idx]) continue;
                    } else {
                        if (omega > f[idx]) continue;
                    }
                } else {
                    if (omega > f[idx]) continue;
                }
                
                /* found a resonance: */

                rr = rad[idx] + (rad[idx+1]-rad[idx])*
                                (omega-f[idx])/(f[idx+1]-f[idx]);
                if (f == omk) {
#if 0                    
                    if (QoILR) {
                        dprintf(0,"iILR: %g\n",rr);
                        break;
                    } else {
                        dprintf(0,"oILR: %g\n",rr);
                        QoILR = TRUE;
                    }
#endif                    
                } else if (f == ome) {
                    dprintf(0,"CR: %g\n",rr);
                    f = omk;
                } else if (f == opk) {
                    dprintf(0,"OLR: %g\n",rr);
                    f = ome;
                } else
                    error("impossble resonance");
            }
            peak(nrad,rad,omk,idx_max,1, &omk_rmax, &omk_max);
            dprintf(0,"OMK_max: %g\n",omk_max);
            dprintf(0,"OMK_rmax: %g\n",omk_rmax);

            if (omega < omk_max) {			/* search for ILR */
            	for (idx=idx_max; idx<nrad; idx++) {
                    if (omega > omk[idx]) {
                        rr = rad[idx-1] + (rad[idx]-rad[idx-1])*
                                (omega-f[idx-1])/(f[idx]-f[idx-1]);
                        dprintf(0,"oILR: %g\n",rr);
                        break;
                    }
            	}
                for (idx=idx_max; idx>0; idx--) {
                    if (omega > omk[idx]) {
                        rr = rad[idx] + (rad[idx+1]-rad[idx])*
                               (omega-f[idx])/(f[idx+1]-f[idx]);
                        dprintf(0,"iILR: %g\n",rr);
                        break;
                    }
            	}
            }
        }
    }
    for (i=0; i<nrad; i++) {                            /* loop to print */
        if (Qtab) {
	  printf(fmt1,rad[i]);
	  printf(fmt1,vel[i]);
	}
	if (Qtab && npots>1 && !Qome) {
	    if (mypot1) printf(fmt1,vel1[i]);
	    if (mypot2) printf(fmt1,vel2[i]);
	    if (mypot3) printf(fmt1,vel3[i]);
	    if (mypot4) printf(fmt1,vel4[i]);
        }
        if (Qtab && Qome) {
	  printf(fmt1,ome[i]);
	  printf(fmt1,kap[i]);
	  printf(fmt1,opk[i]);
	  printf(fmt1,omk[i]);
	}
	if (Qtab) printf("\n");
        if (Qome)
            pmax = MAX(pmax,opk[i]);
        else
            pmax = MAX(pmax,vel[i]);
    }
    if (Qin && Qvel) 
        goodness(nrad,rad,vel,ndat,inrad,invel,(cols[3]>0?invele:NULL));
    if (Qplot) {
        plinit("***",0.0,20.0,0.0,20.0);                /* open device */
        nx = nemoinpr(getparam("xrange"),xplot,2);      /* get xrange in plot */
        switch(nx) {
         case 0:
            xplot[0] = rad[0];
         case 1:
            xplot[1] = rad[nrad-1];
            break;
         case 2:
            break;
         default:
            warning("xrange= only accepts two values");
            break;
        }
        ny = nemoinpr(getparam("yrange"),yplot,2);      /* get yrange in plot */
        switch(ny) {
         case 0:
            yplot[0] = 0.0;
            yplot[1] = 1.1 * pmax;      /* extra 10% for egde */
            break;
         case 1:
            yplot[1] = 1.1 * pmax;      /* extra 10% for egde */
            break;
         case 2:
            break;
         default:
            warning("yrange= only accepts two values");
            break;
        }
        xaxis ( 2.0, 2.0, 16.0, xplot, -7, xtrans, "R");    /* plot axes */
        xaxis ( 2.0,18.0, 16.0, xplot, -7, xtrans, NULL);
        if (Qome)
            yaxis ( 2.0, 2.0, 16.0, yplot, -7, ytrans, "[V/R]");
        else
            yaxis ( 2.0, 2.0, 16.0, yplot, -7, ytrans, "V");
        yaxis (18.0, 2.0, 16.0, yplot, -7, ytrans, NULL);
        if (*plotlabel)
            pltext(plotlabel,2.0,18.5,0.5,0.0);
        else
            pltext(headline,2.0,18.5,0.35,0.0);
        if (*plotmsg)
            pltext(plotmsg,8.0,2.5,0.25,0.0);

        curve = (Qome ? ome : vel);            /* assign first curve */
        plltype(3,1);                                 /* thick solid line */
        plmove(xtrans(rad[0]),ytrans(curve[0]));
        for (i=1; i<nrad; i++)
            plline(xtrans(rad[i]),ytrans(curve[i]));
        if (Qome) {                   /* if Lindblad - plot omk, opk */
            plltype(1,1);                      /* all regular solid lines */
            plmove(xtrans(rad[0]), ytrans(omk[0]));
            for (i=1; i<nrad; i++)
                plline(xtrans(rad[i]),ytrans(omk[i]));
            plmove(xtrans(rad[0]), ytrans(opk[0]));
            for (i=1; i<nrad; i++)
                plline(xtrans(rad[i]),ytrans(opk[i]));
        } else if (npots>1) {            /* if velocity and > 1 component */
            ltype = 1;
            if (mypot1) {
                plltype(1,++ltype);
                plmove(xtrans(rad[0]),ytrans(vel1[0]));
                for (i=1; i<nrad; i++)
                    plline(xtrans(rad[i]),ytrans(vel1[i]));
            }
            if (mypot2) {
                plltype(1,++ltype);
                plmove(xtrans(rad[0]),ytrans(vel2[0]));
                for (i=1; i<nrad; i++)
                    plline(xtrans(rad[i]),ytrans(vel2[i]));
            }
            if (mypot3) {
                plltype(1,++ltype);
                plmove(xtrans(rad[0]),ytrans(vel2[0]));
                for (i=1; i<nrad; i++)
                    plline(xtrans(rad[i]),ytrans(vel3[i]));
            }
            if (mypot4) {
                plltype(1,++ltype);
                plmove(xtrans(rad[0]),ytrans(vel2[0]));
                for (i=1; i<nrad; i++)
                    plline(xtrans(rad[i]),ytrans(vel4[i]));
            }
        }
	plltype(1,1); 
        symsize = 0.1;
        if (Qin && Qvel) {           /* if input file with velocities */
            for (i=0; i<ndat; i++)
                plbox(xtrans(inrad[i]),ytrans(invel[i]),symsize);
            if (cols[3]>0) {        /* if error bars in radius */
                for (i=0; i<ndat; i++) {
                    plmove(xtrans(inrad[i]-inrade[i]),ytrans(invel[i]));
                    plline(xtrans(inrad[i]+inrade[i]),ytrans(invel[i]));
                }
            }
            if (cols[4]>0) {        /* if error bars in velocity */
                for (i=0; i<ndat; i++) {
                    plmove(xtrans(inrad[i]),ytrans(invel[i]-invele[i]));
                    plline(xtrans(inrad[i]),ytrans(invel[i]+invele[i]));
                }
            }
        } else if (Qin && Qome) {       /* if input file with omega */
            for (i=0; i<ndat; i++)
                plbox(xtrans(inrad[i]),ytrans(invel[i]/inrad[i]),symsize);
        }
        plstop();
    }  /* if plot vel/ome */
    if (Qlv) {
        ns = nemoinpr(getparam("r0l"),r0l,MAXPT+2) - 2;
        if (ns < 0)
            error("r0l= needs at least two values: r0 and l");
        else if (ns==0)
            warning("r0l= no lv-radii array supplied");
        lv(nrad,rad,vel,r0l[0],r0l[1],ns,&r0l[2]);
    }
}