implement N^2 calculation for CTD casts