@@ -682,6 +682,106 @@ end subroutine progress_bar
682
682
! | The end of the subroutine progress_bar. |
683
683
! +-------------------------------------------------------------------+
684
684
685
+
686
+ function line_2_strings (line ) result(strings)
687
+
688
+ ! arguments
689
+ character (len=* ), intent (in ) :: line
690
+
691
+ ! local data
692
+ character (len= 20 ), allocatable :: strings(:)
693
+ character (len= 20 ) :: token
694
+
695
+ integer :: n,i,istart
696
+
697
+ ! Initialize counters
698
+
699
+ ! Count number of tokens for allocation
700
+ n = count_tokens(line)
701
+
702
+ ! Allocate arrays based on the number of tokens
703
+ allocate (strings(n))
704
+
705
+ ! Split line into tokens and categorize them
706
+ istart= 1
707
+ do i = 1 , n
708
+ call get_token(line, istart, token)
709
+ strings(i) = token
710
+ end do
711
+
712
+ return
713
+
714
+ end function line_2_strings
715
+
716
+ ! Function to count tokens in a line
717
+ integer function count_tokens (line )
718
+ character (len=* ), intent (in ) :: line
719
+ integer :: idx, len_line, count
720
+
721
+ count = 0
722
+ idx = 1
723
+ len_line = len_trim (line)
724
+
725
+ do while (idx <= len_line)
726
+ ! Skip delimiters
727
+ if (line(idx:idx) == ' ' .or. line(idx:idx) == ' ,' ) then
728
+ idx = idx + 1
729
+ else
730
+ count = count + 1
731
+ ! Skip the current token
732
+ do while (idx <= len_line .and. &
733
+ line(idx:idx) /= ' ' .and. line(idx:idx) /= ' ,' )
734
+ idx = idx + 1
735
+ end do
736
+ end if
737
+ end do
738
+
739
+ count_tokens = count
740
+
741
+ end function count_tokens
742
+
743
+
744
+ ! Function to get each token from the line
745
+ subroutine get_token (line , istart , token )
746
+ character (len=* ), intent (in ) :: line
747
+ integer , intent (inout ) :: istart
748
+ character (len=* ), intent (out ) :: token
749
+ integer :: i, len_line
750
+
751
+ len_line = len_trim (line)
752
+ token = ' '
753
+ i = istart
754
+ do while (i <= len_line .and. (line(i:i) == ' ' .or. line(i:i) == ' ,' ))
755
+ i = i + 1
756
+ end do
757
+ istart = i
758
+ do while (i <= len_line .and. line(i:i) /= ' ' .and. line(i:i) /= ' ,' )
759
+ token = trim (adjustl (token)) // line(i:i)
760
+ i = i + 1
761
+ end do
762
+ istart = i
763
+ end subroutine get_token
764
+
765
+ ! Function to check if a string is numeric
766
+ logical function is_numeric (str )
767
+ character (len=* ), intent (in ) :: str
768
+ integer :: i, dot_count
769
+ dot_count = 0
770
+ is_numeric = .true.
771
+ do i = 1 , len_trim (str)
772
+ if (str(i:i) == ' .' ) then
773
+ dot_count = dot_count + 1
774
+ if (dot_count > 1 ) then
775
+ is_numeric = .false.
776
+ return
777
+ end if
778
+ else if (.not. (str(i:i) >= ' 0' .and. str(i:i) <= ' 9' )) then
779
+ is_numeric = .false.
780
+ return
781
+ end if
782
+ end do
783
+ end function is_numeric
784
+
685
785
end module utility
686
786
! +---------------------------------------------------------------------+
687
787
! | The end of the module utility |
0 commit comments