%This program uses the newest IWRAP lev 1b files (2/4/2011)

d2r = pi/180;
%Storm lat/lon at a central time...
%slat = 21.680;slon = 360 - 58.303;

%lower_fuselage;	%subroutine to display NOAA LF data.

fid = fopen('passes_cband_lev1b.txt');
g=textscan(fid,'%s');

%fid = fopen('/mercury/guimond/GSFC/IWRAP/20030912/volume_reflectivity/passes_cband.txt');
%z=textscan(fid,'%s');

cnt = 0;
a=1;
%for a=1:20
path = fullfile(g{1}{a})
ncid = netcdf.open(path,'NC_NOWRITE');
[ndims,nvars,natts,unlimdimID]= netcdf.inq(ncid);


time = netcdf.getVar(ncid,0);
azi = netcdf.getVar(ncid,1);
scan = netcdf.getVar(ncid,3);
nav = netcdf.getVar(ncid,4);
%alongtrack = netcdf.getVar(ncid,4);
Ze = netcdf.getVar(ncid,6);
%rho = netcdf.getVar(ncid,6);
vel = netcdf.getVar(ncid,8);
%nrcs = netcdf.getVar(ncid,8);
%mZe = netcdf.getVar(ncid,9);
svel = netcdf.getVar(ncid,11);
thetap = netcdf.getVar(ncid,12);
%thetam = netcdf.getVar(ncid,12);
%rdist = netcdf.getVar(ncid,13);
%flags = netcdf.getVar(ncid,14);
mask = netcdf.getVar(ncid,16);
vcorr = netcdf.getVar(ncid,17);
%rdist = netcdf.getVar(ncid,17);
return;
scan = scan(2:length(scan));

ii = 1;     %first point is start of azimuthal scan
for i=1:31
    if (scan(i)~= scan(i+1)) 
        ii = i+1;
    end
end


ff = length(scan);  %lst point is end of azimuthal scan
for i = ff:-1:ff-30
    if (scan(i) ~= scan(i-1))
        ff = i-1;
    end
end

pp = (ff-ii)+1;

%Reflectivity processing...
%%missing = Ze <= 0.0;      %if inequality is true, missing is 1; false, missing is 0.

missing = Ze == 0.0;

Ze(missing) = NaN;     
dbz = 10*log10(abs(Ze));

dbz = shiftdim(dbz(:,ii:ff),1);

dbz = smooth3(reshape(dbz,32,pp/32,183));
avgf = fspecial('average');
pass = squeeze(dbz(14,:,:));
new = imfilter(pass,avgf);

