Convert calculation type string to integer constant
Performs case-insensitive comparison and returns appropriate constant. Returns CALC_TYPE_UNKNOWN for unrecognized strings.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | calc_type_str |
Input string (e.g., “energy”, “gradient”) |
Output integer constant
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | i | ||||
| character(len=len_trim), | private | :: | lower_str |
pure function calc_type_from_string(calc_type_str) result(calc_type) !! Convert calculation type string to integer constant !! !! Performs case-insensitive comparison and returns appropriate constant. !! Returns CALC_TYPE_UNKNOWN for unrecognized strings. character(len=*), intent(in) :: calc_type_str !! Input string (e.g., "energy", "gradient") integer(int32) :: calc_type !! Output integer constant character(len=len_trim(calc_type_str)) :: lower_str integer :: i ! Convert to lowercase for case-insensitive comparison lower_str = trim(adjustl(calc_type_str)) do i = 1, len(lower_str) if (lower_str(i:i) >= 'A' .and. lower_str(i:i) <= 'Z') then lower_str(i:i) = achar(iachar(lower_str(i:i)) + 32) end if end do ! Match against known types select case (lower_str) case ('energy') calc_type = CALC_TYPE_ENERGY case ('gradient') calc_type = CALC_TYPE_GRADIENT case ('hessian') calc_type = CALC_TYPE_HESSIAN case default calc_type = CALC_TYPE_UNKNOWN end select end function calc_type_from_string