@@ -584,6 +584,37 @@ function generate_polar_data(
584584 return polar_data, reynolds_number[1 ]
585585end
586586
587+ function _extract_literature_polar_data (raw_data, path)
588+ table, header = if raw_data isa Tuple
589+ # readdlm(...; header=true) returns (data, header)
590+ raw_table, raw_header = raw_data
591+ raw_table, lowercase .(strip .(string .(vec (raw_header))))
592+ else
593+ # Header is in first row when a single matrix is returned
594+ raw_data[2 : end , :], lowercase .(strip .(string .(raw_data[1 , :])))
595+ end
596+
597+ # Find column indices for alpha, CL, CD, CS (case-insensitive, allow common variants)
598+ alpha_idx = findfirst (x -> occursin (" alpha" , x) || x == " aoa" , header)
599+ cl_idx = findfirst (x -> occursin (" cl" , x), header)
600+ cd_idx = findfirst (x -> occursin (" cd" , x), header)
601+ cs_idx = findfirst (x -> occursin (" cs" , x), header)
602+
603+ (isnothing (alpha_idx) || isnothing (cl_idx) || isnothing (cd_idx)) &&
604+ throw (ArgumentError (" Literature CSV must contain alpha/aoa, cl and cd columns: $path " ))
605+
606+ # Fallback: if CS not found, fill with zeros
607+ cs_col = cs_idx === nothing ? zeros (size (table, 1 )) : table[:, cs_idx]
608+
609+ # Return as [alpha, CL, CD, CS]
610+ return [
611+ table[:, alpha_idx],
612+ table[:, cl_idx],
613+ table[:, cd_idx],
614+ cs_col
615+ ]
616+ end
617+
587618"""
588619 plot_polars(solver_list, body_aero_list, label_list;
589620 literature_path_list=String[],
@@ -658,22 +689,8 @@ function VortexStepMethod.plot_polars(
658689 # Load literature data if provided
659690 if ! isempty (literature_path_list)
660691 for path in literature_path_list
661- data = readdlm (path, ' ,' )
662- header = lowercase .(string .(data[1 , :]))
663- # Find column indices for alpha, CL, CD, CS (case-insensitive, allow common variants)
664- alpha_idx = findfirst (x -> occursin (" alpha" , x), header)
665- cl_idx = findfirst (x -> occursin (" cl" , x), header)
666- cd_idx = findfirst (x -> occursin (" cd" , x), header)
667- cs_idx = findfirst (x -> occursin (" cs" , x), header)
668- # Fallback: if CS not found, fill with zeros
669- cs_col = cs_idx === nothing ? zeros (size (data, 1 )- 1 ) : data[2 : end , cs_idx]
670- # Push as [alpha, CL, CD, CS]
671- push! (polar_data_list, [
672- data[2 : end , alpha_idx],
673- data[2 : end , cl_idx],
674- data[2 : end , cd_idx],
675- cs_col
676- ])
692+ raw_data = readdlm (path, ' ,' )
693+ push! (polar_data_list, _extract_literature_polar_data (raw_data, path))
677694 end
678695 end
679696
0 commit comments