

rpath='/Users/dpainemal/Desktop/vocals_data/MWR_2channels/data_Panama_SH/';%%you have to change the path
elem=dir([rpath  '44_*.dat']);%%names of every file
len=length(elem);
time=[];
wv=[];%%%Water vapor in [cm]
lwp=[];%%%liquid water path in [cm]
Tb23=[];%%%brightness temp., 23GHz
Tb31=[];%%%brightness temp. 31 GHz.

for k=1:len
    time_k=[];
    wv_k=[];
    lwp_k=[];
    Tb23_k=[];
    Tb31_k=[];
    line=textread(strcat(rpath,elem(k).name), '%s');
    if length(line)>4
       
for i=2:length(line)-3
    previous=str2num(cell2mat(line(i-1)));
    a=str2num(cell2mat(line(i)));%%type of record, if a==2 then is LOS data
        b=str2num(cell2mat(line(i+1)));%%line must be 1
            c=str2num(cell2mat(line(i+2)));%%year, it must be 8 (2008)
    if and(and(and(a==2,b==1),c==8),previous>50000)
        index(i-1)=i;
    else
        index(i-1)=NaN;
        
    end
end

    index(find(isnan(index)==1))=[];
    if length(index)>1
    
    
    for i=1:length(index)
        if(length(line(index(i):end))>16)
        year=2000+str2num(cell2mat(line(index(i)+2)));
        month=str2num(cell2mat(line(index(i)+3)));
        day=str2num(cell2mat(line(index(i)+4)));
        hour=str2num(cell2mat(line(index(i)+5)));
        minute=str2num(cell2mat(line(index(i)+6)));
        sec=str2num(cell2mat(line(index(i)+7)))+str2num(cell2mat(line(index(i)+8)))/100;
        
        time_k(i)=datenum(year,month,day,hour,minute,sec)-datenum(2008,1,1)+1;%%julian day, starting from 2008/01/01
        
        wv_k(i)=str2num(cell2mat(line(index(i)+9)));
        lwp_k(i)=str2num(cell2mat(line(index(i)+10)));
        Tb23_k(i)=str2num(cell2mat(line(index(i)+11)));
        Tb31_k(i)=str2num(cell2mat(line(index(i)+12)));
        end
    end
   
time=[time time_k];
wv=[wv wv_k];
lwp=[lwp lwp_k];
Tb23=[Tb23 Tb23_k];
Tb31=[Tb31 Tb31_k];

clear *_k line 
    end
    end
    k
end
    

ind=find(lwp==-9.99);
lwp(ind)=NaN;
clear ind
ind=find(wv==-9.99);
wv(ind)=NaN;


clear elem len rpath ans sec minute ind index a b c k i hour month day

        