100 lines
3.2 KiB
FortranFixed
100 lines
3.2 KiB
FortranFixed
subroutine charfloatlineparser(longchar,nmax,charvars,
|
|
&nchars,floatvars,nfloats)
|
|
implicit none
|
|
!7 Sept 2013, revised version
|
|
!parse a long line of chars into char and/or float variables with the following assumptions:
|
|
!1. Each cell is separated by a separating character which can be either a ',', blank space(s) or anything
|
|
!with the ASCII code less than and including 032 or larger than and including 127
|
|
!2. Any separating characters at the end of the line are discarded, i.e.
|
|
! '1,2,3,4,a,b,c,,,,,,,,,, ,'='1,2,3,4,a,b,c'
|
|
!3. If there is no entry between two non-comma separating characters,these two separating characters are treated as one.
|
|
! i.e. '1 2 3 4 a b c'='1,2,3,4,a,b,c'
|
|
!4. If there is no entry between two commas that are not positioned in the end of the line, a missing value is assumed to
|
|
!exist between these two commas and this missing value is denoted with -9999, i.e.
|
|
! i.e. '1,,3,4,a,b,c'='1,-9999,3,4,a,b,c'
|
|
!5. Comma has priotity as a separating characer. E.g commas and blank spaces are not used simultaneously as
|
|
! separating characters in a single line. When both commas and blank spaces appear in the line, comma is
|
|
! the saparating character and blank spaces are repalced with '_'
|
|
integer nmax,nchars,nfloats
|
|
character(*)::longchar
|
|
character charvars(nmax+100)*50,achar*50,stringvars(nmax+100)*50
|
|
double precision floatvars(nmax)
|
|
integer i,j,k,m,n,ndot,nplus,nminus,nd,ne,nCapD,nCapE,leng
|
|
!
|
|
call charlineparser(longchar,nmax,stringvars,n)
|
|
nchars=0
|
|
nfloats=0
|
|
do j=1,n
|
|
ndot=0
|
|
nplus=0
|
|
nminus=0
|
|
nd=0
|
|
ne=0
|
|
nCapD=0
|
|
nCapE=0
|
|
leng=LEN_TRIM(stringvars(j))
|
|
achar=stringvars(j)(1:leng)
|
|
i=leng
|
|
5 k=ichar(achar(i:i))
|
|
if(k.le.47.or.k.ge.58)then
|
|
m=0
|
|
if(k.eq.46)then
|
|
ndot=ndot+1
|
|
m=1
|
|
endif
|
|
if(k.eq.43)then
|
|
nplus=nplus+1
|
|
m=1
|
|
endif
|
|
if(k.eq.45)then
|
|
nminus=nminus+1
|
|
m=1
|
|
endif
|
|
if(k.eq.100)then
|
|
nd=nd+1
|
|
m=1
|
|
endif
|
|
if(k.eq.101)then
|
|
ne=ne+1
|
|
m=1
|
|
endif
|
|
if(k.eq.68)then
|
|
nCapD=nCapD+1
|
|
m=1
|
|
endif
|
|
if(k.eq.69)then
|
|
nCapE=nCapE+1
|
|
m=1
|
|
endif
|
|
if(m.eq.0)then
|
|
nchars=nchars+1
|
|
charvars(nchars)=achar(1:leng)
|
|
goto 10
|
|
endif
|
|
endif
|
|
i=i-1
|
|
if(i.ge.1)goto 5
|
|
m=0
|
|
if(ndot.gt.1)m=1
|
|
if(nplus.gt.1)m=1
|
|
if(nminus.gt.1)m=1
|
|
if(nd.gt.1)m=1
|
|
if(ne.gt.1)m=1
|
|
if(nCapD.gt.1)m=1
|
|
if(nCapE.gt.1)m=1
|
|
if((nplus*nminus).gt.0)m=1
|
|
if((nd+ne+nCapD+nCapE).gt.1)m=1
|
|
if((nd+ne+nCapD+nCapE).eq.leng)m=1
|
|
if(m.eq.1)then
|
|
nchars=nchars+1
|
|
charvars(nchars)=achar(1:leng)
|
|
else
|
|
nfloats=nfloats+1
|
|
m=len(trim(achar))
|
|
call extCharToFloatNum(m,achar,floatvars(nfloats),k)
|
|
endif
|
|
10 continue
|
|
enddo
|
|
return
|
|
end subroutine charfloatlineparser
|