Ideas please?
Kelvin Hales
Try something like this:
diff=ichar('A')-ichar('a')
upper=char(ichar(lower)+diff)
Markku Save
There are CHAR/ICHAR and ACHAR/IACHAR which can be used.
But I don't want to start a new thread about these functions!
My need for this type of conversions is very limited and I don't care about
what time it takes. Furthermore I often want to deal with "odd" european
characters. Thus I use the module below which is easy to extend for
different local letters.
Hope this helps, Kurt
!==============================
module up_lw
character(len=26), parameter, private :: &
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", &
lower = "abcdefghijklmnopqrstuvwxyz"
contains
subroutine lower_case( str )
implicit none
integer :: i, is
character(len=*) str
!-------------------------------
do is = 1, len_trim( str )
i = index( upper, str(is:is) )
if( i .gt. 0 ) str(is:is) = lower(i:i)
enddo
end subroutine lower_case
subroutine upper_case( str )
implicit none
integer :: i, is
character(len=*) str
!-------------------------------
do is = 1, len_trim( str )
i = index( lower, str(is:is) )
if( i .gt. 0 ) str(is:is) = upper(i:i)
enddo
end subroutine upper_case
end module up_lw
!==============================
Kurt Kaellblad, Ph.D. <kurt.k...@bkl.lth.se>
Building Science, Lund Institute of Technology
Lund University, Sweden
That works, provided that the character 'lower' is guaranteed to be
alphabetic and provided that all the alphabetic characters have the same
fixed difference in the collating sequence (not necesarily a portable
assumption).
--
J. Giles
On Thu, 06 May 1999 11:33:48 +0100, Kelvin Hales <kha...@khales.cix.co.uk>
wrote:
-|Simplest way to convert string to all Upper or Lower Case characters?
-|I was surprised to find (after much searching) that DVF 5.0 seems not
-|to include any function to carry out this simple task.
-|
-|Ideas please?
-|
-|Kelvin Hales
-|
Herman D. Knoble, research associate
mailto:h...@psu.edu
http://www.personal.psu.edu/hdk
Penn State Center for Academic Computing
214 C Computer Building
University Park, PA 16802-2101
phone: +1 (814) 865-0818
fax: +1 (814) 863-7049
Penn State Center for Academic Computing
214-C Computer Building
University Park, PA 16802-2101
phone: +1 (814) 865-0818
fax: +1 (814) 863-7049
Where did you find these functions???
I'm using DVF6.0B and the only place I can find UCASE and LCASE is in the
online documentation but only as functions in MS's Visual Basic. Any attempt
to link a Fortran program with these functions result in "error LNK2001:
unresolved external symbol".
Greetings, Kurt
> Simplest way to convert string to all Upper or Lower Case characters?
> I was surprised to find (after much searching) that DVF 5.0 seems not
> to include any function to carry out this simple task.
>
> Ideas please?
>
> Kelvin Hales
Here is a simple f77 program which will convert a file to upper case
IMPLICIT NONE
CHARACTER*20 Fname
CHARACTER*80 LineIn, LineOut
INTEGER*4 j,ich
write(9,*) 'Enter filename'
read (9,*) Fname
open(2,file=Fname)
open(3,file='uc'//Fname)
DO
LineIn = ' '
LineOut = ' '
read(2,'(a)',END=100) LineIn
DO (j=1,80)
ich = ichar( LineIn(j:j) )
if(ich .ge. 97 .and. ich .le. 122) ich = ich - 32
LineOut(j:j) = char(ich)
END DO
write(3,'(a)') LineOut
END DO
100 CONTINUE
STOP
END
Paul Zarchan
Use DVF 6's user32 mod; it has interfaces to the API's CharLower/Upper.
Regards,
Gerry T.
>Simplest way to convert string to all Upper or Lower Case characters?
>I was surprised to find (after much searching) that DVF 5.0 seems not
>to include any function to carry out this simple task.
>Ideas please?
>Kelvin Hales
This subroutine makes lower case letters in the character variable all
upper case.
SUBROUTINE UPPER(STRING)
IMPLICIT NONE
CHARACTER STRING*140
INTEGER I,J
DO I=1,140
J=ICHAR(STRING(I:I))
IF(J.GE.97.AND.J.LE.122) STRING(I:I)=CHAR(J-32)
END DO
RETURN
END
Kelvin
This doesn't work for s..t on the mainframe IBM with EBCDIC codes.
It doesn't even work on PC clones running windows if you're using the
whole extended character set. The conversion of å to Å won't be done.
And the letters š and Š are not even 32 units apart in the collating sequence.
(If you can't read the examples given here, you obviously don't have the
same character set - a demonstration of the fact that this question is
implementation dependent.)
Case conversion is inherently system dependent (unless you're using IACHAR
and ACHAR and limiting yourself to pure ASCII). A faster means is to do the
following:
Subroutine UPPER (string)
implicit none
Character string*140
Integer i, j
Integer, parameter :: Cmax = size_of_character_set
Character :: table(Cmax) = (/ initialize array of character*1 &
consisting of the whole character set &
in collating sequence order, but with &
upper-case letters where the lower-case &
would normally be /)
Do i = 1,140
j = ICHAR (string(i:i))
string(i:i) = table(j)
End do
End Subroutine UPPER
This is not portable (but then, assumptions about which characters are lower-
and which are upper-case aren't portable anyway). It is fast however. A smart
compiler may eve be able to recognize that the whole body of the loop is just
a single XLAT instruction (if the hardware has such a thing, or something
corresponding).
--
J. Giles