- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Here I go again - messing w/ F77 code from the late 90s. This little subroutine has been converted to F90 but something's not quite right w/ the conversion of the 2 DATA statements. The parameter statement I have "seems" right but compiler gives:
Error: The shapes of the array expressions do not conform. for [UPCASE], [LWCASE], [INDCHECK] & [RUNSTREAM]
Strangely, this line gives no compiler error but doesn't seem equivalent:
character(1), parameter :: UPCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', lwcase = 'abcdefghijklmnopqrstuvwxyz'
Is the real trouble the interaction with the INDEX intrinsic?
Full code snippet is here:
subroutine lowerUPPER(iString,Runstream) !================================================================================================100 ! Purpose: To convert all characters from lower case to UPPER CASE (using INDEX intrinsic function). ! Note that the character(80) 'Runstream' Variable Includes the Original Case for Echoing ! and for Later Use To Retrieve Filenames. !================================================================================================100 implicit none !Local variables: !character :: UPCASE*26 !character :: lwcase*26 character*(*) :: Runstream integer(4) :: I, iString, IndCheck !Variable Initializations: !DATA UPCASE/'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/ !DATA LWCASE/'abcdefghijklmnopqrstuvwxyz'/ character(1), dimension(26), parameter :: UPCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', lwcase = 'abcdefghijklmnopqrstuvwxyz' DO 20 I = 1, iString if (Runstream(I:I) .NE. ' ') then IndCheck = INDEX(lwcase,Runstream(I:I)) if (IndCheck .NE. 0) then Runstream(I:I) = UPCASE(IndCheck:IndCheck) endif endif 20 EndDo return End subroutine lowerUPPER
Ссылка скопирована
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Oops - in the code snippet, this is the line that I used (I omitted the brackets):
character(1), dimension(26), parameter :: UPCASE = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ'], lwcase = ['abcdefghijklmnopqrstuvwxyz']
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Fortran does not use an array of characters to store strings, as does C. You should be using
character(LEN=26), parameter :: UPCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', lwcase = 'abcdefghijklmnopqrstuvwxyz'
Then the code (I:I) extracts a substring from the two strings, rather than the Ith element.
If you want an array, you would need to use
character(1), dimension(26), paramter :: UPCASE =(/'A', 'B', 'C', ..... /)
Then you would reference the Ith element as UPCASE(I).
Regards,
David
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
As explained by David, your use of UPCASE variable in line 24 above is like that of an usual Fortran string. So you can use something like the code below as your lowerUPPER procedure:
SUBROUTINE lowerUPPER(iString,Runstream) !================================================================================================100 ! Purpose: To convert all characters from lower case to UPPER CASE (using INDEX intrinsic function). ! Note that the character(80) 'Runstream' Variable Includes the Original Case for Echoing ! and for Later Use To Retrieve Filenames. !================================================================================================100 IMPLICIT NONE !.. Argument list INTEGER(4), INTENT(IN) :: iString CHARACTER(LEN=*), INTENT(INOUT) :: Runstream !.. Local variables INTEGER(4) :: I INTEGER(4) :: IndCheck !.. Constants CHARACTER(LEN=26), PARAMETER :: UPCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' CHARACTER(LEN=26), PARAMETER :: lwcase = 'abcdefghijklmnopqrstuvwxyz' DO I = 1, iString IF (Runstream(I:I) /= ' ') THEN IndCheck = INDEX(lwcase,Runstream(I:I)) IF (IndCheck /= 0) THEN Runstream(I:I) = UPCASE(IndCheck:IndCheck) END IF END IF END DO RETURN END SUBROUTINE lowerUPPER
This is assuming you want the same logic in converting the string to upper case as you showed originally. You may also want to look into the intrinsic functions ICHAR and CHAR respectively and use them instead to do the string conversion; this way, you will get faster performance and not need the UPCASE and lwcase constants in your code.
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Thank you one and all for your great responses! I would have posted back sooner but was UNable to access this post in my usual way! (I could access all other posts, but not THIS one.) I've never experienced this before on IDZ. I am now accessing this via another machine (Win7 laptop).
David White nailed it & FortranFan did a bang-up job rewriting my routine. Kudos all!
It turns out that I had mistakenly interpreted UPCASE & lwcase as arrays, vs. just simple 26-character strings. Duh.
As was duly pointed out, the answer was:
character(26), parameter :: UPCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', lwcase = 'abcdefghijklmnopqrstuvwxyz'
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
>>Thank you one and all for your great responses! I would have posted back sooner but was UNable to access this post in my usual way! (I could access all other posts, but not THIS one.) I've never experienced this before on IDZ. I am now accessing this via another machine (Win7 laptop).
Of late, I have been having some weird forum access issues too. Many thread links open, some don't IE 10.0.14. When this happens, I open a FireFox session (leaving IE open at "back one" from error), copy the link from IE, paste it into FireFox, the page opens.
Something on those pages are causing this behavior.
TC: you might want to try the dual browser thing to save you a trip to the other computer
Jim Dempsey
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Tommy's problem was that his browser had cached an error page. He cleared his browser cache and the problem resolved.
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
>>Tommy's problem was that his browser had cached an error page. He cleared his browser cache and the problem resolved.
I am not a web page programmer. This said, there must be an attribute such as "don't cache me". It would save a lot of grief if there were an attribute and if it were used properly.
Jim Dempsey
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Most of the time you want caching. But every once in a while it causes a problem.
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Mum says dad's been cached at the pub for 40 years, she wants the innkeeper to pay for the funeral as that is where all the money went

- Подписка на RSS-канал
- Отметить тему как новую
- Отметить тему как прочитанную
- Выполнить отслеживание данной Тема для текущего пользователя
- Закладка
- Подписаться
- Страница в формате печати