function fix_sw_struct
% This function looks for all the codas blockfiles in
% the current directory; for all but the block directory,
% it then changes the RAW_SPECTRAL_WIDTH from STRUCT to
% UBYTE.
% I wrote a cruder version called "fixit.m" for Pat Caldwell
% a year or two ago.
% If we keep running into related, but not identical,
% problems needing this sort of fix, then this can be
% generalized more.
%
% EF 2001/12/14


files = dir('*.blk');

of1 = 160 + 56 * 66 + 32;  % sz_blk_hdr + sz_data_dir_entry * data_id + ofs
                           % 66 is RAW_SPECTRAL_WIDTH
                           % Pat also needed this applied to 76 on occasion

for ii = 1:length(files)
   file = files(ii).name;
   if strcmpi('dir.blk', file((end-6):end)) == 0,
      disp(file)
      fid = fopen(file, 'r+');
      cc = fread(fid, 5, 'char');
      if cc(5) == 'P',             % chars 5-8 are "PC  " or "SUN3"
         byteorder = 'ieee-le';
      else
         byteorder = 'ieee-be';
      end
      fid = fopen(file, 'r+', byteorder);
      fseek(fid, of1, 'bof');
      type = fread(fid, 1, 'int16');
      if type ~= 11,
         disp('Did not find STRUCT id in type field')
      else
         fseek(fid, of1, 'bof');
         newtype = 1;
         c = fwrite(fid, newtype, 'int16');
      end
      fclose(fid);
   end
end
