Reworking external/ build
[WRF.git] / tools / test_nml_domains.csh
blob112c2646b04056720418527702c62f2579531ae1
1 #!/bin/csh
3 unalias cp rm
5 # This script needs know where the Registry directory is
6 # located and also namelist.input file to review.
8 # No arguments, maybe this is a simple default location.
9 # Make a few educated guesses
11 set OK = 1
12 if (${#argv} == 0 ) then
14 # Is this the WRFV3/run directory
16 if ( ( -d ../Registry ) && ( -f namelist.input ) ) then
17 set Reg_Dir = ../Registry
18 set NML_File = namelist.input
19 set OK = 0
21 # Is this the WRFV3/test/em_* directory
23 else if ( ( -d ../../Registry ) && ( -f namelist.input ) ) then
24 set Reg_Dir = ../../Registry
25 set NML_File = namelist.input
26 set OK = 0
28 endif
29 endif
31 if ( $OK != 0 ) then
32 if (${#argv} != 2) then
33 echo "usage: $0 Full_path/Registry Full_path/namelist.input"
34 exit ( 1 )
35 else
36 set Reg_Dir = $argv[1]
37 set NML_File = $argv[2]
38 endif
39 endif
41 # Check that the input arguments are OK: Registry
43 if ( -d $Reg_Dir ) then
44 if ( -e ${Reg_Dir}/Registry.EM_COMMON ) then
45 # noop
46 else
47 echo Cannot find the expected Registry files in the $Reg_Dir directory
48 exit ( 3 )
49 endif
50 else
51 echo $Reg_Dir is not a valid directory
52 exit ( 2 )
53 endif
55 # Check that the input arguments are OK: namelist.input
57 if ( -e $NML_File ) then
58 grep -iq time_control $NML_File
59 set OK_time_control = $status
60 grep -iq domains $NML_File
61 set OK_domains = $status
62 grep -iq physics $NML_File
63 set OK_physics = $status
64 grep -iq dynamics $NML_File
65 set OK_dynamics = $status
66 if ( ( $OK_time_control == 0 ) && \
67 ( $OK_domains == 0 ) && \
68 ( $OK_physics == 0 ) && \
69 ( $OK_dynamics == 0 ) )then
70 else
71 echo "The supplied namelist.input file does not seem to have the necessary NML records"
72 exit ( 5 )
73 endif
74 else
75 echo "Cannot find the namelist.input file specified: $NML_File"
76 exit ( 4 )
77 endif
79 # Get a list of all possible variables in the Registry directory
80 # that have max_domains, and all variables that have only a single
81 # domain of info
83 if ( -e list_of_all_max_dom_vars ) then
84 rm -rf list_of_all_max_dom_vars
85 endif
86 touch list_of_all_max_dom_vars
88 if ( -e list_of_all_one_dom_vars ) then
89 rm -rf list_of_all_one_dom_vars
90 endif
91 touch list_of_all_one_dom_vars
93 foreach f ( $Reg_Dir/Registry.* $Reg_Dir/registry.* )
94 grep -i ^rconfig $f | grep -i max_domains | awk '{print $3}' >> list_of_all_max_dom_vars
95 grep -i ^rconfig $f | grep -vi max_ | awk '{print $3}' >> list_of_all_one_dom_vars
96 end
98 # Pick up the KNOWN namelist variable max_dom
100 foreach f ( $Reg_Dir/Registry.* $Reg_Dir/registry.* )
101 grep -i ^rconfig $f | grep -iw max_dom | awk '{print $3}' >> list_of_all_one_dom_vars
104 sort -u list_of_all_max_dom_vars > list_of_all_max_dom_vars_sorted
105 sort -u list_of_all_one_dom_vars > list_of_all_one_dom_vars_sorted
107 # Check the namelist, record by record. Ignore commented out portions,
108 # and ignore parts outside of the first "/" namelist record closing character.
110 sed -e 's/\!.*//' $NML_File > .nml_no_comments
111 awk '/&/,/\//' .nml_no_comments > .nml_no_comments-within_record_marks
112 grep "=" .nml_no_comments-within_record_marks > .nml_no_comments-within_record_marks-has_equals
113 sed -e 's/=/ /' .nml_no_comments-within_record_marks-has_equals > .nml_no_comments-within_record_marks-has_equals-no_equals
114 sed -e 's/,/ /g' .nml_no_comments-within_record_marks-has_equals-no_equals > .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas
115 grep -v '\&' .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas | grep -v '\/' > .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas-no_record_marks
116 awk '{print $1 }' .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas-no_record_marks > .var_list_only
117 awk '{print $1 , NF}' .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas-no_record_marks > .var_list_num_fields
119 # How many domains are we trying to use
121 grep -iwq max_dom .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas-no_record_marks
122 set OK = $status
123 if ( $OK != 0 ) then
124 echo "The number of domains needs to be specified in the namelist.input file: max_dom"
125 exit ( 6 )
126 else
127 set max_dom = `grep -iw max_dom .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas-no_record_marks | awk '{print $2}'`
128 endif
130 foreach v ( `cat .var_list_only` )
131 set num_fields = `grep -iw $v .var_list_num_fields | awk '{print $2}'`
133 # Is this a single variable, or does the var have an entry for each domain
135 grep -iwq $v list_of_all_one_dom_vars_sorted
136 set OK1 = $status
137 grep -iwq $v list_of_all_max_dom_vars_sorted
138 set OK2 = $status
140 if ( $OK1 == 0 ) then
141 if ( $num_fields > 2 ) then
142 echo "The $v variable should have only one entry: FATAL"
143 endif
144 else if ( $OK2 == 0 ) then
145 if ( `expr $num_fields - 1` < $max_dom ) then
146 echo "The $v variable should have entries for each domain: BE CAREFUL"
147 endif
148 else if ( ( $OK1 != 0 ) && ( $OK2 != 0 ) ) then
149 echo "The $v variable is not in any Registry: Problem if you just modified $v in the namelist.input file"
150 endif
153 # Whack the temporary files.
155 set dummy_files = ( .nml_no_comments .nml_no_comments-within_record_marks .nml_no_comments-within_record_marks-has_equals .nml_no_comments-within_record_marks-has_equals-no_equals .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas .nml_no_comments-within_record_marks-has_equals-no_equals-no_commas-no_record_marks .var_list_num_fields .var_list_only .var_list list_of_all_max_dom_vars list_of_all_max_dom_vars_sorted list_of_all_one_dom_vars list_of_all_one_dom_vars_sorted )
157 foreach f ( $dummy_files )
158 rm -rf $f