/***/
/* bruk_ranceZ.M: Rance-mode gradient shuffling for Z-Axis. (Bruker) 
/***/

/* Process only every pair of planes, one real, one imaginary:  */

if (yLoc != 1)   
   {
    exit( 0 );
   };

if (!(zLoc % 2))
   {
    exit( 0 );
   };

float planeR[size*specnum*2], planeI[size*specnum*2];
float sumR[size], sumI[size], difR[size], difI[size];

(void) dReadB( inUnit, planeR, wordLen*size*specnum*2 );
(void) dReadB( inUnit, planeI, wordLen*size*specnum*2 );

offset = 0;

for( i = 0; i < specnum; i++ )
   {
    /* Move vectors from real and imaginary planes:                */

    (void) vvCopyOff( sumR, planeR, size, 0, offset );
    (void) vvCopyOff( sumI, planeR, size, 0, offset+size );
    (void) vvCopyOff( difR, planeI, size, 0, offset );
    (void) vvCopyOff( difI, planeI, size, 0, offset+size );

    /* Form adjusted sums and differences:                         */

    (void) vvCopy( rdata, sumR, size );
    (void) vvCopy( idata, sumI, size );

    (void) vvSub( sumR, difR, size );
    (void) vvSub( sumI, difI, size );
    (void) vvAdd( difR, rdata, size );
    (void) vvAdd( difI, idata, size );

    (void) vNeg( difI, size );   /* Alternative to 90 degree phase. */
    
    /* Insert adjusted vectors back into real and imaginary planes: */

    (void) vvCopyOff( planeR, sumR, size, offset,      0 );
    (void) vvCopyOff( planeR, sumI, size, offset+size, 0 );
    (void) vvCopyOff( planeI, difI, size, offset,      0 );
    (void) vvCopyOff( planeI, difR, size, offset+size, 0 );

    offset += 2*size;
   }

(void) dWrite( outUnit, planeR, wordLen*size*specnum*2 );
(void) dWrite( outUnit, planeI, wordLen*size*specnum*2 );
