function [h,press,t,dp,rh,w_spd,w_dir,lat,lon]=read_edt(fname)
%[h,press,t,dp,rh,w_spd,w_dir,lat,lon]=read_edt(fname)
% Read LATLON_EDT file with name fname and output:
% h     height (m)
% press pressure (hPa)
% t     temperature (degrees C)
% dp    dew point (degrees C)
% rh    relative humidity (%)
% w_spd true wind speed (m/s)
% w_dir true wind direction (degrees)
% lat   latitude (degrees)
% lon   longitude (degrees)

% SPdeS 2007.10.19, ripped off from Ludovic and Dan's sounding_plot.m

    fid1=fopen(fname,'r');
    if fid1 == -1
        error(['Cannot read ' fname]);
    end %if end

    %%%%%%%%%%%START READING HEADER %%%%%%%%%%%%%%%%%%%%%%%
    %                                                  RS Serial #: B2815335
    %                                                  Station Name: WTEC
    %                                                  Launch Time: 0111Z
    %                                                  Launch Date: 06 MAY 07
    %
    %EDT LEVEL OUTPUT with GPS Lat, Long, Alt
    %
    %    Time     Height  Pressure      Temp    Dew P.    RH    W Spd    W Dir             Lat            Long      GPS Alt
    %     sec       mtrs       hPa        �C       �C    Pct      m/s     Az �       Decimal �       Decimal �         mtrs
    %
    %%%%
    % frewind(fid1);
    for j=1:17
        ij=fgetl(fid1);
        if j==5
            timestamp=ij;
        elseif j==8;
            daystamp=ij;
        end
    end
    %clear ij;
    %%%%%%%%%%%END READING HEADER %%%%%%%%%%%%%%%%%%%%%%%%

    %   -0.88        7.0    1013.0     25.65     20.9     75     10.0     80.0      11.9248377     -44.2862418        -21.3
    %    0.12        7.5    1012.9     25.65     20.8     75      9.7     79.6      11.9247976     -44.2862551        -14.5
    k=0;
    while ~feof(fid1)
        temp=fgetl(fid1);
        if ~isempty(temp)
            k=k+1;
            data=sscanf(temp,'%f') ;
            h(k,1)    =data(2); %Ht m
            press(k,1)=data(3);  %Press mb
            t(k,1)    =data(4);  % T C
            dp(k,1)   =data(5);  %dew Pt C
            rh(k,1)   =data(6);  % RH %
            w_spd(k,1)=data(7);  % wnd spd m/s
            w_dir(k,1)=data(8);  % wnd dir true
            lat(k,1)=data(9); % tenths of degrees N=+ S=-
            lon(k,1)=data(10);  % tenths of degrees W=- E=+
        end % if end
    end %while end
    fclose(fid1);
    %%%%%%%%%%%%%%%%%FINISH READING THE EDT FILE %%%%%%%%%%%%%%%%%%%%%%
    
    lon(lon<=-998)=NaN; lat(lat<=-998)=NaN;