Skip to content

Commit

Permalink
240304.000751.HKT revise fortran examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zaikunzhang committed Mar 3, 2024
1 parent 1e0559a commit 949502e
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 41 deletions.
2 changes: 2 additions & 0 deletions fortran/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.mod
*.mod0
9test
atest
dtest
Expand Down
2 changes: 1 addition & 1 deletion fortran/examples/bobyqa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOLVER := $(shell basename $(CURDIR))
FS ?= 18 # Set FS if it does not have a value.
FSTD := 20$(FS)
# Default options for all the compilers.
FFLAGS := -O3 -g
FFLAGS := -O -g
# Common directories.
COMMON := ../../common
# Headers.
Expand Down
5 changes: 2 additions & 3 deletions fortran/examples/bobyqa/bobyqa_example_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ program bobyqa_exmp
use bobyqa_mod, only : bobyqa

! The following line specifies which module provides CALFUN and CALLBACK_FCN.
use calfun_mod, only : RP, calfun, callback_fcn
use calfun_mod, only : RP, IK, calfun, callback_fcn

implicit none

Expand All @@ -85,7 +85,6 @@ program bobyqa_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = x0
call bobyqa(calfun, x, f, lb, ub, rhobeg=1.0D-1, iprint=1, nf=nf, info=info, callback_fcn=callback_fcn)

call bobyqa(calfun, x, f, lb, ub, rhobeg=1.0_RP, iprint=1_IK, nf=nf, info=info, callback_fcn=callback_fcn)

end program bobyqa_exmp
10 changes: 5 additions & 5 deletions fortran/examples/bobyqa/bobyqa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Wednesday, January 10, 2024 AM12:21:59
! Last Modified: Sunday, March 03, 2024 PM11:45:53
!--------------------------------------------------------------------------------------------------!


Expand All @@ -14,8 +14,9 @@ module calfun_mod

implicit none
private
public :: RP, calfun
public :: RP, IK, calfun
integer, parameter :: RP = kind(0.0D0)
integer, parameter :: IK = kind(0)

contains

Expand Down Expand Up @@ -57,7 +58,7 @@ program bobyqa_exmp
use bobyqa_mod, only : bobyqa

! The following line specifies which module provides CALFUN.
use calfun_mod, only : RP, calfun
use calfun_mod, only : RP, IK, calfun

implicit none

Expand All @@ -82,7 +83,6 @@ program bobyqa_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = x0
call bobyqa(calfun, x, f, lb, ub, rhobeg=1.0D-1, iprint=1, nf=nf, info=info)

call bobyqa(calfun, x, f, lb, ub, rhobeg=0.1_RP, iprint=1_IK, nf=nf, info=info)

end program bobyqa_exmp
2 changes: 1 addition & 1 deletion fortran/examples/cobyla/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOLVER := $(shell basename $(CURDIR))
FS ?= 18 # Set FS if it does not have a value.
FSTD := 20$(FS)
# Default options for all the compilers.
FFLAGS := -O3 -g
FFLAGS := -O -g
# Common directories.
COMMON := ../../common
# Headers.
Expand Down
3 changes: 1 addition & 2 deletions fortran/examples/cobyla/cobyla_example_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ program cobyla_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = x0
call cobyla(calcfc, 1_IK, x, f, cstrv, rhobeg=1.0D-1, iprint=1, nf=nf, info=info, callback_fcn=callback_fcn)

call cobyla(calcfc, 1_IK, x, f, cstrv, rhobeg=1.0_RP, iprint=1_IK, nf=nf, info=info, callback_fcn=callback_fcn)

end program cobyla_exmp
11 changes: 6 additions & 5 deletions fortran/examples/cobyla/cobyla_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Wednesday, September 27, 2023 PM03:12:49
! Last Modified: Sunday, March 03, 2024 PM11:46:06
!--------------------------------------------------------------------------------------------------!


Expand All @@ -14,8 +14,9 @@ module calcfc_mod

implicit none
private
public :: RP, calcfc_chebyquad, calcfc_hexagon
public :: RP, IK, calcfc_chebyquad, calcfc_hexagon
integer, parameter :: RP = kind(0.0D0)
integer, parameter :: IK = kind(0)

contains

Expand Down Expand Up @@ -88,7 +89,7 @@ program cobyla_exmp
use cobyla_mod, only : cobyla

! The following line specifies which module provides CALCFC.
use calcfc_mod, only : RP, calcfc_chebyquad, calcfc_hexagon
use calcfc_mod, only : RP, IK, calcfc_chebyquad, calcfc_hexagon

