-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromedio_netcdf.bash
More file actions
33 lines (25 loc) · 951 Bytes
/
promedio_netcdf.bash
File metadata and controls
33 lines (25 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Define the directory containing your NetCDF files
data_dir="/Volumes/BM_2022_x/Hindcast_1990_2010"
# Output directory for individual mean files
output_dir="/Volumes/BM_2022_x/Hindcast_1990_2010"
# Create the output directory if it doesn't exist
mkdir -p "$output_dir"
# Loop through each year and month
for year in {1991..2010}; do
for month in {1..12}; do
# Construct the input and output filenames
input_file="$data_dir/croco_avg_Y${year}M${month}.nc"
output_file="$output_dir/Mean_Y${year}M${month}.nc"
# Check if the input file exists
if [[ ! -f "$input_file" ]]; then
echo "Skipping missing file: $input_file"
continue
fi
# Calculate mean within the file using ncra
ncra -d time,0 "$input_file" "$output_file"
# Display message upon successful file creation
echo "Mean file created: $output_file"
done
done
echo "Individual means calculated and saved in: $output_dir"