/***/
/* se.M: sensitivity enhancement shuffling macro;
/*       produces two complex 1D output vectors for
/*       each group of four complex 1D input vectors.
/***/

/***/
/* Initialization steps:
/*  ARGS: extract summation or difference mode.
/*  INIT: update header to reflect reduced number of 1D vectors.
/***/

if (sliceCode == CODE_ARGS)
   {
    difFlag = argTest( "-dif" );

    if (difFlag)
       {
        (void) printf( "SE Difference Mode.\n" );
       }
    else
       {
        (void) printf( "SE Summation Mode.\n" );
       };
   };

if (sliceCode == CODE_INIT)
   {
    (void) setParm( fdata, NDSIZE, integer( specnum/2 ), CUR_YDIM ); 
   };

if (sliceCode < 1)
   {
    exit( 0 ); 
   };

/***/
/* Process only every group of 4 complex 1D slices:
/***/

if (sliceCode % 4)
   {
    exit( 0 );
   };

float f1R[size], f1I[size], f2R[size], f2I[size],
      f3R[size], f3I[size], f4R[size], f4I[size];

float a1R[size], a1I[size], a2R[size], a2I[size],
      a3R[size], a3I[size], a4R[size], a4I[size];

(void) dReadB( inUnit, f1R, wordLen*size );
(void) dReadB( inUnit, f1I, wordLen*size );

(void) dReadB( inUnit, f2R, wordLen*size );
(void) dReadB( inUnit, f2I, wordLen*size );

(void) dReadB( inUnit, f3R, wordLen*size );
(void) dReadB( inUnit, f3I, wordLen*size );

(void) dReadB( inUnit, f4R, wordLen*size );
(void) dReadB( inUnit, f4I, wordLen*size );

/***/
/* a1 = f1 + f2
/* a2 = f1 - f2
/* a3 = f3 + f4
/* a4 = f3 - f4
/*
/* 90 degree phase corrections:
/*  swap a2R and a2I, then negate a2I for for 90 phase in t2
/*  swap a4R and a4I, then negate a4I for for 90 phase in t2
/*  swap a2 and a4, then negate a2, for (90) phase in t1
/*
/* form sum or diff: 
/*   f1 = a2 - a1 OR a2 + a1
/*   f2 = a4 - a3 OR a4 - a3
/***/

(void) vvCopy( a1R, f1R, size );
(void) vvCopy( a1I, f1I, size );
(void) vvAdd( a1R, f2R, size );
(void) vvAdd( a1I, f2I, size );

(void) vvCopy( a2R, f1R, size );
(void) vvCopy( a2I, f1I, size );
(void) vvSub( a2R, f2R, size );
(void) vvSub( a2I, f2I, size );

(void) vvCopy( a3R, f3R, size );
(void) vvCopy( a3I, f3I, size );
(void) vvAdd( a3R, f4R, size );
(void) vvAdd( a3I, f4I, size );

(void) vvCopy( a4R, f3R, size );
(void) vvCopy( a4I, f3I, size );
(void) vvSub( a4R, f4R, size );
(void) vvSub( a4I, f4I, size );

(void) vvSwap( a2R, a2I, size );
(void) vNeg( a2I, size );

(void) vvSwap( a4R, a4I, size );
(void) vNeg( a4I, size );

(void) vvSwap( a2R, a4R, size );
(void) vvSwap( a2I, a4I, size );
(void) vNeg( a2R, size );
(void) vNeg( a2I, size );

if (difFlag)
   {
    (void) vvCopy( f1R, a2R, size );
    (void) vvCopy( f1I, a2I, size );
    (void) vvSub( f1R, a1R, size );
    (void) vvSub( f1I, a1I, size );

    (void) vvCopy( f2R, a4R, size );
    (void) vvCopy( f2I, a4I, size );
    (void) vvSub( f2R, a3R, size );
    (void) vvSub( f2I, a3I, size );
   }
else
   {
    (void) vvCopy( f1R, a2R, size );
    (void) vvCopy( f1I, a2I, size );
    (void) vvAdd( f1R, a1R, size );
    (void) vvAdd( f1I, a1I, size );

    (void) vvCopy( f2R, a4R, size );
    (void) vvCopy( f2I, a4I, size );
    (void) vvAdd( f2R, a3R, size );
    (void) vvAdd( f2I, a3I, size );
   };

(void) vvSwap( f1R, f2R, size );
(void) vvSwap( f1I, f2I, size );
(void) vNeg( f2R, size );
(void) vNeg( f2I, size );

(void) dWrite( outUnit, f1R, wordLen*size );
(void) dWrite( outUnit, f1I, wordLen*size );
(void) dWrite( outUnit, f2R, wordLen*size );
(void) dWrite( outUnit, f2I, wordLen*size );
