disp('read_pacs_micro');
clear;
s='f:\epic2\2331\';
dr=dir(s);
[n m]=size(dr);
mx=n;
j=1;
nj=1;
%mx=6*24;
for i=3:mx
   k=1;
   clear dath;
   flnm=dr(i).name
   fid=fopen([s flnm],'r');
   while feof(fid)==0;
      %                   1   2   3   4   5  6    7  8
    
    	stux1=fscanf(fid,'%02d%02d%02d%02d%02d%02d %d %f %f %f',[10,1]);
		stux2=fscanf(fid,'%g %g %g %g %g %g %g %g %g',[9,1]);
		stux3=fscanf(fid,'%g %g %g %g %g %g %g %g %g',[9,1]);
	  if isempty(stux1)
        break
     else
		   datx(j,1)=datenum(2000+stux1(1),stux1(2),stux1(3),stux1(4),stux1(5),stux1(6))-datenum(2000,12,31);
   		datx(j,2)=stux2(9);%vapor
   		datx(j,3)=stux3(9);%liquid
         datx(j,4)=stux2(6);%tau 20
         datx(j,5)=stux2(8);%tb 20
         datx(j,6)=stux3(6);%tau 30
         datx(j,7)=stux3(8);%tb 30
         datx(j,8)=stux1(7);%mode
         datx(j,9)=stux1(8);%angle
         datx(j,10)=stux2(7);%cf20
         datx(j,11)=stux3(7);%cf30
         datx(j,13)=stux2(1);%sky20
         datx(j,14)=stux2(2);%nsky20
         datx(j,15)=stux2(3);%bb20
         datx(j,16)=stux2(4);%nbb20
         datx(j,17)=stux2(5);%tbb20
         datx(j,18)=stux3(1);%sky30
         datx(j,19)=stux3(2);%nsky30
         datx(j,20)=stux3(3);%bb30
         datx(j,21)=stux3(4);%mbb30
         datx(j,22)=stux3(5);%tbb30

         dath(k,1)=datx(j,1);
         dath(k,2)=datx(j,2);
         dath(k,3)=datx(j,3);

         j=j+1;
			k=k+1;
     end;%isempty
  end;%while feof
  fclose(fid);
  if k>1
  [a b]=size(dath);
  ii=find(dath(:,2)<-1 | dath(:,2)>6);
  [nz mz]=size(ii)
  dath(ii,2)=NaN;
  dath(ii,3)=NaN;
  jj=find(isfinite(dath(:,2)));
  if isempty(jj)
     	dathr(nj,1)=datx(j-a,1);
  		dathr(nj,2)=NaN;
        dathr(nj,3)=NaN;
        dathr(nj,4)=0;
        dathr(nj,5)=NaN;
        dathr(nj,6)=NaN;
     else
      dathr(nj,1)=dath(1,1);
  		dathr(nj,2)=median(dath(jj,2));
  		dathr(nj,3)=median(dath(jj,3));
  		y1=dath(jj,2);
      y=sort(y1);
      [ny my]=size(y);
      j1=max(floor(ny*.16),1);j2=max(floor(ny*.84),1);
      dathr(nj,4)=ny;
      dathr(nj,5)=(y(j2)-y(j1))/2;
      y2=dath(jj,3);
      y=sort(y2);
      dathr(nj,6)=(y(j2)-y(j1))/2;
   end;
   nj=nj+1;
  end;
end;%for i
%NaN out the tip cals
ii=find(datx(:,2)<-1 | datx(:,2)>6);
datx(ii,2)=NaN;
datx(ii,3)=NaN;
%
daty=sortrows(datx,1);
dathry=sortrows(dathr,1);
prt_it=1;  %set to 0 to print to screen, 1 to print to a file (i.e., make ascii file)
if prt_it==1   
   ss='d:\cwf\data\epic2001\micro\';
	e=[ss 'micro_s.txt'];
   flist1=fopen([ss 'micro_s.txt'],'w');
   flist2=fopen([ss 'micro_h.txt'],'w');
else
 	flist1=1;flist2=1;
end;

%fprintf(flist1,'%12.6f %10.5f %10.5f \r',daty');
fprintf(flist1,'%12.6f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f \r',daty');
%						jd	     vap  liq     tau20  tb30   tau30  tb30   mode   angle  cf20   cf30

fprintf(flist2,'%12.6f %10.5f %10.5f %5d %10.5f %10.5f \r',dathry');
%						jd	     vap  liq   #obs  sigv   sigl

fclose('all');
	
   %save e datx -ascii;   

figure;plot(dathry(:,1),dathry(:,2),dathry(:,1),dathry(:,5));axis([275 300 0 6]);
figure;plot(dathry(:,1),dathry(:,3)*1e3,dathry(:,1),dathry(:,6)*1e4);axis([275 300 -10 300]);
