% This program extracts data from the Wind CNS files
% The data line is written out into a file along with
% the date and time.

cd 't:\CALNEX_2010\Atlantis\radar\profiler\Processed\MC\';

files = dir('W*.CNS');

dt = zeros(7,1);
d  = zeros(12,1);
rh = zeros(8,1);

fnl = fopen('radarmclow.txt','w');
fnh = fopen('radarmchigh.txt','w');

for i = 1:length(files)
    fprintf(1,'Processing %s\n', files(i).name);
    fid = fopen( files(i).name);
    line = fgetl(fid);
    while ~feof(fid)
        for j = 1:3
            line = fgetl(fid);
        end
        line = fgetl(fid);
        dt(1:7)=sscanf(line,'%d');
        dt(1)=dt(1)+2000;
        for j = 1:2
            line = fgetl(fid);
        end
        line = fgetl(fid);
        rh(1:8)=sscanf(line,'%d');
        for j = 1:3
            line = fgetl(fid);
        end
        for j = 1:36
            line = fgetl(fid);
            d(1:12)=sscanf(line,'%f');
            d(1)=d(1)*1000.;
            if (  rh(5) == 400 )
                fprintf(fnl,'%4d %02d %02d %02d %02d %02d %.1f %.1f %.2f\n',...
                    dt(1:6),d(1:3));
            else
                fprintf(fnh,'%4d %02d %02d %02d %02d %02d %.1f %.1f %.2f\n',...
                    dt(1:6),d(1:3));
            end
        end
        line = fgetl(fid);
    end %while
    fclose(fid);
end %for

close all
