function scan_tags(tag_file,class)

out_dir = '/home/paul.baggenstoss/work/CSToolkit/CSFTK/data';
event_nr=0;
NFFT=256;
au_data;
fp=fopen(tag_file,'r');
%Bm.D ./all/BallenyIslands2015/wav/20150115_170000.wav 1000.000000 1621097 1631096
nline=0;
while(1)
       line=fgetl(fp);
       if isempty(line) || ~ischar(line), break, end;
       nline=nline+1;
       [id,wavfile,fs,s1,s2]  = strread(line,'%s %s %f %d %d');
       id=id{1};
       wavfile=wavfile{1};
       [wd,wn,we]=fileparts(wavfile);
       wavfile=[wn,we];
       fprintf('*****************\nID(%d)=%s, wv=%s\n',nline,id,wavfile);
       ifound=0;
       if(nline==1),
           ID=id;
           whichid=find(strcmp(types,ID));
       end;

       for ifile=1:7,
         ids=files{ifile}(:,2);
         ii=find(strcmp(ID,ids));
         if(isempty(ii)), continue; end;
         fpf=files{ifile}{ii,1};
         %fprintf('found id %s in file %d, pos %d, annot file %s\n',ID,ifile,ii, fpf);
         %fprintf('Reading %s\n',fpf);
         fname = [ddir,fpf];
         fpi=fopen(fname);
         [d,n,e]=fileparts(fname);
         nline2=0;
         while(1)
            line=fgetl(fpi);
            if isempty(line) || ~ischar(line), break, end;
            if strcmp(line(1:9), 'Selection'), continue; end;
            nline2=nline2+1;
            [a1,a2,a3,a4,fname1,fname2,t1,t2,samp1,samp2,a12,a13,a14,a15,a16,a17,dtime,flo,fhi,a21,a22,a23,ID1,ID2,ID3,ID4,ID5,ID6] = ...
                  strread(line,'%d %s %d %d %s %s %f %f %d %d %d/%d/%d %d:%d:%f %f %f %f %f %f %f %s %s %s %s %s %s');
            %fprintf('WAVFILE=%s\n', fname1{1});
            wavfile1=[d,'/wav/',fname1{1}];
            if(strcmp(wavfile,fname1{1})),
              ii3=find(wd=='/');
              dname=wd(ii3(2)+1:ii3(3)-1);
              ii3=find(fpf=='/');
              dname2=fpf(1:ii3(1)-1);
              if(strcmp(dname,dname2)),
                  if( (samp1>= s1  && samp2 <= s2)  ||  (s1>= samp1  && s2 <= samp2)),
                     fprintf('Bingo: file %s, line %d, (%d,%d) inside (%d,%d)\n', fpf,nline2,samp1,samp2,s1,s2);
                     ifound=1;
                     MAXT=12.3;
                     NDES=3072;
                     SIZ=wavread(wavfile1,'size');
                     [samp1,samp2,bord1,bord2]=recenter_au(samp1,samp2,MAXT,SIZ,fs);
                     [x,fs]=wavread(wavfile1,[samp1,samp2]);
                     fs2=250;
                     x=dsamp_au(x,fs,fs2);
                     if length(x) < NDES,
                       fprintf('Event too short, bailing out\n');
                       break;
                     end;
                     x=x(1:NDES);
                     event_nr=event_nr+1;
                     write_event(out_dir,event_nr,x,fs2,0,NDES/fs2,class);
                     t1 = bord1/fs;
                     t2 = MAXT-bord2/fs;
                     dsply_event(x,fs2,t1,t2,flo,fhi,id,NFFT);
                     drawnow
                     break;
                  end;
              end;
            end;
         end;
         fclose(fpi);
         if(ifound), break; end;
       end;
       if ~ifound, fprintf('----------------NOT FOUND----------------\n'); end;
end;
fclose(fp);
return

