if (GetPlotMode() == 2)
{
	// The next bit of code is common to
	// all styles of Agraph.
	// If an Agraph does not exist,
	// the DAYs of it are here synchronised
	// with the current Lambda data-series.
if (
	(PlotAgraph  && !_is.rAgraphExists)
	  ||
	(mPlotAgraph && !_is.mAgraphExists)
	  ||
	(LPlotSynAgr && !_is.SynAgrExists)
	  ||
	(mLPlotSynAgr && !_is.mSynAgrExists)
   ) 
	{
		epDat = epData = align->epfirst ;   // the first data epoch

		// Make sure we use the
		// first in-series alignment,
		// as there may be one found
		// just before the data begins.

		// This is actually redundant, as its
		// function is now performed in Astron.h,
		// but we'll leave it as an extra safeguard!

		k = 1 ; // "found" indices start at 1.
		while ( epDat > floor(epAl = Date_Time[UsePlanet][k]->epal)) k++ ;
		// Should emerge from this with k selecting the first
		// in-series alignment epoch. Check this!

		if (floor(Date_Time[UsePlanet][k]->epal) < epDat)
		{
			msgbox = 1 ;
			MessageBox(NULL,"Oops! Adjusted.","Date Short Fall.",
				       MB_ICONEXCLAMATION|MB_OK) ;
			msgbox = 0 ;
			k++ ;
		}

		// Go find the data day corresponding
	    // the first in-series alignment, call
	    // it DAY ONE, and note the index of
		// the day before.

		alignday[0] = 0 ;
		while ( epDat < floor(epAl)) {epDat += 1.0 ; ++alignday[0] ;}

    	prevday = alignday[0] - 1 ; // the day before

		// Now list the data-day indices for the
		// remaining in-series alignments.

		k++ ;	// point to next alignment (the second)

		for ( i = 1, DAYS = -200 ; k <= align->found ; k++)
		{
		// find the largest IAP
	      if ((DY = (int)(floor(Date_Time[UsePlanet][  k]->epal) -
		                  floor(Date_Time[UsePlanet][k-1]->epal))) > DAYS)
		                  DAYS = DY ;
		   
		 alignday[i++] = (int)(floor(Date_Time[UsePlanet][k]->epal) - floor(epData)) ;
		}

		// Find the IAP pertaining to the section
		// of the data prior to the first in-series
		// alignment. See Astron.h for an explanation
		// of the method.

		PREDAYS = (int) floor(Date_Time[UsePlanet][1]->epal - Date_Time[0][UsePlanet]->epal) ;

		// it may be the largest IAP

		if (PREDAYS > DAYS) DAYS = PREDAYS ;
	}

	// If it doesn't already exist, compile direct or synthetic Agraph on Raw Data

	 if (
		 PlotAgraph  && !_is.rAgraphExists
		   ||
		 LPlotSynAgr && !_is.SynAgrExists
		) 
	{
		// Initialise the sums, etc., to zero.
		for (i = 0 ; i < 17 ; rTotal[i] = rItems[i++] = 0.0) ;

		// Allocate arrays to hold DAYly data values
		// for calculation of standard deviations
		for ( i = 0 ; i < 17 ; i++ )
		{
		 if
		 ((rData[i] = (double *)GlobalAlloc(GPTR, 100 * sizeof(double)))
		  == NULL )
		 {
		  msgbox = 1 ;
		  MessageBox( NULL,
		             "Allocation Failure",
					 "Raw Agraph",
			          MB_OK|MB_ICONEXCLAMATION ) ;
		  msgbox = 0 ;
		 }
		}

		// Start summing up the data
		// in cycles, from alignment
		// day to alignment day, until
		// the end of the list.

		for ( i = alignday[0], k = 0, DAY = 1 ; i < bud ; i++ )  
		{
		  // If the current data-day index
		  // falls on an alignment date,
		  // restart the DAY cycle, and
		  // advance to next alignday. Else,
		  // just fill DAYs as they come.

		  if (alignday[k] == i) { DAY = 1 ; k++ ; }

		  // using raw data,
		  // add current data to DAY's total
		  if (LPlotSynAgr)
		  rTotal[DAY] += pFourier->sOneDay[i] ;
		  else
		  rTotal[DAY] += pFourier->data[i] ;

		  // increment DAY's data item count.
		  // we're using a double for this.
		  rItems[DAY] += 1.0 ;

		  // point to DAY's data array.
		  rd = rData[DAY] ;

		  // enter the current data value.
		  if (LPlotSynAgr)
		  rd[(int)rItems[DAY]] = pFourier->sOneDay[i] ;
		  else
		  rd[(int)rItems[DAY]] = pFourier->data[i] ;

		  // move on by one DAY.
		  DAY++ ;
		}

		// Now, working backwards from prevday,
		// and from DAY 'PREDAYS', fill in the omitted
		// data from the first part of the data list.

		for ( i = prevday, DAY = PREDAYS ; i >= 0 ; i-- )
		{
			 // using raw direct or synthesised data
		  if (LPlotSynAgr)
		  rTotal[DAY] += pFourier->sOneDay[i] ;
		  else
		  rTotal[DAY] += pFourier->data[i] ;
		  
		  rItems[DAY] += 1.0 ;

		  // point to DAY's data array
		  rd = rData[DAY] ;

		  // enter the current data value
		  if (LPlotSynAgr)
		  rd[(int)rItems[DAY]] = pFourier->sOneDay[i] ;
		  else
		  rd[(int)rItems[DAY]] = pFourier->data[i] ;

		  // move one day back
			DAY-- ;
		}

		for (i = 1,
			 rhiAg = -1.0e5,
			 rloAg =  1.0e5 ;
		     i <= DAYS ;
			 i++ )
		{
				 double devsum ;

			// Convert totals to means
			rTotal[i] /= rItems[i] ;
			
			// Find greatest and least means, and the DAY of the least mean
			rhiAg = (rTotal[i] > rhiAg) ? rTotal[i] : rhiAg ;
			if (rTotal[i] < rloAg)
			{ rloAg = rTotal[i] ; rLODAY = i ; }

			// Find standard deviation

			   rd = rData[i] ; // point to the DAY's data array.

		    // Sum up the squares of the DAY's deviations
			for (
				 j = 1, devsum = 0.0 ;
			     j <= (int)rItems[i] ;
				 j++
				)
				  devsum += pow(rd[j] - rTotal[i], 2.0) ;

		    // Get the mean of the DAY's squared deviations.
			// This is the DAY's Standard Deviation.
			  rStdDev[i] = sqrt(devsum / rItems[i]) ; 
		}

		   // Set the plotting limits
			rhi_Y =  ceil(10.0 * rhiAg) / 10.0 ;
			rlo_Y = floor(10.0 * rloAg) / 10.0 ;

		   // Free allocations
			for ( i = 0 ; i < 17 ; i++ )
				if (rData[i] != NULL)
				GlobalFree( rData[i] ) ;

			if (LPlotSynAgr)
			_is.SynAgrExists = 1 ;
			else
			_is.rAgraphExists = 1 ;
	 }

	 if (
		 PlotAgraph  // Plot Agraph on Raw Data.
		   ||		 // or
		 LPlotSynAgr // Plot Synthetic Agraph on Raw Data.
		)
	 {

			SelectObject(hdc, palePen) ;
	        SelectObject(hdc, hfnt) ;
	        SetBkColor(hdc, RGB(255,255,255) ) ;
	        SetTextColor(hdc, RGB(255,0,0) ) ;
			SetBkMode( hdc, OPAQUE ) ;

		 // Report what we're showing.
			if (LPlotSynAgr)
			sprintf(buff,"Bud %s over %s on Synthesised Raw Data",
			        BudSearch->Prefix, plname[align->body]) ;
			else
			sprintf(buff,"Bud %s over %s on Raw Data",
			        BudSearch->Prefix, plname[align->body]) ;
			TextOut(hdc, xlmar, D.top - 18, buff, strlen(buff)) ;

		 // If we have the running-mean Agraph, we
		 // may want to plot it with the Raw Agraph
		 // on the same chart. To match scales, and
		 // still obtain the "least chart", we select
		 // the wider of the two sets of plotting-
		 // limits for it.
			
			if (LPlotSynAgr) // is the synthesised raw agraph
			{
				if (_is.mSynAgrExists)
				{
				clo_Y = (mlo_Y < rlo_Y) ? mlo_Y : rlo_Y ;
				chi_Y = (mhi_Y > rhi_Y) ? mhi_Y : rhi_Y ;
				}
			else // Only the synthesised raw Agraph is currently 
				 // available. Use its limits. 
				{
				clo_Y = rlo_Y ;
				chi_Y = rhi_Y ;
				}
			}
			else // is the direct agraph
			{
				if (_is.mAgraphExists)
				{
				clo_Y = (mlo_Y < rlo_Y) ? mlo_Y : rlo_Y ;
				chi_Y = (mhi_Y > rhi_Y) ? mhi_Y : rhi_Y ;
				}
			else // Only the raw Agraph is currently 
				 // available. Use its limits. 
				{
				clo_Y = rlo_Y ;
				chi_Y = rhi_Y ;
				}
			}

			// Vertical graticule, and notation in red on left.
			for ( u = clo_Y ; u <= chi_Y ; u += 0.1)
			{
				yp = rcArc.bottom -
					(int)((double)ht * (u - clo_Y)/(chi_Y - clo_Y) +
					(double)ylmar) ;
				xp = D.left ;
				MoveToEx(hdc, xp, yp, NULL) ;
				xp = D.right ;
				LineTo(hdc, xp, yp) ;
				sprintf(buff,"%2.1f", u) ;
				TextOut(hdc, 10, yp - 8, buff, strlen(buff)) ; 
			}

			// Horizontal graticule, and notation in black.
			SetTextColor(hdc, RGB(  0,  0,  0)) ;

			for ( i = 0 ; i < 14 ; i++ )
			{
				xp = (int)((double)(wd * i) / 14.0) + xlmar ;
				yp = D.top ;
				MoveToEx(hdc, xp, yp, NULL) ;
				yp = D.bottom ;
				LineTo(hdc, xp, yp) ;
				sprintf(buff, "%2.2d", i + 1 ) ;
				TextOut(hdc, xp - 4, D.bottom + 2, buff, strlen(buff)) ;
			}
			// DAY one will be re-plotted as the last on the right.
				sprintf(buff, "%2.2d", 1 ) ;
				xp = (int)((double)(wd * 14) / 14.0) + xlmar ;
				TextOut(hdc, xp - 4, D.bottom + 2, buff, strlen(buff)) ;

		   // Plot the raw data, and list the numbers of Lambda values
		   // per DAY along the top, and the corresponding Standard
		   // Deviations along the bottom.
	    
		    SelectObject(hdc,redPen) ;

	for ( i = 0 ; i < 14 ; i++)
	{
		xp = (int)((double)(wd * i)/14.0) + xlmar ;
		yp = rcArc.bottom -
			(int)((double)ht * (rTotal[i+1] - clo_Y) / (chi_Y - clo_Y) +
			(double)ylmar) ;

	 // numbers per DAY in black	
		SetTextColor(hdc, RGB(  0,   0,   0)) ;
	 // let background peep through	
		   SetBkMode(hdc, TRANSPARENT) ; 
		sprintf(buff,"N=%d",(int)rItems[i+1]) ;
 		GetTextExtentPoint32(hdc, buff, strlen(buff), &sz) ;
	 // along the top
		TextOut(hdc,xp - sz.cx/2, D.top + sz.cy/4, buff, strlen(buff)) ;

	 // S.D.s in red
		SetTextColor(hdc, RGB(255,   0,   0)) ; 
		sprintf(buff,"%4.3f",rStdDev[i+1]) ;
 		GetTextExtentPoint32(hdc, buff, strlen(buff), &sz) ;
	 // along the bottom
		TextOut(hdc,xp - sz.cx/2, D.bottom - sz.cy,buff,strlen(buff)) ;

		if (i == 0)
			MoveToEx(hdc, xp, yp, NULL) ;
		else
			LineTo(hdc, xp, yp) ;
	}
	  // Plot to DAY one again to complete the graph,
	  // but don't bother repeating the numbers etc.  
		xp = (int)((double)(wd * 14.0)/14.0) + xlmar ;
		yp = rcArc.bottom -
			(int)((double)ht * (rTotal[1] - clo_Y) / (chi_Y - clo_Y) +
			(double)ylmar) ;
		LineTo(hdc, xp, yp) ;

	 } // if (PlotAgraph)

   // If it does not already exist, compile Moving-Mean Agraph.

	 if (
		 mPlotAgraph && !_is.mAgraphExists
		  ||
		 mLPlotSynAgr && !_is.mSynAgrExists
		) 
	{
		// Initialise the sums, etc., to zero.
		for (i = 0 ; i < 17 ; mTotal[i] = mItems[i++] = 0.0) ;

		// Allocate arrays to hold DAYly data values
		// for calculation of standard deviations
		for ( i = 0 ; i < 17 ; i++ )
		{
		 if
		 ((mData[i] = (double *)GlobalAlloc(GPTR, 100 * sizeof(double)))
		  == NULL )
		 {
			 msgbox = 1 ;
		  MessageBox( NULL,
		             "Allocation Failure",
					 "Moving Mean Agraph",
			          MB_OK|MB_ICONEXCLAMATION ) ;
		     msgbox = 0 ;
		 }
		}

		  // If the current data-day index
		  // falls on an alignment date,
		  // restart the DAY cycle, and
		  // advance to next alignday. Else,
		  // just fill DAYs as they come.

		for ( i = alignday[0], k = 0, DAY = 1; i < bud ; i++ )  
		{
		  if (alignday[k] == i) { DAY = 1 ; k++ ;}
		  if (mLPlotSynAgr)
		  mTotal[DAY] += pFourier->msOneDay[i] ;
		  else
		  mTotal[DAY] += pFourier->mdata[i] ; // using mean data
		  mItems[DAY] += 1.0 ;
		  md = mData[DAY] ;
		  if (mLPlotSynAgr)
		  md[(int)mItems[DAY]] = pFourier->msOneDay[i] ;
		  else
		  md[(int)mItems[DAY]] = pFourier->mdata[i] ;
		  DAY++ ;
		}

		// Now, working backwards from prevday,
		// and from DAY 'PREDAYS', fill in the omitted
		// data from the first part of the data
		// list.

		for ( i = prevday, DAY = PREDAYS ; i >= 0 ; i-- )
		{
		  if (mLPlotSynAgr)
		  mTotal[DAY] += pFourier->msOneDay[i] ;
		  else
		  mTotal[DAY] += pFourier->mdata[i] ; // using mean data
		  mItems[DAY] += 1.0 ;
		  md = mData[DAY] ;
		  if (mLPlotSynAgr)
		  md[(int)mItems[DAY]] = pFourier->msOneDay[i] ;
		  else
		  md[(int)mItems[DAY]] = pFourier->mdata[i] ;
			DAY-- ;
		}

		for (i = 1,
			 mhiAg = -1.0e5,
			 mloAg =  1.0e5 ;
		     i <= DAYS ;
			 i++ )
		{
				 double devsum ;
		// convert totals to means
			mTotal[i] /= mItems[i] ;
		// find greatest and least means, and the DAY of the least mean
			mhiAg = (mTotal[i] > mhiAg) ? mTotal[i] : mhiAg ;
			if (mTotal[i] < mloAg)
			{ mloAg = mTotal[i]; mLODAY = i; }

			// Find standard deviation

			  md = mData[i] ; // Point to the DAY's data array
			for (
				 j = 1, devsum = 0.0 ;
			     j <= (int)mItems[i] ;
				 j++
				)
				   devsum += pow(md[j] - mTotal[i], 2.0) ;

			  mStdDev[i] = sqrt(devsum / mItems[i]) ;
		}

			mhi_Y =  ceil(10.0 * mhiAg) / 10.0 ;
			mlo_Y = floor(10.0 * mloAg) / 10.0 ;

			  
		   // Free allocations
			for ( i = 0 ; i < 17 ; i++ )
				if (mData[i] != NULL)
				GlobalFree( mData[i] ) ;

			if (mLPlotSynAgr)
				_is.mSynAgrExists = 1 ;
			else
				_is.mAgraphExists = 1 ;
	 }

	 if (
		 mPlotAgraph   // Plot Moving-Mean Agraph
		   ||
		 mLPlotSynAgr  // Plot Moving-Mean Synthetic Agraph
		)
	 {

			SelectObject(hdc, palePen) ;
	        SelectObject(hdc, hfnt) ;
	        SetBkColor(  hdc, RGB(255,255,255) ) ;
	        SetTextColor(hdc, RGB(  0,  0,255) ) ;
			SetBkMode( hdc, OPAQUE ) ;

			if (mLPlotSynAgr)
			sprintf(buff,"Bud %s over %s on Synthesised Moving-Mean Data",
			        BudSearch->Prefix, plname[align->body]) ;
			else
			sprintf(buff,"BUD %s over %s on Moving-Mean Data",
				BudSearch->Prefix, plname[align->body]) ;
			TextOut(hdc, xlmar, D.top - 34, buff, strlen(buff)) ;

			if (mLPlotSynAgr) // is synthesised mean agraph
			{
				if (_is.SynAgrExists) // use widest chart limits.
				{
				clo_Y = (mlo_Y < rlo_Y) ? mlo_Y : rlo_Y ;
				chi_Y = (mhi_Y > rhi_Y) ? mhi_Y : rhi_Y ;
				}
				else // no raw Agraph. Use mean Agraph's chart limits.
				{
				clo_Y = mlo_Y ;
				chi_Y = mhi_Y ;
				}
			}
			else // is direct mean agraph
			{
				if (_is.rAgraphExists) // use widest chart limits.
				{
				clo_Y = (mlo_Y < rlo_Y) ? mlo_Y : rlo_Y ;
				chi_Y = (mhi_Y > rhi_Y) ? mhi_Y : rhi_Y ;
				}
				else // no raw Agraph. Use mean Agraph's chart limits.
				{
				clo_Y = mlo_Y ;
				chi_Y = mhi_Y ;
				}
			}

			for ( u = clo_Y ; u <= chi_Y ; u += 0.1)
			{
				yp = rcArc.bottom -
					(int)((double)ht * (u - clo_Y)/(chi_Y - clo_Y) +
					(double)ylmar) ;
				xp = D.left ;
				MoveToEx(hdc, xp, yp, NULL) ;
				xp = D.right ;
				LineTo(hdc, xp, yp) ;
				sprintf(buff,"%2.1f", u) ;
				TextOut(hdc, D.right + 8, yp - 8, buff, strlen(buff)) ; 
			}

			SetTextColor(hdc, RGB(  0,  0,  0)) ;

			for ( i = 0 ; i < 14 ; i++ )
			{
				xp = (int)((double)(wd * i) / 14.0) + xlmar ;
				yp = D.top ;
				MoveToEx(hdc, xp, yp, NULL) ;
				yp = D.bottom ;
				LineTo(hdc, xp, yp) ;
				sprintf(buff, "%2.2d", i + 1 ) ;
				TextOut(hdc, xp - 4, D.bottom + 2, buff, strlen(buff)) ;
			}
				sprintf(buff, "%2.2d", 1 ) ;
				xp = (int)((double)(wd * 14) / 14.0) + xlmar ;
				TextOut(hdc, xp - 4, D.bottom + 2, buff, strlen(buff)) ;
	    
		    SelectObject(hdc,bluePen) ;
	for ( i = 0 ; i < 14 ; i++)
	{
		xp = (int)((double)(wd * i)/14.0) + xlmar ;
		yp = rcArc.bottom -
			(int)((double)ht * (mTotal[i+1] - clo_Y) / (chi_Y - clo_Y) +
			(double)ylmar) ;

		SetTextColor(hdc, RGB(  0,   0,   0)) ;	// black
		   SetBkMode(hdc, TRANSPARENT) ;
		sprintf(buff,"N=%d",(int)mItems[i+1]) ;
 		GetTextExtentPoint32(hdc, buff, strlen(buff), &sz) ;
		TextOut(hdc,xp - sz.cx/2, D.top + sz.cy/4, buff, strlen(buff)) ;

		SetTextColor(hdc, RGB(  0,   0, 255)) ; // blue
		sprintf(buff,"%4.3f",mStdDev[i+1]) ;
 		GetTextExtentPoint32(hdc, buff, strlen(buff), &sz) ;
		TextOut(hdc,xp - sz.cx/2, D.bottom - 2 * sz.cy,buff,strlen(buff)) ;

		if (i == 0)
			MoveToEx(hdc, xp, yp, NULL) ;
		else
			LineTo(hdc, xp, yp) ;

	}
		xp = (int)((double)(wd * 14.0)/14.0) + xlmar ;
		yp = rcArc.bottom -
			(int)((double)ht * (mTotal[1] - clo_Y) / (chi_Y - clo_Y) +
			(double)ylmar) ;
		LineTo(hdc, xp, yp) ;

	 } // if (mPlotAgraph)
}