Index: DamClients/DamUI/trunk/utils/PythonScripts/mdb_to_csv_converter.py =================================================================== diff -u --- DamClients/DamUI/trunk/utils/PythonScripts/mdb_to_csv_converter.py (revision 0) +++ DamClients/DamUI/trunk/utils/PythonScripts/mdb_to_csv_converter.py (revision 4665) @@ -0,0 +1,67 @@ +import argparse +import textwrap + + +def fetch_shear_strength_model(shear_strength_model_from_mdb): + if shear_strength_model_from_mdb == 'Default': + shear_strength_model_for_csv = 'CPhi' + elif shear_strength_model_from_mdb == 'C Phi': + shear_strength_model_for_csv = 'CPhi' + elif shear_strength_model_from_mdb == 'Su calculated with POP': + shear_strength_model_for_csv = 'CuCalculated' + else: + shear_strength_model_for_csv = 'CPhi' + return shear_strength_model_for_csv + + +parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, + description=textwrap.dedent('''\ +Script to convert a mdb file to a csv file. + +The following manual steps needs to be taken prior to using this script: +* Open the file in MSoilbase, Select "DAM All" in "Filter For" +* Select the column(s) and click on "Copy with headers (export only)" +* Open the content of the clipboard in notepad and save the file. + +Note: The strength_increase_exponent and the ratio_su_pc are not imported in the output csv +For the shear_strength_model only CPhi and CuCalculated are supported as output +''')) +parser.add_argument("-m", "--mdb", help='the input file') +parser.add_argument("-c", "--csv", help='the output file') + +args = parser.parse_args() + +mdb_file = args.mdb +csv_file = args.csv + +input_file = open(mdb_file, "r") +output_file = open(csv_file, "w") +input_file.readline() +input_lines = input_file.readlines() + +output_header = "soil_name;soil_color;soil_type;saturated_unit_weight;unsaturated_unit_weight;cohesion;" \ + "friction_angle;diameter_d70;permeability_x;shear_strength_model;use_pop;pop" +output_color = "#FFFFFF" +output_file.write(output_header + "\n") + +for input_line in input_lines: + tab_separated_line = input_line.split("\t") + + soil_name = tab_separated_line[2] + soil_color = output_color + soil_type = tab_separated_line[3] + saturated_unit_weight = tab_separated_line[6] + unsaturated_unit_weight = tab_separated_line[5] + cohesion = tab_separated_line[8] + friction_angle = tab_separated_line[9] + diameter_d70 = tab_separated_line[38] + permeability_x = str(float(tab_separated_line[38]) / 1000) + shear_strength_model = fetch_shear_strength_model(tab_separated_line[22]) + pop = tab_separated_line[15] + use_pop = str(float(pop) > 0) + + output_line = soil_name + ";" + soil_color + ";" + soil_type + ";" + saturated_unit_weight + ";" + \ + unsaturated_unit_weight + ";" + cohesion + ";" + friction_angle + ";" + diameter_d70 + ";" + \ + permeability_x + ";" + shear_strength_model + ";" + use_pop + ";" + pop + "\n" + + output_file.write(output_line)