#!/usb/bin/env python
'''
edit_datcnvpsa.py

USAGE:
edit_datcnv.py scannum

DESCRIPTION: 
Edit the DatCnv.psa file in the current directory to replace the ScansToSkip
field with the correct value for the current cast.
'''
#
# edit_datcnvpsa.py
#
# USAGE:
# edit_datcnv.py scannum
#
# DESCRIPTION: 
# Edit the DatCnv.psa file in the current directory to replace the ScansToSkip
# field with the correct value for the current cast.
#
__author__ = "Derrick Snowden <derrick.snowden@noaa.gov>"
import sys,os

scannum = sys.argv[1]

# Base directory is D:\COMISSOES\2017\2-PIRATA_XVII\DADOS\PIRA\1-BRUTOS
# CTDPROC should be set to the base path where most of the cruises reside.
base = os.environ['CTDPROC'] # c:\data\
base = os.path.join(base,'PSA')

in_file_name = os.path.join(base,'DatCnv_H39.psa')
out_file_name = os.path.join(base,'DatCnvOut.psa')
in_file = file(in_file_name)
out_file = file(out_file_name,'w')

for l in in_file.readlines():
	if l.rfind("ScansToSkip")>0:
		this = '  <ScansToSkip value="%s" />\n' % scannum
		out_file.write(this)
	else:
		out_file.write(l)
		
in_file.close()
out_file.close()
cmd = "move %s %s" % (out_file_name, in_file_name)
print cmd
os.system(cmd)
	
