replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Problem with Internal File
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 with Internal File

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



Joined: 16 Nov 2009
Posts: 155

PostPosted: Sun Mar 24, 2013 4:13 pm    Post subject: Problem with Internal File Reply with quote

Dear colleagues,

What is wrong with the following program?

Code:

Winapp

    Program Test79

      Implicit None

      Integer           , Dimension (10) :: n
      Integer                            :: i
      Character (len=20), Dimension (10) :: Buffer

      Buffer (1) = '1 , 2'
      Buffer (2) = '3 , 4, 5'
      Buffer (3) = '6'

      Read ( Buffer, * ) ( n (i), i = 1,5 )
      Read ( Buffer, * )   n (6)

      write (*,*)        ( n (i), i = 1,5 )
      write (*,*)          n (6)
       
!     ----------------------------------------

      Open (Unit = 10, File = 'Input')

      Read  ( 10, * ) ( n (i), i = 1,5 )
      Read  ( 10, * )   n (6)

      write (*,*)     ( n (i), i = 1,5 )
      write (*,*)       n (6)
 
    End Program Test79


The program reads Buffer (1) and Buffer (2) correctly by an implied-do loop but fails reading Buffer (3). If Buffer is put into a file, reading is (of course) correct.

File Input:

Code:

1 , 2     
3 , 4, 5   
6         

Best regards,
K. Lassmann
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sun Mar 24, 2013 4:28 pm    Post subject: Reply with quote

The second read just starts over at the start of the contents of the buffer array. There is only one record with internal files.

If you want to read different array elements you can use code like the following.

Code:

Winapp

    Program Test79

      Implicit None

      Integer           , Dimension (10) :: n
      Integer                            :: i
      Character (len=20), Dimension (10) :: Buffer

      Buffer (1) = '1 , 2'
      Buffer (2) = '3 , 4, 5'
      Buffer (3) = '6'

      Read ( Buffer(1), * ) ( n (i), i = 1,2 )
      Read ( Buffer(2), * ) ( n (i), i = 3,5 )
      Read ( Buffer(3), * )   n (6)

      write (*,*)        ( n (i), i = 1,5 )
      write (*,*)          n (6)
       
!     ----------------------------------------

      Open (Unit = 10, File = 'Input')

      Read  ( 10, * ) ( n (i), i = 1,5 )
      Read  ( 10, * )   n (6)

      write (*,*)     ( n (i), i = 1,5 )
      write (*,*)       n (6)
 
    End Program Test79

_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
KL



Joined: 16 Nov 2009
Posts: 155

PostPosted: Mon Mar 25, 2013 8:15 am    Post subject: Reply with quote

Thank you very much, David. Obviously, I focussed too much on the wording 'Internal File' (you could call it wishful thinking) and the possibility that internal file may be an array, where its elements are treated as records. Unfortunately, I missed the restriction you mention that after any I/O operation the internal file is always positioned at the beginning of the first record. Thanks again for the prompt help,
Klaus
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Mar 26, 2013 9:52 am    Post subject: Re: Reply with quote

KL wrote:
... the possibility that internal file may be an array, where its elements are treated as records.
Klaus


You can use arrays of characters in this way. But the records need to be accessed in **one** read or write operation. For example, the following code uses the / editing to read from each record

Code:

character(len=10) :: buffer(4)
buffer(1) = '1'
buffer(2) = '2'
buffer(3) = '3'
buffer(4) = '4'
read(buffer,'(i5,/)') i, j, k, l, m
end


If you want multiple reads (for example) you need to use the index to the starting record (element) you want.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
KL



Joined: 16 Nov 2009
Posts: 155

PostPosted: Tue Mar 26, 2013 12:12 pm    Post subject: Reply with quote

Thank you David, I have understood the mechanism, which is more a "Convert to..." mechanism rather than an "Internal Fils" mechanism.

Klaus
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