@@ -165,4 +165,77 @@ function create_polars(; dat_path, polar_path, wind_vel, area, width, crease_fra
165165 serialize (polar_path, (alpha_range, delta_range, cl_matrix, cd_matrix, cm_matrix))
166166
167167 toc ()
168- end
168+ end
169+
170+
171+ """
172+ write_aero_matrix(filepath::String, matrix::Matrix{Float64},
173+ alpha_range::Vector{Float64}, delta_range::Vector{Float64};
174+ label::String="C_l")
175+
176+ Write an aerodynamic coefficient matrix to CSV with angle labels.
177+ The first row contains flap deflection angles, first column contains angles of attack.
178+
179+ # Arguments
180+ - `filepath`: Path to output CSV file
181+ - `matrix`: Matrix of aerodynamic coefficients
182+ - `alpha_range`: Vector of angle of attack values in radians
183+ - `delta_range`: Vector of flap deflection angles in radians
184+ - `label`: Coefficient label for the header (default: "C_l")
185+ """
186+ function write_aero_matrix (filepath:: String , matrix:: Matrix{Float64} ,
187+ alpha_range:: Vector{Float64} , delta_range:: Vector{Float64} ;
188+ label:: String = " C_l" )
189+ open (filepath, " w" ) do io
190+ # Write header with delta values
191+ println (io, " $label /delta," * join ([" δ=$(round (rad2deg (δ), digits= 1 )) °" for δ in delta_range], " ," ))
192+
193+ # Write data rows with alpha values and coefficients
194+ for i in eachindex (alpha_range)
195+ row = " α=$(round (rad2deg (alpha_range[i]), digits= 1 )) °," * join (matrix[i,:], " ," )
196+ println (io, row)
197+ end
198+ end
199+ end
200+
201+ """
202+ read_aero_matrix(filepath::String) -> (Matrix{Float64}, Vector{Float64}, Vector{Float64})
203+
204+ Read an aerodynamic coefficient matrix from CSV with angle labels.
205+ Returns the coefficient matrix and corresponding angle ranges.
206+
207+ # Returns
208+ - `matrix`: Matrix of aerodynamic coefficients
209+ - `alpha_range`: Vector of angle of attack values in radians
210+ - `delta_range`: Vector of flap deflection angles in radians
211+ """
212+ function read_aero_matrix (filepath:: String )
213+ lines = readlines (filepath)
214+
215+ # Parse header to get delta values
216+ header = split (lines[1 ], ' ,' )
217+ delta_values = map (header[2 : end ]) do δ_str
218+ # Extract number between "δ=" and "°"
219+ m = match (r" δ=(-?\d +\. ?\d *)°" , δ_str)
220+ deg2rad (parse (Float64, m. captures[1 ]))
221+ end
222+
223+ # Initialize matrix
224+ n_rows = length (lines) - 1 # Subtract header
225+ n_cols = length (delta_values)
226+ matrix = zeros (n_rows, n_cols)
227+ alpha_values = zeros (n_rows)
228+
229+ # Parse data rows
230+ for (i, line) in enumerate (lines[2 : end ])
231+ entries = split (line, ' ,' )
232+ # Extract alpha value
233+ m = match (r" α=(-?\d +\. ?\d *)°" , entries[1 ])
234+ alpha_values[i] = deg2rad (parse (Float64, m. captures[1 ]))
235+ # Parse coefficient values
236+ matrix[i,:] .= parse .(Float64, entries[2 : end ])
237+ end
238+
239+ return matrix, alpha_values, delta_values
240+ end
241+
0 commit comments