static PyObject* pydat_ncomp(HDSObject *self) { // Recover C-pointer passed via Python HDSLoc* loc = HDS_retrieve_locator(self); int status = SAI__OK, ncomp; errBegin(&status); datNcomp(loc, &ncomp, &status); if (raiseHDSException(&status)) return NULL; return Py_BuildValue("i", ncomp); };
void smf_ext2km( int indf, const char *xname, AstKeyMap *keymap, int mode, int *status ){ /* Local Variables */ HDSLoc *cloc = NULL; HDSLoc *sloc = NULL; HDSLoc *xloc = NULL; const char *key = NULL; hdsdim diml[NDF__MXDIM]; hdsdim dimu[NDF__MXDIM]; int dim[ NDF__MXDIM ]; int i; int idim; int lbnd[ NDF__MXDIM ]; int ncomp; int ndim; int nentry; int ntime = 0; int prim; int there; int ubnd[ NDF__MXDIM ]; /* Check the inherited status */ if( *status != SAI__OK ) return; /* Get the shape of the NDF. */ ndfBound( indf, 3, lbnd, ubnd, &ndim, status ); /* Get a locator to the named extension. */ ndfXloc( indf, xname, "READ", &xloc, status ); /* Select the name of the prototype component that determines the length of the arrays to be copied. */ if( !strcmp( xname, "JCMTSTATE" ) ) { key = "RTS_NUM"; } else if( !strcmp( xname, "ACSIS" ) ) { key = "TSYS"; } else { cloc = NULL; msgSetc( "X", xname ); errRep( "", "smf_ext2km: Unknown extension specified - '^X'. " "Must be 'JCMTSTATE' or 'ACSIS'.", status ); } /* Check the prorotype component is present in the extension. Report an error if not. */ datThere( xloc, key, &there, status ); if( !there && *status == SAI__OK ) { msgSetc( "C", key ); msgSetc( "X", xname ); errRep( "", "smf_ext2km: Component '^C' not found in extension " "^X", status ); /* If it is present, get the length of its last pixel axis. This is the length of the arrays to be copied. */ } else { datFind( xloc, key, &cloc, status ); datShape( cloc, NDF__MXDIM, dim, &ndim, status ); ntime = dim[ ndim - 1 ]; datAnnul( &cloc, status ); } /* First deal with mode 1... */ /* ========================= */ if( mode == 1 ) { /* Loop round every component in the extension. */ datNcomp( xloc, &ncomp, status ); for( i = 1; i <= ncomp; i++ ) { datIndex( xloc, i, &cloc, status ); /* Check the component has primitive values. */ datPrim( cloc, &prim, status ); if( prim ) { /* Get the shape of the component. */ datShape( cloc, NDF__MXDIM, dim, &ndim, status ); /* Skip over this component if the length of its final axis is not equal to the expected number of time slices. */ if( ndim > 0 && dim[ ndim - 1 ] == ntime ) { /* Also skip if we are dealing with the ACSIS extension and the array has only 1 (or zero) axes. */ if( ndim > 1 || strcmp( xname, "ACSIS" ) ) { /* Cut a section from the HDS array so that it matches the pixel bounds of the NDF . */ for( idim = 0; idim < ndim - 1; idim++ ) { diml[ idim ] = 1; dimu[ idim ] = dim[ idim ]; } diml[ idim ] = lbnd[ 2 ]; dimu[ idim ] = ubnd[ 2 ]; datSlice( cloc, ndim, diml, dimu, &sloc, status ); /* Store the values as a new entry in "keymap". */ kpg1Hdsky( sloc, keymap, 2, 1, status ); /* Annul the locator for the slice. */ datAnnul( &sloc, status ); } } } datAnnul( &cloc, status ); } /* Now deal with mode 2... */ /* ========================= */ } else if( mode == 2 ) { /* Loop round every entry in the KeyMap. */ nentry = astMapSize( keymap ); for( i = 0; i < nentry; i++ ) { key = astMapKey( keymap, i ); /* See if the supplied extension has a component with the same name. */ datThere( xloc, key, &there, status ); /* If it did, check the component is primitive. */ if( there && *status == SAI__OK ) { datFind( xloc, key, &cloc, status ); datPrim( cloc, &prim, status ); if( prim ) { /* Check the final axis of the primitive array has a length equal to the expected number of time slices. */ datShape( cloc, NDF__MXDIM, dim, &ndim, status ); if( ndim > 0 && dim[ ndim - 1 ] == ntime ) { /* Also skip if we are dealing with the ACSIS extension and the array has only 1 (or zero) axes. */ if( ndim > 1 || strcmp( xname, "ACSIS" ) ) { /* Cut a section from the HDS array so that it matches the pixel bounds of the NDF . */ for( idim = 0; idim < ndim - 1; idim++ ) { diml[ idim ] = 1; dimu[ idim ] = dim[ idim ]; } diml[ idim ] = lbnd[ 2 ]; dimu[ idim ] = ubnd[ 2 ]; datSlice( cloc, ndim, diml, dimu, &sloc, status ); /* Append the values to the end of the existing KeyMap entry. */ kpg1Hdsky( sloc, keymap, 1, 3, status ); /* Annul the locator for the slice. */ datAnnul( &sloc, status ); } } else if( *status == SAI__OK ) { *status = SAI__ERROR; msgSetc( "X", xname ); msgSetc( "K", key ); ndfMsg( "F", indf ); errRep( "", "The ^X.^K array has an unexpected shape in " "\"^F\".", status ); } } else if( *status == SAI__OK ) { *status = SAI__ERROR; msgSetc( "X", xname ); msgSetc( "K", key ); ndfMsg( "F", indf ); errRep( "", "The ^X.^K array has an unexpected data type in " "\"^F\".", status ); } datAnnul( &cloc, status ); } else if( *status == SAI__OK ) { *status = SAI__ERROR; msgSetc( "X", xname ); msgSetc( "K", key ); ndfMsg( "F", indf ); errRep( "", "The ^X.^K array is missing in \"^F\".", status ); } } /* Now tidy up. */ /* ============ */ /* Report an error if the "mode" value was illegal. */ } else if( *status == SAI__OK ) { *status = SAI__ERROR; msgSeti( "MODE", mode ); errRep( "", "smf_ext2km: Illegal value (^MODE) supplied for " "argument MODE (programming error).", status ); } /* Free resources. */ datAnnul( &xloc, status ); }