%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: o2_multi.m,v 1.1 2000/01/10 19:08:16 rob Exp $	

function o2_multi( tabfile, opts, evalstr )

[fid,message] = fopen( tabfile, 'r' );

if fid == -1
    error( [tabfile ': ' message] );
end

				% list directory
ls_pdat = ls;

tabdir = findstr( tabfile, '/' );
if ~isempty( tabdir ), tabdir = tabfile( 1:max(tabdir) ), end

while 1
				% get mission file name
    mission = fgetl( fid );
    if ~isstr( mission ), break; end
    if mission(1) ~= '#'
				% find just the run name
    tail = findstr( mission, '/' );
    if isempty( tail )
        tail = mission;
    else tail = mission( (1 + max(tail)):length(mission) ); end
				% convert relative to absolute path
    if mission(1) ~= '/'
        mission = [tabdir mission]
    end
				% construct resulting namefile:
				% 'tolower' mission name, replace
				% . with _
    mask = find( 'A' <= tail & tail <= 'Z' );
    if ~isempty( mask )
        tail( mask ) = tail( mask ) - 'A' + 'a';
    end
    mask = findstr( tail, '.' );
    if ~isempty( mask )
        tail( mask ) = '_';
    end
				% does namefile exist in ls_pdat?
    if isempty( findstr(ls_pdat, tail) )
				% parse the file with option 4
        disp( ['parsing ' mission ' ...'] );
        status = unix( ['parse -4 ' mission] );
    else
        disp( [tail ' exists, starting review...'] );
    end
				% run the reviews, see 'help eval' for
				% explanation of 2nd argument
    eval( tail, sprintf('fclose(%d)', fid) );
				% evaluate the optional arg EVALSTR
    if nargin > 2, eval(evalstr); end
    end
end
				% close file
fclose( fid );
