function lidar_proc=process_lidar(filename,declination,lat,lon,height,SNRthresh)
%input variables:
%       filename (string)
%       declination (azimuth offset in degrees)
%       lat: latitude in degrees
%       lon: longitude in degrees
%       height: height AGL in meters
%       SNRthresh: SNR thresholding for good data (typically SNRthresh ~=
%       0.008-0.01


lidar_proc=read_CSM(filename,declination);
[na,nr]=size(lidar_proc.xd);

  % correct for yaw pitch and roll to bring coordinates back to ENU local
  % tangent plane   NOTE: yaw is currently not set within instrument. Tis is
  % for a moving platform. For the time being, yaw will be set to
  % zeros(size(lidar.xd))

[xdc,ydc,zdc,azimuthc,elevationc]=ypr_correct(lidar_proc);
lidar_proc.xdc=xdc;
lidar_proc.ydc=ydc;
lidar_proc.zdc=zdc;
lidar_proc.azimuthc=azimuthc;
lidar_proc.elevationc=elevationc;

% create geo coordinates Hampton estimated position Latitude: 37.020419,
% Longitude=-76.336632, height=12m agl

[lat,lon,h]=make_geo(lidar_proc.xdc,lidar_proc.ydc,lidar_proc.zdc+height,lat,lon,90.);
lidar_proc.lat=lat;
lidar_proc.lon=lon;
lidar_proc.h=h;

%delineate scans

scan=scangen_ccny2020(lidar_proc);
lidar_proc.scan=scan;

% smooth radials of data over 3 to 10 points for half width of triangular
% weighting function
for ja=1:na
RWS_filter(ja,:)=trismooth(lidar_proc.RWS(ja,:)',10);
Beta_filter(ja,:)=trismooth(lidar_proc.Beta(ja,:)',10);
SNR_filter(ja,:)=trismooth(lidar_proc.SNR(ja,:)',10);
SNRdb_filter(ja,:)=trismooth(lidar_proc.SNRdb(ja,:)',10);
end

% remove weak SNR data
ind=find(SNR_filter<SNRthresh);
SNR_filter(ind)=NaN;
SNRdb_filter(ind)=NaN;
RWS_filter(ind)=NaN;
Beta_filter(ind)=NaN;


%filter hard target and weak signal
hard=hard_target(lidar_proc);
lidar_proc.hard=hard;
for j=1:length(hard.zh)
    SNR_filter(hard.na(j),hard.nr(j):end)=NaN;
    SNRdb_filter(hard.na(j),hard.nr(j):end)=NaN;
    RWS_filter(hard.na(j),hard.nr(j):end)=NaN;
    Beta_filter(hard.na(j),hard.nr(j):end)=NaN;
end

lidar_proc.SNR_filter=SNR_filter;
lidar_proc.SNRdb_filter=SNRdb_filter;
lidar_proc.RWS_filter=RWS_filter;
lidar_proc.Beta_filter=Beta_filter;


%filter clouds
lidar=cloud_deck(lidar_proc);
lidar_proc=lidar;



lidar_proc.SNR_filter=SNR_filter;
lidar_proc.RWS_filter=RWS_filter;
lidar_proc.Beta_filter=Beta_filter;
lidar_proc.SNRdb_filter=SNRdb_filter;