#!/bin/bash

# List of input and output files
inputs=(ncfile_List)
outputs=(out_put_file_List)

# Desired number of grid cells
nlon=1440  # Number of cells in longitude (horizontal)
nlat=521   # Number of cells in latitude (vertical)

# Create a new grid description file
echo "gridtype  = lonlat" > grid.txt
echo "xsize     = $nlon" >> grid.txt
echo "ysize     = $nlat" >> grid.txt
echo "xfirst    = -180" >> grid.txt
echo "xinc      = 0.25" >> grid.txt
echo "yfirst    = -60" >> grid.txt
echo "yinc      = 0.25" >> grid.txt

# Regrid each input file to the new grid and save the results to the corresponding output files
for i in "${!inputs[@]}"; do
    input="${inputs[$i]}"
    output="${outputs[$i]}"
    
    cdo remapbil,grid.txt $input $output
    
    # Regrid completion message
    echo "Regridding completed: $output"
done
