Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
112 Views

compiler bug ?

I cannot see why this routine will not compile.

It gives error #6366 at line 7. Both sides of the equals sign are character*1 type

. Is  that from an older version that was fixed ?

------------------------------------------------------------------------------------------------------------

    subroutine encode(a,na,code,b)
    implicit integer (a-z)
    integer code(100),na,bb
    character*80 a(na),b(na)
    character*1  bbc
    do ia=1,na    
    bbc=a(ia:ia)
    print *,"bbc=",bbc
    bb=ichar(bbc)
! convert lower case
    if(bb.ge.97 .and. bb.le.121)then
        bb=bb-64
    endif
! apply  code  integer
    bb=bb+code(ia)
    if(bb > 97)then
        b(ia:ia)=char(bb-32)
    else
        b(ia:ia)=char(bb)
    endif
    enddo ! ia
    end subroutine encode
    

0 Kudos
10 Replies
Highlighted
112 Views

>>character*80 a(na),b(na)

a is an array of 80-character wide character variables. (same with array b)
bbc is a 1-character wide character variable
a(ia:ia) single 80-character wide cell of array a at index ia

shapes do not match

I do not think the code makes sense.

Jim Dempsey

0 Kudos
Highlighted
New Contributor II
112 Views

read(iline(1:1),1119)dd

You should try and internal read. 

And you should not use implicit  - it leads to hard to find errors

 

0 Kudos
Highlighted
New Contributor I
112 Views

what do you mean - shapes do not match ?

 

Both shapes are character*1 size.

 

 

PLEASE read what I did before commenting.

 

If I pick the characters out of the array, it still does not compile.

Also, if I go the other direction, using CHAR to convert an integer into a character*1, it compiles fine.

 

 

0 Kudos
Highlighted
Black Belt
112 Views

Bill, since you did not tell us what the code is supposed to be doing, we can only comment on syntax errors. Two of the three character type variables in the code, a and b, are of length 80, whereas the third, bbc, is of length 1. There is no place in the code where you recognize or use the fact that the lengths of a and b are equal to 80 rather than 1 -- that raises a red flag.

The compiler flagged line 7. Let us look at that line.

bbc=a(ia:ia)

The variable a is an array, and a(ia:ia) is an array section with 1 element. You could have written a(ia) instead of a(ia:ia), and we would still have had just 1 element. That element is a character of length 80, since that is how you declared the variable. Thus, the expression on the right of the = sign is an 80-character string. However, the destination variable, bbc, is a 1-character string. You cannot copy an 80-character string into a 1-character string, unless it is acceptable to lose/ignore the remaining 79 characters.

You could do something similar to

bbc=a(ia)(23:23)

Which would take the 23rd character in a(ia), and put that single character into bbc. However, that may or may not be what you want to do -- my choice of 23:23 for the substring is completely arbitrary.

In general, I suggest to you, your code is more likely to be in error than the compiler is to have a bug and give you a false error message. Sometimes the wording of the error message may be difficult to understand, in which case you can ask here, or use another compiler on the same code. For your code, Ifort says: 

bsc.f90(7): error #6366: The shapes of the array expressions do not conform.   [BBC]

and Gfortran says:

 Error: Incompatible ranks 0 and 1 in assignment at (1)

 

0 Kudos
Highlighted
New Contributor II
112 Views

mecej4 (Blackbelt) wrote:

bbc=a(ia:ia)

The variable a is an array, and a(ia:ia) is an array section with 1 element. You could have written a(ia) instead of a(ia:ia), and we would still have had just 1 element. That element is a character of length 80, since that is how you declared the variable. Thus, the expression on the right of the = sign is an 80-character string. However, the destination variable, bbc, is a 1-character string. You cannot copy an 80-character string into a 1-character string.

I think your are wrong. a(ia:ia) is an array section of a. So it cannot be assigned into the scalar variable bbc.

bbc=a(ia)

will work and assign to bbc the first character of the element number ia of array a.

 

 

0 Kudos
Highlighted
112 Views

From the provided code in #1, my interpretation of that code would indicate:

! **** was **** character*80 a(na),b(na)
character :: a(na),b(na) ! two character variables, each na bytes long

Jim Dempsey

0 Kudos
Highlighted
112 Views

Or

character(len=na) :: a,b ! two character variables, each na bytes long

Jim Dempsey

0 Kudos
Highlighted
New Contributor I
112 Views

ok, i HAVE FIGURED OUT WHAT i DID WRONG !

Thanks for your comments  !

is character*4 na the same as character(length=4)na   ?

 

I think so - - - - - 

 

0 Kudos
Highlighted
Black Belt
112 Views

billsincl wrote:

is character*4 na the same as character(length=4)na   ?

Yes, provided "length" is spelled "len".

0 Kudos
Highlighted
112 Views

subroutine encode(a,na,code,b)
    implicit integer (a-z)
    integer code(100),na,bb   ! na is an integer, value is not known
    character(len=4) ::  a,b     ! *** NOT CORRECT, use (len=na)
    character*1  bbc
    do ia=1,na    ! *** Note, na is unknown and may be larger than 4
    bbc=a(ia:ia)  ! *** Note, upper limit of ia is unknown and may be larger than 4
    ...

Jim Dempsey

0 Kudos