I've got a little script which is not working nicely for me, hope you can help and find the problem.
I have two starting files:
traveltimes: contains the lines I need, it's a column file. The lines I need are separated by a line which starts with 11 whitespaces
header lines: contains three header lines
output_file: I want to get 29 files (STA%s). What's inside? Every file will contain the same header lines after which I want to append the group of lines contained in the traveltimes file (one different group of lines for every file). Every group of lines is made by 74307 rows (1 column)
So far this script creates 29 files with the same header lines but then it mixes up everything, I mean it writes something but it's not what I want.
def make_station_files(traveltimes, header_lines): """Gives the STAxx.tgrid files required by loc3d""" sta_counter = 1 # traveltimes = ttarray_tms (traveltimes_data) with open (header_lines, 'r') as file_in: data = file_in.readlines() for i in range (29): with open ('STA%s' % (sta_counter), 'w') as output_files: sta_counter += 1 for i in data [0:3]: values = i.strip() output_files.write ("%s\n\t1\n" % (values)) with open (traveltimes, 'r') as times_file: #collector =  for line in times_file: if line.startswith (" "): break output_files.write ("%s" % (line))