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 = 'MohrCoulomb' elif shear_strength_model_from_mdb == 'C Phi': shear_strength_model_for_csv = 'MohrCoulomb' elif shear_strength_model_from_mdb == 'Su calculated with POP': shear_strength_model_for_csv = 'SHANSEP' elif shear_strength_model_from_mdb == 'Stress table': shear_strength_model_for_csv = 'SigmaTauTable' else: shear_strength_model_for_csv = 'MohrCoulomb' 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;pop;sigma_tau_curve_name;traffic_load_degree_of_consolidation" 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 = tab_separated_line[14] shear_strength_model = fetch_shear_strength_model(tab_separated_line[22]) pop = tab_separated_line[15] sigma_tau_curve_name = tab_separated_line[20] traffic_load_degree_of_consolidation = tab_separated_line[43] output_line = (soil_name + ";" + soil_color + ";" + soil_type + ";" + saturated_unit_weight + ";" + \ unsaturated_unit_weight + ";" + cohesion + ";" + friction_angle + ";" + diameter_d70 + ";" + \ permeability_x + ";" + shear_strength_model + ";" + pop + ";" + sigma_tau_curve_name + ";" + traffic_load_degree_of_consolidation + "\n") output_file.write(output_line)