def file_is_not_old_seplib_cmplx(f_nm): 'Checks if a file has esize=8 and data_format=xdr_float' esize = sf.get(f_nm, 'esize') data_format = sf.get(f_nm, 'data_format') if esize == '8' and data_format == 'xdr_float': return False else: return True
def main(par): f_nm = par.string('file') # Name of file to process preserve_t = par.bool('preserve_t', True) # Whether to preserve timestamp verb = par.bool('verb', False) # Say if file was converted or unchanged ivlad.chk_file_r(f_nm) if file_is_not_old_seplib_cmplx(f_nm): ivlad.msg(f_nm + ': Conversion not necessary', verb) return ivlad.unix_success if not os.access(f_nm, os.W_OK): # Not using an exception because this program may be called on long # lists of files ivlad.msg(f_nm + ': NEED WRITE PERMISSION', True) return ivlad.unix_error if preserve_t: tstamp = get_timestamp(f_nm) bptr = sf.get(f_nm, 'in') # Pointer to binary if bptr == 'stdin': # Header and binary in a single file __replace_last_dataformat_statement(f_nm) else: f = open(f_nm, 'a') f.write('\n'+ooio.first_line_rsf_hdr_entry()) f.write('\tdata_format="xdr_complex"\n') f.close() if preserve_t: os.utime(f_nm, tstamp) ivlad.msg(f_nm + ': Converted', verb) return ivlad.unix_success