added QC and written data file for S inversion