#!/bin/bash

# Create output directory if it doesn't exist
mkdir -p output

# Set power value
power=2.0
cmax=2E-10

# Loop over longitude values
for long in 0 45 90; do
    # Format long as three-digit string (e.g., 000, 045, 090)
    long_fmt=$(printf "%03d" $long)

    # Loop over rho index from 120 to 140
    for i in $(seq 120 140); do
        # Format index as 3-digit zero-padded string
        idx_fmt=$(printf "%03d" $i)

        # Full path to rho file
        rho_file="hdf/rho_0${idx_fmt}.h5"

        # Output filenames
        outfile_b="output/b_${long_fmt}_${idx_fmt}.h5"
        outfile_pb="output/pb_${long_fmt}_${idx_fmt}.h5"
        png_b="output/b_${long_fmt}_${idx_fmt}.png"
        png_pb="output/pb_${long_fmt}_${idx_fmt}.png"

        # Run with -b
        getpb -long $long -b0 0.0 -rocc 31 -power $power -nx 1024 -ny 1024 -x0 -100 -x1 100 -y0 -100 -y1 100 \
              -rho "$rho_file" -r 1.0 -b $outfile_b

        plot2d -cmin 0 -cmax $cmax -cmap psi_blue_white -o "$png_b" "$outfile_b"

        # Run with -pb
        getpb -long $long -b0 0.0 -rocc 31 -power $power -nx 1024 -ny 1024 -x0 -100 -x1 100 -y0 -100 -y1 100 \
              -rho "$rho_file" -r 1.0 -pb $outfile_pb

        plot2d -cmin 0 -cmax $cmax -cmap psi_blue_white -o "$png_pb" "$outfile_pb"

    done
done

