diff --git a/ast.news b/ast.news index 83778b8c..97896c0a 100644 --- a/ast.news +++ b/ast.news @@ -35,6 +35,11 @@ extra argument that gives the number of values supplied in the arguments array. Note, any existing code that uses this method will need to be changed. +- The astSpecAdd (AST_SPECADD) method of the SpecMap class now include an +extra argument that gives the number of values supplied in the arguments +array. Note, any existing code that uses this method will need to be +changed. + - If the astMapRegion (AST_MAPREGION) method is used to map a Region into a new Frame that has fewer axes than the original Region, and if the inverse transformation of the supplied Mapping does not specify a value diff --git a/fspecmap.c b/fspecmap.c index e72a2f72..f96db73a 100644 --- a/fspecmap.c +++ b/fspecmap.c @@ -74,18 +74,20 @@ F77_LOGICAL_FUNCTION(ast_isaspecmap)( INTEGER(THIS), F77_SUBROUTINE(ast_specadd)( INTEGER(THIS), CHARACTER(CVT), + INTEGER(NARG), DOUBLE_ARRAY(ARGS), INTEGER(STATUS) TRAIL(CVT) ) { GENPTR_INTEGER(THIS) GENPTR_CHARACTER(CVT) + GENPTR_INTEGER(NARG) GENPTR_DOUBLE_ARRAY(ARGS) char *cvt; astAt( "AST_SPECADD", NULL, 0 ); astWatchSTATUS( cvt = astString( CVT, CVT_length ); - astSpecAdd( astI2P( *THIS ), cvt, ARGS ); + astSpecAdd( astI2P( *THIS ), cvt, *NARG, ARGS ); astFree( cvt ); ) } diff --git a/specframe.c b/specframe.c index 137a69a6..eef06bac 100644 --- a/specframe.c +++ b/specframe.c @@ -832,22 +832,22 @@ static double ConvertSourceVel( AstSpecFrame *this, AstStdOfRestType newsor, /* Add a conversion from the spectral system in which the SourceVEl value is stored, to relativistic velocity. */ if( sys == AST__VRADIO ) { - astSpecAdd( specmap, "VRTOVL", NULL ); + astSpecAdd( specmap, "VRTOVL", 0, NULL ); } else if( sys == AST__VOPTICAL ) { - astSpecAdd( specmap, "VOTOVL", NULL ); + astSpecAdd( specmap, "VOTOVL", 0, NULL ); } else if( sys == AST__REDSHIFT ) { - astSpecAdd( specmap, "ZOTOVL", NULL ); + astSpecAdd( specmap, "ZOTOVL", 0, NULL ); } else if( sys == AST__BETA ) { - astSpecAdd( specmap, "BTTOVL", NULL ); + astSpecAdd( specmap, "BTTOVL", 0, NULL ); } /* Add a conversion from velocity to frequency since SorConvert converts frequencies. */ rf = astGetRestFreq( this ); - astSpecAdd( specmap, "VLTOFR", &rf ); + astSpecAdd( specmap, "VLTOFR", 1, &rf ); /* Now add a conversion from frequency in the SourveVRF standard of rest to frequency in the required rest frame. */ @@ -855,21 +855,21 @@ static double ConvertSourceVel( AstSpecFrame *this, AstStdOfRestType newsor, /* Add a conversion from frequency back to velocity. Note, the value of the rest frequency does not affect the overall conversion. */ - astSpecAdd( specmap, "FRTOVL", &rf ); + astSpecAdd( specmap, "FRTOVL", 1, &rf ); /* Add a conversion from relativistic velocity to the required spectral system, if needed. */ if( newsys == AST__VRADIO ) { - astSpecAdd( specmap, "VLTOVR", NULL ); + astSpecAdd( specmap, "VLTOVR", 0, NULL ); } else if( newsys == AST__VOPTICAL ) { - astSpecAdd( specmap, "VLTOVO", NULL ); + astSpecAdd( specmap, "VLTOVO",0, NULL ); } else if( newsys == AST__REDSHIFT ) { - astSpecAdd( specmap, "VLTOZO", NULL ); + astSpecAdd( specmap, "VLTOZO",0, NULL ); } else if( newsys == AST__BETA ) { - astSpecAdd( specmap, "VLTOBT", NULL ); + astSpecAdd( specmap, "VLTOBT",0, NULL ); } /* Use the SpecMap to convert the source velocity in the SourceVRF @@ -2612,11 +2612,11 @@ static int MakeSpecMapping( AstSpecFrame *target, AstSpecFrame *result, astSpecAdd. The macros differ in the number of additional argument values. */ #define TRANSFORM_0(cvt) \ - astSpecAdd( specmap, cvt, NULL ); + astSpecAdd( specmap, cvt, 0, NULL ); #define TRANSFORM_1(cvt,arg0) \ args[ 0 ] = arg0; \ - astSpecAdd( specmap, cvt, args ); + astSpecAdd( specmap, cvt, 1, args ); /* Get all the necessary attributes from the result, target and alignment Frames. */ @@ -4305,13 +4305,13 @@ static int SorConvert( AstSpecFrame *this, AstSpecFrame *that, #define TRANSFORM_2(cvt,arg0,arg1) \ args[ 0 ] = arg0; \ args[ 1 ] = arg1; \ - astSpecAdd( specmap, cvt, args ); + astSpecAdd( specmap, cvt, 2, args ); #define TRANSFORM_3(cvt,arg0,arg1,arg2) \ args[ 0 ] = arg0; \ args[ 1 ] = arg1; \ args[ 2 ] = arg2; \ - astSpecAdd( specmap, cvt, args ); + astSpecAdd( specmap, cvt, 3, args ); #define TRANSFORM_6(cvt,arg0,arg1,arg2,arg3,arg4,arg5) \ args[ 0 ] = arg0; \ @@ -4320,7 +4320,7 @@ static int SorConvert( AstSpecFrame *this, AstSpecFrame *that, args[ 3 ] = arg3; \ args[ 4 ] = arg4; \ args[ 5 ] = arg5; \ - astSpecAdd( specmap, cvt, args ); + astSpecAdd( specmap, cvt, 6, args ); /* A string for use in error messages. */ vmess = "convert between different standards of rest"; diff --git a/specmap.c b/specmap.c index 164179aa..48ada4ee 100644 --- a/specmap.c +++ b/specmap.c @@ -105,6 +105,9 @@ f - AST_SPECADD: Add a spectral coordinate conversion to an SpecMap * classes. * 2-OCT-2012 (DSB): * Check for Infs as well as NaNs. +* 1-DEC-2016 (DSB): +* Added a "narg" argumeent to astSpecAdd. + *class-- */ @@ -274,11 +277,11 @@ static int Equal( AstObject *, AstObject *, int * ); static int FrameChange( int, int, double *, double *, double *, double *, int, int * ); static int MapMerge( AstMapping *, int, int, int *, AstMapping ***, int **, int * ); static int SystemChange( int, int, double *, double *, int, int * ); -static void AddSpecCvt( AstSpecMap *, int, const double *, int * ); +static void AddSpecCvt( AstSpecMap *, int, int, const double *, int * ); static void Copy( const AstObject *, AstObject *, int * ); static void Delete( AstObject *, int * ); static void Dump( AstObject *, AstChannel *, int * ); -static void SpecAdd( AstSpecMap *, const char *, const double[], int * ); +static void SpecAdd( AstSpecMap *, const char *, int, const double[], int * ); static int GetObjSize( AstObject *, int * ); /* Member functions. */ @@ -468,7 +471,8 @@ static int GetObjSize( AstObject *this_object, int *status ) { return result; } -static void AddSpecCvt( AstSpecMap *this, int cvttype, const double *args, int *status ) { +static void AddSpecCvt( AstSpecMap *this, int cvttype, int narg, + const double *args, int *status ) { /* * Name: * AddSpecCvt @@ -481,7 +485,8 @@ static void AddSpecCvt( AstSpecMap *this, int cvttype, const double *args, int * * Synopsis: * #include "specmap.h" -* void AddSpecCvt( AstSpecMap *this, int cvttype, const double *args ) +* void AddSpecCvt( AstSpecMap *this, int cvttype, int narg, +* const double *args ) * Class Membership: * SpecMap member function. @@ -504,6 +509,8 @@ static void AddSpecCvt( AstSpecMap *this, int cvttype, const double *args, int * * A code to identify which spectral coordinate conversion is to be * appended. See the "Coordinate Conversions" section for details * of those available. +* narg +* The number of argument values supplied in "args". * args * Pointer to an array of double containing the argument values * required to fully specify the required coordinate @@ -659,6 +666,13 @@ static void AddSpecCvt( AstSpecMap *this, int cvttype, const double *args, int * (int) cvttype ); } +/* If the number of supplied arguments is incorrect, then report an error. */ + if ( astOK && nargs != narg ) { + astError( AST__TIMIN, "AddSpecCvt(%s): Invalid no. of arguments for spectral " + "coordinate conversion type %d - %d supplied, %d required.", + status, astGetClass( this ), (int) cvttype, narg, nargs ); + } + /* Note the number of coordinate conversions already stored in the SpecMap. */ if ( astOK ) { ncvt = this->ncvt; @@ -2208,7 +2222,8 @@ static int MapMerge( AstMapping *this, int where, int series, int *nmap, double (*cvtargs)[ MAX_ARGS ]; /* Pointer to argument arrays */ double tmp; /* Temporary storage */ int *cvttype; /* Pointer to transformation type codes */ - int *szarg; /* Pointer to argument count array */ + int *narg; /* Pointer to argument count */ + int *szarg; /* Pointer to argument array size */ int argdec; /* Index of DEC argument */ int argra; /* Index of RA argument */ int done; /* Finished (no further simplification)? */ @@ -2224,7 +2239,6 @@ static int MapMerge( AstMapping *this, int where, int series, int *nmap, int invert; /* SpecMap applied in inverse direction? */ int istep; /* Loop counter for transformation steps */ int keep; /* Keep transformation step? */ - int narg; /* Number of user-supplied arguments */ int ngone; /* Number of Mappings eliminated */ int nin; /* Numbr of axes for SpecMaps being merged */ int nstep0; /* Original number of transformation steps */ @@ -2281,6 +2295,7 @@ static int MapMerge( AstMapping *this, int where, int series, int *nmap, cvttype = astMalloc( sizeof( int ) * (size_t) nstep ); cvtargs = astMalloc( sizeof( double[ MAX_ARGS ] ) * (size_t) nstep ); szarg = astMalloc( sizeof( int ) * (size_t) nstep ); + narg = astMalloc( sizeof( int ) * (size_t) nstep ); /* Loop to obtain the transformation data for each SpecMap being merged. */ nstep = 0; @@ -2305,7 +2320,7 @@ static int MapMerge( AstMapping *this, int where, int series, int *nmap, the associated number of arguments. Then store these arguments. */ cvttype[ nstep ] = specmap->cvttype[ icvt ]; (void) CvtString( cvttype[ nstep ], &comment, &argra, &argdec, - &narg, szarg + nstep, argdesc, status ); + narg + nstep, szarg + nstep, argdesc, status ); if ( !astOK ) break; for ( iarg = 0; iarg < szarg[ nstep ]; iarg++ ) { cvtargs[ nstep ][ iarg ] = specmap->cvtargs[ icvt ][ iarg ]; @@ -2517,6 +2532,7 @@ static int MapMerge( AstMapping *this, int where, int series, int *nmap, cvtargs[ ikeep ][ iarg ] = cvtargs[ istep ][ iarg ]; } szarg[ ikeep ] = szarg[ istep ]; + narg[ ikeep ] = narg[ istep ]; } } } @@ -2563,7 +2579,7 @@ static int MapMerge( AstMapping *this, int where, int series, int *nmap, new = (AstMapping *) astSpecMap( nin, 0, "", status ); for ( istep = 0; istep < nstep; istep++ ) { AddSpecCvt( (AstSpecMap *) new, cvttype[ istep ], - cvtargs[ istep ], status ); + narg[ istep ], cvtargs[ istep ], status ); } } @@ -2605,6 +2621,7 @@ static int MapMerge( AstMapping *this, int where, int series, int *nmap, cvttype = astFree( cvttype ); cvtargs = astFree( cvtargs ); szarg = astFree( szarg ); + narg = astFree( narg ); } /* If an error occurred, clear the returned value. */ @@ -2825,7 +2842,8 @@ static double Rverot( double phi, double h, double ra, double da, return -palDvdv( v, pv + 3 )*149.597870E6; } -static void SpecAdd( AstSpecMap *this, const char *cvt, const double args[], int *status ) { +static void SpecAdd( AstSpecMap *this, const char *cvt, int narg, + const double args[], int *status ) { /* *++ * Name: @@ -2840,8 +2858,9 @@ f AST_SPECADD * Synopsis: c #include "specmap.h" -c void astSpecAdd( AstSpecMap *this, const char *cvt, const double args[] ) -f CALL AST_SPECADD( THIS, CVT, ARGS, STATUS ) +c void astSpecAdd( AstSpecMap *this, const char *cvt, int narg, +c const double args[] ) +f CALL AST_SPECADD( THIS, CVT, NARG, ARGS, STATUS ) * Class Membership: * SpecMap method. @@ -2886,6 +2905,11 @@ f A character string which identifies the * spectral coordinate conversion to be added to the * SpecMap. See the "Available Conversions" section for details of * those available. +c narg +f NARG = INTEGER (Given) +* The number of argument values supplied in the +c "args" array. +f ARGS array. c args f ARGS( * ) = DOUBLE PRECISION (Given) * An array containing argument values for the spectral @@ -3029,7 +3053,7 @@ f these arguments should be given, via the ARGS array, in the } /* Add the new conversion to the SpecMap. */ - AddSpecCvt( this, cvttype, args, status ); + AddSpecCvt( this, cvttype, narg, args, status ); } static int SystemChange( int cvt_code, int np, double *values, double *args, @@ -4661,9 +4685,10 @@ AstSpecMap *astLoadSpecMap_( void *mem, size_t size, Note that the member function may not be the one defined here, as it may have been over-ridden by a derived class. However, it should still have the same interface. */ -void astSpecAdd_( AstSpecMap *this, const char *cvt, const double args[], int *status ) { +void astSpecAdd_( AstSpecMap *this, const char *cvt, int narg, + const double args[], int *status ) { if ( !astOK ) return; - (**astMEMBER(this,SpecMap,SpecAdd))( this, cvt, args, status ); + (**astMEMBER(this,SpecMap,SpecAdd))( this, cvt, narg, args, status ); } diff --git a/specmap.h b/specmap.h index ac2319ae..d266ba13 100644 --- a/specmap.h +++ b/specmap.h @@ -95,12 +95,12 @@ * License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later * version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. -* +* * You should have received a copy of the GNU Lesser General * License along with this program. If not, see * . @@ -172,7 +172,7 @@ typedef struct AstSpecMapVtab { AstClassIdentifier id; /* Properties (e.g. methods) specific to this class. */ - void (* SpecAdd)( AstSpecMap *, const char *, const double[], int * ); + void (* SpecAdd)( AstSpecMap *, const char *, int, const double[], int * ); } AstSpecMapVtab; #if defined(THREAD_SAFE) @@ -224,7 +224,7 @@ AstSpecMap *astLoadSpecMap_( void *, size_t, AstSpecMapVtab *, /* Prototypes for member functions. */ /* -------------------------------- */ -void astSpecAdd_( AstSpecMap *, const char *, const double[], int * ); +void astSpecAdd_( AstSpecMap *, const char *, int, const double[], int * ); /* Function interfaces. */ /* ==================== */ @@ -271,8 +271,8 @@ astINVOKE(O,astLoadSpecMap_(mem,size,vtab,name,astCheckChannel(channel),STATUS_P /* Here we make use of astCheckSpecMap to validate SpecMap pointers before use. This provides a contextual error report if a pointer to the wrong sort of Object is supplied. */ -#define astSpecAdd(this,cvt,args) \ -astINVOKE(V,astSpecAdd_(astCheckSpecMap(this),cvt,args,STATUS_PTR)) +#define astSpecAdd(this,cvt,narg,args) \ +astINVOKE(V,astSpecAdd_(astCheckSpecMap(this),cvt,narg,args,STATUS_PTR)) #endif diff --git a/sun_master.tex b/sun_master.tex index cdb8897f..3bc3b312 100644 --- a/sun_master.tex +++ b/sun_master.tex @@ -21734,6 +21734,16 @@ \subsection{\xlabel{changes}\xlabel{list_of_most_recent_changes}Changes number of values supplied in the arguments array. Note, any existing code that uses this method will need to be changed. +f+ +\item The AST\_SPECADD +f- +c+ +\item The astSpecAdd +c- +method of the SpecMap class now include an extra argument that gives the +number of values supplied in the arguments array. Note, any existing code +that uses this method will need to be changed. + \item Multiple identical NormMaps in series will now be simplified to a single NormMap.