clear;fclose('all');

%!copy \\asap1\archive\*.edt c:\hare\balloon
%!del c:\hare\balloon\98061705.*
!dir e:\balloon\*.edt > e:\balloon\balloon.dir
fip=fopen('e:\balloon\balloon.dir','r');

fgetl(fip);
fgetl(fip);
fgetl(fip);
fgetl(fip);
fgetl(fip);

while 1
   filenumber=fgetl(fip);
   if filenumber==-1,
      break,
   end;
   if length(filenumber)>46,
      filenumber=[filenumber(40:47),'.edt'];
      disp(filenumber)
      if str2num(filenumber(1:8)) > 0,
         filename=['e:\balloon\',filenumber];
         fir=fopen(filename,'r');
         if fir>2,
            while 1
               teststr = fgetl(fir);
               if ~isempty(teststr),
                  if teststr(2:4) == 'min',
                     break;
                  end;
               end;
            end;
            teststr=fgetl(fir);
            sonde=fscanf(fir,'%g%g%g%g%g%g%g%g%g%g',[10,inf]);
            a=size(sonde);
            if a(1)>9,
               minutes=sonde(1,:);
               seconds=sonde(2,:);
               pressure=sonde(3,:);
               height=sonde(4,:);
               temperature=sonde(5,:);
               relativehumidity=sonde(6,:);
               virtualtemperature=sonde(7,:);
               dewpointdepression=sonde(8,:);
               lapserate=sonde(9,:);
               ascentrate=sonde(10,:);
               theta=(273.15+temperature).*((1013.25./pressure).^(0.286));
               jt=min(find(height>2000));
               if ~isempty(jt),
                  xtemp_h=max(temperature(3:jt));xtemp_l=min(temperature(3:jt));
                  xrh_h=max(relativehumidity(3:jt));xrh_l=min(relativehumidity(3:jt));
                  xpot_h=max(theta(3:jt));xpot_l=min(theta(3:jt));
                  figure;subplot(1,3,1);plot(temperature,height,'g');axis([xtemp_l xtemp_h 0 2000]);grid;xlabel('T [C]');ylabel('height in m');
                  subplot(1,3,2);plot(relativehumidity,height,'g');tit=['GASEX Radiosonde  ',filenumber];grid;title(tit);axis([xrh_l xrh_h 0 2000]);xlabel('RH [%]');
                  subplot(1,3,3);plot(theta,height,'g');axis([xpot_l xpot_h 0 2000]);xlabel('theta');grid;
               end
            end
         else,
            break,
         end;
      end;
   end;
end;