- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friends;
This is probably silly question: why does the first if statement gives Compilation error #6385 while the second one compiles.
C C LOGICAL :: TEST C IF(COMPASX(RUNTYP,STAT)) GOTO 91 C TEST=COMPASX(RUNTYP,STAT) IF(TEST) GOTO 91 C
The function COMPASX is defined as follows:
!----------------------------------------------------------------- LOGICAL FUNCTION COMPASX(AONE,ATWO) ! IMPLICIT INTEGER (I-N) IMPLICIT REAL (A-H,O-Z) ! !LOGICAL::COMPAS CHARACTER,INTENT(IN) :: AONE(4), ATWO(4) ! ! standard Fortran IV convention ! DO I=1,4 IF( (LLE(AONE(I),ATWO(I)) .XOR. LLE(ATWO(I),AONE(I))) ) THEN COMPASX=.FALSE. RETURN END IF END DO ! COMPASX=.TRUE. ! RETURN END FUNCTION COMPASX !-----------------------------------------------------------------
By the way, could somebody suggest a better way to compare two character arrays in FORTRAN?
Regards;
I. Konuk
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way, could somebody suggest a better way to compare two character arrays in FORTRAN?
The following code fits with your coding approach and is valid Fortran:
DO I=1,4 IF ( AONE(I) .EQ. ATWO(I) ) CYCLE COMPASX=.FALSE. RETURN END DO COMPASX=.TRUE. RETURN
I would suggest that if there is confusion with the order or evaluation of functions in an IF statement (more complex than presented), then your second approach is to be preferred as it removes any ambiguity of order or evaluation when reading the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
John,
#3 is not always correct. Depending on character set, one could be defined as having two characters that are lexically equal yet numerically different.
If numerically equal is sufficient, then consider:
!----------------------------------------------------------------- LOGICAL FUNCTION COMPASX(AONE,ATWO) IMPLICIT NONE CHARACTER,INTENT(IN) :: AONE(4), ATWO(4) INTEGER(4) :: MOLD ! COMPASX = (TRANSFER(AONE,MOLD) == TRANSFER(ATWO,MOLD)) RETURN END FUNCTION COMPASX !-----------------------------------------------------------------
Should that function be placed in a module, then chances of inlining are good.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Friends:
Thank you for the clear explanation (I kind of guessed it) and helpful suggestions. I will use the approach closer to mine but much cleaner.
Regards;
I. Konuk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FWIW>>Depending on character set, one could be defined as having two characters that are lexically equal yet numerically different.
As an example: 'a' and 'A' could have the same collating sequence (depending on the selected collating sequence).
Jim Dempsey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page