C
C  doug_sampler.f - fortran program to be complied using gfortran in cygwin shell
C
C  usage: 
C
C  gfortran doug_sampler.f
C  ./a.exe
C

C
C     COMMON block name
C

C      COMMON/BLOCK1/IA,IB,IC	



C
C subroutine to work out to try out subroutine calls
C


      SUBROUTINE doug2( K )

C
C define some common variables in block2
C
        COMMON/BLOCK2/IA,IB,IC	

C
C define array A 
C

	DIMENSION A(3,3)


	do 10 j=1,20,2

C write to screen and channel 2 
C Channel 2 is fort.2
C
          write(*,*) "sub:" ,j
          write(2,*) "sub:" ,j
10	end do
C11	continue

        write(*,*) "common IA:", IA

	IF ( k ) 20,21,22

20	write(*,*) "negative"
	GOTO 30

21	write(*,*) "zero"
	GOTO 30

22	write(*,*) "positive"
	GOTO 30


30	CONTINUE
      RETURN

      END SUBROUTINE

C
C
C

      SUBROUTINE TEST_K( K )

	write(*,*) "Test k:-"

	IF ( k ) 20,21,22

20	write(*,*) "negative"
	GOTO 30

21	write(*,*) "zero"
	GOTO 30

22	write(*,*) "positive"
	GOTO 30


30	CONTINUE

	
      RETURN

      END SUBROUTINE





      FUNCTION INC( K )
         
	INC = K + 1


      END FUNCTION	






      PROGRAM doug

C
C Data statement example, initialise k and J
C

C define some variables that are common

        COMMON/BLOCK2/IA,IB,IC	

	DATA k/1/,j/2/

	ia = 101


1	FORMAT	( I3,I4 )

C http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap02/traps.html
C http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/intro.html

        call doug2( 3 ) 
        write(*,*) "hello doug "
        write(*,*) "hello doug  make me an offer"
        write(*,*) "hello doug "

	do 20 j=1,20,2
          write(*,*) "--" ,j
20	continue

        call doug2( -3 ) 




        CALL TEST_K( -3 ) 
        CALL TEST_K(  0 ) 
        CALL TEST_K(  3 ) 


! read from the file fort.1 which is channel 1

        read  (1,*) k,j

        write(*,*) "L:" , k, j

        read  (1,*) k,j

        write(*,*) "L:" , k, j
        read  (1,*) k,j

        write(*,*) "L:" , k, j


! write to channel 2 which is fort.2, it does not seem to append, only overwrite

        write(2,*) "hello doug "
        write(2,*) "hello doug  make me an offer"
        write(2,*) "hello doug "

	J=10
	L=INC(J)
	write(*,*)	"INC(k):", L

      END PROGRAM doug



  
