Skip to content

Commit

Permalink
gaia: Do not assume .sdf file extension in C and Fortran code
Browse files Browse the repository at this point in the history
DAT_PAR/dat_par.h defines the .sdf extension.

Note that this does not fix the TCL code.
  • Loading branch information
timj committed Sep 2, 2014
1 parent 0f83c54 commit ed5ae8d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
9 changes: 7 additions & 2 deletions applications/gaia/gaia/generic/StarRtdImage.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
* Authors:
* P.W. Draper (PWD)
* Allan Brighton, ESO (ALLAN)
* Tim Jenness, Cornell University (TIMJ)
* Copyright:
* Copyright (C) 1997-2005 Central Laboratory of the Research Councils.
* Copyright (C) 2006-2007 Particle Physics & Astronomy Research Council.
* Copyright (C) 2008-2009 Science and Technology Facilities Council.
* Copyright (C) 2014 Cornell University.
* All Rights Reserved.
* Licence:
Expand Down Expand Up @@ -209,6 +211,8 @@
* 10-FEB-2010 (PWD):
* Added forcedegrees command. Sets whether to display decimal
* degrees for all celestial coordinate systems.
* 02-SEP-2014 (TIMJ):
* Use DAT__FLEXT rather than explicit ".sdf"
*-
*/
#if HAVE_CONFIG_H
Expand Down Expand Up @@ -256,6 +260,7 @@
#include "tcl_err.h"
extern "C" {
#include "ast_tclerr.h"
#include "dat_par.h"
}
#include "rtdDtrn.h"
#include "GaiaRtdRemote.h"
Expand Down Expand Up @@ -6203,9 +6208,9 @@ int StarRtdImage::parseName( const char *imagename, char **fullname,
// for a component name which should be after the ".sdf" string,
// but before the slice.
int found = 0;
char *sdf = strstr( *fullname, ".sdf" );
char *sdf = strstr( *fullname, DAT__FLEXT );
if ( sdf ) {
sdf += 4;
sdf += DAT__SZFLX;
if ( *sdf == '.' ) {
strcpy( *path, sdf );
*sdf = '\0';
Expand Down
28 changes: 16 additions & 12 deletions applications/gaia/gaia/generic/gaiaNDF.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Copyright (C) 1995-2005 Central Laboratory of the Research Councils
* Copyright (C) 2006 Particle Physics & Astronomy Research Council
* Copyright (C) 2008 Science and Technology Facilities Council
* Copyright (C) 2014 Cornell University.
* All Rights Reserved.
* Licence:
Expand All @@ -39,6 +40,7 @@
* Authors:
* PWD: Peter W. Draper, Starlink - University of Durham
* TIMJ: Tim Jenness - Cornell University
* History:
* 18-JAN-1995 (PWD):
Expand All @@ -59,6 +61,8 @@
* (>MAXNDFNAME).
* 21-NOV-2005 (PWD):
* Changed to use public HDS C interface.
* 02-SEP-2014 (TIMJ):
* Use DAT__FLEXT rather than explicit ".sdf"
* {enter_changes_here}
*-
*/
Expand All @@ -81,6 +85,7 @@
#include "ems.h"
#include "merswrap.h"
#include "star/hds.h"
#include "dat_par.h"
#include "dat_err.h"
#include "ndf.h"
#include "gaiaNDF.h"
Expand Down Expand Up @@ -838,12 +843,12 @@ int gaiaInitMNDF( const char *name, int deepsearch, void **handle,
/* Not an NDF. May just be a HDS container name with NDFs at this
level. Need to parse down to a filename and an HDS path. */
filename = strdup( name );
path = strstr( filename, ".sdf" );
path = strstr( filename, DAT__FLEXT );
if ( path ) {
*path++ = ' '; /* Have ".sdf" in name, cut it out. */
*path++ = ' ';
*path++ = ' ';
*path++ = ' ';
int i;
for ( i = 0; i < DAT__SZFLX; i++ ) {
*path++ = ' '; /* Have ".sdf" in name, cut it out. */
}
}
path = strrchr( filename, '/' ); /* Last / in name */
if ( ! path ) {
Expand Down Expand Up @@ -1029,7 +1034,7 @@ NDFinfo *traceMNDFs( NDFinfo **headptr, HDSLoc *baseloc, int baseid,
hdsTrace( newloc, &level, ndfpath, ndffile, &status,
MAXNDFNAME, MAXNDFNAME );

ftype = strstr( ndffile, ".sdf" ); /* Strip .sdf from filename */
ftype = strstr( ndffile, DAT__FLEXT ); /* Strip .sdf from filename */
if ( ftype ) *ftype = '\0';

path = strstr( ndfpath, "." ); /* Now find first component */
Expand Down Expand Up @@ -2089,12 +2094,11 @@ int gaiaNDFFindChild( const char *name, int *ndfid, char **error_mess )

/* Need to parse down to a filename and an HDS path. */
filename = strdup( name );
path = strstr( filename, ".sdf" );
path = strstr( filename, DAT__FLEXT );
if ( path ) {
*path++ = ' '; /* Have ".sdf" in name, cut it out. */
*path++ = ' ';
*path++ = ' ';
*path++ = ' ';
for ( i = 0; i < DAT__SZFLX; i++ ) {
*path++ = ' '; /* Have ".sdf" in name, cut it out. */
}
}
path = strrchr( filename, '/' ); /* Last / in name */
if ( ! path ) {
Expand Down Expand Up @@ -2130,7 +2134,7 @@ int gaiaNDFFindChild( const char *name, int *ndfid, char **error_mess )
hdsTrace( newloc, &level, ndfpath, ndffile, &status,
MAXNDFNAME, MAXNDFNAME );

ftype = strstr( ndffile, ".sdf" ); /* Strip .sdf from filename */
ftype = strstr( ndffile, DAT__FLEXT ); /* Strip .sdf from filename */
if ( ftype ) *ftype = '\0';

path = strstr( ndfpath, "." ); /* Now find first component */
Expand Down
14 changes: 9 additions & 5 deletions applications/gaia/gaia/generic/rtd_rdndf.f
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ SUBROUTINE RTD_RDNDF( NAME, TYPE, ID, NX, NY, IPHEAD, NHEAD,
* Copyright (C) 1998-2001 Central Laboratory of the Research Councils
* Copyright (C) 2006 Particle Physics & Astronomy Research Council.
* Copyright (C) 2012 Science and Technology Facilities Council.
* Copyright (C) 2014 Cornell University
* All Rights Reserved.

* Licence:
Expand All @@ -84,6 +85,7 @@ SUBROUTINE RTD_RDNDF( NAME, TYPE, ID, NX, NY, IPHEAD, NHEAD,

* Authors:
* PWD: Peter Draper (STARLINK - Durham University)
* TIMJ: Tim Jenness (Cornell University)
* {enter_new_authors_here}

* History:
Expand Down Expand Up @@ -113,6 +115,8 @@ SUBROUTINE RTD_RDNDF( NAME, TYPE, ID, NX, NY, IPHEAD, NHEAD,
* Now supports _DOUBLE directly.
* 17-MAY-2012 (PWD):
* Add long integer (_INT64) support.
* 02-SEP-2014 (TIMJ):
* Use DAT__FLEXT rather than explicit .sdf
* {enter_changes_here}

* Bugs:
Expand Down Expand Up @@ -152,7 +156,7 @@ SUBROUTINE RTD_RDNDF( NAME, TYPE, ID, NX, NY, IPHEAD, NHEAD,
INTEGER AVAIL ! Number of cards available in header
INTEGER DIM( NDF__MXDIM ) ! NDF dimensions
INTEGER I ! Loop variable
INTEGER IAT ! Position of .sdf in name
INTEGER IAT ! Position of file extension in name
INTEGER NAMLEN ! Length of name string
INTEGER NDIM ! Number of NDF dimensions
INTEGER PLACE ! NDF placeholder (not used)
Expand All @@ -166,14 +170,14 @@ SUBROUTINE RTD_RDNDF( NAME, TYPE, ID, NX, NY, IPHEAD, NHEAD,
* Remove the .sdf part of the name (if it exists), being careful to
* retain the slice information.
NAMLEN = CHR_LEN( NAME )
IAT = INDEX( NAME, '.sdf' )
IAT = INDEX( NAME, DAT__FLEXT )
IF ( IAT .NE. 0 ) THEN

* Special case is .sdf.something (like a compressed foreign
* datatype). Need to preserve the whole name in this case.
IF ( INDEX( NAME, '.sdf.' ) .EQ. 0 ) THEN
DO 1 I = IAT, MAX( IAT + 4, NAMLEN - 4 )
NAME( I : I ) = NAME( I + 4 : I + 4 )
IF ( INDEX( NAME, DAT__FLEXT ) .EQ. 0 ) THEN
DO 1 I = IAT, MAX( IAT + DAT__SZFLX, NAMLEN - DAT__SZFLX )
NAME( I : I ) = NAME( I + DAT__SZFLX : I + DAT__SZFLX )
1 CONTINUE
NAME( I : ) = ' '
IAT = I
Expand Down
8 changes: 6 additions & 2 deletions applications/gaia/gaia/generic/rtd_wrndf.f
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ SUBROUTINE RTD_WRNDF( NAME, TYPE, ID, IP, NX, NY, COMP, HEAD,

* Authors:
* PWD: Peter Draper (STARLINK - Durham University)
* TIMJ: Tim Jenness (Cornell University)
* {enter_new_authors_here}

* Copyright:
* Copyright (C) 1997 Central Laboratory of the Research Councils
* Copyright (C) 2006 Particle Physics & Astronomy Research Council.
* Copyright (C) 2014 Cornell University
* All Rights Reserved.

* Licence:
Expand Down Expand Up @@ -97,6 +99,8 @@ SUBROUTINE RTD_WRNDF( NAME, TYPE, ID, IP, NX, NY, COMP, HEAD,
* Now supports _DOUBLE data directly rather than presuming _REAL.
* 02-SEP-2004 (PWD):
* Converted to use CNF_PVAL for pointers.
* 02-SEP-2014 (TIMJ):
* Use DAT__FLEXT rather than explicit .sdf
* {enter_changes_here}

* Bugs:
Expand Down Expand Up @@ -138,7 +142,7 @@ SUBROUTINE RTD_WRNDF( NAME, TYPE, ID, IP, NX, NY, COMP, HEAD,
CHARACTER * ( NDF__SZTYP ) DTYPE ! Type of NDF data array
INTEGER DIM( 1 ) ! Dimension of FITS extension
INTEGER EL ! Number of pixels in NDF
INTEGER IAT ! Position of .sdf in name
INTEGER IAT ! Position of file extension in name
INTEGER IDNEW ! Identifier of new NDF
INTEGER IERR ! Not used
INTEGER IPDAT ! Pointer to NDF data array
Expand All @@ -163,7 +167,7 @@ SUBROUTINE RTD_WRNDF( NAME, TYPE, ID, IP, NX, NY, COMP, HEAD,
CALL NDF_BEGIN

* Remove the .sdf part of the name (it if exists).
IAT = INDEX( NAME, '.sdf' )
IAT = INDEX( NAME, DAT__FLEXT )
IF ( IAT .EQ. 0 ) THEN
IAT = CHR_LEN( NAME )
ELSE
Expand Down

1 comment on commit ed5ae8d

@414412
Copy link

@414412 414412 commented on ed5ae8d Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is gaia for Starlink

Please sign in to comment.