Hi there!
I’m pretty sure this is an obvious error on my behalf, but I can’t figure it out for the life of me. Searching the forums didn’t do any good either. Anway, here goes:
I’m trying to diagonalise a matrix. So I’ve set up a ROOT macro to read the data and call J-P Moreau’s algorithm, provided as a C++ source file and some headers. My (not working) minimal example is as follows:
The Root macro, located in QLtest.c:[code]#include “vmblock.h”
void QLtest() {
gROOT->ProcessLine(".L vmblock.cxx+");
void *vmblock = NULL;
int N = 4;
// allocate memory for matrix A and vectors B, X, D (index 0 not used)
vmblock = vminit();
Z = (REAL **) vmalloc(vmblock, MATRIX, N+1, N+1);
D = (REAL *) vmalloc(vmblock, VEKTOR, N+1, 0);
E = (REAL *) vmalloc(vmblock, VEKTOR, N+1, 0);
if (! vmcomplete(vmblock))
LogError (“No Memory”, 0, FILE, LINE);
// define input symmetric matrix
Z[1][1]= 4.0; Z[1][2]=-2.0; Z[1][3]=-1.0; Z[1][4]= 0.0;
Z[2][1]=-2.0; Z[2][2]= 4.0; Z[2][3]= 0.0; Z[2][4]=-1.0;
Z[3][1]=-1.0; Z[3][2]= 0.0; Z[3][3]= 4.0; Z[3][4]=-2.0;
Z[4][1]= 0.0; Z[4][2]=-1.0; Z[4][3]=-2.0; Z[4][4]= 4.0;
free(vmblock);
}[/code]
Running ‘root -l QLtest.c’ yields Error: vminit() header declared but not defined QLtest.c:10:
This error can be cured by removing the #include “vmblock.h”, but if I do so, I lose the MATRIX and all kind of other defines (still, the vminit() works in this case). So what am I doing wrong? Any advice is greatly appreciated.
This is root ROOT 5.18/00b (branches/v5-18-00-patches@22563 running on ubuntu (10.04, IIRC).
Best wishes,
Rufus
Relevant parts of the algorithm, located in vmblock.cxx:[code]#include <malloc.h>
#include “basis.h”
#include “vmblock.h”
typedef struct VML /* Element of a vector/matrix list */
{
void vmzeiger; / pointer to the vector or matrix /
int typ; / kind of pointer: vector or matrix /
/ (possible values: VEKTOR, VVEKTOR, /
/ MATRIX, IMATRIX, /
/ MMATRIX, UMATRIX, /
/ PMATRIX) /
size_t groesse; / in the anchor element: the flag that /
/ indicates failed memory allocations; /
/ otherwise not used except for matrices /
/ where `groesse’ is “abused” to save /
/ the number of rows /
size_t spalten; / number of columns of matrices of /
/ points in R3 */
struct VML naechst; / pointer to next element in the list */
} vmltyp;
#define VMALLOC (vmltyp )malloc(sizeof(vmltyp)) / allocate memory /
/ for a new /
/ element of the /
/ list */
#define LISTE ((vmltyp )vmblock) / for abbreviation /
#define MAGIC 410 / used to mark a /
/ valid anchor /
/ element */
/--------------------------------------------------------------------/
void vminit / create an empty vector/matrix list …/
/.IX{vminit}/
(
void
) / address of list …*/
{
vmltyp liste; / pointer to anchor element of list */
if ((liste = VMALLOC) == NULL) /* allocate memory for the anchor /
return NULL; / unsuccessful? => report error /
liste->vmzeiger = NULL; / to make vmfree() error free /
liste->typ = MAGIC; / mark a valid anchor element /
liste->groesse = 0; / no lack of memory as yet /
liste->naechst = NULL; / no next element */
return (void *)liste;
}
…[/code]
The header file included in the above code, located in vmblock.h:[code]#ifndef VMBLOCK_H_INCLUDED
#define VMBLOCK_H_INCLUDED
#define VEKTOR 0 /* for a REAL vector /
#define VVEKTOR 1 / for a vector with elements /
/ of given size /
#define MATRIX 2 / for a REAL matrix /
#define IMATRIX 3 / for an int matrix */
#define MMATRIX 4 /* for a matrix of 4x4 matrices /
/ (with elements of type `mat4x4’) /
#define UMATRIX 5 / for a lower triangular matrix */
#define PMATRIX 6 /* for a matrix of points in R3 */
void vminit / create an empty vector/matrix list …/
(
void
); / address of list …*/
…
[/code]