ll=[612 613 614 616 617 620 622 623 624 625 628 629 630 632 634 635 637 638 640 643 644 646 649 650 652 654];

llg=[];
for (i=1:1:length(ll)),
   ecg1 = sprintf('s%d_ecg_rest.dat', ll(i));
   ecg2 = sprintf('s%d_ecg_visual_rest.dat', ll(i));
   res1 = sprintf('s%d_respir_rest.dat', ll(i));
   res2 = sprintf('s%d_respir_visual_rest.dat', ll(i));
   if (filexist(ecg1) & filexist(ecg2) & filexist(res1) & filexist(res2)),
      fprintf(1,'%d is good\n', ll(i));
      llg = [llg ll(i)];
   end
end

ll = llg; clear llg;


for (i=1:1:length(ll)),
   ecg1 = sprintf('s%d_ecg_rest.dat', ll(i));
   res1 = sprintf('s%d_respir_rest.dat', ll(i));
   pref1 = sprintf('s%d_RTS', ll(i));
   
   ecg2 = sprintf('s%d_ecg_visual_rest.dat', ll(i));
   res2 = sprintf('s%d_respir_visual_rest.dat', ll(i));
   pref2 = sprintf('s%d_VRTS', ll(i));

   Opt.PhysFS=1./0.02;
   Opt.Nslices=42;
   Opt.VolTR=3.5;

   Opt.Respfile = res1;
   Opt.Cardfile = ecg1;
   Opt.Prefix = pref1;
   [Opt1(i), OptR1(i), OptE1(i)] = RetroTS(Opt);

   Opt.Respfile = res2;
   Opt.Cardfile = ecg2;
   Opt.Prefix = pref2;
   [Opt2(i), OptR2(i), OptE2(i)] = RetroTS(Opt);
   
end
