function [] = calcDrop(campaign,mlh_type) 

    %campaign = '2020_ACTIVATE';
    pathname = sprintf('/data2/juliechristo/%s/dropsondes/',campaign);
    myFiles = dir(fullfile(pathname,'*.dat')); %.ict for most, .nc for CAMP2Ex

    current_date = '';

    %initalize variables to output
    time_lidar = [];
    mlh_parcel = [];
    mlh_theta = [];
    mlh_ri = [];
    mlh_qv = [];
    mlh_lidar = [];
    lat_lidar = [];
    lon_lidar = [];
    alt_lidar = [];
    gps_alt_lidar = [];
    

    % -- Iterate through dropsondes -- 
    for k = 1:length(myFiles)
        subfilename = myFiles(k).name;
        date = subfilename(1:8)
        drop_time = subfilename(9:14);
        drop_name = subfilename (1:14);
        drop_time = str2double([drop_time(1:2) '.' drop_time(3:end)]);
        full_path = fullfile(pathname,subfilename);
        drop = read_dropsonde(campaign,full_path,'stripnan');
        try 
            lat_test = drop.Latitude;
        catch
            disp('read_dropsonde.m returned NaN. Skipping iteration.');
            continue;
        end 
        lat_drop = drop.Latitude(1); %inital lat
        lon_drop = drop.Longitude(1); %initial drop
        try 
            land = checkCoords(lat_drop,lon_drop); %check if drop is over land or water
        catch
            land = 1;
        end
        %disp(size(drop.Time))
        %disp(size(drop.Altitude))
        %disp(size(drop.Temp))
        mlh_parcel = [mlh_parcel;mlh_dropsonde(drop,land,'parcel')]; 
        mlh_theta = [mlh_theta;mlh_dropsonde(drop,1,'theta')];
        mlh_ri = [mlh_ri;mlh_dropsonde(drop,land,'ri')];
        mlh_qv = [mlh_qv;mlh_dropsonde(drop,land,'qv')];
    

        if contains(mlh_type,'.h5') 
            try
                %read .h5 files to find MLH at same latitude and longitude
                h5_direc = sprintf('/data2/juliechristo/%s/Archive/',campaign)
                h5_filename = fullfile(h5_direc, [date,'_R3','.h5']);
                mlh_h5 = h5read(h5_filename,'/DataProducts/MixedLayerHeight');
                gps_time = h5read(h5_filename,'/Nav_Data/gps_time');
    
                %find closest time from lidar and extract index 
                abs_diff = abs(gps_time - drop_time);
                [~, idx] = min(abs_diff);
                time_lidar = [time_lidar;gps_time(idx)];
                mlh_range = mlh_h5(idx-10:idx+10);
                mlh_lidar = [mlh_lidar;mean(mlh_range,'omitnan')];


            catch exception
                time_lidar = nan;
                mlh_lidar = nan;
                fprintf('Error occurred: %s\n', exception.message);
            end
        end 


        if contains(mlh_type,'.ict') 
            try
                %read in the .ict file information
                ict_direc = sprintf('/data2/juliechristo/%s/mlh/',campaign);
                ict_filename = fullfile(ict_direc, [date,'_R0','.ict']);
                mlh_data = ICARTTreader(ict_filename);
                time_start = mlh_data.Time_Start;
                time_stop = mlh_data.Time_Stop;
                time_mid = mlh_data.Time_Mid;
                mlh_ict = mlh_data.MLH;
                %convert the times to a float to match gps_time
                hours = floor(time_mid / 3600);
                minutes = floor(mod(time_mid, 3600) / 60);
                seconds = mod(time_mid, 60);
                gps_time = hours + minutes/60 + seconds/3600;
                %find the closest time from lidar and extract index
                abs_diff = abs(gps_time - drop_time);
                [~, idx] = min(abs_diff);
                time_lidar = [time_lidar;gps_time(idx)];
                mlh_range = mlh_ict(idx-10:idx+10);
                mlh_lidar = [mlh_lidar;mean(mlh_range,'omitnan')];
            catch
                try
                    ict_filename = fullfile(ict_direc, [date,'_R0','_L1.ict']) 
                    mlh_data = ICARTTreader(ict_filename);
                    time_start = mlh_data.Time_Start;
                    time_stop = mlh_data.Time_Stop;
                    time_mid = mlh_data.Time_Mid;
                    mlh_ict = mlh_data.MLH;
                    %convert the times to a float to match gps_time
                    hours = floor(time_mid / 3600);
                    minutes = floor(mod(time_mid, 3600) / 60);
                    seconds = mod(time_mid, 60);
                    gps_time = hours + minutes/60 + seconds/3600;
                    %find the closest time from lidar and extract index
                    abs_diff = abs(gps_time - drop_time);
                    [~, idx] = min(abs_diff);
                    time_lidar = [time_lidar;gps_time(idx)];
                    mlh_range = mlh_ict(idx-10:idx+10);
                    mlh_lidar = [mlh_lidar;mean(mlh_range,'omitnan')];
                catch exception 
                    fprintf('Error occurred: %s\n', exception.message);
                    try
                        ict_filename = fullfile(ict_direc, [date,'_R0','_L2.ict'])
                        mlh_data = ICARTTreader(ict_filename);
                        time_start = mlh_data.Time_Start;
                        time_stop = mlh_data.Time_Stop;
                        time_mid = mlh_data.Time_Mid;
                        mlh_ict = mlh_data.MLH;
                        %convert the times to a float to match gps_time
                        hours = floor(time_mid / 3600);
                        minutes = floor(mod(time_mid, 3600) / 60);
                        seconds = mod(time_mid, 60);
                        gps_time = hours + minutes/60 + seconds/3600;
                        %find the closest time from lidar and extract index
                        abs_diff = abs(gps_time - drop_time);
                        [~, idx] = min(abs_diff);
                        time_lidar = [time_lidar;gps_time(idx)];
                        mlh_range = mlh_ict(idx-10:idx+10);
                        mlh_lidar = [mlh_lidar;mean(mlh_range,'omitnan')];

	            catch exception
                        time_lidar = nan;
                        mlh_lidar = nan;
                        fprintf('Error occurred: %s\n', exception.message);
                    end
                end
            end  

        end 

        % -- Output the dropsonde calculations -- 
        if ~strcmp(date, current_date)
            % Create a new CSV file
            current_date = date;
            csv_filename = fullfile(sprintf('/home/juliechristo/PBL/drop/dropsondes/results/%s/',campaign), [sprintf('%s_MLH_',campaign) date '.csv']);
        
            % Define column labels
            column_labels = {'Time_Lidar', 'MLH_Parcel', 'MLH_Theta', 'MLH_Ri', 'MLH_Qv', 'MLH_Lidar'};
        
            % Create a cell array with column labels and data
            disp(size(time_lidar))
            disp(size(mlh_parcel))
            disp(size(mlh_lidar))
            data_matrix = [time_lidar, mlh_parcel, mlh_theta, mlh_ri, mlh_qv, mlh_lidar];
            try
                data_with_labels = [column_labels; num2cell(data_matrix)];
            catch
                disp('Badsonde.');
                continue;
            end 
            % Write the data to the CSV file
            writecell(data_with_labels, csv_filename);
        else
            % Append data to the existing CSV file
            csv_filename = fullfile(sprintf('/home/juliechristo/PBL/drop/dropsondes/results/%s/',campaign), [sprintf('%s_MLH_',campaign) date '.csv']);
            data_matrix = [time_lidar', mlh_parcel, mlh_theta, mlh_ri, mlh_qv, mlh_lidar'];
        
            % Append data to the existing CSV file
            writematrix(data_matrix, csv_filename, 'WriteMode', 'append');
        end

        % Reset variables for the next iteration
        time_lidar = [];
        mlh_parcel = [];
        mlh_theta = [];
        mlh_ri = [];
        mlh_qv = [];
        mlh_lidar = [];
    end

end












