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); }
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); }
void plabort(const char *errormsg) /* pmr: const */ { if (abort_handler != NULL) (*abort_handler)(errormsg); if (plsc->errcode != NULL) *(plsc->errcode) = 1; if (plsc->errmsg != NULL) { sprintf(plsc->errmsg, "\n*** PLPLOT ERROR ***\n"); if (*errormsg != '\0') sprintf(plsc->errmsg, "%s, aborting operation\n", errormsg); } else { int was_gfx = 0; if (plsc->graphx == 1) { was_gfx = 1; pltext(); } fprintf(stderr, "\n*** PLPLOT ERROR ***\n"); if (*errormsg != '\0') fprintf(stderr, "%s, aborting operation\n", errormsg); if (was_gfx == 1) plgra(); } }
void plwarn(const char *errormsg) /* pmr: const */ { int was_gfx = 0; if (plsc->graphx == 1) { was_gfx = 1; pltext(); } fprintf(stderr, "\n*** PLPLOT WARNING ***\n"); if (*errormsg != '\0') fprintf(stderr, "%s\n", errormsg); if (was_gfx == 1) plgra(); }
void nemo_main() { stream istr; char msg[128]; int i, ndim; string *fn; setparams(); compfuncs(); /* btrrtans snapplot-like interface */ plinit("***", 0.0, 20.0, 0.0, 20.0); xaxis( 2.0, 2.0, 16.0, xrange, -7, xtrans, xlabel); xaxis( 2.0, 18.0, 16.0, xrange, -7, xtrans, NULL); yaxis( 2.0, 2.0, 16.0, yrange, -7, ytrans, ylabel); yaxis(18.0, 2.0, 16.0, yrange, -7, ytrans, NULL); sprintf(msg, "File: %s", input); pltext(msg, 2.0, 18.4, 0.32, 0.0); optr = NULL; ndim = NDIM; allocate_orbit(&optr,ndim,maxsteps); /* allocate a large orbit */ fn = burststring(input," ,"); for (i=0; fn[i]; i++) { /* loop over all files */ istr = stropen(fn[i], "r"); /* open orbit file */ while (read_orbit(istr,&optr)) { /* while an orbit found....*/ dprintf(0,"Read orbit with %d phase-points\n",Nsteps(optr)); plot_path(optr,trange[0],trange[1],nplot); Nsteps(optr) = maxsteps; /* reset for next orbit */ } strclose(istr); } plstop(); }
void xlinax() { char ktemp[9]; int lpower; int ia, ib, igdlog, jdiv, jpower, jstep, jtick, mds, nds, ndsu, ntick, nxdivu; float divlog, divtry, factor, grdlog, power, skfudge, value, valuei, xdivu, xgrdmn, xgrdmx, xref, xrefi, xtick, xticki, xvpmax, xvpmin, yloc, ypow, yvpmax, yvpmin; static char kvalue[17] = " "; static char kpower[9] = " "; /*===================================================================== * PURPOSE: To produce a linearly-scaled axis at the bottom and/or * top of the current plot window. *===================================================================== * MODULE/LEVEL: gem/4 *===================================================================== * GLOBAL INPUT: * MACH: VSMALL * GEM: LXDIV, XDIV, LNXDIV, NXDIV, CHHT, CHWID, LXREV, * XPMNU, XPMXU, XIMNZ, XIMXZ, * LBOTAX, LBOTTC, LTOPAX, LTOPTC, * IHORZ, IVERT, XMPIP1, XMPIP2, * LXGRD, IXGRD, IWIDTH, ISKWIDTH, ITHIN, SKDEVFUDGE *===================================================================== * GLOBAL OUTPUT: * GEM: AXWBOT, AXWTOP *===================================================================== * SUBROUTINES CALLED: * SACLIB: CNVITA, LJUST, SETLINESTYLE, LINE, PLTEXT, CNVFTA, * SETTEXTJUST, SETLINEWIDTH, GETVPORT *===================================================================== * LOCAL VARIABLES: * xdivu: Divison spacing used. * lpower: Set to .TRUE. if there is a multiplying scale factor. * power: Multiplying scale factor. * kpower: Character string containing formatted scale factor. * ypow: Y location in plot coordinates of scale factor. * divtry: Trial division spacing. * jstep: Integer trial step size (constrained to be 10, 5 or 2). * xgrdmn: Minimum labeled grid value (including scale factor). * xgrdmx: Maximum labeled grid value (including scale factor). * value: Labeled grid value excluding scale factor. * valuei: Increment in VALUE. * kvalue: Character string containing formatted label value. * xref: Location of labeled grid value in plot coordinates. * xrefi: Increment in XREF. *===================================================================== * ASSUMPTIONS: * - plmap has set up world to plot coordiate mapping. * - Text orientation is horizontal. *===================================================================== * MODIFICATION HISTORY: * 920526: Added line-width. TEXT is always line-width THIN! * 830929: Added secondary tick marks. * 830927: Moved grid drawing logic into its own do loop. * 830223: Fixed logic in computing annotation format. * 820928: Cleaned up and documented. * 810120: Original PRIME version. *===================================================================== */ /* PROCEDURE: */ settextangle(TEXT_HORIZONTAL); /* - Determine division spacing. There are three possibilities: * (1) The division spacing is set by user (LXDIV=.TRUE.). * (2) The (approximate) number of divsions is set (LNXDIV=.TRUE.). * (3) "Nice" division spacings are calculated. */ if( cmgem.xdiv_spacing_on ){ xdivu = cmgem.xdiv_spacing; power = log10( xdivu ); if( power < 0. ) power = power - 1.; jpower = power; } else { if( cmgem.xdiv_number_on ){ nxdivu = cmgem.xdiv_number; } else { nxdivu = (fabs( cmgem.uplot.xmax - cmgem.uplot.xmin )/(FDIVSP*cmgem.chht)) + .001; if( nxdivu < 5 ) nxdivu = 5; } divtry = (cmgem.zdata.xmax - cmgem.zdata.xmin)/nxdivu; if( divtry > 0. ){ power = log10( divtry ); } else { power = 0.; } if( power < 0. ) power = power - 1.; jpower = power; /* -- Limit divison spacings to steps of 10, 5, or 2 [cases (2) and (3)]. */ jstep = divtry*(powi(10.,-jpower)); if( jstep > 5 ){ jstep = 1; jpower = jpower + 1; /* power = power + 1.; */ } else if( jstep > 2 ) { jstep = 5; } else { jstep = 2; } xdivu = jstep*(powi(10.,jpower)); } /* - Determine "nice-numbered" starting and ending values. */ ia = cmgem.zdata.xmin/xdivu; xgrdmn = xdivu*ia; if( xgrdmn < cmgem.zdata.xmin ){ ia = ia + 1; xgrdmn = xgrdmn + xdivu; } ib = cmgem.zdata.xmax/xdivu; xgrdmx = xdivu*ib; if( xgrdmx > cmgem.zdata.xmax ){ ib = ib - 1; xgrdmx = xgrdmx - xdivu; } nxdivu = ib - ia + 1; /* - Determine the format (Fn.m) of the labels. * The variable NDS assumes the role of "n" and MDS the role of "m". */ /* - The "magic numbers" used in this algorithm generate good division * spacings almost all of the time. Modify them at your own risk. */ grdlog = log10( fmax( fabs( xgrdmn ), fabs( xgrdmx ) ) + 0.001 ); if( grdlog >= 0. ){ grdlog = grdlog + 1.001; } else{ grdlog = grdlog - 0.999; } divlog = log10( xdivu ); if( divlog >= 0. ){ divlog = divlog + 1.001; } else{ divlog = divlog - 0.999; } lpower = FALSE; factor = 1.; if( grdlog*divlog >= 0. ){ if( grdlog < 0. ){ igdlog = grdlog; } else{ igdlog = divlog; } if( labs( igdlog ) >= 3 && cmgem.lxpowr ){ mds = 0; nds = max( 4, (int)( grdlog ) - (int)( divlog ) + 2 ); cnvita( jpower, ktemp,9 ); ljust( ktemp,9 ); if( jpower >= 0 ){ fstrncpy( kpower, 8, "X 10+", 5); fstrncpy( kpower+5, 8-5, ktemp, strlen(ktemp)); } else{ fstrncpy( kpower, 8, "X 10", 4); fstrncpy( kpower+4, 8-4, ktemp, strlen(ktemp)); } factor = powi(10.,-jpower); lpower = TRUE; } else{ mds = labs( minfi( 0., divlog ) ); nds = maxfi( 1., grdlog ); if( mds > 0 ) nds = nds + mds + 2; } } else{ mds = labs( minfi( 0., divlog ) ); nds = maxfi( 0., grdlog ); if( mds > 0 ) nds = nds + mds + 2; } /* - Determine axes fudge factor for thick axes lines. */ getvport( &xvpmin, &xvpmax, &yvpmin, &yvpmax ); skfudge = cmgem.skdevfudge*((yvpmin - yvpmax)/(xvpmin - xvpmax)); /* - Draw the bottom axis. */ setlinestyle( LINE_STYLE_SOLID ); setlinewidth( cmgem.iskwidth ); if( cmgem.axis[BOTTOM].annotate || cmgem.axis[BOTTOM].ticks ){ /* -- Bottom Axes line. */ if( cmgem.iskwidth > LINE_WIDTH_THIN ){ line( cmgem.uplot.xmin - cmgem.iskwidth*skfudge, cmgem.uplot.ymin, cmgem.uplot.xmax + cmgem.iskwidth*skfudge, cmgem.uplot.ymin ); } else{ line( cmgem.uplot.xmin, cmgem.uplot.ymin, cmgem.uplot.xmax, cmgem.uplot.ymin ); } /* -- Label for multiplying scale factor. */ if( lpower && cmgem.axis[BOTTOM].annotate ){ ypow = fmax( cmgem.uplot.ymin - 2.2*cmgem.chht, 0.1*cmgem.chht ); if( cmgem.lxrev ){ settextjust( "RIGHT", "BOTTOM" ); } else{ settextjust( "LEFT", "BOTTOM" ); } pltext( kpower,9, cmgem.uplot.xmin, ypow ); setlinewidth( cmgem.iskwidth ); } /* -- Calculate constants for labeled tick marks. */ value = xgrdmn*factor; xref = xgrdmn*cmgem.xmpip1 + cmgem.xmpip2; valuei = xdivu*factor; xrefi = xdivu*cmgem.xmpip1; strcpy( kvalue, " " ); /* -- Draw secondary tick marks before first labeled one. */ ntick = 1; if( xrefi >= 0.10 ){ ntick = 3; if( jstep == 5 ) ntick = 4; } if( xrefi >= 0.25 ) ntick = 9; xticki = xrefi/(float)( ntick + 1 ); xtick = xref - xrefi; for( jtick = 1; jtick <= ntick; jtick++ ){ xtick = xtick + xticki; if( xtick >= cmgem.uplot.xmin ){ line( xtick, cmgem.uplot.ymin, xtick, cmgem.uplot.ymin + 0.5*cmgem.chwid ); } } /* -- Loop on labeled tick marks. */ for( jdiv = 1; jdiv <= nxdivu; jdiv++ ){ line( xref, cmgem.uplot.ymin, xref, cmgem.uplot.ymin + cmgem.chwid ); if( cmgem.axis[BOTTOM].annotate ){ if( value >= 0 ){ ndsu = nds; } else{ ndsu = nds + 1; } cnvfta( value, ndsu, mds, kvalue,17 ); ljust( kvalue,17 ); yloc = cmgem.uplot.ymin - 0.1*cmgem.chht; settextjust( "CENTER", "TOP" ); pltext( kvalue,17, xref, yloc ); setlinewidth( cmgem.iskwidth ); } /* --- Loop on secondary tick marks. */ xtick = xref; for( jtick = 1; jtick <= ntick; jtick++ ){ xtick = xtick + xticki; if( xtick <= cmgem.uplot.xmax ){ line( xtick, cmgem.uplot.ymin, xtick, cmgem.uplot.ymin + 0.5*cmgem.chwid ); } } value = value + valuei; xref = xref + xrefi; } /* -- Save axes widths. */ if( cmgem.axis[BOTTOM].annotate ){ cmgem.axis[BOTTOM].width = 1.1*cmgem.chht; if( lpower ) cmgem.axis[BOTTOM].width = cmgem.uplot.ymin - ypow; } else{ cmgem.axis[BOTTOM].width = 0.; } } /* - Top axis: */ if( cmgem.axis[TOP].annotate || cmgem.axis[TOP].ticks ){ /* -- Top Axes line. */ if( cmgem.iskwidth > LINE_WIDTH_THIN ){ line( cmgem.uplot.xmin - cmgem.iskwidth*skfudge, cmgem.uplot.ymax, cmgem.uplot.xmax + cmgem.iskwidth*skfudge, cmgem.uplot.ymax ); } else{ line( cmgem.uplot.xmin, cmgem.uplot.ymax, cmgem.uplot.xmax, cmgem.uplot.ymax ); } /* -- Label for multiplying scale factor. */ if( lpower && cmgem.axis[TOP].annotate ){ ypow = fmin( cmgem.uplot.ymax + 2.2*cmgem.chht, cmgem.view.ymax - 0.1*cmgem.chht ); if( cmgem.lxrev ){ settextjust( "RIGHT", "TOP" ); } else{ settextjust( "LEFT", "TOP" ); } pltext( kpower,9, cmgem.uplot.xmin, ypow ); setlinewidth( cmgem.iskwidth ); } /* -- Calculate constants for labeled tick marks. */ value = xgrdmn*factor; xref = xgrdmn*cmgem.xmpip1 + cmgem.xmpip2; valuei = xdivu*factor; xrefi = xdivu*cmgem.xmpip1; strcpy( kvalue, " " ); /* -- Draw secondary tick marks before first labeled one. */ ntick = 1; if( xrefi >= 0.10 ){ ntick = 3; if( jstep == 5 ) ntick = 4; } if( xrefi >= 0.25 ) ntick = 9; xticki = xrefi/(float)( ntick + 1 ); xtick = xref - xrefi; for( jtick = 1; jtick <= ntick; jtick++ ){ xtick = xtick + xticki; if( xtick >= cmgem.uplot.xmin ){ line( xtick, cmgem.uplot.ymax, xtick, cmgem.uplot.ymax - 0.5*cmgem.chwid ); } } /* -- Loop on labeled tick marks. */ for( jdiv = 1; jdiv <= nxdivu; jdiv++ ){ line( xref, cmgem.uplot.ymax, xref, cmgem.uplot.ymax - cmgem.chwid ); if( cmgem.axis[TOP].annotate ){ if( value >= 0. ){ ndsu = nds; } else{ ndsu = nds + 1; } cnvfta( value, ndsu, mds, kvalue,17 ); ljust( kvalue,17 ); yloc = cmgem.uplot.ymax + 0.1*cmgem.chht; settextjust( "CENTER", "BOTTOM" ); pltext( kvalue,17, xref, yloc ); setlinewidth( cmgem.iskwidth ); } /* --- Loop on secondary tick marks. */ xtick = xref; for( jtick = 1; jtick <= ntick; jtick++ ){ xtick = xtick + xticki; if( xtick <= cmgem.uplot.xmax ){ line( xtick, cmgem.uplot.ymax, xtick, cmgem.uplot.ymax - 0.5*cmgem.chwid ); } } value = value + valuei; xref = xref + xrefi; } /* -- Save axes widths. */ if( cmgem.axis[TOP].annotate ){ cmgem.axis[TOP].width = 1.1*cmgem.chht; if( lpower ) cmgem.axis[TOP].width = ypow - cmgem.uplot.ymax; } else{ cmgem.axis[TOP].width = 0.; } } /* - Grid lines. */ if( cmgem.lxgrd ){ setlinewidth( LINE_WIDTH_THIN ); xref = xgrdmn*cmgem.xmpip1 + cmgem.xmpip2; xrefi = xdivu*cmgem.xmpip1; setlinestyle( cmgem.ixgrd ); for( jdiv = 1; jdiv <= nxdivu; jdiv++ ){ line( xref, cmgem.uplot.ymin, xref, cmgem.uplot.ymax ); xref = xref + xrefi; } setlinestyle( LINE_STYLE_SOLID ); setlinewidth( cmgem.iskwidth ); } return; } /* end of function */
int main( int argc, char *argv[] ) { PLINT digmax, cur_strm, new_strm; char ver[80]; // plplot initialization // Parse and process command line arguments plMergeOpts( options, "x01c options", notes ); plparseopts( &argc, argv, PL_PARSE_FULL ); // Get version number, just for kicks plgver( ver ); fprintf( stdout, "PLplot library version: %s\n", ver ); // Initialize plplot // Divide page into 2x2 plots // Note: calling plstar replaces separate calls to plssub and plinit plstar( 2, 2 ); // Select font set as per input flag if ( fontset ) plfontld( 1 ); else plfontld( 0 ); // Set up the data // Original case xscale = 6.; yscale = 1.; xoff = 0.; yoff = 0.; // Do a plot plot1( 0 ); // Set up the data xscale = 1.; yscale = 0.0014; yoff = 0.0185; // Do a plot digmax = 5; plsyax( digmax, 0 ); plot1( 1 ); plot2(); plot3(); // // Show how to save a plot: // Open a new device, make it current, copy parameters, // and replay the plot buffer // if ( f_name ) // command line option '-save filename' { printf( "The current plot was saved in color Postscript under the name `%s'.\n", f_name ); plgstrm( &cur_strm ); // get current stream plmkstrm( &new_strm ); // create a new one plsfnam( f_name ); // file name plsdev( "psc" ); // device type plcpstrm( cur_strm, 0 ); // copy old stream parameters to new stream plreplot(); // do the save by replaying the plot buffer plend1(); // finish the device plsstrm( cur_strm ); // return to previous stream } // Let's get some user input if ( locate_mode ) { for (;; ) { if ( !plGetCursor( &gin ) ) break; if ( gin.keysym == PLK_Escape ) break; pltext(); printf( "subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f\n", gin.subwindow, gin.wX, gin.wY, gin.dX, gin.dY ); printf( "keysym = 0x%02x, button = 0x%02x, string = '%s', type = 0x%02x, state = 0x%02x\n", gin.keysym, gin.button, gin.string, gin.type, gin.state ); plgra(); } } // Don't forget to call plend() to finish off! plend(); exit( 0 ); }
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); }
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(); }
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(); }
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 }
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]); } }