% clear
imax=240;
dfact=imax/120;
% epsi=ones(imax,1236)*NaN;
% dens=ones(imax,1236)*NaN;
N2=ones(imax,1236)*NaN;

fields{1}='Datasets';
fields{2}='COUNT';
fields{3}='NTC';
fields{4}='PRESS';
fields{5}='TEMPcor';
fields{6}='COND';
fields{7}='NTCHP';
fields{8}='NTCAC';
fields{9}='Chl_A';
fields{10}='AccX';
fields{11}='AccY';
fields{12}='rawO2';
fields{13}='Turb';
fields{14}='O2_ml';
fields{15}='Time';
fields{16}='vel';
fields{17}='epsilon1';
fields{18}='epsilon2';
fields{19}='peps';
fields{20}='epsilon';
fields{21}='sal';
fields{22}='sig_t';
fields{23}='dens';
fields{24}='N2';

fclose('all');
dir='C:\Users\torsten\Gf0906\MSS\epsi_1m_torsten\';
if imax==240
    dir='C:\Users\torsten\Gf0906\MSS\epsi_5dm_torsten\';
end

for i=1:1236
    if i<10
        filename=[dir 'epsi000' num2str(i) '.tob'];
    elseif i<100
        filename=[dir 'epsi00' num2str(i) '.tob'];
    elseif i<1000
        filename=[dir 'epsi0' num2str(i) '.tob'];
    else
        filename=[dir 'epsi' num2str(i) '.tob'];
    end
    fid=fopen(filename);
    [i fid]
    if fid>0
        for dummy=1:6
            textscan(fid,'%1000c',1);
        end
        if i>351
            textscan(fid,'%352c',1);
            if imax==240
                cell2mat(textscan(fid,'%5c',1));
            end
        else
            textscan(fid,'%1000c',1);
        end
        if i>1061
            textscan(fid,'%5c',1);
        end
        cell2mat(textscan(fid,'%215c',1));
        lastline=cell2mat(textscan(fid,'%3f',1));
        textscan(fid,'%1019c',1);
        for lines=1:lastline
            for f=1:24
                value0=textscan(fid,'%50f',1);
                value(f)=cell2mat(value0);
            end
%             epsi(value(4)*dfact,i)=value(20);
%             dens(value(4)*dfact,i)=value(23);
            N2(value(4)*dfact,i)=value(24);
        end
        fclose(fid);
    end
end
% S = STRUCT('field1',VALUES1,'field2',VALUES2,...)

