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 

Reading from large file,saving to array

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



Joined: 06 May 2006
Posts: 2

PostPosted: Sun May 07, 2006 1:30 am    Post subject: Reading from large file,saving to array Reply with quote

Hi
I am a recent Fortran user who has still a lot to learn so i
decided to ask for your help as experts for a problem that i face.
I need to read from a file.txt some values and store them to
an allocatable array.Arrays dimensions are given at the first line af the file.
For example a small part of the file is like that:

|----12911=Number of rows <----3 No of columns
12911 3 _ _ ______________|the values that need to
NO2 SO2 O3 / / / be stored
06-12-2000 02:00 17 42 60
06-12-2000 03:00 12 20 65
06-12-2000 04:00 7 10 1.2
06-12-2000 05:00 6 7 74
06-12-2000 06:00 5 5 74
06-12-2000 07:00 13 7 63
06-12-2000 08:00 28 -999 48
etc etc etc
Ofcourse 12911 and 3 may change from file to file
I would be grateful if anyone could tell me the do loop i have to use in order to store the values as well as the format because the values differ in type(e.g.-999,1.2 ,70 etc)
thank for your time

Dimitris
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon May 08, 2006 12:37 am    Post subject: Reading from large file,saving to array Reply with quote

Dimitris

You have picked a difficult exercise for a Fortran beginner. The following may help you to get started...


INTEGER rows,columns,i
CHARACTER date*11,time*6,values*16
REAL,ALLOCATABLE::c1(Smile,c2(Smile,c3(Smile
OPEN(UNIT=7,FILE="test.dat")
READ(7,*) rows,columns
ALLOCATE(c1(rows),c2(rows),c3(rows))
DO i=1,rows
READ(7,"(10a,5a,16a)") date,time,values
READ(values,*) c1(i),c2(i),c3(i)
ENDDO
CLOSE(7)
END
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Mon May 08, 2006 2:19 am    Post subject: Reading from large file,saving to array Reply with quote

Perhaps I should have included the next stage of development....

INTEGER rows,columns,i,j
CHARACTER date*11,time*6,values*16
REAL,ALLOCATABLE::d(:,Smile
OPEN(UNIT=7,FILE="test.dat")
READ(7,*) rows,columns
ALLOCATE(d(rows,columns))
DO i=1,rows
READ(7,"(10a,5a,16a)") date,time,values
READ(values,*) (d(i,j),j=1,columns)
ENDDO
CLOSE(7)
END
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