/** @file  tst_psMatrix_06.c
*
*  @brief Test driver for psMatrix Eigenvectors function
*
*  This test driver contains the following tests for psMatrix test point 6:
*     A)  Create input and output images
*     B)  Calculate Eigenvectors
*     C)  Free input and output images
*
*  @author  Ross Harman, MHPCC
*
*  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
*  @date  $Date: 2004-08-06 22:34:06 $
*
*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
*
*/

#include "pslib.h"
#include "psTest.h"

#define PRINT_MATRIX(IMAGE)                         \
for(int i=0; i<IMAGE->numRows; i++) {           \
    for(int j=0; j<IMAGE->numCols; j++) {       \
        printf("%f ", IMAGE->data.F64[i][j]);   \
    }                                          \
    printf("\n");                              \
}


int main( int argc,
          char* argv[] )
{
    psImage * outImage = NULL;
    psImage *inImage = NULL;


    // Test A - Create input and output images
    printPositiveTestHeader( stdout, "psMatrix", "Create input and output images" );
    outImage = ( psImage* ) psImageAlloc( 4, 4, PS_TYPE_F64 );
    inImage = ( psImage* ) psImageAlloc( 4, 4, PS_TYPE_F64 );

    inImage->data.F64[ 0 ][ 0 ] = 1. / 1.;
    inImage->data.F64[ 0 ][ 1 ] = 1. / 2.;
    inImage->data.F64[ 0 ][ 2 ] = 1. / 3.;
    inImage->data.F64[ 0 ][ 3 ] = 1. / 4.;

    inImage->data.F64[ 1 ][ 0 ] = 1. / 2.;
    inImage->data.F64[ 1 ][ 1 ] = 1. / 3.;
    inImage->data.F64[ 1 ][ 2 ] = 1. / 4.;
    inImage->data.F64[ 1 ][ 3 ] = 1. / 5.;

    inImage->data.F64[ 2 ][ 0 ] = 1. / 3.;
    inImage->data.F64[ 2 ][ 1 ] = 1. / 4.;
    inImage->data.F64[ 2 ][ 2 ] = 1. / 5.;
    inImage->data.F64[ 2 ][ 3 ] = 1. / 6.;

    inImage->data.F64[ 3 ][ 0 ] = 1. / 4.;
    inImage->data.F64[ 3 ][ 1 ] = 1. / 5.;
    inImage->data.F64[ 3 ][ 2 ] = 1. / 6.;
    inImage->data.F64[ 3 ][ 3 ] = 1. / 7.;

    PRINT_MATRIX( inImage );
    printFooter( stdout, "psMatrix", "Create input and output images", true );


    // Test B - Calculate Eigenvectors
    printPositiveTestHeader( stdout, "psMatrix", "Calculate Eigenvectors" );
    psMatrixEigenvectors( outImage, inImage );
    PRINT_MATRIX( outImage );
    printFooter( stdout, "psMatrix", "Calculate Eigenvectors", true );


    // Test C - Free input and output images
    printPositiveTestHeader( stdout, "psMatrix", "Free input and output images" );
    psFree( outImage );
    psFree( inImage );
    int nLeaks = psMemCheckLeaks( 0, NULL, stdout );
    if ( nLeaks != 0 ) {
        printf( "ERROR: Found %d memory leaks\n", nLeaks );
    }
    int nBad = psMemCheckCorruption( 0 );
    if ( nBad ) {
        printf( "ERROR: Found %d bad memory blocks\n", nBad );
    }
    printFooter( stdout, "psMatrix" , "Free input and output images", true );

    return 0;
}
