 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Jim
Joined: 21 Jul 2006 Posts: 24 Location: USA
|
Posted: Mon Sep 19, 2011 1:25 am Post subject: Error 169 - different types cannot be comapred with .EQ. |
|
|
I am getting an error when compiling the following expression:
IF (UX.EQ.'US'.OR.UX.EQ.'ME'.OR.UX.EQ.'us'.OR.UX.EQ.'Me'.
*OR.UX.EQ.'me') GOTO 110
"error 169 - Different types cannot be compared with .EQ. (REAL(KIND=1) and CHARACTER(LEN=2))"
Any suggestions?
Thanks,
Jim |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8214 Location: Salford, UK
|
Posted: Mon Sep 19, 2011 7:56 am Post subject: |
|
|
UX is REAL whilst 'US' is CHARACTER and you are not allowed to compare the two for equality.
Perhaps you need to declare UX as CHARACTER and assign a value to it.
Use IMPLICIT NONE to ensure that all variables are explicitly declared. |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Mon Sep 19, 2011 2:40 pm Post subject: |
|
|
If you programmed Fortran several decades ago, you stored character information in arrays of REAL or INTEGER type. This got progressively more frowned on after the introduction of CHARACTER type, to the point that it is now illegal. If your intention is clear from the code fragment, then you are locked into an obsolete method. Otherwise, you have forgotten to declare the variables as being of CHARACTER type.
E |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Sep 19, 2011 9:19 pm Post subject: |
|
|
Because the error indicates that UX is real(kind=1) which is the default real kind and UX starts with U it is almost certain you have not declared UX to be a character variable (as others say above).
You should use IMPLICIT NONE.
Fix this. Then you might want to consider writing the code like this.
if (any(UX == (/'US','ME','us','me','Us','Me'/))) GOTO 110
This includes the possibility 'Us' which was missing from your code.
Your way should work too. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Tue Sep 27, 2011 10:58 am Post subject: |
|
|
Hi David
I never knew that one can if an array as in your example! Anyway, I tried it as shown below - parsing an array in (/ ... /). This is real cool ans saves a lot of time when connecting nodes. You can image how many lines I wasted doing it the "old" way.
It always pays off keeping an eye in the forum
Code: | call add_bc(srg,14,201,(/-2,-1,11,-7/))
call add_bc(srg,17, 0,(/-17,-16,-31,-18/))
subroutine add_bc(srg,pos,mat,ivrt)
implicit none
integer,dimension(:) :: ivrt
type(srg_type) :: srg
integer :: pos,mat
integer :: n,i,k
n = size(ivrt)
srg%nvbc(pos) = n
srg%itype(pos) = mat
if (pos == 1) then
k = 1
else
k = sum(srg%nvbc(1:pos-1))+1
endif
do i=1,n
srg%ivrt(k) = ivrt(i)
k = k+1
enddo
return
end subroutine |
|
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Tue Sep 27, 2011 9:17 pm Post subject: Re: |
|
|
jjgermis wrote: |
It always pays off keeping an eye in the forum
|
Agreed.
Array syntax is one of the cornerstones of Modern Fortran. My example above uses the fact that an array and a scalar are "Conformable" for the == relational operator. The example creates a temporary array in memory, and whilst I think FTN95 serialises the comparison, other optimizing compilers use SSE processor instructions (on later ia32 microprocessors) to vectorise the comparison (making it very efficient).
As a further example of the power of the Fortran language, I believe some lines in your code can be replaced as follows:
Replace:
Code: |
if (pos == 1) then
k = 1
else
k = sum(srg%nvbc(1:pos-1))+1
endif
do i=1,n
srg%ivrt(k) = ivrt(i)
k = k+1
end do
|
By:
Code: |
k = sum(srg%nvbc(1:pos-1))+1
srg%ivrt(k:k+n-1) = ivrt(1:n)
|
Since the array srg%nvbc( : ) is of zero length and has zero sum when pos = 1. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|