# # A simple test script to convert X,Y coordinates of components # from mm to tens of nanometers # # Version for the Hub Module card. Rev. 4-May-2014 # Version for the Disco-Kraken card. Rev. 14-Dec-2023 # input_comps_file_name = "temp_out_file" output_comps_file_name = "aa_disco_comp_file.txt" conversion_factor = 100 * 1000 word_labels = ( "Comp", "Part", "JUNK", "Geom", "X", "Y", "Side", "Rotation" ) word_num_comp = 0 word_num_x = 4 word_num_y = 5 show_first_few = 2 # show first few converted lines; 0 for none print "Input components file is <%s>" % input_comps_file_name print "Output components file is <%s>" % output_comps_file_name print "Conversion factor is <%d>" % conversion_factor print "" print "" input_comps_file = open ( input_comps_file_name, "r" ) output_comps_file = open ( output_comps_file_name, "w" ) input_lines = input_comps_file.readlines() # handle one line at a time input_line_num = 0 tweak_count = 0 for input_line in input_lines : input_line_num += 1 input_line_words = input_line.split() # on each line handle one word to build an output line output_line = "" for word_num in range ( len(input_line_words) ) : # the default is that we will just copy the word from this line ... output_line_word = input_line_words[word_num] # ... unless this is the X or Y coordinate if word_num in ( word_num_x, word_num_y ) : # try the conversion conv_coord_int = conversion_factor * eval ( output_line_word ) conv_coord_str = "%d" % conv_coord_int # detect a rounding issue by watching least significant digit if ( conv_coord_str[-1:] in ( "1", "9" ) ) : # advertize the correction print "*** Tweaking %s coord for <%s> <%s> from becoming <%s>" % ( word_labels[word_num], input_line_words[word_num_comp], output_line_word, conv_coord_str ) # tweak as necessary tweak_count += 1 if ( conv_coord_str[-1:] == "1" ) : conv_coord_int -= 1 else : conv_coord_int += 1 conv_coord_str = "%d" % conv_coord_int # this will replace the default input word we used earlier output_line_word = conv_coord_str # tack it onto the output line output_line = "%s%s " % ( output_line, output_line_word ) # write the output line output_comps_file.write ( "%s\n" % output_line ) # show the first few lines to the screen if ( input_line_num < show_first_few ) : print output_line elif ( input_line_num == show_first_few ) : print "... and so on ..." # Done print "Done translating; Tweaked %d coordinates" % tweak_count input_comps_file.close () output_comps_file.close ()