{
	int noyear, nomonth, noday ;

	noyear = nomonth = noday = 1 ;	// presume none of these is shown

	// vertical axis, horizontal grid lines

	if (!NoHorizontal) // set in preferences - leave out horizontal graticule lines
	{
			if (ShowLambdaScale && UseScale == 1) // lambda graticule only if showing some Lambdas 
			{
		      oPen = SelectObject(hdc, palePen) ;
			  for ( u = lo_y ; u <= hi_y ; u += minor)
			  {
				yp = rcArc.bottom -
					(int)((double)ht * (u - lo_y) / (hi_y - lo_y) + 
					(double)ylmar) ;
			   if ( u != lo_y || u != hi_y )
			   {
				xp = D.left ;
				MoveToEx(hdc, xp , yp, NULL) ;
				xp = D.right ;
				LineTo(hdc, xp, yp ) ;
			   }
		     }
			  SelectObject(hdc, oPen) ;
	       }

		   if (UseScale == 2) // alignment graticule
		   {
		      oPen = SelectObject(hdc, palePen) ;
			 for ( u = -0.5 ; u <= 0.5 ; u += 0.1)
			 {
				yp = rcArc.bottom -
					(int)((double)ht * (u + 0.5)
					+ (double)ylmar) ;
				xp = D.left ;
				MoveToEx(hdc, xp, yp, NULL) ;
				xp = D.right ;
				LineTo(hdc, xp, yp) ;
			 }
			  SelectObject(hdc, oPen) ;
		   }

		   if (UseScale == 3) // degree graticule 0 - 180
		   {
		      oPen = SelectObject(hdc, palePen) ;
			   for ( i = 0 ; i <= 180 ; i += 5 )    // every 5 degrees
			   {
			   yp = rcArc.bottom -
				   (int)((double)(ht * i) / 180.0 + (double)ylmar) ;
			   xp = D.left ;
			   MoveToEx(hdc, xp, yp, NULL) ;
			   xp = D.right ;
			     LineTo(hdc, xp, yp) ;
			   }
			  SelectObject(hdc, oPen) ;

		      oPen = SelectObject(hdc, ltbluePen) ;
			   for ( i = 0 ; i <= 180 ; i += 45 )    // every 45 degrees
			   {
			   yp = rcArc.bottom -
				   (int)((double)(ht * i) / 180.0 + (double)ylmar) ;
			   xp = D.left ;
			   MoveToEx(hdc, xp, yp, NULL) ;
			   xp = D.right ;
			     LineTo(hdc, xp, yp) ;
			   }
			  SelectObject(hdc, oPen) ;
		   }
	}

		   SelectObject(hdc, hfnt1) ;
		   SetBkColor(  hdc, RGB(192,192,192)) ;
		   SetTextColor(hdc, RGB(  0,  0,  0)) ;
		   SetBkMode(   hdc, TRANSPARENT) ;

				// sort out horizontal scale label clutter (tchart is in days)

		   ppd = (double)wd / tchart ;						// pixels per day
		yrwid  = (int)(   leapyear * ppd ) ;				// pixels between   year markers (max possible)
		monwid = (int)(       31.0 * ppd ) ;				// pixels between  month markers (max possible)
		daywid = (int)(				 ppd ) ;				// pixels between    day markers
		hrwid  = (int)((double)wd / (   24.0 * tchart)) ;	// pixels between   hour markers
		mnwid  = (int)((double)wd / ( 1440.0 * tchart)) ;	// pixels between minute markers
		scwid  = (int)((double)wd / (86400.0 * tchart)) ;	// pixels between second markers

					
				    GetTextExtentPoint32(hdc, "OOOO ", 5, &sz) ;		// pixels for a full year label
						pixperbigyrlab = sz.cx ;
				    GetTextExtentPoint32(hdc, "OO ",   3, &sz) ;		// pixels for a short year label
						pixperweeyrlab = sz.cx ;
				    GetTextExtentPoint32(hdc, "OOO ",  4, &sz) ;		// pixels for a full month label
						pixperbigmnlab = sz.cx ;
				    GetTextExtentPoint32(hdc, "OO ",   3, &sz) ;		// pixels for a short month label
						pixperweemnlab = sz.cx ;
				    GetTextExtentPoint32(hdc, "7 14 21 28 ", 11, &sz) ; // pixels for week labels
						pixperwklab = sz.cx ;

// year labels
					do_wee_yr_name = 0 ;
				// do full year labels if room
					do_yr_name = (yrwid < pixperbigyrlab) ? 0 : 1 ;
				// if unable to draw full-year labels, try for short ones
					if (!do_yr_name)// if can't do short labels either, do neither kind
					do_wee_yr_name = (yrwid < pixperweeyrlab) ? 0 : 1 ;
					
// month labels
					do_wee_mo_name = 0 ;
				// do full month label if room
					do_mo_name = (monwid < pixperbigmnlab) ? 0 : 1 ;
				// if can't do full month labels, try for short ones
					if (!do_mo_name)// if can't do short month labels either, do neither kind 
					do_wee_mo_name = (monwid < pixperweemnlab) ? 0 : 1 ;
// month graticule
					do_mon_marks = (monwid < 6)   ? 0 : 1 ;			// do month lines/marks if room
// week labels
					do_week_marks = (monwid < pixperwklab) ? 0 : 1 ;// do week-in-month labels and lines if room

																	// pixels per hour:minute or 
					GetTextExtentPoint32(hdc, "OO:OO ", 6, &sz) ;	// per minute:second label
					do_hm_name = (hrwid < sz.cx) ? 0 : 1 ;			// do  hr:min label if room
					do_ms_name = (mnwid < sz.cx) ? 0 : 1 ;			// do min:sec label if room

					do_day_marks = (daywid < 4)  ? 0 : 1 ;			// do day lines/marks if room

					if (floor(tchart) > 1.0) // if more than one day in the chart span
					{
					do_day_num = 1 ;
					sprintf( str, " %d ", (int)tchart) ; // largest possible number of days
				    GetTextExtentPoint32(hdc, str, strlen(str), &sz) ;	// pixels for largest day-number label
					daysstep = 0 ; // get the least fittable day step size in intervals of 5
					while (daysstep * wd / (int)tchart < sz.cx) daysstep += 5 ;
					} else do_day_num = 0 ;

		{
			double eptmp ;
			  char buff[50] ;
			   int s ;
			  SIZE sz ;

				eptmp = ep ;

				// we enter the chart construction loop here

				for (
					 ep  = lochart ;	// from the lowest chart epoch
				     ep <= hichart ;	// up to and including the highest chart epoch
					 ep += stu			// increment by appropriate time interval
					)
				{
					civildate() ; // now also provides hour, minute and second (I hope!)

					if (!sc && !mn && !hr && day == 1 && mo == 1) {timecase = tYEAR ;   goto target ;}
					if (!sc && !mn && !hr && day == 1)			  {timecase = tMONTH ;  goto target ;}
					if (!sc && !mn && !hr && !(day%7))			  {timecase = tWEEK ;   goto target ;}
					if (!sc && !mn && !hr)						  {timecase = tDAY ;    goto target ;}
					if (!sc && !mn)								  {timecase = tHOUR ;   goto target ;}
					if (!sc)									  {timecase = tMINUTE ; goto target ;}
					if ( sc)									  {timecase = tSECOND ; goto target ;}

target:		switch(timecase)
			{

			case tSECOND: // it is the start of some non-zero calendar second
						  //SelectObject(hdc, plbluePen) ;
				break ;

			case tMINUTE:	// it is the start of a calendar minute
					{
						xp = ep2xp(ep) ;

						oPen = SelectObject(hdc, palePen) ; // minute line
						yp = D.top ;      MoveToEx(hdc, xp, yp, NULL) ;
						yp = D.bottom ;     LineTo(hdc,xp, yp) ;
						SelectObject(hdc, oPen) ;
					/*
						oPen = SelectObject(hdc, blackPen) ;			// minute tick
						yp = D.top + 6  ; MoveToEx(hdc, xp, yp, NULL) ;	// descent
						yp = D.top - 4 ;    LineTo(hdc, xp, yp) ;		// ascent
						SelectObject(hdc, oPen) ;
					*/
					}
				break ;

			case tHOUR:		// it is the start of a calendar hour
					{
						xp = ep2xp(ep) ;

						oPen = SelectObject(hdc, grayPen) ;				// hour line
						yp = D.top ;  MoveToEx(hdc, xp, yp, NULL) ;
						yp = D.bottom ; LineTo(hdc,xp, yp) ;
						SelectObject(hdc, oPen) ;

						oPen = SelectObject(hdc, blackPen) ;			// hour tick
						yp = D.top + 6  ; MoveToEx(hdc, xp, yp, NULL) ;	// descent
						yp = D.top - 4 ;    LineTo(hdc, xp, yp) ;		// ascent
						SelectObject(hdc, oPen) ;
					}
				break ;

			case tDAY:		// it is the start of a calendar day
				{
					  if (do_day_marks)
					  {
						xp = ep2xp(ep) ;

						oPen = SelectObject(hdc, palePen) ;					// day line
						yp = D.top ;  MoveToEx(hdc, xp, yp, NULL) ;
						yp = D.bottom ; LineTo(hdc,xp, yp) ;
						SelectObject(hdc, oPen) ;

						oPen = SelectObject(hdc, blackPen) ;				// day tick
						yp = D.top + 4  ; MoveToEx(hdc, xp, yp, NULL) ;		// descent
						yp = D.top - 4 ;    LineTo(hdc, xp, yp) ;			// ascent
						SelectObject(hdc, oPen) ;
						noday = 0 ;
					  }
				}
				break ;

			case tWEEK:		// it is start of a calendar week
				{
				if (do_week_marks)
					{
						xp = ep2xp(ep) ;
						
						oPen = SelectObject(hdc, ltgreenPen) ;	// grid : draw 1st day of week line
						yp = D.top ;  MoveToEx(hdc, xp, yp, NULL) ;
						yp = D.bottom ; LineTo(hdc, xp, yp) ;
						SelectObject(hdc, oPen) ;

						oPen = SelectObject(hdc, blackPen) ;	// 1st day of week tick
						yp = D.top + 4  ; MoveToEx(hdc, xp, yp, NULL) ;	// descent
						yp = D.top - 4 ;    LineTo(hdc, xp, yp) ;		// ascent
						SelectObject(hdc, oPen) ;

						sprintf(buff,"%d",day) ;		// 1st day of week label
						GetTextExtentPoint32(hdc, buff, s = strlen(buff), &sz) ;
						TextOut(hdc, xp - sz.cx/2, D.top - (4 + sz.cy), buff, s) ;
					}
				}
				break ;

			case tMONTH:	// it is the start of a calendar month
				{
					if (do_mon_marks)
					{
						xp = ep2xp(ep) ;				// grid : draw month line

						oPen = SelectObject(hdc, ltredPen) ;
						yp = D.top ;  MoveToEx(hdc, xp, yp, NULL) ;
						yp = D.bottom ; LineTo(hdc, xp, yp) ;
						SelectObject(hdc, oPen) ;

						oPen = SelectObject(hdc, blackPen) ;	// month tick
						yp = D.top + 4 ; MoveToEx(hdc, xp, yp, NULL) ;	// descent
						yp = D.top - 12 ;  LineTo(hdc, xp, yp) ;		// ascent
						SelectObject(hdc, oPen) ;

						if (do_mo_name || do_wee_mo_name)	// long or short month label if room for it
						{
						if (do_mo_name)
						sprintf(buff,"%d %s", day, szMonth[mo]) ;
						if (do_wee_mo_name)
							{
							char str[50] ;
							strncpy(str, szMonth[mo], 1) ; str[1] = '\0' ;
							sprintf(buff, "%d %s", day, str) ; 
							}
						GetTextExtentPoint32(hdc, buff, s = strlen(buff), &sz) ;
						TextOut(hdc, xp, D.top - (4 + 2 * sz.cy), buff, s) ;
						}
						nomonth = 0 ;
					}
				}
				break ;

			case tYEAR:		// it is the start of a calendar year
					{
						xp = ep2xp(ep) ;

						oPen = SelectObject(hdc, dkgreenPen) ;	// grid: always draw year line
						yp = D.top - 25 ; MoveToEx(hdc, xp, yp, NULL) ;
						yp = D.bottom ;     LineTo(hdc,xp, yp) ;
						SelectObject(hdc, oPen) ;

						if (do_mo_name)					// month label if room for it
						{
						sprintf(buff,"%d %s", day, szMonth[mo]) ;
						GetTextExtentPoint32(hdc, buff, s = strlen(buff), &sz) ;
						TextOut(hdc, xp, D.top - (4 + 2 * sz.cy), buff, s) ;
						}

						if (do_yr_name)		// full year label
						{
						sprintf(buff," %d", yr ) ;
						GetTextExtentPoint32(hdc, buff, s = strlen(buff), &sz) ;
						TextOut(hdc, xp, D.top - (4 + 3 * sz.cy), buff, s) ;
						}

						if (do_wee_yr_name)	// short year label
						{
						sprintf(buff," %2.2d", (yr < 2000) ? yr - 1900 : yr - 2000) ;
						GetTextExtentPoint32(hdc, buff, s = strlen(buff), &sz) ;
						TextOut(hdc, xp, D.top - (4 + 3 * sz.cy), buff, s) ;
						}
						noyear = 0 ;
					}
				break ;

			default:
				break ;
				} // switch (timecase)

				} // for ( ep = lochart....

				ep = AstEp1 ; civildate() ; // first date
				GetTextExtentPoint32(hdc, dayt, s = strlen(dayt), &sz) ;
				TextOut(hdc, 2, D.top - 4 * (1 + sz.cy), dayt, s) ;

				ep = AstEp2 ; civildate() ;	// final date
				GetTextExtentPoint32(hdc, dayt, s = strlen(dayt), &sz) ;
				TextOut(hdc, rcArc.right - (sz.cx + 2), D.top - 4 * (1 + sz.cy), dayt, s) ;

				ep = eptmp ;
		}

		if (do_day_num)
		{
		// ticks at n * 5 day intervals along the bottom, n = 1, 2, 3 .....
		   oPen = SelectObject(hdc, blackPen) ;
		   oFnt = SelectObject(hdc, hfnt1) ;
		   SetBkColor(hdc, RGB(192, 192, 192)) ;

			   xp = xlmar ;
			   yp = D.bottom + 4 ; MoveToEx(hdc,xp,yp,NULL) ;
			   yp = D.bottom ; LineTo(hdc,xp,yp) ;
			   sprintf(buff, "%d", 1 ) ;
 			   GetTextExtentPoint32(hdc, buff, strlen(buff), &sz) ;
			   TextOut(hdc, xp - sz.cx/2, D.bottom + 6, buff, strlen(buff)) ;


		   for ( i = 4 ; i < (int)AstGP + 1 ; i += daysstep )  
		   {
			   xp = ep2xp(AstEp1 + (double)i) ;
			   yp = D.bottom + 4 ; MoveToEx(hdc,xp,yp,NULL) ;
			   yp = D.bottom ; LineTo(hdc,xp,yp) ;

			   sprintf(buff, "%d", i + 1 ) ;
 			   GetTextExtentPoint32(hdc, buff, strlen(buff), &sz) ;
			   TextOut(hdc, xp - sz.cx/2, D.bottom + 6, buff, strlen(buff)) ;
		   }
		       sprintf(buff,"%d Days", (int)AstGP + 1 ) ;
			   TextOut( hdc,
				       (D.right + D.left) / 2,
					    D.bottom + 6 + sz.cy, buff, strlen(buff)) ;
		}
		SelectObject(hdc, oPen) ;
		SelectObject(hdc, oFnt) ;


		// print Lambda labels etc only if actually showing Lambdas
		if (ShowLambdaScale)
		{

		   oFnt = SelectObject(hdc, hfnt) ;
		   SetTextColor(hdc, RGB(  0,  0,  0)) ; // black text

		   if (UseScale == 1)
		   SetBkColor(hdc, RGB( 223, 223, 223)) ;
		   else
		   SetBkColor(hdc, RGB( 192, 192, 192)) ;


			   // get font height
				sprintf( buff,"0.123" ) ; // sample string
 				GetTextExtentPoint32(hdc, buff, strlen(buff), &sz) ;

			if (ht >= sz.cy) // No labels if ht less than font height 
			{

			   // find least number of ticks accommodating the font height.

			         M = (int)((hi_y - lo_y) / minor) ;		// potential number of ticks
				fnt_ht = (int)((double)ht / (double)M) ;	// size of font needed to fit
			N = 1 ; while ( N * fnt_ht < sz.cy ) N++ ;		// find actual number of ticks that can be labelled
		     for ( u = lo_y ; u <= hi_y ; u += ((double)N * minor))	// label the ticks accordingly
			 {
			   if ( u <= hi_y )
			   {
				yp = rcArc.bottom -	(int)((double)ht * (u - lo_y) / (hi_y - lo_y) + (double)ylmar) ;
			    sprintf(buff, "%4.2f", u ) ;
			    TextOut(hdc, 1, yp - sz.cy/2, buff, strlen(buff)) ;
			   }
			 }
		     SelectObject(hdc, oFnt) ;

		     oFnt = SelectObject(hdc, hgrk2) ;	// use greek font
		     sprintf(buff,"l") ;				// Lambda symbol below
		     TextOut(hdc, 2, D.bottom + sz.cy ,buff, strlen(buff)) ;
		     SelectObject(hdc, oFnt) ;
			}
		}
}


