On 2/14/2010 3:55 PM, Zach Bartels wrote:
> Hi again,
>
> This relates to my video editing project.   Now that I have a list of
> patterns I can (for sake of ease) hard code into my program I have
> been googling about  file operations.   But I have not been able to
> find an answer to my question..
>
> This post originally started as a question on file operations, but
> seems to have evolved into an outline for  my proof of concept program
> and what I'd like it to do / how it should work..
>
> Again not asking anyone to code the whole thing for me..  But  for
> questions mentioned in the post,  or where it seems I don't understand
> how something works,   pointing me in the right direction with links
> to  tutorials and such,  or  general advice on better ways to do
> something,  or if you are inclined to give practical examples on how
> to achieve my goals,  it would be greatly appreciated.
>
>
> I am interested in how you would do several different things,  such
> as:
>
> Start reading a file at a specific line,  that is not guaranteed to be
> the same line every time..   I.e  while the  [MATCHES]  section in  a
> Yatta Project file might start on  line 300 in one case,   in another
> where the user has done different tasks (more, or less)  there may be
> more or less information stored,  and the [MATCHES] section might not
> be on line 300  every single time..
>
> [MATCHES] is the header that proceeds  the list of matches for the
> frames Yatta is working on.   So  I assume  I need to  search the file
> and stop at the first occurance of  [MATCHES].
>
> Then start reading line by line, one at a time.    Each frame is
> listed on one line, with one character for the pattern..  So  a
> parttern of  CCCNN would be presented as 5 lines in the text file like
> so:
>
> C
> C
> C
> N
> N
>
> I am supposing I should iterate through each line,  and  store the
> results in an array?   I think this is best,  because  array indices
> also start with 0,  just like video frame counts.    Frame 0  would
> amount to  Array[0].   Easy  to keep track of..      If I understand
> things right, I don't need to worry about getting the frame count
> beforehand and  creating a  pre-defined  matrix  with  "X number of
> spots" to fill..  I can just expand the array on the fly and the
> appropriate index number will be given?
>
> (Array.push?)
>
>
> So the question is,  how do I open the yatta project file (just a text
> file AFAIK)   then search until [MATCH]  is found -  then start
> counting on the actual  line the pattern  data was started on?   There
> are no blank lines between [MATCH]  and the first frame.   However
> after the last frame in the video  there IS a white space,   and then
> the next section header [POSTPROCESS]  occurs.
>
> So I guess I would want it to iterate through all  lines  AFTER the
> line  [MATCHES]  is found on,  and then stop  iterating and pushing
> data into the array  at the first  blank line it  comes across  (which
> is after the last frame in the video).

http://pleac.sourceforge.net/pleac_ruby/fileaccess.html
change this example
# The method IO#readline is similar  to IO#gets
# but throws an exception when it reaches EOF
f = File.new("bla.txt")
begin
     while (line = f.readline)
         line.chomp
         $stdout.print line if line =~ /blue/
     end
rescue EOFError
     f.close
end

to
...
   $stdout.print line if line =~ /\[MATCHES\]/
...

add an inner loop after that to process all the lines til you hit your blank line