Hi !
I also use a structure with a field being an array of structures. I found a
solution which works for me. Hope this helps:
// here is my table of Structures
PCF_PAIR_INFO ppi = new PCF_PAIR_INFO();
PCF_PAIR_INFO[] ppis = (PCF_PAIR_INFO[])ppi.toArray(nbPairs);
// here I have a loop to init all the PCF_PAIR_INFO the way I want.
The PCF_PAIR_INFO class:
public class PCF_PAIR_INFO extends Structure {
public float distance;
//... all fields here
public float co_tail;
public PCF_PAIR_INFO(){}
public void init(float z1, float z2, float v1, float v2){
this.distance = Math.abs(z2-z1);
// filling every field here with this method.
this.co_tail = 0f;
write(); // this appears to be mandatory (I tried without...No success in
further steps).
}
}
Back to my main Java class:
PCF_DESCR pdescr = new PCF_DESCR(xxx, xxx, xxx, xxx, xxx, ppis[0].getPointer());
The PCF_DESCR class (the one with the nested structures):
public class PCF_DESCR extends Structure {
// xxx fields...
public Pointer pair;
npublic PCF_DESCR(){}
public PCF_DESCR(int xxx, int xxx, float xxx, int xxx, long xxx, Pointer p){
this.dimension = dim;
this.vario_type = vt;
this.missing_float = mf;
this.missing_int = mi;
this.nb_pairs = np;
this.pair = p;
}
}
So in fact I give PCF_DESCR a pointer to the first element of my PCF_PAIR_INFO[]
table (at least that is the way I understand it).
I finally use a PCF_DESCR as an input of a C function. As I have the C sources,
I put a good old fprinft in the C function before building the library: all
elements from my PCF_PAIR_INFO[] are perfectly transmitted to the C when I call
it from my Java code.
Cheers,
Sylvain.