src/GamIO/FrameMaker.cc
/*************************************************************************
**									**
** 		         FrameMaker Histogram Plots			**
**									**
** Author	: SOSI 							**
** Description  : Takes a vector from input along with plot parameters	**
**		  and produces a FrameMaker file containing a histogram **
**		  plot of the vector.					**
**									**
*************************************************************************/


Author : SOSI
Description  : Takes a vector from input along with plot parameters
and produces a FrameMaker file containing a histogram
plot of the vector.
Author : SOSI Description : Takes a vector from input along with plot parameters and produces a FrameMaker file containing a histogram plot of the vector .
void FM_histogram(const std::string& filename, row_vector &vx, int bins,
                                                   double xsize, double ysize)
  {
  int pts = vx.elements();
  if((xsize < 5)||(xsize > 20))
		    xsize = 14;	
  if((ysize < 5)||(ysize > 27))
		    ysize = 14;
  double xmin, xmax;		
  FM_maxima(vx, xmin, xmax, 0);	
  if(xmax == xmin)
    FM_fatality(11);
  if(bins<=0 || bins>pts)	
    bins = pts;
  double width=(xmax-xmin)/bins;
  row_vector hist(bins, xmin);	
  int bin;
  for(bin=0;bin<bins;bin++)	
    hist.put(hist(bin)+(bin+0.5)*width, bin);
  double x, y, xst, xfi;	
  int search;
  for(int j=0; j<pts; j++) 	
    {
    xst = xmin;
    xfi = width;
    y = Im(vx(j));
    x = Re(vx(j));
    search = 1;
    bin=0;
    while((search) && (bin<bins))
      {
      if((x > xst) && (x < xfi))
        {
        hist.put(hist(bin)+complex(0, y), bin);
        search = 0;
        }
      else if(x == xmin)
        {
        hist.put(hist(bin)+complex(0, y), bin);
        search = 0;
        }
      else if(x == xmax)
        {
        hist.put(hist(bins-1) + complex(0, y), bins-1);
        search = 0;
        }
      else if(x == xst)
        {
        hist.put(hist(bin)+0.5*complex(0, y), bin);
        hist.put(hist(bin+1)+0.5*complex(0, y), bin+1);
        search = 0;
        }
      else if(x == xfi)
        {
        hist.put(hist(bin) + 0.5*complex(0, y), bin);
        hist.put(hist(bin+1) + 0.5*complex(0, y), bin+1);
        search = 0;
        }
      xst += width;
      xfi += width;
      bin++;
      }
    }
  double ymin, ymax;			
  FM_maxima(hist, ymin, ymax, 1);
  double top, bottom, right, left;	
  FM_borders(xsize, ysize,		
             top, bottom, right, left);
  double yscale =			
	      (top-bottom)/(ymax-ymin);	
  double xscale =
	      (right-left)/(xmax-xmin);
  std::ofstream out(filename.c_str());	
  FM_Begin(out);			
  FM_AFrames_Begin(out);		
  FM_AFrame_Set (out, xsize, ysize);	
  double height, xinit, yinit;		
  width *= xscale;			
  xinit = left-width/2;
  yinit = bottom - (ymin*yscale);
  for (int i=0; i<bins; i++)
    {
    x = xinit + Re(hist(i))*xscale;
    y = yinit + Im(hist(i))*yscale;
    height = (ymin-Im(hist(i)))*yscale;
    FM_Rectangle(out, 20, x , y, width, height);
    }
  FM_Axis(out, 'x', bottom,
       left, right, xmin, xmax);	
//  FM_Line (out,8,0,1,left,		 line
//  FM_Axis_tics(out, 8, 'x', bottom,	 tics
//  FM_Axis_tics(out, 8, 'x', bottom,	 tics
  FM_Axis (out, 'y', left,
       bottom, top, ymin, ymax);	
  FM_Group (out, 20, 21);		
  FM_AFrame_End(out);			
  FM_AFrames_End(out);			
  FM_ParaText_End(out);			
  FM_End(out);				
  }
