function [zenith, hour_angle] = calcAngle(trainFiles, time, lat, lon)
    % This function computes the solar hour angle for a given date, time, lat, and lon

    % Inputs:
    % - trainFiles: A cell array of file names
    % - time: A cell array of vectors containing times in UTC hours from the lidar
    % - lat: A cell array of vectors containing latitudes
    % - lon: A cell array of vectors containing longitudes

    % Outputs:
    % - solar_hour_angle: A cell array of vectors containing the solar hour angles in degrees

    zenith = cell(size(time));
    hour_angle = cell(size(time));
    
    for vector = 1:length(trainFiles)
        file_name = trainFiles{vector};
        date = file_name(1:8);
        time_data = time{vector};
        lat_data = lat{vector};
        lon_data = lon{vector};
        
    
        %zenith_vector = zeros(size(time_data));
        %hour_angle_vector = zeros(size(time_data));
        zenith_vector = [];
        hour_angle_vector = [];
    
    
        for t = 1:length(time_data)
            if ~isnan(time_data(t))
                % Extract hours and minutes from time_data array 
                hour = floor(time_data(t));
                minute = floor((time_data(t) - hour) * 60);

                if hour >= 24
                    num_days = floor(hour / 24);
                    hour = mod(hour, 24);
                    date = datestr(datenum(date, 'yyyymmdd') + num_days, 'yyyymmdd');
                end
        
                % Convert date and time to MATLAB's datetime format
                datetime_str = [date, ' ', num2str(hour, '%02d'), ':', num2str(minute, '%02d'), ':00'];
                datetime_val = datetime(datetime_str, 'InputFormat', 'yyyyMMdd HH:mm:ss', 'TimeZone', 'UTC');
        
                % Compute the solar hour angle
                [year, month, day, hour, ~, ~] = datevec(datetime_val);
                d = datenum(year, month, day) - datenum(year, 1, 1);
                dec = deg2rad(23.45 * sind(360 * (284 + d) / 365));
                lat_rad = deg2rad(lat_data(t));
                lon_rad = deg2rad(lon_data(t));
                solar_hour_angle = 15 * (12 - hour) - lon_data(t);
                solar_hour_angle_rad = deg2rad(solar_hour_angle);
        
                % Compute the solar zenith angle
                solar_zenith = acosd(sind(lat_rad) * sind(dec) + cosd(lat_rad) * cosd(dec) * cosd(solar_hour_angle_rad));
        
                % Store the solar hour angle in the solar_hour_angle vector
                hour_angle_vector(t) = solar_hour_angle;
                zenith_vector(t) = solar_zenith;
            else
                hour_angle_vector(t) = NaN;
                zenith_vector(t) = NaN;
            end
        zenith{vector} = zenith_vector;
        hour_angle{vector} = (hour_angle_vector);
        end 
    end

