3 ###############################################################################
6 # AUTHOR: RĂ´mulo Pinho 05/08/2011
8 # Helper file with many functions used in the midP scripts.
10 ###############################################################################
13 # block execution untill the number of threads (jobs) launched by the
14 # current process is below the given number of threads.
19 while [[ $(jobs -p | wc -l) -ge $nbth ]]; do
26 # receive a 4D file and and extract the corresponding phase numbers
27 # export the variables containing each of the extracted data
29 extract_4d_phase_numbers()
33 nb_phases=${#phase_files[@]}
35 # get everything except numbers and punctuation
36 cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:' | sed 's/.mhd//' | grep -o "[^0-9[:punct:]]*" | sort -u > /tmp/patterns.txt
38 # find which patterns have the phases connected to it
39 patterns=`cat /tmp/patterns.txt`
40 if [ -z "$patterns" ]; then
41 phase_nbs=( `cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:' | sed 's/.mhd//' | grep "[0-9]\+"` )
43 for i in $patterns; do
45 # check if the pattern appears before the phase number
46 nb_phases_found=`cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:' | sed 's/.mhd//' | grep -o "$i[0-9[:punct:]]\+" | sort -u | wc -l`
47 if [ $nb_phases_found == $nb_phases ]; then
48 # keep only what identifies the phase number
49 phase_nbs=( `cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:' | sed 's/.mhd//' | grep -o "$i[0-9[:punct:]]\+" | grep -o "[^${i}]\+" | grep -o "[0-9]\+[[:punct:]]*[0-9]*" | grep -o "[0-9]*[[:punct:]]*[0-9]\+"` )
53 # check if the pattern appears after the phase number
54 nb_phases_found=`cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:' | sed 's/.mhd//' | grep -o "[0-9[:punct:]]\+$i" | sort -u | wc -l`
55 if [ $nb_phases_found == $nb_phases ]; then
56 # keep only what identifies the phase number
57 phase_nbs=( `cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:' | sed 's/.mhd//' | grep -o "[0-9[:punct:]]\+$i" | grep -o "[^${i}]\+" | grep -o "[0-9]\+[[:punct:]]*[0-9]*" | grep -o "[0-9]*[[:punct:]]*[0-9]\+"` )
64 echo "Phase numbers are ${phase_nbs[@]}"
69 # receive a 4D file and extract the corresponding phase files,
71 # export the variables containing each of the extracted data
77 echo "4D file is $mhd4d"
79 # array of phase files
80 phase_files=( `cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:'` )
81 echo "Phase files are ${phase_files[@]}"
83 extract_4d_phase_numbers $mhd4d
88 # receive a 4D file and the reference phase number as input
89 # and extract the corresponding phase files, phase numbers,
90 # and reference phase file.
92 # export the variables containing each of the extracted data
94 extract_4d_phases_ref()
98 # reference phase file
99 ref_phase_file=`cat $mhd4d | grep ".raw" | sed 's:.raw:.mhd:' | grep $2`
100 echo "Reference phase is $ref_phase_file"
102 # reference phase number
103 for i in $( seq 0 $((${#phase_nbs[@]} - 1))); do
104 ref_phase_nb=`echo ${phase_nbs[$i]} | grep $2`
105 if [ -n "$ref_phase_nb" ]; then
106 echo "Reference phase number is $ref_phase_nb"