void FM_histogram ( const std :: string & filename , row_vector & vx , int bins , double xsize , double ysize ) { int pts = vx . elements ( ) ; if ( ( xsize < 5 ) || ( xsize > 20 ) ) xsize = 14 ; if ( ( ysize < 5 ) || ( ysize > 27 ) ) ysize = 14 ; double xmin , xmax ; FM_maxima ( vx , xmin , xmax , 0 ) ; if ( xmax == xmin ) FM_fatality ( 11 ) ; if ( bins <= 0 || bins > pts ) bins = pts ; double width = ( xmax - xmin ) / bins ; row_vector hist ( bins , xmin ) ; int bin ; for ( bin = 0 ; bin < bins ; bin ++ ) hist . put ( hist ( bin ) + ( bin + 0.5 ) * width , bin ) ; double x , y , xst , xfi ; int search ; for ( int j = 0 ; j < pts ; j ++ ) { xst = xmin ; xfi = width ; y = Im ( vx ( j ) ) ; x = Re ( vx ( j ) ) ; search = 1 ; bin = 0 ; while ( ( search ) && ( bin < bins ) ) { if ( ( x > xst ) && ( x < xfi ) ) { hist . put ( hist ( bin ) + complex ( 0 , y ) , bin ) ; search = 0 ; } else if ( x == xmin ) { hist . put ( hist ( bin ) + complex ( 0 , y ) , bin ) ; search = 0 ; } else if ( x == xmax ) { hist . put ( hist ( bins - 1 ) + complex ( 0 , y ) , bins - 1 ) ; search = 0 ; } else if ( x == xst ) { hist . put ( hist ( bin ) + 0.5 * complex ( 0 , y ) , bin ) ; hist . put ( hist ( bin + 1 ) + 0.5 * complex ( 0 , y ) , bin + 1 ) ; search = 0 ; } else if ( x == xfi ) { hist . put ( hist ( bin ) + 0.5 * complex ( 0 , y ) , bin ) ; hist . put ( hist ( bin + 1 ) + 0.5 * complex ( 0 , y ) , bin + 1 ) ; search = 0 ; } xst += width ; xfi += width ; bin ++ ; } } double ymin , ymax ; FM_maxima ( hist , ymin , ymax , 1 ) ; double top , bottom , right , left ; FM_borders ( xsize , ysize , top , bottom , right , left ) ; double yscale = ( top - bottom ) / ( ymax - ymin ) ; double xscale = ( right - left ) / ( xmax - xmin ) ; std :: ofstream out ( filename . c_str ( ) ) ; FM_Begin ( out ) ; FM_AFrames_Begin ( out ) ; FM_AFrame_Set ( out , xsize , ysize ) ; double height , xinit , yinit ; width *= xscale ; xinit = left - width / 2 ; yinit = bottom - ( ymin * yscale ) ; for ( int i = 0 ; i < bins ; i ++ ) { x = xinit + Re ( hist ( i ) ) * xscale ; y = yinit + Im ( hist ( i ) ) * yscale ; height = ( ymin - Im ( hist ( i ) ) ) * yscale ; FM_Rectangle ( out , 20 , x , y , width , height ) ; } FM_Axis ( out , ' ' , bottom , left , right , xmin , xmax ) ; FM_Axis ( out , ' ' , left , bottom , top , ymin , ymax ) ; FM_Group ( out , 20 , 21 ) ; FM_AFrame_End ( out ) ; FM_AFrames_End ( out ) ; FM_ParaText_End ( out ) ; FM_End ( out ) ; }
FrameMaker Histogram Plots
FrameMaker Histogram Plots
// Input	filename  : FrameMaker mif file name // 		vx        : Data vector containing points //		bin       : Number of bins in histogram // 		xsize     : Horizontal plot size in cm. // 		ysize     : Vertical plot size in cm. // Return		  : Void, FrameMaker plot file output // Insure plot sizes sensible // Insure data has horizontal spread // (units here still that of vx) // Insure number of bins sensible // Compute bin width (vx units) // Decare histogram array & fill // in bin horizontal coordinates // Loop over all points of vx // and find bin(s) where it belongs // Calculate vertical maxima // Declare and set margins // these are in centimeters // Declare & compute scaling factors // xscale, yscale in cm/vx(scales) // Open file, begin plot // FrameMaker begin comment // Anchored Frame begin // Header of Frame // Switch from original vx units // to centimeters and output bins // Output x axis //  FM_Line (out,8,0,1,left,		// Output x axis line // 		   bottom,right,bottom); //  FM_Axis_tics(out, 8, 'x', bottom,	// Output x axis tics //	      left, right, xmin, xmax); //  double delx = Re(hist(1))-Re(hist(0)); //  FM_Axis_tics(out, 8, 'x', bottom,	// Output x axis tics //     left+0.5*width, right-0.5*width, //	 xmin+0.5*delx, xmax-0.5*delx); //  FM_Group (out, 8);			// Group x axis line, tics // Output y axis // Group Histogram // Tail of Frame // Anchored Frame end // Create a TextFlow with Frame // FrameMaker end comment