Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions mk_sam_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def main():
###########################################################################

# setting name
sam_header = hdf['site_info']['site_name'] + '\r\n'
sam_header = hdf['site_info']['site_name'] + '\n'

# creating long lat and dec info
for value in site_values:
Expand All @@ -176,11 +176,11 @@ def main():
if value == 'site_long':
sam_header += ' {:05.1f}'.format(float(hdf['site_info'][value])%360)
sam_header += ' '*(3) + '0.0'
sam_header += '\r\n'
sam_header += '\n'

# making writing sample info
for sample in samples:
sam_header += hdf['site_info']['site_id'] + str(sample) + '\r\n'
sam_header += hdf['site_info']['site_id'] + str(sample) + '\n'

# creating and writing file
print('Writing file - ' + os.path.join(output_directory, hdf['site_info']['site_id'] + '.sam'))
Expand Down Expand Up @@ -245,7 +245,7 @@ def main():
"http://cires.colorado.edu/people/jones.craig/PMag_Formats.html"

# write sample name and comment for sample file
new_file = site_id + ' ' + str(sample) + ' ' + comment + '\r\n'
new_file = site_id + ' ' + str(sample) + ' ' + comment + '\n'

# start second line strat_level get's special treatment
if (math.isnan(float(df[sample]['strat_level']))):
Expand Down Expand Up @@ -297,7 +297,7 @@ def main():
new_file += run + '\r\n'

Copilot AI Mar 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 293 and 297 still use \r\n, which are not stripped by the rstrip('\r\n') on line 300 when they appear in the middle of the string (i.e., when there are runs appended after line 293, or when there are multiple runs). This means the sample files will still contain \r\n line endings for internal lines on Windows, defeating the purpose of this PR. These should be changed to \n as well, consistent with all the other changes in this PR.

Copilot uses AI. Check for mistakes.

# create and write sample file
new_file = new_file.rstrip('\r\n') + '\r\n'
new_file = new_file.rstrip('\r\n') + '\n'
print('Writing file - ' + os.path.join(output_directory, site_id + str(sample)))
sample_file = open(os.path.join(output_directory, site_id + str(sample)), 'w+')
sample_file.write(new_file)
Expand All @@ -311,16 +311,16 @@ def main():
csv_str = ''

for i in range(5):
csv_str += csv_file.readline()

csv_str += csv_file.readline().rstrip('\n')
Comment thread
Swanson-Hysell marked this conversation as resolved.
Outdated
Comment thread
Swanson-Hysell marked this conversation as resolved.
Outdated
comma_count = csv_file.readline().count(',')
csv_str += 'site_elevation' + ',' + \
str(hdf['site_info']['site_elevation']) + ','*(comma_count-1) + '\n'
# elev_line = csv_file.readline().split(',')
# elev_line[1] = str(hdf['site_info']['site_elevation'])
# reduce(lambda x,y: x + ',' + y, elev_line)

header = csv_file.readline()
header = csv_file.readline().rstrip('\n')
csv_str += header
Comment thread
Swanson-Hysell marked this conversation as resolved.
Outdated
header = header.strip('\r\n').split(',')

Expand All @@ -341,7 +341,7 @@ def main():
items[i] = str(sdf[sample][header[i]])
else:
raise KeyError('there is no item: ' + header[i])
csv_str += reduce(lambda x, y: x + ',' + y, items) + '\r\n'
csv_str += reduce(lambda x, y: x + ',' + y, items) + '\n'

print('Writing file - ' + os.path.join(output_directory, hdf['site_info']['site_id'] + '.csv'))
new_csv_file = open(os.path.join(output_directory, hdf['site_info']['site_id'] + '.csv'), 'w+')
Expand Down