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 

IOSTAT = 52
Goto page Previous  1, 2
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Thu Oct 20, 2016 2:52 am    Post subject: Reply with quote

Bill,

Quote:
Seems like a lot of work to do something simple.


It may be simple, but determining the size of an array to allocate and then filling the array, is a problem often discussed. So I tried to identify the key tasks and provide simple routines to do that:

count_lines : determines the number of lines in the file
get_xy : retrieves the 2 real numbers from each line
read_line : reads a line of text from a file ( I should have provided this)
clean_line : determines if there are unexpected characters in then line and responds

What I was trying to highlight is that each of these functions could be isolated and modified if further required. Additional changes can be easily applied as the data files present more problems.

The other main approach is a reallocating a larger array, but if the file can fit in the system buffer, rereading is a fast approach, as the second read is much faster.

The file is actually an ASCII DOS file, with a 3-character header.

I have had similar problems in the past with marine survey files, where there can be 10^8 points in a file. They often present new difficulties, so reporting anything unexpected is useful.

John
Back to top
View user's profile Send private message
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Thu Oct 20, 2016 3:05 am    Post subject: Reply with quote

Thanks for the explanation, John. A lot of good code, and thanks for sharing it.
Back to top
View user's profile Send private message Visit poster's website
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Thu Oct 20, 2016 2:54 pm    Post subject: Reply with quote

Dear Bill,

the "problem" with your code was that I forgot to mention that after reading de file, I had to re-open it to read once again the real data, so your code worked fine only for reading the file in a first instance, but as the file wasn't modified (as John did), I couldn't used it in the second stage where, once the size of the array was known, data was read for the subsequent calculations.

Agustin
Back to top
View user's profile Send private message
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Thu Oct 20, 2016 3:56 pm    Post subject: Reply with quote

OK.

It wasn't clear that you were looking for an end-to-end solution. I'm sure the one given to you will satisfy your needs.
Back to top
View user's profile Send private message Visit poster's website
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Fri Oct 21, 2016 7:29 pm    Post subject: Reply with quote

I found that if the file contains data separated by tabs or spaces, instead of commas, the subroutine get_ xy fails. Is there any way to overcome this issue?.....in general I export data separeated with commas, but sometimes, my data goes through other stages that eventually translate commas into tabs or spaces.

Agustin
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sat Oct 22, 2016 1:20 pm    Post subject: Reply with quote

Agustin,

The solution to this is to change the read statement in subroutine get_xy :
read (line,fmt='(2f30.0)',iostat=iostat) x1,y1
and replace this by a routine to finds each text string that is defined by a separator character ( comma, space, tab or other ) then read each text string to get each number. (Note: to read tab characters, see OPEN help)
The coding for this is straight forward, although the code gets a bit longer as more special characteristics of the data file are included.

John
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Sat Oct 22, 2016 1:25 pm    Post subject: Reply with quote

thanks for the tip John!

Agustin
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
Goto page Previous  1, 2
Page 2 of 2

 
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