%%%
%%%
%%%  adding cruiseid to the variable structures that need it.
%%%  once off?
%  2008/03/20
%%%

clear;
cruiseid=getcruiseid;
load([ cruiseid '_db' ]);
vars=who;
for v=1:length(vars),
   if isstruct(eval(vars{v})),
      if ~isfield(eval(vars{v}),'cruiseid'),
         disp(['fixing ' vars{v}]);
         clear old_var new_var
         eval(['old_var=' vars{v} ';']);
         fn=fieldnames(old_var);
         for j=1:length(old_var),
            new_var(j).cruiseid=cruiseid;
            for i=1:length(fn),
      	       new_var(j).(fn{i})=old_var(j).(fn{i});
            end;
         end;
         clear(vars{v})
         eval([vars{v} '=new_var;']);
      else
         disp(['no need to fix ' vars{v}]);
      end;
   else
      disp([ vars{v} ' is not a structure']);
   end;
end;

disp(['now saving back ' cruiseid '_db']);

save(['new_' cruiseid '_db'],vars{:});

%%%%%

