Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

How would you go about this?

Posted by Avarice (Avarice), 1 August 2003
Alright theres this file that contains data for 3 graphs we'll call this file graph.plot  Within is file is hundreds of numbers.  On my interface i have a button and when i press it, it goes to a procedure that reads the file using
set copy [open copy.plot w]
set eval [open graph.plot r]
foreach line {split [read $eval] \n} {
puts $copy $line
}
Alright when i save what is read to another file and open it with unix,  not all the data is read and put ont copy.plot how do i make sure that everything is read?

ALSO how do i go about searching through the data that is read.  In graph.plot the first 2 graphs are currently meaningless, thus there are hundreds of numbers that i dont' need.  However, the final third of graph.plot have very vital numbers to me.  I need to go in and find the domain of the graph and find the max and min.  However, i don't know how to skip through what is read and get to that part of the file to do commands on those numbers.  Any suggestions/do you even know what i'm talking about?

Posted by admin (Graham Ellis), 2 August 2003
First question.

Answer - you should have square brackets and not curly braces around trhe split, as it's a command to be run.  I tested your code - my output file contained the code in the { } s (21 bytes) until I replaced them with [ and ], when it leapt to being 1 byte LONGER than the incoming file.

The \n on the very end of the incoming data file causes an empty string to be added as the list element of the list that split generates, giving an empty line on the outgoing file end.  use the -nonewline option on read to supress the reading of the final new line.  If you can't be certain that there will be a new line on the end of your data, and you can't allow an extra blank line to be added in any circumstances, you'll need to add an extra check.

Finally, if you're going on to read your data from the copy (in the same program), close the file before you open a fresh handle to do the read - that way, you'll ensure that any buffers are flushed to disc.

With regards skipping through the the start of the file ... how do YOU recognise where the unwanted data ends and the wanted data begins?   Set a variable to 0 before you start your copy loop, then test each line to see if it's the boundary condition, and if it is set that variable to 1.   Only output lines to the output file if this state variable has the value 1 ....



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho