replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - CHARACTER variable size limit query
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 

CHARACTER variable size limit query

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



Joined: 11 Apr 2005
Posts: 371

PostPosted: Tue Mar 23, 2010 1:19 pm    Post subject: CHARACTER variable size limit query Reply with quote

Does anyone know of any "inherent" (i.e. not memory-related) limit on the length of a variable of type CHARACTER (len = ...)? Or any reason why code might behave unexpectedly if manipulating such variables with len = 2**16?

Last edited by sparge on Wed Mar 24, 2010 10:01 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Wed Mar 24, 2010 7:10 am    Post subject: Reply with quote

It's not an array, it is a character variable.
I don't know for sure but I think the limit for length is 1024, as I get different errors in a module compilation if length > 1024.
You can certainly have an array of Character*1 much bigger. I have an array of 750 million and it works ok.
John
Back to top
View user's profile Send private message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Wed Mar 24, 2010 10:09 am    Post subject: Re: Reply with quote

JohnCampbell wrote:
It's not an array, it is a character variable.

Whoops, of course it is; thanks. Subject line duly edited. I was going to call it "String size limit query", then I remembered that string is not in the FORTRAN vocabulary (even though everyone would have known what I meant), then I realised I couldn't call it "Character size limit query" (Answer: yes, 1). I think at that point I got flustered and strove for brevity at the expense of accuracy Smile

JohnCampbell wrote:
I don't know for sure but I think the limit for length is 1024, as I get different errors in a module compilation if length > 1024.
You can certainly have an array of Character*1 much bigger. I have an array of 750 million and it works ok.
John

Yes, I noted your latest post with interest. Did we just happen to cross in the post, as it were?

30 years since I first dipped my toe in the waters of FORTRAN, and I still look forward to the day when someone can explain to me, even by analogy, why it is necessary or desirable to distinguish between CHARACTER (len = n) char and CHARACTER char (n) ... why will one or the other not do?
Back to top
View user's profile Send private message Send e-mail
IanLambley



Joined: 17 Dec 2006
Posts: 506
Location: Sunderland

PostPosted: Wed Mar 24, 2010 1:31 pm    Post subject: Reply with quote

CHARACTER (len = n) char
or
CHARACTER*(n) char
or
CHARACTER char*(n)
creates a character variable called "char" that can hold "n" characters
an individual character can be addressed using char(i:i)
groups of characters can be addressed using char(i:j)

CHARACTER char (n)
or
CHARACTER*1 char(n)
creates a character variable array containing "n" elements that can each hold 1 character
an individual character can be addressed using char(i)
groups of characters can't so easily be addressed for assignments & comparisons etc and is akin to the pre-F77 method of storing each character in an integer*1 array

It is probably better to use a different name for the variable than "char" to avoid confusion with the intrinsic "char" function.
Ian
Back to top
View user's profile Send private message Send e-mail
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Thu Mar 25, 2010 12:34 am    Post subject: Reply with quote

I think I am wrong in my estimate of the limit of character*n, if my program is working as I expect. It shows a value of 200 million compiles and runs. The limit may be 2gb, meaning as much memory as available.
Ian, I have demonstrated the difference between the variable "character a*n" and array "character b(n)*1".
Both have disadvantages as :
1) setting a = ' ' can be inefficient, if you are only using a small part of a.
2) Using the array in a subroutine call will not work if you want to receive as character *(*)
3) using "a" in an internal write or read may have other limitations, based on the maximum record size for an internal read/write buffer. Again I don't know what the limit is or where in Help to find the list of compiler limits.
Code:
      integer*4, parameter :: thousand = 1000
      integer*4, parameter :: million  = thousand*thousand
      integer*4, parameter :: char_len = 200*million
      character (len=char_len) aa
      character bb(char_len), c
      integer*4 i
!
      do i = 1,char_len
         c       = char ( ichar('0')+mod(i,53) )
         aa(i:i) = c
         bb(i)   = c
      end do
!
      i = char_len-50
      write (*,'(a,i0,a,i0,a)') 'Variable is *',char_len,' (',char_len/million,'m)'
      write (*,*) 'Var:   ',aa(i:)   ! this is a single variable
      write (*,*) 'Array: ',bb(i:)   ! this is 50 variables
      end

It's interesting that "aa(i: )" and "bb(i: )" both code and print the same, but are different. They can require a different format statement if not using *. You can convert from one to the other via an internal write, but only aa(i: ) can be easily used as the internal r/w buffer.
I've always preferred the array format for large character data but the example above may show both are useable.
John

ps : I increased the size to 1.5gb, removed the array bb and it still ran.
Back to top
View user's profile Send private message
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