!****************************************************************************
!
!  PROGRAM: Example
!
!  PURPOSE:  Calculates values of objective function using random search
!            generator for coordinates generation.
!------------------------------------------------------------------------
!  FUNCTIONS (library GRILLAGE.LIB):
!	ANALYSIS(Length,SupNum,AllowReaction) - calculates some characteristics
!   of grillage:    
!     Length        - REAL*8  - total length of grillage beams,
!     SupNum        - INTEGER - necessary number of supports,
!     AllowReaction - REAL*8  - allowable reaction force.
!
!	OBJECTIVE_FUNCTION(X_KOORD,SupNum,Reaction) - calculates maximum reaction
!   force depending on coordinates:
!     X_KOORD -  REAL*8  - array of coordinates of supports in 1D space,
!     SupNum  -  INTEGER - necessary number of supports,
!     Reaction - REAL*8  - maximum reaction force.
!------------------------------------------------------------------------
!   IMPORTANT NOTES
!   Data file should be named 'aa_in.dat' and should be placed in the same
!     directory with the program file 'example.exe'.
!   Library 'grillage.lib' should be included into the project
!   File 'aa_mes.dat' is intended for the analysis of possible errors.
!   File 'aa_out.dat' is intended for temporary data output.
!****************************************************************************

	program Example

	implicit none
	
	INTEGER SupNum, i
	REAL*8  Length, AllowReaction, Reaction
	REAL*8,  ALLOCATABLE, DIMENSION(:) :: X_KOORD

101 FORMAT(a,F8.2)
102 FORMAT(a,I4)
103 FORMAT(a,I3,a,F8.2)

	CALL ANALYSIS(Length,SupNum,AllowReaction)
	write(*,101) 'Total length of grillage:',Length
	write(*,102) 'Necessary number of supports:',SupNum
	write(*,101) 'Allowable reaction force:',AllowReaction
    write(*,*)

	ALLOCATE(X_KOORD(SupNum))

	CALL random_seed()
	
	DO i=1,10
	   CALL random_number(X_KOORD) ! values from interval [0.0, 1.0)
	   X_KOORD = X_KOORD*Length    ! values from interval [0.0, Length)
       CALL OBJECTIVE_FUNCTION(X_KOORD,SupNum,Reaction)
	   write(*,103) 'Iteration',i,'. Reaction force =',Reaction
	END DO

    IF(ALLOCATED(X_KOORD))  DEALLOCATE(X_KOORD)

	end program Example


