From 0aef287ab102d1d047372ea9d72c79dc6f3417d7 Mon Sep 17 00:00:00 2001 From: Alistair Adcroft Date: Tue, 13 Sep 2016 10:56:27 -0400 Subject: [PATCH] Fixed extract_word() for n>number of words - extract_word("a,b,c",",",5) was returning "c" when it should have returned "". It turns out we had no instances where we used this or tested for it. - Fixed bug. - Added use case in unit_tests. - No answer changes. --- src/framework/MOM_string_functions.F90 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/framework/MOM_string_functions.F90 b/src/framework/MOM_string_functions.F90 index e5e5df681b..64c14ad213 100644 --- a/src/framework/MOM_string_functions.F90 +++ b/src/framework/MOM_string_functions.F90 @@ -255,7 +255,7 @@ end function extractWord endif endif enddo - if (b<=ns) extract_word = trim(string(b:ns)) + if (b<=ns .and. nw==n-1) extract_word = trim(string(b:ns)) end function extract_word !> Returns string with all spaces removed. @@ -298,6 +298,8 @@ logical function string_functions_unit_tests() call localTest(extractWord("One Two,Three",3),"Three") call localTest(extractWord("One Two, Three",3),"Three") call localTest(extractWord(" One Two,Three",1),"One") + call localTest(extract_word("One,Two,Three",",",3),"Three") + call localTest(extract_word("One,Two,Three",",",4),"") write(*,*) '==========================================================' contains subroutine localTest(str1,str2)