Graphs and coding

Hello all,

I've been given the task to apply a correction to a data set. Basically I have four waves of: H2O, dD, d18O and d. For the first dataset I have used a polynomial function to apply the correction coinciding with H2O values 0 to 45 mmol mol-1. However I'm also required to perform a second correction which is only between 0 and 30 so I can compare the two. Furthermore, for the d18O dataset, I'm required to add a value of "9" to bring the data up to where it should be. The data is sorted by date-time, and I've had difficulties, sorting and unsorting data. Does anyone have a simple solution for this type of problem? I've supplied the code which I've been working on, but I'm not sure if it is the right/easiest direction to take. Any help would be very much appreciated!



Function ApplyCorrection()

Wave dD
Wave/D date

Duplicate/O dD, dD30
Duplicate/O dD_std1_av, H2O30
Duplicate/O d18O_std1_av
Duplicate/O/D date, date30
sort H2O30, H2O30, dD30, d18O30, date30

Duplicate/O/R=[0,1819] dD30, dDfirst
Duplicate/O/R=[(1819+1), 2931] dD30, dDsecond

//Apply correction to wi waves here
Wave dDfirst = dD_std1_av_Corrected
Wave W_coef = W_coef

// do this for dD and d18O
Make/O/N=(numpnts(dDfirst)) wcorrected = dDfirst - (W_coef[0]+W_coef[1]*H2O30+W_coef[2]*h2O30^2+ W_coef[3]*h2O30^3 + W_coef[4]*h2O30^4)//, (if d18O add 9)
Concatenate/O/KILL/NP {wcorrected, dDsecond}, dD30

Sort date, date, H2O30, dD30, d18O30

Make/O/N=(numpnts(H2O30)) dxs30 = dD30-8*d18O30

End Function