subroutine box_behnken ( dim_num, x_num, range, x ) c*********************************************************************72 c cc box_behnken() returns a Box-Behnken design for the given number of factors. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 26 October 2008 c c Author: c c John Burkardt c c Reference: c c George Box, Donald Behnken, c Some new three level designs for the study of quantitative variables, c Technometrics, c Volume 2, pages 455-475, 1960. c c Parameters: c c Input, integer DIM_NUM, the spatial dimension. c c Input, integer X_NUM, the number of elements of the design. c X_NUM should be equal to DIM_NUM * 2**(DIM_NUM-1) + 1. c c Input, double precision RANGE(DIM_NUM,2), the minimum and maximum c value for each component. c c Output, double precision X(DIM_NUM,X_NUM), the elements of the design. c implicit none integer dim_num integer x_num integer i integer i2 integer j integer last_low double precision range(dim_num,2) double precision x(dim_num,x_num) c c Ensure that the range is legal. c do i = 1, dim_num if ( range(i,2) .le. range(i,1)) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'BOX_BEHNKEN - Fatal error!' write ( *, '(a,i8)' ) ' For I = ', i write ( *, '(a)' ) ' RANGE(I,2) <= RANGE(I,1).' stop end if end do c c The first point is the center. c j = 1 do i = 1, dim_num x(i,j) = ( range(i,1) + range(i,2) ) / 2.0D+00 end do c c For subsequent elements, one entry is fixed at the middle of the range. c The others are set to either extreme. c do i = 1, dim_num j = j + 1 do i2 = 1, dim_num x(i2,j) = range(i2,1) end do x(i,j) = ( range(i,1) + range(i,2) ) / 2.0D+00 c c The next element is made by finding the last low value, making it c high, and all subsequent high values low. c 10 continue last_low = -1 do i2 = 1, dim_num if ( x(i2,j) .eq. range(i2,1) ) then last_low = i2 end if end do if ( last_low .eq. -1 ) then go to 20 end if j = j + 1 do i2 = 1, dim_num x(i2,j) = x(i2,j-1) end do x(last_low,j) = range(last_low,2) do i2 = last_low + 1, dim_num if ( x(i2,j) .eq. range(i2,2) ) then x(i2,j) = range(i2,1) end if end do go to 10 20 continue end do return end subroutine box_behnken_size ( dim_num, x_num ) c*********************************************************************72 c cc BOX_BEHNKEN_SIZE returns the size of a Box-Behnken design. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 26 October 2008 c c Author: c c John Burkardt c c Reference: c c George Box, Donald Behnken, c Some new three level designs for the study of quantitative variables, c Technometrics, c Volume 2, pages 455-475, 1960. c c Parameters: c c Input, integer DIM_NUM, the spatial dimension. c c Output, integer X_NUM, the number of elements of the design. c X_NUM will be equal to DIM_NUM * 2**(DIM_NUM-1) + 1. c implicit none integer dim_num integer x_num if ( 1 .le. dim_num ) then x_num = 1 + dim_num * 2**( dim_num - 1 ) else x_num = -1 end if return end subroutine get_unit ( iunit ) c*********************************************************************72 c cc GET_UNIT returns a free FORTRAN unit number. c c Discussion: c c A "free" FORTRAN unit number is a value between 1 and 99 which c is not currently associated with an I/O device. A free FORTRAN unit c number is needed in order to open a file with the OPEN command. c c If IUNIT = 0, then no free FORTRAN unit could be found, although c all 99 units were checked (except for units 5, 6 and 9, which c are commonly reserved for console I/O). c c Otherwise, IUNIT is a value between 1 and 99, representing a c free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6 c are special, and will never return those values. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 02 September 2013 c c Author: c c John Burkardt c c Parameters: c c Output, integer IUNIT, the free unit number. c implicit none integer i integer iunit logical value iunit = 0 do i = 1, 99 if ( i .ne. 5 .and. i .ne. 6 .and. i .ne. 9 ) then inquire ( unit = i, opened = value, err = 10 ) if ( .not. value ) then iunit = i return end if end if 10 continue end do return end subroutine r8mat_transpose_print ( m, n, a, title ) c*********************************************************************72 c cc R8MAT_TRANSPOSE_PRINT prints an R8MAT, transposed. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 April 2008 c c Author: c c John Burkardt c c Parameters: c c Input, integer M, N, the number of rows and columns. c c Input, double precision A(M,N), an M by N matrix to be printed. c c Input, character*(*) TITLE, a title. c implicit none integer m integer n double precision a(m,n) character*(*) title call r8mat_transpose_print_some ( m, n, a, 1, 1, m, n, title ) return end subroutine r8mat_transpose_print_some ( m, n, a, ilo, jlo, ihi, & jhi, title ) c*********************************************************************72 c cc R8MAT_TRANSPOSE_PRINT_SOME prints some of an R8MAT transposed. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 April 2008 c c Author: c c John Burkardt c c Parameters: c c Input, integer M, N, the number of rows and columns. c c Input, double precision A(M,N), an M by N matrix to be printed. c c Input, integer ILO, JLO, the first row and column to print. c c Input, integer IHI, JHI, the last row and column to print. c c Input, character * ( * ) TITLE, a title. c implicit none integer incx parameter ( incx = 5 ) integer m integer n double precision a(m,n) character * ( 14 ) ctemp(incx) integer i integer i2 integer i2hi integer i2lo integer ihi integer ilo integer inc integer j integer j2hi integer j2lo integer jhi integer jlo integer s_len_trim character * ( * ) title integer title_len title_len = s_len_trim ( title ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) title(1:title_len) do i2lo = max ( ilo, 1 ), min ( ihi, m ), incx i2hi = i2lo + incx - 1 i2hi = min ( i2hi, m ) i2hi = min ( i2hi, ihi ) inc = i2hi + 1 - i2lo write ( *, '(a)' ) ' ' do i = i2lo, i2hi i2 = i + 1 - i2lo write ( ctemp(i2), '(i8,6x)') i end do write ( *, '('' Row'',5a14)' ) ctemp(1:inc) write ( *, '(a)' ) ' Col' j2lo = max ( jlo, 1 ) j2hi = min ( jhi, n ) do j = j2lo, j2hi do i2 = 1, inc i = i2lo - 1 + i2 write ( ctemp(i2), '(g14.6)' ) a(i,j) end do write ( *, '(2x,i8,5a14)' ) j, ( ctemp(i), i = 1, inc ) end do end do return end subroutine r8mat_write ( output_filename, m, n, table ) c*********************************************************************72 c cc R8MAT_WRITE writes a R8MAT file. c c Discussion: c c An R8MAT is an array of R8's. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 22 October 2009 c c Author: c c John Burkardt c c Parameters: c c Input, character * ( * ) OUTPUT_FILENAME, the output file name. c c Input, integer M, the spatial dimension. c c Input, integer N, the number of points. c c Input, double precision TABLE(M,N), the data. c implicit none integer m integer n integer j character * ( * ) output_filename integer output_unit character * ( 30 ) string double precision table(m,n) c c Open the file. c call get_unit ( output_unit ) open ( unit = output_unit, file = output_filename, & status = 'replace' ) c c Create the format string. c if ( 0 .lt. m .and. 0 .lt. n ) then write ( string, '(a1,i8,a1,i8,a1,i8,a1)' ) & '(', m, 'g', 24, '.', 16, ')' c c Write the data. c do j = 1, n write ( output_unit, string ) table(1:m,j) end do end if c c Close the file. c close ( unit = output_unit ) return end function s_len_trim ( s ) c*********************************************************************72 c cc S_LEN_TRIM returns the length of a string to the last nonblank. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 05 March 2004 c c Author: c c John Burkardt c c Parameters: c c Input, character*(*) S, a string. c c Output, integer S_LEN_TRIM, the length of the string to the last nonblank. c implicit none integer i character*(*) s integer s_len_trim do i = len ( s ), 1, -1 if ( s(i:i) .ne. ' ' ) then s_len_trim = i return end if end do s_len_trim = 0 return end subroutine timestamp ( ) c*********************************************************************72 c cc TIMESTAMP prints out the current YMDHMS date as a timestamp. c c Discussion: c c This FORTRAN77 version is made available for cases where the c FORTRAN90 version cannot be used. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 12 January 2007 c c Author: c c John Burkardt c c Parameters: c c None c implicit none character * ( 8 ) ampm integer d character * ( 8 ) date integer h integer m integer mm character * ( 9 ) month(12) integer n integer s character * ( 10 ) time integer y save month data month / & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' / call date_and_time ( date, time ) read ( date, '(i4,i2,i2)' ) y, m, d read ( time, '(i2,i2,i2,1x,i3)' ) h, n, s, mm if ( h .lt. 12 ) then ampm = 'AM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h .lt. 12 ) then ampm = 'PM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, & '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & d, month(m), y, h, ':', n, ':', s, '.', mm, ampm return end