function saveTS(X,Y,dStart,dEnd,fileName)

[m,n]=size(Y);
if (m==1) Y=Y'; end

[m,n]=size(X);
if (m==1) X=X'; [m,n]=size(X); end

iStart=1;
while (Y(iStart)<dStart)
    iStart=iStart+1;
end
iEnd=iStart+1;
while (Y(iEnd)<dEnd)
    iEnd=iEnd+1;
end

fileNameFirst=[fileName '_' num2str(dStart) '_' num2str(dEnd) '_' num2str(iEnd-iStart+1)];
fileNameDTE=[fileNameFirst '.dt'];
fileNameDTA=[fileNameFirst '.txt'];

DATE=Y(iStart:iEnd,1);
DATA=X(iStart:iEnd,1);
save(fileNameDTE,'DATE','-ASCII');
save(fileNameDTA,'DATA','-ASCII');