From aef2c3629718705975a181a345d3908776b14af5 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Mon, 5 Apr 2021 16:30:15 -0400 Subject: Fixed checkin json to return a name of instructions needed and a job id --- common/utilities.F90 | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'common') diff --git a/common/utilities.F90 b/common/utilities.F90 index 895e604..d4b7b81 100644 --- a/common/utilities.F90 +++ b/common/utilities.F90 @@ -6,6 +6,11 @@ module utilities character, parameter::dir_sep = '/' #endif + interface replace_field + module procedure replace_field_text + module procedure replace_field_int + end interface + contains function is_absolute_path(path) @@ -219,4 +224,55 @@ contains end subroutine delete_file + subroutine replace_field_text(str, field, val) + implicit none + + character(*), intent(inout)::str + character(*), intent(in)::field + character(*), intent(in)::val + + character(len=:), allocatable::holding + integer::length_estimate + integer::field_location, i + + ! This is too big, but close enough + length_estimate = len_trim(str) + len_trim(val) + allocate(character(len=length_estimate) :: holding) + holding = " " + + print *, trim(str) + + ! Find the field + field_location = index(str, "{"//trim(field)//"}") + if(field_location > 0) then + + i = field_location + len_trim(field) + 2 + holding = str(1:field_location-1)//trim(val)//str(i:len_trim(str)) + + ! Put the results back now + str = holding + + end if + + print *, trim(str) + + deallocate(holding) + + end subroutine replace_field_text + + subroutine replace_field_int(str, field, val) + implicit none + + character(*), intent(inout)::str + character(*), intent(in)::field + integer, intent(in)::val + + character(16)::int_text + + write(int_text, *) val + + call replace_field_text(str, field, trim(adjustl(int_text))) + + end subroutine replace_field_int + end module utilities \ No newline at end of file -- cgit v1.2.3