clear;

nfile=163;

for n=1:nfile
file_o1(n,:)='/sirius2/zhup/wrk/tower_data/Everglads/';
end
fid=fopen('infile_10m_1');
file2=fscanf(fid,'%s',[28 inf]);
fclose(fid);
[d1 d2]=size(file_o1);
file2=file2';
filename(:,1:d2)=file_o1;
filename(:,d2+1:d2+28)=file2(1:nfile,:);

for n=1:nfile
n
fid=fopen(filename(n,:),'r');
for i=1:7
    tmp=fgets(fid); % read each line as a string
end
tmp=fgets(fid);
%data=nan(37,1); time=nan(1,10);
nm=0;
while length(tmp)>100
    k=find(isspace(tmp));
    ik=find(diff(k)==1);
    if ~isempty(ik)
        k(ik)=[];
    end
    nk=length(k);
    k1=k(1:nk-1)+1; %start point for each parameter
    k2=k(2:nk)-1; % end point for each parameter
    nm=nm+1;
    if nm/18000-floor(nm/18000) ==0;
    nm;
    end
    dd=tmp(k1(1):k2(1));
    hour=str2double(dd(1:2));
    minute=str2double(dd(4:5));
    second=str2double(dd(7:8))+str2double(dd(10:11))/100;
    dd=tmp(k1(2):k2(2));
    year=str2double(dd(1:4));
    month=str2double(dd(6:7));
    day=str2double(dd(9:10));
    time(nm)=datenum(year,month,day,hour,minute,second);
    for i=3:length(k1)
        data(i,nm)=str2double(tmp(k1(i):k2(i)));
    end
    tmp=fgets(fid);
end
fclose(fid);

p(:,n)=data(17,:);
u(:,n)=data(23,:);
v(:,n)=data(24,:);
w(:,n)=data(25,:);
t(:,n)=data(26,:)+273.16;
q(:,n)=data(11,:)*18.015/28.964/1000;

end

save /sirius2/zhup/wrk/tower_data/Everglads/out_10m_dat_1.mat p u v w t q;


 
