- 积分
- 17
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-7-24
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
fortran没有数据分割函数,很不方便,这里是一个常用的字符串数据分割函数,直接贴出,免得大家麻烦。
!// ==============================================
subroutine SpiltString_str(str, Space, string_A, ND)
! ******** ********
! string_A(ND): 字符串str分割后的数组,ND为维数
! Space : 分隔符
! ******** ********
implicit none
character(len = *), intent(in) :: str,Space
character(len = 50), intent(out) :: string_A(24)
integer, intent(out) :: ND
! *** *** *** *** *** immediate variable *** *** *** *** ***
logical:: LFT
character(len = 1):: ch
integer:: iL ! for loop
character(len = len(str)):: cstr
integer:: str_len
integer:: bi(size(string_A)) ! begin index
integer:: ei(size(string_A)) ! end index
ND = 0
cstr = adjustL(str)
str_len = len_trim(cstr)
if ( str_len == 0 ) return
LFT = .true.
Do iL = 1, str_len, 1
ch = cstr(iL : iL)
If ( ch /= Space .and. LFT ) Then
ND = ND + 1
LFT = .false.
bi(ND) = iL
Else If ( (ch == Space) .and. (.not. LFT) ) Then
LFT = .true.
ei(ND) = iL - 1
End If
End Do
ei(ND) = str_len
Do iL = 1, ND, 1
string_A(iL) = cstr(bi(iL) : ei(iL))
End Do ! iL
string_A(ND + 1 : size(string_A)) = 0
return
end subroutine SpiltString_str
!// ==============================================
subroutine DataNo(str, ND)
! ***************************
! 字符串str中包含的数据段数ND
! 分隔符为空格
! ***************************
implicit none
character(len = *), intent(in):: str
integer, intent(out):: ND
! *** *** *** *** *** immediate variable *** *** *** *** ***
logical:: LFT
character(len = 1):: ch
integer:: iL ! for loop
character(len = len(str)):: cstr
integer:: str_len
cstr = adjustL( str )
ND = 0
str_len = len_trim(cstr)
IF ( str_len > 0 ) THEN
LFT = .true.
Do iL = 1, str_len, 1
ch = cstr(iL : iL)
If ( (ch /= " ") .and. LFT ) Then
ND = ND + 1
LFT = .false.
Else If ( (ch == " ") .and. (.not. LFT) ) Then
LFT = .true.
End If !
End Do
END IF ! str_len > 0
return
end subroutine
|
评分
-
查看全部评分
|