Removes file extension from filename while preserving time in scientific notation and dots in paths.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | filename |
File name |
Returned string with extension removed
pure function stringtool_obj_RemoveExtension(filename) result(val) !> Removes file extension from filename while preserving ! time in scientific notation and dots in paths. character(len=*), intent(in) :: filename !! File name character(len=:), allocatable :: val !! Returned string with extension removed ! Work variables integer :: last_slash integer :: i,n logical :: is_sci_dot val = trim(adjustl(filename)) n = len(val) ! Find last path separator to avoid dots in directory names last_slash = index(val, '/', back=.true.) ! Scan backwards from the end of the string to find the TRUE extension dot do i = n, last_slash + 1, -1 if (val(i:i) == '.') then ! Assume this is NOT a scientific notation dot unless proven otherwise is_sci_dot = .false. ! Check if this dot is followed by the ES12.4 pattern (e.g., .0000E+01) ! The pattern ".0000E+" is 7 characters long. if (i + 6 <= n) then if (val(i+1:i+1) >= '0' .and. val(i+1:i+1) <= '9' .and. & (val(i+5:i+5) == 'E' .or. val(i+5:i+5) == 'e') .and. & (val(i+6:i+6) == '+' .or. val(i+6:i+6) == '-')) then is_sci_dot = .true. end if end if ! If it's a real extension dot (not part of the time string), truncate and exit if (.not. is_sci_dot) then val = val(:i-1) return end if end if end do return end function stringtool_obj_RemoveExtension