      program blas9F
      USE ISO_C_BINDING
      implicit none

      REAL(C_DOUBLE), DIMENSION(:,:), ALLOCATABLE :: MAT1
      REAL(C_DOUBLE), DIMENSION(:,:), ALLOCATABLE :: MAT2
      INTEGER(C_LONG) :: NROW
      INTEGER(C_LONG) :: NCOL
      INTEGER(C_LONG) :: FIRSTCOLUMNOFSQUARE
      INTEGER(C_LONG) :: NBR
      INTEGER(C_LONG) :: NUMBEROFROWSAWAYFROMBOTTOM
      INTEGER(C_LONG) :: CURRENTROW
      INTEGER(C_LONG) :: CURRENTCOLUMN
      INTEGER(C_LONG) :: I
      REAL :: STARTTIME, FINISHTIME
      REAL :: TIMETAKENVERSION3 = 0
      REAL :: TIMETAKENVERSION4 = 0
      REAL(C_DOUBLE) :: BLASALPHA = 2.0
      REAL(C_DOUBLE) :: BLASBETA = 2.0
      external dger
      NROW = 3001
      NCOL = 4001
      NBR = 0
      FIRSTCOLUMNOFSQUARE = NCOL - NROW + 1
      ALLOCATE(MAT1(NROW,NCOL))
      ALLOCATE(MAT2(NROW,NCOL))
      MAT1 = 1
      DO I = 1,NROW
      MAT1(I,FIRSTCOLUMNOFSQUARE+I-1) = 10*NCOL !diagonally dominant matrix
      END DO
      MAT2 = 1
      DO I = 1,NROW
      MAT2(I,FIRSTCOLUMNOFSQUARE+I-1) = 10*NCOL !diagonally dominant matrix
      END DO
      DO NUMBEROFROWSAWAYFROMBOTTOM=0,NROW-1
         CURRENTROW = NROW - NUMBEROFROWSAWAYFROMBOTTOM
         CURRENTCOLUMN = NCOL - NUMBEROFROWSAWAYFROMBOTTOM

      IF(CURRENTROW .NE. NBR) THEN
      call cpu_time(STARTTIME)
      !call dger(CURRENTROW-1-NBR, CURRENTCOLUMN-1, BLASALPHA, MAT1(1+NBR:CURRENTROW-1,CURRENTCOLUMN), 1, MAT1(CURRENTROW,1:CURRENTCOLUMN-1), 1, MAT1(1+NBR:NROW,1:CURRENTCOLUMN-1), NROW - NBR)
      call dger(CURRENTROW-1-NBR, &
      CURRENTROW-1-NBR, BLASALPHA, &
      MAT1(1+NBR:CURRENTROW-1,CURRENTCOLUMN), 1, &
      MAT1(CURRENTROW,FIRSTCOLUMNOFSQUARE+NBR:CURRENTCOLUMN-1), 1, &
      MAT1(1+NBR:NROW,FIRSTCOLUMNOFSQUARE:CURRENTCOLUMN-1), NROW - NBR)
      call cpu_time(FINISHTIME)
      TIMETAKENVERSION3 = TIMETAKENVERSION3 + FINISHTIME - STARTTIME
      END IF
      END DO
      DO NUMBEROFROWSAWAYFROMBOTTOM=0,NROW-1
         CURRENTROW = NROW - NUMBEROFROWSAWAYFROMBOTTOM
         CURRENTCOLUMN = NCOL - NUMBEROFROWSAWAYFROMBOTTOM
      IF(CURRENTROW .NE. NBR) THEN
      call cpu_time(STARTTIME)
      call dger(CURRENTROW-1-NBR, CURRENTROW-1-NBR, BLASALPHA, &
      MAT2(1+NBR:CURRENTROW-1,CURRENTCOLUMN), 1, &
      MAT2(CURRENTROW,FIRSTCOLUMNOFSQUARE+NBR:CURRENTCOLUMN-1), 1, &
      MAT2((1+NBR):NROW,(FIRSTCOLUMNOFSQUARE+NBR):(CURRENTCOLUMN-1)), & 
      NROW - NBR) 
      call cpu_time(FINISHTIME)
      TIMETAKENVERSION4 = TIMETAKENVERSION4 + FINISHTIME - STARTTIME
      END IF
      END DO
      PRINT *, "TIMETAKENVERSION3"
      PRINT *, TIMETAKENVERSION3
      PRINT *, "TIMETAKENVERSION4"
      PRINT *, TIMETAKENVERSION4
      end
