listing = ls('/cdrom/NH0001/*.ENR');


f = [];
ii = 1;

while 1,
   [file, listing] = strtok(listing);
   if isempty(file), break; end

   d = read_os(file);
   if isempty(d.error),
      f(ii).name = file;
      f(ii).dd = d.dday([1 end]);
      f(ii).ens = d.ens_num([1 end]);
      f(ii).yearbase = d.config.yearbase;
      ii = ii + 1;
   end
   %%% if ii == 4, break, end
end


fid = fopen('NH0001.scn', 'w');

for ii = 1:length(f)
   n = 1 + diff(f(ii).ens);
   dt = 86400 * diff(f(ii).dd)/(n-1);
   DT = dt * n;
   if ii == 1,
      ens_gap = 0;
      t_gap = 0;
   else
      ens_gap = f(ii).ens(1) - f(ii-1).ens(2);
      t_gap = 86400 * (f(ii).dd(1) - f(ii-1).dd(2));
   end

   fprintf(fid, '%s  %s  %s', f(ii).name, ...
                  to_date(f(ii).yearbase, f(ii).dd(1), 'string'), ...
                  to_date(f(ii).yearbase, f(ii).dd(2), 'string'));

   fprintf(fid, '  %12.6f  %12.6f', f(ii).dd);
   fprintf(fid, '  %6d %6d', f(ii).ens);
   fprintf(fid, '  %5d %5d', n, ens_gap);
   fprintf(fid, '  %4.1f %5.0f %6.0f\n', dt, t_gap, DT);

end

fclose(fid)

