float d[2*size], r[2*size], dr[2*size], rr[2*size];
float fR[2*size], fI[2*size], freq[2*size];

ii = integer( size/2 );

for( i = 0; i < size; i++ )
   {
    if (ii < 0) {ii = size - 1;};

    for( j = 0; j < size; j++ )
       {
        t     = 2.0*PI*i*j/size;
        fR[j] = cos( t );
        fI[j] = sin( t );
       }

    (void) vvCopy( d, rdata, size );
    (void) vvCopy( r, fR,    size );

    (void) vvCopyOff( d, idata, size, size, 0 );
    (void) vvCopyOff( r, fI,    size, size, 0 );

    (void) vvCopy( dr, d, 2*size );
    (void) vvCopy( rr, r, 2*size );

    (void) vvMult( dr, r, 2*size );
    (void) vvMult( rr, r, 2*size );

    top = vSum( dr, 2*size );
    bot = vSum( rr, 2*size );

    if (bot == 0.0)
       {
        scale = 0.0;
       }
    else
       {
        scale = top/bot;
       };

    (void) vsMult( r, 2*size, scale );
    (void) vvSub( r, d, 2*size );
    (void) vvMult( r, r, 2*size );

    sum = vSum( r, 2*size );

    freq[ii] = -sqrt( sum/(2*size) );

    ii--;
   }

(void) vvMult( rdata, rdata, size );
(void) vvMult( idata, idata, size );

sum    = vSum( rdata, size ) + vSum( idata, size );
offset = sqrt( sum/(size*2) );
 
(void) vvCopy( rdata, freq, size );
(void) vsAdd( freq, size, offset );
