        integer text(1000000),textns(1000000)
        character line*120,rep*3

        integer cnt(28,28)
        integer countns(26,26),alph(28)

        logical igbl,igpn

        do 101 i=1,26
          alph(i)=0
 101    continue
        do 102 i=1,26
          do 102 j=1,26
            countns(i,j)=0
 102    continue
        do 103 i=1,28
          do 103 j=1,28
            cnt(i,j)=0
 103    continue

        write(*,*)'Do you want to ignore blanks and line feeds?'
     &             //'(y or n)'
        read(*,*)rep
        igbl=.false.
        if(rep(1:1).eq.'y'.or.rep(1:1).eq.'Y')igbl=.true.
        write(*,*)'Do you want to ignore punctuation marks? (y or n)'
        read(*,*)rep
        igpn=.false.
        if(rep(1:1).eq.'y'.or.rep(1:1).eq.'Y')igpn=.true.

        open(8,file="Analysis.in")
        if(igbl)then
          n1=0
        else
          n1=1
          text(1)=28
        end if
        n2=0
  1     read(8,1000,end=2)line
1000    format(a120)
        do 15 i=1,120
         nl=ichar(line(i:i))
         if(nl.gt.64.and.nl.lt.91)then
c       Upper case letters
           nl=nl-64
         else if(nl.gt.96.and.nl.lt.123)then
c       Lower case letters
           nl=nl-96
         else if(nl.ne.32)then
c       Other character (not space)
           nl=27
         else
c       Space
           nl=28
         end if
        if(nl.lt.27)then
c       A letter
          n1=n1+1
          n2=n2+1
          text(n1)=nl
          textns(n2)=nl
        else if(nl.eq.27)then
          if(.not.igpn)then
            n1=n1+1
            text(n1)=nl
            n2=n2+1
            textns(n2)=nl
          end if
        else if(nl.eq.28)then
          if(.not.igbl.and.text(n1).ne.28)then
            n1=n1+1
            text(n1)=nl
          end if
        end if
  15    continue

        go to 1

  2     close(8)
        write(*,*)n2,' letters read, with ',n1-n2,' spaces.'
        do 3 i=1,n1
          alph(text(i))=alph(text(i))+1
  3     continue
      
        do 4 i=1,n1-1
          cnt(text(i),text(i+1))=cnt(text(i),text(i+1))+1
  4     continue

        do 5 i=1,n2-1
           countns(textns(i),textns(i+1))
     &            =countns(textns(i),textns(i+1))+1
  5     continue

        write(*,*)
        write(*,*)'Frequency count of letters and spaces'
        write(*,*)

        do 6 i=1,26
        write(*,1003)char(i+64),alph(i)
  6     continue
        write(*,1003)'Punc.',alph(27)
        write(*,1003)'Space',alph(28)
1003    format(a5,3x,i6)
      if(igpn.and.igbl)then
        write(*,*)
        write(*,*)'Frequency count of pairs not including spaces'
     &           //' or puctuation'
        write(*,*)

        write(*,1002)(char(ic+64),ic=1,26)
1002    format(1x,26(4x,1a,1x))
        do 20 ir=1,26
        write(*,1001)char(64+ir),(countns(ir,ic),ic=1,26)
 20     continue
1001    format(1a,26(1x,i5))
      else if(igpn.and..not.igbl)then

        write(*,*)
        write(*,*)'Frequency count of pairs including spaces'
     &        //' but not punctuation'
        write(*,*)

        write(*,1005)(char(ic+64),ic=1,26)
1005    format(1x,26(4x,1a,1x),'Space')
        do 21 ir=1,26
        write(*,1006)char(64+ir),(cnt(ir,ic),ic=1,26),
     &             cnt(ir,28)
 21     continue
        write(*,1006)' ',(cnt(28,ic),ic=1,26),cnt(28,28)

1006    format(1a,26(1x,i5),1x,i5)
        write(*,*)'The incidence of space C is ',cnt(28,3)
      else if(.not.igpn.and.igbl)then
        write(*,*)
        write(*,*)'Frequency count of pairs including punctuation'
     &        //' but not spaces'
        write(*,*)

        write(*,1007)(char(ic+64),ic=1,26),'*'
1007    format(1x,27(3x,1a,1x))
        do 22 ir=1,26
        write(*,1006)char(64+ir),(cnt(ir,ic),ic=1,27)
 22     continue
        write(*,1006)'*',(cnt(27,ic),ic=1,27)
      else if(.not.igpn.and..not.igbl)then
        write(*,*)'Table for this option not yet implemented'
      end if


        stop
        end
