2008/7/16 Tim Jenness <[log in to unmask]>:
> If I call NDF_CLONE on an NDF that has previously mapped the data array, do
> I need to remap the data array for the new clone or is ndf_annul clever
> enough to not unmap the data array if there are remaining clones active? (so
> I can just copy the pointer of the mapped data array and associate it with
> the cloned identifier).
I thought I knew the answer to this - that ndf_annul would only unmap
the array when no remaining cloned NDF identifiers have the data array
mapped. But in practice this seems not to be the case.
In fortran, annulling an NDF identifier immediately causes CNF to
nullify the true C pointer associated with the corresponding fortran
integer, so CNF_PVAL returns NULL. This is perhaps to be expected.
But in C, ndfMap returns the true C pointer rather than a CNF
identifier, so you would expect the returned pointer to remain valid.
But experiment shows that it doesn't. The following program suffers a
segvio in the second call to "aaa":
#include "ndf.h"
#include <stdio.h>
void aaa( int n, float *d, int *status );
main(){
int status, indf, indf2, place, el;
void *ip;
status = 0;
ndfOpen( NULL, "fred", "Read", "Old", &indf, &place, &status );
ndfMap( indf, "Data", "_REAL", "Read", &ip, &el, &status );
aaa( el, (float *) ip, &status );
ndfClone( indf, &indf2, &status );
ndfAnnul( &indf, &status );
/* ndfMap( indf2, "Data", "_REAL", "Read", &ip, &el, &status );*/
aaa( el, (float *) ip, &status );
ndfAnnul( &indf2, &status );
}
void aaa( int n, float *d, int *status ){
if( *status != 0 ) return;
printf("%g %g\n", d[ 0 ], d[ n - 1 ] );
}
But if you uncomment the second call to ndfMap, it works.
You live and learn...
David
|