% Create figures folder if it doesn't exist
if ~exist('figures', 'dir')
    mkdir('figures')
end

% Loop through casts 01 to 07
for i = 1:7
    % Create variable name dynamically (c01, c02, etc.)
    cast_name = sprintf('c%02d', i);
    cast_data = eval(cast_name);
    
    % Create figure
    figure;
    plot(cast_data.pH_tot, cast_data.PrDM, LineWidth=2, LineStyle="-", Marker="o")
    set(gca,'Ydir','reverse')
    title(sprintf('Cast %d: pH total [20^oC atm]', i))
    ylabel('Depth [m]')
    grid on;
    
    % Set figure to vertical page layout
    set(gcf, 'PaperOrientation', 'portrait')
    set(gcf, 'PaperUnits', 'inches')
    set(gcf, 'PaperPosition', [0 0 6 8])
    
    % Save as JPG in figures folder
    filename = sprintf('figures/cast%d_pH_profile', i);
    print(filename, '-djpeg', '-r300')
    
    % Close figure to free memory
    close(gcf)
end

disp('All figures saved to figures/ folder')