#include <stdio.h>
#include <stdlib.h>



typedef struct {

  double re;
  double im;

} complexd;



/*
static complexd *alloc_matrix(int sz)
{

  return malloc(sz*sz*sizeof(complexd));

}
*/

void   zgeev_(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*); 

void zeig(complexd *m, complexd *eigenvalues, complexd *eigenvectors,  int SIZE)
{
  
  complexd *w;
  complexd *vl=0;
  complexd *vr;
  complexd *WORK;
  complexd *RWORK;
  
  int ok; 
  char jobvl, jobvr; 
  int n, lda, ldvl, ldvr, lwork; 
  
  n=SIZE; 
  jobvl='N'; 
  jobvr='V'; 
  lda=SIZE; 
  ldvl=1;
  ldvr=SIZE; 
  lwork=4*SIZE; 
  
  w = eigenvalues; //malloc(SIZE*sizeof(complexd));
  vr = eigenvectors; //alloc_matrix(SIZE);

  WORK = malloc(4*SIZE*sizeof(complexd));
  RWORK = malloc(2*SIZE*sizeof(complexd));
  
  zgeev_(&jobvl, &jobvr, &n, m, &lda, w, vl, &ldvl, vr, &ldvr, WORK, &lwork, RWORK, &ok); 

  /*
  printf("eigs :\n");
  for(i=0;i<SIZE;i++) {
    printf("\t %d %10e %10e\n", i, w[i].re, w[i].im);
  }


  printf("first eigenvector :\n");
  for(i=0;i<SIZE;i++) {
    printf("\t %d %10e %10e\n", i, vl[i].re, vl[i].im);
  }
  */


  free(WORK);
  free(RWORK);

}

