Skip to content

Commit

Permalink
Fixed extract_word() for n>number of words
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
adcroft committed Sep 14, 2016
1 parent 4a23711 commit 0aef287
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/framework/MOM_string_functions.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0aef287

Please sign in to comment.