File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import numpy as np
2+ import sys
3+
4+ # Function to read two wave data files
5+ def read_wave_data (file_path ):
6+ with open (file_path , 'r' ) as file :
7+ lines = file .readlines ()
8+
9+ wave_data = {}
10+
11+ heave_data = []
12+ for line in lines [1 :]:
13+ time , heave = line .split ()
14+ heave_data .append (float (heave ))
15+ wave_data ['heave' ] = np .array (heave_data )
16+
17+ return wave_data
18+
19+ def calculate_l2_norm (heave_data1 , heave_data2 ):
20+ yd = heave_data1 - heave_data2
21+ nval = yd .shape [0 ]
22+ l2 = np .linalg .norm (yd )/ nval
23+ return l2
24+
25+ def compare_wave_files (file_path1 , file_path2 ):
26+ wave_data1 = read_wave_data (file_path1 )
27+ wave_data2 = read_wave_data (file_path2 )
28+
29+ # calculate the l2 norm of the difference in heave
30+ diff_heave = calculate_l2_norm (wave_data1 ['heave' ],wave_data2 ['heave' ])
31+
32+ # If the difference is more than 1e-6 then error out
33+ if (diff_heave > 1e-6 ): sys .exit (1 ) # error
34+
35+
36+
37+ if __name__ == "__main__" :
38+
39+ fname_ref = sys .argv [1 ]
40+ fname_rst = sys .argv [2 ]
41+
42+ compare_wave_files (fname_ref , fname_rst )
You can’t perform that action at this time.
0 commit comments