T1 timer counter sketch

I am trying to figure out why D8 is the input pin in the attached sketch from Nick Gammon.
However I am at a loss.
How is D8 defined in the code?

// Frequency timer using input capture unit
// Author: Nick Gammon
// Date: 31 August 2013

// Input: Pin D8 

volatile boolean first;
volatile boolean triggered;
volatile unsigned long overflowCount;
volatile unsigned long startTime;
volatile unsigned long finishTime;

// timer overflows (every 65536 counts)
ISR (TIMER1_OVF_vect) 
{
  overflowCount++;
}  // end of TIMER1_OVF_vect

ISR (TIMER1_CAPT_vect)
  {
  // grab counter value before it changes any more
  unsigned int timer1CounterValue;
  timer1CounterValue = ICR1;  // see datasheet, page 117 (accessing 16-bit registers)
  unsigned long overflowCopy = overflowCount;
  
  // if just missed an overflow
  if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 0x7FFF)
    overflowCopy++;
  
  // wait until we noticed last one
  if (triggered)
    return;

  if (first)
    {
    startTime = (overflowCopy << 16) + timer1CounterValue;
    first = false;
    return;  
    }
    
  finishTime = (overflowCopy << 16) + timer1CounterValue;
  triggered = true;
  TIMSK1 = 0;    // no more interrupts for now
  }  // end of TIMER1_CAPT_vect
  
void prepareForInterrupts ()
  {
  noInterrupts ();  // protected code
  first = true;
  triggered = false;  // re-arm for next time
  // reset Timer 1
  TCCR1A = 0;
  TCCR1B = 0;
  
  TIFR1 = bit (ICF1) | bit (TOV1);  // clear flags so we don't get a bogus interrupt
  TCNT1 = 0;          // Counter to zero
  overflowCount = 0;  // Therefore no overflows yet
  
  // Timer 1 - counts clock pulses
  TIMSK1 = bit (TOIE1) | bit (ICIE1);   // interrupt on Timer 1 overflow and input capture
  // start Timer 1, no prescaler
  TCCR1B =  bit (CS10) | bit (ICES1);  // plus Input Capture Edge Select (rising on D8)
  interrupts ();
  }  // end of prepareForInterrupts
  

void setup () 
  {
  Serial.begin(115200);       
  Serial.println("Frequency Counter");
  // set up for interrupts
  prepareForInterrupts ();   
  } // end of setup

void loop () 
  {
  // wait till we have a reading
  if (!triggered)
    return;
 
  // period is elapsed time
  unsigned long elapsedTime = finishTime - startTime;
  // frequency is inverse of period, adjusted for clock period
  float freq = F_CPU / float (elapsedTime);  // each tick is 62.5 nS at 16 MHz
  
  Serial.print ("Took: ");
  Serial.print (elapsedTime);
  Serial.print (" counts. ");

  Serial.print ("Frequency: ");
  Serial.print (freq);
  Serial.println (" Hz. ");

  // so we can read it  
  delay (500);

  prepareForInterrupts ();   
}   // end of loop

LarryD:
I am trying to figure out why D8 is the input pin in the attached sketch from Nick Gammon.
However I am at a loss.
How is D8 defined in the code?

Wow... I think you're going to have to ask Nick about that. If you assume that D8 means "digital pin 8", that doesn't work because pin 8 on either UNO or MEGA2560 isn't involved with the timer and input capture.

Then I wondered if "d8" is a hex value... but that doesn't work either.

I'm at a loss here......

When I run the sketch on my UNO D8 does indeed act as the frequency input pin.
That is to say, if I enter a frequency in on D8 the serial monitor does display the correct frequency.
I thought it might have something to do with the setting of TCCR1B but I don't see any reference in the data sheet for the 328 about D8 / pin 14 / (PB0) on the UNO.
TCCR1B = bit (CS10) | bit (ICES1);
I'm thinking the T1 counter is being clocked internally and somehow D8's state is monitored, but why D8 and how?

Arduino Digital pin 8 is chip pin portB0, which is "ICP1 (Timer/Counter1 Input Capture Input)" according to the datasheet.

For completeness D4 is T0 (can be used to clock timer0)
and D5 is T1 (can clock timer1). Hard wired on the 328.

Arduino Digital pin 8 is chip pin portB0, which is "ICP1 (Timer/Counter1 Input Capture Input)" according to the datasheet.

Yes, I see this now.
"ICP1/CLKO/PCINT0 – Port B, Bit 0 ICP1, Input Capture Pin: The PB0 pin can act as an Input Capture Pin for Timer/Counter1."
Page 84.
And
D8 on the UNO
"This bit selects which edge on the Input Capture pin (ICP1) that is used to trigger a capture event. When the ICES1 bit is written to zero, a falling (negative) edge is used as trigger, and when the ICES1 bit is written to one, a rising (positive) edge will trigger the capture."
On page 136 of the Atmega 328 data sheet
Thanks for the help!

Hello there. I want to make that code run on mega 2560.
I am reading 2 days and nights now, all the datasheets and examples but i didn't understood what pin i should/could use.