implicit none

Expand All @@ -109,7 +110,7 @@ program cobyla_exmp
! and IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x_chebyquad = [(real(i, RP) / real(n_chebyquad + 1, RP), i=1, n_chebyquad)] ! Starting point
call cobyla(calcfc_chebyquad, m, x_chebyquad, f, cstrv, rhobeg=0.2_RP * x_chebyquad(1), iprint=1, nf=nf, info=info)
call cobyla(calcfc_chebyquad, m, x_chebyquad, f, cstrv, rhobeg=0.2_RP * x_chebyquad(1), iprint=1_IK, nf=nf, info=info)

! The following lines illustrates how to call the solver to solve the Hexagon problem.
x_hexagon = 2.0_RP ! Starting point.
Expand All @@ -122,7 +123,7 @@ program cobyla_exmp
! the value of CONSTR(X_HEXAGON) when the solver returns.
x_hexagon = 2.0_RP ! Starting point.
allocate (constr(m))
call cobyla(calcfc_hexagon, m, x_hexagon, f, cstrv, nlconstr=constr, rhobeg=1.0_RP, iprint=1, nf=nf, info=info)
call cobyla(calcfc_hexagon, m, x_hexagon, f, cstrv, nlconstr=constr, rhobeg=1.0_RP, iprint=1_IK, nf=nf, info=info)
deallocate (constr) ! Deallocate the array CONSTR, which is allocated by the solver. Otherwise, memory leaks.

end program cobyla_exmp
2 changes: 1 addition & 1 deletion fortran/examples/lincoa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOLVER := $(shell basename $(CURDIR))
FS ?= 18 # Set FS if it does not have a value.
FSTD := 20$(FS)
# Default options for all the compilers.
FFLAGS := -O3 -g
FFLAGS := -O -g
# Common directories.
COMMON := ../../common
# Headers.
Expand Down
5 changes: 2 additions & 3 deletions fortran/examples/lincoa/lincoa_example_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ program lincoa_exmp
use lincoa_mod, only : lincoa

! The following line specifies which module provides CALFUN and CALLBACK_FCN.
use calfun_mod, only : RP, calfun, callback_fcn
use calfun_mod, only : RP, IK, calfun, callback_fcn

implicit none

Expand All @@ -84,7 +84,6 @@ program lincoa_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = x0
call lincoa(calfun, x, f, cstrv, Aineq, bineq, rhobeg=1.0_RP, iprint=1, nf=nf, info=info, callback_fcn=callback_fcn)

call lincoa(calfun, x, f, cstrv, Aineq, bineq, rhobeg=1.0_RP, iprint=1_IK, nf=nf, info=info, callback_fcn=callback_fcn)

end program lincoa_exmp
9 changes: 5 additions & 4 deletions fortran/examples/lincoa/lincoa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Monday, July 03, 2023 PM02:47:06
! Last Modified: Sunday, March 03, 2024 PM11:48:23
!--------------------------------------------------------------------------------------------------!


Expand All @@ -14,8 +14,9 @@ module tetrahedron_mod

implicit none
private
public :: RP, calfun, setup
public :: RP, IK, calfun, setup
integer, parameter :: RP = kind(0.0D0)
integer, parameter :: IK = kind(0)

contains

Expand Down Expand Up @@ -117,7 +118,7 @@ program lincoa_exmp
use lincoa_mod, only : lincoa

! The following line specifies which module provides CALFUN.
use tetrahedron_mod, only : RP, calfun, setup
use tetrahedron_mod, only : RP, IK, calfun, setup

implicit none

Expand All @@ -136,6 +137,6 @@ program lincoa_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = x0
call lincoa(calfun, x, f, cstrv, Aineq, bineq, rhobeg=1.0_RP, iprint=1, nf=nf, info=info)
call lincoa(calfun, x, f, cstrv, Aineq, bineq, rhobeg=1.0_RP, iprint=1_IK, nf=nf, info=info)

end program lincoa_exmp
2 changes: 1 addition & 1 deletion fortran/examples/newuoa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOLVER := $(shell basename $(CURDIR))
FS ?= 18 # Set FS if it does not have a value.
FSTD := 20$(FS)
# Default options for all the compilers.
FFLAGS := -O3 -g
FFLAGS := -O -g
# Common directories.
COMMON := ../../common
# Headers.
Expand Down
5 changes: 2 additions & 3 deletions fortran/examples/newuoa/newuoa_example_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ program newuoa_exmp
use newuoa_mod, only : newuoa

