C...First things to note: 
C   (a) FORTRAN is NOT Case Sensitive.  (It's like teen texting.  :-)
C   (b) Any line with a "C" or a "c" in Column 1 is a COMMENT.  
C   (c) Normal code starts in Column 7 or greater and end in Column 72. (!)
C   (d) Statement numbers (like "1111") are in columns 2-5.
C   (e) Continuation lines have a character (any character!) in column 6 
C       (for when you can't fit a statement into 65 characters).

C...Every main program must start with a PROGRAM name like this:

      program fib

C...The following commend turns OFF the implicit treatment of 
C   any variable whose name starts with i,j,k,l,m or n as an INTEGER 
C   and all the rest as implicitly REAL.  
C   (This is considered good programming practice.)

      implicit none

C...So now every variable used by the program must have its type 
C   explicitly assigned: here we using INTEGER*8 (or "long integer") 
C   for everything because we are working only with integers and 
C   some of them get pretty big!

      integer*8 jj, nn, nextra, fstart, flast, ff, ftmp

C...Now we start talking to the user via Logical Unit Number (LUN) 6, 
C   the default output LUN, specified by the first "*".  
C   The second "*" refers to the FORMAT of the output, 
C   which in this case is the default FORMAT (semi-free) in gfortran.
C   Note: in C, "\n" means "new line" and "\t" is a "tab"; 
C   But in FORTRAN you start a new line with a forward slash OUTSIDE 
C   the quotation marks (or just print a blank line), 
C   and tabs are best converted to spaces.  
C   Note that "print *, " does the same thing as "write (*,*) ":  

      print *, ' '
      write (*,*) '      Fibonacci Numbers'
      write (*,*) '      ================='

C...This time we need to specify a FORMAT in order to tell the 
C   screen writer to stop at the end of the output question and 
C   wait for the user's response.  (The "$" does this.)  

      write (*,1111) 
 1111 format (/,'Enter the initial Fibonacci number: ',$)

C...Now we READ the user's response via LUN 5, the default for input:

      read  (*,*) fstart

C...And so on...

      write (*,2222) 
 2222 format ('How many additional Fibonacci numbers do you want? ',$)
      read  (*,*) nextra

C...Time to get started on the real work.  
C   Quit if the starting Fibonacco number is less than  or equal to 1:

      if (fstart .le. 1) stop

C...The original imput says how many MORE F_i after the first, 
C   so add 1 to get the total number displayed.  

      nn = nextra + 1

      print *, ' '
      write (*,*) nn,' Fibonacci numbers starting with ',fstart,':'
      print *, ' '

C...Initialize flast and ff and set nn to a bigger value than we could need:

      flast = 1
      ff = 1
      nn = 100

C...Start a loop at the second Fibonacci number (which is also 1):

      do jj=2,100

C...Store ff temporarily while we bump it up to the next F_i:

         ftmp = ff
         ff = ff + flast

C..Now put the stored ff into flast:

         flast = ftmp

C...If we get past fstart before we hit fstart right on, it isn't an F_i! 

         if ((ff .gt. fstart) .and. (nn .ge. 100)) then
            write (*,*) ' '
            write (*,*) 'Ahem! ', fstart, ' is not a Fibonacci number!'
            write (*,*) ' '
            exit

C...If we have hit fstart right on, then reset nn and start counting:

         else if (ff .eq. fstart) then
            nn = -1
         end if

C...Increment nn; if we are in the active counting phase then...

         nn = nn + 1
         if (nn .lt. 100) then

C...Check to see if we have finished yet.  If so, stop. 

            if (nn .gt. nextra) then
               write (*,*) ' '
               stop
            end if

C...Otherwise, print out the current values and continue.
C   Because the default number of digits reserved for integer*8 
C   variables is so big, I have removed the leading ' #':  

            write (*,*) jj, ':	', ff
         end if
      end do

C...We should never reach this point, but if we do, just stop.  

      stop

C...Every program (or function or subroutine) must end with "END".

      end
