forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem using long character strings

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Wed Jul 05, 2006 11:20 am    Post subject: Problem using long character strings Reply with quote

There seems to be a problem using character strings with LEN exceeding 32768. Consider the following program as an example.

PROGRAM p
IMPLICIT NONE
INTEGER, PARAMETER :: lc=32769
CHARACTER(LEN=lc) :: c
!
c=REPEAT(' ',lc)
!
END PROGRAM p

This program crashes.

While there are obvious work-arounds for the above, the reason I want to use long character strings is to find the number of
arguments on the first line of a formatted input text file. The way I do this is to read in the first line as a long character, and
then see how many arguments I can read from this line. Perhaps there is a better way to do this.
Code:
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Thu Jul 06, 2006 12:26 am    Post subject: Problem using long character strings Reply with quote

Simon

The problem in this code concerns the use of REPEAT with a large value for the second argument.
I presume that we could fix this bug but the limitation does not seem unreasonable.

Otherwise you should have no difficulty with long character variables.
If you do have problems, please send an example.

I assume that you know that in this case you can simply write

c = ' '

i.e. a single space, to get the same result, because character variables are always padded out with spaces.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Thu Jul 06, 2006 9:06 am    Post subject: Problem using long character strings Reply with quote

Paul,

Many thanks for your response. Your suggested solutions are useful, but here
is another problem where I am experiencing difficulties with large strings:

PROGRAM p
IMPLICIT NONE
INTEGER, PARAMETER :: iin=11
INTEGER, PARAMETER :: lc=32769
CHARACTER(LEN=lc) :: c
!
c(1:lc)='a'
!
OPEN (UNIT=iin,FILE='tmp.txt',ACTION='write',FORM='formatted',STATUS='unknown')
WRITE (UNIT=iin,FMT='(A)') c(1:lc)
CLOSE (UNIT=iin)
!
OPEN (UNIT=iin,FILE='tmp.txt',ACTION='read',FORM='formatted',STATUS='old')
READ (UNIT=iin,FMT='(A)') c(1:lc)
CLOSE (UNIT=iin)
!
END PROGRAM p

The program will create the file, but will not read the character back in.

Simon
Back to top
View user's profile Send private message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Thu Jul 06, 2006 9:12 am    Post subject: Problem using long character strings Reply with quote

Paul,

Sorry, I see that I can fix this by an ANSI extension: using RECL on sequential access files.

Simon
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Thu Jul 06, 2006 9:15 am    Post subject: Problem using long character strings Reply with quote

Simon

You are opening the files as unformatted, but then using a format to write and read character data.
_________________
John Horspool
Roshaz Software Ltd.
Gloucestershire
Back to top
View user's profile Send private message Visit poster's website
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Thu Jul 06, 2006 4:53 pm    Post subject: Problem using long character strings Reply with quote

John,

Thanks for responding. The file was explicitly opened as a formatted file for both the write and the read (see OPEN statements
on the earlier message). The solution is to use the RECL specifier even though the file is sequential. This is allowed in FTN95
even though it's not part of the ANSI standard. So the fixed code looks like this:

PROGRAM p
IMPLICIT NONE
INTEGER, PARAMETER :: iin=11
INTEGER, PARAMETER :: lc=32769
CHARACTER(LEN=lc) :: c
!
c(1:lc)='a'
!
OPEN (UNIT=iin,FILE='tmp.txt',ACTION='write',FORM='formatted',STATUS='unknown')
WRITE (UNIT=iin,FMT='(A)') c(1:lc)
CLOSE (UNIT=iin)
!
OPEN (UNIT=iin,FILE='tmp.txt',ACCESS='sequentual',ACTION='read',FORM='formatted',STATUS='old',RECL=lc)
READ (UNIT=iin,FMT='(A)') c(1:lc)
CLOSE (UNIT=iin)
!
END PROGRAM p
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Fri Jul 07, 2006 12:56 am    Post subject: Problem using long character strings Reply with quote

Simon

An alternative may be to consider using READF@.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Mon Jul 10, 2006 1:50 am    Post subject: Problem using long character strings Reply with quote

Simon

This bug has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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