Change the variable bounds in a numdiff_type.
Note
The bounds must be set when the class is initialized, but this routine can be used to change them later if required.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | xlow |
lower bounds on |
|
real(kind=wp), | intent(in), | dimension(:) | :: | xhigh |
upper bounds on |
subroutine set_numdiff_bounds(me,xlow,xhigh) implicit none class(numdiff_type),intent(inout) :: me real(wp),dimension(:),intent(in) :: xlow !! lower bounds on `x` real(wp),dimension(:),intent(in) :: xhigh !! upper bounds on `x` integer :: i !! counter for error print character(len=:),allocatable :: error_info !! error message info character(len=:),allocatable :: istr !! for integer to string character(len=30) :: xlow_str, xhigh_str !! for real to string if (me%exception_raised) return ! check for exceptions if (allocated(me%xlow)) deallocate(me%xlow) if (allocated(me%xhigh)) deallocate(me%xhigh) if (size(xlow)/=me%n .or. size(xhigh)/=me%n) then call me%raise_exception(3,'set_numdiff_bounds',& 'invalid size of xlow or xhigh') return else if (any(xlow>=xhigh)) then error_info = 'all xlow must be < xhigh' do i = 1, size(xlow) if (xlow(i)>=xhigh(i)) then istr = integer_to_string(i) write(xlow_str,'(F30.16)') xlow(i) write(xhigh_str,'(F30.16)') xhigh(i) error_info = error_info//new_line('')//' Error for optimization variable '//trim(adjustl(istr))//& ': xlow='//trim(adjustl(xlow_str))//& ' >= xhigh='//trim(adjustl(xhigh_str)) end if end do call me%raise_exception(4,'set_numdiff_bounds',error_info) return else allocate(me%xlow(me%n)) allocate(me%xhigh(me%n)) me%xlow = xlow me%xhigh = xhigh end if end subroutine set_numdiff_bounds