Skip to content

Commit bb593a2

Browse files
authored
Docs and script for paraview series (#4548)
## Summary * Adds write_series_file_timestamp.sh which has a rounded time * Adds to the documentation describing how to use it ## Additional background This script is based on an existing script from PR #3934 and adds a non-integer time ## Checklist The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [X] include documentation in the code and/or rst files, if appropriate
1 parent 0da05f1 commit bb593a2

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

Docs/sphinx_documentation/source/Visualization.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,11 @@ save this script. Then run the bash script by executing the following command in
362362

363363
bash write_series_file.sh
364364

365-
This will generate a file ``plot_files.series``. Open ParaView, and then select
365+
This will generate a file ``plot_files.series`` which indexes the time variable based on the order of the plotfile numbers.
366+
367+
To make a ``.series`` file which reads the time out of the plotfile header, use :download:`write_series_file_timestamp.sh </Visualization/write_series_file_timestamp.sh>`.
368+
369+
Open ParaView, and then select
366370
"File" :math:`\rightarrow` "Open". In the "Files of Type" dropdown menu (see :numref:`fig:ParaView_filegroup`)
367371
choose the option ``All Files (*)``. Then choose ``plot_files.series`` and click "OK". Now the plotfiles have been
368372
loaded as a Group as in Step 2 of section :ref:`section-1`. Now, you can follow the steps 2 to 7 in the section
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
# Specify the root directory for traversal
4+
root_directory="./"
5+
6+
# Initialize an empty array to store directory information
7+
declare -a dir_info
8+
9+
# Find all plt directories
10+
for dir in plt*; do
11+
if [[ -d "$dir" && -f "$dir/Header" ]]; then
12+
# Extract time from the fifth line of the Header file
13+
time_value=$(sed -n '5p' "$dir/Header")
14+
15+
# Store directory and time as a pair
16+
dir_info+=("$dir:$time_value")
17+
fi
18+
done
19+
20+
# Sort directories numerically by their numbers
21+
IFS=$'\n' sorted_dirs=($(for entry in "${dir_info[@]}"; do
22+
echo "$entry"
23+
done | sort -t: -k1.4,1 -n))
24+
unset IFS
25+
26+
# Initialize an empty string to store file information
27+
files_list=""
28+
29+
# Process sorted directories
30+
for entry in "${sorted_dirs[@]}"; do
31+
dir=$(echo "$entry" | cut -d: -f1)
32+
time_value=$(echo "$entry" | cut -d: -f2)
33+
34+
# Round to 6 decimal places and format nicely
35+
rounded_time=$(awk -v t="$time_value" 'BEGIN{printf "%.6f", t}' | sed 's/\.0*$//;s/\.\([0-9]*[1-9]\)0*$/.\1/')
36+
37+
echo "Processing $dir with time $rounded_time"
38+
39+
# Create file information
40+
files_list+="$(printf "{ \"name\": \"$dir\", \"time\": $rounded_time},")"
41+
files_list+=$'\n'
42+
done
43+
44+
# Remove trailing comma from the last entry
45+
files_list="${files_list%,}"
46+
47+
# Create the final JSON structure
48+
header_line="{ \"file-series-version\": \"1.0\", \"files\": ["
49+
all_files="$(printf '%s\n' "$files_list") ] }"
50+
51+
file_series_data="$header_line"
52+
file_series_data+=$'\n'
53+
file_series_data+="$all_files"
54+
55+
# Write the generated JSON structure to a file named plot_files.series
56+
echo "$file_series_data" > plot_files.series
57+
58+
echo "JSON structure has been written to plot_files.series"

0 commit comments

Comments
 (0)