! The following line specifies which module provides CALFUN.
use calfun_mod, only : RP, calfun, callback_fcn
use calfun_mod, only : RP, IK, calfun, callback_fcn

implicit none

Expand All @@ -80,7 +80,6 @@ program newuoa_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = x0
call newuoa(calfun, x, f, rhobeg=1.0D-1, iprint=1, nf=nf, info=info, callback_fcn=callback_fcn)

call newuoa(calfun, x, f, rhobeg=1.0_RP, iprint=1_IK, nf=nf, info=info, callback_fcn=callback_fcn)

end program newuoa_exmp
9 changes: 5 additions & 4 deletions fortran/examples/newuoa/newuoa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Tuesday, May 30, 2023 PM06:30:04
! Last Modified: Sunday, March 03, 2024 PM11:49:07
!--------------------------------------------------------------------------------------------------!


Expand All @@ -14,8 +14,9 @@ module calfun_mod

implicit none
private
public :: RP, calfun
public :: RP, IK, calfun
integer, parameter :: RP = kind(0.0D0)
integer, parameter :: IK = kind(0)

contains

Expand Down Expand Up @@ -57,7 +58,7 @@ program newuoa_exmp
use newuoa_mod, only : newuoa

! The following line specifies which module provides CALFUN.
use calfun_mod, only : RP, calfun
use calfun_mod, only : RP, IK, calfun

implicit none

Expand All @@ -73,6 +74,6 @@ program newuoa_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = [(real(i, RP) / real(n + 1, RP), i=1, n)] ! Define the starting point.
call newuoa(calfun, x, f, rhobeg=0.2_RP * x(1), iprint=1, nf=nf, info=info)
call newuoa(calfun, x, f, rhobeg=0.2_RP * x(1), iprint=1_IK, nf=nf, info=info)

end program newuoa_exmp
2 changes: 1 addition & 1 deletion fortran/examples/uobyqa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOLVER := $(shell basename $(CURDIR))
FS ?= 18 # Set FS if it does not have a value.
FSTD := 20$(FS)
# Default options for all the compilers.
FFLAGS := -O3 -g
FFLAGS := -O -g
# Common directories.
COMMON := ../../common
# Headers.
Expand Down
5 changes: 2 additions & 3 deletions fortran/examples/uobyqa/uobyqa_example_1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ program uobyqa_exmp
use uobyqa_mod, only : uobyqa

! The following line specifies which module provides CALFUN and CALLBACK_FCN.
use calfun_mod, only : RP, calfun, callback_fcn
use calfun_mod, only : RP, IK, calfun, callback_fcn

implicit none

Expand All @@ -80,7 +80,6 @@ program uobyqa_exmp
! IPRINT, which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will
! take their default values coded in the solver.
x = x0
call uobyqa(calfun, x, f, rhobeg=1.0D-1, iprint=1, nf=nf, info=info, callback_fcn=callback_fcn)

call uobyqa(calfun, x, f, rhobeg=1.0_RP, iprint=1_IK, nf=nf, info=info, callback_fcn=callback_fcn)

end program uobyqa_exmp
9 changes: 5 additions & 4 deletions fortran/examples/uobyqa/uobyqa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Tuesday, May 30, 2023 PM06:33:27
! Last Modified: Sunday, March 03, 2024 PM11:50:17
!--------------------------------------------------------------------------------------------------!


Expand All @@ -14,8 +14,9 @@ module calfun_mod

implicit none
private
public :: RP, calfun
public :: RP, IK, calfun
integer, parameter :: RP = kind(0.0D0)
integer, parameter :: IK = kind(0)

contains

Expand Down Expand Up @@ -57,7 +58,7 @@ program uobyqa_exmp
use uobyqa_mod, only : uobyqa

! The following line specifies which module provides CALFUN.
use calfun_mod, only : RP, calfun
use calfun_mod, only : RP, IK, calfun

implicit none

Expand All @@ -73,6 +74,6 @@ program uobyqa_exmp
! which are optional. All the unspecified optional arguments (RHOEND, MAXFUN, etc.) will take their
! default values coded in the solver.
x = [(real(i, RP) / real(n + 1, RP), i=1, n)] ! Starting point
call uobyqa(calfun, x, f, rhobeg=0.2_RP * x(1), iprint=1, nf=nf, info=info)
call uobyqa(calfun, x, f, rhobeg=0.2_RP * x(1), iprint=1_IK, nf=nf, info=info)

end program uobyqa_exmp

0 comments on commit 949502e

Please sign in to comment.