Indent qfits to GNU style, perhaps
parent
7621d31783
commit
db0415128c
File diff suppressed because it is too large
Load Diff
|
@ -66,14 +66,14 @@
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void * xmemory_malloc(size_t, const char *, int) ;
|
void *xmemory_malloc (size_t, const char *, int);
|
||||||
void * xmemory_calloc(size_t, size_t, const char *, int) ;
|
void *xmemory_calloc (size_t, size_t, const char *, int);
|
||||||
void * xmemory_realloc(void *, size_t, const char *, int) ;
|
void *xmemory_realloc (void *, size_t, const char *, int);
|
||||||
void xmemory_free(void *, const char *, int) ;
|
void xmemory_free (void *, const char *, int);
|
||||||
char * xmemory_strdup(const char *, const char *, int) ;
|
char *xmemory_strdup (const char *, const char *, int);
|
||||||
char * xmemory_falloc(char *, size_t, size_t *, const char *, int) ;
|
char *xmemory_falloc (char *, size_t, size_t *, const char *, int);
|
||||||
void xmemory_fdealloc(void *, size_t, size_t, const char *, int) ;
|
void xmemory_fdealloc (void *, size_t, size_t, const char *, int);
|
||||||
|
|
||||||
void xmemory_status_(const char * filename, int lineno) ;
|
void xmemory_status_ (const char *filename, int lineno);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -45,275 +45,307 @@
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void usage(char * pname) ;
|
void usage (char *pname);
|
||||||
void parse_cmd_line(int, char **, int *, int *, int *) ;
|
void parse_cmd_line (int, char **, int *, int *, int *);
|
||||||
int dump_fits_filter(FILE *, int) ;
|
int dump_fits_filter (FILE *, int);
|
||||||
int dump_fits(char *, int) ;
|
int dump_fits (char *, int);
|
||||||
char * rstrip(char *) ;
|
char *rstrip (char *);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int xtnum ;
|
int xtnum;
|
||||||
int c_arg ;
|
int c_arg;
|
||||||
int filter ;
|
int filter;
|
||||||
int err ;
|
int err;
|
||||||
|
|
||||||
/* No arguments prints out a usage message */
|
/* No arguments prints out a usage message */
|
||||||
if (argc<2) usage(argv[0]);
|
if (argc < 2)
|
||||||
|
usage (argv[0]);
|
||||||
|
|
||||||
/* Parse command-line options */
|
/* Parse command-line options */
|
||||||
parse_cmd_line(argc, argv, &xtnum, &filter, &c_arg);
|
parse_cmd_line (argc, argv, &xtnum, &filter, &c_arg);
|
||||||
|
|
||||||
/* Filter mode: process data received from stdin */
|
/* Filter mode: process data received from stdin */
|
||||||
if (filter) {
|
if (filter)
|
||||||
|
{
|
||||||
#if HAVE_ZLIB
|
#if HAVE_ZLIB
|
||||||
printf("filter mode does not support gzipped files\n");
|
printf ("filter mode does not support gzipped files\n");
|
||||||
printf("use: gunzip -c file.fits | dfits -\n");
|
printf ("use: gunzip -c file.fits | dfits -\n");
|
||||||
return 1 ;
|
return 1;
|
||||||
#else
|
#else
|
||||||
return dump_fits_filter(stdin, xtnum);
|
return dump_fits_filter (stdin, xtnum);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normal mode: loop on all file names given on command-line */
|
/* Normal mode: loop on all file names given on command-line */
|
||||||
err = 0 ;
|
err = 0;
|
||||||
while (c_arg < argc) {
|
while (c_arg < argc)
|
||||||
err += dump_fits(argv[c_arg], xtnum);
|
{
|
||||||
c_arg++;
|
err += dump_fits (argv[c_arg], xtnum);
|
||||||
}
|
c_arg++;
|
||||||
return err ; /* Returns number of errors during process */
|
}
|
||||||
|
return err; /* Returns number of errors during process */
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(char * pname)
|
void
|
||||||
|
usage (char *pname)
|
||||||
{
|
{
|
||||||
printf(
|
printf ("\n\n"
|
||||||
"\n\n"
|
"usage: %s [-x xtnum] <list of FITS files>\n"
|
||||||
"usage: %s [-x xtnum] <list of FITS files>\n"
|
"usage: %s [-x xtnum] -\n"
|
||||||
"usage: %s [-x xtnum] -\n"
|
"\n"
|
||||||
"\n"
|
"The former version expects file names.\n"
|
||||||
"The former version expects file names.\n"
|
"The latter expects data coming in from stdin.\n"
|
||||||
"The latter expects data coming in from stdin.\n"
|
"\n"
|
||||||
"\n"
|
"-x xtnum specifies the extension header to print\n"
|
||||||
"-x xtnum specifies the extension header to print\n"
|
"-x 0 specifies main header + all extensions\n"
|
||||||
"-x 0 specifies main header + all extensions\n"
|
"\n\n", pname, pname);
|
||||||
"\n\n",
|
|
||||||
pname, pname);
|
|
||||||
|
|
||||||
#if HAVE_ZLIB
|
#if HAVE_ZLIB
|
||||||
printf(
|
printf ("This program was compiled against zlib %s\n"
|
||||||
"This program was compiled against zlib %s\n"
|
"This means you can use it with gzipped FITS files\n"
|
||||||
"This means you can use it with gzipped FITS files\n"
|
"as with uncompressed FITS files.\n"
|
||||||
"as with uncompressed FITS files.\n"
|
"NB: this does not apply to the '-' option (input from stdin)\n"
|
||||||
"NB: this does not apply to the '-' option (input from stdin)\n"
|
"\n\n", ZLIB_VERSION);
|
||||||
"\n\n", ZLIB_VERSION);
|
|
||||||
#endif
|
#endif
|
||||||
exit(1) ;
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_cmd_line(
|
void
|
||||||
int argc,
|
parse_cmd_line (int argc, char **argv, int *xtnum, int *filter, int *c_arg)
|
||||||
char ** argv,
|
|
||||||
int * xtnum,
|
|
||||||
int * filter,
|
|
||||||
int * c_arg)
|
|
||||||
{
|
{
|
||||||
*filter = 0 ;
|
*filter = 0;
|
||||||
*xtnum = -1 ;
|
*xtnum = -1;
|
||||||
*c_arg = argc-1 ;
|
*c_arg = argc - 1;
|
||||||
|
|
||||||
/* If '-' is on the command-line, it must be the last argument */
|
/* If '-' is on the command-line, it must be the last argument */
|
||||||
if (!strcmp(argv[argc-1], "-")) *filter = 1 ;
|
if (!strcmp (argv[argc - 1], "-"))
|
||||||
/* If -x xtnum is on the command-line, it must be the first two arguments */
|
*filter = 1;
|
||||||
if (!strcmp(argv[1], "-x")) {
|
/* If -x xtnum is on the command-line, it must be the first two arguments */
|
||||||
*xtnum = atoi(argv[2]);
|
if (!strcmp (argv[1], "-x"))
|
||||||
*c_arg = 3 ;
|
{
|
||||||
} else {
|
*xtnum = atoi (argv[2]);
|
||||||
*c_arg = 1 ;
|
*c_arg = 3;
|
||||||
}
|
}
|
||||||
return ;
|
else
|
||||||
|
{
|
||||||
|
*c_arg = 1;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Strip off all blank characters in a string from the right-side. */
|
/* Strip off all blank characters in a string from the right-side. */
|
||||||
char * rstrip(char * s)
|
char *
|
||||||
|
rstrip (char *s)
|
||||||
{
|
{
|
||||||
int len ;
|
int len;
|
||||||
if (s==NULL) return s ;
|
if (s == NULL)
|
||||||
len = strlen(s);
|
return s;
|
||||||
if (len<1) return s ;
|
len = strlen (s);
|
||||||
len -- ;
|
if (len < 1)
|
||||||
while (s[len]== ' ') {
|
return s;
|
||||||
s[len]=(char)0 ;
|
len--;
|
||||||
len --;
|
while (s[len] == ' ')
|
||||||
if (len<0) break ;
|
{
|
||||||
|
s[len] = (char) 0;
|
||||||
|
len--;
|
||||||
|
if (len < 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return s ;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump the requested header (main or extension) from a filename. */
|
/* Dump the requested header (main or extension) from a filename. */
|
||||||
int dump_fits(char * name, int xtnum)
|
int
|
||||||
|
dump_fits (char *name, int xtnum)
|
||||||
{
|
{
|
||||||
FILE * in ;
|
FILE *in;
|
||||||
int err ;
|
int err;
|
||||||
|
|
||||||
if ((in=fopen(name, "r"))==NULL) {
|
if ((in = fopen (name, "r")) == NULL)
|
||||||
fprintf(stderr, "error: cannot open file [%s]\n", name);
|
{
|
||||||
return 1 ;
|
fprintf (stderr, "error: cannot open file [%s]\n", name);
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
printf("====> file %s (main) <====\n", name) ;
|
printf ("====> file %s (main) <====\n", name);
|
||||||
err = dump_fits_filter(in, xtnum);
|
err = dump_fits_filter (in, xtnum);
|
||||||
fclose(in);
|
fclose (in);
|
||||||
return err ;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump the requested header (main or extension) from a FILE * */
|
/* Dump the requested header (main or extension) from a FILE * */
|
||||||
int dump_fits_filter(FILE * in, int xtnum)
|
int
|
||||||
|
dump_fits_filter (FILE * in, int xtnum)
|
||||||
{
|
{
|
||||||
int n_xt ;
|
int n_xt;
|
||||||
char buf[LGTH+1];
|
char buf[LGTH + 1];
|
||||||
int err ;
|
int err;
|
||||||
int data_bytes, naxis ;
|
int data_bytes, naxis;
|
||||||
char * read_val ;
|
char *read_val;
|
||||||
int skip_blocks ;
|
int skip_blocks;
|
||||||
int seeked ;
|
int seeked;
|
||||||
|
|
||||||
/* Try getting the first 80 chars */
|
/* Try getting the first 80 chars */
|
||||||
memset(buf, 0, LGTH+1);
|
memset (buf, 0, LGTH + 1);
|
||||||
if (fread(buf, sizeof(char), LGTH, in)!=LGTH) {
|
if (fread (buf, sizeof (char), LGTH, in) != LGTH)
|
||||||
fprintf(stderr, "error reading input\n");
|
{
|
||||||
return 1;
|
fprintf (stderr, "error reading input\n");
|
||||||
}
|
return 1;
|
||||||
/* Check that it is indeed FITS */
|
}
|
||||||
if (strncmp(buf, MAGIC, strlen(MAGIC))) {
|
/* Check that it is indeed FITS */
|
||||||
fprintf(stderr, "not a FITS file\n");
|
if (strncmp (buf, MAGIC, strlen (MAGIC)))
|
||||||
return 1 ;
|
{
|
||||||
}
|
fprintf (stderr, "not a FITS file\n");
|
||||||
naxis = 0 ;
|
return 1;
|
||||||
data_bytes = 1 ;
|
}
|
||||||
if (xtnum<1) {
|
naxis = 0;
|
||||||
/* Output main header */
|
data_bytes = 1;
|
||||||
printf("%s\n", rstrip(buf));
|
if (xtnum < 1)
|
||||||
data_bytes = 1 ;
|
{
|
||||||
naxis = 0 ;
|
/* Output main header */
|
||||||
while ((err=fread(buf, sizeof(char), LGTH, in))==LGTH) {
|
printf ("%s\n", rstrip (buf));
|
||||||
printf("%s\n", rstrip(buf));
|
data_bytes = 1;
|
||||||
/* Look for BITPIX keyword */
|
naxis = 0;
|
||||||
if (buf[0]=='B' &&
|
while ((err = fread (buf, sizeof (char), LGTH, in)) == LGTH)
|
||||||
buf[1]=='I' &&
|
{
|
||||||
buf[2]=='T' &&
|
printf ("%s\n", rstrip (buf));
|
||||||
buf[3]=='P' &&
|
/* Look for BITPIX keyword */
|
||||||
buf[4]=='I' &&
|
if (buf[0] == 'B' &&
|
||||||
buf[5]=='X' &&
|
buf[1] == 'I' &&
|
||||||
buf[6]==' ') {
|
buf[2] == 'T' &&
|
||||||
read_val = qfits_getvalue(buf);
|
buf[3] == 'P' &&
|
||||||
data_bytes *= (int)atoi(read_val) / 8 ;
|
buf[4] == 'I' && buf[5] == 'X' && buf[6] == ' ')
|
||||||
if (data_bytes<0) data_bytes *= -1 ;
|
{
|
||||||
} else
|
read_val = qfits_getvalue (buf);
|
||||||
/* Look for NAXIS keyword */
|
data_bytes *= (int) atoi (read_val) / 8;
|
||||||
if (buf[0]=='N' &&
|
if (data_bytes < 0)
|
||||||
buf[1]=='A' &&
|
data_bytes *= -1;
|
||||||
buf[2]=='X' &&
|
}
|
||||||
buf[3]=='I' &&
|
else
|
||||||
buf[4]=='S') {
|
/* Look for NAXIS keyword */
|
||||||
|
if (buf[0] == 'N' &&
|
||||||
|
buf[1] == 'A' &&
|
||||||
|
buf[2] == 'X' && buf[3] == 'I' && buf[4] == 'S')
|
||||||
|
{
|
||||||
|
|
||||||
if (buf[5]==' ') {
|
if (buf[5] == ' ')
|
||||||
/* NAXIS keyword */
|
{
|
||||||
read_val = qfits_getvalue(buf);
|
/* NAXIS keyword */
|
||||||
naxis = (int)atoi(read_val);
|
read_val = qfits_getvalue (buf);
|
||||||
} else {
|
naxis = (int) atoi (read_val);
|
||||||
/* NAXIS?? keyword (axis size) */
|
|
||||||
read_val = qfits_getvalue(buf);
|
|
||||||
data_bytes *= (int)atoi(read_val);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
/* Look for END keyword */
|
|
||||||
if (buf[0]=='E' &&
|
|
||||||
buf[1]=='N' &&
|
|
||||||
buf[2]=='D') {
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (err!=LGTH) return 1 ;
|
else
|
||||||
}
|
{
|
||||||
if (xtnum<0) return 0 ;
|
/* NAXIS?? keyword (axis size) */
|
||||||
|
read_val = qfits_getvalue (buf);
|
||||||
n_xt=0 ;
|
data_bytes *= (int) atoi (read_val);
|
||||||
while (1) {
|
|
||||||
/*
|
|
||||||
* Skip the previous data section if pixels were declared
|
|
||||||
*/
|
|
||||||
if (naxis>0) {
|
|
||||||
/* Skip as many blocks as there are declared pixels */
|
|
||||||
skip_blocks = data_bytes/BLOCK_SIZE ;
|
|
||||||
if ((data_bytes % BLOCK_SIZE)!=0) skip_blocks ++ ;
|
|
||||||
seeked = fseek(in, skip_blocks*BLOCK_SIZE, SEEK_CUR);
|
|
||||||
if (seeked<0) return -1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Look for next XTENSION keyword */
|
|
||||||
while ((err=fread(buf, sizeof(char), LGTH, in))==LGTH) {
|
|
||||||
if (buf[0]=='X' &&
|
|
||||||
buf[1]=='T' &&
|
|
||||||
buf[2]=='E' &&
|
|
||||||
buf[3]=='N' &&
|
|
||||||
buf[4]=='S' &&
|
|
||||||
buf[5]=='I' &&
|
|
||||||
buf[6]=='O' &&
|
|
||||||
buf[7]=='N') break ;
|
|
||||||
}
|
}
|
||||||
if (err==0) break ;
|
}
|
||||||
if (err!=LGTH) return 1 ;
|
else
|
||||||
|
/* Look for END keyword */
|
||||||
n_xt++ ;
|
if (buf[0] == 'E' && buf[1] == 'N' && buf[2] == 'D')
|
||||||
|
{
|
||||||
if (xtnum==0 || xtnum==n_xt) {
|
break;
|
||||||
printf("===> xtension %d\n", n_xt) ;
|
}
|
||||||
printf("%s\n", rstrip(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
data_bytes = 1 ;
|
|
||||||
naxis = 0 ;
|
|
||||||
while ((err=fread(buf, sizeof(char), LGTH, in))==LGTH) {
|
|
||||||
if (xtnum==0 || xtnum==n_xt) printf("%s\n", rstrip(buf));
|
|
||||||
|
|
||||||
/* Look for BITPIX keyword */
|
|
||||||
if (buf[0]=='B' &&
|
|
||||||
buf[1]=='I' &&
|
|
||||||
buf[2]=='T' &&
|
|
||||||
buf[3]=='P' &&
|
|
||||||
buf[4]=='I' &&
|
|
||||||
buf[5]=='X' &&
|
|
||||||
buf[6]==' ') {
|
|
||||||
read_val = qfits_getvalue(buf);
|
|
||||||
data_bytes *= (int)atoi(read_val) / 8 ;
|
|
||||||
if (data_bytes<0) data_bytes *= -1 ;
|
|
||||||
} else
|
|
||||||
/* Look for NAXIS keyword */
|
|
||||||
if (buf[0]=='N' &&
|
|
||||||
buf[1]=='A' &&
|
|
||||||
buf[2]=='X' &&
|
|
||||||
buf[3]=='I' &&
|
|
||||||
buf[4]=='S') {
|
|
||||||
|
|
||||||
if (buf[5]==' ') {
|
|
||||||
/* NAXIS keyword */
|
|
||||||
read_val = qfits_getvalue(buf);
|
|
||||||
naxis = (int)atoi(read_val);
|
|
||||||
} else {
|
|
||||||
/* NAXIS?? keyword (axis size) */
|
|
||||||
read_val = qfits_getvalue(buf);
|
|
||||||
data_bytes *= (int)atoi(read_val);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
/* Look for END keyword */
|
|
||||||
if (buf[0]=='E' &&
|
|
||||||
buf[1]=='N' &&
|
|
||||||
buf[2]=='D') break ;
|
|
||||||
}
|
|
||||||
if (n_xt==xtnum) break ;
|
|
||||||
}
|
}
|
||||||
return 0 ;
|
if (err != LGTH)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xtnum < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
n_xt = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Skip the previous data section if pixels were declared
|
||||||
|
*/
|
||||||
|
if (naxis > 0)
|
||||||
|
{
|
||||||
|
/* Skip as many blocks as there are declared pixels */
|
||||||
|
skip_blocks = data_bytes / BLOCK_SIZE;
|
||||||
|
if ((data_bytes % BLOCK_SIZE) != 0)
|
||||||
|
skip_blocks++;
|
||||||
|
seeked = fseek (in, skip_blocks * BLOCK_SIZE, SEEK_CUR);
|
||||||
|
if (seeked < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Look for next XTENSION keyword */
|
||||||
|
while ((err = fread (buf, sizeof (char), LGTH, in)) == LGTH)
|
||||||
|
{
|
||||||
|
if (buf[0] == 'X' &&
|
||||||
|
buf[1] == 'T' &&
|
||||||
|
buf[2] == 'E' &&
|
||||||
|
buf[3] == 'N' &&
|
||||||
|
buf[4] == 'S' &&
|
||||||
|
buf[5] == 'I' && buf[6] == 'O' && buf[7] == 'N')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (err == 0)
|
||||||
|
break;
|
||||||
|
if (err != LGTH)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
n_xt++;
|
||||||
|
|
||||||
|
if (xtnum == 0 || xtnum == n_xt)
|
||||||
|
{
|
||||||
|
printf ("===> xtension %d\n", n_xt);
|
||||||
|
printf ("%s\n", rstrip (buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
data_bytes = 1;
|
||||||
|
naxis = 0;
|
||||||
|
while ((err = fread (buf, sizeof (char), LGTH, in)) == LGTH)
|
||||||
|
{
|
||||||
|
if (xtnum == 0 || xtnum == n_xt)
|
||||||
|
printf ("%s\n", rstrip (buf));
|
||||||
|
|
||||||
|
/* Look for BITPIX keyword */
|
||||||
|
if (buf[0] == 'B' &&
|
||||||
|
buf[1] == 'I' &&
|
||||||
|
buf[2] == 'T' &&
|
||||||
|
buf[3] == 'P' &&
|
||||||
|
buf[4] == 'I' && buf[5] == 'X' && buf[6] == ' ')
|
||||||
|
{
|
||||||
|
read_val = qfits_getvalue (buf);
|
||||||
|
data_bytes *= (int) atoi (read_val) / 8;
|
||||||
|
if (data_bytes < 0)
|
||||||
|
data_bytes *= -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Look for NAXIS keyword */
|
||||||
|
if (buf[0] == 'N' &&
|
||||||
|
buf[1] == 'A' &&
|
||||||
|
buf[2] == 'X' && buf[3] == 'I' && buf[4] == 'S')
|
||||||
|
{
|
||||||
|
|
||||||
|
if (buf[5] == ' ')
|
||||||
|
{
|
||||||
|
/* NAXIS keyword */
|
||||||
|
read_val = qfits_getvalue (buf);
|
||||||
|
naxis = (int) atoi (read_val);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* NAXIS?? keyword (axis size) */
|
||||||
|
read_val = qfits_getvalue (buf);
|
||||||
|
data_bytes *= (int) atoi (read_val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Look for END keyword */
|
||||||
|
if (buf[0] == 'E' && buf[1] == 'N' && buf[2] == 'D')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (n_xt == xtnum)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
1012
qfits/main/dtfits.c
1012
qfits/main/dtfits.c
File diff suppressed because it is too large
Load Diff
|
@ -37,132 +37,149 @@
|
||||||
* Swap pixels between position p1 and p2, regardless of the pixel
|
* Swap pixels between position p1 and p2, regardless of the pixel
|
||||||
* type and endian-ness of the local host.
|
* type and endian-ness of the local host.
|
||||||
*/
|
*/
|
||||||
static void swap_pix(char * buf, int p1, int p2, int psize)
|
static void
|
||||||
|
swap_pix (char *buf, int p1, int p2, int psize)
|
||||||
{
|
{
|
||||||
int i ;
|
int i;
|
||||||
char c ;
|
char c;
|
||||||
|
|
||||||
for (i=0 ; i<psize ; i++) {
|
for (i = 0; i < psize; i++)
|
||||||
c = buf[p1+i] ;
|
{
|
||||||
buf[p1+i] = buf[p2+i];
|
c = buf[p1 + i];
|
||||||
buf[p2+i] = c ;
|
buf[p1 + i] = buf[p2 + i];
|
||||||
}
|
buf[p2 + i] = c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main processing function. It expects one only file name
|
* Main processing function. It expects one only file name
|
||||||
* and will flip pixels on the input frame.
|
* and will flip pixels on the input frame.
|
||||||
*/
|
*/
|
||||||
static int fits_flip(char * pname, char * filename)
|
static int
|
||||||
|
fits_flip (char *pname, char *filename)
|
||||||
{
|
{
|
||||||
char * sval ;
|
char *sval;
|
||||||
int dstart;
|
int dstart;
|
||||||
int lx, ly ;
|
int lx, ly;
|
||||||
int bpp ;
|
int bpp;
|
||||||
int i, j ;
|
int i, j;
|
||||||
char * buf ;
|
char *buf;
|
||||||
char * fbuf ;
|
char *fbuf;
|
||||||
int psize;
|
int psize;
|
||||||
struct stat fileinfo ;
|
struct stat fileinfo;
|
||||||
int fd ;
|
int fd;
|
||||||
|
|
||||||
printf("%s: processing %s\n", pname, filename);
|
printf ("%s: processing %s\n", pname, filename);
|
||||||
|
|
||||||
if (stat(filename, &fileinfo)!=0) {
|
if (stat (filename, &fileinfo) != 0)
|
||||||
return -1 ;
|
{
|
||||||
}
|
return -1;
|
||||||
if (fileinfo.st_size<1) {
|
}
|
||||||
printf("cannot stat file\n");
|
if (fileinfo.st_size < 1)
|
||||||
return -1 ;
|
{
|
||||||
}
|
printf ("cannot stat file\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Retrieve image attributes */
|
/* Retrieve image attributes */
|
||||||
if (is_fits_file(filename)!=1) {
|
if (is_fits_file (filename) != 1)
|
||||||
printf("not a FITS file\n");
|
{
|
||||||
return -1 ;
|
printf ("not a FITS file\n");
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
sval = qfits_query_hdr(filename, "NAXIS1");
|
sval = qfits_query_hdr (filename, "NAXIS1");
|
||||||
if (sval==NULL) {
|
if (sval == NULL)
|
||||||
printf("cannot read NAXIS1\n");
|
{
|
||||||
return -1 ;
|
printf ("cannot read NAXIS1\n");
|
||||||
}
|
return -1;
|
||||||
lx = atoi(sval);
|
}
|
||||||
sval = qfits_query_hdr(filename, "NAXIS2");
|
lx = atoi (sval);
|
||||||
if (sval==NULL) {
|
sval = qfits_query_hdr (filename, "NAXIS2");
|
||||||
printf("cannot read NAXIS2\n");
|
if (sval == NULL)
|
||||||
return -1 ;
|
{
|
||||||
}
|
printf ("cannot read NAXIS2\n");
|
||||||
ly = atoi(sval);
|
return -1;
|
||||||
sval = qfits_query_hdr(filename, "BITPIX");
|
}
|
||||||
if (sval==NULL) {
|
ly = atoi (sval);
|
||||||
printf("cannot read BITPIX\n");
|
sval = qfits_query_hdr (filename, "BITPIX");
|
||||||
return -1 ;
|
if (sval == NULL)
|
||||||
}
|
{
|
||||||
bpp = atoi(sval);
|
printf ("cannot read BITPIX\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
bpp = atoi (sval);
|
||||||
|
|
||||||
psize = bpp/8 ;
|
psize = bpp / 8;
|
||||||
if (psize<0) psize=-psize ;
|
if (psize < 0)
|
||||||
|
psize = -psize;
|
||||||
|
|
||||||
/* Retrieve start of first data section */
|
/* Retrieve start of first data section */
|
||||||
if (qfits_get_hdrinfo(filename, 0, &dstart, NULL)!=0) {
|
if (qfits_get_hdrinfo (filename, 0, &dstart, NULL) != 0)
|
||||||
printf("reading header information\n");
|
{
|
||||||
return -1 ;
|
printf ("reading header information\n");
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Map the input file in read/write mode (input file is modified) */
|
/* Map the input file in read/write mode (input file is modified) */
|
||||||
if ((fd=open(filename, O_RDWR))==-1) {
|
if ((fd = open (filename, O_RDWR)) == -1)
|
||||||
perror("open");
|
{
|
||||||
printf("reading file\n");
|
perror ("open");
|
||||||
return -1 ;
|
printf ("reading file\n");
|
||||||
}
|
return -1;
|
||||||
fbuf = (char*)mmap(0,
|
}
|
||||||
fileinfo.st_size,
|
fbuf = (char *) mmap (0,
|
||||||
PROT_READ | PROT_WRITE,
|
fileinfo.st_size,
|
||||||
MAP_SHARED,
|
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
fd,
|
if (fbuf == (char *) -1)
|
||||||
0);
|
{
|
||||||
if (fbuf==(char*)-1) {
|
perror ("mmap");
|
||||||
perror("mmap");
|
printf ("mapping file\n");
|
||||||
printf("mapping file\n");
|
return -1;
|
||||||
return -1 ;
|
}
|
||||||
}
|
buf = fbuf + dstart;
|
||||||
buf = fbuf + dstart ;
|
|
||||||
|
|
||||||
/* Double loop */
|
/* Double loop */
|
||||||
for (j=0 ; j<ly ; j++) {
|
for (j = 0; j < ly; j++)
|
||||||
for (i=0 ; i<lx/2 ; i++) {
|
{
|
||||||
/* Swap bytes */
|
for (i = 0; i < lx / 2; i++)
|
||||||
swap_pix(buf, i*psize, (lx-i-1)*psize, psize);
|
{
|
||||||
}
|
/* Swap bytes */
|
||||||
buf += lx * psize ;
|
swap_pix (buf, i * psize, (lx - i - 1) * psize, psize);
|
||||||
}
|
}
|
||||||
if (munmap(fbuf, fileinfo.st_size)!=0) {
|
buf += lx * psize;
|
||||||
printf("unmapping file\n");
|
}
|
||||||
return -1 ;
|
if (munmap (fbuf, fileinfo.st_size) != 0)
|
||||||
}
|
{
|
||||||
return 0 ;
|
printf ("unmapping file\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char * argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i ;
|
int i;
|
||||||
int err ;
|
int err;
|
||||||
|
|
||||||
if (argc<2) {
|
if (argc < 2)
|
||||||
printf("use: %s <list of FITS files...>\n", argv[0]);
|
{
|
||||||
return 1 ;
|
printf ("use: %s <list of FITS files...>\n", argv[0]);
|
||||||
}
|
return 1;
|
||||||
err=0 ;
|
}
|
||||||
for (i=1 ; i<argc ; i++) {
|
err = 0;
|
||||||
err += fits_flip(argv[0], argv[i]) ;
|
for (i = 1; i < argc; i++)
|
||||||
}
|
{
|
||||||
if (err>0) {
|
err += fits_flip (argv[0], argv[i]);
|
||||||
fprintf(stderr, "%s: %d error(s) occurred\n", argv[0], err);
|
}
|
||||||
return -1 ;
|
if (err > 0)
|
||||||
}
|
{
|
||||||
return 0 ;
|
fprintf (stderr, "%s: %d error(s) occurred\n", argv[0], err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,31 +33,33 @@
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* Frame informations needed to classify it */
|
/* Frame informations needed to classify it */
|
||||||
typedef struct _framei {
|
typedef struct _framei
|
||||||
char * name ;
|
{
|
||||||
char * tplid ;
|
char *name;
|
||||||
char * origfile ;
|
char *tplid;
|
||||||
int expno ;
|
char *origfile;
|
||||||
int nexp ;
|
int expno;
|
||||||
|
int nexp;
|
||||||
|
|
||||||
struct _framei * next ;
|
struct _framei *next;
|
||||||
} framei ;
|
} framei;
|
||||||
|
|
||||||
/* Frame queue: is mostly a pointer to a list of frame information objects */
|
/* Frame queue: is mostly a pointer to a list of frame information objects */
|
||||||
typedef struct _frameq {
|
typedef struct _frameq
|
||||||
framei * first ;
|
{
|
||||||
int n ;
|
framei *first;
|
||||||
} frameq ;
|
int n;
|
||||||
|
} frameq;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Global variables
|
Global variables
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* List of strings to identify unwanted templates. */
|
/* List of strings to identify unwanted templates. */
|
||||||
char * tpl_filter[] = {
|
char *tpl_filter[] = {
|
||||||
"_acq_",
|
"_acq_",
|
||||||
"_CheckAoCorrection",
|
"_CheckAoCorrection",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -71,43 +73,56 @@ char * tpl_filter[] = {
|
||||||
@return A newly allocated framei obj. NULL in error case
|
@return A newly allocated framei obj. NULL in error case
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static framei * framei_new(char * filename)
|
static framei *
|
||||||
|
framei_new (char *filename)
|
||||||
{
|
{
|
||||||
framei * fi ;
|
framei *fi;
|
||||||
char * sval ;
|
char *sval;
|
||||||
char * sval2 ;
|
char *sval2;
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
fi = malloc(sizeof(framei));
|
fi = malloc (sizeof (framei));
|
||||||
fi->name = strdup(filename);
|
fi->name = strdup (filename);
|
||||||
sval = qfits_query_hdr(filename, "tpl.id");
|
sval = qfits_query_hdr (filename, "tpl.id");
|
||||||
if (sval!=NULL) {
|
if (sval != NULL)
|
||||||
/* Filter out unwanted template IDs */
|
{
|
||||||
i=0 ;
|
/* Filter out unwanted template IDs */
|
||||||
while (tpl_filter[i]!=NULL) {
|
i = 0;
|
||||||
if (strstr(sval, tpl_filter[i])!=NULL) return NULL ;
|
while (tpl_filter[i] != NULL)
|
||||||
i++ ;
|
{
|
||||||
}
|
if (strstr (sval, tpl_filter[i]) != NULL)
|
||||||
fi->tplid = strdup(qfits_pretty_string(sval)) ;
|
return NULL;
|
||||||
} else {
|
i++;
|
||||||
fi->tplid = NULL ;
|
}
|
||||||
|
fi->tplid = strdup (qfits_pretty_string (sval));
|
||||||
}
|
}
|
||||||
sval = qfits_query_hdr(filename, "origfile");
|
else
|
||||||
if (sval!=NULL) {
|
{
|
||||||
sval2 = qfits_pretty_string(sval) ;
|
fi->tplid = NULL;
|
||||||
fi->origfile = strdup(qfits_get_root_name(sval2)) ;
|
|
||||||
} else {
|
|
||||||
fi->origfile = NULL ;
|
|
||||||
}
|
}
|
||||||
sval = qfits_query_hdr(filename, "tpl.expno");
|
sval = qfits_query_hdr (filename, "origfile");
|
||||||
if (sval!=NULL) fi->expno = (int)atoi(sval);
|
if (sval != NULL)
|
||||||
else fi->expno = -1 ;
|
{
|
||||||
sval = qfits_query_hdr(filename, "tpl.nexp");
|
sval2 = qfits_pretty_string (sval);
|
||||||
if (sval!=NULL) fi->nexp = (int)atoi(sval);
|
fi->origfile = strdup (qfits_get_root_name (sval2));
|
||||||
else fi->nexp = -1 ;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fi->origfile = NULL;
|
||||||
|
}
|
||||||
|
sval = qfits_query_hdr (filename, "tpl.expno");
|
||||||
|
if (sval != NULL)
|
||||||
|
fi->expno = (int) atoi (sval);
|
||||||
|
else
|
||||||
|
fi->expno = -1;
|
||||||
|
sval = qfits_query_hdr (filename, "tpl.nexp");
|
||||||
|
if (sval != NULL)
|
||||||
|
fi->nexp = (int) atoi (sval);
|
||||||
|
else
|
||||||
|
fi->nexp = -1;
|
||||||
|
|
||||||
fi->next = NULL ;
|
fi->next = NULL;
|
||||||
return fi ;
|
return fi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -116,18 +131,22 @@ static framei * framei_new(char * filename)
|
||||||
@param fi Object to delete
|
@param fi Object to delete
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void framei_del(framei * fi)
|
static void
|
||||||
|
framei_del (framei * fi)
|
||||||
{
|
{
|
||||||
if (fi==NULL) return ;
|
if (fi == NULL)
|
||||||
if (fi->name!=NULL)
|
return;
|
||||||
free(fi->name);
|
if (fi->name != NULL)
|
||||||
if (fi->tplid!=NULL) {
|
free (fi->name);
|
||||||
free(fi->tplid);
|
if (fi->tplid != NULL)
|
||||||
|
{
|
||||||
|
free (fi->tplid);
|
||||||
}
|
}
|
||||||
if (fi->origfile!=NULL) {
|
if (fi->origfile != NULL)
|
||||||
free(fi->origfile);
|
{
|
||||||
|
free (fi->origfile);
|
||||||
}
|
}
|
||||||
free(fi);
|
free (fi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -136,14 +155,15 @@ static void framei_del(framei * fi)
|
||||||
@return A newly allocated empty frameq object
|
@return A newly allocated empty frameq object
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
frameq * frameq_new(void)
|
frameq *
|
||||||
|
frameq_new (void)
|
||||||
{
|
{
|
||||||
frameq * fq ;
|
frameq *fq;
|
||||||
|
|
||||||
fq = malloc(sizeof(frameq));
|
fq = malloc (sizeof (frameq));
|
||||||
fq->first = NULL ;
|
fq->first = NULL;
|
||||||
fq->n = 0 ;
|
fq->n = 0;
|
||||||
return fq ;
|
return fq;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -152,21 +172,24 @@ frameq * frameq_new(void)
|
||||||
@param fq The object to delete
|
@param fq The object to delete
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void frameq_del(frameq * fq)
|
void
|
||||||
|
frameq_del (frameq * fq)
|
||||||
{
|
{
|
||||||
framei * fi ;
|
framei *fi;
|
||||||
framei * fin ;
|
framei *fin;
|
||||||
|
|
||||||
if (fq==NULL) return ;
|
if (fq == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
fi = fq->first ;
|
fi = fq->first;
|
||||||
while (fi!=NULL) {
|
while (fi != NULL)
|
||||||
fin = fi->next ;
|
{
|
||||||
framei_del(fi);
|
fin = fi->next;
|
||||||
fi = fin ;
|
framei_del (fi);
|
||||||
|
fi = fin;
|
||||||
}
|
}
|
||||||
free(fq);
|
free (fq);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -176,28 +199,31 @@ void frameq_del(frameq * fq)
|
||||||
@param filename The file to append name
|
@param filename The file to append name
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void frameq_append(frameq * fq, char * filename)
|
void
|
||||||
|
frameq_append (frameq * fq, char *filename)
|
||||||
{
|
{
|
||||||
framei * fi ;
|
framei *fi;
|
||||||
framei * fn ;
|
framei *fn;
|
||||||
|
|
||||||
if (fq==NULL || filename==NULL) return ;
|
if (fq == NULL || filename == NULL)
|
||||||
fi = framei_new(filename);
|
return;
|
||||||
if (fi==NULL)
|
fi = framei_new (filename);
|
||||||
return ;
|
if (fi == NULL)
|
||||||
if (fq->n==0) {
|
return;
|
||||||
fq->first = fi ;
|
if (fq->n == 0)
|
||||||
fq->n = 1 ;
|
{
|
||||||
return ;
|
fq->first = fi;
|
||||||
|
fq->n = 1;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn = fq->first ;
|
fn = fq->first;
|
||||||
while (fn->next!=NULL)
|
while (fn->next != NULL)
|
||||||
fn = fn->next ;
|
fn = fn->next;
|
||||||
|
|
||||||
fn->next = fi ;
|
fn->next = fi;
|
||||||
fq->n ++ ;
|
fq->n++;
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -206,14 +232,15 @@ void frameq_append(frameq * fq, char * filename)
|
||||||
@param fq The frame queue
|
@param fq The frame queue
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void frameq_pop(frameq * fq)
|
void
|
||||||
|
frameq_pop (frameq * fq)
|
||||||
{
|
{
|
||||||
framei * first ;
|
framei *first;
|
||||||
|
|
||||||
first = fq->first->next ;
|
first = fq->first->next;
|
||||||
framei_del(fq->first);
|
framei_del (fq->first);
|
||||||
fq->first = first ;
|
fq->first = first;
|
||||||
fq->n -- ;
|
fq->n--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -223,20 +250,18 @@ void frameq_pop(frameq * fq)
|
||||||
@param out File where the queue is dumped
|
@param out File where the queue is dumped
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void frameq_dump(frameq * fq, FILE * out)
|
void
|
||||||
|
frameq_dump (frameq * fq, FILE * out)
|
||||||
{
|
{
|
||||||
int i ;
|
int i;
|
||||||
framei * fi ;
|
framei *fi;
|
||||||
|
|
||||||
fi = fq->first ;
|
fi = fq->first;
|
||||||
for (i=0 ; i<fq->n ; i++) {
|
for (i = 0; i < fq->n; i++)
|
||||||
fprintf(out,
|
{
|
||||||
"%s %s %02d/%02d\n",
|
fprintf (out,
|
||||||
fi->name,
|
"%s %s %02d/%02d\n", fi->name, fi->tplid, fi->expno, fi->nexp);
|
||||||
fi->tplid,
|
fi = fi->next;
|
||||||
fi->expno,
|
|
||||||
fi->nexp);
|
|
||||||
fi = fi->next ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,42 +272,46 @@ void frameq_dump(frameq * fq, FILE * out)
|
||||||
@return A newly allocated frame queue
|
@return A newly allocated frame queue
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
frameq * frameq_load(char * dirname)
|
frameq *
|
||||||
|
frameq_load (char *dirname)
|
||||||
{
|
{
|
||||||
frameq * fq ;
|
frameq *fq;
|
||||||
int i ;
|
int i;
|
||||||
glob_t pglob ;
|
glob_t pglob;
|
||||||
char filename[FILENAMESZ];
|
char filename[FILENAMESZ];
|
||||||
|
|
||||||
/* Look for *.fits *.FITS *.fits.gz *.FITS.gz */
|
/* Look for *.fits *.FITS *.fits.gz *.FITS.gz */
|
||||||
sprintf(filename, "%s/*.fits", dirname);
|
sprintf (filename, "%s/*.fits", dirname);
|
||||||
glob(filename, GLOB_MARK, NULL, &pglob);
|
glob (filename, GLOB_MARK, NULL, &pglob);
|
||||||
sprintf(filename, "%s/*.FITS", dirname);
|
sprintf (filename, "%s/*.FITS", dirname);
|
||||||
glob(filename, GLOB_APPEND, NULL, &pglob);
|
glob (filename, GLOB_APPEND, NULL, &pglob);
|
||||||
sprintf(filename, "%s/*.fits.gz", dirname);
|
sprintf (filename, "%s/*.fits.gz", dirname);
|
||||||
glob(filename, GLOB_APPEND, NULL, &pglob);
|
glob (filename, GLOB_APPEND, NULL, &pglob);
|
||||||
sprintf(filename, "%s/*.FITS.gz", dirname);
|
sprintf (filename, "%s/*.FITS.gz", dirname);
|
||||||
glob(filename, GLOB_APPEND, NULL, &pglob);
|
glob (filename, GLOB_APPEND, NULL, &pglob);
|
||||||
if (pglob.gl_pathc<1) {
|
if (pglob.gl_pathc < 1)
|
||||||
printf("found no frame\n");
|
{
|
||||||
return NULL ;
|
printf ("found no frame\n");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build frame queue */
|
/* Build frame queue */
|
||||||
fq = frameq_new();
|
fq = frameq_new ();
|
||||||
for (i=0 ; i<pglob.gl_pathc ; i++) {
|
for (i = 0; i < pglob.gl_pathc; i++)
|
||||||
printf("\radding %d of %d", i+1, pglob.gl_pathc);
|
{
|
||||||
fflush(stdout);
|
printf ("\radding %d of %d", i + 1, pglob.gl_pathc);
|
||||||
frameq_append(fq, pglob.gl_pathv[i]);
|
fflush (stdout);
|
||||||
|
frameq_append (fq, pglob.gl_pathv[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf ("\n");
|
||||||
globfree(&pglob);
|
globfree (&pglob);
|
||||||
return fq ;
|
return fq;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stringsort(const void * e1, const void * e2)
|
static int
|
||||||
|
stringsort (const void *e1, const void *e2)
|
||||||
{
|
{
|
||||||
return strcmp(*(char**)e1, *(char**)e2);
|
return strcmp (*(char **) e1, *(char **) e2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -293,53 +322,64 @@ static int stringsort(const void * e1, const void * e2)
|
||||||
@return List of n strings
|
@return List of n strings
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char ** frameq_get_tplid(frameq * fq, int * n)
|
char **
|
||||||
|
frameq_get_tplid (frameq * fq, int *n)
|
||||||
{
|
{
|
||||||
framei * fn ;
|
framei *fn;
|
||||||
char ** tplid_all ;
|
char **tplid_all;
|
||||||
char ** tplid ;
|
char **tplid;
|
||||||
int i, j ;
|
int i, j;
|
||||||
int ntplid ;
|
int ntplid;
|
||||||
|
|
||||||
/* Get all possible values for tplid */
|
/* Get all possible values for tplid */
|
||||||
tplid_all = malloc(fq->n * sizeof(char*));
|
tplid_all = malloc (fq->n * sizeof (char *));
|
||||||
fn = fq->first ;
|
fn = fq->first;
|
||||||
for (i=0 ; i<fq->n ; i++) {
|
for (i = 0; i < fq->n; i++)
|
||||||
if (fn->tplid==NULL) {
|
{
|
||||||
tplid_all[i] = strdup("none");
|
if (fn->tplid == NULL)
|
||||||
} else {
|
{
|
||||||
tplid_all[i] = strdup(fn->tplid);
|
tplid_all[i] = strdup ("none");
|
||||||
}
|
}
|
||||||
fn = fn->next ;
|
else
|
||||||
|
{
|
||||||
|
tplid_all[i] = strdup (fn->tplid);
|
||||||
|
}
|
||||||
|
fn = fn->next;
|
||||||
}
|
}
|
||||||
/* Sort all tplid's */
|
/* Sort all tplid's */
|
||||||
qsort(tplid_all, fq->n, sizeof(char*), stringsort);
|
qsort (tplid_all, fq->n, sizeof (char *), stringsort);
|
||||||
|
|
||||||
/* Compute how many different tplid's can be found */
|
/* Compute how many different tplid's can be found */
|
||||||
ntplid=1 ;
|
ntplid = 1;
|
||||||
for (i=1 ; i<fq->n ; i++) {
|
for (i = 1; i < fq->n; i++)
|
||||||
if (strcmp(tplid_all[i], tplid_all[i-1])) {
|
{
|
||||||
ntplid++ ;
|
if (strcmp (tplid_all[i], tplid_all[i - 1]))
|
||||||
}
|
{
|
||||||
|
ntplid++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tplid = malloc(ntplid * sizeof(char*));
|
tplid = malloc (ntplid * sizeof (char *));
|
||||||
tplid[0] = tplid_all[0] ;
|
tplid[0] = tplid_all[0];
|
||||||
tplid_all[0] = NULL ;
|
tplid_all[0] = NULL;
|
||||||
j=0 ;
|
j = 0;
|
||||||
for (i=1 ; i<fq->n ; i++) {
|
for (i = 1; i < fq->n; i++)
|
||||||
if (strcmp(tplid_all[i], tplid[j])) {
|
{
|
||||||
j++ ;
|
if (strcmp (tplid_all[i], tplid[j]))
|
||||||
tplid[j] = tplid_all[i] ;
|
{
|
||||||
} else {
|
j++;
|
||||||
free(tplid_all[i]);
|
tplid[j] = tplid_all[i];
|
||||||
}
|
}
|
||||||
tplid_all[i] = NULL ;
|
else
|
||||||
|
{
|
||||||
|
free (tplid_all[i]);
|
||||||
|
}
|
||||||
|
tplid_all[i] = NULL;
|
||||||
}
|
}
|
||||||
free(tplid_all);
|
free (tplid_all);
|
||||||
|
|
||||||
*n = ntplid ;
|
*n = ntplid;
|
||||||
return tplid ;
|
return tplid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -349,29 +389,34 @@ char ** frameq_get_tplid(frameq * fq, int * n)
|
||||||
@return Setting number
|
@return Setting number
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int frameq_getsetnum(char * dirname)
|
int
|
||||||
|
frameq_getsetnum (char *dirname)
|
||||||
{
|
{
|
||||||
char pattern[FILENAMESZ];
|
char pattern[FILENAMESZ];
|
||||||
glob_t pglob ;
|
glob_t pglob;
|
||||||
int i ;
|
int i;
|
||||||
int max ;
|
int max;
|
||||||
int num ;
|
int num;
|
||||||
|
|
||||||
sprintf(pattern, "%s/set*", dirname);
|
sprintf (pattern, "%s/set*", dirname);
|
||||||
glob(pattern, GLOB_MARK, NULL, &pglob);
|
glob (pattern, GLOB_MARK, NULL, &pglob);
|
||||||
if (pglob.gl_pathc<1) {
|
if (pglob.gl_pathc < 1)
|
||||||
max=0 ;
|
{
|
||||||
} else {
|
max = 0;
|
||||||
sprintf(pattern, "%s/set%%02d", dirname);
|
|
||||||
max=0 ;
|
|
||||||
for (i=0 ; i<pglob.gl_pathc ; i++) {
|
|
||||||
sscanf(pglob.gl_pathv[i], pattern, &num);
|
|
||||||
if (num>max)
|
|
||||||
max=num ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
globfree(&pglob);
|
else
|
||||||
return max+1 ;
|
{
|
||||||
|
sprintf (pattern, "%s/set%%02d", dirname);
|
||||||
|
max = 0;
|
||||||
|
for (i = 0; i < pglob.gl_pathc; i++)
|
||||||
|
{
|
||||||
|
sscanf (pglob.gl_pathv[i], pattern, &num);
|
||||||
|
if (num > max)
|
||||||
|
max = num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
globfree (&pglob);
|
||||||
|
return max + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -380,82 +425,93 @@ int frameq_getsetnum(char * dirname)
|
||||||
@param fq Frame queue
|
@param fq Frame queue
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void frameq_makelists(frameq * fq)
|
void
|
||||||
|
frameq_makelists (frameq * fq)
|
||||||
{
|
{
|
||||||
FILE * list ;
|
FILE *list;
|
||||||
char filename[FILENAMESZ];
|
char filename[FILENAMESZ];
|
||||||
framei * fi ;
|
framei *fi;
|
||||||
int setnum ;
|
int setnum;
|
||||||
int count ;
|
int count;
|
||||||
int batches ;
|
int batches;
|
||||||
|
|
||||||
/* Count # of batches in input */
|
/* Count # of batches in input */
|
||||||
fi = fq->first ;
|
fi = fq->first;
|
||||||
batches=0 ;
|
batches = 0;
|
||||||
while (fi!=NULL) {
|
while (fi != NULL)
|
||||||
if (fi->expno==1)
|
{
|
||||||
batches++ ;
|
if (fi->expno == 1)
|
||||||
fi = fi->next ;
|
batches++;
|
||||||
|
fi = fi->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
fi = fq->first ;
|
fi = fq->first;
|
||||||
count=0 ;
|
count = 0;
|
||||||
list=NULL ;
|
list = NULL;
|
||||||
while (fi!=NULL) {
|
while (fi != NULL)
|
||||||
printf("\rclassifying batches: %d of %d", count, batches);
|
{
|
||||||
fflush(stdout);
|
printf ("\rclassifying batches: %d of %d", count, batches);
|
||||||
if (fi->expno<0) {
|
fflush (stdout);
|
||||||
fi=fi->next ;
|
if (fi->expno < 0)
|
||||||
continue ;
|
{
|
||||||
}
|
fi = fi->next;
|
||||||
if (fi->expno==1) {
|
continue;
|
||||||
count++ ;
|
}
|
||||||
if (list!=NULL) {
|
if (fi->expno == 1)
|
||||||
fclose(list);
|
{
|
||||||
}
|
count++;
|
||||||
if (fi->tplid == NULL) {
|
if (list != NULL)
|
||||||
printf("No TPL ID - abort\n") ;
|
{
|
||||||
return ;
|
fclose (list);
|
||||||
}
|
}
|
||||||
if (fi->origfile == NULL) {
|
if (fi->tplid == NULL)
|
||||||
printf("No ORIGFILE - abort\n") ;
|
{
|
||||||
return ;
|
printf ("No TPL ID - abort\n");
|
||||||
}
|
return;
|
||||||
mkdir(fi->tplid, 0755);
|
}
|
||||||
setnum = frameq_getsetnum(fi->tplid);
|
if (fi->origfile == NULL)
|
||||||
sprintf(filename, "%s/%s_%02d", fi->tplid, fi->origfile, fi->nexp);
|
{
|
||||||
mkdir(filename, 0755);
|
printf ("No ORIGFILE - abort\n");
|
||||||
sprintf(filename, "%s/%s_%02d/IN", fi->tplid,fi->origfile,fi->nexp);
|
return;
|
||||||
list = fopen(filename, "w");
|
}
|
||||||
fprintf(list,"# TPL.ID= %s\n", fi->tplid);
|
mkdir (fi->tplid, 0755);
|
||||||
fprintf(list,"# NEXP = %02d\n", fi->nexp);
|
setnum = frameq_getsetnum (fi->tplid);
|
||||||
}
|
sprintf (filename, "%s/%s_%02d", fi->tplid, fi->origfile, fi->nexp);
|
||||||
if (list) fprintf(list, "%s\n", fi->name);
|
mkdir (filename, 0755);
|
||||||
fi = fi->next ;
|
sprintf (filename, "%s/%s_%02d/IN", fi->tplid, fi->origfile,
|
||||||
|
fi->nexp);
|
||||||
|
list = fopen (filename, "w");
|
||||||
|
fprintf (list, "# TPL.ID= %s\n", fi->tplid);
|
||||||
|
fprintf (list, "# NEXP = %02d\n", fi->nexp);
|
||||||
|
}
|
||||||
|
if (list)
|
||||||
|
fprintf (list, "%s\n", fi->name);
|
||||||
|
fi = fi->next;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf ("\n");
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char * argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
frameq * fq ;
|
frameq *fq;
|
||||||
|
|
||||||
if (argc<2) {
|
if (argc < 2)
|
||||||
printf("use: %s <dirname>\n", argv[0]);
|
{
|
||||||
return 1 ;
|
printf ("use: %s <dirname>\n", argv[0]);
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
printf("loading frames from %s...\n", argv[1]);
|
|
||||||
fq = frameq_load(argv[1]);
|
|
||||||
printf("processing lists...\n");
|
|
||||||
frameq_makelists(fq);
|
|
||||||
frameq_del(fq);
|
|
||||||
printf("done\n");
|
|
||||||
|
|
||||||
return 0 ;
|
printf ("loading frames from %s...\n", argv[1]);
|
||||||
|
fq = frameq_load (argv[1]);
|
||||||
|
printf ("processing lists...\n");
|
||||||
|
frameq_makelists (fq);
|
||||||
|
frameq_del (fq);
|
||||||
|
printf ("done\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
@date Nov, 2002
|
@date Nov, 2002
|
||||||
@version $Revision: 1.5 $
|
@version $Revision: 1.5 $
|
||||||
@brief Extract a FITS extension and write it in a new FITS file
|
@brief Extract a FITS extension and write it in a new FITS file
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -19,249 +19,275 @@
|
||||||
Includes
|
Includes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "qfits.h"
|
#include "qfits.h"
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static int textract_write_ext(char *, int) ;
|
static int textract_write_ext (char *, int);
|
||||||
static int iextract_write_ext(char *, int) ;
|
static int iextract_write_ext (char *, int);
|
||||||
static char prog_desc[] = "Extract and write FITS extensions" ;
|
static char prog_desc[] = "Extract and write FITS extensions";
|
||||||
static void usage(char *) ;
|
static void usage (char *);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char * name_in ;
|
char *name_in;
|
||||||
int ext ;
|
int ext;
|
||||||
int nb_ext ;
|
int nb_ext;
|
||||||
int ext_type ;
|
int ext_type;
|
||||||
|
|
||||||
if (argc<3) usage(argv[0]) ;
|
if (argc < 3)
|
||||||
|
usage (argv[0]);
|
||||||
/* Get input file name and extension number */
|
|
||||||
name_in = strdup(argv[1]) ;
|
/* Get input file name and extension number */
|
||||||
ext = (int)atoi(argv[2]) ;
|
name_in = strdup (argv[1]);
|
||||||
|
ext = (int) atoi (argv[2]);
|
||||||
/* Check if the file is a FITS file */
|
|
||||||
if (!is_fits_file(name_in)) {
|
/* Check if the file is a FITS file */
|
||||||
printf("[%s] is not a FITS file\n", name_in) ;
|
if (!is_fits_file (name_in))
|
||||||
free(name_in) ;
|
{
|
||||||
return -1 ;
|
printf ("[%s] is not a FITS file\n", name_in);
|
||||||
}
|
free (name_in);
|
||||||
|
return -1;
|
||||||
/* Check if the extension is valid */
|
|
||||||
nb_ext = qfits_query_n_ext(name_in) ;
|
|
||||||
if (nb_ext < ext) {
|
|
||||||
printf("Only %d extensions in this file\n", nb_ext) ;
|
|
||||||
free(name_in) ;
|
|
||||||
return -1 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if it's a table or an image */
|
/* Check if the extension is valid */
|
||||||
ext_type = qfits_is_table(name_in, ext) ;
|
nb_ext = qfits_query_n_ext (name_in);
|
||||||
|
if (nb_ext < ext)
|
||||||
switch (ext_type) {
|
{
|
||||||
case QFITS_BINTABLE:
|
printf ("Only %d extensions in this file\n", nb_ext);
|
||||||
case QFITS_ASCIITABLE:
|
free (name_in);
|
||||||
if (textract_write_ext(name_in, ext) == -1) {
|
return -1;
|
||||||
printf("cannot read-write extension no %d\n", ext) ;
|
|
||||||
free(name_in) ;
|
|
||||||
return -1 ;
|
|
||||||
}
|
|
||||||
break ;
|
|
||||||
case QFITS_INVALIDTABLE:
|
|
||||||
if (iextract_write_ext(name_in, ext) == -1) {
|
|
||||||
printf("cannot read-write extension no %d\n", ext) ;
|
|
||||||
free(name_in) ;
|
|
||||||
return -1 ;
|
|
||||||
}
|
|
||||||
break ;
|
|
||||||
default:
|
|
||||||
printf("Unrecognized FITS type\n") ;
|
|
||||||
free(name_in) ;
|
|
||||||
return -1 ;
|
|
||||||
}
|
}
|
||||||
free(name_in) ;
|
|
||||||
|
/* Check if it's a table or an image */
|
||||||
return 0 ;
|
ext_type = qfits_is_table (name_in, ext);
|
||||||
|
|
||||||
|
switch (ext_type)
|
||||||
|
{
|
||||||
|
case QFITS_BINTABLE:
|
||||||
|
case QFITS_ASCIITABLE:
|
||||||
|
if (textract_write_ext (name_in, ext) == -1)
|
||||||
|
{
|
||||||
|
printf ("cannot read-write extension no %d\n", ext);
|
||||||
|
free (name_in);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QFITS_INVALIDTABLE:
|
||||||
|
if (iextract_write_ext (name_in, ext) == -1)
|
||||||
|
{
|
||||||
|
printf ("cannot read-write extension no %d\n", ext);
|
||||||
|
free (name_in);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf ("Unrecognized FITS type\n");
|
||||||
|
free (name_in);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free (name_in);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Functions code
|
Functions code
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void usage(char * pname)
|
static void
|
||||||
|
usage (char *pname)
|
||||||
{
|
{
|
||||||
printf("%s : %s\n", pname, prog_desc) ;
|
printf ("%s : %s\n", pname, prog_desc);
|
||||||
printf(
|
printf ("use : %s <in> <extension>\n" "\n", pname);
|
||||||
"use : %s <in> <extension>\n"
|
exit (0);
|
||||||
"\n", pname) ;
|
|
||||||
exit(0) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int textract_write_ext(
|
static int
|
||||||
char * in,
|
textract_write_ext (char *in, int ext)
|
||||||
int ext)
|
|
||||||
{
|
{
|
||||||
qfits_table * th ;
|
qfits_table *th;
|
||||||
void ** array ;
|
void **array;
|
||||||
qfits_header * fh ;
|
qfits_header *fh;
|
||||||
int array_size ;
|
int array_size;
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
/* Get the table infos */
|
/* Get the table infos */
|
||||||
if ((th = qfits_table_open(in, ext)) == NULL) {
|
if ((th = qfits_table_open (in, ext)) == NULL)
|
||||||
printf("cannot read extension: %d\n", ext) ;
|
{
|
||||||
return -1 ;
|
printf ("cannot read extension: %d\n", ext);
|
||||||
}
|
return -1;
|
||||||
|
|
||||||
/* Compute array_size */
|
|
||||||
array_size = 0 ;
|
|
||||||
for (i=0 ; i<th->nc ; i++) {
|
|
||||||
switch (th->col[i].atom_type) {
|
|
||||||
case TFITS_ASCII_TYPE_A:
|
|
||||||
case TFITS_ASCII_TYPE_I:
|
|
||||||
case TFITS_ASCII_TYPE_E:
|
|
||||||
case TFITS_ASCII_TYPE_F:
|
|
||||||
case TFITS_ASCII_TYPE_D:
|
|
||||||
case TFITS_BIN_TYPE_A:
|
|
||||||
case TFITS_BIN_TYPE_L:
|
|
||||||
case TFITS_BIN_TYPE_B:
|
|
||||||
case TFITS_BIN_TYPE_X:
|
|
||||||
array_size += sizeof(char*) ;
|
|
||||||
break ;
|
|
||||||
|
|
||||||
case TFITS_BIN_TYPE_I:
|
|
||||||
array_size += sizeof(short*) ;
|
|
||||||
break ;
|
|
||||||
|
|
||||||
case TFITS_BIN_TYPE_J:
|
|
||||||
case TFITS_BIN_TYPE_E:
|
|
||||||
array_size += sizeof(int*) ;
|
|
||||||
break ;
|
|
||||||
|
|
||||||
case TFITS_BIN_TYPE_C:
|
|
||||||
case TFITS_BIN_TYPE_P:
|
|
||||||
array_size += sizeof(float*) ;
|
|
||||||
break ;
|
|
||||||
|
|
||||||
case TFITS_BIN_TYPE_D:
|
|
||||||
case TFITS_BIN_TYPE_M:
|
|
||||||
array_size += sizeof(double*) ;
|
|
||||||
break ;
|
|
||||||
default:
|
|
||||||
return -1 ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate memory for array */
|
|
||||||
array = malloc(array_size) ;
|
|
||||||
|
|
||||||
/* Load columns in array */
|
|
||||||
for (i=0 ; i<th->nc ; i++) {
|
|
||||||
array[i] = qfits_query_column_data(th, i, NULL, NULL) ;
|
|
||||||
if (array[i] == NULL) {
|
|
||||||
printf("cannot read column %d\n", i+1) ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update th : filename */
|
/* Compute array_size */
|
||||||
sprintf(th->filename, "ext%d.tfits", ext) ;
|
array_size = 0;
|
||||||
|
for (i = 0; i < th->nc; i++)
|
||||||
|
{
|
||||||
|
switch (th->col[i].atom_type)
|
||||||
|
{
|
||||||
|
case TFITS_ASCII_TYPE_A:
|
||||||
|
case TFITS_ASCII_TYPE_I:
|
||||||
|
case TFITS_ASCII_TYPE_E:
|
||||||
|
case TFITS_ASCII_TYPE_F:
|
||||||
|
case TFITS_ASCII_TYPE_D:
|
||||||
|
case TFITS_BIN_TYPE_A:
|
||||||
|
case TFITS_BIN_TYPE_L:
|
||||||
|
case TFITS_BIN_TYPE_B:
|
||||||
|
case TFITS_BIN_TYPE_X:
|
||||||
|
array_size += sizeof (char *);
|
||||||
|
break;
|
||||||
|
|
||||||
/* Get fits primary header */
|
case TFITS_BIN_TYPE_I:
|
||||||
if ((fh = qfits_header_read(in)) == NULL) {
|
array_size += sizeof (short *);
|
||||||
for (i=0 ; i<th->nc ; i++) if (array[i] != NULL) free(array[i]) ;
|
break;
|
||||||
qfits_table_close(th) ;
|
|
||||||
free(array) ;
|
|
||||||
printf("cannot read fits header\n") ;
|
|
||||||
return -1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ext != 0) {
|
|
||||||
/* No data in primary HDU */
|
|
||||||
qfits_header_mod(fh, "NAXIS", "0", NULL) ;
|
|
||||||
qfits_header_del(fh, "NAXIS1") ;
|
|
||||||
qfits_header_del(fh, "NAXIS2") ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write the tfits file */
|
case TFITS_BIN_TYPE_J:
|
||||||
if (qfits_save_table_hdrdump((void **)array, th, fh) == -1) {
|
case TFITS_BIN_TYPE_E:
|
||||||
qfits_header_destroy(fh) ;
|
array_size += sizeof (int *);
|
||||||
for (i=0 ; i<th->nc ; i++) if (array[i] != NULL) free(array[i]) ;
|
break;
|
||||||
qfits_table_close(th) ;
|
|
||||||
free(array) ;
|
case TFITS_BIN_TYPE_C:
|
||||||
printf("cannot write fits table\n") ;
|
case TFITS_BIN_TYPE_P:
|
||||||
return -1 ;
|
array_size += sizeof (float *);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TFITS_BIN_TYPE_D:
|
||||||
|
case TFITS_BIN_TYPE_M:
|
||||||
|
array_size += sizeof (double *);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free and return */
|
/* Allocate memory for array */
|
||||||
qfits_header_destroy(fh) ;
|
array = malloc (array_size);
|
||||||
for (i=0 ; i<th->nc ; i++) if (array[i] != NULL) free(array[i]) ;
|
|
||||||
qfits_table_close(th) ;
|
/* Load columns in array */
|
||||||
free(array) ;
|
for (i = 0; i < th->nc; i++)
|
||||||
return 0 ;
|
{
|
||||||
|
array[i] = qfits_query_column_data (th, i, NULL, NULL);
|
||||||
|
if (array[i] == NULL)
|
||||||
|
{
|
||||||
|
printf ("cannot read column %d\n", i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update th : filename */
|
||||||
|
sprintf (th->filename, "ext%d.tfits", ext);
|
||||||
|
|
||||||
|
/* Get fits primary header */
|
||||||
|
if ((fh = qfits_header_read (in)) == NULL)
|
||||||
|
{
|
||||||
|
for (i = 0; i < th->nc; i++)
|
||||||
|
if (array[i] != NULL)
|
||||||
|
free (array[i]);
|
||||||
|
qfits_table_close (th);
|
||||||
|
free (array);
|
||||||
|
printf ("cannot read fits header\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext != 0)
|
||||||
|
{
|
||||||
|
/* No data in primary HDU */
|
||||||
|
qfits_header_mod (fh, "NAXIS", "0", NULL);
|
||||||
|
qfits_header_del (fh, "NAXIS1");
|
||||||
|
qfits_header_del (fh, "NAXIS2");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write the tfits file */
|
||||||
|
if (qfits_save_table_hdrdump ((void **) array, th, fh) == -1)
|
||||||
|
{
|
||||||
|
qfits_header_destroy (fh);
|
||||||
|
for (i = 0; i < th->nc; i++)
|
||||||
|
if (array[i] != NULL)
|
||||||
|
free (array[i]);
|
||||||
|
qfits_table_close (th);
|
||||||
|
free (array);
|
||||||
|
printf ("cannot write fits table\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free and return */
|
||||||
|
qfits_header_destroy (fh);
|
||||||
|
for (i = 0; i < th->nc; i++)
|
||||||
|
if (array[i] != NULL)
|
||||||
|
free (array[i]);
|
||||||
|
qfits_table_close (th);
|
||||||
|
free (array);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int iextract_write_ext(
|
static int
|
||||||
char * in,
|
iextract_write_ext (char *in, int ext)
|
||||||
int ext)
|
|
||||||
{
|
{
|
||||||
qfitsloader ql ;
|
qfitsloader ql;
|
||||||
qfitsdumper qd ;
|
qfitsdumper qd;
|
||||||
qfits_header * fh ;
|
qfits_header *fh;
|
||||||
char outname[1024] ;
|
char outname[1024];
|
||||||
FILE * out ;
|
FILE *out;
|
||||||
|
|
||||||
sprintf(outname, "ext%d.fits", ext) ;
|
|
||||||
|
|
||||||
/* Initialize a FITS loader */
|
|
||||||
ql.filename = in ;
|
|
||||||
ql.xtnum = ext ;
|
|
||||||
ql.pnum = 0 ;
|
|
||||||
ql.map = 1 ;
|
|
||||||
ql.ptype = PTYPE_DOUBLE ;
|
|
||||||
if (qfitsloader_init(&ql)!=0) return -1 ;
|
|
||||||
|
|
||||||
/* Load the primary header */
|
|
||||||
if ((fh = qfits_header_read(ql.filename)) == NULL) return -1 ;
|
|
||||||
|
|
||||||
if (ext != 0) {
|
sprintf (outname, "ext%d.fits", ext);
|
||||||
/* No data in primary HDU */
|
|
||||||
qfits_header_mod(fh, "NAXIS", "0", NULL) ;
|
|
||||||
qfits_header_del(fh, "NAXIS1") ;
|
|
||||||
qfits_header_del(fh, "NAXIS2") ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dump the primary header */
|
|
||||||
if ((out = fopen(outname, "w")) == NULL) return -1 ;
|
|
||||||
qfits_header_dump(fh, out);
|
|
||||||
qfits_header_destroy(fh) ;
|
|
||||||
|
|
||||||
if (ext != 0) {
|
/* Initialize a FITS loader */
|
||||||
/* Load the extension header */
|
ql.filename = in;
|
||||||
if ((fh = qfits_header_readext(ql.filename, ext)) == NULL) return -1 ;
|
ql.xtnum = ext;
|
||||||
/* Dump the extension header */
|
ql.pnum = 0;
|
||||||
qfits_header_dump(fh, out);
|
ql.map = 1;
|
||||||
qfits_header_destroy(fh) ;
|
ql.ptype = PTYPE_DOUBLE;
|
||||||
|
if (qfitsloader_init (&ql) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Load the primary header */
|
||||||
|
if ((fh = qfits_header_read (ql.filename)) == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (ext != 0)
|
||||||
|
{
|
||||||
|
/* No data in primary HDU */
|
||||||
|
qfits_header_mod (fh, "NAXIS", "0", NULL);
|
||||||
|
qfits_header_del (fh, "NAXIS1");
|
||||||
|
qfits_header_del (fh, "NAXIS2");
|
||||||
}
|
}
|
||||||
fclose(out) ;
|
|
||||||
|
/* Dump the primary header */
|
||||||
/* Load the FITS image */
|
if ((out = fopen (outname, "w")) == NULL)
|
||||||
if (qfits_loadpix(&ql)!=0) return -1 ;
|
return -1;
|
||||||
|
qfits_header_dump (fh, out);
|
||||||
/* Write the FITS image */
|
qfits_header_destroy (fh);
|
||||||
qd.filename = outname ;
|
|
||||||
qd.npix = ql.lx * ql.ly ;
|
if (ext != 0)
|
||||||
qd.ptype = PTYPE_DOUBLE ;
|
{
|
||||||
qd.dbuf = ql.dbuf ;
|
/* Load the extension header */
|
||||||
qd.out_ptype = ql.bitpix ;
|
if ((fh = qfits_header_readext (ql.filename, ext)) == NULL)
|
||||||
if (qfits_pixdump(&qd)!=0) return -1 ;
|
return -1;
|
||||||
/* qfits_zeropad(outname) ; */
|
/* Dump the extension header */
|
||||||
free(ql.dbuf) ;
|
qfits_header_dump (fh, out);
|
||||||
|
qfits_header_destroy (fh);
|
||||||
return 0 ;
|
}
|
||||||
|
fclose (out);
|
||||||
|
|
||||||
|
/* Load the FITS image */
|
||||||
|
if (qfits_loadpix (&ql) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Write the FITS image */
|
||||||
|
qd.filename = outname;
|
||||||
|
qd.npix = ql.lx * ql.ly;
|
||||||
|
qd.ptype = PTYPE_DOUBLE;
|
||||||
|
qd.dbuf = ql.dbuf;
|
||||||
|
qd.out_ptype = ql.bitpix;
|
||||||
|
if (qfits_pixdump (&qd) != 0)
|
||||||
|
return -1;
|
||||||
|
/* qfits_zeropad(outname) ; */
|
||||||
|
free (ql.dbuf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
Include
|
Include
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "qfits.h"
|
#include "qfits.h"
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Define
|
Define
|
||||||
|
@ -31,182 +31,231 @@
|
||||||
Functions prototypes
|
Functions prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static char prog_desc[] = "replace keyword in a FITS header" ;
|
static char prog_desc[] = "replace keyword in a FITS header";
|
||||||
static void usage(char *) ;
|
static void usage (char *);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char * name_in ;
|
char *name_in;
|
||||||
char * card ;
|
char *card;
|
||||||
char * place ;
|
char *place;
|
||||||
char * key ;
|
char *key;
|
||||||
char * key_tmp ;
|
char *key_tmp;
|
||||||
char * val ;
|
char *val;
|
||||||
char * val_tmp ;
|
char *val_tmp;
|
||||||
char * com ;
|
char *com;
|
||||||
char * com_tmp ;
|
char *com_tmp;
|
||||||
int keep_com ;
|
int keep_com;
|
||||||
int numeric ;
|
int numeric;
|
||||||
char * stmp ;
|
char *stmp;
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
char card_tmp[NM_SIZ] ;
|
|
||||||
|
|
||||||
if (argc<2) usage(argv[0]) ;
|
char card_tmp[NM_SIZ];
|
||||||
|
|
||||||
/* Initialize */
|
|
||||||
name_in = NULL ;
|
|
||||||
card = NULL ;
|
|
||||||
place = NULL ;
|
|
||||||
key = NULL ;
|
|
||||||
val = NULL ;
|
|
||||||
com = NULL ;
|
|
||||||
keep_com = 0 ;
|
|
||||||
numeric = 0 ;
|
|
||||||
|
|
||||||
/* Command line handling */
|
if (argc < 2)
|
||||||
i=1 ;
|
usage (argv[0]);
|
||||||
while (i<argc) {
|
|
||||||
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
|
/* Initialize */
|
||||||
usage(argv[0]);
|
name_in = NULL;
|
||||||
} else if (!strcmp(argv[i], "-p")) {
|
card = NULL;
|
||||||
if ((i+1)>=argc) {
|
place = NULL;
|
||||||
fprintf(stderr, "option -p needs an argument\n");
|
key = NULL;
|
||||||
return -1 ;
|
val = NULL;
|
||||||
}
|
com = NULL;
|
||||||
i++ ;
|
keep_com = 0;
|
||||||
place = strdup(argv[i]);
|
numeric = 0;
|
||||||
} else if (!strcmp(argv[i], "-k")) {
|
|
||||||
if ((i+1)>=argc) {
|
/* Command line handling */
|
||||||
fprintf(stderr, "option -k needs an argument\n");
|
i = 1;
|
||||||
return -1 ;
|
while (i < argc)
|
||||||
}
|
{
|
||||||
i++ ;
|
if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-h"))
|
||||||
key = strdup(argv[i]);
|
{
|
||||||
} else if (!strcmp(argv[i], "-v")) {
|
usage (argv[0]);
|
||||||
if ((i+1)>=argc) {
|
}
|
||||||
fprintf(stderr, "option -v needs an argument\n");
|
else if (!strcmp (argv[i], "-p"))
|
||||||
return -1 ;
|
{
|
||||||
}
|
if ((i + 1) >= argc)
|
||||||
i++ ;
|
{
|
||||||
val = strdup(argv[i]);
|
fprintf (stderr, "option -p needs an argument\n");
|
||||||
} else if (!strcmp(argv[i], "-c")) {
|
return -1;
|
||||||
if ((i+1)>=argc) {
|
}
|
||||||
fprintf(stderr, "option -c needs an argument\n");
|
i++;
|
||||||
return -1 ;
|
place = strdup (argv[i]);
|
||||||
}
|
}
|
||||||
i++ ;
|
else if (!strcmp (argv[i], "-k"))
|
||||||
com = strdup(argv[i]);
|
{
|
||||||
} else if (!strcmp(argv[i], "-C")) {
|
if ((i + 1) >= argc)
|
||||||
keep_com = 1 ;
|
{
|
||||||
} else if (!strcmp(argv[i], "-n")) {
|
fprintf (stderr, "option -k needs an argument\n");
|
||||||
numeric = 1 ;
|
return -1;
|
||||||
} else {
|
}
|
||||||
break ;
|
i++;
|
||||||
}
|
key = strdup (argv[i]);
|
||||||
i++ ;
|
}
|
||||||
}
|
else if (!strcmp (argv[i], "-v"))
|
||||||
|
{
|
||||||
/* Check options coherence */
|
if ((i + 1) >= argc)
|
||||||
if ((keep_com == 1) && (com != NULL)) {
|
{
|
||||||
fprintf(stderr, "options -c and -C should not be used together\n") ;
|
fprintf (stderr, "option -v needs an argument\n");
|
||||||
if (place) free(place) ;
|
return -1;
|
||||||
if (key) free(key) ;
|
}
|
||||||
if (val) free(val) ;
|
i++;
|
||||||
free(com) ;
|
val = strdup (argv[i]);
|
||||||
return -1 ;
|
}
|
||||||
}
|
else if (!strcmp (argv[i], "-c"))
|
||||||
if (place == NULL) {
|
{
|
||||||
fprintf(stderr, "options -p has to be used\n") ;
|
if ((i + 1) >= argc)
|
||||||
if (key) free(key) ;
|
{
|
||||||
if (val) free(val) ;
|
fprintf (stderr, "option -c needs an argument\n");
|
||||||
if (com) free(com) ;
|
return -1;
|
||||||
return -1 ;
|
}
|
||||||
|
i++;
|
||||||
|
com = strdup (argv[i]);
|
||||||
|
}
|
||||||
|
else if (!strcmp (argv[i], "-C"))
|
||||||
|
{
|
||||||
|
keep_com = 1;
|
||||||
|
}
|
||||||
|
else if (!strcmp (argv[i], "-n"))
|
||||||
|
{
|
||||||
|
numeric = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get input file name */
|
/* Check options coherence */
|
||||||
if ((argc-i)<1) {
|
if ((keep_com == 1) && (com != NULL))
|
||||||
fprintf(stderr, "missing input file name\n");
|
{
|
||||||
return -1 ;
|
fprintf (stderr, "options -c and -C should not be used together\n");
|
||||||
|
if (place)
|
||||||
|
free (place);
|
||||||
|
if (key)
|
||||||
|
free (key);
|
||||||
|
if (val)
|
||||||
|
free (val);
|
||||||
|
free (com);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (place == NULL)
|
||||||
/* Loop on the input files */
|
{
|
||||||
while (argc-i >= 1) {
|
fprintf (stderr, "options -p has to be used\n");
|
||||||
name_in = strdup(argv[i]) ;
|
if (key)
|
||||||
|
free (key);
|
||||||
/* Set keyword to write */
|
if (val)
|
||||||
key_tmp = NULL ;
|
free (val);
|
||||||
if (key==NULL) key_tmp = strdup(place) ;
|
if (com)
|
||||||
else key_tmp = strdup(key) ;
|
free (com);
|
||||||
|
return -1;
|
||||||
/* Set value to write */
|
|
||||||
val_tmp = NULL ;
|
|
||||||
if (val==NULL) {
|
|
||||||
card = qfits_query_card(name_in, place) ;
|
|
||||||
if (card!= NULL) {
|
|
||||||
stmp = qfits_getvalue(card) ;
|
|
||||||
val_tmp = strdup(stmp) ;
|
|
||||||
}
|
|
||||||
} else val_tmp = strdup(val) ;
|
|
||||||
|
|
||||||
com_tmp = NULL ;
|
|
||||||
/* Set comment to write */
|
|
||||||
if ((com == NULL) && (keep_com == 1)) {
|
|
||||||
if (card == NULL) card = qfits_query_card(name_in, place) ;
|
|
||||||
if (card != NULL) {
|
|
||||||
stmp = qfits_getcomment(card) ;
|
|
||||||
com_tmp = strdup(stmp) ;
|
|
||||||
}
|
|
||||||
} else if (com != NULL) com_tmp = strdup(com) ;
|
|
||||||
if (card != NULL) free(card) ;
|
|
||||||
card = NULL ;
|
|
||||||
printf("DEBUG: %s\n", key_tmp) ;
|
|
||||||
|
|
||||||
/* Create the card */
|
|
||||||
keytuple2str(card_tmp, key_tmp, val_tmp, com_tmp) ;
|
|
||||||
if (key_tmp) free(key_tmp) ;
|
|
||||||
if (val_tmp) free(val_tmp) ;
|
|
||||||
if (com_tmp) free(com_tmp) ;
|
|
||||||
card = strdup(card_tmp) ;
|
|
||||||
|
|
||||||
/* Display what will be written where */
|
|
||||||
printf("File %s\n", name_in) ;
|
|
||||||
printf("\tcard : \n\t\t%s\n", card) ;
|
|
||||||
printf("\tplace : \n\t\t%s\n", place) ;
|
|
||||||
|
|
||||||
/* Try to replace the first key */
|
|
||||||
if (qfits_replace_card(name_in, place, card) == -1) {
|
|
||||||
fprintf(stderr, "cannot replace the key %s\n", place) ;
|
|
||||||
}
|
|
||||||
free(name_in);
|
|
||||||
free(card) ;
|
|
||||||
card = NULL ;
|
|
||||||
i++ ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val) free(val) ;
|
/* Get input file name */
|
||||||
if (com) free(com) ;
|
if ((argc - i) < 1)
|
||||||
if (key) free(key) ;
|
{
|
||||||
free(place) ;
|
fprintf (stderr, "missing input file name\n");
|
||||||
/* Free and return */
|
return -1;
|
||||||
return 0 ;
|
}
|
||||||
|
|
||||||
|
/* Loop on the input files */
|
||||||
|
while (argc - i >= 1)
|
||||||
|
{
|
||||||
|
name_in = strdup (argv[i]);
|
||||||
|
|
||||||
|
/* Set keyword to write */
|
||||||
|
key_tmp = NULL;
|
||||||
|
if (key == NULL)
|
||||||
|
key_tmp = strdup (place);
|
||||||
|
else
|
||||||
|
key_tmp = strdup (key);
|
||||||
|
|
||||||
|
/* Set value to write */
|
||||||
|
val_tmp = NULL;
|
||||||
|
if (val == NULL)
|
||||||
|
{
|
||||||
|
card = qfits_query_card (name_in, place);
|
||||||
|
if (card != NULL)
|
||||||
|
{
|
||||||
|
stmp = qfits_getvalue (card);
|
||||||
|
val_tmp = strdup (stmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
val_tmp = strdup (val);
|
||||||
|
|
||||||
|
com_tmp = NULL;
|
||||||
|
/* Set comment to write */
|
||||||
|
if ((com == NULL) && (keep_com == 1))
|
||||||
|
{
|
||||||
|
if (card == NULL)
|
||||||
|
card = qfits_query_card (name_in, place);
|
||||||
|
if (card != NULL)
|
||||||
|
{
|
||||||
|
stmp = qfits_getcomment (card);
|
||||||
|
com_tmp = strdup (stmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (com != NULL)
|
||||||
|
com_tmp = strdup (com);
|
||||||
|
if (card != NULL)
|
||||||
|
free (card);
|
||||||
|
card = NULL;
|
||||||
|
printf ("DEBUG: %s\n", key_tmp);
|
||||||
|
|
||||||
|
/* Create the card */
|
||||||
|
keytuple2str (card_tmp, key_tmp, val_tmp, com_tmp);
|
||||||
|
if (key_tmp)
|
||||||
|
free (key_tmp);
|
||||||
|
if (val_tmp)
|
||||||
|
free (val_tmp);
|
||||||
|
if (com_tmp)
|
||||||
|
free (com_tmp);
|
||||||
|
card = strdup (card_tmp);
|
||||||
|
|
||||||
|
/* Display what will be written where */
|
||||||
|
printf ("File %s\n", name_in);
|
||||||
|
printf ("\tcard : \n\t\t%s\n", card);
|
||||||
|
printf ("\tplace : \n\t\t%s\n", place);
|
||||||
|
|
||||||
|
/* Try to replace the first key */
|
||||||
|
if (qfits_replace_card (name_in, place, card) == -1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "cannot replace the key %s\n", place);
|
||||||
|
}
|
||||||
|
free (name_in);
|
||||||
|
free (card);
|
||||||
|
card = NULL;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val)
|
||||||
|
free (val);
|
||||||
|
if (com)
|
||||||
|
free (com);
|
||||||
|
if (key)
|
||||||
|
free (key);
|
||||||
|
free (place);
|
||||||
|
/* Free and return */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(char * pname)
|
static void
|
||||||
|
usage (char *pname)
|
||||||
{
|
{
|
||||||
printf("%s : %s\n", pname, prog_desc) ;
|
printf ("%s : %s\n", pname, prog_desc);
|
||||||
printf(
|
printf ("use : %s [options] <in>\n"
|
||||||
"use : %s [options] <in>\n"
|
"options are:\n"
|
||||||
"options are:\n"
|
"\t-p place gives the keyword to write over (required).\n"
|
||||||
"\t-p place gives the keyword to write over (required).\n"
|
"\t-k key gives the new keyword name (optional).\n"
|
||||||
"\t-k key gives the new keyword name (optional).\n"
|
"\t-v val gives the value to write (optional).\n"
|
||||||
"\t-v val gives the value to write (optional).\n"
|
"\t-c com gives the comment to write (optional).\n"
|
||||||
"\t-c com gives the comment to write (optional).\n"
|
"\t-C flag to keep comment\n" "\n", pname);
|
||||||
"\t-C flag to keep comment\n"
|
exit (0);
|
||||||
"\n", pname) ;
|
|
||||||
exit(0) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1231
qfits/saft/fitsmd5.c
1231
qfits/saft/fitsmd5.c
File diff suppressed because it is too large
Load Diff
|
@ -52,8 +52,8 @@
|
||||||
Define
|
Define
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define MAX_STRING 128
|
#define MAX_STRING 128
|
||||||
#define MAX_KEY 512
|
#define MAX_KEY 512
|
||||||
#define FMT_STRING "%%-%ds\t"
|
#define FMT_STRING "%%-%ds\t"
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -61,147 +61,178 @@
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* This holds a keyword value and a flag to indicate its presence */
|
/* This holds a keyword value and a flag to indicate its presence */
|
||||||
typedef struct _KEYWORD_ {
|
typedef struct _KEYWORD_
|
||||||
char value[MAX_STRING] ;
|
{
|
||||||
int present ;
|
char value[MAX_STRING];
|
||||||
} keyword ;
|
int present;
|
||||||
|
} keyword;
|
||||||
|
|
||||||
/* Each detected file in input has such an associated structure */
|
/* Each detected file in input has such an associated structure */
|
||||||
typedef struct _RECORD_ {
|
typedef struct _RECORD_
|
||||||
char filename[MAX_STRING] ;
|
{
|
||||||
keyword listkw[MAX_KEY] ;
|
char filename[MAX_STRING];
|
||||||
} record ;
|
keyword listkw[MAX_KEY];
|
||||||
|
} record;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static int isfilename(char *string) ;
|
static int isfilename (char *string);
|
||||||
static void getfilename(char *line, char *word) ;
|
static void getfilename (char *line, char *word);
|
||||||
static char * expand_hierarch_keyword(char *, char *) ;
|
static char *expand_hierarch_keyword (char *, char *);
|
||||||
static int isdetectedkeyword(char *line, char *keywords[], int nkeys) ;
|
static int isdetectedkeyword (char *line, char *keywords[], int nkeys);
|
||||||
static void getkeywordvalue(char *line, char *word) ;
|
static void getkeywordvalue (char *line, char *word);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char curline[MAX_STRING] ;
|
char curline[MAX_STRING];
|
||||||
char word[MAX_STRING] ;
|
char word[MAX_STRING];
|
||||||
int i, j ;
|
int i, j;
|
||||||
int nfiles ;
|
int nfiles;
|
||||||
record *allrecords ;
|
record *allrecords;
|
||||||
int kwnum ;
|
int kwnum;
|
||||||
int len ;
|
int len;
|
||||||
int max_width[MAX_KEY] ;
|
int max_width[MAX_KEY];
|
||||||
int max_filnam ;
|
int max_filnam;
|
||||||
char fmt[8] ;
|
char fmt[8];
|
||||||
int flag ;
|
int flag;
|
||||||
int printnames ;
|
int printnames;
|
||||||
int print_hdr ;
|
int print_hdr;
|
||||||
|
|
||||||
if (argc<2) {
|
if (argc < 2)
|
||||||
printf("\n\nuse : %s [-d] KEY1 KEY2 ... KEYn\n", argv[0]) ;
|
{
|
||||||
printf("Input data is received from stdin\n") ;
|
printf ("\n\nuse : %s [-d] KEY1 KEY2 ... KEYn\n", argv[0]);
|
||||||
printf("See man page for more details and examples\n\n") ;
|
printf ("Input data is received from stdin\n");
|
||||||
return 0 ;
|
printf ("See man page for more details and examples\n\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize */
|
/* Initialize */
|
||||||
printnames = 0 ;
|
printnames = 0;
|
||||||
print_hdr = 1 ;
|
print_hdr = 1;
|
||||||
nfiles = 0 ;
|
nfiles = 0;
|
||||||
allrecords = (record*)calloc(1, sizeof(record));
|
allrecords = (record *) calloc (1, sizeof (record));
|
||||||
if (!strcmp(argv[1], "-d")) {
|
if (!strcmp (argv[1], "-d"))
|
||||||
print_hdr = 0;
|
{
|
||||||
argv++ ;
|
print_hdr = 0;
|
||||||
argc-- ;
|
argv++;
|
||||||
}
|
argc--;
|
||||||
argv++ ;
|
|
||||||
|
|
||||||
/* Uppercase all inputs */
|
|
||||||
for (i=0 ; i<(argc-1) ; i++) {
|
|
||||||
j=0 ;
|
|
||||||
while (argv[i][j]!=0) {
|
|
||||||
argv[i][j] = toupper(argv[i][j]);
|
|
||||||
j++ ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (fgets(curline, MAX_STRING, stdin) != (char*)NULL) {
|
|
||||||
flag=isfilename(curline) ;
|
|
||||||
if (flag == 1) {
|
|
||||||
/* New file name is detected, get the new file name */
|
|
||||||
printnames = 1 ;
|
|
||||||
getfilename(curline, allrecords[nfiles].filename) ;
|
|
||||||
nfiles++ ;
|
|
||||||
|
|
||||||
/* Initialize a new record structure to store data for this file. */
|
|
||||||
allrecords = (record*)realloc(allrecords,(nfiles+1)*sizeof(record));
|
|
||||||
for (i=0 ; i<MAX_KEY ; i++) allrecords[nfiles].listkw[i].present=0;
|
|
||||||
} else if (flag==0) {
|
|
||||||
/* Is not a file name, is it a searched keyword? */
|
|
||||||
if ((kwnum = isdetectedkeyword( curline, argv, argc-1)) != -1) {
|
|
||||||
/* Is there anything allocated yet to store this? */
|
|
||||||
if (nfiles>0) {
|
|
||||||
/* It has been detected as a searched keyword. */
|
|
||||||
/* Get its value, store it, present flag up */
|
|
||||||
getkeywordvalue(curline, word) ;
|
|
||||||
strcpy(allrecords[nfiles-1].listkw[kwnum].value, word) ;
|
|
||||||
allrecords[nfiles-1].listkw[kwnum].present ++ ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (i=0 ; i<argc-1 ; i++) max_width[i] = (int)strlen(argv[i]) ;
|
argv++;
|
||||||
|
|
||||||
/* Record the maximum width for each column */
|
/* Uppercase all inputs */
|
||||||
max_filnam = 0 ;
|
for (i = 0; i < (argc - 1); i++)
|
||||||
for (i=0 ; i<nfiles ; i++) {
|
{
|
||||||
len = (int)strlen(allrecords[i].filename) ;
|
j = 0;
|
||||||
if (len>max_filnam) max_filnam=len ;
|
while (argv[i][j] != 0)
|
||||||
for (kwnum=0 ; kwnum<argc-1 ; kwnum++) {
|
{
|
||||||
if (allrecords[i].listkw[kwnum].present) {
|
argv[i][j] = toupper (argv[i][j]);
|
||||||
len = (int)strlen(allrecords[i].listkw[kwnum].value) ;
|
j++;
|
||||||
} else {
|
|
||||||
len = 0 ;
|
|
||||||
}
|
|
||||||
if (len>max_width[kwnum]) max_width[kwnum] = len ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print out header line */
|
|
||||||
if (print_hdr) {
|
|
||||||
sprintf(fmt, FMT_STRING, max_filnam) ;
|
|
||||||
if (printnames) printf(fmt, "FILE");
|
|
||||||
for (i=0 ; i<argc-1 ; i++) {
|
|
||||||
sprintf(fmt, FMT_STRING, max_width[i]) ;
|
|
||||||
printf(fmt, argv[i]) ;
|
|
||||||
}
|
|
||||||
printf("\n") ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now print out stored data */
|
|
||||||
if (nfiles<1) {
|
|
||||||
printf("*** error: no input data corresponding to dfits output\n");
|
|
||||||
return -1 ;
|
|
||||||
}
|
|
||||||
for (i=0 ; i<nfiles ; i++) {
|
|
||||||
if (printnames) {
|
|
||||||
sprintf(fmt, FMT_STRING, max_filnam) ;
|
|
||||||
printf(fmt, allrecords[i].filename) ;
|
|
||||||
}
|
|
||||||
for (kwnum=0 ; kwnum<argc-1 ; kwnum++) {
|
|
||||||
sprintf(fmt, FMT_STRING, max_width[kwnum]);
|
|
||||||
if (allrecords[i].listkw[kwnum].present)
|
|
||||||
printf(fmt, allrecords[i].listkw[kwnum].value) ;
|
|
||||||
else printf(fmt, " ");
|
|
||||||
}
|
|
||||||
printf("\n") ;
|
|
||||||
}
|
}
|
||||||
free(allrecords) ;
|
|
||||||
return 0 ;
|
while (fgets (curline, MAX_STRING, stdin) != (char *) NULL)
|
||||||
|
{
|
||||||
|
flag = isfilename (curline);
|
||||||
|
if (flag == 1)
|
||||||
|
{
|
||||||
|
/* New file name is detected, get the new file name */
|
||||||
|
printnames = 1;
|
||||||
|
getfilename (curline, allrecords[nfiles].filename);
|
||||||
|
nfiles++;
|
||||||
|
|
||||||
|
/* Initialize a new record structure to store data for this file. */
|
||||||
|
allrecords =
|
||||||
|
(record *) realloc (allrecords, (nfiles + 1) * sizeof (record));
|
||||||
|
for (i = 0; i < MAX_KEY; i++)
|
||||||
|
allrecords[nfiles].listkw[i].present = 0;
|
||||||
|
}
|
||||||
|
else if (flag == 0)
|
||||||
|
{
|
||||||
|
/* Is not a file name, is it a searched keyword? */
|
||||||
|
if ((kwnum = isdetectedkeyword (curline, argv, argc - 1)) != -1)
|
||||||
|
{
|
||||||
|
/* Is there anything allocated yet to store this? */
|
||||||
|
if (nfiles > 0)
|
||||||
|
{
|
||||||
|
/* It has been detected as a searched keyword. */
|
||||||
|
/* Get its value, store it, present flag up */
|
||||||
|
getkeywordvalue (curline, word);
|
||||||
|
strcpy (allrecords[nfiles - 1].listkw[kwnum].value, word);
|
||||||
|
allrecords[nfiles - 1].listkw[kwnum].present++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < argc - 1; i++)
|
||||||
|
max_width[i] = (int) strlen (argv[i]);
|
||||||
|
|
||||||
|
/* Record the maximum width for each column */
|
||||||
|
max_filnam = 0;
|
||||||
|
for (i = 0; i < nfiles; i++)
|
||||||
|
{
|
||||||
|
len = (int) strlen (allrecords[i].filename);
|
||||||
|
if (len > max_filnam)
|
||||||
|
max_filnam = len;
|
||||||
|
for (kwnum = 0; kwnum < argc - 1; kwnum++)
|
||||||
|
{
|
||||||
|
if (allrecords[i].listkw[kwnum].present)
|
||||||
|
{
|
||||||
|
len = (int) strlen (allrecords[i].listkw[kwnum].value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
if (len > max_width[kwnum])
|
||||||
|
max_width[kwnum] = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print out header line */
|
||||||
|
if (print_hdr)
|
||||||
|
{
|
||||||
|
sprintf (fmt, FMT_STRING, max_filnam);
|
||||||
|
if (printnames)
|
||||||
|
printf (fmt, "FILE");
|
||||||
|
for (i = 0; i < argc - 1; i++)
|
||||||
|
{
|
||||||
|
sprintf (fmt, FMT_STRING, max_width[i]);
|
||||||
|
printf (fmt, argv[i]);
|
||||||
|
}
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now print out stored data */
|
||||||
|
if (nfiles < 1)
|
||||||
|
{
|
||||||
|
printf ("*** error: no input data corresponding to dfits output\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (i = 0; i < nfiles; i++)
|
||||||
|
{
|
||||||
|
if (printnames)
|
||||||
|
{
|
||||||
|
sprintf (fmt, FMT_STRING, max_filnam);
|
||||||
|
printf (fmt, allrecords[i].filename);
|
||||||
|
}
|
||||||
|
for (kwnum = 0; kwnum < argc - 1; kwnum++)
|
||||||
|
{
|
||||||
|
sprintf (fmt, FMT_STRING, max_width[kwnum]);
|
||||||
|
if (allrecords[i].listkw[kwnum].present)
|
||||||
|
printf (fmt, allrecords[i].listkw[kwnum].value);
|
||||||
|
else
|
||||||
|
printf (fmt, " ");
|
||||||
|
}
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
free (allrecords);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -218,11 +249,14 @@ int main(int argc, char *argv[])
|
||||||
extension, 0 otherwise.
|
extension, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int isfilename(char * string)
|
static int
|
||||||
|
isfilename (char *string)
|
||||||
{
|
{
|
||||||
if (!strncmp(string, "====>", 5)) return 1 ;
|
if (!strncmp (string, "====>", 5))
|
||||||
if (!strncmp(string, "===>", 4)) return 2 ;
|
return 1;
|
||||||
return 0 ;
|
if (!strncmp (string, "===>", 4))
|
||||||
|
return 2;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -234,13 +268,14 @@ static int isfilename(char * string)
|
||||||
This is dfits dependent.
|
This is dfits dependent.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void getfilename(char * line, char * word)
|
static void
|
||||||
|
getfilename (char *line, char *word)
|
||||||
{
|
{
|
||||||
/* get filename from a dfits output */
|
/* get filename from a dfits output */
|
||||||
sscanf(line, "%*s %*s %s", word) ;
|
sscanf (line, "%*s %*s %s", word);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief detects a if a keyword is present in a FITS line
|
@brief detects a if a keyword is present in a FITS line
|
||||||
|
@ -254,41 +289,45 @@ static void getfilename(char * line, char * word)
|
||||||
otherwise, -1 is returned.
|
otherwise, -1 is returned.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int isdetectedkeyword(
|
static int
|
||||||
char * line,
|
isdetectedkeyword (char *line, char *keywords[], int nkeys)
|
||||||
char * keywords[],
|
|
||||||
int nkeys)
|
|
||||||
{
|
{
|
||||||
char kw[MAX_STRING] ;
|
char kw[MAX_STRING];
|
||||||
char esokw[MAX_STRING] ;
|
char esokw[MAX_STRING];
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
/* The keyword is up to the equal character, with trailing blanks removed */
|
/* The keyword is up to the equal character, with trailing blanks removed */
|
||||||
strcpy(kw, line) ;
|
strcpy (kw, line);
|
||||||
strtok(kw, "=") ;
|
strtok (kw, "=");
|
||||||
/* Now remove all trailing blanks (if any) */
|
/* Now remove all trailing blanks (if any) */
|
||||||
i = (int)strlen(kw) -1 ;
|
i = (int) strlen (kw) - 1;
|
||||||
while (kw[i] == ' ') i -- ;
|
while (kw[i] == ' ')
|
||||||
kw[i+1] = (char)0 ;
|
i--;
|
||||||
|
kw[i + 1] = (char) 0;
|
||||||
/* Now compare what we got with what's available */
|
|
||||||
for (i=0 ; i<nkeys ; i++) {
|
/* Now compare what we got with what's available */
|
||||||
if (strstr(keywords[i], ".")!=NULL) {
|
for (i = 0; i < nkeys; i++)
|
||||||
/*
|
{
|
||||||
* keyword contains a dot, it is a hierarchical keyword that
|
if (strstr (keywords[i], ".") != NULL)
|
||||||
* must be expanded. Pattern is:
|
{
|
||||||
* A.B.C... becomes HIERARCH ESO A B C ...
|
/*
|
||||||
*/
|
* keyword contains a dot, it is a hierarchical keyword that
|
||||||
expand_hierarch_keyword(keywords[i], esokw) ;
|
* must be expanded. Pattern is:
|
||||||
if (!strcmp(kw, esokw)) {
|
* A.B.C... becomes HIERARCH ESO A B C ...
|
||||||
return i ;
|
*/
|
||||||
}
|
expand_hierarch_keyword (keywords[i], esokw);
|
||||||
} else if (!strcmp(kw, keywords[i])) {
|
if (!strcmp (kw, esokw))
|
||||||
return i ;
|
{
|
||||||
}
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!strcmp (kw, keywords[i]))
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Keyword not found */
|
/* Keyword not found */
|
||||||
return -1 ;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -299,22 +338,22 @@ static int isdetectedkeyword(
|
||||||
@return char *, pointer to second input string (modified)
|
@return char *, pointer to second input string (modified)
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static char * expand_hierarch_keyword(
|
static char *
|
||||||
char * dotkey,
|
expand_hierarch_keyword (char *dotkey, char *hierarchy)
|
||||||
char * hierarchy)
|
|
||||||
{
|
{
|
||||||
char * token ;
|
char *token;
|
||||||
char ws[MAX_STRING] ;
|
char ws[MAX_STRING];
|
||||||
|
|
||||||
sprintf(hierarchy, "HIERARCH ESO");
|
sprintf (hierarchy, "HIERARCH ESO");
|
||||||
strcpy(ws, dotkey) ;
|
strcpy (ws, dotkey);
|
||||||
token = strtok(ws, ".") ;
|
token = strtok (ws, ".");
|
||||||
while (token!=NULL) {
|
while (token != NULL)
|
||||||
strcat(hierarchy, " ") ;
|
{
|
||||||
strcat(hierarchy, token) ;
|
strcat (hierarchy, " ");
|
||||||
token = strtok(NULL, ".");
|
strcat (hierarchy, token);
|
||||||
}
|
token = strtok (NULL, ".");
|
||||||
return hierarchy ;
|
}
|
||||||
|
return hierarchy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -326,48 +365,54 @@ static char * expand_hierarch_keyword(
|
||||||
No complex value is recognized
|
No complex value is recognized
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void getkeywordvalue(
|
static void
|
||||||
char * line,
|
getkeywordvalue (char *line, char *word)
|
||||||
char * word)
|
|
||||||
{
|
{
|
||||||
int c, w ;
|
int c, w;
|
||||||
char tmp[MAX_STRING] ;
|
char tmp[MAX_STRING];
|
||||||
char *begin, *end ;
|
char *begin, *end;
|
||||||
int length ;
|
int length;
|
||||||
int quote = 0 ;
|
int quote = 0;
|
||||||
int search = 1 ;
|
int search = 1;
|
||||||
|
|
||||||
memset(tmp, (char)0, MAX_STRING) ;
|
memset (tmp, (char) 0, MAX_STRING);
|
||||||
memset(word, (char)0, MAX_STRING) ;
|
memset (word, (char) 0, MAX_STRING);
|
||||||
c = w = 0;
|
c = w = 0;
|
||||||
|
|
||||||
/* Parse the line till the equal '=' sign is found */
|
/* Parse the line till the equal '=' sign is found */
|
||||||
while (line[c] != '=') c++ ;
|
while (line[c] != '=')
|
||||||
c++ ;
|
c++;
|
||||||
|
c++;
|
||||||
|
|
||||||
/* Copy the line till the slash '/' sign or the end of data is found. */
|
/* Copy the line till the slash '/' sign or the end of data is found. */
|
||||||
while (search == 1) {
|
while (search == 1)
|
||||||
if (c>=80) search = 0 ;
|
{
|
||||||
else if ((line[c] == '/') && (quote == 0)) search = 0 ;
|
if (c >= 80)
|
||||||
if (line[c] == '\'') quote = !quote ;
|
search = 0;
|
||||||
tmp[w++] = line[c++] ;
|
else if ((line[c] == '/') && (quote == 0))
|
||||||
|
search = 0;
|
||||||
|
if (line[c] == '\'')
|
||||||
|
quote = !quote;
|
||||||
|
tmp[w++] = line[c++];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NULL termination of the string */
|
|
||||||
tmp[--w] = (char)0 ;
|
|
||||||
|
|
||||||
/* Return the keyword only : a diff is made between text fields and nbs. */
|
/* NULL termination of the string */
|
||||||
if ((begin = strchr(tmp, '\'')) != (char*)NULL) {
|
tmp[--w] = (char) 0;
|
||||||
/* A quote has been found: it is a string value */
|
|
||||||
begin++ ;
|
/* Return the keyword only : a diff is made between text fields and nbs. */
|
||||||
end = strrchr(tmp, '\'') ;
|
if ((begin = strchr (tmp, '\'')) != (char *) NULL)
|
||||||
length = (int)strlen(begin) - (int)strlen(end) ;
|
{
|
||||||
strncpy(word, begin, length) ;
|
/* A quote has been found: it is a string value */
|
||||||
} else {
|
begin++;
|
||||||
/* No quote, just get the value (only one, no complex supported) */
|
end = strrchr (tmp, '\'');
|
||||||
sscanf(tmp, "%s", word) ;
|
length = (int) strlen (begin) - (int) strlen (end);
|
||||||
|
strncpy (word, begin, length);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return ;
|
{
|
||||||
|
/* No quote, just get the value (only one, no complex supported) */
|
||||||
|
sscanf (tmp, "%s", word);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,136 +40,136 @@
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static char prog_desc[] = "header conversion from ESO to standard FITS" ;
|
static char prog_desc[] = "header conversion from ESO to standard FITS";
|
||||||
static void usage(char *) ;
|
static void usage (char *);
|
||||||
static int convert_eso_to_std_FITS(char *, char *) ;
|
static int convert_eso_to_std_FITS (char *, char *);
|
||||||
static void free_keys(char **, int n) ;
|
static void free_keys (char **, int n);
|
||||||
static void strip_beg_end(char *) ;
|
static void strip_beg_end (char *);
|
||||||
static int search_and_replace_kw(char *, int, char **, char **, int) ;
|
static int search_and_replace_kw (char *, int, char **, char **, int);
|
||||||
static void search_rep(char *, char *, char *);
|
static void search_rep (char *, char *, char *);
|
||||||
static void generate_default_convtab(void);
|
static void generate_default_convtab (void);
|
||||||
static char * convert_deg_to_str(double deg) ;
|
static char *convert_deg_to_str (double deg);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Static variables
|
Static variables
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static char CONVTAB_DEFAULT1[] =
|
static char CONVTAB_DEFAULT1[] =
|
||||||
"#\n"
|
"#\n"
|
||||||
"# Example of conversion table for hierarch28\n"
|
"# Example of conversion table for hierarch28\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# A note about this file's format:\n"
|
"# A note about this file's format:\n"
|
||||||
"# Any blank line or line starting with a hash is ignored.\n"
|
"# Any blank line or line starting with a hash is ignored.\n"
|
||||||
"# Declare the keyword names to search and replace with:\n"
|
"# Declare the keyword names to search and replace with:\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# OLDKEYWORD = NEWKEYWORD\n"
|
"# OLDKEYWORD = NEWKEYWORD\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# Spaces are allowed within keyword names, to allow e.g.:\n"
|
"# Spaces are allowed within keyword names, to allow e.g.:\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# HIERARCH ESO DET NDIT = DET NDIT\n"
|
"# HIERARCH ESO DET NDIT = DET NDIT\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# The most important restriction is that new keywords shall not be\n"
|
"# The most important restriction is that new keywords shall not be\n"
|
||||||
"# longer than the keywords they replace.\n"
|
"# longer than the keywords they replace.\n" "#\n";
|
||||||
"#\n" ;
|
|
||||||
|
|
||||||
|
|
||||||
static char CONVTAB_DEFAULT2[] =
|
static char CONVTAB_DEFAULT2[] =
|
||||||
"#\n"
|
"#\n"
|
||||||
"# Translation table for basic keywords used by IRAF\n"
|
"# Translation table for basic keywords used by IRAF\n"
|
||||||
"# -------------------------------------------------\n"
|
"# -------------------------------------------------\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# Note: hierarch28 will replace keywords in the main header\n"
|
"# Note: hierarch28 will replace keywords in the main header\n"
|
||||||
"# and also in extensions.\n"
|
"# and also in extensions.\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# Disclaimer:\n"
|
"# Disclaimer:\n"
|
||||||
"# this table has been compiled to best knowledge of present\n"
|
"# this table has been compiled to best knowledge of present\n"
|
||||||
"# IRAF packages. Please let us know of any addition/change.\n"
|
"# IRAF packages. Please let us know of any addition/change.\n"
|
||||||
"#\n"
|
"#\n" "\n";
|
||||||
"\n" ;
|
|
||||||
|
|
||||||
|
|
||||||
static char CONVTAB_DEFAULT3[] =
|
static char CONVTAB_DEFAULT3[] =
|
||||||
"UTC = UT\n"
|
"UTC = UT\n"
|
||||||
"LST = ST\n"
|
"LST = ST\n"
|
||||||
"RA = RA\n"
|
"RA = RA\n"
|
||||||
"DEC = DEC\n"
|
"DEC = DEC\n"
|
||||||
"\n"
|
"\n"
|
||||||
"HIERARCH ESO TEL AIRM START = AIRMASS\n"
|
"HIERARCH ESO TEL AIRM START = AIRMASS\n"
|
||||||
"HIERARCH ESO DPR TYPE = IMAGETYP\n"
|
"HIERARCH ESO DPR TYPE = IMAGETYP\n"
|
||||||
"HIERARCH ESO INS FILT1 NAME = FILTER1\n"
|
"HIERARCH ESO INS FILT1 NAME = FILTER1\n"
|
||||||
"HIERARCH ESO INS SLIT2 NAME = SLIT\n"
|
"HIERARCH ESO INS SLIT2 NAME = SLIT\n"
|
||||||
"HIERARCH ESO INS GRIS1 NAME = GRISM\n"
|
"HIERARCH ESO INS GRIS1 NAME = GRISM\n"
|
||||||
"HIERARCH ESO INS GRAT NAME = GRAT\n"
|
"HIERARCH ESO INS GRAT NAME = GRAT\n"
|
||||||
"HIERARCH ESO INS GRAT1 NAME = GRAT1\n"
|
"HIERARCH ESO INS GRAT1 NAME = GRAT1\n"
|
||||||
"HIERARCH ESO INS GRAT2 NAME = GRAT2\n"
|
"HIERARCH ESO INS GRAT2 NAME = GRAT2\n"
|
||||||
"HIERARCH ESO INS GRAT WLEN = WLEN\n"
|
"HIERARCH ESO INS GRAT WLEN = WLEN\n"
|
||||||
"HIERARCH ESO INS GRAT1 WLEN = WLEN1\n"
|
"HIERARCH ESO INS GRAT1 WLEN = WLEN1\n"
|
||||||
"HIERARCH ESO INS GRAT2 WLEN = WLEN2\n"
|
"HIERARCH ESO INS GRAT2 WLEN = WLEN2\n"
|
||||||
"HIERARCH ESO INS GRAT ORDER = ORDER\n"
|
"HIERARCH ESO INS GRAT ORDER = ORDER\n" "\n";
|
||||||
"\n" ;
|
|
||||||
|
|
||||||
static char CONVTAB_DEFAULT4[] =
|
static char CONVTAB_DEFAULT4[] =
|
||||||
"#\n"
|
"#\n"
|
||||||
"# A note for IRAF users:\n"
|
"# A note for IRAF users:\n"
|
||||||
"# Be aware also that the ESO convention names the keywords UTC and\n"
|
"# Be aware also that the ESO convention names the keywords UTC and\n"
|
||||||
"# LST, whereas the IRAF convention is 'UT' and 'ST'.\n"
|
"# LST, whereas the IRAF convention is 'UT' and 'ST'.\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# The ESO standard (see http://archive.eso.org/dicb) defines these\n"
|
"# The ESO standard (see http://archive.eso.org/dicb) defines these\n"
|
||||||
"# keywords as floating point values with the units degrees for RA/DEC\n"
|
"# keywords as floating point values with the units degrees for RA/DEC\n"
|
||||||
"# and elapsed seconds since midnight for UT/ST.\n"
|
"# and elapsed seconds since midnight for UT/ST.\n"
|
||||||
"#\n"
|
"#\n"
|
||||||
"# In order to have this tranlation performed, add\n"
|
"# In order to have this tranlation performed, add\n"
|
||||||
"# RA = RA\n"
|
"# RA = RA\n"
|
||||||
"# DEC = DEC\n"
|
"# DEC = DEC\n"
|
||||||
"# UTC = UT\n"
|
"# UTC = UT\n" "# LST = ST\n" "# to the conversion table.\n" "#\n";
|
||||||
"# LST = ST\n"
|
|
||||||
"# to the conversion table.\n"
|
|
||||||
"#\n";
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char name_conv[NM_SIZ] ;
|
char name_conv[NM_SIZ];
|
||||||
char name_in[NM_SIZ] ;
|
char name_in[NM_SIZ];
|
||||||
|
|
||||||
if (argc<2) usage(argv[0]) ;
|
if (argc < 2)
|
||||||
if (!strcmp(argv[1], "-g")) {
|
usage (argv[0]);
|
||||||
generate_default_convtab() ;
|
if (!strcmp (argv[1], "-g"))
|
||||||
return 0 ;
|
{
|
||||||
}
|
generate_default_convtab ();
|
||||||
|
return 0;
|
||||||
strcpy(name_in, argv[1]) ;
|
|
||||||
if (argc==3) {
|
|
||||||
strcpy(name_conv, argv[2]) ;
|
|
||||||
} else {
|
|
||||||
strcpy(name_conv, "table.conv") ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convert_eso_to_std_FITS(name_in, name_conv) != 0) {
|
strcpy (name_in, argv[1]);
|
||||||
fprintf(stderr, "error during conversion: aborting\n") ;
|
if (argc == 3)
|
||||||
|
{
|
||||||
|
strcpy (name_conv, argv[2]);
|
||||||
}
|
}
|
||||||
return 0 ;
|
else
|
||||||
|
{
|
||||||
|
strcpy (name_conv, "table.conv");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convert_eso_to_std_FITS (name_in, name_conv) != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "error during conversion: aborting\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(char * pname)
|
static void
|
||||||
|
usage (char *pname)
|
||||||
{
|
{
|
||||||
printf(
|
printf ("\n\n"
|
||||||
"\n\n"
|
"hierarch28 (hierarch-to-eight)\n"
|
||||||
"hierarch28 (hierarch-to-eight)\n"
|
"%s : %s\n"
|
||||||
"%s : %s\n"
|
"use : %s [options] <in> [table]\n"
|
||||||
"use : %s [options] <in> [table]\n"
|
"options are:\n"
|
||||||
"options are:\n"
|
"\t-g generates a generic table\n"
|
||||||
"\t-g generates a generic table\n"
|
"\n"
|
||||||
"\n"
|
"default conversion table name is 'table.conv'\n"
|
||||||
"default conversion table name is 'table.conv'\n"
|
"\n"
|
||||||
"\n"
|
"More help can be found in the comments included in the default\n"
|
||||||
"More help can be found in the comments included in the default\n"
|
"conversion table. Generate one with the -g option and read it.\n"
|
||||||
"conversion table. Generate one with the -g option and read it.\n"
|
"\n\n", pname, prog_desc, pname);
|
||||||
"\n\n",
|
exit (0);
|
||||||
pname, prog_desc, pname);
|
|
||||||
exit(0) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,132 +185,140 @@ static void usage(char * pname)
|
||||||
keyword values are also modified to follow the IRAF convention.
|
keyword values are also modified to follow the IRAF convention.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
static int
|
||||||
|
convert_eso_to_std_FITS (char *name_in, char *name_conv)
|
||||||
{
|
{
|
||||||
FILE * convtab ;
|
FILE *convtab;
|
||||||
int nkeys ;
|
int nkeys;
|
||||||
int i ;
|
int i;
|
||||||
char ** key_in ;
|
char **key_in;
|
||||||
char ** key_out ;
|
char **key_out;
|
||||||
int fd ;
|
int fd;
|
||||||
char * buf ;
|
char *buf;
|
||||||
char line[NM_SIZ] ;
|
char line[NM_SIZ];
|
||||||
char kw1[FITS_LINE],
|
char kw1[FITS_LINE], kw2[FITS_LINE];
|
||||||
kw2[FITS_LINE] ;
|
int lineno;
|
||||||
int lineno ;
|
int fs;
|
||||||
int fs ;
|
struct stat fileinfo;
|
||||||
struct stat fileinfo ;
|
|
||||||
|
|
||||||
/* Read conversion table and translate it to key_in, key_out */
|
/* Read conversion table and translate it to key_in, key_out */
|
||||||
if ((convtab = fopen(name_conv, "r")) == NULL) {
|
if ((convtab = fopen (name_conv, "r")) == NULL)
|
||||||
fprintf(stderr, "cannot open conversion table: %s\n", name_conv) ;
|
{
|
||||||
return -1 ;
|
fprintf (stderr, "cannot open conversion table: %s\n", name_conv);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First, count how many keywords we need to translate */
|
/* First, count how many keywords we need to translate */
|
||||||
nkeys = 0 ;
|
nkeys = 0;
|
||||||
while (fgets(line, FITS_LINE, convtab)!=NULL) {
|
while (fgets (line, FITS_LINE, convtab) != NULL)
|
||||||
if ((line[0] != '#') && (line[0] != '\n')) {
|
{
|
||||||
nkeys ++ ;
|
if ((line[0] != '#') && (line[0] != '\n'))
|
||||||
}
|
{
|
||||||
|
nkeys++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rewind(convtab) ;
|
rewind (convtab);
|
||||||
|
|
||||||
/* Allocate space to store keyword info */
|
/* Allocate space to store keyword info */
|
||||||
key_in = malloc(nkeys * sizeof(char*)) ;
|
key_in = malloc (nkeys * sizeof (char *));
|
||||||
key_out = malloc(nkeys * sizeof(char*)) ;
|
key_out = malloc (nkeys * sizeof (char *));
|
||||||
|
|
||||||
/* Now read the file through and get the keywords */
|
/* Now read the file through and get the keywords */
|
||||||
i = 0 ;
|
i = 0;
|
||||||
lineno = 0 ;
|
lineno = 0;
|
||||||
while (fgets(line, FITS_LINE, convtab)!=NULL) {
|
while (fgets (line, FITS_LINE, convtab) != NULL)
|
||||||
lineno++ ;
|
{
|
||||||
if ((line[0]!='#') && (line[0]!='\n')) {
|
lineno++;
|
||||||
if (sscanf(line, "%[^=] = %[^;#]", kw1, kw2)!=2) {
|
if ((line[0] != '#') && (line[0] != '\n'))
|
||||||
fprintf(stderr,
|
{
|
||||||
"*** error parsing table file %s\n", name_conv);
|
if (sscanf (line, "%[^=] = %[^;#]", kw1, kw2) != 2)
|
||||||
fprintf(stderr, "line: %d\n", lineno) ;
|
{
|
||||||
free_keys(key_in, i) ;
|
fprintf (stderr,
|
||||||
free_keys(key_out, i) ;
|
"*** error parsing table file %s\n", name_conv);
|
||||||
fclose(convtab) ;
|
fprintf (stderr, "line: %d\n", lineno);
|
||||||
return -1 ;
|
free_keys (key_in, i);
|
||||||
}
|
free_keys (key_out, i);
|
||||||
strip_beg_end(kw1) ;
|
fclose (convtab);
|
||||||
strip_beg_end(kw2) ;
|
return -1;
|
||||||
if (strlen(kw2)>strlen(kw1)) {
|
}
|
||||||
fprintf(stderr,
|
strip_beg_end (kw1);
|
||||||
"*** error in conversion table %s (line %d)\n",
|
strip_beg_end (kw2);
|
||||||
name_conv, lineno);
|
if (strlen (kw2) > strlen (kw1))
|
||||||
fprintf(stderr,
|
{
|
||||||
"*** error: dest keyword is longer than original\n");
|
fprintf (stderr,
|
||||||
fprintf(stderr, "orig: [%s] dest: [%s]\n", kw1, kw2);
|
"*** error in conversion table %s (line %d)\n",
|
||||||
fclose(convtab) ;
|
name_conv, lineno);
|
||||||
free_keys(key_in, i) ;
|
fprintf (stderr,
|
||||||
free_keys(key_out, i) ;
|
"*** error: dest keyword is longer than original\n");
|
||||||
return -1 ;
|
fprintf (stderr, "orig: [%s] dest: [%s]\n", kw1, kw2);
|
||||||
}
|
fclose (convtab);
|
||||||
key_in[i] = strdup(kw1) ;
|
free_keys (key_in, i);
|
||||||
key_out[i] = strdup(kw2) ;
|
free_keys (key_out, i);
|
||||||
i++ ;
|
return -1;
|
||||||
}
|
}
|
||||||
|
key_in[i] = strdup (kw1);
|
||||||
|
key_out[i] = strdup (kw2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose(convtab) ;
|
fclose (convtab);
|
||||||
|
|
||||||
/* Print out some information about what is being done */
|
/* Print out some information about what is being done */
|
||||||
printf("\n\n") ;
|
printf ("\n\n");
|
||||||
printf("*** hierarch28\n") ;
|
printf ("*** hierarch28\n");
|
||||||
printf("\n") ;
|
printf ("\n");
|
||||||
printf("searching %s and replacing the following keywords:\n", name_in) ;
|
printf ("searching %s and replacing the following keywords:\n", name_in);
|
||||||
for (i=0 ; i<nkeys ; i++) {
|
for (i = 0; i < nkeys; i++)
|
||||||
printf("\t[%s]\t=>\t[%s]\n", key_in[i], key_out[i]) ;
|
{
|
||||||
|
printf ("\t[%s]\t=>\t[%s]\n", key_in[i], key_out[i]);
|
||||||
}
|
}
|
||||||
printf("\n\n") ;
|
printf ("\n\n");
|
||||||
|
|
||||||
/* mmap the input file entirely */
|
/* mmap the input file entirely */
|
||||||
if (stat(name_in, &fileinfo)!=0) {
|
if (stat (name_in, &fileinfo) != 0)
|
||||||
fprintf(stderr, "*** error: accessing file [%s]\n", name_in);
|
{
|
||||||
free_keys(key_in, nkeys) ;
|
fprintf (stderr, "*** error: accessing file [%s]\n", name_in);
|
||||||
free_keys(key_out, nkeys) ;
|
free_keys (key_in, nkeys);
|
||||||
return -1 ;
|
free_keys (key_out, nkeys);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
fs = (int)fileinfo.st_size ;
|
fs = (int) fileinfo.st_size;
|
||||||
if (fs < 1) {
|
if (fs < 1)
|
||||||
fprintf(stderr, "error getting FITS header size for %s\n", name_in);
|
{
|
||||||
free_keys(key_in, nkeys) ;
|
fprintf (stderr, "error getting FITS header size for %s\n", name_in);
|
||||||
free_keys(key_out, nkeys) ;
|
free_keys (key_in, nkeys);
|
||||||
return -1 ;
|
free_keys (key_out, nkeys);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
fd = open(name_in, O_RDWR) ;
|
fd = open (name_in, O_RDWR);
|
||||||
if (fd == -1) {
|
if (fd == -1)
|
||||||
fprintf(stderr, "cannot open %s: aborting\n", name_in) ;
|
{
|
||||||
free_keys(key_in, nkeys) ;
|
fprintf (stderr, "cannot open %s: aborting\n", name_in);
|
||||||
free_keys(key_out, nkeys) ;
|
free_keys (key_in, nkeys);
|
||||||
return -1 ;
|
free_keys (key_out, nkeys);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
buf = (char*)mmap(0,
|
buf = (char *) mmap (0, fs, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
fs,
|
if (buf == (char *) -1)
|
||||||
PROT_READ | PROT_WRITE,
|
{
|
||||||
MAP_SHARED,
|
perror ("mmap");
|
||||||
fd,
|
fprintf (stderr, "cannot mmap file: %s\n", name_in);
|
||||||
0) ;
|
free_keys (key_in, nkeys);
|
||||||
if (buf == (char*)-1) {
|
free_keys (key_out, nkeys);
|
||||||
perror("mmap") ;
|
close (fd);
|
||||||
fprintf(stderr, "cannot mmap file: %s\n", name_in) ;
|
return -1;
|
||||||
free_keys(key_in, nkeys) ;
|
|
||||||
free_keys(key_out, nkeys) ;
|
|
||||||
close(fd) ;
|
|
||||||
return -1 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply search and replace for the input keyword lists */
|
/* Apply search and replace for the input keyword lists */
|
||||||
if (search_and_replace_kw(buf, fs, key_in, key_out, nkeys) != 0) {
|
if (search_and_replace_kw (buf, fs, key_in, key_out, nkeys) != 0)
|
||||||
fprintf(stderr, "error while doing search and replace\n") ;
|
{
|
||||||
|
fprintf (stderr, "error while doing search and replace\n");
|
||||||
}
|
}
|
||||||
free_keys(key_in, nkeys) ;
|
free_keys (key_in, nkeys);
|
||||||
free_keys(key_out, nkeys) ;
|
free_keys (key_out, nkeys);
|
||||||
close(fd) ;
|
close (fd);
|
||||||
munmap(buf, fs) ;
|
munmap (buf, fs);
|
||||||
return 0 ;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -325,19 +333,22 @@ static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
||||||
characters (like FITS keywords).
|
characters (like FITS keywords).
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void strip_beg_end(char * s)
|
static void
|
||||||
|
strip_beg_end (char *s)
|
||||||
{
|
{
|
||||||
int beg, len ;
|
int beg, len;
|
||||||
|
|
||||||
beg = 0 ;
|
beg = 0;
|
||||||
while (!isalnum((unsigned char)(s[beg]))) beg++ ;
|
while (!isalnum ((unsigned char) (s[beg])))
|
||||||
|
beg++;
|
||||||
|
|
||||||
len = (int)strlen(s) -1 ;
|
len = (int) strlen (s) - 1;
|
||||||
while (!isalnum((unsigned char)(s[len]))) len -- ;
|
while (!isalnum ((unsigned char) (s[len])))
|
||||||
|
len--;
|
||||||
|
|
||||||
strncpy(s, s+beg, len-beg+1) ;
|
strncpy (s, s + beg, len - beg + 1);
|
||||||
s[len-beg+1] = (char)0 ;
|
s[len - beg + 1] = (char) 0;
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -351,13 +362,16 @@ static void strip_beg_end(char * s)
|
||||||
keys and the master table pointer.
|
keys and the master table pointer.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void free_keys(char ** keyt, int n)
|
static void
|
||||||
|
free_keys (char **keyt, int n)
|
||||||
{
|
{
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
if (n<1) return ;
|
if (n < 1)
|
||||||
for (i=0 ; i<n ; i++) free(keyt[i]) ;
|
return;
|
||||||
free(keyt) ;
|
for (i = 0; i < n; i++)
|
||||||
|
free (keyt[i]);
|
||||||
|
free (keyt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -374,74 +388,82 @@ static void free_keys(char ** keyt, int n)
|
||||||
keyword changes in extensions too. Heavily optimized for speed.
|
keyword changes in extensions too. Heavily optimized for speed.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int search_and_replace_kw(
|
static int
|
||||||
char * buf,
|
search_and_replace_kw (char *buf,
|
||||||
int bufsize,
|
int bufsize, char **key_in, char **key_out, int nk)
|
||||||
char ** key_in,
|
|
||||||
char ** key_out,
|
|
||||||
int nk)
|
|
||||||
{
|
{
|
||||||
char * w ;
|
char *w;
|
||||||
int i, j ;
|
int i, j;
|
||||||
int in_header ;
|
int in_header;
|
||||||
int match_flag ;
|
int match_flag;
|
||||||
int * keysizes ;
|
int *keysizes;
|
||||||
|
|
||||||
/* Pre-compute key sizes to gain time */
|
/* Pre-compute key sizes to gain time */
|
||||||
keysizes = malloc(nk * sizeof(int));
|
keysizes = malloc (nk * sizeof (int));
|
||||||
for (i=0 ; i<nk ; i++) keysizes[i] = (int)strlen(key_in[i]);
|
for (i = 0; i < nk; i++)
|
||||||
|
keysizes[i] = (int) strlen (key_in[i]);
|
||||||
|
|
||||||
/* Browse through file line by line */
|
/* Browse through file line by line */
|
||||||
w = buf ;
|
w = buf;
|
||||||
in_header=1 ;
|
in_header = 1;
|
||||||
while ((w-buf+FITS_LINE)<bufsize) {
|
while ((w - buf + FITS_LINE) < bufsize)
|
||||||
if (in_header) { /* Currently browsing a header */
|
{
|
||||||
if (w[0]=='E' &&
|
if (in_header)
|
||||||
w[1]=='N' &&
|
{ /* Currently browsing a header */
|
||||||
w[2]=='D' &&
|
if (w[0] == 'E' && w[1] == 'N' && w[2] == 'D' && w[3] == ' ')
|
||||||
w[3]==' ') {
|
{
|
||||||
/* Found an END keyword: exit from header */
|
/* Found an END keyword: exit from header */
|
||||||
in_header=0 ;
|
in_header = 0;
|
||||||
} else {
|
}
|
||||||
/* Compare the current line with all searched keys */
|
else
|
||||||
for (i=0 ; i<nk ; i++) {
|
{
|
||||||
match_flag=1 ;
|
/* Compare the current line with all searched keys */
|
||||||
for (j=0 ; j<=keysizes[i] ; j++) {
|
for (i = 0; i < nk; i++)
|
||||||
if (j<keysizes[i]) {
|
{
|
||||||
if (key_in[i][j]!=w[j]) {
|
match_flag = 1;
|
||||||
match_flag=0 ;
|
for (j = 0; j <= keysizes[i]; j++)
|
||||||
break ;
|
{
|
||||||
}
|
if (j < keysizes[i])
|
||||||
} else {
|
{
|
||||||
if ((w[j] != '=') && (w[j] != ' ')) {
|
if (key_in[i][j] != w[j])
|
||||||
match_flag=0 ;
|
{
|
||||||
break ;
|
match_flag = 0;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (match_flag) {
|
|
||||||
search_rep(w, key_in[i], key_out[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
else
|
||||||
/* Currently out of header, look for next extension */
|
{
|
||||||
if (w[0]=='X' &&
|
if ((w[j] != '=') && (w[j] != ' '))
|
||||||
w[1]=='T' &&
|
{
|
||||||
w[2]=='E' &&
|
match_flag = 0;
|
||||||
w[3]=='N' &&
|
break;
|
||||||
w[4]=='S' &&
|
}
|
||||||
w[5]=='I' &&
|
|
||||||
w[6]=='O' &&
|
|
||||||
w[7]=='N') {
|
|
||||||
/* Found a header start */
|
|
||||||
in_header=1 ;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (match_flag)
|
||||||
|
{
|
||||||
|
search_rep (w, key_in[i], key_out[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w+=FITS_LINE ;
|
}
|
||||||
}
|
}
|
||||||
free(keysizes);
|
else
|
||||||
return 0 ;
|
{
|
||||||
|
/* Currently out of header, look for next extension */
|
||||||
|
if (w[0] == 'X' &&
|
||||||
|
w[1] == 'T' &&
|
||||||
|
w[2] == 'E' &&
|
||||||
|
w[3] == 'N' &&
|
||||||
|
w[4] == 'S' && w[5] == 'I' && w[6] == 'O' && w[7] == 'N')
|
||||||
|
{
|
||||||
|
/* Found a header start */
|
||||||
|
in_header = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w += FITS_LINE;
|
||||||
|
}
|
||||||
|
free (keysizes);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -457,92 +479,114 @@ static int search_and_replace_kw(
|
||||||
conventions.
|
conventions.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void search_rep(char * line, char * key_i, char * key_o)
|
static void
|
||||||
|
search_rep (char *line, char *key_i, char *key_o)
|
||||||
{
|
{
|
||||||
int i, j ;
|
int i, j;
|
||||||
char * equal ;
|
char *equal;
|
||||||
int to_copy ;
|
int to_copy;
|
||||||
char * p ;
|
char *p;
|
||||||
char tmp[FITS_LINE+1];
|
char tmp[FITS_LINE + 1];
|
||||||
char comment[FITS_LINE+1];
|
char comment[FITS_LINE + 1];
|
||||||
|
|
||||||
equal = strstr(line, "=");
|
equal = strstr (line, "=");
|
||||||
to_copy = FITS_LINE - (equal-line);
|
to_copy = FITS_LINE - (equal - line);
|
||||||
for (i=0 ; i<(int)strlen(key_o) ; i++) {
|
for (i = 0; i < (int) strlen (key_o); i++)
|
||||||
line[i] = key_o[i] ;
|
{
|
||||||
|
line[i] = key_o[i];
|
||||||
|
}
|
||||||
|
if (strlen (key_o) <= 8)
|
||||||
|
{
|
||||||
|
/* Blank-pad until equal sign is reached */
|
||||||
|
for (; i < 8; i++)
|
||||||
|
{
|
||||||
|
line[i] = ' ';
|
||||||
}
|
}
|
||||||
if (strlen(key_o)<=8) {
|
/* Add equal sign */
|
||||||
/* Blank-pad until equal sign is reached */
|
line[i] = '=';
|
||||||
for ( ; i<8 ; i++) {
|
i++;
|
||||||
line[i]=' ';
|
|
||||||
}
|
|
||||||
/* Add equal sign */
|
|
||||||
line[i] = '=' ;
|
|
||||||
i++ ;
|
|
||||||
|
|
||||||
/* Handle special cases: the value also needs conversion */
|
/* Handle special cases: the value also needs conversion */
|
||||||
if(!strcmp(key_o, "RA")) {
|
if (!strcmp (key_o, "RA"))
|
||||||
if (*(equal+2)!='\'') {
|
{
|
||||||
/* out key is RA, translate to ' HH:MM:SS.SSS' */
|
if (*(equal + 2) != '\'')
|
||||||
p = strchr(line+i, '/');
|
{
|
||||||
if (p)
|
/* out key is RA, translate to ' HH:MM:SS.SSS' */
|
||||||
strncpy(comment, p, line+FITS_LINE-p);
|
p = strchr (line + i, '/');
|
||||||
sprintf(tmp, " %-29.29s %-40.40s",
|
if (p)
|
||||||
convert_deg_to_str(atof(equal+1)/15.),
|
strncpy (comment, p, line + FITS_LINE - p);
|
||||||
(p)? comment : "/ Right Ascension");
|
sprintf (tmp, " %-29.29s %-40.40s",
|
||||||
memcpy(line+i, tmp, 71);
|
convert_deg_to_str (atof (equal + 1) / 15.),
|
||||||
}
|
(p) ? comment : "/ Right Ascension");
|
||||||
} else if(!strcmp(key_o, "DEC")) {
|
memcpy (line + i, tmp, 71);
|
||||||
if( *(equal+2)!='\'') {
|
}
|
||||||
/* out key is DEC, translate to '+DD:MM:SS.SSS' */
|
|
||||||
p = strchr(line+i, '/');
|
|
||||||
if (p)
|
|
||||||
strncpy(comment, p, line+FITS_LINE-p);
|
|
||||||
sprintf(tmp, " %-29.29s %-40.40s",
|
|
||||||
convert_deg_to_str(atof(equal+1)),
|
|
||||||
(p)? comment : "/ Declination");
|
|
||||||
memcpy(line+i, tmp, 71);
|
|
||||||
}
|
|
||||||
} else if(!strcmp(key_o, "UT")) {
|
|
||||||
if( *(equal+2)!='\'') {
|
|
||||||
/* out key is UT, translate to ' HH:MM:SS.SSS' */
|
|
||||||
p = strchr(line+i, '/');
|
|
||||||
if (p)
|
|
||||||
strncpy(comment, p, line+FITS_LINE-p);
|
|
||||||
sprintf(tmp, " %-29.29s %-40.40s",
|
|
||||||
convert_deg_to_str(atof(equal+1)/3600.),
|
|
||||||
(p)? comment : "/ UT");
|
|
||||||
memcpy(line+i, tmp, 71);
|
|
||||||
}
|
|
||||||
} else if(!strcmp(key_o, "ST")) {
|
|
||||||
if( *(equal+2)!='\'') {
|
|
||||||
/* out key is ST, translate to ' HH:MM:SS.SSS' */
|
|
||||||
p = strchr(line+i, '/');
|
|
||||||
if (p)
|
|
||||||
strncpy(comment, p, line+FITS_LINE-p);
|
|
||||||
sprintf(tmp, " %-29.29s %-40.40s",
|
|
||||||
convert_deg_to_str(atof(equal+1)/3600.),
|
|
||||||
(p)? comment : "/ ST");
|
|
||||||
memcpy(line+i, tmp, 71);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Copy line from first char after real equal sign */
|
|
||||||
for (j=0 ; j<to_copy ; j++) {
|
|
||||||
line[i+j] = equal[j+1];
|
|
||||||
}
|
|
||||||
i+=to_copy-1 ;
|
|
||||||
/* Blank padding */
|
|
||||||
for ( ; i<FITS_LINE ; i++) {
|
|
||||||
line[i]=' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Blank padding */
|
|
||||||
for (i=(int)strlen(key_o) ; i<(int)strlen(key_i) ; i++) {
|
|
||||||
line[i]=' ';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ;
|
else if (!strcmp (key_o, "DEC"))
|
||||||
|
{
|
||||||
|
if (*(equal + 2) != '\'')
|
||||||
|
{
|
||||||
|
/* out key is DEC, translate to '+DD:MM:SS.SSS' */
|
||||||
|
p = strchr (line + i, '/');
|
||||||
|
if (p)
|
||||||
|
strncpy (comment, p, line + FITS_LINE - p);
|
||||||
|
sprintf (tmp, " %-29.29s %-40.40s",
|
||||||
|
convert_deg_to_str (atof (equal + 1)),
|
||||||
|
(p) ? comment : "/ Declination");
|
||||||
|
memcpy (line + i, tmp, 71);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!strcmp (key_o, "UT"))
|
||||||
|
{
|
||||||
|
if (*(equal + 2) != '\'')
|
||||||
|
{
|
||||||
|
/* out key is UT, translate to ' HH:MM:SS.SSS' */
|
||||||
|
p = strchr (line + i, '/');
|
||||||
|
if (p)
|
||||||
|
strncpy (comment, p, line + FITS_LINE - p);
|
||||||
|
sprintf (tmp, " %-29.29s %-40.40s",
|
||||||
|
convert_deg_to_str (atof (equal + 1) / 3600.),
|
||||||
|
(p) ? comment : "/ UT");
|
||||||
|
memcpy (line + i, tmp, 71);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!strcmp (key_o, "ST"))
|
||||||
|
{
|
||||||
|
if (*(equal + 2) != '\'')
|
||||||
|
{
|
||||||
|
/* out key is ST, translate to ' HH:MM:SS.SSS' */
|
||||||
|
p = strchr (line + i, '/');
|
||||||
|
if (p)
|
||||||
|
strncpy (comment, p, line + FITS_LINE - p);
|
||||||
|
sprintf (tmp, " %-29.29s %-40.40s",
|
||||||
|
convert_deg_to_str (atof (equal + 1) / 3600.),
|
||||||
|
(p) ? comment : "/ ST");
|
||||||
|
memcpy (line + i, tmp, 71);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Copy line from first char after real equal sign */
|
||||||
|
for (j = 0; j < to_copy; j++)
|
||||||
|
{
|
||||||
|
line[i + j] = equal[j + 1];
|
||||||
|
}
|
||||||
|
i += to_copy - 1;
|
||||||
|
/* Blank padding */
|
||||||
|
for (; i < FITS_LINE; i++)
|
||||||
|
{
|
||||||
|
line[i] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Blank padding */
|
||||||
|
for (i = (int) strlen (key_o); i < (int) strlen (key_i); i++)
|
||||||
|
{
|
||||||
|
line[i] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -555,20 +599,22 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
||||||
instrument is specified (ins==NULL) a default table is generated.
|
instrument is specified (ins==NULL) a default table is generated.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void generate_default_convtab(void)
|
static void
|
||||||
|
generate_default_convtab (void)
|
||||||
{
|
{
|
||||||
FILE * convtab ;
|
FILE *convtab;
|
||||||
|
|
||||||
if ((convtab = fopen("table.conv", "w")) == NULL) {
|
if ((convtab = fopen ("table.conv", "w")) == NULL)
|
||||||
fprintf(stderr, "*** error: cannot create table.conv: aborting\n") ;
|
{
|
||||||
return ;
|
fprintf (stderr, "*** error: cannot create table.conv: aborting\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fprintf(convtab, CONVTAB_DEFAULT1);
|
fprintf (convtab, CONVTAB_DEFAULT1);
|
||||||
fprintf(convtab, CONVTAB_DEFAULT2);
|
fprintf (convtab, CONVTAB_DEFAULT2);
|
||||||
fprintf(convtab, CONVTAB_DEFAULT3);
|
fprintf (convtab, CONVTAB_DEFAULT3);
|
||||||
fprintf(convtab, CONVTAB_DEFAULT4);
|
fprintf (convtab, CONVTAB_DEFAULT4);
|
||||||
fclose(convtab) ;
|
fclose (convtab);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -582,22 +628,24 @@ static void generate_default_convtab(void)
|
||||||
string.
|
string.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static char * convert_deg_to_str( double deg )
|
static char *
|
||||||
|
convert_deg_to_str (double deg)
|
||||||
{
|
{
|
||||||
int d, m;
|
int d, m;
|
||||||
double s;
|
double s;
|
||||||
int sign;
|
int sign;
|
||||||
static char buf[13];
|
static char buf[13];
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if(deg < 0.) sign = -1;
|
if (deg < 0.)
|
||||||
|
sign = -1;
|
||||||
|
|
||||||
deg *= sign;
|
deg *= sign;
|
||||||
d = (int)deg;
|
d = (int) deg;
|
||||||
m = (int)( (deg - d) * 60);
|
m = (int) ((deg - d) * 60);
|
||||||
s = (deg - d) * 3600. - m * 60;
|
s = (deg - d) * 3600. - m * 60;
|
||||||
|
|
||||||
sprintf(buf, "'%c%02d:%02d:%06.3f'", (sign<0)? '-' : ' ', d, m, s);
|
sprintf (buf, "'%c%02d:%02d:%06.3f'", (sign < 0) ? '-' : ' ', d, m, s);
|
||||||
|
|
||||||
return(buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
2363
qfits/saft/iofits.c
2363
qfits/saft/iofits.c
File diff suppressed because it is too large
Load Diff
|
@ -53,32 +53,35 @@
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static int dump_pix(char*, char*);
|
static int dump_pix (char *, char *);
|
||||||
static int get_FITS_header_size(char *) ;
|
static int get_FITS_header_size (char *);
|
||||||
static int filesize(char*) ;
|
static int filesize (char *);
|
||||||
static int get_bitpix(char*) ;
|
static int get_bitpix (char *);
|
||||||
static int get_npix(char*) ;
|
static int get_npix (char *);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc<3) {
|
if (argc < 3)
|
||||||
printf("\n\n") ;
|
{
|
||||||
printf("use: %s <in> <out>\n", argv[0]) ;
|
printf ("\n\n");
|
||||||
printf("\n") ;
|
printf ("use: %s <in> <out>\n", argv[0]);
|
||||||
printf("\t<in> is a valid FITS file in the current directory\n") ;
|
printf ("\n");
|
||||||
printf("\t<out> is the name of the output file\n") ;
|
printf ("\t<in> is a valid FITS file in the current directory\n");
|
||||||
printf("\n\n") ;
|
printf ("\t<out> is the name of the output file\n");
|
||||||
return 0 ;
|
printf ("\n\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(argv[1], argv[2])) {
|
if (!strcmp (argv[1], argv[2]))
|
||||||
fprintf(stderr, "cannot convert a file to itself\n") ;
|
{
|
||||||
fprintf(stderr, "specify another name for the output\n") ;
|
fprintf (stderr, "cannot convert a file to itself\n");
|
||||||
return -1 ;
|
fprintf (stderr, "specify another name for the output\n");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return dump_pix(argv[1], argv[2]);
|
return dump_pix (argv[1], argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -90,108 +93,117 @@ int main(int argc, char *argv[])
|
||||||
Heavy use of mmap() to speed up the process
|
Heavy use of mmap() to speed up the process
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int dump_pix(
|
static int
|
||||||
char * name_in,
|
dump_pix (char *name_in, char *name_out)
|
||||||
char * name_out)
|
|
||||||
{
|
{
|
||||||
int fd_in,
|
int fd_in, fd_out;
|
||||||
fd_out ;
|
char *buf_in;
|
||||||
char * buf_in ;
|
char *buf_out;
|
||||||
char * buf_out ;
|
int fsize_in, fsize_out, header_size;
|
||||||
int fsize_in,
|
int npix;
|
||||||
fsize_out,
|
|
||||||
header_size ;
|
|
||||||
int npix ;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Open input file and get information we need:
|
|
||||||
* - pixel depth
|
|
||||||
* - number of pixels
|
|
||||||
*/
|
|
||||||
|
|
||||||
fsize_in = filesize(name_in) ;
|
/*
|
||||||
header_size = get_FITS_header_size(name_in) ;
|
* Open input file and get information we need:
|
||||||
if ((fd_in = open(name_in, O_RDONLY)) == -1) {
|
* - pixel depth
|
||||||
fprintf(stderr, "cannot open file %s: aborting\n", name_in) ;
|
* - number of pixels
|
||||||
return -1 ;
|
*/
|
||||||
|
|
||||||
|
fsize_in = filesize (name_in);
|
||||||
|
header_size = get_FITS_header_size (name_in);
|
||||||
|
if ((fd_in = open (name_in, O_RDONLY)) == -1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "cannot open file %s: aborting\n", name_in);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
buf_in = (char*)mmap(0, fsize_in, PROT_READ, MAP_SHARED, fd_in, 0) ;
|
buf_in = (char *) mmap (0, fsize_in, PROT_READ, MAP_SHARED, fd_in, 0);
|
||||||
if (buf_in == (char*)-1) {
|
if (buf_in == (char *) -1)
|
||||||
perror("mmap") ;
|
{
|
||||||
fprintf(stderr, "cannot mmap file: %s\n", name_in) ;
|
perror ("mmap");
|
||||||
close(fd_in) ;
|
fprintf (stderr, "cannot mmap file: %s\n", name_in);
|
||||||
return -1 ;
|
close (fd_in);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (get_bitpix(buf_in) != -32) {
|
if (get_bitpix (buf_in) != -32)
|
||||||
fprintf(stderr, "only 32-bit IEEE floating point format supported\n");
|
{
|
||||||
close(fd_in) ; munmap(buf_in, fsize_in) ;
|
fprintf (stderr, "only 32-bit IEEE floating point format supported\n");
|
||||||
return -1 ;
|
close (fd_in);
|
||||||
|
munmap (buf_in, fsize_in);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the size of the output file
|
* Compute the size of the output file
|
||||||
* same header size, + pixel area + blank padding
|
* same header size, + pixel area + blank padding
|
||||||
*/
|
*/
|
||||||
npix = get_npix(buf_in) ;
|
npix = get_npix (buf_in);
|
||||||
if (npix < 1) {
|
if (npix < 1)
|
||||||
fprintf(stderr, "cannot compute number of pixels\n");
|
{
|
||||||
close(fd_in) ;
|
fprintf (stderr, "cannot compute number of pixels\n");
|
||||||
munmap(buf_in, fsize_in) ;
|
close (fd_in);
|
||||||
return -1 ;
|
munmap (buf_in, fsize_in);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
fsize_out = npix * 4 ;
|
fsize_out = npix * 4;
|
||||||
/*
|
/*
|
||||||
* Now create the output file and fill it with zeros, then mmap it.
|
* Now create the output file and fill it with zeros, then mmap it.
|
||||||
* The permissions are rw-rw-r-- by default.
|
* The permissions are rw-rw-r-- by default.
|
||||||
*/
|
*/
|
||||||
if ((fd_out=creat(name_out,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH))==-1){
|
if ((fd_out =
|
||||||
perror("creat") ;
|
creat (name_out,
|
||||||
fprintf(stderr, "cannot create file %s: aborting\n", name_out) ;
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) == -1)
|
||||||
close(fd_in) ; munmap(buf_in, fsize_in) ;
|
{
|
||||||
return -1 ;
|
perror ("creat");
|
||||||
|
fprintf (stderr, "cannot create file %s: aborting\n", name_out);
|
||||||
|
close (fd_in);
|
||||||
|
munmap (buf_in, fsize_in);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf_out = malloc(fsize_out) ;
|
buf_out = malloc (fsize_out);
|
||||||
if (buf_out == NULL) {
|
if (buf_out == NULL)
|
||||||
fprintf(stderr, "not enough memory\n");
|
{
|
||||||
fprintf(stderr, "failed to allocate %d bytes\n", fsize_out);
|
fprintf (stderr, "not enough memory\n");
|
||||||
close(fd_in) ; munmap(buf_in, fsize_in) ;
|
fprintf (stderr, "failed to allocate %d bytes\n", fsize_out);
|
||||||
return -1;
|
close (fd_in);
|
||||||
|
munmap (buf_in, fsize_in);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
write(fd_out, buf_out, fsize_out);
|
write (fd_out, buf_out, fsize_out);
|
||||||
close(fd_out);
|
close (fd_out);
|
||||||
free(buf_out);
|
free (buf_out);
|
||||||
|
|
||||||
fd_out = open(name_out, O_RDWR);
|
fd_out = open (name_out, O_RDWR);
|
||||||
if (fd_out==-1) {
|
if (fd_out == -1)
|
||||||
fprintf(stderr, "error opening file %s\n", name_out);
|
{
|
||||||
close(fd_in) ; munmap(buf_in, fsize_in) ;
|
fprintf (stderr, "error opening file %s\n", name_out);
|
||||||
return -1;
|
close (fd_in);
|
||||||
|
munmap (buf_in, fsize_in);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
buf_out = (char*)mmap(0,
|
buf_out = (char *) mmap (0,
|
||||||
fsize_out,
|
fsize_out,
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE, MAP_SHARED, fd_out, 0);
|
||||||
MAP_SHARED,
|
if (buf_out == (char *) -1)
|
||||||
fd_out,
|
{
|
||||||
0) ;
|
perror ("mmap");
|
||||||
if (buf_out == (char*)-1) {
|
fprintf (stderr, "cannot mmap file: %s\n", name_out);
|
||||||
perror("mmap") ;
|
munmap (buf_in, fsize_in);
|
||||||
fprintf(stderr, "cannot mmap file: %s\n", name_out) ;
|
close (fd_in);
|
||||||
munmap(buf_in, fsize_in) ; close(fd_in) ; close(fd_out) ;
|
close (fd_out);
|
||||||
return -1 ;
|
return -1;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Copy FITS header from input to output, modify BITPIX
|
* Copy FITS header from input to output, modify BITPIX
|
||||||
*/
|
*/
|
||||||
memcpy(buf_out, buf_in+header_size, fsize_out) ;
|
memcpy (buf_out, buf_in + header_size, fsize_out);
|
||||||
/*
|
/*
|
||||||
* Close, unmap, goodbye
|
* Close, unmap, goodbye
|
||||||
*/
|
*/
|
||||||
close(fd_in) ;
|
close (fd_in);
|
||||||
close(fd_out) ;
|
close (fd_out);
|
||||||
munmap(buf_in, fsize_in) ;
|
munmap (buf_in, fsize_in);
|
||||||
munmap(buf_out, fsize_out) ;
|
munmap (buf_out, fsize_out);
|
||||||
return 0 ;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -203,40 +215,47 @@ static int dump_pix(
|
||||||
80 characters are found per line.
|
80 characters are found per line.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int get_FITS_header_size(char * name)
|
static int
|
||||||
|
get_FITS_header_size (char *name)
|
||||||
{
|
{
|
||||||
FILE * in ;
|
FILE *in;
|
||||||
char line[81] ;
|
char line[81];
|
||||||
int found = 0 ;
|
int found = 0;
|
||||||
int count ;
|
int count;
|
||||||
int hs ;
|
int hs;
|
||||||
|
|
||||||
if ((in = fopen(name, "r")) == NULL) {
|
if ((in = fopen (name, "r")) == NULL)
|
||||||
fprintf(stderr, "cannot open %s: aborting\n", name) ;
|
{
|
||||||
return 0 ;
|
fprintf (stderr, "cannot open %s: aborting\n", name);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
count = 0 ;
|
count = 0;
|
||||||
while (!found) {
|
while (!found)
|
||||||
if (fread(line, 1, 80, in)!=80) {
|
{
|
||||||
break ;
|
if (fread (line, 1, 80, in) != 80)
|
||||||
}
|
{
|
||||||
count ++ ;
|
break;
|
||||||
if (!strncmp(line, "END ", 4)) {
|
}
|
||||||
found = 1 ;
|
count++;
|
||||||
}
|
if (!strncmp (line, "END ", 4))
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose(in);
|
fclose (in);
|
||||||
|
|
||||||
if (!found) return 0 ;
|
if (!found)
|
||||||
/*
|
return 0;
|
||||||
* The size is the number of found cards times 80,
|
/*
|
||||||
* rounded to the closest higher multiple of 2880.
|
* The size is the number of found cards times 80,
|
||||||
*/
|
* rounded to the closest higher multiple of 2880.
|
||||||
hs = count * 80 ;
|
*/
|
||||||
if ((hs % FITS_BLSZ) != 0) {
|
hs = count * 80;
|
||||||
hs = (1+(hs/FITS_BLSZ)) * FITS_BLSZ ;
|
if ((hs % FITS_BLSZ) != 0)
|
||||||
|
{
|
||||||
|
hs = (1 + (hs / FITS_BLSZ)) * FITS_BLSZ;
|
||||||
}
|
}
|
||||||
return hs ;
|
return hs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -247,18 +266,22 @@ static int get_FITS_header_size(char * name)
|
||||||
Strongly non portable. Only on Unix systems!
|
Strongly non portable. Only on Unix systems!
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int filesize(char *filename)
|
static int
|
||||||
|
filesize (char *filename)
|
||||||
{
|
{
|
||||||
int size ;
|
int size;
|
||||||
struct stat fileinfo ;
|
struct stat fileinfo;
|
||||||
|
|
||||||
/* POSIX compliant */
|
/* POSIX compliant */
|
||||||
if (stat(filename, &fileinfo) != 0) {
|
if (stat (filename, &fileinfo) != 0)
|
||||||
size = (int)0 ;
|
{
|
||||||
} else {
|
size = (int) 0;
|
||||||
size = (int)fileinfo.st_size ;
|
|
||||||
}
|
}
|
||||||
return size ;
|
else
|
||||||
|
{
|
||||||
|
size = (int) fileinfo.st_size;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -268,28 +291,28 @@ static int filesize(char *filename)
|
||||||
@return int 8 16 32 -32 or -64 or 0 if cannot find it
|
@return int 8 16 32 -32 or -64 or 0 if cannot find it
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int get_bitpix(char * buf)
|
static int
|
||||||
|
get_bitpix (char *buf)
|
||||||
{
|
{
|
||||||
int bitpix ;
|
int bitpix;
|
||||||
char * where ;
|
char *where;
|
||||||
|
|
||||||
where = strstr(buf, "BITPIX") ;
|
where = strstr (buf, "BITPIX");
|
||||||
if (where == NULL) {
|
if (where == NULL)
|
||||||
fprintf(stderr, "cannot find BITPIX in header: aborting\n") ;
|
{
|
||||||
return 0 ;
|
fprintf (stderr, "cannot find BITPIX in header: aborting\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
sscanf(where, "%*[^=] = %d", &bitpix) ;
|
sscanf (where, "%*[^=] = %d", &bitpix);
|
||||||
/*
|
/*
|
||||||
* Check the returned value makes sense
|
* Check the returned value makes sense
|
||||||
*/
|
*/
|
||||||
if ((bitpix != 8) &&
|
if ((bitpix != 8) &&
|
||||||
(bitpix != 16) &&
|
(bitpix != 16) && (bitpix != 32) && (bitpix != -32) && (bitpix != -64))
|
||||||
(bitpix != 32) &&
|
{
|
||||||
(bitpix != -32) &&
|
bitpix = 0;
|
||||||
(bitpix != -64)) {
|
|
||||||
bitpix = 0 ;
|
|
||||||
}
|
}
|
||||||
return bitpix ;
|
return bitpix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -300,41 +323,45 @@ static int get_bitpix(char * buf)
|
||||||
Does not support extensions!
|
Does not support extensions!
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int get_npix(char * buf)
|
static int
|
||||||
|
get_npix (char *buf)
|
||||||
{
|
{
|
||||||
int naxes ;
|
int naxes;
|
||||||
int npix ;
|
int npix;
|
||||||
int naxis ;
|
int naxis;
|
||||||
char * where ;
|
char *where;
|
||||||
char lookfor[80] ;
|
char lookfor[80];
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
where = strstr(buf, "NAXIS") ;
|
where = strstr (buf, "NAXIS");
|
||||||
if (where == NULL) {
|
if (where == NULL)
|
||||||
fprintf(stderr, "cannot find NAXIS in header: aborting\n") ;
|
{
|
||||||
return 0 ;
|
fprintf (stderr, "cannot find NAXIS in header: aborting\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
sscanf(where, "%*[^=] = %d", &naxes) ;
|
sscanf (where, "%*[^=] = %d", &naxes);
|
||||||
if ((naxes<1) || (naxes>999)) {
|
if ((naxes < 1) || (naxes > 999))
|
||||||
fprintf(stderr, "illegal value for %s: %d\n", lookfor, naxes) ;
|
{
|
||||||
return 0 ;
|
fprintf (stderr, "illegal value for %s: %d\n", lookfor, naxes);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
npix = 1 ;
|
npix = 1;
|
||||||
for (i=1 ; i<=naxes ; i++) {
|
for (i = 1; i <= naxes; i++)
|
||||||
sprintf(lookfor, "NAXIS%d", i) ;
|
{
|
||||||
where = strstr(buf, lookfor) ;
|
sprintf (lookfor, "NAXIS%d", i);
|
||||||
if (where == NULL) {
|
where = strstr (buf, lookfor);
|
||||||
fprintf(stderr, "cannot find %s in header: aborting\n",
|
if (where == NULL)
|
||||||
lookfor) ;
|
{
|
||||||
return 0 ;
|
fprintf (stderr, "cannot find %s in header: aborting\n", lookfor);
|
||||||
}
|
return 0;
|
||||||
sscanf(where, "%*[^=] = %d", &naxis) ;
|
}
|
||||||
if (naxis<1) {
|
sscanf (where, "%*[^=] = %d", &naxis);
|
||||||
fprintf(stderr, "error: found %s=%d\n", lookfor, naxis);
|
if (naxis < 1)
|
||||||
return 0 ;
|
{
|
||||||
}
|
fprintf (stderr, "error: found %s=%d\n", lookfor, naxis);
|
||||||
npix *= (int)naxis ;
|
return 0;
|
||||||
|
}
|
||||||
|
npix *= (int) naxis;
|
||||||
}
|
}
|
||||||
return npix ;
|
return npix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,15 +51,16 @@
|
||||||
modifying the passed argument. Assembler included for x86 architectures.
|
modifying the passed argument. Assembler included for x86 architectures.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
unsigned short __NOTRACE__ swap_bytes_16(unsigned short w)
|
unsigned short __NOTRACE__
|
||||||
|
swap_bytes_16 (unsigned short w)
|
||||||
{
|
{
|
||||||
#ifdef CPU_X86
|
#ifdef CPU_X86
|
||||||
__asm("xchgb %b0,%h0" :
|
__asm ("xchgb %b0,%h0":
|
||||||
"=q" (w) :
|
"=q" (w):
|
||||||
"0" (w));
|
"0" (w));
|
||||||
return w ;
|
return w;
|
||||||
#else
|
#else
|
||||||
return (((w) & 0x00ff) << 8 | ((w) & 0xff00) >> 8);
|
return (((w) & 0x00ff) << 8 | ((w) & 0xff00) >> 8);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,23 +75,22 @@ unsigned short __NOTRACE__ swap_bytes_16(unsigned short w)
|
||||||
and optimized for processors above 386.
|
and optimized for processors above 386.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
unsigned int __NOTRACE__ swap_bytes_32(unsigned int dw)
|
unsigned int __NOTRACE__
|
||||||
|
swap_bytes_32 (unsigned int dw)
|
||||||
{
|
{
|
||||||
#ifdef CPU_X86
|
#ifdef CPU_X86
|
||||||
#if CPU_X86 > 386
|
#if CPU_X86 > 386
|
||||||
__asm("bswap %0":
|
__asm ("bswap %0":
|
||||||
"=r" (dw) :
|
"=r" (dw):
|
||||||
#else
|
#else
|
||||||
__asm("xchgb %b0,%h0\n"
|
__asm ("xchgb %b0,%h0\n" " rorl $16,%0\n" " xchgb %b0,%h0":
|
||||||
" rorl $16,%0\n"
|
"=q" (dw):
|
||||||
" xchgb %b0,%h0":
|
|
||||||
"=q" (dw) :
|
|
||||||
#endif
|
#endif
|
||||||
"0" (dw));
|
"0" (dw));
|
||||||
return dw ;
|
return dw;
|
||||||
#else
|
#else
|
||||||
return ((((dw) & 0xff000000) >> 24) | (((dw) & 0x00ff0000) >> 8) |
|
return ((((dw) & 0xff000000) >> 24) | (((dw) & 0x00ff0000) >> 8) |
|
||||||
(((dw) & 0x0000ff00) << 8) | (((dw) & 0x000000ff) << 24));
|
(((dw) & 0x0000ff00) << 8) | (((dw) & 0x000000ff) << 24));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,17 +107,19 @@ unsigned int __NOTRACE__ swap_bytes_32(unsigned int dw)
|
||||||
everywhere this file compiles.
|
everywhere this file compiles.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void __NOTRACE__ swap_bytes(void * p, int s)
|
void __NOTRACE__
|
||||||
|
swap_bytes (void *p, int s)
|
||||||
{
|
{
|
||||||
unsigned char tmp, *a, *b ;
|
unsigned char tmp, *a, *b;
|
||||||
|
|
||||||
a = (unsigned char*)p ;
|
a = (unsigned char *) p;
|
||||||
b = a + s ;
|
b = a + s;
|
||||||
|
|
||||||
while (a<b) {
|
while (a < b)
|
||||||
tmp = *a ;
|
{
|
||||||
*a++ = *--b ;
|
tmp = *a;
|
||||||
*b = tmp ;
|
*a++ = *--b;
|
||||||
|
*b = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +133,11 @@ void __NOTRACE__ swap_bytes(void * p, int s)
|
||||||
MOTOROLA-like one does not.
|
MOTOROLA-like one does not.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int need_byteswapping(void)
|
int
|
||||||
|
need_byteswapping (void)
|
||||||
{
|
{
|
||||||
short ps = 0xFF ;
|
short ps = 0xFF;
|
||||||
return ((*((char*)(&ps))) ? 1 : 0 ) ;
|
return ((*((char *) (&ps))) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
1073
qfits/src/cache.c
1073
qfits/src/cache.c
File diff suppressed because it is too large
Load Diff
|
@ -56,7 +56,7 @@
|
||||||
fairly small, you should not need to care too much about this.
|
fairly small, you should not need to care too much about this.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_cache_purge(void);
|
void qfits_cache_purge (void);
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -116,7 +116,7 @@ void qfits_cache_purge(void);
|
||||||
of the FITS file.
|
of the FITS file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_query(char * filename, int what);
|
int qfits_query (char *filename, int what);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -40,20 +40,23 @@
|
||||||
@return string
|
@return string
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static char * expkey_strupc(const char * s)
|
static char *
|
||||||
|
expkey_strupc (const char *s)
|
||||||
{
|
{
|
||||||
static char l[ASCIILINESZ+1];
|
static char l[ASCIILINESZ + 1];
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
if (s==NULL) return NULL ;
|
if (s == NULL)
|
||||||
memset(l, 0, ASCIILINESZ+1);
|
return NULL;
|
||||||
i=0 ;
|
memset (l, 0, ASCIILINESZ + 1);
|
||||||
while (s[i] && i<ASCIILINESZ) {
|
i = 0;
|
||||||
l[i] = (char)toupper((int)s[i]);
|
while (s[i] && i < ASCIILINESZ)
|
||||||
i++ ;
|
{
|
||||||
|
l[i] = (char) toupper ((int) s[i]);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
l[ASCIILINESZ]=(char)0;
|
l[ASCIILINESZ] = (char) 0;
|
||||||
return l ;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -76,28 +79,33 @@ static char * expkey_strupc(const char * s)
|
||||||
not dots '.') the result is identical to the input.
|
not dots '.') the result is identical to the input.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_expand_keyword(const char * keyword)
|
char *
|
||||||
|
qfits_expand_keyword (const char *keyword)
|
||||||
{
|
{
|
||||||
static char expanded[81];
|
static char expanded[81];
|
||||||
char ws[81];
|
char ws[81];
|
||||||
char * token ;
|
char *token;
|
||||||
|
|
||||||
/* Bulletproof entries */
|
/* Bulletproof entries */
|
||||||
if (keyword==NULL) return NULL ;
|
if (keyword == NULL)
|
||||||
/* If regular keyword, copy the uppercased input and return */
|
return NULL;
|
||||||
if (strstr(keyword, ".")==NULL) {
|
/* If regular keyword, copy the uppercased input and return */
|
||||||
strcpy(expanded, expkey_strupc(keyword));
|
if (strstr (keyword, ".") == NULL)
|
||||||
return expanded ;
|
{
|
||||||
}
|
strcpy (expanded, expkey_strupc (keyword));
|
||||||
/* Regular shortFITS keyword */
|
return expanded;
|
||||||
sprintf(expanded, "HIERARCH ESO");
|
}
|
||||||
strcpy(ws, expkey_strupc(keyword));
|
/* Regular shortFITS keyword */
|
||||||
token = strtok(ws, ".");
|
sprintf (expanded, "HIERARCH ESO");
|
||||||
while (token!=NULL) {
|
strcpy (ws, expkey_strupc (keyword));
|
||||||
strcat(expanded, " ");
|
token = strtok (ws, ".");
|
||||||
strcat(expanded, token);
|
while (token != NULL)
|
||||||
token = strtok(NULL, ".");
|
{
|
||||||
}
|
strcat (expanded, " ");
|
||||||
return expanded ;
|
strcat (expanded, token);
|
||||||
|
token = strtok (NULL, ".");
|
||||||
|
}
|
||||||
|
return expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
not dots '.') the result is identical to the input.
|
not dots '.') the result is identical to the input.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_expand_keyword(const char * keyword);
|
char *qfits_expand_keyword (const char *keyword);
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
1540
qfits/src/fits_h.c
1540
qfits/src/fits_h.c
File diff suppressed because it is too large
Load Diff
|
@ -23,7 +23,8 @@
|
||||||
#define FITS_HEADER_H
|
#define FITS_HEADER_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -50,11 +51,12 @@ extern "C" {
|
||||||
accessor functions.
|
accessor functions.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
typedef struct qfits_header {
|
typedef struct qfits_header
|
||||||
void * first ; /* Pointer to list start */
|
{
|
||||||
void * last ; /* Pointer to list end */
|
void *first; /* Pointer to list start */
|
||||||
int n ; /* Number of cards in list */
|
void *last; /* Pointer to list end */
|
||||||
} qfits_header ;
|
int n; /* Number of cards in list */
|
||||||
|
} qfits_header;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function ANSI prototypes
|
Function ANSI prototypes
|
||||||
|
@ -69,7 +71,7 @@ typedef struct qfits_header {
|
||||||
an allocated linked-list handler with an empty card list.
|
an allocated linked-list handler with an empty card list.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_new(void) ;
|
qfits_header *qfits_header_new (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +83,7 @@ qfits_header * qfits_header_new(void) ;
|
||||||
(SIMPLE=T) and the last one (END).
|
(SIMPLE=T) and the last one (END).
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_default(void) ;
|
qfits_header *qfits_header_default (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -99,12 +101,8 @@ qfits_header * qfits_header_default(void) ;
|
||||||
are allowed to get NULL values.
|
are allowed to get NULL values.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_add(
|
void qfits_header_add (qfits_header * hdr,
|
||||||
qfits_header * hdr,
|
char *key, char *val, char *com, char *lin);
|
||||||
char * key,
|
|
||||||
char * val,
|
|
||||||
char * com,
|
|
||||||
char * lin) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -122,13 +120,9 @@ void qfits_header_add(
|
||||||
can be NULL, except after and key.
|
can be NULL, except after and key.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_add_after(
|
void qfits_header_add_after (qfits_header * hdr,
|
||||||
qfits_header * hdr,
|
char *after,
|
||||||
char * after,
|
char *key, char *val, char *com, char *lin);
|
||||||
char * key,
|
|
||||||
char * val,
|
|
||||||
char * com,
|
|
||||||
char * lin) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -144,12 +138,10 @@ void qfits_header_add_after(
|
||||||
NULL except key.
|
NULL except key.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_append(
|
void qfits_header_append (qfits_header * hdr,
|
||||||
qfits_header * hdr,
|
const char *key,
|
||||||
const char * key,
|
const char *val,
|
||||||
const char * val,
|
const char *com, const char *lin);
|
||||||
const char * com,
|
|
||||||
const char * lin) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -162,7 +154,7 @@ void qfits_header_append(
|
||||||
the key is removed.
|
the key is removed.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_del(qfits_header * hdr, char * key) ;
|
void qfits_header_del (qfits_header * hdr, char *key);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -178,7 +170,7 @@ void qfits_header_del(qfits_header * hdr, char * key) ;
|
||||||
line is set to NULL in the card.
|
line is set to NULL in the card.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_mod(qfits_header * hdr, char * key, char * val, char * com) ;
|
void qfits_header_mod (qfits_header * hdr, char *key, char *val, char *com);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -187,7 +179,7 @@ void qfits_header_mod(qfits_header * hdr, char * key, char * val, char * com) ;
|
||||||
@return -1 in error case, 0 otherwise
|
@return -1 in error case, 0 otherwise
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_header_sort(qfits_header ** hdr) ;
|
int qfits_header_sort (qfits_header ** hdr);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +191,7 @@ int qfits_header_sort(qfits_header ** hdr) ;
|
||||||
header. The returned header must be freed using qfits_header_destroy.
|
header. The returned header must be freed using qfits_header_destroy.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_copy(qfits_header * src) ;
|
qfits_header *qfits_header_copy (qfits_header * src);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -211,7 +203,7 @@ qfits_header * qfits_header_copy(qfits_header * src) ;
|
||||||
freed and set to NULL. Useful when a header needs to be reformatted.
|
freed and set to NULL. Useful when a header needs to be reformatted.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_touchall(qfits_header * hdr) ;
|
void qfits_header_touchall (qfits_header * hdr);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -222,7 +214,7 @@ void qfits_header_touchall(qfits_header * hdr) ;
|
||||||
Dump a FITS header to stdout. Mostly for debugging purposes.
|
Dump a FITS header to stdout. Mostly for debugging purposes.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_consoledump(qfits_header * hdr) ;
|
void qfits_header_consoledump (qfits_header * hdr);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -233,7 +225,7 @@ void qfits_header_consoledump(qfits_header * hdr) ;
|
||||||
Frees all memory associated to a given qfits_header object.
|
Frees all memory associated to a given qfits_header object.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_header_destroy(qfits_header * hdr) ;
|
void qfits_header_destroy (qfits_header * hdr);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -249,7 +241,7 @@ void qfits_header_destroy(qfits_header * hdr) ;
|
||||||
Returns NULL if no matching key is found or no value is attached.
|
Returns NULL if no matching key is found or no value is attached.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_header_getstr(qfits_header * hdr, const char * key) ;
|
char *qfits_header_getstr (qfits_header * hdr, const char *key);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -273,7 +265,7 @@ char * qfits_header_getstr(qfits_header * hdr, const char * key) ;
|
||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_header_findmatch(qfits_header * hdr, char * key) ;
|
char *qfits_header_findmatch (qfits_header * hdr, char *key);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -312,13 +304,9 @@ char * qfits_header_findmatch(qfits_header * hdr, char * key) ;
|
||||||
available in this module.
|
available in this module.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_header_getitem(
|
int qfits_header_getitem (qfits_header * hdr,
|
||||||
qfits_header * hdr,
|
int idx,
|
||||||
int idx,
|
char *key, char *val, char *com, char *lin);
|
||||||
char * key,
|
|
||||||
char * val,
|
|
||||||
char * com,
|
|
||||||
char * lin) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -334,7 +322,7 @@ int qfits_header_getitem(
|
||||||
Returns NULL if no matching key is found or no line is attached.
|
Returns NULL if no matching key is found or no line is attached.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_header_getline(qfits_header * hdr, char * key) ;
|
char *qfits_header_getline (qfits_header * hdr, char *key);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -351,7 +339,7 @@ char * qfits_header_getline(qfits_header * hdr, char * key) ;
|
||||||
Returns NULL if no matching key is found or no comment is attached.
|
Returns NULL if no matching key is found or no comment is attached.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_header_getcom(qfits_header * hdr, char * key) ;
|
char *qfits_header_getcom (qfits_header * hdr, char *key);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -366,7 +354,7 @@ char * qfits_header_getcom(qfits_header * hdr, char * key) ;
|
||||||
attached.
|
attached.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_header_getint(qfits_header * hdr, const char * key, int errval) ;
|
int qfits_header_getint (qfits_header * hdr, const char *key, int errval);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -381,7 +369,8 @@ int qfits_header_getint(qfits_header * hdr, const char * key, int errval) ;
|
||||||
attached.
|
attached.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
double qfits_header_getdouble(qfits_header * hdr, const char * key, double errval) ;
|
double qfits_header_getdouble (qfits_header * hdr, const char *key,
|
||||||
|
double errval);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -405,7 +394,8 @@ double qfits_header_getdouble(qfits_header * hdr, const char * key, double errva
|
||||||
beginning with a 'n' (no), a 'f' (false) or the digit '0'.
|
beginning with a 'n' (no), a 'f' (false) or the digit '0'.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_header_getboolean(qfits_header * hdr, const char * key, int errval) ;
|
int qfits_header_getboolean (qfits_header * hdr, const char *key,
|
||||||
|
int errval);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -421,7 +411,7 @@ int qfits_header_getboolean(qfits_header * hdr, const char * key, int errval) ;
|
||||||
Formatting is done according to FITS standard.
|
Formatting is done according to FITS standard.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void keytuple2str(char * line, char * key, char * val, char * com) ;
|
void keytuple2str (char *line, char *key, char *val, char *com);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -433,7 +423,7 @@ void keytuple2str(char * line, char * key, char * val, char * com) ;
|
||||||
Dumps a FITS header to an opened file pointer.
|
Dumps a FITS header to an opened file pointer.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_header_dump(qfits_header * hdr, FILE * out) ;
|
int qfits_header_dump (qfits_header * hdr, FILE * out);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -446,7 +436,7 @@ int qfits_header_dump(qfits_header * hdr, FILE * out) ;
|
||||||
This function is meant to create hdr files.
|
This function is meant to create hdr files.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_header_dump_hdr(qfits_header * hdr, FILE * out) ;
|
int qfits_header_dump_hdr (qfits_header * hdr, FILE * out);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -464,7 +454,7 @@ int qfits_header_dump_hdr(qfits_header * hdr, FILE * out) ;
|
||||||
'hsize'. The returned block must be deallocated using free().
|
'hsize'. The returned block must be deallocated using free().
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_header_to_memblock(qfits_header * fh, int * hsize) ;
|
char *qfits_header_to_memblock (qfits_header * fh, int *hsize);
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -58,121 +58,128 @@
|
||||||
of error.
|
of error.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_datamd5(char * filename)
|
char *
|
||||||
|
qfits_datamd5 (char *filename)
|
||||||
{
|
{
|
||||||
static char datamd5[MD5HASHSZ+1] ;
|
static char datamd5[MD5HASHSZ + 1];
|
||||||
struct MD5Context ctx ;
|
struct MD5Context ctx;
|
||||||
unsigned char digest[16] ;
|
unsigned char digest[16];
|
||||||
FILE * in ;
|
FILE *in;
|
||||||
char buf[FITS_BLOCK_SIZE];
|
char buf[FITS_BLOCK_SIZE];
|
||||||
char * buf_c ;
|
char *buf_c;
|
||||||
int i ;
|
int i;
|
||||||
int in_header ;
|
int in_header;
|
||||||
int check_fits ;
|
int check_fits;
|
||||||
|
|
||||||
/* Check entries */
|
/* Check entries */
|
||||||
if (filename==NULL) return NULL ;
|
if (filename == NULL)
|
||||||
/* Open input file */
|
return NULL;
|
||||||
if ((in=fopen(filename, "r"))==NULL) {
|
/* Open input file */
|
||||||
qfits_error("cannot open file %s", filename);
|
if ((in = fopen (filename, "r")) == NULL)
|
||||||
return NULL ;
|
{
|
||||||
|
qfits_error ("cannot open file %s", filename);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Initialize all variables */
|
/* Initialize all variables */
|
||||||
MD5Init(&ctx);
|
MD5Init (&ctx);
|
||||||
in_header=1 ;
|
in_header = 1;
|
||||||
check_fits=0 ;
|
check_fits = 0;
|
||||||
/* Loop over input file */
|
/* Loop over input file */
|
||||||
while (fread(buf, 1, FITS_BLOCK_SIZE, in)==FITS_BLOCK_SIZE) {
|
while (fread (buf, 1, FITS_BLOCK_SIZE, in) == FITS_BLOCK_SIZE)
|
||||||
/* First time in the loop: check the file is FITS */
|
{
|
||||||
if (check_fits==0) {
|
/* First time in the loop: check the file is FITS */
|
||||||
/* Examine first characters in block */
|
if (check_fits == 0)
|
||||||
if (buf[0]!='S' ||
|
{
|
||||||
buf[1]!='I' ||
|
/* Examine first characters in block */
|
||||||
buf[2]!='M' ||
|
if (buf[0] != 'S' ||
|
||||||
buf[3]!='P' ||
|
buf[1] != 'I' ||
|
||||||
buf[4]!='L' ||
|
buf[2] != 'M' ||
|
||||||
buf[5]!='E' ||
|
buf[3] != 'P' ||
|
||||||
buf[6]!=' ' ||
|
buf[4] != 'L' ||
|
||||||
buf[7]!=' ' ||
|
buf[5] != 'E' ||
|
||||||
buf[8]!='=') {
|
buf[6] != ' ' || buf[7] != ' ' || buf[8] != '=')
|
||||||
qfits_error("file [%s] is not FITS\n", filename);
|
{
|
||||||
fclose(in);
|
qfits_error ("file [%s] is not FITS\n", filename);
|
||||||
return NULL ;
|
fclose (in);
|
||||||
} else {
|
return NULL;
|
||||||
check_fits=1 ;
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
if (in_header) {
|
check_fits = 1;
|
||||||
buf_c = buf ;
|
}
|
||||||
for (i=0 ; i<FITS_NCARDS ; i++) {
|
|
||||||
if (buf_c[0]=='E' &&
|
|
||||||
buf_c[1]=='N' &&
|
|
||||||
buf_c[2]=='D' &&
|
|
||||||
buf_c[3]==' ') {
|
|
||||||
in_header=0 ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
buf_c += FITS_LINESZ ;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* If current block is a data block */
|
|
||||||
/* Try to locate an extension header */
|
|
||||||
if (buf[0]=='X' &&
|
|
||||||
buf[1]=='T' &&
|
|
||||||
buf[2]=='E' &&
|
|
||||||
buf[3]=='N' &&
|
|
||||||
buf[4]=='S' &&
|
|
||||||
buf[5]=='I' &&
|
|
||||||
buf[6]=='O' &&
|
|
||||||
buf[7]=='N' &&
|
|
||||||
buf[8]=='=') {
|
|
||||||
in_header=1 ;
|
|
||||||
buf_c = buf ;
|
|
||||||
for (i=0 ; i<FITS_NCARDS ; i++) {
|
|
||||||
/* Try to find an END marker in this block */
|
|
||||||
if (buf_c[0]=='E' &&
|
|
||||||
buf_c[1]=='N' &&
|
|
||||||
buf_c[2]=='D' &&
|
|
||||||
buf_c[3]==' ') {
|
|
||||||
/* Found END marker in same block as XTENSION */
|
|
||||||
in_header=0;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
buf_c += FITS_LINESZ ;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MD5Update(&ctx, (unsigned char *)buf, FITS_BLOCK_SIZE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(in);
|
|
||||||
if (check_fits==0) {
|
|
||||||
/* Never went through the read loop: file is not FITS */
|
|
||||||
qfits_error("file [%s] is not FITS", filename);
|
|
||||||
return NULL ;
|
|
||||||
}
|
}
|
||||||
/* Got to the end of file: summarize */
|
if (in_header)
|
||||||
MD5Final(digest, &ctx);
|
{
|
||||||
/* Write digest into a string */
|
buf_c = buf;
|
||||||
sprintf(datamd5,
|
for (i = 0; i < FITS_NCARDS; i++)
|
||||||
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
{
|
||||||
digest[ 0],
|
if (buf_c[0] == 'E' &&
|
||||||
digest[ 1],
|
buf_c[1] == 'N' && buf_c[2] == 'D' && buf_c[3] == ' ')
|
||||||
digest[ 2],
|
{
|
||||||
digest[ 3],
|
in_header = 0;
|
||||||
digest[ 4],
|
break;
|
||||||
digest[ 5],
|
}
|
||||||
digest[ 6],
|
buf_c += FITS_LINESZ;
|
||||||
digest[ 7],
|
}
|
||||||
digest[ 8],
|
}
|
||||||
digest[ 9],
|
else
|
||||||
digest[10],
|
{
|
||||||
digest[11],
|
/* If current block is a data block */
|
||||||
digest[12],
|
/* Try to locate an extension header */
|
||||||
digest[13],
|
if (buf[0] == 'X' &&
|
||||||
digest[14],
|
buf[1] == 'T' &&
|
||||||
digest[15]);
|
buf[2] == 'E' &&
|
||||||
return datamd5 ;
|
buf[3] == 'N' &&
|
||||||
|
buf[4] == 'S' &&
|
||||||
|
buf[5] == 'I' &&
|
||||||
|
buf[6] == 'O' && buf[7] == 'N' && buf[8] == '=')
|
||||||
|
{
|
||||||
|
in_header = 1;
|
||||||
|
buf_c = buf;
|
||||||
|
for (i = 0; i < FITS_NCARDS; i++)
|
||||||
|
{
|
||||||
|
/* Try to find an END marker in this block */
|
||||||
|
if (buf_c[0] == 'E' &&
|
||||||
|
buf_c[1] == 'N' && buf_c[2] == 'D' && buf_c[3] == ' ')
|
||||||
|
{
|
||||||
|
/* Found END marker in same block as XTENSION */
|
||||||
|
in_header = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf_c += FITS_LINESZ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MD5Update (&ctx, (unsigned char *) buf, FITS_BLOCK_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose (in);
|
||||||
|
if (check_fits == 0)
|
||||||
|
{
|
||||||
|
/* Never went through the read loop: file is not FITS */
|
||||||
|
qfits_error ("file [%s] is not FITS", filename);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* Got to the end of file: summarize */
|
||||||
|
MD5Final (digest, &ctx);
|
||||||
|
/* Write digest into a string */
|
||||||
|
sprintf (datamd5,
|
||||||
|
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
|
digest[0],
|
||||||
|
digest[1],
|
||||||
|
digest[2],
|
||||||
|
digest[3],
|
||||||
|
digest[4],
|
||||||
|
digest[5],
|
||||||
|
digest[6],
|
||||||
|
digest[7],
|
||||||
|
digest[8],
|
||||||
|
digest[9],
|
||||||
|
digest[10],
|
||||||
|
digest[11], digest[12], digest[13], digest[14], digest[15]);
|
||||||
|
return datamd5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
of error.
|
of error.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_datamd5(char * filename);
|
char *qfits_datamd5 (char *filename);
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,63 +50,73 @@
|
||||||
allocated in this function, so do not modify or try to free it.
|
allocated in this function, so do not modify or try to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_getkey(char * line)
|
char *
|
||||||
|
qfits_getkey (char *line)
|
||||||
{
|
{
|
||||||
static char key[81];
|
static char key[81];
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
if (line==NULL) {
|
if (line == NULL)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getkey: NULL input line\n");
|
printf ("qfits_getkey: NULL input line\n");
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Special case: blank keyword */
|
/* Special case: blank keyword */
|
||||||
if (!strncmp(line, " ", 8)) {
|
if (!strncmp (line, " ", 8))
|
||||||
strcpy(key, " ");
|
{
|
||||||
return key ;
|
strcpy (key, " ");
|
||||||
}
|
return key;
|
||||||
/* Sort out special cases: HISTORY, COMMENT, END do not have = in line */
|
}
|
||||||
if (!strncmp(line, "HISTORY ", 8)) {
|
/* Sort out special cases: HISTORY, COMMENT, END do not have = in line */
|
||||||
strcpy(key, "HISTORY");
|
if (!strncmp (line, "HISTORY ", 8))
|
||||||
return key ;
|
{
|
||||||
}
|
strcpy (key, "HISTORY");
|
||||||
if (!strncmp(line, "COMMENT ", 8)) {
|
return key;
|
||||||
strcpy(key, "COMMENT");
|
}
|
||||||
return key ;
|
if (!strncmp (line, "COMMENT ", 8))
|
||||||
}
|
{
|
||||||
if (!strncmp(line, "END ", 4)) {
|
strcpy (key, "COMMENT");
|
||||||
strcpy(key, "END");
|
return key;
|
||||||
return key ;
|
}
|
||||||
}
|
if (!strncmp (line, "END ", 4))
|
||||||
|
{
|
||||||
|
strcpy (key, "END");
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
memset(key, 0, 81);
|
memset (key, 0, 81);
|
||||||
/* General case: look for the first equal sign */
|
/* General case: look for the first equal sign */
|
||||||
i=0 ;
|
i = 0;
|
||||||
while (line[i]!='=' && i<80) i++ ;
|
while (line[i] != '=' && i < 80)
|
||||||
if (i>=80) {
|
i++;
|
||||||
|
if (i >= 80)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getkey: cannot find equal sign\n");
|
printf ("qfits_getkey: cannot find equal sign\n");
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
}
|
||||||
i-- ;
|
i--;
|
||||||
/* Equal sign found, now backtrack on blanks */
|
/* Equal sign found, now backtrack on blanks */
|
||||||
while (line[i]==' ' && i>=0) i-- ;
|
while (line[i] == ' ' && i >= 0)
|
||||||
if (i<=0) {
|
i--;
|
||||||
|
if (i <= 0)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getkey: error backtracking on blanks\n");
|
printf ("qfits_getkey: error backtracking on blanks\n");
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
}
|
||||||
i++ ;
|
i++;
|
||||||
|
|
||||||
/* Copy relevant characters into output buffer */
|
/* Copy relevant characters into output buffer */
|
||||||
strncpy(key, line, i) ;
|
strncpy (key, line, i);
|
||||||
/* Null-terminate the string */
|
/* Null-terminate the string */
|
||||||
key[i+1] = (char)0;
|
key[i + 1] = (char) 0;
|
||||||
return key ;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -121,124 +131,145 @@ char * qfits_getkey(char * line)
|
||||||
modify or try to free it.
|
modify or try to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_getvalue(char * line)
|
char *
|
||||||
|
qfits_getvalue (char *line)
|
||||||
{
|
{
|
||||||
static char value[81] ;
|
static char value[81];
|
||||||
int i ;
|
int i;
|
||||||
int from, to ;
|
int from, to;
|
||||||
int inq ;
|
int inq;
|
||||||
|
|
||||||
if (line==NULL) {
|
if (line == NULL)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getvalue: NULL input line\n");
|
printf ("qfits_getvalue: NULL input line\n");
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* Special cases */
|
|
||||||
|
|
||||||
/* END has no associated value */
|
|
||||||
if (!strncmp(line, "END ", 4)) {
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* HISTORY has for value everything else on the line, stripping
|
|
||||||
* blanks before and after. Blank HISTORY is also accepted.
|
|
||||||
*/
|
|
||||||
memset(value, 0, 81);
|
|
||||||
|
|
||||||
if (!strncmp(line, "HISTORY ", 8) || !strncmp(line, " ", 8)) {
|
|
||||||
i=7 ;
|
|
||||||
/* Strip blanks from the left side */
|
|
||||||
while (line[i]==' ' && i<80) i++ ;
|
|
||||||
if (i>=80) return NULL ; /* Blank HISTORY */
|
|
||||||
from=i ;
|
|
||||||
|
|
||||||
/* Strip blanks from the right side */
|
|
||||||
to=79 ;
|
|
||||||
while (line[to]==' ') to-- ;
|
|
||||||
/* Copy relevant characters into output buffer */
|
|
||||||
strncpy(value, line+from, to-from+1);
|
|
||||||
/* Null-terminate the string */
|
|
||||||
value[to-from+1] = (char)0;
|
|
||||||
return value ;
|
|
||||||
} else if (!strncmp(line, "COMMENT ", 8)) {
|
|
||||||
/* COMMENT is like HISTORY */
|
|
||||||
/* Strip blanks from the left side */
|
|
||||||
i=7 ;
|
|
||||||
while (line[i]==' ' && i<80) i++ ;
|
|
||||||
if (i>=80) return NULL ;
|
|
||||||
from=i ;
|
|
||||||
|
|
||||||
/* Strip blanks from the right side */
|
|
||||||
to=79 ;
|
|
||||||
while (line[to]==' ') to-- ;
|
|
||||||
|
|
||||||
if (to<from) {
|
|
||||||
#ifdef DEBUG_FITSHEADER
|
|
||||||
printf("qfits_getvalue: inconsistent value search in COMMENT\n");
|
|
||||||
#endif
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
/* Copy relevant characters into output buffer */
|
|
||||||
strncpy(value, line+from, to-from+1);
|
|
||||||
/* Null-terminate the string */
|
|
||||||
value[to-from+1] = (char)0;
|
|
||||||
return value ;
|
|
||||||
}
|
|
||||||
/* General case - Get past the keyword */
|
|
||||||
i=0 ;
|
|
||||||
while (line[i]!='=' && i<80) i++ ;
|
|
||||||
if (i>80) {
|
|
||||||
#ifdef DEBUG_FITSHEADER
|
|
||||||
printf("qfits_getvalue: no equal sign found on line\n");
|
|
||||||
#endif
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
i++ ;
|
|
||||||
while (line[i]==' ' && i<80) i++ ;
|
|
||||||
if (i>80) {
|
|
||||||
#ifdef DEBUG_FITSHEADER
|
|
||||||
printf("qfits_getvalue: no value past the equal sign\n");
|
|
||||||
#endif
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
from=i;
|
|
||||||
|
|
||||||
/* Now value section: Look for the first slash '/' outside a string */
|
|
||||||
inq = 0 ;
|
|
||||||
while (i<80) {
|
|
||||||
if (line[i]=='\'')
|
|
||||||
inq=!inq ;
|
|
||||||
if (line[i]=='/')
|
|
||||||
if (!inq)
|
|
||||||
break ;
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
i-- ;
|
|
||||||
|
|
||||||
/* Backtrack on blanks */
|
/* Special cases */
|
||||||
while (line[i]==' ' && i>=0) i-- ;
|
|
||||||
if (i<0) {
|
|
||||||
#ifdef DEBUG_FITSHEADER
|
|
||||||
printf("qfits_getvalue: error backtracking on blanks\n");
|
|
||||||
#endif
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
to=i ;
|
|
||||||
|
|
||||||
if (to<from) {
|
/* END has no associated value */
|
||||||
|
if (!strncmp (line, "END ", 4))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* HISTORY has for value everything else on the line, stripping
|
||||||
|
* blanks before and after. Blank HISTORY is also accepted.
|
||||||
|
*/
|
||||||
|
memset (value, 0, 81);
|
||||||
|
|
||||||
|
if (!strncmp (line, "HISTORY ", 8) || !strncmp (line, " ", 8))
|
||||||
|
{
|
||||||
|
i = 7;
|
||||||
|
/* Strip blanks from the left side */
|
||||||
|
while (line[i] == ' ' && i < 80)
|
||||||
|
i++;
|
||||||
|
if (i >= 80)
|
||||||
|
return NULL; /* Blank HISTORY */
|
||||||
|
from = i;
|
||||||
|
|
||||||
|
/* Strip blanks from the right side */
|
||||||
|
to = 79;
|
||||||
|
while (line[to] == ' ')
|
||||||
|
to--;
|
||||||
|
/* Copy relevant characters into output buffer */
|
||||||
|
strncpy (value, line + from, to - from + 1);
|
||||||
|
/* Null-terminate the string */
|
||||||
|
value[to - from + 1] = (char) 0;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else if (!strncmp (line, "COMMENT ", 8))
|
||||||
|
{
|
||||||
|
/* COMMENT is like HISTORY */
|
||||||
|
/* Strip blanks from the left side */
|
||||||
|
i = 7;
|
||||||
|
while (line[i] == ' ' && i < 80)
|
||||||
|
i++;
|
||||||
|
if (i >= 80)
|
||||||
|
return NULL;
|
||||||
|
from = i;
|
||||||
|
|
||||||
|
/* Strip blanks from the right side */
|
||||||
|
to = 79;
|
||||||
|
while (line[to] == ' ')
|
||||||
|
to--;
|
||||||
|
|
||||||
|
if (to < from)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getvalue: from>to?\n");
|
printf ("qfits_getvalue: inconsistent value search in COMMENT\n");
|
||||||
printf("line=[%s]\n", line);
|
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Copy relevant characters into output buffer */
|
/* Copy relevant characters into output buffer */
|
||||||
strncpy(value, line+from, to-from+1);
|
strncpy (value, line + from, to - from + 1);
|
||||||
/* Null-terminate the string */
|
/* Null-terminate the string */
|
||||||
value[to-from+1] = (char)0;
|
value[to - from + 1] = (char) 0;
|
||||||
return value ;
|
return value;
|
||||||
|
}
|
||||||
|
/* General case - Get past the keyword */
|
||||||
|
i = 0;
|
||||||
|
while (line[i] != '=' && i < 80)
|
||||||
|
i++;
|
||||||
|
if (i > 80)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_FITSHEADER
|
||||||
|
printf ("qfits_getvalue: no equal sign found on line\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
while (line[i] == ' ' && i < 80)
|
||||||
|
i++;
|
||||||
|
if (i > 80)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_FITSHEADER
|
||||||
|
printf ("qfits_getvalue: no value past the equal sign\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
from = i;
|
||||||
|
|
||||||
|
/* Now value section: Look for the first slash '/' outside a string */
|
||||||
|
inq = 0;
|
||||||
|
while (i < 80)
|
||||||
|
{
|
||||||
|
if (line[i] == '\'')
|
||||||
|
inq = !inq;
|
||||||
|
if (line[i] == '/')
|
||||||
|
if (!inq)
|
||||||
|
break;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
|
||||||
|
/* Backtrack on blanks */
|
||||||
|
while (line[i] == ' ' && i >= 0)
|
||||||
|
i--;
|
||||||
|
if (i < 0)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_FITSHEADER
|
||||||
|
printf ("qfits_getvalue: error backtracking on blanks\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
to = i;
|
||||||
|
|
||||||
|
if (to < from)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_FITSHEADER
|
||||||
|
printf ("qfits_getvalue: from>to?\n");
|
||||||
|
printf ("line=[%s]\n", line);
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* Copy relevant characters into output buffer */
|
||||||
|
strncpy (value, line + from, to - from + 1);
|
||||||
|
/* Null-terminate the string */
|
||||||
|
value[to - from + 1] = (char) 0;
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -253,74 +284,87 @@ char * qfits_getvalue(char * line)
|
||||||
modify or try to free it.
|
modify or try to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_getcomment(char * line)
|
char *
|
||||||
|
qfits_getcomment (char *line)
|
||||||
{
|
{
|
||||||
static char comment[81];
|
static char comment[81];
|
||||||
int i ;
|
int i;
|
||||||
int from, to ;
|
int from, to;
|
||||||
int inq ;
|
int inq;
|
||||||
|
|
||||||
if (line==NULL) {
|
if (line == NULL)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getcomment: null line in input\n");
|
printf ("qfits_getcomment: null line in input\n");
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Special cases: END, HISTORY, COMMENT and blank have no comment */
|
/* Special cases: END, HISTORY, COMMENT and blank have no comment */
|
||||||
if (!strncmp(line, "END ", 4)) return NULL ;
|
if (!strncmp (line, "END ", 4))
|
||||||
if (!strncmp(line, "HISTORY ", 8)) return NULL ;
|
return NULL;
|
||||||
if (!strncmp(line, "COMMENT ", 8)) return NULL ;
|
if (!strncmp (line, "HISTORY ", 8))
|
||||||
if (!strncmp(line, " ", 8)) return NULL ;
|
return NULL;
|
||||||
|
if (!strncmp (line, "COMMENT ", 8))
|
||||||
|
return NULL;
|
||||||
|
if (!strncmp (line, " ", 8))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
memset(comment, 0, 81);
|
memset (comment, 0, 81);
|
||||||
/* Get past the keyword */
|
/* Get past the keyword */
|
||||||
i=0 ;
|
i = 0;
|
||||||
while (line[i]!='=' && i<80) i++ ;
|
while (line[i] != '=' && i < 80)
|
||||||
if (i>=80) {
|
i++;
|
||||||
|
if (i >= 80)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getcomment: no equal sign on line\n");
|
printf ("qfits_getcomment: no equal sign on line\n");
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
}
|
||||||
i++ ;
|
i++;
|
||||||
|
|
||||||
/* Get past the value until the slash */
|
|
||||||
inq = 0 ;
|
|
||||||
while (i<80) {
|
|
||||||
if (line[i]=='\'')
|
|
||||||
inq = !inq ;
|
|
||||||
if (line[i]=='/')
|
|
||||||
if (!inq)
|
|
||||||
break ;
|
|
||||||
i++ ;
|
|
||||||
}
|
|
||||||
if (i>=80) {
|
|
||||||
#ifdef DEBUG_FITSHEADER
|
|
||||||
printf("qfits_getcomment: no slash found on line\n");
|
|
||||||
#endif
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
i++ ;
|
|
||||||
/* Get past the first blanks */
|
|
||||||
while (line[i]==' ') i++ ;
|
|
||||||
from=i ;
|
|
||||||
|
|
||||||
/* Now backtrack from the end of the line to the first non-blank char */
|
/* Get past the value until the slash */
|
||||||
to=79 ;
|
inq = 0;
|
||||||
while (line[to]==' ') to-- ;
|
while (i < 80)
|
||||||
|
{
|
||||||
if (to<from) {
|
if (line[i] == '\'')
|
||||||
|
inq = !inq;
|
||||||
|
if (line[i] == '/')
|
||||||
|
if (!inq)
|
||||||
|
break;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i >= 80)
|
||||||
|
{
|
||||||
#ifdef DEBUG_FITSHEADER
|
#ifdef DEBUG_FITSHEADER
|
||||||
printf("qfits_getcomment: from>to?\n");
|
printf ("qfits_getcomment: no slash found on line\n");
|
||||||
#endif
|
#endif
|
||||||
return NULL ;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Copy relevant characters into output buffer */
|
i++;
|
||||||
strncpy(comment, line+from, to-from+1);
|
/* Get past the first blanks */
|
||||||
/* Null-terminate the string */
|
while (line[i] == ' ')
|
||||||
comment[to-from+1] = (char)0;
|
i++;
|
||||||
return comment ;
|
from = i;
|
||||||
|
|
||||||
|
/* Now backtrack from the end of the line to the first non-blank char */
|
||||||
|
to = 79;
|
||||||
|
while (line[to] == ' ')
|
||||||
|
to--;
|
||||||
|
|
||||||
|
if (to < from)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_FITSHEADER
|
||||||
|
printf ("qfits_getcomment: from>to?\n");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* Copy relevant characters into output buffer */
|
||||||
|
strncpy (comment, line + from, to - from + 1);
|
||||||
|
/* Null-terminate the string */
|
||||||
|
comment[to - from + 1] = (char) 0;
|
||||||
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
#define FITSEP_H
|
#define FITSEP_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* <dox> */
|
/* <dox> */
|
||||||
|
@ -41,7 +42,7 @@ extern "C" {
|
||||||
allocated in this function, so do not modify or try to free it.
|
allocated in this function, so do not modify or try to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_getkey(char * line) ;
|
char *qfits_getkey (char *line);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +56,7 @@ char * qfits_getkey(char * line) ;
|
||||||
modify or try to free it.
|
modify or try to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_getvalue(char * line) ;
|
char *qfits_getvalue (char *line);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +70,7 @@ char * qfits_getvalue(char * line) ;
|
||||||
modify or try to free it.
|
modify or try to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_getcomment(char * line) ;
|
char *qfits_getcomment (char *line);
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -35,14 +35,17 @@
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Private to this module
|
Private to this module
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
static int is_blank_line(char * s)
|
static int
|
||||||
|
is_blank_line (char *s)
|
||||||
{
|
{
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
for (i=0 ; i<(int)strlen(s) ; i++) {
|
for (i = 0; i < (int) strlen (s); i++)
|
||||||
if (s[i]!=' ') return 0 ;
|
{
|
||||||
|
if (s[i] != ' ')
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return 1 ;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -70,10 +73,11 @@ static int is_blank_line(char * s)
|
||||||
Value, comment, and original line might be NULL pointers.
|
Value, comment, and original line might be NULL pointers.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_read(char * filename)
|
qfits_header *
|
||||||
|
qfits_header_read (char *filename)
|
||||||
{
|
{
|
||||||
/* Forward job to readext */
|
/* Forward job to readext */
|
||||||
return qfits_header_readext(filename, 0);
|
return qfits_header_readext (filename, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -88,76 +92,86 @@ qfits_header * qfits_header_read(char * filename)
|
||||||
a hdr file.
|
a hdr file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_read_hdr(char * filename)
|
qfits_header *
|
||||||
|
qfits_header_read_hdr (char *filename)
|
||||||
{
|
{
|
||||||
qfits_header * hdr ;
|
qfits_header *hdr;
|
||||||
FILE * in ;
|
FILE *in;
|
||||||
char line[81];
|
char line[81];
|
||||||
char * key,
|
char *key, *val, *com;
|
||||||
* val,
|
int i, j;
|
||||||
* com ;
|
|
||||||
int i, j ;
|
|
||||||
|
|
||||||
/* Check input */
|
/* Check input */
|
||||||
if (filename==NULL) return NULL ;
|
if (filename == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Initialise */
|
/* Initialise */
|
||||||
key = val = com = NULL ;
|
key = val = com = NULL;
|
||||||
|
|
||||||
/* Open the file */
|
/* Open the file */
|
||||||
if ((in=fopen(filename, "r"))==NULL) {
|
if ((in = fopen (filename, "r")) == NULL)
|
||||||
qfits_error("cannot read [%s]", filename) ;
|
{
|
||||||
return NULL ;
|
qfits_error ("cannot read [%s]", filename);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the header */
|
|
||||||
hdr = qfits_header_new() ;
|
|
||||||
|
|
||||||
/* Go through the file */
|
|
||||||
while (fgets(line, 81, in)!=NULL) {
|
|
||||||
for (i=0 ; i<81 ; i++) {
|
|
||||||
if (line[i] == '\n') {
|
|
||||||
for (j=i ; j<81 ; j++) line[j] = ' ' ;
|
|
||||||
line[80] = (char)0 ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!strcmp(line, "END")) {
|
|
||||||
line[3] = ' ';
|
|
||||||
line[4] = (char)0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Rule out blank lines */
|
|
||||||
if (!is_blank_line(line)) {
|
|
||||||
|
|
||||||
/* Get key, value, comment for the current line */
|
/* Create the header */
|
||||||
key = qfits_getkey(line);
|
hdr = qfits_header_new ();
|
||||||
val = qfits_getvalue(line);
|
|
||||||
com = qfits_getcomment(line);
|
|
||||||
|
|
||||||
/* If key or value cannot be found, trigger an error */
|
/* Go through the file */
|
||||||
if (key==NULL) {
|
while (fgets (line, 81, in) != NULL)
|
||||||
qfits_header_destroy(hdr);
|
{
|
||||||
fclose(in) ;
|
for (i = 0; i < 81; i++)
|
||||||
return NULL ;
|
{
|
||||||
}
|
if (line[i] == '\n')
|
||||||
/* Append card to linked-list */
|
{
|
||||||
qfits_header_append(hdr, key, val, com, NULL);
|
for (j = i; j < 81; j++)
|
||||||
}
|
line[j] = ' ';
|
||||||
|
line[80] = (char) 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!strcmp (line, "END"))
|
||||||
|
{
|
||||||
|
line[3] = ' ';
|
||||||
|
line[4] = (char) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rule out blank lines */
|
||||||
|
if (!is_blank_line (line))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Get key, value, comment for the current line */
|
||||||
|
key = qfits_getkey (line);
|
||||||
|
val = qfits_getvalue (line);
|
||||||
|
com = qfits_getcomment (line);
|
||||||
|
|
||||||
|
/* If key or value cannot be found, trigger an error */
|
||||||
|
if (key == NULL)
|
||||||
|
{
|
||||||
|
qfits_header_destroy (hdr);
|
||||||
|
fclose (in);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* Append card to linked-list */
|
||||||
|
qfits_header_append (hdr, key, val, com, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose(in) ;
|
fclose (in);
|
||||||
|
|
||||||
/* The last key should be 'END' */
|
/* The last key should be 'END' */
|
||||||
if (strlen(key)!=3) {
|
if (strlen (key) != 3)
|
||||||
qfits_header_destroy(hdr);
|
{
|
||||||
return NULL ;
|
qfits_header_destroy (hdr);
|
||||||
}
|
return NULL;
|
||||||
if (key[0]!='E' || key[1]!='N' || key[2]!='D') {
|
|
||||||
qfits_header_destroy(hdr);
|
|
||||||
return NULL ;
|
|
||||||
}
|
}
|
||||||
|
if (key[0] != 'E' || key[1] != 'N' || key[2] != 'D')
|
||||||
return hdr ;
|
{
|
||||||
|
qfits_header_destroy (hdr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -171,74 +185,81 @@ qfits_header * qfits_header_read_hdr(char * filename)
|
||||||
object.
|
object.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_read_hdr_string(
|
qfits_header *
|
||||||
unsigned char * hdr_str,
|
qfits_header_read_hdr_string (unsigned char *hdr_str, int nb_char)
|
||||||
int nb_char)
|
|
||||||
{
|
{
|
||||||
qfits_header * hdr ;
|
qfits_header *hdr;
|
||||||
char line[81];
|
char line[81];
|
||||||
char * key,
|
char *key, *val, *com;
|
||||||
* val,
|
int ind;
|
||||||
* com ;
|
int i, j;
|
||||||
int ind ;
|
|
||||||
int i, j ;
|
|
||||||
|
|
||||||
/* Check input */
|
/* Check input */
|
||||||
if (hdr_str==NULL) return NULL ;
|
if (hdr_str == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Initialise */
|
/* Initialise */
|
||||||
key = val = com = NULL ;
|
key = val = com = NULL;
|
||||||
|
|
||||||
/* Create the header */
|
/* Create the header */
|
||||||
hdr = qfits_header_new() ;
|
hdr = qfits_header_new ();
|
||||||
|
|
||||||
/* Go through the file */
|
|
||||||
ind = 0 ;
|
|
||||||
while (ind <= nb_char - 80) {
|
|
||||||
strncpy(line, (char*)hdr_str + ind, 80) ;
|
|
||||||
line[80] = (char)0 ;
|
|
||||||
for (i=0 ; i<81 ; i++) {
|
|
||||||
if (line[i] == '\n') {
|
|
||||||
for (j=i ; j<81 ; j++) line[j] = ' ' ;
|
|
||||||
line[80] = (char)0 ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!strcmp(line, "END")) {
|
|
||||||
line[3] = ' ';
|
|
||||||
line[4] = (char)0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Rule out blank lines */
|
|
||||||
if (!is_blank_line(line)) {
|
|
||||||
|
|
||||||
/* Get key, value, comment for the current line */
|
/* Go through the file */
|
||||||
key = qfits_getkey(line);
|
ind = 0;
|
||||||
val = qfits_getvalue(line);
|
while (ind <= nb_char - 80)
|
||||||
com = qfits_getcomment(line);
|
{
|
||||||
|
strncpy (line, (char *) hdr_str + ind, 80);
|
||||||
|
line[80] = (char) 0;
|
||||||
|
for (i = 0; i < 81; i++)
|
||||||
|
{
|
||||||
|
if (line[i] == '\n')
|
||||||
|
{
|
||||||
|
for (j = i; j < 81; j++)
|
||||||
|
line[j] = ' ';
|
||||||
|
line[80] = (char) 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!strcmp (line, "END"))
|
||||||
|
{
|
||||||
|
line[3] = ' ';
|
||||||
|
line[4] = (char) 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* If key or value cannot be found, trigger an error */
|
/* Rule out blank lines */
|
||||||
if (key==NULL) {
|
if (!is_blank_line (line))
|
||||||
qfits_header_destroy(hdr);
|
{
|
||||||
return NULL ;
|
|
||||||
}
|
/* Get key, value, comment for the current line */
|
||||||
/* Append card to linked-list */
|
key = qfits_getkey (line);
|
||||||
qfits_header_append(hdr, key, val, com, NULL);
|
val = qfits_getvalue (line);
|
||||||
}
|
com = qfits_getcomment (line);
|
||||||
ind += 80 ;
|
|
||||||
|
/* If key or value cannot be found, trigger an error */
|
||||||
|
if (key == NULL)
|
||||||
|
{
|
||||||
|
qfits_header_destroy (hdr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* Append card to linked-list */
|
||||||
|
qfits_header_append (hdr, key, val, com, NULL);
|
||||||
|
}
|
||||||
|
ind += 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The last key should be 'END' */
|
/* The last key should be 'END' */
|
||||||
if (strlen(key)!=3) {
|
if (strlen (key) != 3)
|
||||||
qfits_header_destroy(hdr);
|
{
|
||||||
return NULL ;
|
qfits_header_destroy (hdr);
|
||||||
}
|
return NULL;
|
||||||
if (key[0]!='E' || key[1]!='N' || key[2]!='D') {
|
|
||||||
qfits_header_destroy(hdr);
|
|
||||||
return NULL ;
|
|
||||||
}
|
}
|
||||||
|
if (key[0] != 'E' || key[1] != 'N' || key[2] != 'D')
|
||||||
return hdr ;
|
{
|
||||||
|
qfits_header_destroy (hdr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -255,80 +276,85 @@ qfits_header * qfits_header_read_hdr_string(
|
||||||
Returns NULL in case of error.
|
Returns NULL in case of error.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_readext(char * filename, int xtnum)
|
qfits_header *
|
||||||
|
qfits_header_readext (char *filename, int xtnum)
|
||||||
{
|
{
|
||||||
qfits_header* hdr ;
|
qfits_header *hdr;
|
||||||
int n_ext ;
|
int n_ext;
|
||||||
char line[81];
|
char line[81];
|
||||||
char * where ;
|
char *where;
|
||||||
char * start ;
|
char *start;
|
||||||
char * key,
|
char *key, *val, *com;
|
||||||
* val,
|
int seg_start;
|
||||||
* com ;
|
int seg_size;
|
||||||
int seg_start ;
|
size_t size;
|
||||||
int seg_size ;
|
|
||||||
size_t size ;
|
|
||||||
|
|
||||||
/* Check input */
|
/* Check input */
|
||||||
if (filename==NULL || xtnum<0)
|
if (filename == NULL || xtnum < 0)
|
||||||
return NULL ;
|
return NULL;
|
||||||
|
|
||||||
/* Check that there are enough extensions */
|
/* Check that there are enough extensions */
|
||||||
if (xtnum>0) {
|
if (xtnum > 0)
|
||||||
n_ext = qfits_query_n_ext(filename);
|
{
|
||||||
if (xtnum>n_ext) {
|
n_ext = qfits_query_n_ext (filename);
|
||||||
return NULL ;
|
if (xtnum > n_ext)
|
||||||
}
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get offset to the extension header */
|
/* Get offset to the extension header */
|
||||||
if (qfits_get_hdrinfo(filename, xtnum, &seg_start, &seg_size)!=0) {
|
if (qfits_get_hdrinfo (filename, xtnum, &seg_start, &seg_size) != 0)
|
||||||
return NULL ;
|
{
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Memory-map the input file */
|
/* Memory-map the input file */
|
||||||
start = falloc(filename, seg_start, &size) ;
|
start = falloc (filename, seg_start, &size);
|
||||||
if (start==NULL) return NULL ;
|
if (start == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
hdr = qfits_header_new() ;
|
hdr = qfits_header_new ();
|
||||||
where = start ;
|
where = start;
|
||||||
while (1) {
|
while (1)
|
||||||
memcpy(line, where, 80);
|
{
|
||||||
line[80] = (char)0;
|
memcpy (line, where, 80);
|
||||||
|
line[80] = (char) 0;
|
||||||
|
|
||||||
/* Rule out blank lines */
|
/* Rule out blank lines */
|
||||||
if (!is_blank_line(line)) {
|
if (!is_blank_line (line))
|
||||||
|
{
|
||||||
|
|
||||||
/* Get key, value, comment for the current line */
|
/* Get key, value, comment for the current line */
|
||||||
key = qfits_getkey(line);
|
key = qfits_getkey (line);
|
||||||
val = qfits_getvalue(line);
|
val = qfits_getvalue (line);
|
||||||
com = qfits_getcomment(line);
|
com = qfits_getcomment (line);
|
||||||
|
|
||||||
/* If key or value cannot be found, trigger an error */
|
/* If key or value cannot be found, trigger an error */
|
||||||
if (key==NULL) {
|
if (key == NULL)
|
||||||
qfits_header_destroy(hdr);
|
{
|
||||||
hdr = NULL ;
|
qfits_header_destroy (hdr);
|
||||||
break ;
|
hdr = NULL;
|
||||||
}
|
break;
|
||||||
/* Append card to linked-list */
|
}
|
||||||
qfits_header_append(hdr, key, val, com, line);
|
/* Append card to linked-list */
|
||||||
/* Check for END keyword */
|
qfits_header_append (hdr, key, val, com, line);
|
||||||
if (strlen(key)==3)
|
/* Check for END keyword */
|
||||||
if (key[0]=='E' &&
|
if (strlen (key) == 3)
|
||||||
key[1]=='N' &&
|
if (key[0] == 'E' && key[1] == 'N' && key[2] == 'D')
|
||||||
key[2]=='D')
|
break;
|
||||||
break ;
|
}
|
||||||
}
|
where += 80;
|
||||||
where += 80 ;
|
/* If reaching the end of file, trigger an error */
|
||||||
/* If reaching the end of file, trigger an error */
|
if ((int) (where - start) >= (int) (seg_size + 80))
|
||||||
if ((int)(where-start)>=(int)(seg_size+80)) {
|
{
|
||||||
qfits_header_destroy(hdr);
|
qfits_header_destroy (hdr);
|
||||||
hdr = NULL ;
|
hdr = NULL;
|
||||||
break ;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fdealloc(start, seg_start, size) ;
|
fdealloc (start, seg_start, size);
|
||||||
return hdr ;
|
return hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -341,34 +367,38 @@ qfits_header * qfits_header_readext(char * filename, int xtnum)
|
||||||
for the file size to reach a multiple of 2880, as required by FITS.
|
for the file size to reach a multiple of 2880, as required by FITS.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_zeropad(char * filename)
|
void
|
||||||
|
qfits_zeropad (char *filename)
|
||||||
{
|
{
|
||||||
struct stat sta ;
|
struct stat sta;
|
||||||
int size ;
|
int size;
|
||||||
int remaining;
|
int remaining;
|
||||||
FILE * out ;
|
FILE *out;
|
||||||
char * buf;
|
char *buf;
|
||||||
|
|
||||||
if (filename==NULL) return ;
|
if (filename == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Get file size in bytes */
|
/* Get file size in bytes */
|
||||||
if (stat(filename, &sta)!=0) {
|
if (stat (filename, &sta) != 0)
|
||||||
return ;
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
size = (int)sta.st_size ;
|
size = (int) sta.st_size;
|
||||||
/* Compute number of zeros to pad */
|
/* Compute number of zeros to pad */
|
||||||
remaining = size % FITS_BLOCK_SIZE ;
|
remaining = size % FITS_BLOCK_SIZE;
|
||||||
if (remaining==0) return ;
|
if (remaining == 0)
|
||||||
remaining = FITS_BLOCK_SIZE - remaining ;
|
return;
|
||||||
|
remaining = FITS_BLOCK_SIZE - remaining;
|
||||||
|
|
||||||
/* Open file, dump zeros, exit */
|
/* Open file, dump zeros, exit */
|
||||||
if ((out=fopen(filename, "a"))==NULL)
|
if ((out = fopen (filename, "a")) == NULL)
|
||||||
return ;
|
return;
|
||||||
buf = calloc(remaining, sizeof(char));
|
buf = calloc (remaining, sizeof (char));
|
||||||
fwrite(buf, 1, remaining, out);
|
fwrite (buf, 1, remaining, out);
|
||||||
fclose(out);
|
fclose (out);
|
||||||
free(buf);
|
free (buf);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -381,28 +411,31 @@ void qfits_zeropad(char * filename)
|
||||||
0 else. If the file does not exist, returns -1.
|
0 else. If the file does not exist, returns -1.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int is_fits_file(char *filename)
|
int
|
||||||
|
is_fits_file (char *filename)
|
||||||
{
|
{
|
||||||
FILE * fp ;
|
FILE *fp;
|
||||||
char * magic ;
|
char *magic;
|
||||||
int isfits ;
|
int isfits;
|
||||||
|
|
||||||
if (filename==NULL) return -1 ;
|
if (filename == NULL)
|
||||||
if ((fp = fopen(filename, "r"))==NULL) {
|
return -1;
|
||||||
qfits_error("cannot open file [%s]", filename) ;
|
if ((fp = fopen (filename, "r")) == NULL)
|
||||||
return -1 ;
|
{
|
||||||
|
qfits_error ("cannot open file [%s]", filename);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
magic = calloc(FITS_MAGIC_SZ+1, sizeof(char)) ;
|
magic = calloc (FITS_MAGIC_SZ + 1, sizeof (char));
|
||||||
fread(magic, 1, FITS_MAGIC_SZ, fp) ;
|
fread (magic, 1, FITS_MAGIC_SZ, fp);
|
||||||
fclose(fp) ;
|
fclose (fp);
|
||||||
magic[FITS_MAGIC_SZ] = (char)0 ;
|
magic[FITS_MAGIC_SZ] = (char) 0;
|
||||||
if (strstr(magic, FITS_MAGIC)!=NULL)
|
if (strstr (magic, FITS_MAGIC) != NULL)
|
||||||
isfits = 1 ;
|
isfits = 1;
|
||||||
else
|
else
|
||||||
isfits = 0 ;
|
isfits = 0;
|
||||||
free(magic) ;
|
free (magic);
|
||||||
return isfits ;
|
return isfits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
#define FITS_RW_H
|
#define FITS_RW_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -55,7 +56,7 @@ extern "C" {
|
||||||
Value, comment, and original line might be NULL pointers.
|
Value, comment, and original line might be NULL pointers.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_read(char * filename) ;
|
qfits_header *qfits_header_read (char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +70,7 @@ qfits_header * qfits_header_read(char * filename) ;
|
||||||
a hdr file.
|
a hdr file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_read_hdr(char * filename) ;
|
qfits_header *qfits_header_read_hdr (char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -82,9 +83,8 @@ qfits_header * qfits_header_read_hdr(char * filename) ;
|
||||||
object.
|
object.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_read_hdr_string(
|
qfits_header *qfits_header_read_hdr_string (unsigned char *hdr_str,
|
||||||
unsigned char * hdr_str,
|
int nb_char);
|
||||||
int nb_char) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -100,7 +100,7 @@ qfits_header * qfits_header_read_hdr_string(
|
||||||
Returns NULL in case of error.
|
Returns NULL in case of error.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_header_readext(char * filename, int xtnum) ;
|
qfits_header *qfits_header_readext (char *filename, int xtnum);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +112,7 @@ qfits_header * qfits_header_readext(char * filename, int xtnum) ;
|
||||||
for the file size to reach a multiple of 2880, as required by FITS.
|
for the file size to reach a multiple of 2880, as required by FITS.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_zeropad(char * filename) ;
|
void qfits_zeropad (char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -124,7 +124,7 @@ void qfits_zeropad(char * filename) ;
|
||||||
0 else. If the file does not exist, returns -1.
|
0 else. If the file does not exist, returns -1.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int is_fits_file(char *filename) ;
|
int is_fits_file (char *filename);
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
((x) == BPP_16_SIGNED) ? 2 : \
|
((x) == BPP_16_SIGNED) ? 2 : \
|
||||||
((x) == BPP_32_SIGNED) ? 4 : \
|
((x) == BPP_32_SIGNED) ? 4 : \
|
||||||
((x) == BPP_IEEE_FLOAT) ? 4 : \
|
((x) == BPP_IEEE_FLOAT) ? 4 : \
|
||||||
((x) == BPP_IEEE_DOUBLE) ? 8 : 0 )
|
((x) == BPP_IEEE_DOUBLE) ? 8 : 0 )
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#endif
|
#endif
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -89,33 +89,35 @@
|
||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_dir_name(char * filename)
|
char *
|
||||||
|
qfits_get_dir_name (char *filename)
|
||||||
{
|
{
|
||||||
static char path[MAXNAMESZ];
|
static char path[MAXNAMESZ];
|
||||||
char *last_slash;
|
char *last_slash;
|
||||||
|
|
||||||
if (strlen(filename)>MAXNAMESZ) return NULL ;
|
if (strlen (filename) > MAXNAMESZ)
|
||||||
strcpy(path, filename);
|
return NULL;
|
||||||
/* Find last '/'. */
|
strcpy (path, filename);
|
||||||
last_slash = path != NULL ? strrchr (path, '/') : NULL;
|
/* Find last '/'. */
|
||||||
|
last_slash = path != NULL ? strrchr (path, '/') : NULL;
|
||||||
|
|
||||||
if (last_slash == path)
|
if (last_slash == path)
|
||||||
/* The last slash is the first character in the string. We have to
|
/* The last slash is the first character in the string. We have to
|
||||||
return "/". */
|
return "/". */
|
||||||
++last_slash;
|
++last_slash;
|
||||||
else if (last_slash != NULL && last_slash[1] == '\0')
|
else if (last_slash != NULL && last_slash[1] == '\0')
|
||||||
/* The '/' is the last character, we have to look further. */
|
/* The '/' is the last character, we have to look further. */
|
||||||
last_slash = memchr (path, last_slash - path, '/');
|
last_slash = memchr (path, last_slash - path, '/');
|
||||||
|
|
||||||
if (last_slash != NULL)
|
if (last_slash != NULL)
|
||||||
/* Terminate the path. */
|
/* Terminate the path. */
|
||||||
last_slash[0] = '\0';
|
last_slash[0] = '\0';
|
||||||
else
|
else
|
||||||
/* This assignment is ill-designed but the XPG specs require to
|
/* This assignment is ill-designed but the XPG specs require to
|
||||||
return a string containing "." in any case no directory part is
|
return a string containing "." in any case no directory part is
|
||||||
found and so a static and constant string is required. */
|
found and so a static and constant string is required. */
|
||||||
strcpy(path, ".");
|
strcpy (path, ".");
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -138,11 +140,12 @@ char * qfits_get_dir_name(char * filename)
|
||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_base_name(const char *filename)
|
char *
|
||||||
|
qfits_get_base_name (const char *filename)
|
||||||
{
|
{
|
||||||
char *p ;
|
char *p;
|
||||||
p = strrchr (filename, '/');
|
p = strrchr (filename, '/');
|
||||||
return p ? p + 1 : (char *) filename;
|
return p ? p + 1 : (char *) filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -176,26 +179,29 @@ char * qfits_get_base_name(const char *filename)
|
||||||
to free it or modify its contents.
|
to free it or modify its contents.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_root_name(char * filename)
|
char *
|
||||||
|
qfits_get_root_name (char *filename)
|
||||||
{
|
{
|
||||||
static char path[MAXNAMESZ+1];
|
static char path[MAXNAMESZ + 1];
|
||||||
char * lastdot ;
|
char *lastdot;
|
||||||
|
|
||||||
if (strlen(filename)>MAXNAMESZ) return NULL ;
|
if (strlen (filename) > MAXNAMESZ)
|
||||||
memset(path, MAXNAMESZ, 0);
|
return NULL;
|
||||||
strcpy(path, filename);
|
memset (path, MAXNAMESZ, 0);
|
||||||
lastdot = strrchr(path, '.');
|
strcpy (path, filename);
|
||||||
if (lastdot == NULL) return path ;
|
lastdot = strrchr (path, '.');
|
||||||
if ((!strcmp(lastdot, ".fits")) || (!strcmp(lastdot, ".FITS")) ||
|
if (lastdot == NULL)
|
||||||
(!strcmp(lastdot, ".paf")) || (!strcmp(lastdot, ".PAF")) ||
|
return path;
|
||||||
(!strcmp(lastdot, ".dat")) || (!strcmp(lastdot, ".DAT")) ||
|
if ((!strcmp (lastdot, ".fits")) || (!strcmp (lastdot, ".FITS")) ||
|
||||||
(!strcmp(lastdot, ".txt")) || (!strcmp(lastdot, ".TXT")) ||
|
(!strcmp (lastdot, ".paf")) || (!strcmp (lastdot, ".PAF")) ||
|
||||||
(!strcmp(lastdot, ".tfits")) || (!strcmp(lastdot, ".TFITS")) ||
|
(!strcmp (lastdot, ".dat")) || (!strcmp (lastdot, ".DAT")) ||
|
||||||
(!strcmp(lastdot, ".ascii")) || (!strcmp(lastdot, ".ASCII")))
|
(!strcmp (lastdot, ".txt")) || (!strcmp (lastdot, ".TXT")) ||
|
||||||
|
(!strcmp (lastdot, ".tfits")) || (!strcmp (lastdot, ".TFITS")) ||
|
||||||
|
(!strcmp (lastdot, ".ascii")) || (!strcmp (lastdot, ".ASCII")))
|
||||||
{
|
{
|
||||||
lastdot[0] = (char)0;
|
lastdot[0] = (char) 0;
|
||||||
}
|
}
|
||||||
return path ;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -219,11 +225,12 @@ char * qfits_get_root_name(char * filename)
|
||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_ext_name(char * filename)
|
char *
|
||||||
|
qfits_get_ext_name (char *filename)
|
||||||
{
|
{
|
||||||
char * p;
|
char *p;
|
||||||
p = strrchr(filename, '.');
|
p = strrchr (filename, '.');
|
||||||
return p ? p+1 : NULL ;
|
return p ? p + 1 : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -240,17 +247,20 @@ char * qfits_get_ext_name(char * filename)
|
||||||
string which first character is a null character.
|
string which first character is a null character.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_login_name(void)
|
char *
|
||||||
|
qfits_get_login_name (void)
|
||||||
{
|
{
|
||||||
struct passwd * pw ;
|
struct passwd *pw;
|
||||||
static char name[32];
|
static char name[32];
|
||||||
|
|
||||||
pw = getpwuid(getuid());
|
pw = getpwuid (getuid ());
|
||||||
if (pw!=NULL) {
|
if (pw != NULL)
|
||||||
strcpy(name, pw->pw_name);
|
{
|
||||||
} else {
|
strcpy (name, pw->pw_name);
|
||||||
name[0]=0 ;
|
|
||||||
}
|
}
|
||||||
return name ;
|
else
|
||||||
|
{
|
||||||
|
name[0] = 0;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
#define GET_NAME_H
|
#define GET_NAME_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ extern "C" {
|
||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_dir_name(char * filename) ;
|
char *qfits_get_dir_name (char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +74,7 @@ char * qfits_get_dir_name(char * filename) ;
|
||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_base_name(const char *filename) ;
|
char *qfits_get_base_name (const char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -105,7 +106,7 @@ char * qfits_get_base_name(const char *filename) ;
|
||||||
to free it or modify its contents.
|
to free it or modify its contents.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_root_name(char * filename) ;
|
char *qfits_get_root_name (char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -128,7 +129,7 @@ char * qfits_get_root_name(char * filename) ;
|
||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_ext_name(char * filename) ;
|
char *qfits_get_ext_name (char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -144,7 +145,7 @@ char * qfits_get_ext_name(char * filename) ;
|
||||||
point to a string which first character is a null character.
|
point to a string which first character is a null character.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_login_name(void) ;
|
char *qfits_get_login_name (void);
|
||||||
|
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -38,85 +38,94 @@
|
||||||
|
|
||||||
#ifndef WORDS_BIGENDIAN
|
#ifndef WORDS_BIGENDIAN
|
||||||
/* Little endian ordering */
|
/* Little endian ordering */
|
||||||
typedef union _ieee_double_pattern_ {
|
typedef union _ieee_double_pattern_
|
||||||
double d ;
|
{
|
||||||
struct {
|
double d;
|
||||||
unsigned int lsw ;
|
struct
|
||||||
unsigned int msw ;
|
{
|
||||||
} p ;
|
unsigned int lsw;
|
||||||
} ieee_double_pattern ;
|
unsigned int msw;
|
||||||
|
} p;
|
||||||
|
} ieee_double_pattern;
|
||||||
#else
|
#else
|
||||||
/* Big endian ordering */
|
/* Big endian ordering */
|
||||||
typedef union _ieee_double_pattern_ {
|
typedef union _ieee_double_pattern_
|
||||||
double d ;
|
{
|
||||||
struct {
|
double d;
|
||||||
unsigned int msw ;
|
struct
|
||||||
unsigned int lsw ;
|
{
|
||||||
} p ;
|
unsigned int msw;
|
||||||
} ieee_double_pattern ;
|
unsigned int lsw;
|
||||||
|
} p;
|
||||||
|
} ieee_double_pattern;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef union _ieee_float_pattern_ {
|
typedef union _ieee_float_pattern_
|
||||||
float f ;
|
{
|
||||||
int i ;
|
float f;
|
||||||
} ieee_float_pattern ;
|
int i;
|
||||||
|
} ieee_float_pattern;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function codes
|
Function codes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
int _qfits_isnanf(float f)
|
int
|
||||||
|
_qfits_isnanf (float f)
|
||||||
{
|
{
|
||||||
ieee_float_pattern ip ;
|
ieee_float_pattern ip;
|
||||||
int ix ;
|
int ix;
|
||||||
|
|
||||||
ip.f = f ;
|
ip.f = f;
|
||||||
ix = ip.i ;
|
ix = ip.i;
|
||||||
ix &= 0x7fffffff ;
|
ix &= 0x7fffffff;
|
||||||
ix = 0x7f800000 - ix ;
|
ix = 0x7f800000 - ix;
|
||||||
return (int)(((unsigned int)(ix))>>31);
|
return (int) (((unsigned int) (ix)) >> 31);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _qfits_isinff(float f)
|
int
|
||||||
|
_qfits_isinff (float f)
|
||||||
{
|
{
|
||||||
ieee_float_pattern ip ;
|
ieee_float_pattern ip;
|
||||||
int ix, t ;
|
int ix, t;
|
||||||
|
|
||||||
ip.f = f ;
|
ip.f = f;
|
||||||
ix = ip.i ;
|
ix = ip.i;
|
||||||
t = ix & 0x7fffffff;
|
t = ix & 0x7fffffff;
|
||||||
t ^= 0x7f800000;
|
t ^= 0x7f800000;
|
||||||
t |= -t;
|
t |= -t;
|
||||||
return ~(t >> 31) & (ix >> 30);
|
return ~(t >> 31) & (ix >> 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _qfits_isnand(double d)
|
int
|
||||||
|
_qfits_isnand (double d)
|
||||||
{
|
{
|
||||||
ieee_double_pattern id ;
|
ieee_double_pattern id;
|
||||||
int hx, lx ;
|
int hx, lx;
|
||||||
|
|
||||||
id.d = d ;
|
id.d = d;
|
||||||
lx = id.p.lsw ;
|
lx = id.p.lsw;
|
||||||
hx = id.p.msw ;
|
hx = id.p.msw;
|
||||||
|
|
||||||
hx &= 0x7fffffff;
|
hx &= 0x7fffffff;
|
||||||
hx |= (unsigned int)(lx|(-lx))>>31;
|
hx |= (unsigned int) (lx | (-lx)) >> 31;
|
||||||
hx = 0x7ff00000 - hx;
|
hx = 0x7ff00000 - hx;
|
||||||
return (int)(((unsigned int)hx)>>31);
|
return (int) (((unsigned int) hx) >> 31);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _qfits_isinfd(double d)
|
int
|
||||||
|
_qfits_isinfd (double d)
|
||||||
{
|
{
|
||||||
ieee_double_pattern id ;
|
ieee_double_pattern id;
|
||||||
int hx, lx ;
|
int hx, lx;
|
||||||
|
|
||||||
id.d = d ;
|
id.d = d;
|
||||||
lx = id.p.lsw ;
|
lx = id.p.lsw;
|
||||||
hx = id.p.msw ;
|
hx = id.p.msw;
|
||||||
|
|
||||||
lx |= (hx & 0x7fffffff) ^ 0x7ff00000;
|
lx |= (hx & 0x7fffffff) ^ 0x7ff00000;
|
||||||
lx |= -lx;
|
lx |= -lx;
|
||||||
return ~(lx >> 31) & (hx >> 30);
|
return ~(lx >> 31) & (hx >> 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,88 +142,99 @@ int _qfits_isinfd(double d)
|
||||||
|
|
||||||
#ifndef WORDS_BIGENDIAN
|
#ifndef WORDS_BIGENDIAN
|
||||||
/* Little endian patterns */
|
/* Little endian patterns */
|
||||||
static unsigned char fnan_pat[] = {0, 0, 0xc0, 0x7f};
|
static unsigned char fnan_pat[] = { 0, 0, 0xc0, 0x7f };
|
||||||
static unsigned char dnan_pat[] = {0, 0, 0, 0, 0, 0, 0xf8, 0x7f};
|
static unsigned char dnan_pat[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
|
||||||
static unsigned char finf_pat[] = {0, 0, 0x80, 0x7f};
|
static unsigned char finf_pat[] = { 0, 0, 0x80, 0x7f };
|
||||||
static unsigned char dinf_pat[] = {0, 0, 0, 0, 0, 0, 0xf0, 0x7f};
|
static unsigned char dinf_pat[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
|
||||||
static unsigned char fminf_pat[] = {0, 0, 0x80, 0xff};
|
static unsigned char fminf_pat[] = { 0, 0, 0x80, 0xff };
|
||||||
|
|
||||||
/* static unsigned char dminf_pat[] = {0, 0, 0, 0, 0, 0, 0xf0, 0xff}; */
|
/* static unsigned char dminf_pat[] = {0, 0, 0, 0, 0, 0, 0xf0, 0xff}; */
|
||||||
static unsigned char dminf_pat[] = {0, 0, 0, 0, 0, 0, 0xf0, 0x7f};
|
static unsigned char dminf_pat[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
|
||||||
#else
|
#else
|
||||||
/* Big endian patterns */
|
/* Big endian patterns */
|
||||||
static unsigned char fnan_pat[] = {0x7f, 0xc0, 0, 0};
|
static unsigned char fnan_pat[] = { 0x7f, 0xc0, 0, 0 };
|
||||||
static unsigned char dnan_pat[] = {0x7f, 0xf8, 0, 0, 0, 0, 0, 0};
|
static unsigned char dnan_pat[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
|
||||||
static unsigned char finf_pat[] = {0x7f, 0x80, 0, 0};
|
static unsigned char finf_pat[] = { 0x7f, 0x80, 0, 0 };
|
||||||
static unsigned char dinf_pat[] = {0x7f, 0xf0, 0, 0, 0, 0, 0, 0};
|
static unsigned char dinf_pat[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
|
||||||
static unsigned char fminf_pat[] = {0xff, 0x80, 0, 0};
|
static unsigned char fminf_pat[] = { 0xff, 0x80, 0, 0 };
|
||||||
static unsigned char dminf_pat[] = {0xff, 0xf0, 0, 0, 0, 0, 0, 0};
|
static unsigned char dminf_pat[] = { 0xff, 0xf0, 0, 0, 0, 0, 0, 0 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void hexdump(void * p, int s)
|
static void
|
||||||
|
hexdump (void *p, int s)
|
||||||
{
|
{
|
||||||
unsigned char * c ;
|
unsigned char *c;
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
c=(unsigned char*)p ;
|
c = (unsigned char *) p;
|
||||||
#ifndef WORDS_BIGENDIAN
|
#ifndef WORDS_BIGENDIAN
|
||||||
for (i=s-1 ; i>=0 ; i--) {
|
for (i = s - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
#else
|
#else
|
||||||
for (i=0 ; i<s ; i++) {
|
for (i = 0; i < s; i++)
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
printf("%02x", c[i]);
|
printf ("%02x", c[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int
|
||||||
|
main (void)
|
||||||
{
|
{
|
||||||
float f ;
|
float f;
|
||||||
double d ;
|
double d;
|
||||||
|
|
||||||
printf("Testing Nan...\n");
|
printf ("Testing Nan...\n");
|
||||||
memcpy(&f, fnan_pat, 4);
|
memcpy (&f, fnan_pat, 4);
|
||||||
memcpy(&d, dnan_pat, 8);
|
memcpy (&d, dnan_pat, 8);
|
||||||
printf("f=%g d=%g\n", f, d);
|
printf ("f=%g d=%g\n", f, d);
|
||||||
hexdump(&f, sizeof(float));
|
hexdump (&f, sizeof (float));
|
||||||
hexdump(&d, sizeof(double));
|
hexdump (&d, sizeof (double));
|
||||||
|
|
||||||
if (qfits_isnan(f)) {
|
if (qfits_isnan (f))
|
||||||
printf("f is NaN\n");
|
{
|
||||||
|
printf ("f is NaN\n");
|
||||||
}
|
}
|
||||||
if (qfits_isnan(d)) {
|
if (qfits_isnan (d))
|
||||||
printf("d is NaN\n");
|
{
|
||||||
|
printf ("d is NaN\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Testing +Inf...\n");
|
printf ("Testing +Inf...\n");
|
||||||
memcpy(&f, finf_pat, 4);
|
memcpy (&f, finf_pat, 4);
|
||||||
memcpy(&d, dinf_pat, 8);
|
memcpy (&d, dinf_pat, 8);
|
||||||
printf("f=%g d=%g\n", f, d);
|
printf ("f=%g d=%g\n", f, d);
|
||||||
hexdump(&f, sizeof(float));
|
hexdump (&f, sizeof (float));
|
||||||
hexdump(&d, sizeof(double));
|
hexdump (&d, sizeof (double));
|
||||||
|
|
||||||
if (qfits_isinf(f)) {
|
if (qfits_isinf (f))
|
||||||
printf("f is Inf\n");
|
{
|
||||||
|
printf ("f is Inf\n");
|
||||||
}
|
}
|
||||||
if (qfits_isinf(d)) {
|
if (qfits_isinf (d))
|
||||||
printf("d is Inf\n");
|
{
|
||||||
|
printf ("d is Inf\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Testing -Inf...\n");
|
printf ("Testing -Inf...\n");
|
||||||
memcpy(&f, fminf_pat, 4);
|
memcpy (&f, fminf_pat, 4);
|
||||||
memcpy(&d, dminf_pat, 8);
|
memcpy (&d, dminf_pat, 8);
|
||||||
printf("f=%g d=%g\n", f, d);
|
printf ("f=%g d=%g\n", f, d);
|
||||||
hexdump(&f, sizeof(float));
|
hexdump (&f, sizeof (float));
|
||||||
hexdump(&d, sizeof(double));
|
hexdump (&d, sizeof (double));
|
||||||
|
|
||||||
if (qfits_isinf(f)) {
|
if (qfits_isinf (f))
|
||||||
printf("f is (-)Inf\n");
|
{
|
||||||
|
printf ("f is (-)Inf\n");
|
||||||
}
|
}
|
||||||
if (qfits_isinf(d)) {
|
if (qfits_isinf (d))
|
||||||
printf("d is (-)Inf\n");
|
{
|
||||||
|
printf ("d is (-)Inf\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0 ;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -82,22 +82,22 @@
|
||||||
* Test a float variable for NaN value.
|
* Test a float variable for NaN value.
|
||||||
* Do not call directly, call qfits_isnan().
|
* Do not call directly, call qfits_isnan().
|
||||||
*/
|
*/
|
||||||
int _qfits_isnanf(float f);
|
int _qfits_isnanf (float f);
|
||||||
/**
|
/**
|
||||||
* Test a float variable for Inf value.
|
* Test a float variable for Inf value.
|
||||||
* Do not call directly, call qfits_isinf().
|
* Do not call directly, call qfits_isinf().
|
||||||
*/
|
*/
|
||||||
int _qfits_isinff(float f);
|
int _qfits_isinff (float f);
|
||||||
/**
|
/**
|
||||||
* Test a double variable for NaN value.
|
* Test a double variable for NaN value.
|
||||||
* Do not call directly, call qfits_isnan().
|
* Do not call directly, call qfits_isnan().
|
||||||
*/
|
*/
|
||||||
int _qfits_isnand(double d);
|
int _qfits_isnand (double d);
|
||||||
/**
|
/**
|
||||||
* Test a double variable for Inf value.
|
* Test a double variable for Inf value.
|
||||||
* Do not call directly, call qfits_isinf().
|
* Do not call directly, call qfits_isinf().
|
||||||
*/
|
*/
|
||||||
int _qfits_isinfd(double d);
|
int _qfits_isinfd (double d);
|
||||||
|
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#endif
|
#endif
|
||||||
|
|
314
qfits/src/md5.c
314
qfits/src/md5.c
|
@ -31,13 +31,13 @@
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void byteReverse(unsigned char *buf, unsigned longs) ;
|
static void byteReverse (unsigned char *buf, unsigned longs);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function codes
|
Function codes
|
||||||
|
@ -46,123 +46,135 @@ static void byteReverse(unsigned char *buf, unsigned longs) ;
|
||||||
/*
|
/*
|
||||||
* Note: this code is harmless on little-endian machines.
|
* Note: this code is harmless on little-endian machines.
|
||||||
*/
|
*/
|
||||||
static void byteReverse(unsigned char *buf, unsigned longs)
|
static void
|
||||||
|
byteReverse (unsigned char *buf, unsigned longs)
|
||||||
{
|
{
|
||||||
word32 t;
|
word32 t;
|
||||||
do {
|
do
|
||||||
t = (word32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
|
{
|
||||||
((unsigned) buf[1] << 8 | buf[0]);
|
t = (word32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
|
||||||
*(word32 *) buf = t;
|
((unsigned) buf[1] << 8 | buf[0]);
|
||||||
buf += 4;
|
*(word32 *) buf = t;
|
||||||
} while (--longs);
|
buf += 4;
|
||||||
|
}
|
||||||
|
while (--longs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
||||||
* initialization constants.
|
* initialization constants.
|
||||||
*/
|
*/
|
||||||
void MD5Init(struct MD5Context *ctx)
|
void
|
||||||
|
MD5Init (struct MD5Context *ctx)
|
||||||
{
|
{
|
||||||
ctx->buf[0] = 0x67452301;
|
ctx->buf[0] = 0x67452301;
|
||||||
ctx->buf[1] = 0xefcdab89;
|
ctx->buf[1] = 0xefcdab89;
|
||||||
ctx->buf[2] = 0x98badcfe;
|
ctx->buf[2] = 0x98badcfe;
|
||||||
ctx->buf[3] = 0x10325476;
|
ctx->buf[3] = 0x10325476;
|
||||||
|
|
||||||
ctx->bits[0] = 0;
|
ctx->bits[0] = 0;
|
||||||
ctx->bits[1] = 0;
|
ctx->bits[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update context to reflect the concatenation of another buffer full
|
* Update context to reflect the concatenation of another buffer full
|
||||||
* of bytes.
|
* of bytes.
|
||||||
*/
|
*/
|
||||||
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
|
void
|
||||||
|
MD5Update (struct MD5Context *ctx, unsigned char const *buf, unsigned len)
|
||||||
{
|
{
|
||||||
register word32 t;
|
register word32 t;
|
||||||
|
|
||||||
/* Update bitcount */
|
/* Update bitcount */
|
||||||
|
|
||||||
t = ctx->bits[0];
|
t = ctx->bits[0];
|
||||||
if ((ctx->bits[0] = t + ((word32) len << 3)) < t)
|
if ((ctx->bits[0] = t + ((word32) len << 3)) < t)
|
||||||
ctx->bits[1]++; /* Carry from low to high */
|
ctx->bits[1]++; /* Carry from low to high */
|
||||||
ctx->bits[1] += len >> 29;
|
ctx->bits[1] += len >> 29;
|
||||||
|
|
||||||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||||
|
|
||||||
/* Handle any leading odd-sized chunks */
|
/* Handle any leading odd-sized chunks */
|
||||||
|
|
||||||
if (t) {
|
if (t)
|
||||||
unsigned char *p = (unsigned char *) ctx->in + t;
|
{
|
||||||
|
unsigned char *p = (unsigned char *) ctx->in + t;
|
||||||
|
|
||||||
t = 64 - t;
|
t = 64 - t;
|
||||||
if (len < t) {
|
if (len < t)
|
||||||
memmove(p, buf, len);
|
{
|
||||||
return;
|
memmove (p, buf, len);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
memmove(p, buf, t);
|
memmove (p, buf, t);
|
||||||
byteReverse(ctx->in, 16);
|
byteReverse (ctx->in, 16);
|
||||||
MD5Transform(ctx->buf, (word32 *) ctx->in);
|
MD5Transform (ctx->buf, (word32 *) ctx->in);
|
||||||
buf += t;
|
buf += t;
|
||||||
len -= t;
|
len -= t;
|
||||||
}
|
}
|
||||||
/* Process data in 64-byte chunks */
|
/* Process data in 64-byte chunks */
|
||||||
|
|
||||||
while (len >= 64) {
|
while (len >= 64)
|
||||||
memmove(ctx->in, buf, 64);
|
{
|
||||||
byteReverse(ctx->in, 16);
|
memmove (ctx->in, buf, 64);
|
||||||
MD5Transform(ctx->buf, (word32 *) ctx->in);
|
byteReverse (ctx->in, 16);
|
||||||
buf += 64;
|
MD5Transform (ctx->buf, (word32 *) ctx->in);
|
||||||
len -= 64;
|
buf += 64;
|
||||||
|
len -= 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle any remaining bytes of data. */
|
/* Handle any remaining bytes of data. */
|
||||||
|
|
||||||
memmove(ctx->in, buf, len);
|
memmove (ctx->in, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||||
* 1 0* (64-bit count of bits processed, MSB-first)
|
* 1 0* (64-bit count of bits processed, MSB-first)
|
||||||
*/
|
*/
|
||||||
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
void
|
||||||
|
MD5Final (unsigned char digest[16], struct MD5Context *ctx)
|
||||||
{
|
{
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
|
|
||||||
/* Compute number of bytes mod 64 */
|
/* Compute number of bytes mod 64 */
|
||||||
count = (ctx->bits[0] >> 3) & 0x3F;
|
count = (ctx->bits[0] >> 3) & 0x3F;
|
||||||
|
|
||||||
/* Set the first char of padding to 0x80. This is safe since there is
|
/* Set the first char of padding to 0x80. This is safe since there is
|
||||||
always at least one byte free */
|
always at least one byte free */
|
||||||
p = ctx->in + count;
|
p = ctx->in + count;
|
||||||
*p++ = 0x80;
|
*p++ = 0x80;
|
||||||
|
|
||||||
/* Bytes of padding needed to make 64 bytes */
|
/* Bytes of padding needed to make 64 bytes */
|
||||||
count = 64 - 1 - count;
|
count = 64 - 1 - count;
|
||||||
|
|
||||||
/* Pad out to 56 mod 64 */
|
/* Pad out to 56 mod 64 */
|
||||||
if (count < 8) {
|
if (count < 8)
|
||||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
{
|
||||||
memset(p, 0, count);
|
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||||
byteReverse(ctx->in, 16);
|
memset (p, 0, count);
|
||||||
MD5Transform(ctx->buf, (word32 *) ctx->in);
|
byteReverse (ctx->in, 16);
|
||||||
|
MD5Transform (ctx->buf, (word32 *) ctx->in);
|
||||||
|
|
||||||
/* Now fill the next block with 56 bytes */
|
/* Now fill the next block with 56 bytes */
|
||||||
memset(ctx->in, 0, 56);
|
memset (ctx->in, 0, 56);
|
||||||
} else {
|
|
||||||
/* Pad block to 56 bytes */
|
|
||||||
memset(p, 0, count - 8);
|
|
||||||
}
|
}
|
||||||
byteReverse(ctx->in, 14);
|
else
|
||||||
|
{
|
||||||
|
/* Pad block to 56 bytes */
|
||||||
|
memset (p, 0, count - 8);
|
||||||
|
}
|
||||||
|
byteReverse (ctx->in, 14);
|
||||||
|
|
||||||
/* Append length in bits and transform */
|
/* Append length in bits and transform */
|
||||||
((word32 *) ctx->in)[14] = ctx->bits[0];
|
((word32 *) ctx->in)[14] = ctx->bits[0];
|
||||||
((word32 *) ctx->in)[15] = ctx->bits[1];
|
((word32 *) ctx->in)[15] = ctx->bits[1];
|
||||||
|
|
||||||
MD5Transform(ctx->buf, (word32 *) ctx->in);
|
MD5Transform (ctx->buf, (word32 *) ctx->in);
|
||||||
byteReverse((unsigned char *) ctx->buf, 4);
|
byteReverse ((unsigned char *) ctx->buf, 4);
|
||||||
memmove(digest, ctx->buf, 16);
|
memmove (digest, ctx->buf, 16);
|
||||||
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
|
memset (ctx, 0, sizeof (ctx)); /* In case it's sensitive */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The four core functions - F1 is optimized somewhat */
|
/* The four core functions - F1 is optimized somewhat */
|
||||||
|
@ -182,86 +194,88 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
||||||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||||
* the data and converts bytes into longwords for this routine.
|
* the data and converts bytes into longwords for this routine.
|
||||||
*/
|
*/
|
||||||
void MD5Transform(word32 buf[4], word32 const in[16])
|
void
|
||||||
|
MD5Transform (word32 buf[4], word32 const in[16])
|
||||||
{
|
{
|
||||||
register word32 a, b, c, d;
|
register word32 a, b, c, d;
|
||||||
|
|
||||||
a = buf[0];
|
a = buf[0];
|
||||||
b = buf[1];
|
b = buf[1];
|
||||||
c = buf[2];
|
c = buf[2];
|
||||||
d = buf[3];
|
d = buf[3];
|
||||||
|
|
||||||
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
MD5STEP (F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
||||||
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
MD5STEP (F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
||||||
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
|
MD5STEP (F1, c, d, a, b, in[2] + 0x242070db, 17);
|
||||||
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
MD5STEP (F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
||||||
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
MD5STEP (F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
||||||
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
MD5STEP (F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
||||||
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
MD5STEP (F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
||||||
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
MD5STEP (F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
||||||
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
MD5STEP (F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
||||||
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
MD5STEP (F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
||||||
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
MD5STEP (F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
||||||
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
MD5STEP (F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
||||||
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
MD5STEP (F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
||||||
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
MD5STEP (F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
||||||
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
MD5STEP (F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
||||||
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
MD5STEP (F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
||||||
|
|
||||||
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
MD5STEP (F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
||||||
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
MD5STEP (F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
||||||
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
MD5STEP (F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
||||||
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
MD5STEP (F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
||||||
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
MD5STEP (F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
||||||
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
|
MD5STEP (F2, d, a, b, c, in[10] + 0x02441453, 9);
|
||||||
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
MD5STEP (F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
||||||
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
MD5STEP (F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
||||||
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
MD5STEP (F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
||||||
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
MD5STEP (F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
||||||
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
MD5STEP (F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
||||||
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
MD5STEP (F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
||||||
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
MD5STEP (F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
||||||
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
MD5STEP (F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
||||||
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
MD5STEP (F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
||||||
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
MD5STEP (F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
||||||
|
|
||||||
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
MD5STEP (F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
||||||
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
MD5STEP (F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
||||||
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
MD5STEP (F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
||||||
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
MD5STEP (F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
||||||
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
MD5STEP (F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
||||||
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
MD5STEP (F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
||||||
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
MD5STEP (F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
||||||
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
MD5STEP (F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
||||||
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
MD5STEP (F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
||||||
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
MD5STEP (F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
||||||
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
MD5STEP (F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
||||||
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
MD5STEP (F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
||||||
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
MD5STEP (F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
||||||
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
MD5STEP (F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
||||||
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
MD5STEP (F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
||||||
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
MD5STEP (F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
||||||
|
|
||||||
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
MD5STEP (F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
||||||
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
MD5STEP (F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
||||||
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
MD5STEP (F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
||||||
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
MD5STEP (F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
||||||
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
MD5STEP (F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
||||||
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
MD5STEP (F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
||||||
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
MD5STEP (F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
||||||
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
MD5STEP (F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
||||||
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
MD5STEP (F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
||||||
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
MD5STEP (F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
||||||
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
MD5STEP (F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
||||||
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
MD5STEP (F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
||||||
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
MD5STEP (F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
||||||
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
MD5STEP (F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
||||||
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
MD5STEP (F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
||||||
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
MD5STEP (F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
||||||
|
|
||||||
buf[0] += a;
|
buf[0] += a;
|
||||||
buf[1] += b;
|
buf[1] += b;
|
||||||
buf[2] += c;
|
buf[2] += c;
|
||||||
buf[3] += d;
|
buf[3] += d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
#ifndef MD5_H
|
#ifndef MD5_H
|
||||||
#define MD5_H
|
#define MD5_H
|
||||||
|
|
||||||
typedef unsigned int word32 ;
|
typedef unsigned int word32;
|
||||||
|
|
||||||
struct MD5Context {
|
struct MD5Context
|
||||||
word32 buf[4];
|
{
|
||||||
word32 bits[2];
|
word32 buf[4];
|
||||||
unsigned char in[64];
|
word32 bits[2];
|
||||||
|
unsigned char in[64];
|
||||||
};
|
};
|
||||||
|
|
||||||
void MD5Init(struct MD5Context *context);
|
void MD5Init (struct MD5Context *context);
|
||||||
void MD5Update(struct MD5Context *context, unsigned char const *buf,
|
void MD5Update (struct MD5Context *context, unsigned char const *buf,
|
||||||
unsigned len);
|
unsigned len);
|
||||||
void MD5Final(unsigned char digest[16], struct MD5Context *context);
|
void MD5Final (unsigned char digest[16], struct MD5Context *context);
|
||||||
void MD5Transform(word32 buf[4], word32 const in[16]);
|
void MD5Transform (word32 buf[4], word32 const in[16]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is needed to make RSAREF happy on some MS-DOS compilers.
|
* This is needed to make RSAREF happy on some MS-DOS compilers.
|
||||||
|
|
232
qfits/src/pafs.c
232
qfits/src/pafs.c
|
@ -33,7 +33,7 @@
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
static char * qfits_strcrop(char * s) ;
|
static char *qfits_strcrop (char *s);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function codes
|
Function codes
|
||||||
|
@ -65,32 +65,31 @@ static char * qfits_strcrop(char * s) ;
|
||||||
the file.
|
the file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
FILE * qfits_paf_print_header(
|
FILE *
|
||||||
char * filename,
|
qfits_paf_print_header (char *filename,
|
||||||
char * paf_id,
|
char *paf_id,
|
||||||
char * paf_desc,
|
char *paf_desc, char *login_name, char *datetime)
|
||||||
char * login_name,
|
|
||||||
char * datetime)
|
|
||||||
{
|
{
|
||||||
FILE * paf ;
|
FILE *paf;
|
||||||
|
|
||||||
if ((paf=fopen(filename, "w"))==NULL) {
|
if ((paf = fopen (filename, "w")) == NULL)
|
||||||
qfits_error("cannot create PAF file [%s]", filename);
|
{
|
||||||
return NULL ;
|
qfits_error ("cannot create PAF file [%s]", filename);
|
||||||
}
|
return NULL;
|
||||||
fprintf(paf, "PAF.HDR.START ;# start of header\n");
|
}
|
||||||
fprintf(paf, "PAF.TYPE \"pipeline product\" ;\n");
|
fprintf (paf, "PAF.HDR.START ;# start of header\n");
|
||||||
fprintf(paf, "PAF.ID \"%s\"\n", paf_id);
|
fprintf (paf, "PAF.TYPE \"pipeline product\" ;\n");
|
||||||
fprintf(paf, "PAF.NAME \"%s\"\n", filename);
|
fprintf (paf, "PAF.ID \"%s\"\n", paf_id);
|
||||||
fprintf(paf, "PAF.DESC \"%s\"\n", paf_desc);
|
fprintf (paf, "PAF.NAME \"%s\"\n", filename);
|
||||||
fprintf(paf, "PAF.CRTE.NAME \"%s\"\n", login_name) ;
|
fprintf (paf, "PAF.DESC \"%s\"\n", paf_desc);
|
||||||
fprintf(paf, "PAF.CRTE.DAYTIM \"%s\"\n", datetime) ;
|
fprintf (paf, "PAF.CRTE.NAME \"%s\"\n", login_name);
|
||||||
fprintf(paf, "PAF.LCHG.NAME \"%s\"\n", login_name) ;
|
fprintf (paf, "PAF.CRTE.DAYTIM \"%s\"\n", datetime);
|
||||||
fprintf(paf, "PAF.LCHG.DAYTIM \"%s\"\n", datetime) ;
|
fprintf (paf, "PAF.LCHG.NAME \"%s\"\n", login_name);
|
||||||
fprintf(paf, "PAF.CHCK.CHECKSUM \"\"\n");
|
fprintf (paf, "PAF.LCHG.DAYTIM \"%s\"\n", datetime);
|
||||||
fprintf(paf, "PAF.HDR.END ;# end of header\n");
|
fprintf (paf, "PAF.CHCK.CHECKSUM \"\"\n");
|
||||||
fprintf(paf, "\n");
|
fprintf (paf, "PAF.HDR.END ;# end of header\n");
|
||||||
return paf ;
|
fprintf (paf, "\n");
|
||||||
|
return paf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -107,57 +106,65 @@ FILE * qfits_paf_print_header(
|
||||||
If the key is not found, this function returns NULL.
|
If the key is not found, this function returns NULL.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_paf_query(
|
char *
|
||||||
char * filename,
|
qfits_paf_query (char *filename, char *key)
|
||||||
char * key)
|
|
||||||
{
|
{
|
||||||
static char value[ASCIILINESZ];
|
static char value[ASCIILINESZ];
|
||||||
FILE * paf ;
|
FILE *paf;
|
||||||
char line[ASCIILINESZ+1];
|
char line[ASCIILINESZ + 1];
|
||||||
char val[ASCIILINESZ+1];
|
char val[ASCIILINESZ + 1];
|
||||||
char head[ASCIILINESZ+1];
|
char head[ASCIILINESZ + 1];
|
||||||
int found ;
|
int found;
|
||||||
int len ;
|
int len;
|
||||||
|
|
||||||
/* Check inputs */
|
/* Check inputs */
|
||||||
if (filename==NULL || key==NULL) return NULL ;
|
if (filename == NULL || key == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Check PAF validity */
|
/* Check PAF validity */
|
||||||
if (qfits_is_paf_file(filename)!=1) {
|
if (qfits_is_paf_file (filename) != 1)
|
||||||
qfits_error("not a PAF file: [%s]", filename);
|
{
|
||||||
return NULL ;
|
qfits_error ("not a PAF file: [%s]", filename);
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Open file and read it */
|
/* Open file and read it */
|
||||||
paf = fopen(filename, "r");
|
paf = fopen (filename, "r");
|
||||||
if (paf==NULL) {
|
if (paf == NULL)
|
||||||
qfits_error("opening [%s]", filename);
|
{
|
||||||
return NULL ;
|
qfits_error ("opening [%s]", filename);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
found = 0;
|
||||||
|
while (fgets (line, ASCIILINESZ, paf) != NULL)
|
||||||
|
{
|
||||||
|
sscanf (line, "%[^ ]", head);
|
||||||
|
if (!strcmp (head, key))
|
||||||
|
{
|
||||||
|
/* Get value */
|
||||||
|
sscanf (line, "%*[^ ] %[^;]", value);
|
||||||
|
found++;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
found = 0 ;
|
if (!found)
|
||||||
while (fgets(line, ASCIILINESZ, paf)!=NULL) {
|
return NULL;
|
||||||
sscanf(line, "%[^ ]", head);
|
|
||||||
if (!strcmp(head, key)) {
|
/* Remove trailing blanks */
|
||||||
/* Get value */
|
strcpy (val, qfits_strcrop (value));
|
||||||
sscanf(line, "%*[^ ] %[^;]", value);
|
/* Get rid of possible quotes */
|
||||||
found ++ ;
|
len = strlen (val);
|
||||||
break ;
|
if (val[0] == '\"' && val[len - 1] == '\"')
|
||||||
}
|
{
|
||||||
}
|
strncpy (value, val + 1, len - 2);
|
||||||
if (!found) return NULL ;
|
value[len - 2] = (char) 0;
|
||||||
|
}
|
||||||
/* Remove trailing blanks */
|
else
|
||||||
strcpy(val, qfits_strcrop(value));
|
{
|
||||||
/* Get rid of possible quotes */
|
strcpy (value, val);
|
||||||
len = strlen(val);
|
}
|
||||||
if (val[0]=='\"' && val[len-1]=='\"') {
|
return value;
|
||||||
strncpy(value, val+1, len-2);
|
|
||||||
value[len-2]=(char)0;
|
|
||||||
} else {
|
|
||||||
strcpy(value, val);
|
|
||||||
}
|
|
||||||
return value ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -170,34 +177,40 @@ char * qfits_paf_query(
|
||||||
is checked with the presence of PAF.HDR.START at the beginning
|
is checked with the presence of PAF.HDR.START at the beginning
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_paf_file(char * filename)
|
int
|
||||||
|
qfits_is_paf_file (char *filename)
|
||||||
{
|
{
|
||||||
FILE * fp ;
|
FILE *fp;
|
||||||
int is_paf ;
|
int is_paf;
|
||||||
char line[ASCIILINESZ] ;
|
char line[ASCIILINESZ];
|
||||||
|
|
||||||
if (filename==NULL) return -1 ;
|
|
||||||
|
|
||||||
/* Initialize is_paf */
|
if (filename == NULL)
|
||||||
is_paf = 0 ;
|
return -1;
|
||||||
|
|
||||||
/* Open file */
|
/* Initialize is_paf */
|
||||||
if ((fp = fopen(filename, "r"))==NULL) {
|
is_paf = 0;
|
||||||
qfits_error("cannot open file [%s]", filename) ;
|
|
||||||
return -1 ;
|
/* Open file */
|
||||||
|
if ((fp = fopen (filename, "r")) == NULL)
|
||||||
|
{
|
||||||
|
qfits_error ("cannot open file [%s]", filename);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse file */
|
||||||
|
while (fgets (line, ASCIILINESZ, fp) != NULL)
|
||||||
|
{
|
||||||
|
if (line[0] != '#')
|
||||||
|
{
|
||||||
|
if (!strncmp (line, PAF_MAGIC, PAF_MAGIC_SZ))
|
||||||
|
is_paf = 1;
|
||||||
|
(void) fclose (fp);
|
||||||
|
return is_paf;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse file */
|
(void) fclose (fp);
|
||||||
while (fgets(line, ASCIILINESZ, fp) != NULL) {
|
return is_paf;
|
||||||
if (line[0] != '#') {
|
|
||||||
if (!strncmp(line, PAF_MAGIC, PAF_MAGIC_SZ)) is_paf = 1 ;
|
|
||||||
(void)fclose(fp) ;
|
|
||||||
return is_paf ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)fclose(fp) ;
|
|
||||||
return is_paf ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -214,22 +227,25 @@ int qfits_is_paf_file(char * filename)
|
||||||
(not re-entrant).
|
(not re-entrant).
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static char * qfits_strcrop(char * s)
|
static char *
|
||||||
|
qfits_strcrop (char *s)
|
||||||
{
|
{
|
||||||
static char l[ASCIILINESZ+1];
|
static char l[ASCIILINESZ + 1];
|
||||||
char * last ;
|
char *last;
|
||||||
|
|
||||||
if (s==NULL) return NULL ;
|
if (s == NULL)
|
||||||
memset(l, 0, ASCIILINESZ+1);
|
return NULL;
|
||||||
strcpy(l, s);
|
memset (l, 0, ASCIILINESZ + 1);
|
||||||
last = l + strlen(l);
|
strcpy (l, s);
|
||||||
while (last > l) {
|
last = l + strlen (l);
|
||||||
if (!isspace((int)*(last-1)))
|
while (last > l)
|
||||||
break ;
|
{
|
||||||
last -- ;
|
if (!isspace ((int) *(last - 1)))
|
||||||
|
break;
|
||||||
|
last--;
|
||||||
}
|
}
|
||||||
*last = (char)0;
|
*last = (char) 0;
|
||||||
return l ;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
#define PAFS_H
|
#define PAFS_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -65,12 +66,10 @@ extern "C" {
|
||||||
the file.
|
the file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
FILE * qfits_paf_print_header(
|
FILE *qfits_paf_print_header (char *filename,
|
||||||
char * filename,
|
char *paf_id,
|
||||||
char * paf_id,
|
char *paf_desc,
|
||||||
char * paf_desc,
|
char *login_name, char *datetime);
|
||||||
char * login_name,
|
|
||||||
char * datetime) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -86,9 +85,7 @@ FILE * qfits_paf_print_header(
|
||||||
If the key is not found, this function returns NULL.
|
If the key is not found, this function returns NULL.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_paf_query(
|
char *qfits_paf_query (char *filename, char *key);
|
||||||
char * filename,
|
|
||||||
char * key) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -100,7 +97,7 @@ char * qfits_paf_query(
|
||||||
is checked with the presence of PAF.HDR.START at the beginning
|
is checked with the presence of PAF.HDR.START at the beginning
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_paf_file(char * filename) ;
|
int qfits_is_paf_file (char *filename);
|
||||||
|
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
1819
qfits/src/pixio.c
1819
qfits/src/pixio.c
File diff suppressed because it is too large
Load Diff
|
@ -53,7 +53,7 @@
|
||||||
for readability.
|
for readability.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
typedef unsigned char byte ;
|
typedef unsigned char byte;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -126,49 +126,50 @@ int main(int argc, char * argv[])
|
||||||
@endcode
|
@endcode
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
typedef struct qfitsloader {
|
typedef struct qfitsloader
|
||||||
|
{
|
||||||
|
|
||||||
/** Private field to see if structure has been initialized */
|
/** Private field to see if structure has been initialized */
|
||||||
int _init ;
|
int _init;
|
||||||
|
|
||||||
/** input: Name of the file you want to read pixels from */
|
/** input: Name of the file you want to read pixels from */
|
||||||
char * filename ;
|
char *filename;
|
||||||
/** input: xtension number you want to read */
|
/** input: xtension number you want to read */
|
||||||
int xtnum ;
|
int xtnum;
|
||||||
/** input: Index of the plane you want, from 0 to np-1 */
|
/** input: Index of the plane you want, from 0 to np-1 */
|
||||||
int pnum ;
|
int pnum;
|
||||||
/** input: Pixel type you want (PTYPE_FLOAT, PTYPE_INT or PTYPE_DOUBLE) */
|
/** input: Pixel type you want (PTYPE_FLOAT, PTYPE_INT or PTYPE_DOUBLE) */
|
||||||
int ptype ;
|
int ptype;
|
||||||
/** input: Guarantee file copy or allow file mapping */
|
/** input: Guarantee file copy or allow file mapping */
|
||||||
int map ;
|
int map;
|
||||||
|
|
||||||
/** output: Total number of extensions found in file */
|
/** output: Total number of extensions found in file */
|
||||||
int exts ;
|
int exts;
|
||||||
/** output: Size in X of the requested plane */
|
/** output: Size in X of the requested plane */
|
||||||
int lx ;
|
int lx;
|
||||||
/** output: Size in Y of the requested plane */
|
/** output: Size in Y of the requested plane */
|
||||||
int ly ;
|
int ly;
|
||||||
/** output: Number of planes present in this extension */
|
/** output: Number of planes present in this extension */
|
||||||
int np ;
|
int np;
|
||||||
/** output: BITPIX for this extension */
|
/** output: BITPIX for this extension */
|
||||||
int bitpix ;
|
int bitpix;
|
||||||
/** output: Start of the data segment (in bytes) for your request */
|
/** output: Start of the data segment (in bytes) for your request */
|
||||||
int seg_start ;
|
int seg_start;
|
||||||
/** output: Size of the data segment (in bytes) for your request */
|
/** output: Size of the data segment (in bytes) for your request */
|
||||||
int seg_size ;
|
int seg_size;
|
||||||
/** output: BSCALE found for this extension */
|
/** output: BSCALE found for this extension */
|
||||||
double bscale ;
|
double bscale;
|
||||||
/** output: BZERO found for this extension */
|
/** output: BZERO found for this extension */
|
||||||
double bzero ;
|
double bzero;
|
||||||
|
|
||||||
/** output: Pointer to pixel buffer loaded as integer values */
|
/** output: Pointer to pixel buffer loaded as integer values */
|
||||||
int * ibuf ;
|
int *ibuf;
|
||||||
/** output: Pointer to pixel buffer loaded as float values */
|
/** output: Pointer to pixel buffer loaded as float values */
|
||||||
float * fbuf ;
|
float *fbuf;
|
||||||
/** output: Pointer to pixel buffer loaded as double values */
|
/** output: Pointer to pixel buffer loaded as double values */
|
||||||
double * dbuf ;
|
double *dbuf;
|
||||||
|
|
||||||
} qfitsloader ;
|
} qfitsloader;
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -215,25 +216,26 @@ typedef struct qfitsloader {
|
||||||
could have been re-directed).
|
could have been re-directed).
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
typedef struct qfitsdumper {
|
typedef struct qfitsdumper
|
||||||
|
{
|
||||||
|
|
||||||
/** Name of the file to dump to, "STDOUT" to dump to stdout */
|
/** Name of the file to dump to, "STDOUT" to dump to stdout */
|
||||||
char * filename ;
|
char *filename;
|
||||||
/** Number of pixels in the buffer to dump */
|
/** Number of pixels in the buffer to dump */
|
||||||
int npix ;
|
int npix;
|
||||||
/** Buffer type: PTYPE_FLOAT, PTYPE_INT or PTYPE_DOUBLE */
|
/** Buffer type: PTYPE_FLOAT, PTYPE_INT or PTYPE_DOUBLE */
|
||||||
int ptype ;
|
int ptype;
|
||||||
|
|
||||||
/** Pointer to input integer pixel buffer */
|
/** Pointer to input integer pixel buffer */
|
||||||
int * ibuf ;
|
int *ibuf;
|
||||||
/** Pointer to input float pixel buffer */
|
/** Pointer to input float pixel buffer */
|
||||||
float * fbuf ;
|
float *fbuf;
|
||||||
/** Pointer to input double pixel buffer */
|
/** Pointer to input double pixel buffer */
|
||||||
double * dbuf ;
|
double *dbuf;
|
||||||
|
|
||||||
/** Requested BITPIX in output FITS file */
|
/** Requested BITPIX in output FITS file */
|
||||||
int out_ptype ;
|
int out_ptype;
|
||||||
} qfitsdumper ;
|
} qfitsdumper;
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -265,7 +267,7 @@ typedef struct qfitsdumper {
|
||||||
is performed by qfits_loadpix() afterwards.
|
is performed by qfits_loadpix() afterwards.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfitsloader_init(qfitsloader * ql);
|
int qfitsloader_init (qfitsloader * ql);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -287,7 +289,7 @@ int qfitsloader_init(qfitsloader * ql);
|
||||||
code before you make calls to the pixel loader here.
|
code before you make calls to the pixel loader here.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_loadpix(qfitsloader * ql);
|
int qfits_loadpix (qfitsloader * ql);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -310,7 +312,7 @@ int qfits_loadpix(qfitsloader * ql);
|
||||||
free on the returned pointer.
|
free on the returned pointer.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
float * qfits_pixin_float (byte *, int, int, double, double);
|
float *qfits_pixin_float (byte *, int, int, double, double);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -333,7 +335,7 @@ float * qfits_pixin_float (byte *, int, int, double, double);
|
||||||
free on the returned pointer.
|
free on the returned pointer.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int * qfits_pixin_int (byte *, int, int, double, double);
|
int *qfits_pixin_int (byte *, int, int, double, double);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -354,9 +356,9 @@ int * qfits_pixin_int (byte *, int, int, double, double);
|
||||||
The returned buffer must be deallocated using the free() offered
|
The returned buffer must be deallocated using the free() offered
|
||||||
by xmemory. It is enough to #include "xmemory.h" before calling
|
by xmemory. It is enough to #include "xmemory.h" before calling
|
||||||
free on the returned pointer.
|
free on the returned pointer.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
double * qfits_pixin_double(byte *, int, int, double, double);
|
double *qfits_pixin_double (byte *, int, int, double, double);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -393,7 +395,7 @@ double * qfits_pixin_double(byte *, int, int, double, double);
|
||||||
will be performed to stdout.
|
will be performed to stdout.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_pixdump(qfitsdumper * qd) ;
|
int qfits_pixdump (qfitsdumper * qd);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -407,9 +409,9 @@ int qfits_pixdump(qfitsdumper * qd) ;
|
||||||
suitable for dumping to a FITS file (i.e. big-endian, in the
|
suitable for dumping to a FITS file (i.e. big-endian, in the
|
||||||
requested pixel type). The returned pointer must be deallocated
|
requested pixel type). The returned pointer must be deallocated
|
||||||
using the free() function offered by xmemory.
|
using the free() function offered by xmemory.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
byte * qfits_pixdump_float(float * buf, int npix, int ptype);
|
byte *qfits_pixdump_float (float *buf, int npix, int ptype);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -425,7 +427,7 @@ byte * qfits_pixdump_float(float * buf, int npix, int ptype);
|
||||||
using the free() function offered by xmemory.
|
using the free() function offered by xmemory.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
byte * qfits_pixdump_int(int * buf, int npix, int ptype);
|
byte *qfits_pixdump_int (int *buf, int npix, int ptype);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -441,7 +443,7 @@ byte * qfits_pixdump_int(int * buf, int npix, int ptype);
|
||||||
using the free() function offered by xmemory.
|
using the free() function offered by xmemory.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
byte * qfits_pixdump_double(double * buf, int npix, int ptype);
|
byte *qfits_pixdump_double (double *buf, int npix, int ptype);
|
||||||
|
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,16 +41,21 @@
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* Type of a display function only defined for legibility here */
|
/* Type of a display function only defined for legibility here */
|
||||||
typedef void (*qfits_err_dispfunc)(char *) ;
|
typedef void (*qfits_err_dispfunc) (char *);
|
||||||
/* Default display function prints out msg to stderr */
|
/* Default display function prints out msg to stderr */
|
||||||
static void qfits_err_display_stderr(char * s)
|
static void
|
||||||
{ fprintf(stderr, "qfits: %s\n", s); }
|
qfits_err_display_stderr (char *s)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "qfits: %s\n", s);
|
||||||
|
}
|
||||||
|
|
||||||
/* Static control structure, completely private */
|
/* Static control structure, completely private */
|
||||||
static struct {
|
static struct
|
||||||
qfits_err_dispfunc disp[QFITS_ERR_MAXERRDISP] ;
|
{
|
||||||
int n ;
|
qfits_err_dispfunc disp[QFITS_ERR_MAXERRDISP];
|
||||||
int active ;
|
int n;
|
||||||
} qfits_err_control = {{qfits_err_display_stderr}, 1, 0} ;
|
int active;
|
||||||
|
} qfits_err_control = { {qfits_err_display_stderr}, 1, 0 };
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function codes
|
Function codes
|
||||||
|
@ -64,21 +69,24 @@ static struct {
|
||||||
It calls registered display functions one after another.
|
It calls registered display functions one after another.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void qfits_err_main_display(char * msg)
|
static void
|
||||||
|
qfits_err_main_display (char *msg)
|
||||||
{
|
{
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
/* Check if there is a message in input */
|
/* Check if there is a message in input */
|
||||||
if (msg==NULL)
|
if (msg == NULL)
|
||||||
return ;
|
return;
|
||||||
|
|
||||||
/* Loop on all registered functions and call them */
|
/* Loop on all registered functions and call them */
|
||||||
for (i=0 ; i<qfits_err_control.n ; i++) {
|
for (i = 0; i < qfits_err_control.n; i++)
|
||||||
if (qfits_err_control.disp[i]) {
|
{
|
||||||
qfits_err_control.disp[i](msg);
|
if (qfits_err_control.disp[i])
|
||||||
}
|
{
|
||||||
|
qfits_err_control.disp[i] (msg);
|
||||||
}
|
}
|
||||||
return ;
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -91,9 +99,10 @@ static void qfits_err_main_display(char * msg)
|
||||||
messages using the registered functions, otherwise they do nothing.
|
messages using the registered functions, otherwise they do nothing.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_err_statget(void)
|
int
|
||||||
|
qfits_err_statget (void)
|
||||||
{
|
{
|
||||||
return qfits_err_control.active ;
|
return qfits_err_control.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -114,12 +123,13 @@ int qfits_err_statget(void)
|
||||||
@endcode
|
@endcode
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_err_statset(int sta)
|
int
|
||||||
|
qfits_err_statset (int sta)
|
||||||
{
|
{
|
||||||
int prev ;
|
int prev;
|
||||||
prev = qfits_err_control.active ;
|
prev = qfits_err_control.active;
|
||||||
qfits_err_control.active=sta ;
|
qfits_err_control.active = sta;
|
||||||
return prev ;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -146,53 +156,60 @@ int qfits_err_statset(int sta)
|
||||||
returning -1.
|
returning -1.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_err_register(qfits_err_dispfunc dispfn)
|
int
|
||||||
|
qfits_err_register (qfits_err_dispfunc dispfn)
|
||||||
{
|
{
|
||||||
if (qfits_err_control.n==QFITS_ERR_MAXERRDISP) {
|
if (qfits_err_control.n == QFITS_ERR_MAXERRDISP)
|
||||||
/* Cannot register any more function */
|
{
|
||||||
return -1 ;
|
/* Cannot register any more function */
|
||||||
}
|
return -1;
|
||||||
qfits_err_control.disp[qfits_err_control.n] = dispfn ;
|
}
|
||||||
qfits_err_control.n ++ ;
|
qfits_err_control.disp[qfits_err_control.n] = dispfn;
|
||||||
return 0 ;
|
qfits_err_control.n++;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Public warning/error functions */
|
/* Public warning/error functions */
|
||||||
void qfits_warning(const char *fmt, ...)
|
void
|
||||||
|
qfits_warning (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char msg[QFITS_ERR_MSGSIZE] ;
|
char msg[QFITS_ERR_MSGSIZE];
|
||||||
char all[QFITS_ERR_MSGSIZE] ;
|
char all[QFITS_ERR_MSGSIZE];
|
||||||
va_list ap ;
|
va_list ap;
|
||||||
|
|
||||||
/* Check if display is activated */
|
/* Check if display is activated */
|
||||||
if (qfits_err_control.active==0) {
|
if (qfits_err_control.active == 0)
|
||||||
return ;
|
{
|
||||||
}
|
return;
|
||||||
va_start(ap, fmt) ;
|
}
|
||||||
vsprintf(msg, fmt, ap) ;
|
va_start (ap, fmt);
|
||||||
va_end(ap);
|
vsprintf (msg, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
sprintf(all, "*** %s", msg);
|
sprintf (all, "*** %s", msg);
|
||||||
qfits_err_main_display(all);
|
qfits_err_main_display (all);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
void qfits_error(const char *fmt, ...)
|
|
||||||
|
void
|
||||||
|
qfits_error (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char msg[QFITS_ERR_MSGSIZE] ;
|
char msg[QFITS_ERR_MSGSIZE];
|
||||||
char all[QFITS_ERR_MSGSIZE] ;
|
char all[QFITS_ERR_MSGSIZE];
|
||||||
va_list ap ;
|
va_list ap;
|
||||||
|
|
||||||
/* Check if display is activated */
|
/* Check if display is activated */
|
||||||
if (qfits_err_control.active==0) {
|
if (qfits_err_control.active == 0)
|
||||||
return ;
|
{
|
||||||
}
|
return;
|
||||||
va_start(ap, fmt) ;
|
}
|
||||||
vsprintf(msg, fmt, ap) ;
|
va_start (ap, fmt);
|
||||||
va_end(ap);
|
vsprintf (msg, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
sprintf(all, "error: %s", msg);
|
sprintf (all, "error: %s", msg);
|
||||||
qfits_err_main_display(all);
|
qfits_err_main_display (all);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
messages using the registered functions, otherwise they do nothing.
|
messages using the registered functions, otherwise they do nothing.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_err_statget(void);
|
int qfits_err_statget (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +60,7 @@ int qfits_err_statget(void);
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_err_statset(int sta);
|
int qfits_err_statset (int sta);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -86,12 +86,12 @@ int qfits_err_statset(int sta);
|
||||||
returning -1.
|
returning -1.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_err_register( void (*dispfn)(char*) ) ;
|
int qfits_err_register (void (*dispfn) (char *));
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
|
|
||||||
/* Public warning/error functions */
|
/* Public warning/error functions */
|
||||||
void qfits_warning(const char *fmt, ...);
|
void qfits_warning (const char *fmt, ...);
|
||||||
void qfits_error(const char *fmt, ...);
|
void qfits_error (const char *fmt, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -50,14 +50,14 @@
|
||||||
*/
|
*/
|
||||||
/** A regular expression matching a floating-point number */
|
/** A regular expression matching a floating-point number */
|
||||||
static char regex_float[] =
|
static char regex_float[] =
|
||||||
"^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eEdD][+-]?[0-9]+)?$";
|
"^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eEdD][+-]?[0-9]+)?$";
|
||||||
|
|
||||||
/** A regular expression matching an integer */
|
/** A regular expression matching an integer */
|
||||||
static char regex_int[] = "^[+-]?[0-9]+$";
|
static char regex_int[] = "^[+-]?[0-9]+$";
|
||||||
|
|
||||||
/** A regular expression matching a complex number (int or float) */
|
/** A regular expression matching a complex number (int or float) */
|
||||||
static char regex_cmp[] =
|
static char regex_cmp[] =
|
||||||
"^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eEdD][+-]?[0-9]+)?[ ]+[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eEdD][+-]?[0-9]+)?$";
|
"^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eEdD][+-]?[0-9]+)?[ ]+[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eEdD][+-]?[0-9]+)?$";
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function codes
|
Function codes
|
||||||
|
@ -90,9 +90,10 @@ static char regex_cmp[] =
|
||||||
Returns NULL in case the requested keyword cannot be found.
|
Returns NULL in case the requested keyword cannot be found.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_query_hdr(char * filename, const char * keyword)
|
char *
|
||||||
|
qfits_query_hdr (char *filename, const char *keyword)
|
||||||
{
|
{
|
||||||
return qfits_query_ext(filename, keyword, 0);
|
return qfits_query_ext (filename, keyword, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -108,90 +109,99 @@ char * qfits_query_hdr(char * filename, const char * keyword)
|
||||||
strictly identical to qfits_query_hdr().
|
strictly identical to qfits_query_hdr().
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
char *
|
||||||
|
qfits_query_ext (char *filename, const char *keyword, int xtnum)
|
||||||
{
|
{
|
||||||
char * exp_key ;
|
char *exp_key;
|
||||||
char * where ;
|
char *where;
|
||||||
char * start ;
|
char *start;
|
||||||
char * value ;
|
char *value;
|
||||||
char test1, test2 ;
|
char test1, test2;
|
||||||
int i ;
|
int i;
|
||||||
int len ;
|
int len;
|
||||||
int different ;
|
int different;
|
||||||
int seg_start ;
|
int seg_start;
|
||||||
int seg_size ;
|
int seg_size;
|
||||||
long bufcount ;
|
long bufcount;
|
||||||
size_t size ;
|
size_t size;
|
||||||
|
|
||||||
/* Bulletproof entries */
|
/* Bulletproof entries */
|
||||||
if (filename==NULL || keyword==NULL || xtnum<0) return NULL ;
|
if (filename == NULL || keyword == NULL || xtnum < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Expand keyword */
|
/* Expand keyword */
|
||||||
exp_key = qfits_expand_keyword(keyword);
|
exp_key = qfits_expand_keyword (keyword);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find out offsets to the required extension
|
* Find out offsets to the required extension
|
||||||
* Record the xtension start and stop offsets
|
* Record the xtension start and stop offsets
|
||||||
*/
|
*/
|
||||||
if (qfits_get_hdrinfo(filename, xtnum, &seg_start, &seg_size)==-1) {
|
if (qfits_get_hdrinfo (filename, xtnum, &seg_start, &seg_size) == -1)
|
||||||
return NULL ;
|
{
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a hand on requested buffer
|
* Get a hand on requested buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
start = falloc(filename, seg_start, &size);
|
start = falloc (filename, seg_start, &size);
|
||||||
if (start==NULL) return NULL ;
|
if (start == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for keyword in header
|
* Look for keyword in header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bufcount=0 ;
|
bufcount = 0;
|
||||||
where = start ;
|
where = start;
|
||||||
len = (int)strlen(exp_key);
|
len = (int) strlen (exp_key);
|
||||||
while (1) {
|
while (1)
|
||||||
different=0 ;
|
{
|
||||||
for (i=0 ; i<len ; i++) {
|
different = 0;
|
||||||
if (where[i]!=exp_key[i]) {
|
for (i = 0; i < len; i++)
|
||||||
different++ ;
|
{
|
||||||
break ;
|
if (where[i] != exp_key[i])
|
||||||
}
|
{
|
||||||
}
|
different++;
|
||||||
if (!different) {
|
break;
|
||||||
/* Get 2 chars after keyword */
|
}
|
||||||
test1=where[len];
|
}
|
||||||
test2=where[len+1];
|
if (!different)
|
||||||
/* If first subsequent character is the equal sign, bingo. */
|
{
|
||||||
if (test1=='=') break ;
|
/* Get 2 chars after keyword */
|
||||||
/* If subsequent char is equal sign, bingo */
|
test1 = where[len];
|
||||||
if (test1==' ' && (test2=='=' || test2==' '))
|
test2 = where[len + 1];
|
||||||
break ;
|
/* If first subsequent character is the equal sign, bingo. */
|
||||||
}
|
if (test1 == '=')
|
||||||
/* Watch out for header end */
|
break;
|
||||||
if ((where[0]=='E') &&
|
/* If subsequent char is equal sign, bingo */
|
||||||
(where[1]=='N') &&
|
if (test1 == ' ' && (test2 == '=' || test2 == ' '))
|
||||||
(where[2]=='D') &&
|
break;
|
||||||
(where[3]==' ')) {
|
}
|
||||||
/* Detected header end */
|
/* Watch out for header end */
|
||||||
fdealloc(start, seg_start, size) ;
|
if ((where[0] == 'E') &&
|
||||||
return NULL ;
|
(where[1] == 'N') && (where[2] == 'D') && (where[3] == ' '))
|
||||||
}
|
{
|
||||||
/* Forward one line */
|
/* Detected header end */
|
||||||
where += 80 ;
|
fdealloc (start, seg_start, size);
|
||||||
bufcount += 80 ;
|
return NULL;
|
||||||
if (bufcount>seg_size) {
|
}
|
||||||
/* File is damaged or not FITS: bailout */
|
/* Forward one line */
|
||||||
fdealloc(start, seg_start, size) ;
|
where += 80;
|
||||||
return NULL ;
|
bufcount += 80;
|
||||||
}
|
if (bufcount > seg_size)
|
||||||
|
{
|
||||||
|
/* File is damaged or not FITS: bailout */
|
||||||
|
fdealloc (start, seg_start, size);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Found the keyword, now get its value */
|
/* Found the keyword, now get its value */
|
||||||
value = qfits_getvalue(where);
|
value = qfits_getvalue (where);
|
||||||
fdealloc(start, seg_start, size) ;
|
fdealloc (start, seg_start, size);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -203,9 +213,10 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
||||||
extension is found, and -1 if an error occurred.
|
extension is found, and -1 if an error occurred.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_query_n_ext(char * filename)
|
int
|
||||||
|
qfits_query_n_ext (char *filename)
|
||||||
{
|
{
|
||||||
return qfits_query(filename, QFITS_QUERY_N_EXT);
|
return qfits_query (filename, QFITS_QUERY_N_EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -218,45 +229,54 @@ int qfits_query_n_ext(char * filename)
|
||||||
and -1 if an error occurred.
|
and -1 if an error occurred.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_query_nplanes(char * filename, int extnum)
|
int
|
||||||
|
qfits_query_nplanes (char *filename, int extnum)
|
||||||
{
|
{
|
||||||
char * sval ;
|
char *sval;
|
||||||
int next ;
|
int next;
|
||||||
int naxes ;
|
int naxes;
|
||||||
int nplanes ;
|
int nplanes;
|
||||||
|
|
||||||
/* Check file existence */
|
/* Check file existence */
|
||||||
if (filename == NULL) return -1 ;
|
if (filename == NULL)
|
||||||
/* Check validity of extnum */
|
return -1;
|
||||||
next = qfits_query_n_ext(filename) ;
|
/* Check validity of extnum */
|
||||||
if (extnum>next) {
|
next = qfits_query_n_ext (filename);
|
||||||
qfits_error("invalid extension specified") ;
|
if (extnum > next)
|
||||||
return -1 ;
|
{
|
||||||
|
qfits_error ("invalid extension specified");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find the number of axes */
|
||||||
|
naxes = 0;
|
||||||
|
if ((sval = qfits_query_ext (filename, "NAXIS", extnum)) == NULL)
|
||||||
|
{
|
||||||
|
qfits_error ("missing key in header: NAXIS");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
naxes = atoi (sval);
|
||||||
|
|
||||||
|
/* Check validity of naxes */
|
||||||
|
if ((naxes < 2) || (naxes > 3))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Two dimensions cube */
|
||||||
|
if (naxes == 2)
|
||||||
|
nplanes = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* For 3D cubes, get the third dimension size */
|
||||||
|
if ((sval = qfits_query_ext (filename, "NAXIS3", extnum)) == NULL)
|
||||||
|
{
|
||||||
|
qfits_error ("missing key in header: NAXIS3");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
nplanes = atoi (sval);
|
||||||
/* Find the number of axes */
|
if (nplanes < 1)
|
||||||
naxes = 0 ;
|
nplanes = 0;
|
||||||
if ((sval = qfits_query_ext(filename, "NAXIS", extnum)) == NULL) {
|
}
|
||||||
qfits_error("missing key in header: NAXIS");
|
return nplanes;
|
||||||
return -1 ;
|
|
||||||
}
|
|
||||||
naxes = atoi(sval) ;
|
|
||||||
|
|
||||||
/* Check validity of naxes */
|
|
||||||
if ((naxes < 2) || (naxes > 3)) return -1 ;
|
|
||||||
|
|
||||||
/* Two dimensions cube */
|
|
||||||
if (naxes == 2) nplanes = 1 ;
|
|
||||||
else {
|
|
||||||
/* For 3D cubes, get the third dimension size */
|
|
||||||
if ((sval = qfits_query_ext(filename, "NAXIS3", extnum))==NULL) {
|
|
||||||
qfits_error("missing key in header: NAXIS3");
|
|
||||||
return -1 ;
|
|
||||||
}
|
|
||||||
nplanes = atoi(sval);
|
|
||||||
if (nplanes < 1) nplanes = 0 ;
|
|
||||||
}
|
|
||||||
return nplanes ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -278,51 +298,61 @@ int qfits_query_nplanes(char * filename, int extnum)
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
#define PRETTY_STRING_STATICBUFS 8
|
#define PRETTY_STRING_STATICBUFS 8
|
||||||
char * qfits_pretty_string(char * s)
|
char *
|
||||||
|
qfits_pretty_string (char *s)
|
||||||
{
|
{
|
||||||
static char pretty_buf[PRETTY_STRING_STATICBUFS][81] ;
|
static char pretty_buf[PRETTY_STRING_STATICBUFS][81];
|
||||||
static int flip=0 ;
|
static int flip = 0;
|
||||||
char * pretty ;
|
char *pretty;
|
||||||
int i,j ;
|
int i, j;
|
||||||
|
|
||||||
/* bulletproof */
|
/* bulletproof */
|
||||||
if (s==NULL) return NULL ;
|
if (s == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Switch between static buffers */
|
/* Switch between static buffers */
|
||||||
pretty = pretty_buf[flip];
|
pretty = pretty_buf[flip];
|
||||||
flip++ ;
|
flip++;
|
||||||
if (flip==PRETTY_STRING_STATICBUFS)
|
if (flip == PRETTY_STRING_STATICBUFS)
|
||||||
flip=0 ;
|
flip = 0;
|
||||||
|
|
||||||
pretty[0] = (char)0 ;
|
|
||||||
if (s[0]!='\'') return s ;
|
|
||||||
|
|
||||||
/* skip first quote */
|
pretty[0] = (char) 0;
|
||||||
i=1 ;
|
if (s[0] != '\'')
|
||||||
j=0 ;
|
return s;
|
||||||
/* trim left-side blanks */
|
|
||||||
while (s[i]==' ') {
|
/* skip first quote */
|
||||||
if (i==(int)strlen(s)) break ;
|
i = 1;
|
||||||
i++ ;
|
j = 0;
|
||||||
|
/* trim left-side blanks */
|
||||||
|
while (s[i] == ' ')
|
||||||
|
{
|
||||||
|
if (i == (int) strlen (s))
|
||||||
|
break;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if (i>=(int)(strlen(s)-1)) return pretty ;
|
if (i >= (int) (strlen (s) - 1))
|
||||||
/* copy string, changing double quotes to single ones */
|
|
||||||
while (i<(int)strlen(s)) {
|
|
||||||
if (s[i]=='\'') {
|
|
||||||
i++ ;
|
|
||||||
}
|
|
||||||
pretty[j]=s[i];
|
|
||||||
i++ ;
|
|
||||||
j++ ;
|
|
||||||
}
|
|
||||||
/* NULL-terminate the pretty string */
|
|
||||||
pretty[j+1]=(char)0;
|
|
||||||
/* trim right-side blanks */
|
|
||||||
j = (int)strlen(pretty)-1;
|
|
||||||
while (pretty[j]==' ') j-- ;
|
|
||||||
pretty[j+1]=(char)0;
|
|
||||||
return pretty;
|
return pretty;
|
||||||
|
/* copy string, changing double quotes to single ones */
|
||||||
|
while (i < (int) strlen (s))
|
||||||
|
{
|
||||||
|
if (s[i] == '\'')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
pretty[j] = s[i];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
/* NULL-terminate the pretty string */
|
||||||
|
pretty[j + 1] = (char) 0;
|
||||||
|
/* trim right-side blanks */
|
||||||
|
j = (int) strlen (pretty) - 1;
|
||||||
|
while (pretty[j] == ' ')
|
||||||
|
j--;
|
||||||
|
pretty[j + 1] = (char) 0;
|
||||||
|
return pretty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef PRETTY_STRING_STATICBUFS
|
#undef PRETTY_STRING_STATICBUFS
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -334,13 +364,18 @@ char * qfits_pretty_string(char * s)
|
||||||
Identifies if a FITS value is boolean.
|
Identifies if a FITS value is boolean.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_boolean(char * s)
|
int
|
||||||
|
qfits_is_boolean (char *s)
|
||||||
{
|
{
|
||||||
if (s==NULL) return 0 ;
|
if (s == NULL)
|
||||||
if (s[0]==0) return 0 ;
|
return 0;
|
||||||
if ((int)strlen(s)>1) return 0 ;
|
if (s[0] == 0)
|
||||||
if (s[0]=='T' || s[0]=='F') return 1 ;
|
return 0;
|
||||||
return 0 ;
|
if ((int) strlen (s) > 1)
|
||||||
|
return 0;
|
||||||
|
if (s[0] == 'T' || s[0] == 'F')
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -352,20 +387,24 @@ int qfits_is_boolean(char * s)
|
||||||
Identifies if a FITS value is an integer.
|
Identifies if a FITS value is an integer.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_int(char * s)
|
int
|
||||||
|
qfits_is_int (char *s)
|
||||||
{
|
{
|
||||||
regex_t re_int ;
|
regex_t re_int;
|
||||||
int status ;
|
int status;
|
||||||
|
|
||||||
if (s==NULL) return 0 ;
|
if (s == NULL)
|
||||||
if (s[0]==0) return 0 ;
|
return 0;
|
||||||
if (regcomp(&re_int, ®ex_int[0], REG_EXTENDED|REG_NOSUB)!=0) {
|
if (s[0] == 0)
|
||||||
qfits_error("internal error: compiling int rule");
|
return 0;
|
||||||
exit(-1);
|
if (regcomp (&re_int, ®ex_int[0], REG_EXTENDED | REG_NOSUB) != 0)
|
||||||
|
{
|
||||||
|
qfits_error ("internal error: compiling int rule");
|
||||||
|
exit (-1);
|
||||||
}
|
}
|
||||||
status = regexec(&re_int, s, 0, NULL, 0) ;
|
status = regexec (&re_int, s, 0, NULL, 0);
|
||||||
regfree(&re_int) ;
|
regfree (&re_int);
|
||||||
return (status) ? 0 : 1 ;
|
return (status) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -377,20 +416,24 @@ int qfits_is_int(char * s)
|
||||||
Identifies if a FITS value is float.
|
Identifies if a FITS value is float.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_float(char * s)
|
int
|
||||||
|
qfits_is_float (char *s)
|
||||||
{
|
{
|
||||||
regex_t re_float;
|
regex_t re_float;
|
||||||
int status ;
|
int status;
|
||||||
|
|
||||||
if (s==NULL) return 0 ;
|
if (s == NULL)
|
||||||
if (s[0]==0) return 0 ;
|
return 0;
|
||||||
if (regcomp(&re_float, ®ex_float[0], REG_EXTENDED|REG_NOSUB)!=0) {
|
if (s[0] == 0)
|
||||||
qfits_error("internal error: compiling float rule");
|
return 0;
|
||||||
exit(-1);
|
if (regcomp (&re_float, ®ex_float[0], REG_EXTENDED | REG_NOSUB) != 0)
|
||||||
|
{
|
||||||
|
qfits_error ("internal error: compiling float rule");
|
||||||
|
exit (-1);
|
||||||
}
|
}
|
||||||
status = regexec(&re_float, s, 0, NULL, 0) ;
|
status = regexec (&re_float, s, 0, NULL, 0);
|
||||||
regfree(&re_float) ;
|
regfree (&re_float);
|
||||||
return (status) ? 0 : 1 ;
|
return (status) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -402,20 +445,24 @@ int qfits_is_float(char * s)
|
||||||
Identifies if a FITS value is complex.
|
Identifies if a FITS value is complex.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_complex(char * s)
|
int
|
||||||
|
qfits_is_complex (char *s)
|
||||||
{
|
{
|
||||||
regex_t re_cmp ;
|
regex_t re_cmp;
|
||||||
int status ;
|
int status;
|
||||||
|
|
||||||
if (s==NULL) return 0 ;
|
if (s == NULL)
|
||||||
if (s[0]==0) return 0 ;
|
return 0;
|
||||||
if (regcomp(&re_cmp, ®ex_cmp[0], REG_EXTENDED|REG_NOSUB)!=0) {
|
if (s[0] == 0)
|
||||||
qfits_error("internal error: compiling complex rule");
|
return 0;
|
||||||
exit(-1);
|
if (regcomp (&re_cmp, ®ex_cmp[0], REG_EXTENDED | REG_NOSUB) != 0)
|
||||||
|
{
|
||||||
|
qfits_error ("internal error: compiling complex rule");
|
||||||
|
exit (-1);
|
||||||
}
|
}
|
||||||
status = regexec(&re_cmp, s, 0, NULL, 0) ;
|
status = regexec (&re_cmp, s, 0, NULL, 0);
|
||||||
regfree(&re_cmp) ;
|
regfree (&re_cmp);
|
||||||
return (status) ? 0 : 1 ;
|
return (status) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -427,11 +474,14 @@ int qfits_is_complex(char * s)
|
||||||
Identifies if a FITS value is a string.
|
Identifies if a FITS value is a string.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_string(char * s)
|
int
|
||||||
|
qfits_is_string (char *s)
|
||||||
{
|
{
|
||||||
if (s==NULL) return 0 ;
|
if (s == NULL)
|
||||||
if (s[0]=='\'') return 1 ;
|
return 0;
|
||||||
return 0 ;
|
if (s[0] == '\'')
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -450,14 +500,20 @@ int qfits_is_string(char * s)
|
||||||
- QFITS_STRING (5) for a FITS string.
|
- QFITS_STRING (5) for a FITS string.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_get_type(char * s)
|
int
|
||||||
|
qfits_get_type (char *s)
|
||||||
{
|
{
|
||||||
if (s==NULL) return QFITS_UNKNOWN ;
|
if (s == NULL)
|
||||||
if (qfits_is_boolean(s)) return QFITS_BOOLEAN ;
|
return QFITS_UNKNOWN;
|
||||||
if (qfits_is_int(s)) return QFITS_INT ;
|
if (qfits_is_boolean (s))
|
||||||
if (qfits_is_float(s)) return QFITS_FLOAT ;
|
return QFITS_BOOLEAN;
|
||||||
if (qfits_is_complex(s)) return QFITS_COMPLEX ;
|
if (qfits_is_int (s))
|
||||||
return QFITS_STRING ;
|
return QFITS_INT;
|
||||||
|
if (qfits_is_float (s))
|
||||||
|
return QFITS_FLOAT;
|
||||||
|
if (qfits_is_complex (s))
|
||||||
|
return QFITS_COMPLEX;
|
||||||
|
return QFITS_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -479,26 +535,27 @@ int qfits_get_type(char * s)
|
||||||
main header in the file.
|
main header in the file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_get_hdrinfo(
|
int
|
||||||
char * filename,
|
qfits_get_hdrinfo (char *filename, int xtnum, int *seg_start, int *seg_size)
|
||||||
int xtnum,
|
|
||||||
int * seg_start,
|
|
||||||
int * seg_size)
|
|
||||||
{
|
{
|
||||||
if (filename==NULL || xtnum<0 || (seg_start==NULL && seg_size==NULL)) {
|
if (filename == NULL || xtnum < 0
|
||||||
return -1 ;
|
|| (seg_start == NULL && seg_size == NULL))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (seg_start!=NULL) {
|
if (seg_start != NULL)
|
||||||
*seg_start = qfits_query(filename, QFITS_QUERY_HDR_START | xtnum);
|
{
|
||||||
if (*seg_start<0)
|
*seg_start = qfits_query (filename, QFITS_QUERY_HDR_START | xtnum);
|
||||||
return -1 ;
|
if (*seg_start < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (seg_size!=NULL) {
|
if (seg_size != NULL)
|
||||||
*seg_size = qfits_query(filename, QFITS_QUERY_HDR_SIZE | xtnum);
|
{
|
||||||
if (*seg_size<0)
|
*seg_size = qfits_query (filename, QFITS_QUERY_HDR_SIZE | xtnum);
|
||||||
return -1 ;
|
if (*seg_size < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return 0 ;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -520,26 +577,27 @@ int qfits_get_hdrinfo(
|
||||||
main header in the file.
|
main header in the file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_get_datinfo(
|
int
|
||||||
char * filename,
|
qfits_get_datinfo (char *filename, int xtnum, int *seg_start, int *seg_size)
|
||||||
int xtnum,
|
|
||||||
int * seg_start,
|
|
||||||
int * seg_size)
|
|
||||||
{
|
{
|
||||||
if (filename==NULL || xtnum<0 || (seg_start==NULL && seg_size==NULL)) {
|
if (filename == NULL || xtnum < 0
|
||||||
return -1 ;
|
|| (seg_start == NULL && seg_size == NULL))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (seg_start!=NULL) {
|
if (seg_start != NULL)
|
||||||
*seg_start = qfits_query(filename, QFITS_QUERY_DAT_START | xtnum);
|
{
|
||||||
if (*seg_start<0)
|
*seg_start = qfits_query (filename, QFITS_QUERY_DAT_START | xtnum);
|
||||||
return -1 ;
|
if (*seg_start < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (seg_size!=NULL) {
|
if (seg_size != NULL)
|
||||||
*seg_size = qfits_query(filename, QFITS_QUERY_DAT_SIZE | xtnum);
|
{
|
||||||
if (*seg_size<0)
|
*seg_size = qfits_query (filename, QFITS_QUERY_DAT_SIZE | xtnum);
|
||||||
return -1 ;
|
if (*seg_size < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return 0 ;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -550,72 +608,74 @@ int qfits_get_datinfo(
|
||||||
@return Allocated string containing the card or NULL
|
@return Allocated string containing the card or NULL
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_query_card(
|
char *
|
||||||
char * filename,
|
qfits_query_card (char *filename, char *keyword)
|
||||||
char * keyword)
|
|
||||||
{
|
{
|
||||||
char * exp_key ;
|
char *exp_key;
|
||||||
int fd ;
|
int fd;
|
||||||
char * buf ;
|
char *buf;
|
||||||
char * buf2 ;
|
char *buf2;
|
||||||
char * where ;
|
char *where;
|
||||||
int hs ;
|
int hs;
|
||||||
char * card ;
|
char *card;
|
||||||
|
|
||||||
/* Bulletproof entries */
|
/* Bulletproof entries */
|
||||||
if (filename==NULL || keyword==NULL) return NULL ;
|
if (filename == NULL || keyword == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Expand keyword */
|
/* Expand keyword */
|
||||||
exp_key = qfits_expand_keyword(keyword) ;
|
exp_key = qfits_expand_keyword (keyword);
|
||||||
|
|
||||||
/* Memory-map the FITS header of the input file */
|
/* Memory-map the FITS header of the input file */
|
||||||
qfits_get_hdrinfo(filename, 0, NULL, &hs) ;
|
qfits_get_hdrinfo (filename, 0, NULL, &hs);
|
||||||
if (hs < 1) {
|
if (hs < 1)
|
||||||
qfits_error("error getting FITS header size for %s", filename);
|
{
|
||||||
return NULL ;
|
qfits_error ("error getting FITS header size for %s", filename);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
fd = open(filename, O_RDWR) ;
|
fd = open (filename, O_RDWR);
|
||||||
if (fd == -1) return NULL ;
|
if (fd == -1)
|
||||||
buf = (char*)mmap(0,
|
return NULL;
|
||||||
hs,
|
buf = (char *) mmap (0, hs, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
PROT_READ | PROT_WRITE,
|
if (buf == (char *) -1)
|
||||||
MAP_SHARED,
|
{
|
||||||
fd,
|
perror ("mmap");
|
||||||
0) ;
|
close (fd);
|
||||||
if (buf == (char*)-1) {
|
return NULL;
|
||||||
perror("mmap") ;
|
|
||||||
close(fd) ;
|
|
||||||
return NULL ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply search for the input keyword */
|
/* Apply search for the input keyword */
|
||||||
buf2 = malloc(hs+1) ;
|
buf2 = malloc (hs + 1);
|
||||||
memcpy(buf2, buf, hs) ;
|
memcpy (buf2, buf, hs);
|
||||||
buf2[hs] = (char)0 ;
|
buf2[hs] = (char) 0;
|
||||||
where = buf2 ;
|
where = buf2;
|
||||||
do {
|
do
|
||||||
where = strstr(where, exp_key);
|
{
|
||||||
if (where == NULL) {
|
where = strstr (where, exp_key);
|
||||||
close(fd);
|
if (where == NULL)
|
||||||
munmap(buf,hs);
|
{
|
||||||
free(buf2) ;
|
close (fd);
|
||||||
return NULL ;
|
munmap (buf, hs);
|
||||||
}
|
free (buf2);
|
||||||
if ((where-buf2)%80) where++ ;
|
return NULL;
|
||||||
} while ((where-buf2)%80) ;
|
}
|
||||||
|
if ((where - buf2) % 80)
|
||||||
where = buf + (int)(where - buf2) ;
|
where++;
|
||||||
|
}
|
||||||
/* Create the card */
|
while ((where - buf2) % 80);
|
||||||
card = malloc(81*sizeof(char)) ;
|
|
||||||
strncpy(card, where, 80) ;
|
|
||||||
card[80] = (char)0 ;
|
|
||||||
|
|
||||||
/* Free and return */
|
where = buf + (int) (where - buf2);
|
||||||
close(fd) ;
|
|
||||||
munmap(buf, hs) ;
|
/* Create the card */
|
||||||
free(buf2) ;
|
card = malloc (81 * sizeof (char));
|
||||||
return card ;
|
strncpy (card, where, 80);
|
||||||
|
card[80] = (char) 0;
|
||||||
|
|
||||||
|
/* Free and return */
|
||||||
|
close (fd);
|
||||||
|
munmap (buf, hs);
|
||||||
|
free (buf2);
|
||||||
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -637,76 +697,77 @@ char * qfits_query_card(
|
||||||
Returns 0 if everything worked Ok, -1 otherwise.
|
Returns 0 if everything worked Ok, -1 otherwise.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_replace_card(
|
int
|
||||||
char * filename,
|
qfits_replace_card (char *filename, const char *keyword, char *substitute)
|
||||||
const char * keyword,
|
|
||||||
char * substitute)
|
|
||||||
{
|
{
|
||||||
char * exp_key ;
|
char *exp_key;
|
||||||
int fd ;
|
int fd;
|
||||||
char * buf ;
|
char *buf;
|
||||||
char * buf2 ;
|
char *buf2;
|
||||||
char * where ;
|
char *where;
|
||||||
int hs ;
|
int hs;
|
||||||
|
|
||||||
|
|
||||||
/* Bulletproof entries */
|
/* Bulletproof entries */
|
||||||
if (filename==NULL || keyword==NULL || substitute==NULL) return -1 ;
|
if (filename == NULL || keyword == NULL || substitute == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* Expand keyword */
|
/* Expand keyword */
|
||||||
exp_key = qfits_expand_keyword(keyword);
|
exp_key = qfits_expand_keyword (keyword);
|
||||||
/*
|
/*
|
||||||
* Memory-map the FITS header of the input file
|
* Memory-map the FITS header of the input file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
qfits_get_hdrinfo(filename, 0, NULL, &hs) ;
|
qfits_get_hdrinfo (filename, 0, NULL, &hs);
|
||||||
if (hs < 1) {
|
if (hs < 1)
|
||||||
qfits_error("error getting FITS header size for %s", filename);
|
{
|
||||||
return -1 ;
|
qfits_error ("error getting FITS header size for %s", filename);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
fd = open(filename, O_RDWR) ;
|
fd = open (filename, O_RDWR);
|
||||||
if (fd == -1) {
|
if (fd == -1)
|
||||||
return -1 ;
|
{
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
buf = (char*)mmap(0,
|
buf = (char *) mmap (0, hs, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
hs,
|
if (buf == (char *) -1)
|
||||||
PROT_READ | PROT_WRITE,
|
{
|
||||||
MAP_SHARED,
|
perror ("mmap");
|
||||||
fd,
|
close (fd);
|
||||||
0) ;
|
return -1;
|
||||||
if (buf == (char*)-1) {
|
|
||||||
perror("mmap") ;
|
|
||||||
close(fd) ;
|
|
||||||
return -1 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply search and replace for the input keyword lists */
|
/* Apply search and replace for the input keyword lists */
|
||||||
buf2 = malloc(hs+1) ;
|
buf2 = malloc (hs + 1);
|
||||||
memcpy(buf2, buf, hs) ;
|
memcpy (buf2, buf, hs);
|
||||||
buf2[hs] = (char)0 ;
|
buf2[hs] = (char) 0;
|
||||||
where = buf2 ;
|
where = buf2;
|
||||||
do {
|
do
|
||||||
where = strstr(where, exp_key);
|
{
|
||||||
if (where == NULL) {
|
where = strstr (where, exp_key);
|
||||||
close(fd);
|
if (where == NULL)
|
||||||
munmap(buf,hs);
|
{
|
||||||
free(buf2) ;
|
close (fd);
|
||||||
return -1 ;
|
munmap (buf, hs);
|
||||||
}
|
free (buf2);
|
||||||
if ((where-buf2)%80) where++ ;
|
return -1;
|
||||||
} while ((where-buf2)%80) ;
|
}
|
||||||
|
if ((where - buf2) % 80)
|
||||||
where = buf + (int)(where - buf2) ;
|
where++;
|
||||||
|
}
|
||||||
/* Replace current placeholder by blanks */
|
while ((where - buf2) % 80);
|
||||||
memset(where, ' ', 80);
|
|
||||||
/* Copy substitute into placeholder */
|
|
||||||
memcpy(where, substitute, strlen(substitute));
|
|
||||||
|
|
||||||
close(fd) ;
|
where = buf + (int) (where - buf2);
|
||||||
munmap(buf, hs) ;
|
|
||||||
free(buf2) ;
|
/* Replace current placeholder by blanks */
|
||||||
return 0 ;
|
memset (where, ' ', 80);
|
||||||
|
/* Copy substitute into placeholder */
|
||||||
|
memcpy (where, substitute, strlen (substitute));
|
||||||
|
|
||||||
|
close (fd);
|
||||||
|
munmap (buf, hs);
|
||||||
|
free (buf2);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
#define SIMPLE_H
|
#define SIMPLE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -82,7 +83,7 @@ extern "C" {
|
||||||
Returns NULL in case the requested keyword cannot be found.
|
Returns NULL in case the requested keyword cannot be found.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_query_hdr(char * filename, const char * keyword) ;
|
char *qfits_query_hdr (char *filename, const char *keyword);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +98,7 @@ char * qfits_query_hdr(char * filename, const char * keyword) ;
|
||||||
strictly identical to qfits_query_hdr().
|
strictly identical to qfits_query_hdr().
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_query_ext(char * filename, const char * keyword, int xtnum) ;
|
char *qfits_query_ext (char *filename, const char *keyword, int xtnum);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -109,7 +110,7 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum) ;
|
||||||
extension is found, and -1 if an error occurred.
|
extension is found, and -1 if an error occurred.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_query_n_ext(char * filename) ;
|
int qfits_query_n_ext (char *filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +122,7 @@ int qfits_query_n_ext(char * filename) ;
|
||||||
and -1 if an error occurred.
|
and -1 if an error occurred.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_query_nplanes(char * filename, int extnum) ;
|
int qfits_query_nplanes (char *filename, int extnum);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -141,7 +142,7 @@ int qfits_query_nplanes(char * filename, int extnum) ;
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_pretty_string(char * s) ;
|
char *qfits_pretty_string (char *s);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -152,7 +153,7 @@ char * qfits_pretty_string(char * s) ;
|
||||||
Identifies if a FITS value is boolean.
|
Identifies if a FITS value is boolean.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_boolean(char * s) ;
|
int qfits_is_boolean (char *s);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -163,7 +164,7 @@ int qfits_is_boolean(char * s) ;
|
||||||
Identifies if a FITS value is an integer.
|
Identifies if a FITS value is an integer.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_int(char * s) ;
|
int qfits_is_int (char *s);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -174,7 +175,7 @@ int qfits_is_int(char * s) ;
|
||||||
Identifies if a FITS value is float.
|
Identifies if a FITS value is float.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_float(char * s) ;
|
int qfits_is_float (char *s);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -185,7 +186,7 @@ int qfits_is_float(char * s) ;
|
||||||
Identifies if a FITS value is complex.
|
Identifies if a FITS value is complex.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_complex(char * s) ;
|
int qfits_is_complex (char *s);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -196,7 +197,7 @@ int qfits_is_complex(char * s) ;
|
||||||
Identifies if a FITS value is a string.
|
Identifies if a FITS value is a string.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_string(char * s) ;
|
int qfits_is_string (char *s);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -214,7 +215,7 @@ int qfits_is_string(char * s) ;
|
||||||
- QFITS_STRING (5) for a FITS string.
|
- QFITS_STRING (5) for a FITS string.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_get_type(char * s) ;
|
int qfits_get_type (char *s);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -235,11 +236,8 @@ int qfits_get_type(char * s) ;
|
||||||
main header in the file.
|
main header in the file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_get_hdrinfo(
|
int qfits_get_hdrinfo (char *filename,
|
||||||
char * filename,
|
int xtnum, int *seg_start, int *seg_size);
|
||||||
int xtnum,
|
|
||||||
int * seg_start,
|
|
||||||
int * seg_size) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -260,11 +258,8 @@ int qfits_get_hdrinfo(
|
||||||
main header in the file.
|
main header in the file.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_get_datinfo(
|
int qfits_get_datinfo (char *filename,
|
||||||
char * filename,
|
int xtnum, int *seg_start, int *seg_size);
|
||||||
int xtnum,
|
|
||||||
int * seg_start,
|
|
||||||
int * seg_size) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -274,9 +269,7 @@ int qfits_get_datinfo(
|
||||||
@return Allocated string containing the card or NULL
|
@return Allocated string containing the card or NULL
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_query_card(
|
char *qfits_query_card (char *filename, char *keyword);
|
||||||
char * filename,
|
|
||||||
char * keyword) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -297,10 +290,8 @@ char * qfits_query_card(
|
||||||
Returns 0 if everything worked Ok, -1 otherwise.
|
Returns 0 if everything worked Ok, -1 otherwise.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_replace_card(
|
int qfits_replace_card (char *filename,
|
||||||
char * filename,
|
const char *keyword, char *substitute);
|
||||||
const char * keyword,
|
|
||||||
char * substitute) ;
|
|
||||||
|
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
#define STATIC_SZ_H
|
#define STATIC_SZ_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* <dox> */
|
/* <dox> */
|
||||||
|
|
|
@ -75,8 +75,8 @@
|
||||||
Private to this module
|
Private to this module
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static long timer_to_date(time_t time_secs) ;
|
static long timer_to_date (time_t time_secs);
|
||||||
static long timer_to_time(time_t time_secs) ;
|
static long timer_to_time (time_t time_secs);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Static Function code
|
Static Function code
|
||||||
|
@ -95,9 +95,10 @@ static long timer_to_time(time_t time_secs) ;
|
||||||
Example: 19 Oct 2000 is returned as 20001019
|
Example: 19 Oct 2000 is returned as 20001019
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
long qfits_date_now (void)
|
long
|
||||||
|
qfits_date_now (void)
|
||||||
{
|
{
|
||||||
return (timer_to_date (time (NULL)));
|
return (timer_to_date (time (NULL)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -111,13 +112,13 @@ long qfits_date_now (void)
|
||||||
Example: 15:36:12.84 is returned as 15361284
|
Example: 15:36:12.84 is returned as 15361284
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
long qfits_time_now(void)
|
long
|
||||||
|
qfits_time_now (void)
|
||||||
{
|
{
|
||||||
struct timeval time_struct;
|
struct timeval time_struct;
|
||||||
|
|
||||||
gettimeofday (&time_struct, 0);
|
gettimeofday (&time_struct, 0);
|
||||||
return (timer_to_time (time_struct.tv_sec)
|
return (timer_to_time (time_struct.tv_sec) + time_struct.tv_usec / 10000);
|
||||||
+ time_struct.tv_usec / 10000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -133,25 +134,31 @@ long qfits_time_now(void)
|
||||||
(GMT).
|
(GMT).
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static long timer_to_date(time_t time_secs)
|
static long
|
||||||
|
timer_to_date (time_t time_secs)
|
||||||
{
|
{
|
||||||
struct tm *time_struct;
|
struct tm *time_struct;
|
||||||
|
|
||||||
if (time_secs == 0) {
|
if (time_secs == 0)
|
||||||
return 0;
|
{
|
||||||
} else {
|
return 0;
|
||||||
/* Convert into a long value CCYYMMDD */
|
}
|
||||||
time_struct = localtime (&time_secs);
|
else
|
||||||
if (time_struct) {
|
{
|
||||||
time_struct-> tm_year += 1900;
|
/* Convert into a long value CCYYMMDD */
|
||||||
return (MAKE_DATE ( time_struct-> tm_year / 100,
|
time_struct = localtime (&time_secs);
|
||||||
time_struct-> tm_year % 100,
|
if (time_struct)
|
||||||
time_struct-> tm_mon + 1,
|
{
|
||||||
time_struct-> tm_mday));
|
time_struct->tm_year += 1900;
|
||||||
} else {
|
return (MAKE_DATE (time_struct->tm_year / 100,
|
||||||
return (19700101);
|
time_struct->tm_year % 100,
|
||||||
}
|
time_struct->tm_mon + 1, time_struct->tm_mday));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (19700101);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -167,24 +174,29 @@ static long timer_to_date(time_t time_secs)
|
||||||
(GMT).
|
(GMT).
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static long timer_to_time(time_t time_secs)
|
static long
|
||||||
|
timer_to_time (time_t time_secs)
|
||||||
{
|
{
|
||||||
struct tm *time_struct;
|
struct tm *time_struct;
|
||||||
|
|
||||||
if (time_secs == 0) {
|
if (time_secs == 0)
|
||||||
return 0;
|
{
|
||||||
} else {
|
return 0;
|
||||||
/* Convert into a long value HHMMSS00 */
|
}
|
||||||
time_struct = localtime (&time_secs);
|
else
|
||||||
if (time_struct) {
|
{
|
||||||
return (MAKE_TIME (time_struct-> tm_hour,
|
/* Convert into a long value HHMMSS00 */
|
||||||
time_struct-> tm_min,
|
time_struct = localtime (&time_secs);
|
||||||
time_struct-> tm_sec,
|
if (time_struct)
|
||||||
0));
|
{
|
||||||
} else {
|
return (MAKE_TIME (time_struct->tm_hour,
|
||||||
return 0;
|
time_struct->tm_min, time_struct->tm_sec, 0));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -201,17 +213,16 @@ static long timer_to_time(time_t time_secs)
|
||||||
in the function, so no need to free it.
|
in the function, so no need to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_date_iso8601(void)
|
char *
|
||||||
|
qfits_get_date_iso8601 (void)
|
||||||
{
|
{
|
||||||
static char date_iso8601[20] ;
|
static char date_iso8601[20];
|
||||||
long curdate ;
|
long curdate;
|
||||||
|
|
||||||
curdate = qfits_date_now() ;
|
curdate = qfits_date_now ();
|
||||||
sprintf(date_iso8601, "%04d-%02d-%02d",
|
sprintf (date_iso8601, "%04d-%02d-%02d",
|
||||||
GET_CCYEAR(curdate),
|
GET_CCYEAR (curdate), GET_MONTH (curdate), GET_DAY (curdate));
|
||||||
GET_MONTH(curdate),
|
return date_iso8601;
|
||||||
GET_DAY(curdate));
|
|
||||||
return date_iso8601 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -224,38 +235,37 @@ char * qfits_get_date_iso8601(void)
|
||||||
statically allocated string in the function, so no need to free it.
|
statically allocated string in the function, so no need to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_datetime_iso8601(void)
|
char *
|
||||||
|
qfits_get_datetime_iso8601 (void)
|
||||||
{
|
{
|
||||||
static char date_iso8601[20] ;
|
static char date_iso8601[20];
|
||||||
long curdate ;
|
long curdate;
|
||||||
long curtime ;
|
long curtime;
|
||||||
|
|
||||||
curdate = qfits_date_now() ;
|
curdate = qfits_date_now ();
|
||||||
curtime = qfits_time_now() ;
|
curtime = qfits_time_now ();
|
||||||
|
|
||||||
sprintf(date_iso8601, "%04d-%02d-%02dT%02d:%02d:%02d",
|
sprintf (date_iso8601, "%04d-%02d-%02dT%02d:%02d:%02d",
|
||||||
GET_CCYEAR(curdate),
|
GET_CCYEAR (curdate),
|
||||||
GET_MONTH(curdate),
|
GET_MONTH (curdate),
|
||||||
GET_DAY(curdate),
|
GET_DAY (curdate),
|
||||||
GET_HOUR(curtime),
|
GET_HOUR (curtime), GET_MINUTE (curtime), GET_SECOND (curtime));
|
||||||
GET_MINUTE(curtime),
|
return date_iso8601;
|
||||||
GET_SECOND(curtime));
|
|
||||||
return date_iso8601 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
printf( "date now %ld\n"
|
printf ("date now %ld\n"
|
||||||
"time now %ld\n"
|
"time now %ld\n"
|
||||||
"date iso8601 %s\n"
|
"date iso8601 %s\n"
|
||||||
"date/time iso 8601 %s\n",
|
"date/time iso 8601 %s\n",
|
||||||
qfits_date_now(),
|
qfits_date_now (),
|
||||||
qfits_time_now(),
|
qfits_time_now (),
|
||||||
qfits_get_date_iso8601(),
|
qfits_get_date_iso8601 (), qfits_get_datetime_iso8601 ());
|
||||||
qfits_get_datetime_iso8601());
|
|
||||||
|
return 0;
|
||||||
return 0 ;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* vim: set ts=4 et sw=4 tw=75 */
|
/* vim: set ts=4 et sw=4 tw=75 */
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
#define T_ISO8601_H
|
#define T_ISO8601_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ extern "C" {
|
||||||
Example: 19 Oct 2000 is returned as 20001019
|
Example: 19 Oct 2000 is returned as 20001019
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
long qfits_date_now (void);
|
long qfits_date_now (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +59,7 @@ long qfits_date_now (void);
|
||||||
Example: 15:36:12.84 is returned as 15361284
|
Example: 15:36:12.84 is returned as 15361284
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
long qfits_time_now(void);
|
long qfits_time_now (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +71,7 @@ long qfits_time_now(void);
|
||||||
in the function, so no need to free it.
|
in the function, so no need to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_date_iso8601(void);
|
char *qfits_get_date_iso8601 (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +83,7 @@ char * qfits_get_date_iso8601(void);
|
||||||
statically allocated string in the function, so no need to free it.
|
statically allocated string in the function, so no need to free it.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_get_datetime_iso8601(void);
|
char *qfits_get_datetime_iso8601 (void);
|
||||||
|
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
3979
qfits/src/tfits.c
3979
qfits/src/tfits.c
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,8 @@
|
||||||
#define TFITS_H
|
#define TFITS_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -30,7 +31,7 @@ extern "C" {
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "fits_h.h"
|
#include "fits_h.h"
|
||||||
#include "static_sz.h"
|
#include "static_sz.h"
|
||||||
|
|
||||||
|
@ -53,27 +54,28 @@ extern "C" {
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief Column data type
|
@brief Column data type
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
typedef enum _TFITS_DATA_TYPE_ {
|
typedef enum _TFITS_DATA_TYPE_
|
||||||
TFITS_ASCII_TYPE_A,
|
{
|
||||||
TFITS_ASCII_TYPE_D,
|
TFITS_ASCII_TYPE_A,
|
||||||
TFITS_ASCII_TYPE_E,
|
TFITS_ASCII_TYPE_D,
|
||||||
TFITS_ASCII_TYPE_F,
|
TFITS_ASCII_TYPE_E,
|
||||||
TFITS_ASCII_TYPE_I,
|
TFITS_ASCII_TYPE_F,
|
||||||
TFITS_BIN_TYPE_A,
|
TFITS_ASCII_TYPE_I,
|
||||||
TFITS_BIN_TYPE_B,
|
TFITS_BIN_TYPE_A,
|
||||||
TFITS_BIN_TYPE_C,
|
TFITS_BIN_TYPE_B,
|
||||||
TFITS_BIN_TYPE_D,
|
TFITS_BIN_TYPE_C,
|
||||||
TFITS_BIN_TYPE_E,
|
TFITS_BIN_TYPE_D,
|
||||||
TFITS_BIN_TYPE_I,
|
TFITS_BIN_TYPE_E,
|
||||||
TFITS_BIN_TYPE_J,
|
TFITS_BIN_TYPE_I,
|
||||||
TFITS_BIN_TYPE_L,
|
TFITS_BIN_TYPE_J,
|
||||||
TFITS_BIN_TYPE_M,
|
TFITS_BIN_TYPE_L,
|
||||||
TFITS_BIN_TYPE_P,
|
TFITS_BIN_TYPE_M,
|
||||||
TFITS_BIN_TYPE_X,
|
TFITS_BIN_TYPE_P,
|
||||||
TFITS_BIN_TYPE_UNKNOWN
|
TFITS_BIN_TYPE_X,
|
||||||
} tfits_type ;
|
TFITS_BIN_TYPE_UNKNOWN
|
||||||
|
} tfits_type;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -87,8 +89,8 @@ typedef enum _TFITS_DATA_TYPE_ {
|
||||||
generate a FITS table.
|
generate a FITS table.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
typedef struct qfits_col
|
typedef struct qfits_col
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
Number of atoms in one field.
|
Number of atoms in one field.
|
||||||
In ASCII tables, it is the number of characters in the field as defined
|
In ASCII tables, it is the number of characters in the field as defined
|
||||||
|
@ -97,13 +99,13 @@ typedef struct qfits_col
|
||||||
it is the number of characters. A field with two complex object will
|
it is the number of characters. A field with two complex object will
|
||||||
have atom_nb = 4.
|
have atom_nb = 4.
|
||||||
*/
|
*/
|
||||||
int atom_nb ;
|
int atom_nb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Number of decimals in a ASCII field.
|
Number of decimals in a ASCII field.
|
||||||
This value is always 0 for BIN tables
|
This value is always 0 for BIN tables
|
||||||
*/
|
*/
|
||||||
int atom_dec_nb ;
|
int atom_dec_nb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Size of one element in bytes. In ASCII tables, atom_size is the size
|
Size of one element in bytes. In ASCII tables, atom_size is the size
|
||||||
|
@ -124,44 +126,44 @@ typedef struct qfits_col
|
||||||
conversion of the field is atom_size.
|
conversion of the field is atom_size.
|
||||||
In BIN tables, the size in bytes of a field is always atom_nb*atom_size.
|
In BIN tables, the size in bytes of a field is always atom_nb*atom_size.
|
||||||
*/
|
*/
|
||||||
int atom_size ;
|
int atom_size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Type of data in the column as specified in TFORM keyword
|
Type of data in the column as specified in TFORM keyword
|
||||||
In ASCII tables : TFITS_ASCII_TYPE_* with *=A, I, F, E or D
|
In ASCII tables : TFITS_ASCII_TYPE_* with *=A, I, F, E or D
|
||||||
In BIN tables : TFITS_BIN_TYPE_* with *=L, X, B, I, J, A, E, D, C, M or P
|
In BIN tables : TFITS_BIN_TYPE_* with *=L, X, B, I, J, A, E, D, C, M or P
|
||||||
*/
|
*/
|
||||||
tfits_type atom_type ;
|
tfits_type atom_type;
|
||||||
|
|
||||||
/** Label of the column */
|
/** Label of the column */
|
||||||
char tlabel[FITSVALSZ] ;
|
char tlabel[FITSVALSZ];
|
||||||
|
|
||||||
/** Unit of the data */
|
/** Unit of the data */
|
||||||
char tunit[FITSVALSZ] ;
|
char tunit[FITSVALSZ];
|
||||||
|
|
||||||
/** Null value */
|
/** Null value */
|
||||||
char nullval[FITSVALSZ] ;
|
char nullval[FITSVALSZ];
|
||||||
|
|
||||||
/** Display format */
|
/** Display format */
|
||||||
char tdisp[FITSVALSZ] ;
|
char tdisp[FITSVALSZ];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
zero and scale are used when the quantity in the field does not
|
zero and scale are used when the quantity in the field does not
|
||||||
represent a true physical quantity. Basically, thez should be used
|
represent a true physical quantity. Basically, thez should be used
|
||||||
when they are present: physical_value = zero + scale * field_value
|
when they are present: physical_value = zero + scale * field_value
|
||||||
They are read from TZERO and TSCAL in the header
|
They are read from TZERO and TSCAL in the header
|
||||||
*/
|
*/
|
||||||
int zero_present ;
|
int zero_present;
|
||||||
float zero ;
|
float zero;
|
||||||
int scale_present ;
|
int scale_present;
|
||||||
float scale ;
|
float scale;
|
||||||
|
|
||||||
/** Offset between the beg. of the table and the beg. of the column. */
|
/** Offset between the beg. of the table and the beg. of the column. */
|
||||||
int off_beg ;
|
int off_beg;
|
||||||
|
|
||||||
/** Flag to know if the column is readable. An empty col is not readable */
|
/** Flag to know if the column is readable. An empty col is not readable */
|
||||||
int readable ;
|
int readable;
|
||||||
} qfits_col ;
|
} qfits_col;
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -195,26 +197,26 @@ typedef struct qfits_col
|
||||||
@endcode
|
@endcode
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
typedef struct qfits_table
|
typedef struct qfits_table
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
Name of the file the table comes from or it is intended to end to
|
Name of the file the table comes from or it is intended to end to
|
||||||
*/
|
*/
|
||||||
char filename[FILENAMESZ] ;
|
char filename[FILENAMESZ];
|
||||||
/**
|
/**
|
||||||
Table type.
|
Table type.
|
||||||
Possible values: QFITS_INVALIDTABLE, QFITS_BINTABLE, QFITS_ASCIITABLE
|
Possible values: QFITS_INVALIDTABLE, QFITS_BINTABLE, QFITS_ASCIITABLE
|
||||||
*/
|
*/
|
||||||
int tab_t ;
|
int tab_t;
|
||||||
/** Width in bytes of the table */
|
/** Width in bytes of the table */
|
||||||
int tab_w ;
|
int tab_w;
|
||||||
/** Number of columns */
|
/** Number of columns */
|
||||||
int nc ;
|
int nc;
|
||||||
/** Number of raws */
|
/** Number of raws */
|
||||||
int nr ;
|
int nr;
|
||||||
/** Array of qfits_col objects */
|
/** Array of qfits_col objects */
|
||||||
qfits_col * col ;
|
qfits_col *col;
|
||||||
} qfits_table ;
|
} qfits_table;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
|
@ -231,7 +233,7 @@ typedef struct qfits_table
|
||||||
FITS table.
|
FITS table.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_is_table(char * filename, int xtnum) ;
|
int qfits_is_table (char *filename, int xtnum);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -239,7 +241,7 @@ int qfits_is_table(char * filename, int xtnum) ;
|
||||||
@return the header object
|
@return the header object
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_table_prim_header_default(void) ;
|
qfits_header *qfits_table_prim_header_default (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -247,7 +249,7 @@ qfits_header * qfits_table_prim_header_default(void) ;
|
||||||
@return the header object
|
@return the header object
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_header * qfits_table_ext_header_default(qfits_table *) ;
|
qfits_header *qfits_table_ext_header_default (qfits_table *);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -262,12 +264,9 @@ qfits_header * qfits_table_ext_header_default(qfits_table *) ;
|
||||||
qfits_table_close()
|
qfits_table_close()
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_table * qfits_table_new(
|
qfits_table *qfits_table_new (char *filename,
|
||||||
char * filename,
|
int table_type,
|
||||||
int table_type,
|
int table_width, int nb_cols, int nb_raws);
|
||||||
int table_width,
|
|
||||||
int nb_cols,
|
|
||||||
int nb_raws) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -293,21 +292,18 @@ qfits_table * qfits_table_new(
|
||||||
@return -1 in error case, 0 otherwise
|
@return -1 in error case, 0 otherwise
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_col_fill(
|
int qfits_col_fill (qfits_col * qc,
|
||||||
qfits_col * qc,
|
int atom_nb,
|
||||||
int atom_nb,
|
int atom_dec_nb,
|
||||||
int atom_dec_nb,
|
int atom_size,
|
||||||
int atom_size,
|
tfits_type atom_type,
|
||||||
tfits_type atom_type,
|
char *label,
|
||||||
char * label,
|
char *unit,
|
||||||
char * unit,
|
char *nullval,
|
||||||
char * nullval,
|
char *disp,
|
||||||
char * disp,
|
int zero_present,
|
||||||
int zero_present,
|
float zero,
|
||||||
float zero,
|
int scale_present, float scale, int offset_beg);
|
||||||
int scale_present,
|
|
||||||
float scale,
|
|
||||||
int offset_beg) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -320,9 +316,7 @@ int qfits_col_fill(
|
||||||
newly allocated qfits_table structure.
|
newly allocated qfits_table structure.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
qfits_table * qfits_table_open(
|
qfits_table *qfits_table_open (char *filename, int xtnum);
|
||||||
char * filename,
|
|
||||||
int xtnum) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -332,7 +326,7 @@ qfits_table * qfits_table_open(
|
||||||
Frees all memory associated to a qfits_table structure.
|
Frees all memory associated to a qfits_table structure.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void qfits_table_close(qfits_table * t) ;
|
void qfits_table_close (qfits_table * t);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -363,10 +357,8 @@ void qfits_table_close(qfits_table * t) ;
|
||||||
the pixel loader here.
|
the pixel loader here.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
unsigned char * qfits_query_column(
|
unsigned char *qfits_query_column (qfits_table * th,
|
||||||
qfits_table * th,
|
int colnum, int *selection);
|
||||||
int colnum,
|
|
||||||
int * selection) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -380,11 +372,9 @@ unsigned char * qfits_query_column(
|
||||||
Spares the overhead of the selection object allocation
|
Spares the overhead of the selection object allocation
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
unsigned char * qfits_query_column_seq(
|
unsigned char *qfits_query_column_seq (qfits_table * th,
|
||||||
qfits_table * th,
|
int colnum,
|
||||||
int colnum,
|
int start_ind, int nb_rows);
|
||||||
int start_ind,
|
|
||||||
int nb_rows) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -393,7 +383,7 @@ unsigned char * qfits_query_column_seq(
|
||||||
@return the width (-1 in error case)
|
@return the width (-1 in error case)
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_compute_table_width(qfits_table * th) ;
|
int qfits_compute_table_width (qfits_table * th);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -420,11 +410,9 @@ int qfits_compute_table_width(qfits_table * th) ;
|
||||||
the pixel loader here.
|
the pixel loader here.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void * qfits_query_column_data(
|
void *qfits_query_column_data (qfits_table * th,
|
||||||
qfits_table * th,
|
int colnum,
|
||||||
int colnum,
|
int *selection, void *null_value);
|
||||||
int * selection,
|
|
||||||
void * null_value) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -439,12 +427,10 @@ void * qfits_query_column_data(
|
||||||
of rows. Spares the overhead of the selection object allocation
|
of rows. Spares the overhead of the selection object allocation
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void * qfits_query_column_seq_data(
|
void *qfits_query_column_seq_data (qfits_table * th,
|
||||||
qfits_table * th,
|
int colnum,
|
||||||
int colnum,
|
int start_ind,
|
||||||
int start_ind,
|
int nb_rows, void *null_value);
|
||||||
int nb_rows,
|
|
||||||
void * null_value) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -457,12 +443,9 @@ void * qfits_query_column_seq_data(
|
||||||
@return array with 1 for NULLs and 0 for non-NULLs
|
@return array with 1 for NULLs and 0 for non-NULLs
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int * qfits_query_column_nulls(
|
int *qfits_query_column_nulls (qfits_table * th,
|
||||||
qfits_table * th,
|
int colnum,
|
||||||
int colnum,
|
int *selection, int *nb_vals, int *nb_nulls);
|
||||||
int * selection,
|
|
||||||
int * nb_vals,
|
|
||||||
int * nb_nulls) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -473,10 +456,8 @@ int * qfits_query_column_nulls(
|
||||||
@return -1 in error case, 0 otherwise
|
@return -1 in error case, 0 otherwise
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_save_table_hdrdump(
|
int qfits_save_table_hdrdump (void **array,
|
||||||
void ** array,
|
qfits_table * table, qfits_header * fh);
|
||||||
qfits_table * table,
|
|
||||||
qfits_header * fh) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -494,10 +475,8 @@ int qfits_save_table_hdrdump(
|
||||||
Notice that no main header is produced, only the extension part.
|
Notice that no main header is produced, only the extension part.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_table_append_xtension(
|
int qfits_table_append_xtension (FILE * outfile,
|
||||||
FILE * outfile,
|
qfits_table * t, void **data);
|
||||||
qfits_table * t,
|
|
||||||
void ** data) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -515,11 +494,9 @@ int qfits_table_append_xtension(
|
||||||
Notice that no main header is produced, only the extension part.
|
Notice that no main header is produced, only the extension part.
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
int qfits_table_append_xtension_hdr(
|
int qfits_table_append_xtension_hdr (FILE * outfile,
|
||||||
FILE * outfile,
|
qfits_table * t,
|
||||||
qfits_table * t,
|
void **data, qfits_header * hdr);
|
||||||
void ** data,
|
|
||||||
qfits_header * hdr) ;
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -531,11 +508,9 @@ int qfits_table_append_xtension_hdr(
|
||||||
@return the string to write
|
@return the string to write
|
||||||
*/
|
*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
char * qfits_table_field_to_string(
|
char *qfits_table_field_to_string (qfits_table * table,
|
||||||
qfits_table * table,
|
int col_id,
|
||||||
int col_id,
|
int row_id, int use_zero_scale);
|
||||||
int row_id,
|
|
||||||
int use_zero_scale) ;
|
|
||||||
|
|
||||||
/* </dox> */
|
/* </dox> */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
/* Library version */
|
/* Library version */
|
||||||
static const char *
|
static const char *_qfits_version = "5.4.0";
|
||||||
_qfits_version = "5.4.0" ;
|
|
||||||
|
|
||||||
const char * qfits_version(void)
|
const char *
|
||||||
|
qfits_version (void)
|
||||||
{
|
{
|
||||||
return _qfits_version ;
|
return _qfits_version;
|
||||||
}
|
}
|
||||||
|
|
1842
qfits/src/xmemory.c
1842
qfits/src/xmemory.c
File diff suppressed because it is too large
Load Diff
1694
qfits/sysconf.c
1694
qfits/sysconf.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue