On Wed, 7 Jun 2006, Edward Chapin wrote:
> I'm having some trouble taking an existing NDF with only a DATA component,
> and attempting to create a VARIANCE component. If I explain what I'm trying
> to do, maybe someone will have a clever suggestion...
>
> I have an input NDF, with a DATA component (whose dimensions happen to be 3d
> although it is not important - 1st two dimensions are x- and y- pixel
> coordinates for a camera, z- is a time axis). My goal is to create a new NDF
> with the same dimensions as the input, but including a VARIANCE component
> (and in the future QUALITY as well) to which I will write new values. I want
> to only ever open the input NDF with READ access and never modify its
> contents.
>
>
> 1. The input NDF is the element of a group. I create a copy of it doing the
> following:
>
> ndgNdfas( igrp, i, "READ", &indf, status );
> ndgNdfpr( indf, " ", ogrp, i, &ondf, status );
>
> ndfAnnul( &indf, status );
>
> 2. I then set parameters for the data and variance arrays and map them (I
> believe this will make the components "active" so that they are defined when
> I annul the output NDF):
>
> ndfStype( "_DOUBLE", ondf, "DATA", status );
> ndfStype( "_DOUBLE", ondf, "VARIANCE", status );
Hi Ed,
you don't need to call ndfStype, unless the data type of the output arrays
will be different from those of the NDF that you have propagated from.
> ndfMap( ondf, "DATA", "_DOUBLE", "WRITE", &(ptr[0]), &nmap, status );
> ndfMap( ondf, "VARIANCE", "_DOUBLE", "WRITE", &(ptr[1]), &nmap, status );
This should create the two components. You could initialise them to BAD or
ZERO using "WRITE/BAD" or "WRITE/ZERO", but that's not necessary.
> ndfAnnul( ondf );
Clearly this call is broken and should be "ndfAnnul( &ondf, status );",
I'll assume that's a transcription problem?
> Using this code no VARIANCE component seems to get created in ondf (verified
> with hdstrace). However, if in step #2 I compare ondf with and without the
> ndfStype/ndfMap for the VARIANCE component I get different file sizes, i.e.
> it seems to be allocating more space to accomodate the VARIANCE component but
> somehow it isn't getting stored properly?
Only the ndfMap should have an effect, when that's called the NDF should
be expanded to include space for the VARIANCE component.
> Another weird thing: I have gotten a nearly identical piece of code to this
> to work (in fact I'm not sure what the difference is - it is a much more
> complicated routine that does other things that don't appear to be related to
> this NDF copying...). Although it works, the code has a check for the total
> number of HDS locators at the start and finish of execution, and they're off
> by 1. I've tracked it down, and it seems that when the VARIANCE component is
> created in #2 by the ndfMap, the # of HDS locators increases by 1, but then
> it doesn't go down by the correct amount with the ndfAnnul.
>
> Either I'm using NDF incorrectly, or perhaps I've found a bug? (or both...)
>
> I did a fresh checkout yesterday, and I'm using 64bit Fedora Core 4. Any help
> would be greatly appreciated.
This is worrying, I've tried to re-create the problem using my machines
(64bit/SL4.2 & 32bit/FC5) and I don't see the problem. Tried various
combinations of input files (HDS4 and HDS3, with different data types) and
output files. Tim, does this sound like one of the outstanding HDS issues?
I've attached my test program to this message for you and anyone else to
try out. The link command is:
gcc -o ndf_ctest -I$STARCONF_DEFAULT_PREFIX/include ndf_ctest.c \
-L$STARCONF_DEFAULT_PREFIX/lib `ndf_link` `cnfrtl_link` `ndg_link` `grp_link`
It takes an NDF "frame.sdf" as input and creates an NDF "ndf_test.sdf".
Cheers,
Peter.
#include <stdio.h>
#include "sae_par.h"
#include "star/ndg.h"
#include "star/grp.h"
#include "star/hds.h"
#include "ndf.h"
int main( int argc, char *argv[] ) {
Grp *igrp;
Grp *ogrp;
int el;
int indf;
int ondf;
int status;
void *pntr;
status = SAI__OK;
cnfInitRTL( argc, argv );
ndfInit( argc, argv, &status );
igrp = grpNew( "IN", &status );
grpPut1( igrp, "frame", 1, &status );
ogrp = grpNew( "OUT", &status );
grpPut1( ogrp, "ndf_test", 1, &status );
ndgNdfas( igrp, 1, "READ", &indf, &status );
ndgNdfpr( indf, " ", ogrp, 1, &ondf, &status );
printf( "Both NDFs open\n" );
hdsShow( "FILES", &status );
ndfAnnul( &indf, &status );
ndfStype( "_REAL", ondf, "DATA", &status );
ndfStype( "_REAL", ondf, "VARIANCE", &status );
ndfMap( ondf, "DATA", "_REAL", "WRITE", &pntr, &el, &status );
ndfMap( ondf, "VARIANCE", "_REAL", "WRITE", &pntr, &el, &status );
printf( "Output NDF open\n" );
hdsShow( "FILES", &status );
ndfAnnul( &ondf, &status );
grpDelet( &igrp, &status );
grpDelet( &ogrp, &status );
printf( "Both NDFs closed\n" );
hdsShow( "FILES", &status );
return ( status != SAI__OK );
}
|