1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573 |
- #define TRACEBACK write (gol,'("in ",a," (",a,i6,")")') rname, __FILE__, __LINE__ ; call goErr
- #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
- #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
- module GO_String
- use GO_Print, only : gol, goPr, goErr
- implicit none
-
- private
- public :: goSplitLine
- public :: goReadFromLine
- public :: goSplitString
- public :: goMatchValue
- public :: goMatchValues
- public :: goVarValue
- public :: goNum2str
- public :: goUpCase, goLoCase
- public :: goWriteKeyNum
- public :: goTab2Space
- public :: goReplace, goTranslate
-
-
- character(len=*), parameter :: mname = 'GO_String'
-
-
- interface goReadFromLine
- module procedure ReadFromLine_i
- module procedure ReadFromLine_r
- module procedure ReadFromLine_l
- module procedure ReadFromLine_s
- end interface
- interface goSplitString
- module procedure goSplitString_s
- module procedure goSplitString_r
- end interface
-
- interface goMatchValue
- module procedure MatchValue_s
- end interface
- interface goMatchValues
- module procedure MatchValues_s
- module procedure MatchValues_i
- end interface
- interface goVarValue
- module procedure goVarValue_s
- module procedure goVarValue_i
- module procedure goVarValue_r
- module procedure goVarValue_l
- end interface
- interface goNum2str
- module procedure num2str_i
- module procedure num2str_r
- end interface
- interface goUpCase
- module procedure UpCase
- end interface
- interface goLoCase
- module procedure LoCase
- end interface
- interface goWriteKeyNum
- module procedure WriteKeyNum
- end interface
- interface goReplace
- module procedure goReplace_s
- module procedure goReplace_i
- end interface
- contains
-
- subroutine goSplitLine( line, s1, c, s2, status )
-
- character(len=*), intent(in) :: line
- character(len=*), intent(out) :: s1
- character(len=1), intent(in) :: c
- character(len=*), intent(out) :: s2
- integer, intent(out) :: status
-
- integer :: l, pos
- character(len=len(line)) :: s
-
- s = line
- l = len_trim(s)
- pos = scan(s,c)
- if ( (pos<1) .or. (pos>l) ) then
-
-
- s1 = AdjustL( s(1:l) )
- s2 = ''
- else if (pos==1) then
-
- s1 = ''
- if (l==1) then
-
- s2 = ''
- else
-
- s2 = AdjustL( s(pos+1:l) )
- end if
- else
-
-
- s1 = AdjustL( s(1:pos-1) )
- if (pos==l) then
-
- s2 = ''
- else
-
-
- s2 = AdjustL( s(pos+1:l) )
- end if
- end if
-
-
- status = 0
- end subroutine goSplitLine
-
-
- subroutine ReadFromLine_i( s, i, status, sep, default )
-
- character(len=*), intent(inout) :: s
- integer, intent(inout) :: i
- integer, intent(out) :: status
-
- character(len=1), intent(in), optional :: sep
- integer, intent(in), optional :: default
-
-
- character(len=*), parameter :: rname = mname//'/ReadFromLine_i'
-
-
- character(len=len(s)) :: s1, s2
- character(len=1) :: thesep
-
-
-
- thesep = ','
- if (present(sep)) thesep = sep
-
- call goSplitLine( s, s1, thesep, s2, status )
- IF_ERROR_RETURN(status=1)
-
- if ( len_trim(s1) == 0 ) then
-
- if ( present(default) ) then
- i = default
- else
- write (gol,'("found empty leading part while no default specified:")'); call goErr
- write (gol,'(" line : `",a,"`")') trim(s); call goErr
- write (gol,'(" sep : `",a,"`")') trim(thesep); call goErr
- TRACEBACK; status=1; return
- end if
- else
-
- read (s1,*,iostat=status) i
- if ( status /= 0 ) then
- write (gol,'(a," while reading integer out of `",a,"`")') trim(s); call goErr
- write (gol,'("in ",a)') rname; call goErr; status=1; return
- end if
- end if
-
-
- s = s2
-
-
- status = 0
- end subroutine ReadFromLine_i
-
- subroutine ReadFromLine_r( s, r, status, sep, default )
-
- character(len=*), intent(inout) :: s
- real, intent(out) :: r
- integer, intent(out) :: status
- character(len=1), intent(in), optional :: sep
- real, intent(in), optional :: default
-
-
- character(len=*), parameter :: rname = mname//'/ReadFromLine_r'
-
-
- character(len=len(s)) :: s1, s2
- character(len=1) :: thesep
-
-
- thesep = ','
- if (present(sep)) thesep = sep
-
- call goSplitLine( s, s1, thesep, s2, status )
- IF_ERROR_RETURN(status=1)
-
- if ( len_trim(s1) == 0 ) then
-
- if ( present(default) ) then
- r = default
- else
- write (gol,'("found empty leading part while no default specified:")'); call goErr
- write (gol,'(" line : `",a,"`")') trim(s); call goErr
- write (gol,'(" sep : `",a,"`")') trim(thesep); call goErr
- TRACEBACK; status=1; return
- end if
- else
-
- read (s1,*,iostat=status) r
- if ( status /= 0 ) then
- write (gol,'("error while reading real out `",a,"`")') trim(s); call goErr
- write (gol,'("in ",a)') rname; call goErr; status=1; return
- end if
- end if
-
- s = s2
-
- status = 0
- end subroutine ReadFromLine_r
-
- subroutine ReadFromLine_l( s, l, status, sep, default )
-
- character(len=*), intent(inout) :: s
- logical, intent(out) :: l
- integer, intent(out) :: status
- character(len=1), intent(in), optional :: sep
- logical, intent(in), optional :: default
-
-
- character(len=*), parameter :: rname = mname//'/ReadFromLine_l'
-
-
- character(len=len(s)) :: s1, s2
- character(len=1) :: thesep
-
-
- thesep = ','
- if (present(sep)) thesep = sep
-
- call goSplitLine( s, s1, thesep, s2, status )
- IF_ERROR_RETURN(status=1)
-
- if ( len_trim(s1) == 0 ) then
-
- if ( present(default) ) then
- l = default
- else
- write (gol,'("found empty leading part while no default specified:")'); call goErr
- write (gol,'(" line : `",a,"`")') trim(s); call goErr
- write (gol,'(" sep : `",a,"`")') trim(thesep); call goErr
- TRACEBACK; status=1; return
- end if
- else
-
- read (s1,*,iostat=status) l
- if ( status /= 0 ) then
- write (gol,'("while reading logical out `",a,"`")') trim(s); call goErr
- write (gol,'("in ",a)') rname; call goErr; status=1; return
- end if
- end if
-
- s = s2
-
- status = 0
- end subroutine ReadFromLine_l
-
- subroutine ReadFromLine_s( s, ss, status, sep )
-
- character(len=*), intent(inout) :: s
- character(len=*), intent(out) :: ss
- integer, intent(out) :: status
- character(len=1), intent(in), optional :: sep
-
-
- character(len=*), parameter :: rname = mname//'/ReadFromLine_s'
-
-
- character(len=len(s)) :: s1, s2
- character(len=1) :: thesep
- integer :: l, ll
-
-
- thesep = ','
- if (present(sep)) thesep = sep
-
- call goSplitLine( s, s1, thesep, s2, status )
- IF_ERROR_RETURN(status=1)
-
-
- l = len_trim(s1)
- ll = len(ss)
- if ( ll < l ) then
- write (gol,'("size of output string not sufficient:")'); call goErr
- write (gol,'(" first part of input : ",a )') trim(s1) ; call goErr
- write (gol,'(" output length : ",i4)') ll ; call goErr
- write (gol,'("in ",a)') rname; call goErr; status=1; return
- end if
-
- ss = trim(s1)
-
- s = s2
-
- status = 0
- end subroutine ReadFromLine_s
-
- subroutine goSplitString_s( line, n, values, status, sep )
-
-
-
- character(len=*), intent(in) :: line
- integer, intent(out) :: n
- character(len=*), intent(out) :: values(:)
- integer, intent(out) :: status
- character(len=1), intent(in), optional :: sep
-
-
-
- character(len=*), parameter :: rname = mname//'/goSplitString'
-
-
-
- character(len=1) :: the_sep
- character(len=len(line)) :: line_curr
- character(len=len(line)) :: val
-
-
-
- the_sep = ' '
- if ( present(sep) ) the_sep = sep
-
-
- line_curr = line
-
-
- n = 0
-
- do
-
- if ( len_trim(line_curr) == 0 ) exit
-
- n = n + 1
-
- if ( n > size(values) ) then
- write (gol,'("output array is too small:")'); call goErr
- write (gol,'(" input line : ",a )') trim(line); call goErr
- write (gol,'(" size(values) : ",i4)') size(values); call goErr
- TRACEBACK; status=1; return
- end if
-
- call goReadFromLine( line_curr, val, status, sep=the_sep )
- IF_NOTOK_RETURN(status=1)
-
- values(n) = val
- end do
-
-
- status = 0
-
- end subroutine goSplitString_s
-
-
-
-
-
- subroutine goSplitString_r( line, n, values, status, sep )
-
- character(len=*), intent(in) :: line
- integer, intent(out) :: n
- real, intent(out) :: values(:)
- integer, intent(out) :: status
- character(len=1), intent(in), optional :: sep
-
- character(len=*), parameter :: rname = mname//'/goSplitString'
-
- character(len=1) :: the_sep
- character(len=len(line)) :: line_curr
- real :: val
-
-
- the_sep = ' '
- if ( present(sep) ) the_sep = sep
-
- line_curr = line
-
- n = 0
-
- do
-
- if ( len_trim(line_curr) == 0 ) exit
-
- n = n + 1
-
- if ( n > size(values) ) then
- write (gol,'("output array is too small:")'); call goErr
- write (gol,'(" input line : ",a )') trim(line); call goErr
- write (gol,'(" size(values) : ",i4)') size(values); call goErr
- TRACEBACK; status=1; return
- end if
-
- call goReadFromLine( line_curr, val, status, sep=the_sep )
- IF_NOTOK_RETURN(status=1)
-
- values(n) = val
- end do
-
- status = 0
- end subroutine goSplitString_r
-
-
- subroutine MatchValue_s( val, list, ind, status, quiet )
-
-
-
- character(len=*), intent(in) :: val
- character(len=*), intent(in) :: list(:)
- integer, intent(out) :: ind
- integer, intent(out) :: status
-
- logical, optional :: quiet
-
-
-
- character(len=*), parameter :: rname = mname//'/MatchValue_s'
-
-
-
- integer :: nlist
- integer :: i
- logical :: verbose
-
-
-
- verbose = .true.
- if ( present(quiet) ) verbose = .not. quiet
-
-
- nlist = size(list)
-
-
- ind = -1
- do i = 1, nlist
-
- if ( goUpCase(trim(val)) == goUpCase(trim(list(i))) ) then
-
- ind = i
-
- exit
- end if
- end do
-
- if ( ind < 0 ) then
- if ( verbose ) then
- write (gol,'("name not supported:")'); call goErr
- write (gol,'(" value : ",a )') trim(val); call goErr
- write (gol,'(" possible values : ")'); call goErr
- do i = 1, nlist
- write (gol,'(" ",i4," ",a)') i, trim(list(i)); call goErr
- end do
- TRACEBACK
- end if
- status=-1; return
- end if
-
- status = 0
-
- end subroutine MatchValue_s
-
-
-
-
- subroutine MatchValues_s( line, list, &
- n, values, inds, &
- status, quiet )
-
-
-
- character(len=*), intent(in) :: line
- character(len=*), intent(in) :: list(:)
- integer, intent(out) :: n
- character(len=*), intent(out) :: values(:)
- integer, intent(out) :: inds(:)
- integer, intent(out) :: status
-
- logical, optional :: quiet
-
-
-
- character(len=*), parameter :: rname = mname//'/MatchValues_s'
-
-
-
- integer :: nlist
- character(len=len(line)) :: line_curr
- character(len=16) :: val
- integer :: ind
- logical :: verbose
-
-
-
- verbose = .true.
- if ( present(quiet) ) verbose = .not. quiet
-
-
- nlist = size(list)
-
-
- line_curr = line
-
-
- n = 0
-
- do
-
- if ( len_trim(line_curr) == 0 ) exit
-
- n = n + 1
-
- if ( (n > size(values)) .or. (n > size(inds)) ) then
- write (gol,'("output array is too small:")'); call goErr
- write (gol,'(" input line : ",a )') trim(line); call goErr
- write (gol,'(" size(values) : ",i4)') size(values); call goErr
- write (gol,'(" size(inds ) : ",i4)') size(inds ); call goErr
- TRACEBACK; status=1; return
- end if
-
- call goReadFromLine( line_curr, val, status, sep=' ' )
- IF_NOTOK_RETURN(status=1)
-
- values(n) = val
-
- call goMatchValue( val, list, ind, status, quiet )
-
- if ( status /= 0 ) then
- if ( verbose ) then
- write (gol,'("unable to match value with list:")'); call goErr
- write (gol,'(" line : ",a )') trim(line); call goErr
- write (gol,'(" line element : ",i3)') n; call goErr
- write (gol,'(" line value : ",a )') trim(val); call goErr
- TRACEBACK
- end if
- status=1; return
- end if
-
- inds(n) = ind
- end do
-
-
- if ( n < 1 ) then
- write (gol,'("no values extracted from line :")'); call goErr
- write (gol,'(" ",a)') trim(line); call goErr
- TRACEBACK; status=1; return
- end if
-
-
- status = 0
-
- end subroutine MatchValues_s
-
-
-
-
- subroutine MatchValues_i( line, i1, i2, &
- n, values, &
- status, quiet )
-
-
-
- character(len=*), intent(in) :: line
- integer, intent(in) :: i1, i2
- integer, intent(out) :: n
- integer, intent(out) :: values(:)
- integer, intent(out) :: status
-
- logical, optional :: quiet
-
-
-
- character(len=*), parameter :: rname = mname//'/MatchValues_i'
-
-
-
- character(len=len(line)) :: line_curr
- integer :: val
- logical :: verbose
-
-
-
- verbose = .true.
- if ( present(quiet) ) verbose = .not. quiet
-
-
- line_curr = line
-
-
- n = 0
-
- do
-
- if ( len_trim(line_curr) == 0 ) exit
-
- n = n + 1
-
- if ( n > size(values) ) then
- write (gol,'("output arrays are too small:")'); call goErr
- write (gol,'(" input line : ",a )') trim(line); call goErr
- write (gol,'(" size(values) : ",i4)') size(values); call goErr
- TRACEBACK; status=1; return
- end if
-
- call goReadFromLine( line_curr, val, status, sep=' ' )
- IF_NOTOK_RETURN(status=1)
-
- values(n) = val
-
- if ( (val < i1) .or. (val > i2) ) then
- if ( verbose ) then
- write (gol,'("value not in range:")'); call goErr
- write (gol,'(" list : ",a )') trim(line); call goErr
- write (gol,'(" list element : ",i3)') n; call goErr
- write (gol,'(" list value : ",i3)') val; call goErr
- write (gol,'(" possible range : ",i3," .. ",i3)') i1, i2; call goErr
- TRACEBACK
- end if
- status=1; return
- end if
- end do
-
-
- if ( n < 1 ) then
- write (gol,'("no values extracted from line :")'); call goErr
- write (gol,'(" ",a)') trim(line); call goErr
- TRACEBACK; status=1; return
- end if
-
-
- status = 0
-
- end subroutine MatchValues_i
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- subroutine goVarValue_s( line, sep, var, is, val, status )
-
- use GO_Print, only : gol, goPr, goErr
-
-
- character(len=*), intent(in) :: line
- character(len=1), intent(in) :: sep
- character(len=*), intent(in) :: var
- character(len=1), intent(in) :: is
- character(len=*), intent(inout) :: val
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/goVarValue_s'
-
-
-
- character(len=len(line)) :: line2
- character(len=len(line)) :: varval
- character(len=16) :: var2
- character(len=256) :: val2
-
-
-
-
- line2 = line
-
-
- status = -1
-
- do
-
- if ( len_trim(line2) == 0 ) exit
-
- call goReadFromLine( line2, varval, status, sep=sep )
- IF_ERROR_RETURN(status=1)
-
- call goSplitLine( varval, var2, is, val2, status )
- IF_ERROR_RETURN(status=1)
-
- if ( trim(var2) == trim(var) ) then
-
- val = trim(val2)
-
- status = 0
- end if
- end do
-
- return
-
- end subroutine goVarValue_s
-
-
- subroutine goVarValue_i( line, sep, var, is, val, status )
-
- use GO_Print, only : gol, goPr, goErr
-
-
- character(len=*), intent(in) :: line
- character(len=1), intent(in) :: sep
- character(len=*), intent(in) :: var
- character(len=1), intent(in) :: is
- integer, intent(inout) :: val
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/goVarValue_i'
-
-
-
- character(len=len(line)) :: line2
- character(len=len(line)) :: varval
- character(len=16) :: var2
- character(len=256) :: val2
-
-
-
-
- line2 = line
-
-
- status = -1
-
- do
-
- if ( len_trim(line2) == 0 ) exit
-
- call goReadFromLine( line2, varval, status, sep=sep )
- IF_ERROR_RETURN(status=1)
-
- call goSplitLine( varval, var2, is, val2, status )
- IF_ERROR_RETURN(status=1)
-
- if ( trim(var2) == trim(var) ) then
-
- read (val2,'(i6)') val
-
- status = 0
- end if
- end do
-
- return
- end subroutine goVarValue_i
-
-
-
- subroutine goVarValue_r( line, sep, var, is, val, status )
-
- use GO_Print, only : gol, goPr, goErr
-
-
- character(len=*), intent(in) :: line
- character(len=1), intent(in) :: sep
- character(len=*), intent(in) :: var
- character(len=1), intent(in) :: is
- real, intent(inout) :: val
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/goVarValue_r'
-
-
-
- character(len=len(line)) :: line2
- character(len=len(line)) :: varval
- character(len=16) :: var2
- character(len=256) :: val2
-
-
-
-
- line2 = line
-
- status = -1
-
- do
-
- if ( len_trim(line2) == 0 ) exit
-
- call goReadFromLine( line2, varval, status, sep=sep )
- IF_ERROR_RETURN(status=1)
-
- call goSplitLine( varval, var2, is, val2, status )
- IF_ERROR_RETURN(status=1)
-
- if ( trim(var2) == trim(var) ) then
-
- read (val2,*) val
-
- status = 0
- end if
- end do
-
- return
- end subroutine goVarValue_r
-
-
- subroutine goVarValue_l( line, sep, var, is, val, status )
-
- use GO_Print, only : gol, goPr, goErr
-
-
- character(len=*), intent(in) :: line
- character(len=1), intent(in) :: sep
- character(len=*), intent(in) :: var
- character(len=1), intent(in) :: is
- logical, intent(inout) :: val
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/goVarValue_l'
-
-
-
- character(len=len(line)) :: line2
- character(len=len(line)) :: varval
- character(len=16) :: var2
- character(len=256) :: val2
-
-
-
-
- line2 = line
-
-
- status = -1
-
- do
-
- if ( len_trim(line2) == 0 ) exit
-
- call goReadFromLine( line2, varval, status, sep=sep )
- IF_ERROR_RETURN(status=1)
-
- call goSplitLine( varval, var2, is, val2, status )
- IF_ERROR_RETURN(status=1)
-
- if ( trim(var2) == trim(var) ) then
-
- read (val2,'(l1)') val
-
- status = 0
- end if
- end do
-
- return
- end subroutine goVarValue_l
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- character(len=6) function num2str_i( i, fmt )
-
- integer, intent(in) :: i
- character(len=*), intent(in), optional :: fmt
-
- character(len=6) :: s
-
- if (present(fmt)) then
- write (s,fmt=fmt) i
- else
- write (s,'(i6)') i
- end if
- num2str_i=adjustl(s)
- end function num2str_i
- character(len=12) function num2str_r( r, fmt )
-
- real, intent(in) :: r
- character(len=*), intent(in), optional :: fmt
-
- character(len=12) :: s
-
- if (present(fmt)) then
- write (s,fmt=fmt) r
- else
- write (s,'(g10.3)') r
- end if
- num2str_r=adjustl(s)
- end function num2str_r
-
- function UpCase( s )
-
- character(len=*), intent(in) :: s
- character(len=len(s)) :: UpCase
-
- integer :: i
-
- do i = 1, len_trim(s)
- select case (s(i:i))
- case ('a') ; UpCase(i:i) = 'A'
- case ('b') ; UpCase(i:i) = 'B'
- case ('c') ; UpCase(i:i) = 'C'
- case ('d') ; UpCase(i:i) = 'D'
- case ('e') ; UpCase(i:i) = 'E'
- case ('f') ; UpCase(i:i) = 'F'
- case ('g') ; UpCase(i:i) = 'G'
- case ('h') ; UpCase(i:i) = 'H'
- case ('i') ; UpCase(i:i) = 'I'
- case ('j') ; UpCase(i:i) = 'J'
- case ('k') ; UpCase(i:i) = 'K'
- case ('l') ; UpCase(i:i) = 'L'
- case ('m') ; UpCase(i:i) = 'M'
- case ('n') ; UpCase(i:i) = 'N'
- case ('o') ; UpCase(i:i) = 'O'
- case ('p') ; UpCase(i:i) = 'P'
- case ('q') ; UpCase(i:i) = 'Q'
- case ('r') ; UpCase(i:i) = 'R'
- case ('s') ; UpCase(i:i) = 'S'
- case ('t') ; UpCase(i:i) = 'T'
- case ('u') ; UpCase(i:i) = 'U'
- case ('v') ; UpCase(i:i) = 'V'
- case ('w') ; UpCase(i:i) = 'W'
- case ('x') ; UpCase(i:i) = 'X'
- case ('y') ; UpCase(i:i) = 'Y'
- case ('z') ; UpCase(i:i) = 'Z'
- case default
- UpCase(i:i) = s(i:i)
- end select
- end do
- end function UpCase
-
- function LoCase( s )
-
- character(len=*), intent(in) :: s
- character(len=len(s)) :: LoCase
-
- integer :: i
-
- do i = 1, len_trim(s)
- select case (s(i:i))
- case ('A') ; LoCase(i:i) = 'a'
- case ('B') ; LoCase(i:i) = 'b'
- case ('C') ; LoCase(i:i) = 'c'
- case ('D') ; LoCase(i:i) = 'd'
- case ('E') ; LoCase(i:i) = 'e'
- case ('F') ; LoCase(i:i) = 'f'
- case ('G') ; LoCase(i:i) = 'g'
- case ('H') ; LoCase(i:i) = 'h'
- case ('I') ; LoCase(i:i) = 'i'
- case ('J') ; LoCase(i:i) = 'j'
- case ('K') ; LoCase(i:i) = 'k'
- case ('L') ; LoCase(i:i) = 'l'
- case ('M') ; LoCase(i:i) = 'm'
- case ('N') ; LoCase(i:i) = 'n'
- case ('O') ; LoCase(i:i) = 'o'
- case ('P') ; LoCase(i:i) = 'p'
- case ('Q') ; LoCase(i:i) = 'q'
- case ('R') ; LoCase(i:i) = 'r'
- case ('S') ; LoCase(i:i) = 's'
- case ('T') ; LoCase(i:i) = 't'
- case ('U') ; LoCase(i:i) = 'u'
- case ('V') ; LoCase(i:i) = 'v'
- case ('W') ; LoCase(i:i) = 'w'
- case ('X') ; LoCase(i:i) = 'x'
- case ('Y') ; LoCase(i:i) = 'y'
- case ('Z') ; LoCase(i:i) = 'z'
- case default
- LoCase(i:i) = s(i:i)
- end select
- end do
- end function LoCase
-
-
-
-
-
- subroutine WriteKeyNum( res, key, num )
-
-
-
- character(len=*), intent(out) :: res
- character(len=*), intent(in) :: key
- integer, intent(in) :: num
-
-
-
- integer :: anum
-
-
-
- anum = abs(num)
-
- if ( anum <= 9 ) then
- write (res,'(a,i1)') trim(key), anum
- else if ( anum <= 99 ) then
- write (res,'(a,i2)') trim(key), anum
- else if ( anum <= 999 ) then
- write (res,'(a,i3)') trim(key), anum
- else if ( anum <= 9999 ) then
- write (res,'(a,i4)') trim(key), anum
- else if ( anum <= 99999 ) then
- write (res,'(a,i5)') trim(key), anum
- else
- write (res,'(a,i6)') trim(key), anum
- end if
-
- end subroutine WriteKeyNum
-
-
-
- subroutine goTab2Space( s )
-
- character(len=*), intent(inout) :: s
-
- integer :: pos
-
- do
- pos = scan(s,char(9))
- if ( pos == 0 ) exit
- s(pos:pos) = ' '
- end do
- end subroutine goTab2Space
-
-
-
- subroutine goReplace_s( s, key, repl, status )
-
-
-
- character(len=*), intent(inout) :: s
- character(len=*), intent(in) :: key
- character(len=*), intent(in) :: repl
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/goReplace_s'
-
-
-
- integer :: n_in, l_in
- integer :: n_out
- integer :: ind
- character(len=len(s)) :: s_in
-
-
-
-
- s_in = s
-
-
- s = ''
- n_out = 0
-
-
- l_in = len_trim(s_in)
-
-
- n_in = 0
-
-
- do
-
-
- if ( n_in > l_in ) exit
-
-
- if ( len(key) < 1 ) then
- ind = 0
- else
- ind = index(s_in(n_in+1:l_in),key)
- end if
-
-
- if ( ind < 1 ) then
-
- s = s(1:n_out)//s_in(n_in+1:l_in)
- n_out = n_out + l_in-n_in
-
- exit
- end if
-
- s = s(1:n_out)//s_in(n_in+1:n_in+ind-1)
- n_out = n_out + ind-1
- n_in = n_in + ind-1
-
-
- s = s(1:n_out)//repl
- n_out = n_out + len(repl)
- n_in = n_in + len(key)
-
- end do
-
-
- status = 0
-
- end subroutine goReplace_s
-
-
-
- subroutine goReplace_i( s, key, fmt, i, status )
-
-
-
- character(len=*), intent(inout) :: s
- character(len=*), intent(in) :: key
- character(len=*), intent(in) :: fmt
- integer, intent(in) :: i
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/goReplace_i'
-
-
-
- character(len=8) :: repl
-
-
-
-
- write (repl,fmt) i
-
-
- call goReplace( s, key, trim(repl), status )
- IF_NOTOK_RETURN(status=1)
-
-
- status = 0
-
- end subroutine goReplace_i
-
-
-
-
-
- subroutine goTranslate( s, chars, repl, status )
-
-
-
- character(len=*), intent(inout) :: s
- character(len=*), intent(in) :: chars
- character(len=*), intent(in) :: repl
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/goTranslate'
-
-
-
- integer :: i
-
-
-
-
- do i = 1, len(chars)
-
- call goReplace( s, chars(i:i), repl, status )
- IF_NOTOK_RETURN(status=1)
- end do
-
-
- status = 0
-
- end subroutine goTranslate
- end module GO_String
|