#------------------------------------------------------------------------------- # dump_string: Dumps an array of strings to a file in edn format #------------------------------------------------------------------------------- def dump_string_array( EdnName, string, file_id): Text = ''' "%s" { "source-value" [ "%s" ] }''' %(EdnName, string) file_id.write("%s\n" %(Text)) #------------------------------------------------------------------------------- # dump_dbl_scalar: Dumps a scalar property to a file in edn format #------------------------------------------------------------------------------- def dump_dbl_scalar( EdnName, source_scalar, file_id, source_unit=None ): Text = ''' "%s" { "source-value" %.15e\n''' %( EdnName, source_scalar ) if (source_unit is not None): Text = Text + ' "source-unit" "%s"\n' %(source_unit) Text = Text + " }" file_id.write("%s\n" %(Text)) #------------------------------------------------------------------------------- # dump_dbl_vector: Dumps a double precision vector to a file in edn format #------------------------------------------------------------------------------- def dump_dbl_vector( EdnName, source_vector, file_id, source_unit=None ): str_vector = "".join(format(element, "25.15e") for element in source_vector) Text = ''' "%s" { "source-value" [ %s ]\n''' %( EdnName, str_vector ) if (source_unit is not None): Text = Text + ' "source-unit" "%s"\n ' %(source_unit) Text = Text + " }" file_id.write("%s\n" %(Text)) #------------------------------------------------------------------------------- # dump_dbl_matrix: Dumps a double precision matrix to a file in edn format #------------------------------------------------------------------------------- def dump_dbl_matrix( EdnName, source_matrix, file_id, source_unit=None ): Text = ''' "%s" { "source-value" [''' %EdnName row_Idx = 0 for row in source_matrix: str_row = "".join(format(element, "25.15e") for element in row) if (row_Idx == 0): Text = Text + "[ %s ]\n" %str_row elif (row_Idx == len(source_matrix)-1): Text = Text + " "*25 + "[ %s ]]\n" %str_row else: Text = Text + " "*25 + "[ %s ]\n" %str_row row_Idx = row_Idx + 1 if (source_unit is not None): Text = Text + ' "source-unit" "%s"\n ' %(source_unit) Text = Text + " }" file_id.write("%s\n" %(Text))