function [ ] = wavsplit(filename,FS,Nbit,prefix)
%
%splits a wave file into 1 minute sections for editing and analysis.
%filename must be entered in single quotes e.g. 'name.wav'
%FS = sample rate of recording
%Nbit = desired bit depth of output wav files
%prefix = the prefix you want to start the output file with (e.g. A01 or C01)
%prefix must be entered in single quotes
%
%Jason Wood 2007
%
%example of command
%SIZ=wavread('A03.wav','size');

a = 'SIZ=wavread(''';
b = '''size''';
c = [a filename ''',' b ');'];
eval(c);


minutes = SIZ/FS/60;
files = ceil(minutes);

%example of command
%[data,Fs,nbit] = wavread('A03.wav',[1 44100]);

d = '[data,Fs,nbit] = wavread(''';
e = ']);';

g = 'wavwrite(data,FS,Nbit,''';
h = '.wav'');';

for i = 1:files
    start = (FS*60*(i-1))+1;
    start = num2str(start);
    if (FS*60*i) < SIZ(1,1)
        stop = (FS*60*i);
        stop = num2str(stop);
    else
        stop = SIZ(1,1);
        stop = num2str(stop);
    end
    f = [d filename ''',[' start ' ' stop e];
    eval(f);
    
    %WAVWRITE(Y,FS,NBITS,WAVEFILE)
    if i < 10
        listout = ['00' num2str(i)];
    elseif i >= 10 && i < 100
        listout = ['0' num2str(i)];
    else
        listout = num2str(i);
    end
    k = [g prefix listout h];
    eval(k);
end

