
float rBuff[xyCount];

bestRMS   = 1.0e+16;
bestShift = integer(sMin);

for( iShift = sMin; iShift <= sMax; iShift += sStep )
   {
    thisShift = integer(iShift);

    (void) vvCopy( rBuff, aData, xyCount );
    (void) clShift( rBuff, xyCount, thisShift, 0 );
    (void) vsMult( rBuff, xyCount, pList[0] );
    (void) vvSub( rBuff, dList, xyCount );

    thisRMS = vRMS( rBuff, xyCount );

    if (thisRMS < bestRMS)
       {
        bestRMS = thisRMS;
        bestShift = thisShift;
       };
   }
    
(void) vvCopy( yList, aData, xyCount );
(void) clShift( yList, xyCount, bestShift, 0 );
(void) vsMult( yList, xyCount, pList[0] );

if (reportFlag)
   {
    (void) printf( "lshift %.0f scale %.4e RMS %.4e\n", bestShift, pList[0], bestRMS );
   };
