Indent qfits to GNU style, perhaps
parent
7621d31783
commit
db0415128c
|
@ -53,7 +53,8 @@ char * qfits_expand_keyword(const char * keyword);
|
|||
accessor functions.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct qfits_header {
|
||||
typedef struct qfits_header
|
||||
{
|
||||
void *first; /* Pointer to list start */
|
||||
void *last; /* Pointer to list end */
|
||||
int n; /* Number of cards in list */
|
||||
|
@ -102,12 +103,8 @@ qfits_header * qfits_header_default(void) ;
|
|||
are allowed to get NULL values.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void qfits_header_add(
|
||||
qfits_header * hdr,
|
||||
char * key,
|
||||
char * val,
|
||||
char * com,
|
||||
char * lin) ;
|
||||
void qfits_header_add (qfits_header * hdr,
|
||||
char *key, char *val, char *com, char *lin);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -125,13 +122,9 @@ void qfits_header_add(
|
|||
can be NULL, except after and key.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void qfits_header_add_after(
|
||||
qfits_header * hdr,
|
||||
void qfits_header_add_after (qfits_header * hdr,
|
||||
char *after,
|
||||
char * key,
|
||||
char * val,
|
||||
char * com,
|
||||
char * lin) ;
|
||||
char *key, char *val, char *com, char *lin);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -147,12 +140,9 @@ void qfits_header_add_after(
|
|||
NULL except key.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void qfits_header_append(
|
||||
qfits_header * hdr,
|
||||
void qfits_header_append (qfits_header * hdr,
|
||||
const char *key,
|
||||
const char * val,
|
||||
const char * com,
|
||||
const char * lin) ;
|
||||
const char *val, const char *com, const char *lin);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -315,13 +305,9 @@ char * qfits_header_findmatch(qfits_header * hdr, char * key) ;
|
|||
available in this module.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_header_getitem(
|
||||
qfits_header * hdr,
|
||||
int qfits_header_getitem (qfits_header * hdr,
|
||||
int idx,
|
||||
char * key,
|
||||
char * val,
|
||||
char * com,
|
||||
char * lin) ;
|
||||
char *key, char *val, char *com, char *lin);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -384,7 +370,8 @@ int qfits_header_getint(qfits_header * hdr, const char * key, int errval) ;
|
|||
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);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -577,8 +564,7 @@ qfits_header * qfits_header_read_hdr(char * filename) ;
|
|||
object.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_header * qfits_header_read_hdr_string(
|
||||
unsigned char * hdr_str,
|
||||
qfits_header *qfits_header_read_hdr_string (unsigned char *hdr_str,
|
||||
int nb_char);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
@ -873,12 +859,10 @@ int _qfits_isinfd(double d);
|
|||
the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
FILE * qfits_paf_print_header(
|
||||
char * filename,
|
||||
FILE *qfits_paf_print_header (char *filename,
|
||||
char *paf_id,
|
||||
char *paf_desc,
|
||||
char * login_name,
|
||||
char * datetime) ;
|
||||
char *login_name, char *datetime);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -894,9 +878,7 @@ FILE * qfits_paf_print_header(
|
|||
If the key is not found, this function returns NULL.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_paf_query(
|
||||
char * filename,
|
||||
char * key) ;
|
||||
char *qfits_paf_query (char *filename, char *key);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -1006,7 +988,8 @@ int main(int argc, char * argv[])
|
|||
@endcode
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct qfitsloader {
|
||||
typedef struct qfitsloader
|
||||
{
|
||||
|
||||
/** Private field to see if structure has been initialized */
|
||||
int _init;
|
||||
|
@ -1095,7 +1078,8 @@ typedef struct qfitsloader {
|
|||
could have been re-directed).
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct qfitsdumper {
|
||||
typedef struct qfitsdumper
|
||||
{
|
||||
|
||||
/** Name of the file to dump to, "STDOUT" to dump to stdout */
|
||||
char *filename;
|
||||
|
@ -1581,11 +1565,8 @@ int qfits_get_type(char * s) ;
|
|||
main header in the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_get_hdrinfo(
|
||||
char * filename,
|
||||
int xtnum,
|
||||
int * seg_start,
|
||||
int * seg_size) ;
|
||||
int qfits_get_hdrinfo (char *filename,
|
||||
int xtnum, int *seg_start, int *seg_size);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -1606,11 +1587,8 @@ int qfits_get_hdrinfo(
|
|||
main header in the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_get_datinfo(
|
||||
char * filename,
|
||||
int xtnum,
|
||||
int * seg_start,
|
||||
int * seg_size) ;
|
||||
int qfits_get_datinfo (char *filename,
|
||||
int xtnum, int *seg_start, int *seg_size);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -1620,9 +1598,7 @@ int qfits_get_datinfo(
|
|||
@return Allocated string containing the card or NULL
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_query_card(
|
||||
char * filename,
|
||||
char * keyword) ;
|
||||
char *qfits_query_card (char *filename, char *keyword);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -1643,10 +1619,8 @@ char * qfits_query_card(
|
|||
Returns 0 if everything worked Ok, -1 otherwise.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_replace_card(
|
||||
char * filename,
|
||||
const char * keyword,
|
||||
char * substitute) ;
|
||||
int qfits_replace_card (char *filename,
|
||||
const char *keyword, char *substitute);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Defines
|
||||
|
@ -1734,7 +1708,8 @@ char * qfits_get_datetime_iso8601(void);
|
|||
@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_E,
|
||||
|
@ -1941,12 +1916,9 @@ qfits_header * qfits_table_ext_header_default(qfits_table *) ;
|
|||
qfits_table_close()
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_table * qfits_table_new(
|
||||
char * filename,
|
||||
qfits_table *qfits_table_new (char *filename,
|
||||
int table_type,
|
||||
int table_width,
|
||||
int nb_cols,
|
||||
int nb_raws) ;
|
||||
int table_width, int nb_cols, int nb_raws);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -1972,8 +1944,7 @@ qfits_table * qfits_table_new(
|
|||
@return -1 in error case, 0 otherwise
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_col_fill(
|
||||
qfits_col * qc,
|
||||
int qfits_col_fill (qfits_col * qc,
|
||||
int atom_nb,
|
||||
int atom_dec_nb,
|
||||
int atom_size,
|
||||
|
@ -1984,9 +1955,7 @@ int qfits_col_fill(
|
|||
char *disp,
|
||||
int zero_present,
|
||||
float zero,
|
||||
int scale_present,
|
||||
float scale,
|
||||
int offset_beg) ;
|
||||
int scale_present, float scale, int offset_beg);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -1999,9 +1968,7 @@ int qfits_col_fill(
|
|||
newly allocated qfits_table structure.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_table * qfits_table_open(
|
||||
char * filename,
|
||||
int xtnum) ;
|
||||
qfits_table *qfits_table_open (char *filename, int xtnum);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2042,10 +2009,8 @@ void qfits_table_close(qfits_table * t) ;
|
|||
the pixel loader here.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
unsigned char * qfits_query_column(
|
||||
qfits_table * th,
|
||||
int colnum,
|
||||
int * selection) ;
|
||||
unsigned char *qfits_query_column (qfits_table * th,
|
||||
int colnum, int *selection);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2059,11 +2024,9 @@ unsigned char * qfits_query_column(
|
|||
Spares the overhead of the selection object allocation
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
unsigned char * qfits_query_column_seq(
|
||||
qfits_table * th,
|
||||
unsigned char *qfits_query_column_seq (qfits_table * th,
|
||||
int colnum,
|
||||
int start_ind,
|
||||
int nb_rows) ;
|
||||
int start_ind, int nb_rows);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2099,11 +2062,8 @@ int qfits_compute_table_width(qfits_table * th) ;
|
|||
the pixel loader here.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void * qfits_query_column_data(
|
||||
qfits_table * th,
|
||||
int colnum,
|
||||
int * selection,
|
||||
void * null_value) ;
|
||||
void *qfits_query_column_data (qfits_table * th,
|
||||
int colnum, int *selection, void *null_value);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2118,12 +2078,10 @@ void * qfits_query_column_data(
|
|||
of rows. Spares the overhead of the selection object allocation
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void * qfits_query_column_seq_data(
|
||||
qfits_table * th,
|
||||
void *qfits_query_column_seq_data (qfits_table * th,
|
||||
int colnum,
|
||||
int start_ind,
|
||||
int nb_rows,
|
||||
void * null_value) ;
|
||||
int nb_rows, void *null_value);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2136,12 +2094,9 @@ void * qfits_query_column_seq_data(
|
|||
@return array with 1 for NULLs and 0 for non-NULLs
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int * qfits_query_column_nulls(
|
||||
qfits_table * th,
|
||||
int *qfits_query_column_nulls (qfits_table * th,
|
||||
int colnum,
|
||||
int * selection,
|
||||
int * nb_vals,
|
||||
int * nb_nulls) ;
|
||||
int *selection, int *nb_vals, int *nb_nulls);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2152,10 +2107,8 @@ int * qfits_query_column_nulls(
|
|||
@return -1 in error case, 0 otherwise
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_save_table_hdrdump(
|
||||
void ** array,
|
||||
qfits_table * table,
|
||||
qfits_header * fh) ;
|
||||
int qfits_save_table_hdrdump (void **array,
|
||||
qfits_table * table, qfits_header * fh);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2173,10 +2126,8 @@ int qfits_save_table_hdrdump(
|
|||
Notice that no main header is produced, only the extension part.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_table_append_xtension(
|
||||
FILE * outfile,
|
||||
qfits_table * t,
|
||||
void ** data) ;
|
||||
int qfits_table_append_xtension (FILE * outfile,
|
||||
qfits_table * t, void **data);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2194,11 +2145,9 @@ int qfits_table_append_xtension(
|
|||
Notice that no main header is produced, only the extension part.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_table_append_xtension_hdr(
|
||||
FILE * outfile,
|
||||
int qfits_table_append_xtension_hdr (FILE * outfile,
|
||||
qfits_table * t,
|
||||
void ** data,
|
||||
qfits_header * hdr) ;
|
||||
void **data, qfits_header * hdr);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -2210,13 +2159,10 @@ int qfits_table_append_xtension_hdr(
|
|||
@return the string to write
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_table_field_to_string(
|
||||
qfits_table * table,
|
||||
char *qfits_table_field_to_string (qfits_table * table,
|
||||
int col_id,
|
||||
int row_id,
|
||||
int use_zero_scale) ;
|
||||
int row_id, int use_zero_scale);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -54,7 +54,8 @@ char * rstrip(char *) ;
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int xtnum;
|
||||
int c_arg;
|
||||
|
@ -62,13 +63,15 @@ int main(int argc, char *argv[])
|
|||
int err;
|
||||
|
||||
/* No arguments prints out a usage message */
|
||||
if (argc<2) usage(argv[0]);
|
||||
if (argc < 2)
|
||||
usage (argv[0]);
|
||||
|
||||
/* Parse command-line options */
|
||||
parse_cmd_line (argc, argv, &xtnum, &filter, &c_arg);
|
||||
|
||||
/* Filter mode: process data received from stdin */
|
||||
if (filter) {
|
||||
if (filter)
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
printf ("filter mode does not support gzipped files\n");
|
||||
printf ("use: gunzip -c file.fits | dfits -\n");
|
||||
|
@ -80,17 +83,18 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Normal mode: loop on all file names given on command-line */
|
||||
err = 0;
|
||||
while (c_arg < argc) {
|
||||
while (c_arg < argc)
|
||||
{
|
||||
err += dump_fits (argv[c_arg], xtnum);
|
||||
c_arg++;
|
||||
}
|
||||
return err; /* Returns number of errors during process */
|
||||
}
|
||||
|
||||
void usage(char * pname)
|
||||
void
|
||||
usage (char *pname)
|
||||
{
|
||||
printf(
|
||||
"\n\n"
|
||||
printf ("\n\n"
|
||||
"usage: %s [-x xtnum] <list of FITS files>\n"
|
||||
"usage: %s [-x xtnum] -\n"
|
||||
"\n"
|
||||
|
@ -99,12 +103,10 @@ void usage(char * pname)
|
|||
"\n"
|
||||
"-x xtnum specifies the extension header to print\n"
|
||||
"-x 0 specifies main header + all extensions\n"
|
||||
"\n\n",
|
||||
pname, pname);
|
||||
"\n\n", pname, pname);
|
||||
|
||||
#if HAVE_ZLIB
|
||||
printf(
|
||||
"This program was compiled against zlib %s\n"
|
||||
printf ("This program was compiled against zlib %s\n"
|
||||
"This means you can use it with gzipped FITS files\n"
|
||||
"as with uncompressed FITS files.\n"
|
||||
"NB: this does not apply to the '-' option (input from stdin)\n"
|
||||
|
@ -113,52 +115,59 @@ void usage(char * pname)
|
|||
exit (1);
|
||||
}
|
||||
|
||||
void parse_cmd_line(
|
||||
int argc,
|
||||
char ** argv,
|
||||
int * xtnum,
|
||||
int * filter,
|
||||
int * c_arg)
|
||||
void
|
||||
parse_cmd_line (int argc, char **argv, int *xtnum, int *filter, int *c_arg)
|
||||
{
|
||||
*filter = 0;
|
||||
*xtnum = -1;
|
||||
*c_arg = argc - 1;
|
||||
|
||||
/* If '-' is on the command-line, it must be the last argument */
|
||||
if (!strcmp(argv[argc-1], "-")) *filter = 1 ;
|
||||
if (!strcmp (argv[argc - 1], "-"))
|
||||
*filter = 1;
|
||||
/* If -x xtnum is on the command-line, it must be the first two arguments */
|
||||
if (!strcmp(argv[1], "-x")) {
|
||||
if (!strcmp (argv[1], "-x"))
|
||||
{
|
||||
*xtnum = atoi (argv[2]);
|
||||
*c_arg = 3;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
*c_arg = 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Strip off all blank characters in a string from the right-side. */
|
||||
char * rstrip(char * s)
|
||||
char *
|
||||
rstrip (char *s)
|
||||
{
|
||||
int len;
|
||||
if (s==NULL) return s ;
|
||||
if (s == NULL)
|
||||
return s;
|
||||
len = strlen (s);
|
||||
if (len<1) return s ;
|
||||
if (len < 1)
|
||||
return s;
|
||||
len--;
|
||||
while (s[len]== ' ') {
|
||||
while (s[len] == ' ')
|
||||
{
|
||||
s[len] = (char) 0;
|
||||
len--;
|
||||
if (len<0) break ;
|
||||
if (len < 0)
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
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;
|
||||
}
|
||||
|
@ -170,7 +179,8 @@ int dump_fits(char * name, int xtnum)
|
|||
}
|
||||
|
||||
/* 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;
|
||||
char buf[LGTH + 1];
|
||||
|
@ -182,138 +192,160 @@ int dump_fits_filter(FILE * in, int xtnum)
|
|||
|
||||
/* Try getting the first 80 chars */
|
||||
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;
|
||||
}
|
||||
/* Check that it is indeed FITS */
|
||||
if (strncmp(buf, MAGIC, strlen(MAGIC))) {
|
||||
if (strncmp (buf, MAGIC, strlen (MAGIC)))
|
||||
{
|
||||
fprintf (stderr, "not a FITS file\n");
|
||||
return 1;
|
||||
}
|
||||
naxis = 0;
|
||||
data_bytes = 1;
|
||||
if (xtnum<1) {
|
||||
if (xtnum < 1)
|
||||
{
|
||||
/* Output main header */
|
||||
printf ("%s\n", rstrip (buf));
|
||||
data_bytes = 1;
|
||||
naxis = 0;
|
||||
while ((err=fread(buf, sizeof(char), LGTH, in))==LGTH) {
|
||||
while ((err = fread (buf, sizeof (char), LGTH, in)) == LGTH)
|
||||
{
|
||||
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]==' ') {
|
||||
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
|
||||
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') {
|
||||
buf[2] == 'X' && buf[3] == 'I' && buf[4] == 'S')
|
||||
{
|
||||
|
||||
if (buf[5]==' ') {
|
||||
if (buf[5] == ' ')
|
||||
{
|
||||
/* NAXIS keyword */
|
||||
read_val = qfits_getvalue (buf);
|
||||
naxis = (int) atoi (read_val);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* NAXIS?? keyword (axis size) */
|
||||
read_val = qfits_getvalue (buf);
|
||||
data_bytes *= (int) atoi (read_val);
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
/* Look for END keyword */
|
||||
if (buf[0]=='E' &&
|
||||
buf[1]=='N' &&
|
||||
buf[2]=='D') {
|
||||
if (buf[0] == 'E' && buf[1] == 'N' && buf[2] == 'D')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (err!=LGTH) return 1 ;
|
||||
if (err != LGTH)
|
||||
return 1;
|
||||
}
|
||||
if (xtnum<0) return 0 ;
|
||||
if (xtnum < 0)
|
||||
return 0;
|
||||
|
||||
n_xt = 0;
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
/*
|
||||
* Skip the previous data section if pixels were declared
|
||||
*/
|
||||
if (naxis>0) {
|
||||
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 ++ ;
|
||||
if ((data_bytes % BLOCK_SIZE) != 0)
|
||||
skip_blocks++;
|
||||
seeked = fseek (in, skip_blocks * BLOCK_SIZE, SEEK_CUR);
|
||||
if (seeked<0) return -1 ;
|
||||
if (seeked < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Look for next XTENSION keyword */
|
||||
while ((err=fread(buf, sizeof(char), LGTH, in))==LGTH) {
|
||||
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 ;
|
||||
buf[5] == 'I' && buf[6] == 'O' && buf[7] == 'N')
|
||||
break;
|
||||
}
|
||||
if (err==0) break ;
|
||||
if (err!=LGTH) return 1 ;
|
||||
if (err == 0)
|
||||
break;
|
||||
if (err != LGTH)
|
||||
return 1;
|
||||
|
||||
n_xt++;
|
||||
|
||||
if (xtnum==0 || xtnum==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));
|
||||
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]==' ') {
|
||||
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
|
||||
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') {
|
||||
buf[2] == 'X' && buf[3] == 'I' && buf[4] == 'S')
|
||||
{
|
||||
|
||||
if (buf[5]==' ') {
|
||||
if (buf[5] == ' ')
|
||||
{
|
||||
/* NAXIS keyword */
|
||||
read_val = qfits_getvalue (buf);
|
||||
naxis = (int) atoi (read_val);
|
||||
} else {
|
||||
}
|
||||
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 ;
|
||||
else
|
||||
/* Look for END keyword */
|
||||
if (buf[0] == 'E' && buf[1] == 'N' && buf[2] == 'D')
|
||||
break;
|
||||
}
|
||||
if (n_xt == xtnum)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,8 @@ static char prog_desc[] = "FITS table dump" ;
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char name_i[FILENAMESZ];
|
||||
char name_o[FILENAMESZ];
|
||||
|
@ -65,16 +66,23 @@ int main(int argc, char *argv[])
|
|||
|
||||
i = 1;
|
||||
|
||||
if (argc<2) usage(argv[0]);
|
||||
|
||||
while (i<argc) {
|
||||
if (!strcmp(argv[i], "--help") ||
|
||||
!strcmp(argv[i], "-h")) {
|
||||
if (argc < 2)
|
||||
usage (argv[0]);
|
||||
} else if (!strcmp(argv[i], "-d")) {
|
||||
|
||||
while (i < argc)
|
||||
{
|
||||
if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-h"))
|
||||
{
|
||||
usage (argv[0]);
|
||||
}
|
||||
else if (!strcmp (argv[i], "-d"))
|
||||
{
|
||||
data_only = 1;
|
||||
} else if (!strcmp(argv[i], "-s")) {
|
||||
if ((i+1)>=argc) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-s"))
|
||||
{
|
||||
if ((i + 1) >= argc)
|
||||
{
|
||||
fprintf (stderr, "option -s needs an argument\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -82,50 +90,53 @@ int main(int argc, char *argv[])
|
|||
separator = argv[i][0];
|
||||
|
||||
|
||||
} else if (!strcmp(argv[i], "-x")) {
|
||||
if ((i+1)>=argc) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-x"))
|
||||
{
|
||||
if ((i + 1) >= argc)
|
||||
{
|
||||
fprintf (stderr, "option -x needs an argument\n");
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
ext = atoi (argv[i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if ((argc-i)<1) {
|
||||
if ((argc - i) < 1)
|
||||
{
|
||||
fprintf (stderr, "missing input file name\n");
|
||||
return -1;
|
||||
}
|
||||
strcpy (name_i, argv[i]);
|
||||
i++;
|
||||
if ((argc-i)<1) name_o[0] = 0 ;
|
||||
else strcpy(name_o, argv[i]);
|
||||
if ((argc - i) < 1)
|
||||
name_o[0] = 0;
|
||||
else
|
||||
strcpy (name_o, argv[i]);
|
||||
|
||||
qfits_dump (name_i, name_o, data_only, separator, ext);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(char * pname)
|
||||
static void
|
||||
usage (char *pname)
|
||||
{
|
||||
printf ("%s -- %s\n", pname, prog_desc);
|
||||
printf(
|
||||
"use : %s [options] <FITS table> [out]\n"
|
||||
printf ("use : %s [options] <FITS table> [out]\n"
|
||||
"options are:\n"
|
||||
"\t-d to dump data only (no headers)\n"
|
||||
"\t-s <char> to output data with separator <char>\n"
|
||||
"\n",
|
||||
pname);
|
||||
"\t-s <char> to output data with separator <char>\n" "\n", pname);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
static void qfits_dump(
|
||||
char * name_i,
|
||||
char * name_o,
|
||||
int data_only,
|
||||
char separator,
|
||||
int ext)
|
||||
static void
|
||||
qfits_dump (char *name_i,
|
||||
char *name_o, int data_only, char separator, int ext)
|
||||
{
|
||||
qfits_table *tdesc;
|
||||
FILE *out;
|
||||
|
@ -134,52 +145,70 @@ static void qfits_dump(
|
|||
int i;
|
||||
|
||||
/* Set where to send the output */
|
||||
if (name_o[0]==(char)0) {
|
||||
if (name_o[0] == (char) 0)
|
||||
{
|
||||
out = stdout;
|
||||
} else {
|
||||
if ((out = fopen(name_o, "w"))==NULL) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((out = fopen (name_o, "w")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "cannot create output file [%s]\n", name_o);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data_only) {
|
||||
if (!data_only)
|
||||
{
|
||||
fprintf (out, "#\n");
|
||||
fprintf (out, "# file %s\n", name_i);
|
||||
}
|
||||
|
||||
/* Query number of extensions in the file */
|
||||
n_ext = qfits_query_n_ext (name_i);
|
||||
if (!data_only) {
|
||||
if (!data_only)
|
||||
{
|
||||
fprintf (out, "# extensions %d\n", n_ext);
|
||||
}
|
||||
/* If no extension, bail out */
|
||||
if (n_ext<1) {
|
||||
if (out!=stdout) fclose(out) ;
|
||||
if (n_ext < 1)
|
||||
{
|
||||
if (out != stdout)
|
||||
fclose (out);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 1 extension required or all */
|
||||
if (ext < 1) {
|
||||
if (ext < 1)
|
||||
{
|
||||
xtnum_start = 1;
|
||||
xtnum_stop = n_ext;
|
||||
} else if (ext > n_ext) {
|
||||
}
|
||||
else if (ext > n_ext)
|
||||
{
|
||||
fprintf (out, "# requested extension does not exist %d\n", ext);
|
||||
if (out!=stdout) fclose(out) ;
|
||||
if (out != stdout)
|
||||
fclose (out);
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
xtnum_start = xtnum_stop = ext;
|
||||
}
|
||||
|
||||
/* Loop over all extensions */
|
||||
for (i=xtnum_start ; i<=xtnum_stop ; i++) {
|
||||
if (!data_only) {
|
||||
for (i = xtnum_start; i <= xtnum_stop; i++)
|
||||
{
|
||||
if (!data_only)
|
||||
{
|
||||
fprintf (out, "# --------------------------------------------\n");
|
||||
fprintf (out, "# XTENSION %d\n", i);
|
||||
}
|
||||
if ((tdesc = qfits_table_open(name_i, i)) == NULL) {
|
||||
if ((tdesc = qfits_table_open (name_i, i)) == NULL)
|
||||
{
|
||||
printf ("cannot open table [%s]:[%d]\n", name_i, i);
|
||||
if (out!=stdout) fclose(out);
|
||||
if (out != stdout)
|
||||
fclose (out);
|
||||
return;
|
||||
}
|
||||
dump_extension (tdesc, out, separator, data_only, 1);
|
||||
|
@ -189,31 +218,32 @@ static void qfits_dump(
|
|||
return;
|
||||
}
|
||||
|
||||
static int dump_extension(
|
||||
qfits_table * tdesc,
|
||||
FILE * out,
|
||||
char separator,
|
||||
int data_only,
|
||||
int use_zero_scale)
|
||||
static int
|
||||
dump_extension (qfits_table * tdesc,
|
||||
FILE * out, char separator, int data_only, int use_zero_scale)
|
||||
{
|
||||
void **cols;
|
||||
int i, j;
|
||||
|
||||
if (!data_only) {
|
||||
if (!data_only)
|
||||
{
|
||||
fprintf (out, "# Number of columns %d\n", tdesc->nc);
|
||||
fprintf (out, "#\n");
|
||||
}
|
||||
|
||||
/* First read the columns in memory */
|
||||
cols = malloc (tdesc->nc * sizeof (void *));
|
||||
for (i=0 ; i<tdesc->nc ; i++) {
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
{
|
||||
cols[i] = qfits_query_column_data (tdesc, i, NULL, NULL);
|
||||
if (cols[i] == NULL) {
|
||||
if (cols[i] == NULL)
|
||||
{
|
||||
fprintf (out, "# Cannot load column nb %d\n", i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
switch (tdesc->tab_t) {
|
||||
switch (tdesc->tab_t)
|
||||
{
|
||||
case QFITS_BINTABLE:
|
||||
dump_extension_bin (tdesc, out, cols, separator, data_only,
|
||||
use_zero_scale);
|
||||
|
@ -227,18 +257,18 @@ static int dump_extension(
|
|||
break;
|
||||
}
|
||||
|
||||
for (i=0 ; i<tdesc->nc ; i++) if (cols[i]) free(cols[i]) ;
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
if (cols[i])
|
||||
free (cols[i]);
|
||||
free (cols);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dump_extension_bin(
|
||||
qfits_table * tdesc,
|
||||
static int
|
||||
dump_extension_bin (qfits_table * tdesc,
|
||||
FILE * out,
|
||||
void **cols,
|
||||
char separator,
|
||||
int data_only,
|
||||
int use_zero_scale)
|
||||
char separator, int data_only, int use_zero_scale)
|
||||
{
|
||||
int *col_sizes;
|
||||
qfits_col *col;
|
||||
|
@ -256,10 +286,12 @@ static int dump_extension_bin(
|
|||
|
||||
/* GET THE FIELDS SIZES */
|
||||
col_sizes = calloc (tdesc->nc, sizeof (int));
|
||||
for (i=0 ; i<tdesc->nc ; i++) {
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
{
|
||||
col = tdesc->col + i;
|
||||
col_sizes[i] = (int) strlen (col->tlabel);
|
||||
switch(col->atom_type) {
|
||||
switch (col->atom_type)
|
||||
{
|
||||
case TFITS_BIN_TYPE_A:
|
||||
size = col->atom_size * col->atom_nb;
|
||||
break;
|
||||
|
@ -293,28 +325,36 @@ static int dump_extension_bin(
|
|||
fprintf (out, "Type not recognized");
|
||||
break;
|
||||
}
|
||||
if (size > col_sizes[i]) col_sizes[i] = size ;
|
||||
if (size > col_sizes[i])
|
||||
col_sizes[i] = size;
|
||||
}
|
||||
|
||||
/* Print out the column names */
|
||||
if (!data_only) {
|
||||
for (i=0 ; i<tdesc->nc ; i++) {
|
||||
if (!data_only)
|
||||
{
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
{
|
||||
col = tdesc->col + i;
|
||||
fprintf (out, "%*s", col_sizes[i], col->tlabel);
|
||||
if (i!=(tdesc->nc-1)) printf("%c", separator);
|
||||
if (i != (tdesc->nc - 1))
|
||||
printf ("%c", separator);
|
||||
}
|
||||
fprintf (out, "\n");
|
||||
}
|
||||
|
||||
/* Get the string to write according to the type */
|
||||
for (j=0 ; j<tdesc->nr ; j++) {
|
||||
for (i=0 ; i<tdesc->nc ; i++) {
|
||||
if (cols[i] == NULL) continue ;
|
||||
for (j = 0; j < tdesc->nr; j++)
|
||||
{
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
{
|
||||
if (cols[i] == NULL)
|
||||
continue;
|
||||
col = tdesc->col + i;
|
||||
field_size = col->atom_nb * ELEMENT_MAX_DISP_SIZE;
|
||||
str = malloc (field_size * sizeof (char));
|
||||
str[0] = (char) 0;
|
||||
switch(col->atom_type) {
|
||||
switch (col->atom_type)
|
||||
{
|
||||
case TFITS_BIN_TYPE_A:
|
||||
ccol = (char *) (cols[i]);
|
||||
ccol += col->atom_size * col->atom_nb * j;
|
||||
|
@ -326,7 +366,8 @@ static int dump_extension_bin(
|
|||
ucol = (unsigned char *) (cols[i]);
|
||||
ucol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%d, ", (int) ucol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -339,7 +380,8 @@ static int dump_extension_bin(
|
|||
dcol = (double *) (cols[i]);
|
||||
dcol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%g, ", dcol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -352,7 +394,8 @@ static int dump_extension_bin(
|
|||
fcol = (float *) (cols[i]);
|
||||
fcol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%f, ", fcol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -364,7 +407,8 @@ static int dump_extension_bin(
|
|||
scol = (short *) (cols[i]);
|
||||
scol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%d, ", scol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -376,7 +420,8 @@ static int dump_extension_bin(
|
|||
icol = (int *) (cols[i]);
|
||||
icol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%d, ", icol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -388,7 +433,8 @@ static int dump_extension_bin(
|
|||
ccol = (char *) (cols[i]);
|
||||
ccol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%c, ", ccol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -400,7 +446,8 @@ static int dump_extension_bin(
|
|||
ucol = (unsigned char *) (cols[i]);
|
||||
ucol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%d, ", ucol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -412,7 +459,8 @@ static int dump_extension_bin(
|
|||
icol = (int *) (cols[i]);
|
||||
icol += col->atom_nb * j;
|
||||
/* For each atom of the column */
|
||||
for (k=0 ; k<col->atom_nb-1 ; k++) {
|
||||
for (k = 0; k < col->atom_nb - 1; k++)
|
||||
{
|
||||
sprintf (ctmp, "%d, ", icol[k]);
|
||||
strcat (str, ctmp);
|
||||
}
|
||||
|
@ -425,7 +473,8 @@ static int dump_extension_bin(
|
|||
break;
|
||||
}
|
||||
fprintf (out, "%*s", col_sizes[i], str);
|
||||
if (i!=(tdesc->nc-1)) printf("%c", separator);
|
||||
if (i != (tdesc->nc - 1))
|
||||
printf ("%c", separator);
|
||||
free (str);
|
||||
}
|
||||
fprintf (out, "\n");
|
||||
|
@ -433,13 +482,11 @@ static int dump_extension_bin(
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dump_extension_ascii(
|
||||
qfits_table * tdesc,
|
||||
static int
|
||||
dump_extension_ascii (qfits_table * tdesc,
|
||||
FILE * out,
|
||||
void **cols,
|
||||
char separator,
|
||||
int data_only,
|
||||
int use_zero_scale)
|
||||
char separator, int data_only, int use_zero_scale)
|
||||
{
|
||||
int *col_sizes;
|
||||
qfits_col *col;
|
||||
|
@ -455,10 +502,12 @@ static int dump_extension_ascii(
|
|||
|
||||
/* GET THE FIELDS SIZES */
|
||||
col_sizes = calloc (tdesc->nc, sizeof (int));
|
||||
for (i=0 ; i<tdesc->nc ; i++) {
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
{
|
||||
col = tdesc->col + i;
|
||||
col_sizes[i] = (int) strlen (col->tlabel);
|
||||
switch(col->atom_type) {
|
||||
switch (col->atom_type)
|
||||
{
|
||||
case TFITS_ASCII_TYPE_A:
|
||||
size = col->atom_nb;
|
||||
break;
|
||||
|
@ -476,28 +525,36 @@ static int dump_extension_ascii(
|
|||
fprintf (out, "Type not recognized");
|
||||
break;
|
||||
}
|
||||
if (size > col_sizes[i]) col_sizes[i] = size ;
|
||||
if (size > col_sizes[i])
|
||||
col_sizes[i] = size;
|
||||
}
|
||||
|
||||
/* Print out the column names */
|
||||
if (!data_only) {
|
||||
for (i=0 ; i<tdesc->nc ; i++) {
|
||||
if (!data_only)
|
||||
{
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
{
|
||||
col = tdesc->col + i;
|
||||
fprintf (out, "%*s", col_sizes[i], col->tlabel);
|
||||
if (i!=(tdesc->nc-1)) printf("%c", separator);
|
||||
if (i != (tdesc->nc - 1))
|
||||
printf ("%c", separator);
|
||||
}
|
||||
fprintf (out, "\n");
|
||||
}
|
||||
|
||||
/* Get the string to write according to the type */
|
||||
for (j=0 ; j<tdesc->nr ; j++) {
|
||||
for (i=0 ; i<tdesc->nc ; i++) {
|
||||
if (cols[i] == NULL) continue ;
|
||||
for (j = 0; j < tdesc->nr; j++)
|
||||
{
|
||||
for (i = 0; i < tdesc->nc; i++)
|
||||
{
|
||||
if (cols[i] == NULL)
|
||||
continue;
|
||||
col = tdesc->col + i;
|
||||
field_size = col->atom_nb * ELEMENT_MAX_DISP_SIZE;
|
||||
str = malloc (field_size * sizeof (char));
|
||||
str[0] = (char) 0;
|
||||
switch(col->atom_type) {
|
||||
switch (col->atom_type)
|
||||
{
|
||||
case TFITS_ASCII_TYPE_A:
|
||||
ccol = (char *) (cols[i]);
|
||||
ccol += col->atom_nb * j;
|
||||
|
@ -529,7 +586,8 @@ static int dump_extension_ascii(
|
|||
break;
|
||||
}
|
||||
fprintf (out, "%*s", col_sizes[i], str);
|
||||
if (i!=(tdesc->nc-1)) printf("%c", separator);
|
||||
if (i != (tdesc->nc - 1))
|
||||
printf ("%c", separator);
|
||||
free (str);
|
||||
}
|
||||
fprintf (out, "\n");
|
||||
|
@ -538,5 +596,3 @@ static int dump_extension_ascii(
|
|||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,12 +37,14 @@
|
|||
* Swap pixels between position p1 and p2, regardless of the pixel
|
||||
* 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;
|
||||
char c;
|
||||
|
||||
for (i=0 ; i<psize ; i++) {
|
||||
for (i = 0; i < psize; i++)
|
||||
{
|
||||
c = buf[p1 + i];
|
||||
buf[p1 + i] = buf[p2 + i];
|
||||
buf[p2 + i] = c;
|
||||
|
@ -53,7 +55,8 @@ static void swap_pix(char * buf, int p1, int p2, int psize)
|
|||
* Main processing function. It expects one only file name
|
||||
* 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;
|
||||
int dstart;
|
||||
|
@ -68,61 +71,68 @@ static int fits_flip(char * pname, char * filename)
|
|||
|
||||
printf ("%s: processing %s\n", pname, filename);
|
||||
|
||||
if (stat(filename, &fileinfo)!=0) {
|
||||
if (stat (filename, &fileinfo) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (fileinfo.st_size<1) {
|
||||
if (fileinfo.st_size < 1)
|
||||
{
|
||||
printf ("cannot stat file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Retrieve image attributes */
|
||||
if (is_fits_file(filename)!=1) {
|
||||
if (is_fits_file (filename) != 1)
|
||||
{
|
||||
printf ("not a FITS file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sval = qfits_query_hdr (filename, "NAXIS1");
|
||||
if (sval==NULL) {
|
||||
if (sval == NULL)
|
||||
{
|
||||
printf ("cannot read NAXIS1\n");
|
||||
return -1;
|
||||
}
|
||||
lx = atoi (sval);
|
||||
sval = qfits_query_hdr (filename, "NAXIS2");
|
||||
if (sval==NULL) {
|
||||
if (sval == NULL)
|
||||
{
|
||||
printf ("cannot read NAXIS2\n");
|
||||
return -1;
|
||||
}
|
||||
ly = atoi (sval);
|
||||
sval = qfits_query_hdr (filename, "BITPIX");
|
||||
if (sval==NULL) {
|
||||
if (sval == NULL)
|
||||
{
|
||||
printf ("cannot read BITPIX\n");
|
||||
return -1;
|
||||
}
|
||||
bpp = atoi (sval);
|
||||
|
||||
psize = bpp / 8;
|
||||
if (psize<0) psize=-psize ;
|
||||
if (psize < 0)
|
||||
psize = -psize;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* 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");
|
||||
return -1;
|
||||
}
|
||||
fbuf = (char *) mmap (0,
|
||||
fileinfo.st_size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
fd,
|
||||
0);
|
||||
if (fbuf==(char*)-1) {
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (fbuf == (char *) -1)
|
||||
{
|
||||
perror ("mmap");
|
||||
printf ("mapping file\n");
|
||||
return -1;
|
||||
|
@ -130,14 +140,17 @@ static int fits_flip(char * pname, char * filename)
|
|||
buf = fbuf + dstart;
|
||||
|
||||
/* Double loop */
|
||||
for (j=0 ; j<ly ; j++) {
|
||||
for (i=0 ; i<lx/2 ; i++) {
|
||||
for (j = 0; j < ly; j++)
|
||||
{
|
||||
for (i = 0; i < lx / 2; i++)
|
||||
{
|
||||
/* Swap bytes */
|
||||
swap_pix (buf, i * psize, (lx - i - 1) * psize, psize);
|
||||
}
|
||||
buf += lx * psize;
|
||||
}
|
||||
if (munmap(fbuf, fileinfo.st_size)!=0) {
|
||||
if (munmap (fbuf, fileinfo.st_size) != 0)
|
||||
{
|
||||
printf ("unmapping file\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -147,20 +160,24 @@ static int fits_flip(char * pname, char * filename)
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char * argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int err;
|
||||
|
||||
if (argc<2) {
|
||||
if (argc < 2)
|
||||
{
|
||||
printf ("use: %s <list of FITS files...>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
err = 0;
|
||||
for (i=1 ; i<argc ; i++) {
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
err += fits_flip (argv[0], argv[i]);
|
||||
}
|
||||
if (err>0) {
|
||||
if (err > 0)
|
||||
{
|
||||
fprintf (stderr, "%s: %d error(s) occurred\n", argv[0], err);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
-----------------------------------------------------------------------------*/
|
||||
|
||||
/* Frame informations needed to classify it */
|
||||
typedef struct _framei {
|
||||
typedef struct _framei
|
||||
{
|
||||
char *name;
|
||||
char *tplid;
|
||||
char *origfile;
|
||||
|
@ -44,7 +45,8 @@ typedef struct _framei {
|
|||
} framei;
|
||||
|
||||
/* Frame queue: is mostly a pointer to a list of frame information objects */
|
||||
typedef struct _frameq {
|
||||
typedef struct _frameq
|
||||
{
|
||||
framei *first;
|
||||
int n;
|
||||
} frameq;
|
||||
|
@ -71,7 +73,8 @@ char * tpl_filter[] = {
|
|||
@return A newly allocated framei obj. NULL in error case
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static framei * framei_new(char * filename)
|
||||
static framei *
|
||||
framei_new (char *filename)
|
||||
{
|
||||
framei *fi;
|
||||
char *sval;
|
||||
|
@ -81,30 +84,42 @@ static framei * framei_new(char * filename)
|
|||
fi = malloc (sizeof (framei));
|
||||
fi->name = strdup (filename);
|
||||
sval = qfits_query_hdr (filename, "tpl.id");
|
||||
if (sval!=NULL) {
|
||||
if (sval != NULL)
|
||||
{
|
||||
/* Filter out unwanted template IDs */
|
||||
i = 0;
|
||||
while (tpl_filter[i]!=NULL) {
|
||||
if (strstr(sval, tpl_filter[i])!=NULL) return NULL ;
|
||||
while (tpl_filter[i] != NULL)
|
||||
{
|
||||
if (strstr (sval, tpl_filter[i]) != NULL)
|
||||
return NULL;
|
||||
i++;
|
||||
}
|
||||
fi->tplid = strdup (qfits_pretty_string (sval));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fi->tplid = NULL;
|
||||
}
|
||||
sval = qfits_query_hdr (filename, "origfile");
|
||||
if (sval!=NULL) {
|
||||
if (sval != NULL)
|
||||
{
|
||||
sval2 = qfits_pretty_string (sval);
|
||||
fi->origfile = strdup (qfits_get_root_name (sval2));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fi->origfile = NULL;
|
||||
}
|
||||
sval = qfits_query_hdr (filename, "tpl.expno");
|
||||
if (sval!=NULL) fi->expno = (int)atoi(sval);
|
||||
else fi->expno = -1 ;
|
||||
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 ;
|
||||
if (sval != NULL)
|
||||
fi->nexp = (int) atoi (sval);
|
||||
else
|
||||
fi->nexp = -1;
|
||||
|
||||
fi->next = NULL;
|
||||
return fi;
|
||||
|
@ -116,15 +131,19 @@ static framei * framei_new(char * filename)
|
|||
@param fi Object to delete
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void framei_del(framei * fi)
|
||||
static void
|
||||
framei_del (framei * fi)
|
||||
{
|
||||
if (fi==NULL) return ;
|
||||
if (fi == NULL)
|
||||
return;
|
||||
if (fi->name != NULL)
|
||||
free (fi->name);
|
||||
if (fi->tplid!=NULL) {
|
||||
if (fi->tplid != NULL)
|
||||
{
|
||||
free (fi->tplid);
|
||||
}
|
||||
if (fi->origfile!=NULL) {
|
||||
if (fi->origfile != NULL)
|
||||
{
|
||||
free (fi->origfile);
|
||||
}
|
||||
free (fi);
|
||||
|
@ -136,7 +155,8 @@ static void framei_del(framei * fi)
|
|||
@return A newly allocated empty frameq object
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
frameq * frameq_new(void)
|
||||
frameq *
|
||||
frameq_new (void)
|
||||
{
|
||||
frameq *fq;
|
||||
|
||||
|
@ -152,15 +172,18 @@ frameq * frameq_new(void)
|
|||
@param fq The object to delete
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void frameq_del(frameq * fq)
|
||||
void
|
||||
frameq_del (frameq * fq)
|
||||
{
|
||||
framei *fi;
|
||||
framei *fin;
|
||||
|
||||
if (fq==NULL) return ;
|
||||
if (fq == NULL)
|
||||
return;
|
||||
|
||||
fi = fq->first;
|
||||
while (fi!=NULL) {
|
||||
while (fi != NULL)
|
||||
{
|
||||
fin = fi->next;
|
||||
framei_del (fi);
|
||||
fi = fin;
|
||||
|
@ -176,16 +199,19 @@ void frameq_del(frameq * fq)
|
|||
@param filename The file to append name
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void frameq_append(frameq * fq, char * filename)
|
||||
void
|
||||
frameq_append (frameq * fq, char *filename)
|
||||
{
|
||||
framei *fi;
|
||||
framei *fn;
|
||||
|
||||
if (fq==NULL || filename==NULL) return ;
|
||||
if (fq == NULL || filename == NULL)
|
||||
return;
|
||||
fi = framei_new (filename);
|
||||
if (fi == NULL)
|
||||
return;
|
||||
if (fq->n==0) {
|
||||
if (fq->n == 0)
|
||||
{
|
||||
fq->first = fi;
|
||||
fq->n = 1;
|
||||
return;
|
||||
|
@ -206,7 +232,8 @@ void frameq_append(frameq * fq, char * filename)
|
|||
@param fq The frame queue
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void frameq_pop(frameq * fq)
|
||||
void
|
||||
frameq_pop (frameq * fq)
|
||||
{
|
||||
framei *first;
|
||||
|
||||
|
@ -223,19 +250,17 @@ void frameq_pop(frameq * fq)
|
|||
@param out File where the queue is dumped
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void frameq_dump(frameq * fq, FILE * out)
|
||||
void
|
||||
frameq_dump (frameq * fq, FILE * out)
|
||||
{
|
||||
int i;
|
||||
framei *fi;
|
||||
|
||||
fi = fq->first;
|
||||
for (i=0 ; i<fq->n ; i++) {
|
||||
for (i = 0; i < fq->n; i++)
|
||||
{
|
||||
fprintf (out,
|
||||
"%s %s %02d/%02d\n",
|
||||
fi->name,
|
||||
fi->tplid,
|
||||
fi->expno,
|
||||
fi->nexp);
|
||||
"%s %s %02d/%02d\n", fi->name, fi->tplid, fi->expno, fi->nexp);
|
||||
fi = fi->next;
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +272,8 @@ void frameq_dump(frameq * fq, FILE * out)
|
|||
@return A newly allocated frame queue
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
frameq * frameq_load(char * dirname)
|
||||
frameq *
|
||||
frameq_load (char *dirname)
|
||||
{
|
||||
frameq *fq;
|
||||
int i;
|
||||
|
@ -263,14 +289,16 @@ frameq * frameq_load(char * dirname)
|
|||
glob (filename, GLOB_APPEND, NULL, &pglob);
|
||||
sprintf (filename, "%s/*.FITS.gz", dirname);
|
||||
glob (filename, GLOB_APPEND, NULL, &pglob);
|
||||
if (pglob.gl_pathc<1) {
|
||||
if (pglob.gl_pathc < 1)
|
||||
{
|
||||
printf ("found no frame\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Build frame queue */
|
||||
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);
|
||||
frameq_append (fq, pglob.gl_pathv[i]);
|
||||
|
@ -280,7 +308,8 @@ frameq * frameq_load(char * dirname)
|
|||
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);
|
||||
}
|
||||
|
@ -293,7 +322,8 @@ static int stringsort(const void * e1, const void * e2)
|
|||
@return List of n strings
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char ** frameq_get_tplid(frameq * fq, int * n)
|
||||
char **
|
||||
frameq_get_tplid (frameq * fq, int *n)
|
||||
{
|
||||
framei *fn;
|
||||
char **tplid_all;
|
||||
|
@ -304,10 +334,14 @@ char ** frameq_get_tplid(frameq * fq, int * n)
|
|||
/* Get all possible values for tplid */
|
||||
tplid_all = malloc (fq->n * sizeof (char *));
|
||||
fn = fq->first;
|
||||
for (i=0 ; i<fq->n ; i++) {
|
||||
if (fn->tplid==NULL) {
|
||||
for (i = 0; i < fq->n; i++)
|
||||
{
|
||||
if (fn->tplid == NULL)
|
||||
{
|
||||
tplid_all[i] = strdup ("none");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
tplid_all[i] = strdup (fn->tplid);
|
||||
}
|
||||
fn = fn->next;
|
||||
|
@ -317,8 +351,10 @@ char ** frameq_get_tplid(frameq * fq, int * n)
|
|||
|
||||
/* Compute how many different tplid's can be found */
|
||||
ntplid = 1;
|
||||
for (i=1 ; i<fq->n ; i++) {
|
||||
if (strcmp(tplid_all[i], tplid_all[i-1])) {
|
||||
for (i = 1; i < fq->n; i++)
|
||||
{
|
||||
if (strcmp (tplid_all[i], tplid_all[i - 1]))
|
||||
{
|
||||
ntplid++;
|
||||
}
|
||||
}
|
||||
|
@ -327,11 +363,15 @@ char ** frameq_get_tplid(frameq * fq, int * n)
|
|||
tplid[0] = tplid_all[0];
|
||||
tplid_all[0] = NULL;
|
||||
j = 0;
|
||||
for (i=1 ; i<fq->n ; i++) {
|
||||
if (strcmp(tplid_all[i], tplid[j])) {
|
||||
for (i = 1; i < fq->n; i++)
|
||||
{
|
||||
if (strcmp (tplid_all[i], tplid[j]))
|
||||
{
|
||||
j++;
|
||||
tplid[j] = tplid_all[i];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
free (tplid_all[i]);
|
||||
}
|
||||
tplid_all[i] = NULL;
|
||||
|
@ -349,7 +389,8 @@ char ** frameq_get_tplid(frameq * fq, int * n)
|
|||
@return Setting number
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int frameq_getsetnum(char * dirname)
|
||||
int
|
||||
frameq_getsetnum (char *dirname)
|
||||
{
|
||||
char pattern[FILENAMESZ];
|
||||
glob_t pglob;
|
||||
|
@ -359,12 +400,16 @@ int frameq_getsetnum(char * dirname)
|
|||
|
||||
sprintf (pattern, "%s/set*", dirname);
|
||||
glob (pattern, GLOB_MARK, NULL, &pglob);
|
||||
if (pglob.gl_pathc<1) {
|
||||
if (pglob.gl_pathc < 1)
|
||||
{
|
||||
max = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (pattern, "%s/set%%02d", dirname);
|
||||
max = 0;
|
||||
for (i=0 ; i<pglob.gl_pathc ; i++) {
|
||||
for (i = 0; i < pglob.gl_pathc; i++)
|
||||
{
|
||||
sscanf (pglob.gl_pathv[i], pattern, &num);
|
||||
if (num > max)
|
||||
max = num;
|
||||
|
@ -380,7 +425,8 @@ int frameq_getsetnum(char * dirname)
|
|||
@param fq Frame queue
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void frameq_makelists(frameq * fq)
|
||||
void
|
||||
frameq_makelists (frameq * fq)
|
||||
{
|
||||
FILE *list;
|
||||
char filename[FILENAMESZ];
|
||||
|
@ -392,7 +438,8 @@ void frameq_makelists(frameq * fq)
|
|||
/* Count # of batches in input */
|
||||
fi = fq->first;
|
||||
batches = 0;
|
||||
while (fi!=NULL) {
|
||||
while (fi != NULL)
|
||||
{
|
||||
if (fi->expno == 1)
|
||||
batches++;
|
||||
fi = fi->next;
|
||||
|
@ -401,23 +448,29 @@ void frameq_makelists(frameq * fq)
|
|||
fi = fq->first;
|
||||
count = 0;
|
||||
list = NULL;
|
||||
while (fi!=NULL) {
|
||||
while (fi != NULL)
|
||||
{
|
||||
printf ("\rclassifying batches: %d of %d", count, batches);
|
||||
fflush (stdout);
|
||||
if (fi->expno<0) {
|
||||
if (fi->expno < 0)
|
||||
{
|
||||
fi = fi->next;
|
||||
continue;
|
||||
}
|
||||
if (fi->expno==1) {
|
||||
if (fi->expno == 1)
|
||||
{
|
||||
count++;
|
||||
if (list!=NULL) {
|
||||
if (list != NULL)
|
||||
{
|
||||
fclose (list);
|
||||
}
|
||||
if (fi->tplid == NULL) {
|
||||
if (fi->tplid == NULL)
|
||||
{
|
||||
printf ("No TPL ID - abort\n");
|
||||
return;
|
||||
}
|
||||
if (fi->origfile == NULL) {
|
||||
if (fi->origfile == NULL)
|
||||
{
|
||||
printf ("No ORIGFILE - abort\n");
|
||||
return;
|
||||
}
|
||||
|
@ -425,12 +478,14 @@ void frameq_makelists(frameq * fq)
|
|||
setnum = frameq_getsetnum (fi->tplid);
|
||||
sprintf (filename, "%s/%s_%02d", fi->tplid, fi->origfile, fi->nexp);
|
||||
mkdir (filename, 0755);
|
||||
sprintf(filename, "%s/%s_%02d/IN", fi->tplid,fi->origfile,fi->nexp);
|
||||
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);
|
||||
if (list)
|
||||
fprintf (list, "%s\n", fi->name);
|
||||
fi = fi->next;
|
||||
}
|
||||
printf ("\n");
|
||||
|
@ -440,11 +495,13 @@ void frameq_makelists(frameq * fq)
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char * argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
frameq *fq;
|
||||
|
||||
if (argc<2) {
|
||||
if (argc < 2)
|
||||
{
|
||||
printf ("use: %s <dirname>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
@ -458,4 +515,3 @@ int main(int argc, char * argv[])
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,21 +33,24 @@ static void usage(char *) ;
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *name_in;
|
||||
int ext;
|
||||
int nb_ext;
|
||||
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]);
|
||||
ext = (int) atoi (argv[2]);
|
||||
|
||||
/* Check if the file is a FITS file */
|
||||
if (!is_fits_file(name_in)) {
|
||||
if (!is_fits_file (name_in))
|
||||
{
|
||||
printf ("[%s] is not a FITS file\n", name_in);
|
||||
free (name_in);
|
||||
return -1;
|
||||
|
@ -55,7 +58,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Check if the extension is valid */
|
||||
nb_ext = qfits_query_n_ext (name_in);
|
||||
if (nb_ext < ext) {
|
||||
if (nb_ext < ext)
|
||||
{
|
||||
printf ("Only %d extensions in this file\n", nb_ext);
|
||||
free (name_in);
|
||||
return -1;
|
||||
|
@ -64,17 +68,20 @@ int main(int argc, char *argv[])
|
|||
/* Check if it's a table or an image */
|
||||
ext_type = qfits_is_table (name_in, ext);
|
||||
|
||||
switch (ext_type) {
|
||||
switch (ext_type)
|
||||
{
|
||||
case QFITS_BINTABLE:
|
||||
case QFITS_ASCIITABLE:
|
||||
if (textract_write_ext(name_in, ext) == -1) {
|
||||
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) {
|
||||
if (iextract_write_ext (name_in, ext) == -1)
|
||||
{
|
||||
printf ("cannot read-write extension no %d\n", ext);
|
||||
free (name_in);
|
||||
return -1;
|
||||
|
@ -94,18 +101,16 @@ int main(int argc, char *argv[])
|
|||
Functions code
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
static void usage(char * pname)
|
||||
static void
|
||||
usage (char *pname)
|
||||
{
|
||||
printf ("%s : %s\n", pname, prog_desc);
|
||||
printf(
|
||||
"use : %s <in> <extension>\n"
|
||||
"\n", pname) ;
|
||||
printf ("use : %s <in> <extension>\n" "\n", pname);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
static int textract_write_ext(
|
||||
char * in,
|
||||
int ext)
|
||||
static int
|
||||
textract_write_ext (char *in, int ext)
|
||||
{
|
||||
qfits_table *th;
|
||||
void **array;
|
||||
|
@ -114,15 +119,18 @@ static int textract_write_ext(
|
|||
int i;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Compute array_size */
|
||||
array_size = 0;
|
||||
for (i=0 ; i<th->nc ; i++) {
|
||||
switch (th->col[i].atom_type) {
|
||||
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:
|
||||
|
@ -162,9 +170,11 @@ static int textract_write_ext(
|
|||
array = malloc (array_size);
|
||||
|
||||
/* Load columns in array */
|
||||
for (i=0 ; i<th->nc ; i++) {
|
||||
for (i = 0; i < th->nc; i++)
|
||||
{
|
||||
array[i] = qfits_query_column_data (th, i, NULL, NULL);
|
||||
if (array[i] == NULL) {
|
||||
if (array[i] == NULL)
|
||||
{
|
||||
printf ("cannot read column %d\n", i + 1);
|
||||
}
|
||||
}
|
||||
|
@ -173,15 +183,19 @@ static int textract_write_ext(
|
|||
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]) ;
|
||||
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) {
|
||||
if (ext != 0)
|
||||
{
|
||||
/* No data in primary HDU */
|
||||
qfits_header_mod (fh, "NAXIS", "0", NULL);
|
||||
qfits_header_del (fh, "NAXIS1");
|
||||
|
@ -189,9 +203,12 @@ static int textract_write_ext(
|
|||
}
|
||||
|
||||
/* Write the tfits file */
|
||||
if (qfits_save_table_hdrdump((void **)array, th, fh) == -1) {
|
||||
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]) ;
|
||||
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");
|
||||
|
@ -200,15 +217,16 @@ static int textract_write_ext(
|
|||
|
||||
/* Free and return */
|
||||
qfits_header_destroy (fh);
|
||||
for (i=0 ; i<th->nc ; i++) if (array[i] != NULL) free(array[i]) ;
|
||||
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(
|
||||
char * in,
|
||||
int ext)
|
||||
static int
|
||||
iextract_write_ext (char *in, int ext)
|
||||
{
|
||||
qfitsloader ql;
|
||||
qfitsdumper qd;
|
||||
|
@ -224,12 +242,15 @@ static int iextract_write_ext(
|
|||
ql.pnum = 0;
|
||||
ql.map = 1;
|
||||
ql.ptype = PTYPE_DOUBLE;
|
||||
if (qfitsloader_init(&ql)!=0) return -1 ;
|
||||
if (qfitsloader_init (&ql) != 0)
|
||||
return -1;
|
||||
|
||||
/* Load the primary header */
|
||||
if ((fh = qfits_header_read(ql.filename)) == NULL) return -1 ;
|
||||
if ((fh = qfits_header_read (ql.filename)) == NULL)
|
||||
return -1;
|
||||
|
||||
if (ext != 0) {
|
||||
if (ext != 0)
|
||||
{
|
||||
/* No data in primary HDU */
|
||||
qfits_header_mod (fh, "NAXIS", "0", NULL);
|
||||
qfits_header_del (fh, "NAXIS1");
|
||||
|
@ -237,13 +258,16 @@ static int iextract_write_ext(
|
|||
}
|
||||
|
||||
/* Dump the primary header */
|
||||
if ((out = fopen(outname, "w")) == NULL) return -1 ;
|
||||
if ((out = fopen (outname, "w")) == NULL)
|
||||
return -1;
|
||||
qfits_header_dump (fh, out);
|
||||
qfits_header_destroy (fh);
|
||||
|
||||
if (ext != 0) {
|
||||
if (ext != 0)
|
||||
{
|
||||
/* Load the extension header */
|
||||
if ((fh = qfits_header_readext(ql.filename, ext)) == NULL) return -1 ;
|
||||
if ((fh = qfits_header_readext (ql.filename, ext)) == NULL)
|
||||
return -1;
|
||||
/* Dump the extension header */
|
||||
qfits_header_dump (fh, out);
|
||||
qfits_header_destroy (fh);
|
||||
|
@ -251,7 +275,8 @@ static int iextract_write_ext(
|
|||
fclose (out);
|
||||
|
||||
/* Load the FITS image */
|
||||
if (qfits_loadpix(&ql)!=0) return -1 ;
|
||||
if (qfits_loadpix (&ql) != 0)
|
||||
return -1;
|
||||
|
||||
/* Write the FITS image */
|
||||
qd.filename = outname;
|
||||
|
@ -259,7 +284,8 @@ static int iextract_write_ext(
|
|||
qd.ptype = PTYPE_DOUBLE;
|
||||
qd.dbuf = ql.dbuf;
|
||||
qd.out_ptype = ql.bitpix;
|
||||
if (qfits_pixdump(&qd)!=0) return -1 ;
|
||||
if (qfits_pixdump (&qd) != 0)
|
||||
return -1;
|
||||
/* qfits_zeropad(outname) ; */
|
||||
free (ql.dbuf);
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ static void usage(char *) ;
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *name_in;
|
||||
char *card;
|
||||
|
@ -55,7 +56,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
char card_tmp[NM_SIZ];
|
||||
|
||||
if (argc<2) usage(argv[0]) ;
|
||||
if (argc < 2)
|
||||
usage (argv[0]);
|
||||
|
||||
/* Initialize */
|
||||
name_in = NULL;
|
||||
|
@ -69,107 +71,152 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Command line handling */
|
||||
i = 1;
|
||||
while (i<argc) {
|
||||
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
|
||||
while (i < argc)
|
||||
{
|
||||
if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-h"))
|
||||
{
|
||||
usage (argv[0]);
|
||||
} else if (!strcmp(argv[i], "-p")) {
|
||||
if ((i+1)>=argc) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-p"))
|
||||
{
|
||||
if ((i + 1) >= argc)
|
||||
{
|
||||
fprintf (stderr, "option -p needs an argument\n");
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
place = strdup (argv[i]);
|
||||
} else if (!strcmp(argv[i], "-k")) {
|
||||
if ((i+1)>=argc) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-k"))
|
||||
{
|
||||
if ((i + 1) >= argc)
|
||||
{
|
||||
fprintf (stderr, "option -k needs an argument\n");
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
key = strdup (argv[i]);
|
||||
} else if (!strcmp(argv[i], "-v")) {
|
||||
if ((i+1)>=argc) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-v"))
|
||||
{
|
||||
if ((i + 1) >= argc)
|
||||
{
|
||||
fprintf (stderr, "option -v needs an argument\n");
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
val = strdup (argv[i]);
|
||||
} else if (!strcmp(argv[i], "-c")) {
|
||||
if ((i+1)>=argc) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-c"))
|
||||
{
|
||||
if ((i + 1) >= argc)
|
||||
{
|
||||
fprintf (stderr, "option -c needs an argument\n");
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
com = strdup (argv[i]);
|
||||
} else if (!strcmp(argv[i], "-C")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-C"))
|
||||
{
|
||||
keep_com = 1;
|
||||
} else if (!strcmp(argv[i], "-n")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-n"))
|
||||
{
|
||||
numeric = 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Check options coherence */
|
||||
if ((keep_com == 1) && (com != NULL)) {
|
||||
if ((keep_com == 1) && (com != NULL))
|
||||
{
|
||||
fprintf (stderr, "options -c and -C should not be used together\n");
|
||||
if (place) free(place) ;
|
||||
if (key) free(key) ;
|
||||
if (val) free(val) ;
|
||||
if (place)
|
||||
free (place);
|
||||
if (key)
|
||||
free (key);
|
||||
if (val)
|
||||
free (val);
|
||||
free (com);
|
||||
return -1;
|
||||
}
|
||||
if (place == NULL) {
|
||||
if (place == NULL)
|
||||
{
|
||||
fprintf (stderr, "options -p has to be used\n");
|
||||
if (key) free(key) ;
|
||||
if (val) free(val) ;
|
||||
if (com) free(com) ;
|
||||
if (key)
|
||||
free (key);
|
||||
if (val)
|
||||
free (val);
|
||||
if (com)
|
||||
free (com);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get input file name */
|
||||
if ((argc-i)<1) {
|
||||
if ((argc - i) < 1)
|
||||
{
|
||||
fprintf (stderr, "missing input file name\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Loop on the input files */
|
||||
while (argc-i >= 1) {
|
||||
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) ;
|
||||
if (key == NULL)
|
||||
key_tmp = strdup (place);
|
||||
else
|
||||
key_tmp = strdup (key);
|
||||
|
||||
/* Set value to write */
|
||||
val_tmp = NULL;
|
||||
if (val==NULL) {
|
||||
if (val == NULL)
|
||||
{
|
||||
card = qfits_query_card (name_in, place);
|
||||
if (card!= NULL) {
|
||||
if (card != NULL)
|
||||
{
|
||||
stmp = qfits_getvalue (card);
|
||||
val_tmp = strdup (stmp);
|
||||
}
|
||||
} else val_tmp = strdup(val) ;
|
||||
}
|
||||
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) {
|
||||
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) ;
|
||||
}
|
||||
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) ;
|
||||
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 */
|
||||
|
@ -178,7 +225,8 @@ int main(int argc, char *argv[])
|
|||
printf ("\tplace : \n\t\t%s\n", place);
|
||||
|
||||
/* Try to replace the first key */
|
||||
if (qfits_replace_card(name_in, place, card) == -1) {
|
||||
if (qfits_replace_card (name_in, place, card) == -1)
|
||||
{
|
||||
fprintf (stderr, "cannot replace the key %s\n", place);
|
||||
}
|
||||
free (name_in);
|
||||
|
@ -187,26 +235,27 @@ int main(int argc, char *argv[])
|
|||
i++;
|
||||
}
|
||||
|
||||
if (val) free(val) ;
|
||||
if (com) free(com) ;
|
||||
if (key) free(key) ;
|
||||
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(
|
||||
"use : %s [options] <in>\n"
|
||||
printf ("use : %s [options] <in>\n"
|
||||
"options are:\n"
|
||||
"\t-p place gives the keyword to write over (required).\n"
|
||||
"\t-k key gives the new keyword name (optional).\n"
|
||||
"\t-v val gives the value 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" "\n", pname);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,13 +45,15 @@
|
|||
#define GZIP_MAGIC1 0x1f
|
||||
#define GZIP_MAGIC2 0x8b
|
||||
|
||||
static is_gzipped(char * filename)
|
||||
static
|
||||
is_gzipped (char *filename)
|
||||
{
|
||||
FILE *in;
|
||||
unsigned char b1, b2;
|
||||
int r1, r2;
|
||||
|
||||
if ((in=fopen(filename, "r"))==NULL) {
|
||||
if ((in = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
r1 = fread (&b1, 1, 1, in);
|
||||
|
@ -59,7 +61,8 @@ static is_gzipped(char * filename)
|
|||
fclose (in);
|
||||
if (r1 != 1 || r2 != 1)
|
||||
return 0;
|
||||
if ((int)b1!=GZIP_MAGIC1 || (int)b2!=GZIP_MAGIC2) {
|
||||
if ((int) b1 != GZIP_MAGIC1 || (int) b2 != GZIP_MAGIC2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
@ -88,7 +91,8 @@ static is_gzipped(char * filename)
|
|||
/* The following types defined for MD5 computation only */
|
||||
typedef unsigned int word32;
|
||||
|
||||
struct MD5Context {
|
||||
struct MD5Context
|
||||
{
|
||||
word32 buf[4];
|
||||
word32 bits[2];
|
||||
unsigned char in[64];
|
||||
|
@ -123,19 +127,23 @@ static int silent_process=0 ;
|
|||
-----------------------------------------------------------------------------*/
|
||||
|
||||
/* Reverse bytes in a 32-bit word. Harmless on little endian machines */
|
||||
static void byteReverse(unsigned char *buf, unsigned longs)
|
||||
static void
|
||||
byteReverse (unsigned char *buf, unsigned longs)
|
||||
{
|
||||
word32 t;
|
||||
do {
|
||||
do
|
||||
{
|
||||
t = (word32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
|
||||
((unsigned) buf[1] << 8 | buf[0]);
|
||||
*(word32 *) buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
}
|
||||
while (--longs);
|
||||
}
|
||||
|
||||
/* Start MD5 accumulation. Set bit count to 0 and buffer to MD5 init. const. */
|
||||
static void MD5Init(struct MD5Context *ctx)
|
||||
static void
|
||||
MD5Init (struct MD5Context *ctx)
|
||||
{
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
|
@ -146,7 +154,8 @@ static void MD5Init(struct MD5Context *ctx)
|
|||
}
|
||||
|
||||
/* Update to reflect the concatenation of another buffer full of bytes. */
|
||||
static void MD5Update(struct MD5Context *ctx, unsigned char *buf, unsigned len)
|
||||
static void
|
||||
MD5Update (struct MD5Context *ctx, unsigned char *buf, unsigned len)
|
||||
{
|
||||
register word32 t;
|
||||
|
||||
|
@ -159,10 +168,12 @@ static void MD5Update(struct MD5Context *ctx, unsigned char *buf, unsigned len)
|
|||
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
|
||||
|
||||
/* Handle any leading odd-sized chunks */
|
||||
if (t) {
|
||||
if (t)
|
||||
{
|
||||
unsigned char *p = (unsigned char *) ctx->in + t;
|
||||
t = 64 - t;
|
||||
if (len < t) {
|
||||
if (len < t)
|
||||
{
|
||||
memmove (p, buf, len);
|
||||
return;
|
||||
}
|
||||
|
@ -173,7 +184,8 @@ static void MD5Update(struct MD5Context *ctx, unsigned char *buf, unsigned len)
|
|||
len -= t;
|
||||
}
|
||||
/* Process data in 64-byte chunks */
|
||||
while (len >= 64) {
|
||||
while (len >= 64)
|
||||
{
|
||||
memmove (ctx->in, buf, 64);
|
||||
byteReverse (ctx->in, 16);
|
||||
MD5Transform (ctx->buf, (word32 *) ctx->in);
|
||||
|
@ -187,7 +199,8 @@ static void MD5Update(struct MD5Context *ctx, unsigned char *buf, unsigned len)
|
|||
|
||||
/* Final wrapup - pad to 64-byte boundary with the bit pattern 1 0* */
|
||||
/* (64-bit count of bits processed, MSB-first) */
|
||||
static void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
||||
static void
|
||||
MD5Final (unsigned char digest[16], struct MD5Context *ctx)
|
||||
{
|
||||
unsigned int count;
|
||||
unsigned char *p;
|
||||
|
@ -204,7 +217,8 @@ static void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
|||
count = 64 - 1 - count;
|
||||
|
||||
/* 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);
|
||||
byteReverse (ctx->in, 16);
|
||||
|
@ -212,7 +226,9 @@ static void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
|||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset (ctx->in, 0, 56);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Pad block to 56 bytes */
|
||||
memset (p, 0, count - 8);
|
||||
}
|
||||
|
@ -245,7 +261,8 @@ static void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
|||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||
* the data and converts bytes into longwords for this routine.
|
||||
*/
|
||||
static void MD5Transform(word32 buf[4], word32 in[16])
|
||||
static void
|
||||
MD5Transform (word32 buf[4], word32 in[16])
|
||||
{
|
||||
register word32 a, b, c, d;
|
||||
|
||||
|
@ -334,28 +351,36 @@ static void MD5Transform(word32 buf[4], word32 in[16])
|
|||
-----------------------------------------------------------------------------*/
|
||||
|
||||
/* Pretty-print a FITS string value */
|
||||
static char * fits_pretty_string(char * s)
|
||||
static char *
|
||||
fits_pretty_string (char *s)
|
||||
{
|
||||
static char pretty[FITSLINESZ + 1];
|
||||
int i, j;
|
||||
|
||||
if (s==NULL) return NULL ;
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
pretty[0] = (char) 0;
|
||||
if (s[0]!='\'') return s ;
|
||||
if (s[0] != '\'')
|
||||
return s;
|
||||
|
||||
/* skip first quote */
|
||||
i = 1;
|
||||
j = 0;
|
||||
/* trim left-side blanks */
|
||||
while (s[i]==' ') {
|
||||
if (i==(int)strlen(s)) break ;
|
||||
while (s[i] == ' ')
|
||||
{
|
||||
if (i == (int) strlen (s))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
if (i>=(int)(strlen(s)-1)) return pretty ;
|
||||
if (i >= (int) (strlen (s) - 1))
|
||||
return pretty;
|
||||
/* copy string, changing double quotes to single ones */
|
||||
while (i<(int)strlen(s)) {
|
||||
if (s[i]=='\'') i++ ;
|
||||
while (i < (int) strlen (s))
|
||||
{
|
||||
if (s[i] == '\'')
|
||||
i++;
|
||||
pretty[j] = s[i];
|
||||
i++;
|
||||
j++;
|
||||
|
@ -364,43 +389,57 @@ static char * fits_pretty_string(char * s)
|
|||
pretty[j + 1] = (char) 0;
|
||||
/* trim right-side blanks */
|
||||
j = (int) strlen (pretty) - 1;
|
||||
while (pretty[j]==' ') j-- ;
|
||||
while (pretty[j] == ' ')
|
||||
j--;
|
||||
pretty[j + 1] = (char) 0;
|
||||
return pretty;
|
||||
}
|
||||
|
||||
/* Get the FITS value in a FITS card */
|
||||
static char * fits_getvalue(char * line)
|
||||
static char *
|
||||
fits_getvalue (char *line)
|
||||
{
|
||||
static char value[FITSLINESZ + 1];
|
||||
int from, to;
|
||||
int inq;
|
||||
int i;
|
||||
|
||||
if (line==NULL) return NULL ;
|
||||
if (line == NULL)
|
||||
return NULL;
|
||||
memset (value, 0, FITSLINESZ + 1);
|
||||
/* Get past the keyword */
|
||||
i = 0;
|
||||
while (line[i]!='=' && i<FITSLINESZ) i++ ;
|
||||
if (i>FITSLINESZ) return NULL ;
|
||||
while (line[i] != '=' && i < FITSLINESZ)
|
||||
i++;
|
||||
while (line[i]==' ' && i<FITSLINESZ) i++ ;
|
||||
if (i>FITSLINESZ) return NULL ;
|
||||
if (i > FITSLINESZ)
|
||||
return NULL;
|
||||
i++;
|
||||
while (line[i] == ' ' && i < FITSLINESZ)
|
||||
i++;
|
||||
if (i > FITSLINESZ)
|
||||
return NULL;
|
||||
from = i;
|
||||
/* Now in the value section */
|
||||
/* Look for the first slash '/' outside of a string */
|
||||
inq = 0;
|
||||
while (i<FITSLINESZ) {
|
||||
if (line[i]=='\'') inq=!inq ;
|
||||
if (line[i]=='/') if (!inq) break ;
|
||||
while (i < FITSLINESZ)
|
||||
{
|
||||
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) return NULL ;
|
||||
while (line[i] == ' ' && i >= 0)
|
||||
i--;
|
||||
if (i < 0)
|
||||
return NULL;
|
||||
to = i;
|
||||
if (to<from) return NULL ;
|
||||
if (to < from)
|
||||
return NULL;
|
||||
/* Copy relevant characters into output buffer */
|
||||
strncpy (value, line + from, to - from + 1);
|
||||
/* Null-terminate the string */
|
||||
|
@ -414,7 +453,8 @@ static char * fits_getvalue(char * line)
|
|||
}
|
||||
|
||||
/* Replace the MD5 card in the input header */
|
||||
static int fits_replace_card(char * filename, int off_md5, char * datamd5)
|
||||
static int
|
||||
fits_replace_card (char *filename, int off_md5, char *datamd5)
|
||||
{
|
||||
char *buf;
|
||||
int fd;
|
||||
|
@ -424,29 +464,27 @@ static int fits_replace_card(char * filename, int off_md5, char * datamd5)
|
|||
int err;
|
||||
|
||||
/* Get file size */
|
||||
if (stat(filename, &sta)==-1) {
|
||||
if (stat (filename, &sta) == -1)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot stat file [%s]: no update done\n",
|
||||
pname,
|
||||
filename);
|
||||
pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* Open file */
|
||||
fd = open (filename, O_RDWR);
|
||||
if (fd==-1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: cannot open file [%s] for modification: no update done\n",
|
||||
pname,
|
||||
filename);
|
||||
pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* Memory-map the file */
|
||||
buf = (char *) mmap (0,
|
||||
sta.st_size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
fd,
|
||||
0);
|
||||
if (buf==(char*)-1 || buf==NULL) {
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (buf == (char *) -1 || buf == NULL)
|
||||
{
|
||||
perror ("mmap");
|
||||
close (fd);
|
||||
return 1;
|
||||
|
@ -454,7 +492,8 @@ static int fits_replace_card(char * filename, int off_md5, char * datamd5)
|
|||
/* sprintf should be safe, the MD5 signature size is 32 chars */
|
||||
sprintf (card, "%s= '%s' / data MD5 signature", FITSMD5KEY, datamd5);
|
||||
i = FITSLINESZ - 1;
|
||||
while (card[i]!='e') {
|
||||
while (card[i] != 'e')
|
||||
{
|
||||
card[i] = ' ';
|
||||
i--;
|
||||
}
|
||||
|
@ -463,13 +502,14 @@ static int fits_replace_card(char * filename, int off_md5, char * datamd5)
|
|||
/* flush output, unmap buffer, close file and quit */
|
||||
err = 0;
|
||||
sync ();
|
||||
if (close(fd)==-1) {
|
||||
if (close (fd) == -1)
|
||||
{
|
||||
fprintf (stderr, "%s: error closing modified file [%s]",
|
||||
pname,
|
||||
filename);
|
||||
pname, filename);
|
||||
err++;
|
||||
}
|
||||
if (munmap(buf, sta.st_size)==-1) {
|
||||
if (munmap (buf, sta.st_size) == -1)
|
||||
{
|
||||
perror ("munmap");
|
||||
err++;
|
||||
}
|
||||
|
@ -477,7 +517,8 @@ static int fits_replace_card(char * filename, int off_md5, char * datamd5)
|
|||
}
|
||||
|
||||
/* Display or modify the DATAMD5 value. Returns the number of errors. */
|
||||
static int fits_md5_check(char * filename, int update_header)
|
||||
static int
|
||||
fits_md5_check (char *filename, int update_header)
|
||||
{
|
||||
FILE *in;
|
||||
char buf[FITSBLOCKSZ];
|
||||
|
@ -495,20 +536,24 @@ static int fits_md5_check(char * filename, int update_header)
|
|||
int check_fits;
|
||||
struct stat sta;
|
||||
|
||||
if (filename==NULL) return 1 ;
|
||||
if (filename == NULL)
|
||||
return 1;
|
||||
|
||||
/* Try to stat file */
|
||||
if (stat(filename, &sta)!=0) {
|
||||
if (stat (filename, &sta) != 0)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot stat file %s\n", pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* See if this is a regular file */
|
||||
if (!S_ISREG(sta.st_mode)) {
|
||||
if (!S_ISREG (sta.st_mode))
|
||||
{
|
||||
fprintf (stderr, "%s: not a regular file: %s\n", pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* Open input file */
|
||||
if ((in=fopen(filename, "r"))==NULL) {
|
||||
if ((in = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot open file [%s]\n", pname, filename);
|
||||
return 1;
|
||||
}
|
||||
|
@ -521,9 +566,11 @@ static int fits_md5_check(char * filename, int update_header)
|
|||
md5keysz = (int) strlen (FITSMD5KEY);
|
||||
check_fits = 0;
|
||||
/* Loop over input file */
|
||||
while (fread(buf, 1, FITSBLOCKSZ, in)==FITSBLOCKSZ) {
|
||||
while (fread (buf, 1, FITSBLOCKSZ, in) == FITSBLOCKSZ)
|
||||
{
|
||||
/* First time in the loop: check the file is FITS */
|
||||
if (check_fits==0) {
|
||||
if (check_fits == 0)
|
||||
{
|
||||
/* Examine first characters in block */
|
||||
if (buf[0] != 'S' ||
|
||||
buf[1] != 'I' ||
|
||||
|
@ -531,41 +578,46 @@ static int fits_md5_check(char * filename, int update_header)
|
|||
buf[3] != 'P' ||
|
||||
buf[4] != 'L' ||
|
||||
buf[5] != 'E' ||
|
||||
buf[6]!=' ' ||
|
||||
buf[7]!=' ' ||
|
||||
buf[8]!='=') {
|
||||
buf[6] != ' ' || buf[7] != ' ' || buf[8] != '=')
|
||||
{
|
||||
fprintf (stderr, "%s: file [%s] is not FITS\n",
|
||||
pname,
|
||||
filename);
|
||||
pname, filename);
|
||||
fclose (in);
|
||||
return 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
check_fits = 1;
|
||||
}
|
||||
}
|
||||
/* If current block is a header block */
|
||||
if (in_header) {
|
||||
if (in_header)
|
||||
{
|
||||
buf_c = buf;
|
||||
for (i=0 ; i<FITSCARDS ; i++) {
|
||||
for (i = 0; i < FITSCARDS; i++)
|
||||
{
|
||||
/* Try to locate MD5 keyword if not located already */
|
||||
if (hdrmd5==NULL) {
|
||||
if (!strncmp(buf_c, FITSMD5KEY, md5keysz)) {
|
||||
if (hdrmd5 == NULL)
|
||||
{
|
||||
if (!strncmp (buf_c, FITSMD5KEY, md5keysz))
|
||||
{
|
||||
hdrmd5 = fits_getvalue (buf_c);
|
||||
off_md5 = cur_off;
|
||||
}
|
||||
}
|
||||
/* Try to locate an END key */
|
||||
if (buf_c[0] == 'E' &&
|
||||
buf_c[1]=='N' &&
|
||||
buf_c[2]=='D' &&
|
||||
buf_c[3]==' ') {
|
||||
buf_c[1] == 'N' && buf_c[2] == 'D' && buf_c[3] == ' ')
|
||||
{
|
||||
in_header = 0;
|
||||
break;
|
||||
}
|
||||
buf_c += FITSLINESZ;
|
||||
cur_off += FITSLINESZ;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If current block is a data block */
|
||||
/* Try to locate an extension header */
|
||||
if (buf[0] == 'X' &&
|
||||
|
@ -574,35 +626,35 @@ static int fits_md5_check(char * filename, int update_header)
|
|||
buf[3] == 'N' &&
|
||||
buf[4] == 'S' &&
|
||||
buf[5] == 'I' &&
|
||||
buf[6]=='O' &&
|
||||
buf[7]=='N' &&
|
||||
buf[8]=='=') {
|
||||
buf[6] == 'O' && buf[7] == 'N' && buf[8] == '=')
|
||||
{
|
||||
in_header = 1;
|
||||
buf_c = buf;
|
||||
for (i=0 ; i<FITSCARDS ; i++) {
|
||||
for (i = 0; i < FITSCARDS; 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]==' ') {
|
||||
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 += FITSLINESZ;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Data block: accumulate for MD5 */
|
||||
MD5Update (&ctx, (unsigned char *) buf, FITSBLOCKSZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (in);
|
||||
if (check_fits==0) {
|
||||
if (check_fits == 0)
|
||||
{
|
||||
/* Never went through the read loop: file is not FITS */
|
||||
fprintf(stderr, "%s: file [%s] is not FITS\n",
|
||||
pname,
|
||||
filename);
|
||||
fprintf (stderr, "%s: file [%s] is not FITS\n", pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* Got to the end of file: summarize */
|
||||
|
@ -615,12 +667,17 @@ static int fits_md5_check(char * filename, int update_header)
|
|||
digest[5], digest[6], digest[7], digest[8], digest[9],
|
||||
digest[10], digest[11], digest[12], digest[13], digest[14],
|
||||
digest[15]);
|
||||
if (!silent_process) {
|
||||
if (!silent_process)
|
||||
{
|
||||
printf ("%s %s", datamd5, filename);
|
||||
if (hdrmd5) {
|
||||
if (!strcmp(hdrmd5, datamd5)) {
|
||||
if (hdrmd5)
|
||||
{
|
||||
if (!strcmp (hdrmd5, datamd5))
|
||||
{
|
||||
printf (" (header Ok)");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf (" (header is wrong)");
|
||||
}
|
||||
}
|
||||
|
@ -628,15 +685,17 @@ static int fits_md5_check(char * filename, int update_header)
|
|||
}
|
||||
/* Update header if requested */
|
||||
err = 0;
|
||||
if (update_header) {
|
||||
if (hdrmd5==NULL) {
|
||||
if (update_header)
|
||||
{
|
||||
if (hdrmd5 == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot update header: missing %s\n",
|
||||
pname,
|
||||
FITSMD5KEY);
|
||||
pname, FITSMD5KEY);
|
||||
return 1;
|
||||
}
|
||||
#if HAVE_ZLIB
|
||||
if (is_gzipped(filename)) {
|
||||
if (is_gzipped (filename))
|
||||
{
|
||||
fprintf (stderr, "%s: cannot update header in gzipped file\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -648,7 +707,8 @@ static int fits_md5_check(char * filename, int update_header)
|
|||
|
||||
|
||||
/* Compute MD5 sum on the whole file and print out results on stdout */
|
||||
static int compute_md5(char * filename)
|
||||
static int
|
||||
compute_md5 (char *filename)
|
||||
{
|
||||
struct MD5Context ctx;
|
||||
unsigned char digest[16];
|
||||
|
@ -657,23 +717,28 @@ static int compute_md5(char * filename)
|
|||
unsigned char *buf;
|
||||
|
||||
/* Try to stat file */
|
||||
if (stat(filename, &sta)!=0) {
|
||||
if (stat (filename, &sta) != 0)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot stat file %s\n", pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* See if this is a regular file */
|
||||
if (!S_ISREG(sta.st_mode)) {
|
||||
if (!S_ISREG (sta.st_mode))
|
||||
{
|
||||
fprintf (stderr, "%s: not a regular file: %s\n", pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* Open file */
|
||||
if ((fd = open(filename, O_RDONLY))==-1) {
|
||||
if ((fd = open (filename, O_RDONLY)) == -1)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot open file %s\n", pname, filename);
|
||||
return 1;
|
||||
}
|
||||
/* Memory-map the file */
|
||||
buf = (unsigned char*)mmap(0, sta.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (buf==(unsigned char*)-1 || buf==NULL) {
|
||||
buf =
|
||||
(unsigned char *) mmap (0, sta.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (buf == (unsigned char *) -1 || buf == NULL)
|
||||
{
|
||||
perror ("mmap");
|
||||
close (fd);
|
||||
return 1;
|
||||
|
@ -686,25 +751,19 @@ static int compute_md5(char * filename)
|
|||
close (fd);
|
||||
munmap ((char *) buf, sta.st_size);
|
||||
MD5Final (digest, &ctx);
|
||||
printf(
|
||||
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
|
||||
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],
|
||||
filename);
|
||||
printf
|
||||
("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
|
||||
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], filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
static void
|
||||
usage (void)
|
||||
{
|
||||
printf(
|
||||
"%s -- %s\n"
|
||||
"version: $Revision: 1.5 $\n",
|
||||
pname,
|
||||
prog_desc);
|
||||
printf(
|
||||
"\n"
|
||||
printf ("%s -- %s\n" "version: $Revision: 1.5 $\n", pname, prog_desc);
|
||||
printf ("\n"
|
||||
"use : %s [-u] [-s] [-a] <FITS files...>\n"
|
||||
"options are:\n"
|
||||
"\t-u update MD5 keyword in the file: %s\n"
|
||||
|
@ -717,26 +776,19 @@ static void usage(void)
|
|||
"declared in DATAMD5 if present. It can also update the value\n"
|
||||
"of this keyword (if present) with its own computed MD5 sum.\n"
|
||||
"\n", pname, FITSMD5KEY);
|
||||
printf(
|
||||
"You can also use it with the -a option to compute the MD5 sum\n"
|
||||
printf ("You can also use it with the -a option to compute the MD5 sum\n"
|
||||
"on the complete file (all bits). In this case, the file needs\n"
|
||||
"not be FITS. This option is only provided to check this program\n"
|
||||
"against other MD5 computation tools.\n"
|
||||
"NB: Other options cannot be used together with -a.\n"
|
||||
"\n");
|
||||
"NB: Other options cannot be used together with -a.\n" "\n");
|
||||
|
||||
#if HAVE_ZLIB
|
||||
printf(
|
||||
"\n"
|
||||
printf ("\n"
|
||||
"This program was compiled against zlib %s\n"
|
||||
"which allows to process gzipped FITS files\n"
|
||||
"as if they were normal FITS files.\n"
|
||||
"Notice that you cannot use the -u option on\n"
|
||||
"gzipped files, though.\n"
|
||||
"\n"
|
||||
"\n",
|
||||
ZLIB_VERSION
|
||||
);
|
||||
"gzipped files, though.\n" "\n" "\n", ZLIB_VERSION);
|
||||
#endif
|
||||
exit (0);
|
||||
}
|
||||
|
@ -744,7 +796,8 @@ static void usage(void)
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int update_header;
|
||||
|
@ -756,34 +809,46 @@ int main(int argc, char *argv[])
|
|||
update_header = 0;
|
||||
total_md5 = 0;
|
||||
|
||||
if (argc<2) usage();
|
||||
if (argc < 2)
|
||||
usage ();
|
||||
|
||||
/* Parse arguments for options */
|
||||
for (i=1 ; i<argc ; i++) {
|
||||
if (!strcmp(argv[i], "-u")) {
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (!strcmp (argv[i], "-u"))
|
||||
{
|
||||
update_header = 1;
|
||||
} else if (!strcmp(argv[i], "-s")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-s"))
|
||||
{
|
||||
silent_process = 1;
|
||||
} else if (!strcmp(argv[i], "-a")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "-a"))
|
||||
{
|
||||
total_md5 = 1;
|
||||
}
|
||||
}
|
||||
/* Loop on input file names */
|
||||
err = 0;
|
||||
for (i=1 ; i<argc ; i++) {
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
/* If not a command-line option */
|
||||
if (strcmp (argv[i], "-u") &&
|
||||
strcmp(argv[i], "-s") &&
|
||||
strcmp(argv[i], "-a")) {
|
||||
strcmp (argv[i], "-s") && strcmp (argv[i], "-a"))
|
||||
{
|
||||
/* Launch MD5 process on this file */
|
||||
if (total_md5) {
|
||||
if (total_md5)
|
||||
{
|
||||
err += compute_md5 (argv[i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
err += fits_md5_check (argv[i], update_header);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (err>0) {
|
||||
if (err > 0)
|
||||
{
|
||||
fprintf (stderr, "%s: %d error(s) during process\n", pname, err);
|
||||
}
|
||||
return err;
|
||||
|
|
|
@ -61,13 +61,15 @@
|
|||
-----------------------------------------------------------------------------*/
|
||||
|
||||
/* This holds a keyword value and a flag to indicate its presence */
|
||||
typedef struct _KEYWORD_ {
|
||||
typedef struct _KEYWORD_
|
||||
{
|
||||
char value[MAX_STRING];
|
||||
int present;
|
||||
} keyword;
|
||||
|
||||
/* Each detected file in input has such an associated structure */
|
||||
typedef struct _RECORD_ {
|
||||
typedef struct _RECORD_
|
||||
{
|
||||
char filename[MAX_STRING];
|
||||
keyword listkw[MAX_KEY];
|
||||
} record;
|
||||
|
@ -85,7 +87,8 @@ static void getkeywordvalue(char *line, char *word) ;
|
|||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char curline[MAX_STRING];
|
||||
char word[MAX_STRING];
|
||||
|
@ -101,7 +104,8 @@ int main(int argc, char *argv[])
|
|||
int printnames;
|
||||
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 ("See man page for more details and examples\n\n");
|
||||
|
@ -113,7 +117,8 @@ int main(int argc, char *argv[])
|
|||
print_hdr = 1;
|
||||
nfiles = 0;
|
||||
allrecords = (record *) calloc (1, sizeof (record));
|
||||
if (!strcmp(argv[1], "-d")) {
|
||||
if (!strcmp (argv[1], "-d"))
|
||||
{
|
||||
print_hdr = 0;
|
||||
argv++;
|
||||
argc--;
|
||||
|
@ -121,30 +126,40 @@ int main(int argc, char *argv[])
|
|||
argv++;
|
||||
|
||||
/* Uppercase all inputs */
|
||||
for (i=0 ; i<(argc-1) ; i++) {
|
||||
for (i = 0; i < (argc - 1); i++)
|
||||
{
|
||||
j = 0;
|
||||
while (argv[i][j]!=0) {
|
||||
while (argv[i][j] != 0)
|
||||
{
|
||||
argv[i][j] = toupper (argv[i][j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
while (fgets(curline, MAX_STRING, stdin) != (char*)NULL) {
|
||||
while (fgets (curline, MAX_STRING, stdin) != (char *) NULL)
|
||||
{
|
||||
flag = isfilename (curline);
|
||||
if (flag == 1) {
|
||||
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) {
|
||||
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) {
|
||||
if ((kwnum = isdetectedkeyword (curline, argv, argc - 1)) != -1)
|
||||
{
|
||||
/* Is there anything allocated yet to store this? */
|
||||
if (nfiles>0) {
|
||||
if (nfiles > 0)
|
||||
{
|
||||
/* It has been detected as a searched keyword. */
|
||||
/* Get its value, store it, present flag up */
|
||||
getkeywordvalue (curline, word);
|
||||
|
@ -154,28 +169,39 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
}
|
||||
for (i=0 ; i<argc-1 ; i++) max_width[i] = (int)strlen(argv[i]) ;
|
||||
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++) {
|
||||
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) {
|
||||
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 {
|
||||
}
|
||||
else
|
||||
{
|
||||
len = 0;
|
||||
}
|
||||
if (len>max_width[kwnum]) max_width[kwnum] = len ;
|
||||
if (len > max_width[kwnum])
|
||||
max_width[kwnum] = len;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print out header line */
|
||||
if (print_hdr) {
|
||||
if (print_hdr)
|
||||
{
|
||||
sprintf (fmt, FMT_STRING, max_filnam);
|
||||
if (printnames) printf(fmt, "FILE");
|
||||
for (i=0 ; i<argc-1 ; i++) {
|
||||
if (printnames)
|
||||
printf (fmt, "FILE");
|
||||
for (i = 0; i < argc - 1; i++)
|
||||
{
|
||||
sprintf (fmt, FMT_STRING, max_width[i]);
|
||||
printf (fmt, argv[i]);
|
||||
}
|
||||
|
@ -183,20 +209,25 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Now print out stored data */
|
||||
if (nfiles<1) {
|
||||
if (nfiles < 1)
|
||||
{
|
||||
printf ("*** error: no input data corresponding to dfits output\n");
|
||||
return -1;
|
||||
}
|
||||
for (i=0 ; i<nfiles ; i++) {
|
||||
if (printnames) {
|
||||
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++) {
|
||||
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, " ");
|
||||
else
|
||||
printf (fmt, " ");
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
|
@ -218,10 +249,13 @@ int main(int argc, char *argv[])
|
|||
extension, 0 otherwise.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int isfilename(char * string)
|
||||
static int
|
||||
isfilename (char *string)
|
||||
{
|
||||
if (!strncmp(string, "====>", 5)) return 1 ;
|
||||
if (!strncmp(string, "===>", 4)) return 2 ;
|
||||
if (!strncmp (string, "====>", 5))
|
||||
return 1;
|
||||
if (!strncmp (string, "===>", 4))
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -234,7 +268,8 @@ static int isfilename(char * string)
|
|||
This is dfits dependent.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void getfilename(char * line, char * word)
|
||||
static void
|
||||
getfilename (char *line, char *word)
|
||||
{
|
||||
/* get filename from a dfits output */
|
||||
sscanf (line, "%*s %*s %s", word);
|
||||
|
@ -254,10 +289,8 @@ static void getfilename(char * line, char * word)
|
|||
otherwise, -1 is returned.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int isdetectedkeyword(
|
||||
char * line,
|
||||
char * keywords[],
|
||||
int nkeys)
|
||||
static int
|
||||
isdetectedkeyword (char *line, char *keywords[], int nkeys)
|
||||
{
|
||||
char kw[MAX_STRING];
|
||||
char esokw[MAX_STRING];
|
||||
|
@ -268,22 +301,28 @@ static int isdetectedkeyword(
|
|||
strtok (kw, "=");
|
||||
/* Now remove all trailing blanks (if any) */
|
||||
i = (int) strlen (kw) - 1;
|
||||
while (kw[i] == ' ') i -- ;
|
||||
while (kw[i] == ' ')
|
||||
i--;
|
||||
kw[i + 1] = (char) 0;
|
||||
|
||||
/* Now compare what we got with what's available */
|
||||
for (i=0 ; i<nkeys ; i++) {
|
||||
if (strstr(keywords[i], ".")!=NULL) {
|
||||
for (i = 0; i < nkeys; i++)
|
||||
{
|
||||
if (strstr (keywords[i], ".") != NULL)
|
||||
{
|
||||
/*
|
||||
* keyword contains a dot, it is a hierarchical keyword that
|
||||
* must be expanded. Pattern is:
|
||||
* A.B.C... becomes HIERARCH ESO A B C ...
|
||||
*/
|
||||
expand_hierarch_keyword (keywords[i], esokw);
|
||||
if (!strcmp(kw, esokw)) {
|
||||
if (!strcmp (kw, esokw))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
} else if (!strcmp(kw, keywords[i])) {
|
||||
}
|
||||
else if (!strcmp (kw, keywords[i]))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -299,9 +338,8 @@ static int isdetectedkeyword(
|
|||
@return char *, pointer to second input string (modified)
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char * expand_hierarch_keyword(
|
||||
char * dotkey,
|
||||
char * hierarchy)
|
||||
static char *
|
||||
expand_hierarch_keyword (char *dotkey, char *hierarchy)
|
||||
{
|
||||
char *token;
|
||||
char ws[MAX_STRING];
|
||||
|
@ -309,7 +347,8 @@ static char * expand_hierarch_keyword(
|
|||
sprintf (hierarchy, "HIERARCH ESO");
|
||||
strcpy (ws, dotkey);
|
||||
token = strtok (ws, ".");
|
||||
while (token!=NULL) {
|
||||
while (token != NULL)
|
||||
{
|
||||
strcat (hierarchy, " ");
|
||||
strcat (hierarchy, token);
|
||||
token = strtok (NULL, ".");
|
||||
|
@ -326,9 +365,8 @@ static char * expand_hierarch_keyword(
|
|||
No complex value is recognized
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void getkeywordvalue(
|
||||
char * line,
|
||||
char * word)
|
||||
static void
|
||||
getkeywordvalue (char *line, char *word)
|
||||
{
|
||||
int c, w;
|
||||
char tmp[MAX_STRING];
|
||||
|
@ -342,14 +380,19 @@ static void getkeywordvalue(
|
|||
c = w = 0;
|
||||
|
||||
/* Parse the line till the equal '=' sign is found */
|
||||
while (line[c] != '=') c++ ;
|
||||
while (line[c] != '=')
|
||||
c++;
|
||||
c++;
|
||||
|
||||
/* Copy the line till the slash '/' sign or the end of data is found. */
|
||||
while (search == 1) {
|
||||
if (c>=80) search = 0 ;
|
||||
else if ((line[c] == '/') && (quote == 0)) search = 0 ;
|
||||
if (line[c] == '\'') quote = !quote ;
|
||||
while (search == 1)
|
||||
{
|
||||
if (c >= 80)
|
||||
search = 0;
|
||||
else if ((line[c] == '/') && (quote == 0))
|
||||
search = 0;
|
||||
if (line[c] == '\'')
|
||||
quote = !quote;
|
||||
tmp[w++] = line[c++];
|
||||
}
|
||||
|
||||
|
@ -357,17 +400,19 @@ static void getkeywordvalue(
|
|||
tmp[--w] = (char) 0;
|
||||
|
||||
/* Return the keyword only : a diff is made between text fields and nbs. */
|
||||
if ((begin = strchr(tmp, '\'')) != (char*)NULL) {
|
||||
if ((begin = strchr (tmp, '\'')) != (char *) NULL)
|
||||
{
|
||||
/* A quote has been found: it is a string value */
|
||||
begin++;
|
||||
end = strrchr (tmp, '\'');
|
||||
length = (int) strlen (begin) - (int) strlen (end);
|
||||
strncpy (word, begin, length);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No quote, just get the value (only one, no complex supported) */
|
||||
sscanf (tmp, "%s", word);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,8 +69,7 @@ static char CONVTAB_DEFAULT1[] =
|
|||
"# HIERARCH ESO DET NDIT = DET NDIT\n"
|
||||
"#\n"
|
||||
"# The most important restriction is that new keywords shall not be\n"
|
||||
"# longer than the keywords they replace.\n"
|
||||
"#\n" ;
|
||||
"# longer than the keywords they replace.\n" "#\n";
|
||||
|
||||
|
||||
static char CONVTAB_DEFAULT2[] =
|
||||
|
@ -84,8 +83,7 @@ static char CONVTAB_DEFAULT2[] =
|
|||
"# Disclaimer:\n"
|
||||
"# this table has been compiled to best knowledge of present\n"
|
||||
"# IRAF packages. Please let us know of any addition/change.\n"
|
||||
"#\n"
|
||||
"\n" ;
|
||||
"#\n" "\n";
|
||||
|
||||
|
||||
static char CONVTAB_DEFAULT3[] =
|
||||
|
@ -105,8 +103,7 @@ static char CONVTAB_DEFAULT3[] =
|
|||
"HIERARCH ESO INS GRAT WLEN = WLEN\n"
|
||||
"HIERARCH ESO INS GRAT1 WLEN = WLEN1\n"
|
||||
"HIERARCH ESO INS GRAT2 WLEN = WLEN2\n"
|
||||
"HIERARCH ESO INS GRAT ORDER = ORDER\n"
|
||||
"\n" ;
|
||||
"HIERARCH ESO INS GRAT ORDER = ORDER\n" "\n";
|
||||
|
||||
static char CONVTAB_DEFAULT4[] =
|
||||
"#\n"
|
||||
|
@ -121,42 +118,46 @@ static char CONVTAB_DEFAULT4[] =
|
|||
"# In order to have this tranlation performed, add\n"
|
||||
"# RA = RA\n"
|
||||
"# DEC = DEC\n"
|
||||
"# UTC = UT\n"
|
||||
"# LST = ST\n"
|
||||
"# to the conversion table.\n"
|
||||
"#\n";
|
||||
"# UTC = UT\n" "# LST = ST\n" "# to the conversion table.\n" "#\n";
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Main
|
||||
-----------------------------------------------------------------------------*/
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char name_conv[NM_SIZ];
|
||||
char name_in[NM_SIZ];
|
||||
|
||||
if (argc<2) usage(argv[0]) ;
|
||||
if (!strcmp(argv[1], "-g")) {
|
||||
if (argc < 2)
|
||||
usage (argv[0]);
|
||||
if (!strcmp (argv[1], "-g"))
|
||||
{
|
||||
generate_default_convtab ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy (name_in, argv[1]);
|
||||
if (argc==3) {
|
||||
if (argc == 3)
|
||||
{
|
||||
strcpy (name_conv, argv[2]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy (name_conv, "table.conv");
|
||||
}
|
||||
|
||||
if (convert_eso_to_std_FITS(name_in, name_conv) != 0) {
|
||||
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(
|
||||
"\n\n"
|
||||
printf ("\n\n"
|
||||
"hierarch28 (hierarch-to-eight)\n"
|
||||
"%s : %s\n"
|
||||
"use : %s [options] <in> [table]\n"
|
||||
|
@ -167,8 +168,7 @@ static void usage(char * pname)
|
|||
"\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"
|
||||
"\n\n",
|
||||
pname, prog_desc, pname);
|
||||
"\n\n", pname, prog_desc, pname);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,8 @@ static void usage(char * pname)
|
|||
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;
|
||||
int nkeys;
|
||||
|
@ -195,22 +196,24 @@ static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
|||
int fd;
|
||||
char *buf;
|
||||
char line[NM_SIZ];
|
||||
char kw1[FITS_LINE],
|
||||
kw2[FITS_LINE] ;
|
||||
char kw1[FITS_LINE], kw2[FITS_LINE];
|
||||
int lineno;
|
||||
int fs;
|
||||
struct stat fileinfo;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* First, count how many keywords we need to translate */
|
||||
nkeys = 0;
|
||||
while (fgets(line, FITS_LINE, convtab)!=NULL) {
|
||||
if ((line[0] != '#') && (line[0] != '\n')) {
|
||||
while (fgets (line, FITS_LINE, convtab) != NULL)
|
||||
{
|
||||
if ((line[0] != '#') && (line[0] != '\n'))
|
||||
{
|
||||
nkeys++;
|
||||
}
|
||||
}
|
||||
|
@ -223,10 +226,13 @@ static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
|||
/* Now read the file through and get the keywords */
|
||||
i = 0;
|
||||
lineno = 0;
|
||||
while (fgets(line, FITS_LINE, convtab)!=NULL) {
|
||||
while (fgets (line, FITS_LINE, convtab) != NULL)
|
||||
{
|
||||
lineno++;
|
||||
if ((line[0]!='#') && (line[0]!='\n')) {
|
||||
if (sscanf(line, "%[^=] = %[^;#]", kw1, kw2)!=2) {
|
||||
if ((line[0] != '#') && (line[0] != '\n'))
|
||||
{
|
||||
if (sscanf (line, "%[^=] = %[^;#]", kw1, kw2) != 2)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"*** error parsing table file %s\n", name_conv);
|
||||
fprintf (stderr, "line: %d\n", lineno);
|
||||
|
@ -237,7 +243,8 @@ static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
|||
}
|
||||
strip_beg_end (kw1);
|
||||
strip_beg_end (kw2);
|
||||
if (strlen(kw2)>strlen(kw1)) {
|
||||
if (strlen (kw2) > strlen (kw1))
|
||||
{
|
||||
fprintf (stderr,
|
||||
"*** error in conversion table %s (line %d)\n",
|
||||
name_conv, lineno);
|
||||
|
@ -261,39 +268,39 @@ static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
|||
printf ("*** hierarch28\n");
|
||||
printf ("\n");
|
||||
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 ("\n\n");
|
||||
|
||||
/* 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);
|
||||
free_keys (key_out, nkeys);
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
free_keys (key_out, nkeys);
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
free_keys (key_out, nkeys);
|
||||
return -1;
|
||||
}
|
||||
buf = (char*)mmap(0,
|
||||
fs,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
fd,
|
||||
0) ;
|
||||
if (buf == (char*)-1) {
|
||||
buf = (char *) mmap (0, fs, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (buf == (char *) -1)
|
||||
{
|
||||
perror ("mmap");
|
||||
fprintf (stderr, "cannot mmap file: %s\n", name_in);
|
||||
free_keys (key_in, nkeys);
|
||||
|
@ -303,7 +310,8 @@ static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
|||
}
|
||||
|
||||
/* 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");
|
||||
}
|
||||
free_keys (key_in, nkeys);
|
||||
|
@ -325,15 +333,18 @@ static int convert_eso_to_std_FITS(char * name_in, char * name_conv)
|
|||
characters (like FITS keywords).
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void strip_beg_end(char * s)
|
||||
static void
|
||||
strip_beg_end (char *s)
|
||||
{
|
||||
int beg, len;
|
||||
|
||||
beg = 0;
|
||||
while (!isalnum((unsigned char)(s[beg]))) beg++ ;
|
||||
while (!isalnum ((unsigned char) (s[beg])))
|
||||
beg++;
|
||||
|
||||
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);
|
||||
s[len - beg + 1] = (char) 0;
|
||||
|
@ -351,12 +362,15 @@ static void strip_beg_end(char * s)
|
|||
keys and the master table pointer.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void free_keys(char ** keyt, int n)
|
||||
static void
|
||||
free_keys (char **keyt, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (n<1) return ;
|
||||
for (i=0 ; i<n ; i++) free(keyt[i]) ;
|
||||
if (n < 1)
|
||||
return;
|
||||
for (i = 0; i < n; i++)
|
||||
free (keyt[i]);
|
||||
free (keyt);
|
||||
}
|
||||
|
||||
|
@ -374,12 +388,9 @@ static void free_keys(char ** keyt, int n)
|
|||
keyword changes in extensions too. Heavily optimized for speed.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int search_and_replace_kw(
|
||||
char * buf,
|
||||
int bufsize,
|
||||
char ** key_in,
|
||||
char ** key_out,
|
||||
int nk)
|
||||
static int
|
||||
search_and_replace_kw (char *buf,
|
||||
int bufsize, char **key_in, char **key_out, int nk)
|
||||
{
|
||||
char *w;
|
||||
int i, j;
|
||||
|
@ -389,51 +400,62 @@ static int search_and_replace_kw(
|
|||
|
||||
/* Pre-compute key sizes to gain time */
|
||||
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 */
|
||||
w = buf;
|
||||
in_header = 1;
|
||||
while ((w-buf+FITS_LINE)<bufsize) {
|
||||
if (in_header) { /* Currently browsing a header */
|
||||
if (w[0]=='E' &&
|
||||
w[1]=='N' &&
|
||||
w[2]=='D' &&
|
||||
w[3]==' ') {
|
||||
while ((w - buf + FITS_LINE) < bufsize)
|
||||
{
|
||||
if (in_header)
|
||||
{ /* Currently browsing a header */
|
||||
if (w[0] == 'E' && w[1] == 'N' && w[2] == 'D' && w[3] == ' ')
|
||||
{
|
||||
/* Found an END keyword: exit from header */
|
||||
in_header = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Compare the current line with all searched keys */
|
||||
for (i=0 ; i<nk ; i++) {
|
||||
for (i = 0; i < nk; i++)
|
||||
{
|
||||
match_flag = 1;
|
||||
for (j=0 ; j<=keysizes[i] ; j++) {
|
||||
if (j<keysizes[i]) {
|
||||
if (key_in[i][j]!=w[j]) {
|
||||
for (j = 0; j <= keysizes[i]; j++)
|
||||
{
|
||||
if (j < keysizes[i])
|
||||
{
|
||||
if (key_in[i][j] != w[j])
|
||||
{
|
||||
match_flag = 0;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if ((w[j] != '=') && (w[j] != ' ')) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((w[j] != '=') && (w[j] != ' '))
|
||||
{
|
||||
match_flag = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match_flag) {
|
||||
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' &&
|
||||
w[1] == 'T' &&
|
||||
w[2] == 'E' &&
|
||||
w[3] == 'N' &&
|
||||
w[4]=='S' &&
|
||||
w[5]=='I' &&
|
||||
w[6]=='O' &&
|
||||
w[7]=='N') {
|
||||
w[4] == 'S' && w[5] == 'I' && w[6] == 'O' && w[7] == 'N')
|
||||
{
|
||||
/* Found a header start */
|
||||
in_header = 1;
|
||||
}
|
||||
|
@ -457,7 +479,8 @@ static int search_and_replace_kw(
|
|||
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;
|
||||
char *equal;
|
||||
|
@ -468,12 +491,15 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
|||
|
||||
equal = strstr (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];
|
||||
}
|
||||
if (strlen(key_o)<=8) {
|
||||
if (strlen (key_o) <= 8)
|
||||
{
|
||||
/* Blank-pad until equal sign is reached */
|
||||
for ( ; i<8 ; i++) {
|
||||
for (; i < 8; i++)
|
||||
{
|
||||
line[i] = ' ';
|
||||
}
|
||||
/* Add equal sign */
|
||||
|
@ -481,8 +507,10 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
|||
i++;
|
||||
|
||||
/* Handle special cases: the value also needs conversion */
|
||||
if(!strcmp(key_o, "RA")) {
|
||||
if (*(equal+2)!='\'') {
|
||||
if (!strcmp (key_o, "RA"))
|
||||
{
|
||||
if (*(equal + 2) != '\'')
|
||||
{
|
||||
/* out key is RA, translate to ' HH:MM:SS.SSS' */
|
||||
p = strchr (line + i, '/');
|
||||
if (p)
|
||||
|
@ -492,8 +520,11 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
|||
(p) ? comment : "/ Right Ascension");
|
||||
memcpy (line + i, tmp, 71);
|
||||
}
|
||||
} else if(!strcmp(key_o, "DEC")) {
|
||||
if( *(equal+2)!='\'') {
|
||||
}
|
||||
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)
|
||||
|
@ -503,8 +534,11 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
|||
(p) ? comment : "/ Declination");
|
||||
memcpy (line + i, tmp, 71);
|
||||
}
|
||||
} else if(!strcmp(key_o, "UT")) {
|
||||
if( *(equal+2)!='\'') {
|
||||
}
|
||||
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)
|
||||
|
@ -514,8 +548,11 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
|||
(p) ? comment : "/ UT");
|
||||
memcpy (line + i, tmp, 71);
|
||||
}
|
||||
} else if(!strcmp(key_o, "ST")) {
|
||||
if( *(equal+2)!='\'') {
|
||||
}
|
||||
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)
|
||||
|
@ -525,20 +562,27 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
|||
(p) ? comment : "/ ST");
|
||||
memcpy (line + i, tmp, 71);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Copy line from first char after real equal sign */
|
||||
for (j=0 ; j<to_copy ; j++) {
|
||||
for (j = 0; j < to_copy; j++)
|
||||
{
|
||||
line[i + j] = equal[j + 1];
|
||||
}
|
||||
i += to_copy - 1;
|
||||
/* Blank padding */
|
||||
for ( ; i<FITS_LINE ; i++) {
|
||||
for (; i < FITS_LINE; i++)
|
||||
{
|
||||
line[i] = ' ';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Blank padding */
|
||||
for (i=(int)strlen(key_o) ; i<(int)strlen(key_i) ; i++) {
|
||||
for (i = (int) strlen (key_o); i < (int) strlen (key_i); i++)
|
||||
{
|
||||
line[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
@ -555,11 +599,13 @@ static void search_rep(char * line, char * key_i, char * key_o)
|
|||
instrument is specified (ins==NULL) a default table is generated.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void generate_default_convtab(void)
|
||||
static void
|
||||
generate_default_convtab (void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -582,7 +628,8 @@ static void generate_default_convtab(void)
|
|||
string.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char * convert_deg_to_str( double deg )
|
||||
static char *
|
||||
convert_deg_to_str (double deg)
|
||||
{
|
||||
int d, m;
|
||||
double s;
|
||||
|
@ -590,7 +637,8 @@ static char * convert_deg_to_str( double deg )
|
|||
static char buf[13];
|
||||
|
||||
sign = 1;
|
||||
if(deg < 0.) sign = -1;
|
||||
if (deg < 0.)
|
||||
sign = -1;
|
||||
|
||||
deg *= sign;
|
||||
d = (int) deg;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -62,9 +62,11 @@ static int get_npix(char*) ;
|
|||
/*-----------------------------------------------------------------------------
|
||||
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");
|
||||
|
@ -73,7 +75,8 @@ int main(int argc, char *argv[])
|
|||
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");
|
||||
return -1;
|
||||
|
@ -90,17 +93,13 @@ int main(int argc, char *argv[])
|
|||
Heavy use of mmap() to speed up the process
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int dump_pix(
|
||||
char * name_in,
|
||||
char * name_out)
|
||||
static int
|
||||
dump_pix (char *name_in, char *name_out)
|
||||
{
|
||||
int fd_in,
|
||||
fd_out ;
|
||||
int fd_in, fd_out;
|
||||
char *buf_in;
|
||||
char *buf_out;
|
||||
int fsize_in,
|
||||
fsize_out,
|
||||
header_size ;
|
||||
int fsize_in, fsize_out, header_size;
|
||||
int npix;
|
||||
|
||||
/*
|
||||
|
@ -111,20 +110,24 @@ static int dump_pix(
|
|||
|
||||
fsize_in = filesize (name_in);
|
||||
header_size = get_FITS_header_size (name_in);
|
||||
if ((fd_in = open(name_in, O_RDONLY)) == -1) {
|
||||
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);
|
||||
if (buf_in == (char*)-1) {
|
||||
if (buf_in == (char *) -1)
|
||||
{
|
||||
perror ("mmap");
|
||||
fprintf (stderr, "cannot mmap file: %s\n", name_in);
|
||||
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) ;
|
||||
close (fd_in);
|
||||
munmap (buf_in, fsize_in);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -133,7 +136,8 @@ static int dump_pix(
|
|||
* same header size, + pixel area + blank padding
|
||||
*/
|
||||
npix = get_npix (buf_in);
|
||||
if (npix < 1) {
|
||||
if (npix < 1)
|
||||
{
|
||||
fprintf (stderr, "cannot compute number of pixels\n");
|
||||
close (fd_in);
|
||||
munmap (buf_in, fsize_in);
|
||||
|
@ -144,18 +148,24 @@ static int dump_pix(
|
|||
* Now create the output file and fill it with zeros, then mmap it.
|
||||
* 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 =
|
||||
creat (name_out,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) == -1)
|
||||
{
|
||||
perror ("creat");
|
||||
fprintf (stderr, "cannot create file %s: aborting\n", name_out);
|
||||
close(fd_in) ; munmap(buf_in, fsize_in) ;
|
||||
close (fd_in);
|
||||
munmap (buf_in, fsize_in);
|
||||
return -1;
|
||||
}
|
||||
|
||||
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);
|
||||
close(fd_in) ; munmap(buf_in, fsize_in) ;
|
||||
close (fd_in);
|
||||
munmap (buf_in, fsize_in);
|
||||
return -1;
|
||||
}
|
||||
write (fd_out, buf_out, fsize_out);
|
||||
|
@ -163,21 +173,23 @@ static int dump_pix(
|
|||
free (buf_out);
|
||||
|
||||
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) ;
|
||||
close (fd_in);
|
||||
munmap (buf_in, fsize_in);
|
||||
return -1;
|
||||
}
|
||||
buf_out = (char *) mmap (0,
|
||||
fsize_out,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
fd_out,
|
||||
0) ;
|
||||
if (buf_out == (char*)-1) {
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd_out, 0);
|
||||
if (buf_out == (char *) -1)
|
||||
{
|
||||
perror ("mmap");
|
||||
fprintf (stderr, "cannot mmap file: %s\n", name_out);
|
||||
munmap(buf_in, fsize_in) ; close(fd_in) ; close(fd_out) ;
|
||||
munmap (buf_in, fsize_in);
|
||||
close (fd_in);
|
||||
close (fd_out);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
|
@ -203,7 +215,8 @@ static int dump_pix(
|
|||
80 characters are found per line.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int get_FITS_header_size(char * name)
|
||||
static int
|
||||
get_FITS_header_size (char *name)
|
||||
{
|
||||
FILE *in;
|
||||
char line[81];
|
||||
|
@ -211,29 +224,35 @@ static int get_FITS_header_size(char * name)
|
|||
int count;
|
||||
int hs;
|
||||
|
||||
if ((in = fopen(name, "r")) == NULL) {
|
||||
if ((in = fopen (name, "r")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "cannot open %s: aborting\n", name);
|
||||
return 0;
|
||||
}
|
||||
count = 0;
|
||||
while (!found) {
|
||||
if (fread(line, 1, 80, in)!=80) {
|
||||
while (!found)
|
||||
{
|
||||
if (fread (line, 1, 80, in) != 80)
|
||||
{
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
if (!strncmp(line, "END ", 4)) {
|
||||
if (!strncmp (line, "END ", 4))
|
||||
{
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
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.
|
||||
*/
|
||||
hs = count * 80;
|
||||
if ((hs % FITS_BLSZ) != 0) {
|
||||
if ((hs % FITS_BLSZ) != 0)
|
||||
{
|
||||
hs = (1 + (hs / FITS_BLSZ)) * FITS_BLSZ;
|
||||
}
|
||||
return hs;
|
||||
|
@ -247,15 +266,19 @@ static int get_FITS_header_size(char * name)
|
|||
Strongly non portable. Only on Unix systems!
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int filesize(char *filename)
|
||||
static int
|
||||
filesize (char *filename)
|
||||
{
|
||||
int size;
|
||||
struct stat fileinfo;
|
||||
|
||||
/* POSIX compliant */
|
||||
if (stat(filename, &fileinfo) != 0) {
|
||||
if (stat (filename, &fileinfo) != 0)
|
||||
{
|
||||
size = (int) 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
size = (int) fileinfo.st_size;
|
||||
}
|
||||
return size;
|
||||
|
@ -268,13 +291,15 @@ static int filesize(char *filename)
|
|||
@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;
|
||||
char *where;
|
||||
|
||||
where = strstr (buf, "BITPIX");
|
||||
if (where == NULL) {
|
||||
if (where == NULL)
|
||||
{
|
||||
fprintf (stderr, "cannot find BITPIX in header: aborting\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -283,10 +308,8 @@ static int get_bitpix(char * buf)
|
|||
* Check the returned value makes sense
|
||||
*/
|
||||
if ((bitpix != 8) &&
|
||||
(bitpix != 16) &&
|
||||
(bitpix != 32) &&
|
||||
(bitpix != -32) &&
|
||||
(bitpix != -64)) {
|
||||
(bitpix != 16) && (bitpix != 32) && (bitpix != -32) && (bitpix != -64))
|
||||
{
|
||||
bitpix = 0;
|
||||
}
|
||||
return bitpix;
|
||||
|
@ -300,7 +323,8 @@ static int get_bitpix(char * buf)
|
|||
Does not support extensions!
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int get_npix(char * buf)
|
||||
static int
|
||||
get_npix (char *buf)
|
||||
{
|
||||
int naxes;
|
||||
int npix;
|
||||
|
@ -310,26 +334,30 @@ static int get_npix(char * buf)
|
|||
int i;
|
||||
|
||||
where = strstr (buf, "NAXIS");
|
||||
if (where == NULL) {
|
||||
if (where == NULL)
|
||||
{
|
||||
fprintf (stderr, "cannot find NAXIS in header: aborting\n");
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
npix = 1;
|
||||
for (i=1 ; i<=naxes ; i++) {
|
||||
for (i = 1; i <= naxes; i++)
|
||||
{
|
||||
sprintf (lookfor, "NAXIS%d", i);
|
||||
where = strstr (buf, lookfor);
|
||||
if (where == NULL) {
|
||||
fprintf(stderr, "cannot find %s in header: aborting\n",
|
||||
lookfor) ;
|
||||
if (where == NULL)
|
||||
{
|
||||
fprintf (stderr, "cannot find %s in header: aborting\n", lookfor);
|
||||
return 0;
|
||||
}
|
||||
sscanf (where, "%*[^=] = %d", &naxis);
|
||||
if (naxis<1) {
|
||||
if (naxis < 1)
|
||||
{
|
||||
fprintf (stderr, "error: found %s=%d\n", lookfor, naxis);
|
||||
return 0;
|
||||
}
|
||||
|
@ -337,4 +365,3 @@ static int get_npix(char * buf)
|
|||
}
|
||||
return npix;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,8 @@
|
|||
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
|
||||
__asm ("xchgb %b0,%h0":
|
||||
|
@ -74,16 +75,15 @@ unsigned short __NOTRACE__ swap_bytes_16(unsigned short w)
|
|||
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
|
||||
#if CPU_X86 > 386
|
||||
__asm ("bswap %0":
|
||||
"=r" (dw):
|
||||
#else
|
||||
__asm("xchgb %b0,%h0\n"
|
||||
" rorl $16,%0\n"
|
||||
" xchgb %b0,%h0":
|
||||
__asm ("xchgb %b0,%h0\n" " rorl $16,%0\n" " xchgb %b0,%h0":
|
||||
"=q" (dw):
|
||||
#endif
|
||||
"0" (dw));
|
||||
|
@ -107,14 +107,16 @@ unsigned int __NOTRACE__ swap_bytes_32(unsigned int dw)
|
|||
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;
|
||||
|
||||
a = (unsigned char *) p;
|
||||
b = a + s;
|
||||
|
||||
while (a<b) {
|
||||
while (a < b)
|
||||
{
|
||||
tmp = *a;
|
||||
*a++ = *--b;
|
||||
*b = tmp;
|
||||
|
@ -131,7 +133,8 @@ void __NOTRACE__ swap_bytes(void * p, int s)
|
|||
MOTOROLA-like one does not.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int need_byteswapping(void)
|
||||
int
|
||||
need_byteswapping (void)
|
||||
{
|
||||
short ps = 0xFF;
|
||||
return ((*((char *) (&ps))) ? 1 : 0);
|
||||
|
|
|
@ -77,7 +77,8 @@
|
|||
It is strictly internal to this module.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct _qfits_cache_cell_ {
|
||||
typedef struct _qfits_cache_cell_
|
||||
{
|
||||
char *name; /* File name */
|
||||
ino_t inode; /* Inode */
|
||||
time_t mtime; /* Last modification date */
|
||||
|
@ -116,14 +117,15 @@ static int qfits_cache_add(char * name);
|
|||
@brief initialize cache buffer with minimum size
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void qfits_cache_activate(void)
|
||||
static void
|
||||
qfits_cache_activate (void)
|
||||
{
|
||||
int i;
|
||||
qdebug(
|
||||
printf("qfits: activating cache...\n");
|
||||
qdebug (printf ("qfits: activating cache...\n");
|
||||
);
|
||||
/* Set all slots to NULL */
|
||||
for (i=0 ; i<QFITS_CACHESZ ; i++) {
|
||||
for (i = 0; i < QFITS_CACHESZ; i++)
|
||||
{
|
||||
qfits_cache[i].name = NULL;
|
||||
}
|
||||
/* Register purge function with atexit */
|
||||
|
@ -142,16 +144,18 @@ static void qfits_cache_activate(void)
|
|||
fairly small, you should not need to care too much about this.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void qfits_cache_purge(void)
|
||||
void
|
||||
qfits_cache_purge (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
qdebug(
|
||||
printf("qfits: purging cache...\n");
|
||||
qdebug (printf ("qfits: purging cache...\n");
|
||||
);
|
||||
|
||||
for (i=0 ; i<QFITS_CACHESZ; i++) {
|
||||
if (qfits_cache[i].name!=NULL) {
|
||||
for (i = 0; i < QFITS_CACHESZ; i++)
|
||||
{
|
||||
if (qfits_cache[i].name != NULL)
|
||||
{
|
||||
free (qfits_cache[i].name);
|
||||
qfits_cache[i].name = NULL;
|
||||
free (qfits_cache[i].ohdr);
|
||||
|
@ -161,9 +165,9 @@ void qfits_cache_purge(void)
|
|||
qfits_cache_entries--;
|
||||
}
|
||||
}
|
||||
if (qfits_cache_entries!=0) {
|
||||
qdebug(
|
||||
printf("qfits: internal error in cache consistency\n");
|
||||
if (qfits_cache_entries != 0)
|
||||
{
|
||||
qdebug (printf ("qfits: internal error in cache consistency\n");
|
||||
);
|
||||
exit (-1);
|
||||
}
|
||||
|
@ -178,33 +182,39 @@ void qfits_cache_purge(void)
|
|||
@return int 1 if in the cache, 0 if not
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int qfits_is_cached(char * filename)
|
||||
static int
|
||||
qfits_is_cached (char *filename)
|
||||
{
|
||||
int i, n;
|
||||
struct stat sta;
|
||||
|
||||
/* Stat input file */
|
||||
if (stat(filename, &sta)!=0) {
|
||||
if (stat (filename, &sta) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
n = 0;
|
||||
/* Loop over all cache entries */
|
||||
for (i=0 ; i<QFITS_CACHESZ ; i++) {
|
||||
for (i = 0; i < QFITS_CACHESZ; i++)
|
||||
{
|
||||
/* If entry is valid (name is not NULL) */
|
||||
if (qfits_cache[i].name!=NULL) {
|
||||
if (qfits_cache[i].name != NULL)
|
||||
{
|
||||
/* One more entry found */
|
||||
n++;
|
||||
/* If inode is the same */
|
||||
if ((qfits_cache[i].inode == sta.st_ino) &&
|
||||
(qfits_cache[i].mtime == sta.st_mtime) &&
|
||||
(qfits_cache[i].filesize == sta.st_size) &&
|
||||
(qfits_cache[i].ctime == sta.st_ctime)) {
|
||||
(qfits_cache[i].ctime == sta.st_ctime))
|
||||
{
|
||||
/* This is the requested file */
|
||||
return i;
|
||||
}
|
||||
}
|
||||
/* Early exit: all entries have been browsed */
|
||||
if (n>=qfits_cache_entries) {
|
||||
if (n >= qfits_cache_entries)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -212,15 +222,18 @@ static int qfits_is_cached(char * filename)
|
|||
}
|
||||
|
||||
#if QFITS_CACHE_DEBUG
|
||||
void qfits_cache_dump(void)
|
||||
void
|
||||
qfits_cache_dump (void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
printf ("qfits: dumping cache...\n");
|
||||
|
||||
printf ("cache contains %d entries\n", qfits_cache_entries);
|
||||
for (i=0 ; i<QFITS_CACHESZ ; i++) {
|
||||
if (qfits_cache[i].name!=NULL) {
|
||||
for (i = 0; i < QFITS_CACHESZ; i++)
|
||||
{
|
||||
if (qfits_cache[i].name != NULL)
|
||||
{
|
||||
printf ("qfits: -----> entry: %d\n", i);
|
||||
printf ("qfits: name %s\n", qfits_cache[i].name);
|
||||
printf ("qfits: exts %d\n", qfits_cache[i].exts);
|
||||
|
@ -231,10 +244,11 @@ void qfits_cache_dump(void)
|
|||
"qfits: dsiz %d\n",
|
||||
qfits_cache[i].ohdr[0],
|
||||
qfits_cache[i].shdr[0],
|
||||
qfits_cache[i].data[0],
|
||||
qfits_cache[i].dsiz[0]);
|
||||
if (qfits_cache[i].exts>0) {
|
||||
for (j=1 ; j<=qfits_cache[i].exts ; j++) {
|
||||
qfits_cache[i].data[0], qfits_cache[i].dsiz[0]);
|
||||
if (qfits_cache[i].exts > 0)
|
||||
{
|
||||
for (j = 1; j <= qfits_cache[i].exts; j++)
|
||||
{
|
||||
printf ("qfits: %s [%d]\n", qfits_cache[i].name, j);
|
||||
printf ("qfits: ohdr %d\n"
|
||||
"qfits: shdr %d\n"
|
||||
|
@ -242,8 +256,7 @@ void qfits_cache_dump(void)
|
|||
"qfits: dsiz %d\n",
|
||||
qfits_cache[i].ohdr[j],
|
||||
qfits_cache[i].shdr[j],
|
||||
qfits_cache[i].data[j],
|
||||
qfits_cache[i].dsiz[j]);
|
||||
qfits_cache[i].data[j], qfits_cache[i].dsiz[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,67 +322,76 @@ void qfits_cache_dump(void)
|
|||
of the FITS file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_query(char * filename, int what)
|
||||
int
|
||||
qfits_query (char *filename, int what)
|
||||
{
|
||||
int rank;
|
||||
int which;
|
||||
int answer;
|
||||
|
||||
qdebug(
|
||||
printf("qfits: cache req %s\n", filename);
|
||||
qdebug (printf ("qfits: cache req %s\n", filename);
|
||||
);
|
||||
if ((rank=qfits_is_cached(filename))==-1) {
|
||||
if ((rank = qfits_is_cached (filename)) == -1)
|
||||
{
|
||||
rank = qfits_cache_add (filename);
|
||||
}
|
||||
if (rank==-1) {
|
||||
qdebug(
|
||||
printf("qfits: error adding %s to cache\n", filename);
|
||||
if (rank == -1)
|
||||
{
|
||||
qdebug (printf ("qfits: error adding %s to cache\n", filename);
|
||||
);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* See what was requested */
|
||||
answer = -1;
|
||||
if (what & QFITS_QUERY_N_EXT) {
|
||||
if (what & QFITS_QUERY_N_EXT)
|
||||
{
|
||||
answer = qfits_cache[rank].exts;
|
||||
qdebug(
|
||||
printf("qfits: query n_exts\n");
|
||||
qdebug (printf ("qfits: query n_exts\n");
|
||||
printf ("qfits: -> %d\n", answer);
|
||||
);
|
||||
} else if (what & QFITS_QUERY_HDR_START) {
|
||||
}
|
||||
else if (what & QFITS_QUERY_HDR_START)
|
||||
{
|
||||
which = what & (~QFITS_QUERY_HDR_START);
|
||||
if (which>=0 && which<=qfits_cache[rank].exts) {
|
||||
if (which >= 0 && which <= qfits_cache[rank].exts)
|
||||
{
|
||||
answer = qfits_cache[rank].ohdr[which] * FITS_BLOCK_SIZE;
|
||||
}
|
||||
qdebug(
|
||||
printf("qfits: query offset to header %d\n", which);
|
||||
qdebug (printf ("qfits: query offset to header %d\n", which);
|
||||
printf ("qfits: -> %d (%d bytes)\n", answer / 2880, answer);
|
||||
);
|
||||
} else if (what & QFITS_QUERY_DAT_START) {
|
||||
}
|
||||
else if (what & QFITS_QUERY_DAT_START)
|
||||
{
|
||||
which = what & (~QFITS_QUERY_DAT_START);
|
||||
if (which>=0 && which<=qfits_cache[rank].exts) {
|
||||
if (which >= 0 && which <= qfits_cache[rank].exts)
|
||||
{
|
||||
answer = qfits_cache[rank].data[which] * FITS_BLOCK_SIZE;
|
||||
}
|
||||
qdebug(
|
||||
printf("qfits: query offset to data %d\n", which);
|
||||
qdebug (printf ("qfits: query offset to data %d\n", which);
|
||||
printf ("qfits: -> %d (%d bytes)\n", answer / 2880, answer);
|
||||
);
|
||||
} else if (what & QFITS_QUERY_HDR_SIZE) {
|
||||
}
|
||||
else if (what & QFITS_QUERY_HDR_SIZE)
|
||||
{
|
||||
which = what & (~QFITS_QUERY_HDR_SIZE);
|
||||
if (which>=0 && which<=qfits_cache[rank].exts) {
|
||||
if (which >= 0 && which <= qfits_cache[rank].exts)
|
||||
{
|
||||
answer = qfits_cache[rank].shdr[which] * FITS_BLOCK_SIZE;
|
||||
}
|
||||
qdebug(
|
||||
printf("qfits: query sizeof header %d\n", which);
|
||||
qdebug (printf ("qfits: query sizeof header %d\n", which);
|
||||
printf ("qfits: -> %d (%d bytes)\n", answer / 2880, answer);
|
||||
);
|
||||
} else if (what & QFITS_QUERY_DAT_SIZE) {
|
||||
}
|
||||
else if (what & QFITS_QUERY_DAT_SIZE)
|
||||
{
|
||||
which = what & (~QFITS_QUERY_DAT_SIZE);
|
||||
if (which>=0 && which<=qfits_cache[rank].exts) {
|
||||
if (which >= 0 && which <= qfits_cache[rank].exts)
|
||||
{
|
||||
answer = qfits_cache[rank].dsiz[which] * FITS_BLOCK_SIZE;
|
||||
}
|
||||
qdebug(
|
||||
printf("qfits: query sizeof data %d\n", which);
|
||||
qdebug (printf ("qfits: query sizeof data %d\n", which);
|
||||
printf ("qfits: -> %d (%d bytes)\n", answer / 2880, answer);
|
||||
);
|
||||
}
|
||||
|
@ -402,7 +424,8 @@ int qfits_query(char * filename, int what)
|
|||
and extension data start.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int qfits_cache_add(char * filename)
|
||||
static int
|
||||
qfits_cache_add (char *filename)
|
||||
{
|
||||
FILE *in;
|
||||
int off_hdr[QFITS_MAX_EXTS];
|
||||
|
@ -425,31 +448,32 @@ static int qfits_cache_add(char * filename)
|
|||
qfits_cache_cell *qc;
|
||||
|
||||
/* Initialize cache if not done yet (done only once) */
|
||||
if (qfits_cache_init==0) {
|
||||
if (qfits_cache_init == 0)
|
||||
{
|
||||
qfits_cache_init++;
|
||||
qfits_cache_activate ();
|
||||
}
|
||||
|
||||
/* Stat file to get its size */
|
||||
if (stat(filename, &sta)!=0) {
|
||||
qdebug(
|
||||
printf("qfits: cannot stat file %s\n", filename);
|
||||
if (stat (filename, &sta) != 0)
|
||||
{
|
||||
qdebug (printf ("qfits: cannot stat file %s\n", filename);
|
||||
);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Open input file */
|
||||
if ((in=fopen(filename, "r"))==NULL) {
|
||||
qdebug(
|
||||
printf("qfits: cannot open file %s\n", filename);
|
||||
if ((in = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
qdebug (printf ("qfits: cannot open file %s\n", filename);
|
||||
);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read first block in */
|
||||
if (fread(buf, 1, FITS_BLOCK_SIZE, in)!=FITS_BLOCK_SIZE) {
|
||||
qdebug(
|
||||
printf("qfits: error reading first block from %s\n", filename);
|
||||
if (fread (buf, 1, FITS_BLOCK_SIZE, in) != FITS_BLOCK_SIZE)
|
||||
{
|
||||
qdebug (printf ("qfits: error reading first block from %s\n", filename);
|
||||
);
|
||||
fclose (in);
|
||||
return -1;
|
||||
|
@ -460,12 +484,9 @@ static int qfits_cache_add(char * filename)
|
|||
buf[2] != 'M' ||
|
||||
buf[3] != 'P' ||
|
||||
buf[4] != 'L' ||
|
||||
buf[5]!='E' ||
|
||||
buf[6]!=' ' ||
|
||||
buf[7]!=' ' ||
|
||||
buf[8]!='=') {
|
||||
qdebug(
|
||||
printf("qfits: file %s is not FITS\n", filename);
|
||||
buf[5] != 'E' || buf[6] != ' ' || buf[7] != ' ' || buf[8] != '=')
|
||||
{
|
||||
qdebug (printf ("qfits: file %s is not FITS\n", filename);
|
||||
);
|
||||
fclose (in);
|
||||
return -1;
|
||||
|
@ -489,11 +510,12 @@ static int qfits_cache_add(char * filename)
|
|||
data_bytes = 1;
|
||||
|
||||
/* Start looking for END card */
|
||||
while (found_it==0) {
|
||||
while (found_it == 0)
|
||||
{
|
||||
/* Read one FITS block */
|
||||
if (fread(buf, 1, FITS_BLOCK_SIZE, in)!=FITS_BLOCK_SIZE) {
|
||||
qdebug(
|
||||
printf("qfits: error reading file %s\n", filename);
|
||||
if (fread (buf, 1, FITS_BLOCK_SIZE, in) != FITS_BLOCK_SIZE)
|
||||
{
|
||||
qdebug (printf ("qfits: error reading file %s\n", filename);
|
||||
);
|
||||
fclose (in);
|
||||
return -1;
|
||||
|
@ -501,56 +523,61 @@ static int qfits_cache_add(char * filename)
|
|||
n_blocks++;
|
||||
/* Browse through current block */
|
||||
buf_c = buf;
|
||||
for (i=0 ; i<FITS_NCARDS ; i++) {
|
||||
for (i = 0; i < FITS_NCARDS; i++)
|
||||
{
|
||||
|
||||
/* Look for BITPIX keyword */
|
||||
if (buf_c[0] == 'B' &&
|
||||
buf_c[1] == 'I' &&
|
||||
buf_c[2] == 'T' &&
|
||||
buf_c[3] == 'P' &&
|
||||
buf_c[4]=='I' &&
|
||||
buf_c[5]=='X' &&
|
||||
buf_c[6]==' ') {
|
||||
buf_c[4] == 'I' && buf_c[5] == 'X' && buf_c[6] == ' ')
|
||||
{
|
||||
read_val = qfits_getvalue (buf_c);
|
||||
data_bytes *= (int) atoi (read_val) / 8;
|
||||
if (data_bytes<0) data_bytes *= -1 ;
|
||||
} else
|
||||
if (data_bytes < 0)
|
||||
data_bytes *= -1;
|
||||
}
|
||||
else
|
||||
/* Look for NAXIS keyword */
|
||||
if (buf_c[0] == 'N' &&
|
||||
buf_c[1] == 'A' &&
|
||||
buf_c[2]=='X' &&
|
||||
buf_c[3]=='I' &&
|
||||
buf_c[4]=='S') {
|
||||
buf_c[2] == 'X' && buf_c[3] == 'I' && buf_c[4] == 'S')
|
||||
{
|
||||
|
||||
if (buf_c[5]==' ') {
|
||||
if (buf_c[5] == ' ')
|
||||
{
|
||||
/* NAXIS keyword */
|
||||
read_val = qfits_getvalue (buf_c);
|
||||
naxis = (int) atoi (read_val);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* NAXIS?? keyword (axis size) */
|
||||
read_val = qfits_getvalue (buf_c);
|
||||
data_bytes *= (int) atoi (read_val);
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
/* Look for EXTEND keyword */
|
||||
if (buf_c[0] == 'E' &&
|
||||
buf_c[1] == 'X' &&
|
||||
buf_c[2] == 'T' &&
|
||||
buf_c[3] == 'E' &&
|
||||
buf_c[4]=='N' &&
|
||||
buf_c[5]=='D' &&
|
||||
buf_c[6]==' ') {
|
||||
buf_c[4] == 'N' && buf_c[5] == 'D' && buf_c[6] == ' ')
|
||||
{
|
||||
/* The EXTEND keyword is present: might be some extensions */
|
||||
read_val = qfits_getvalue (buf_c);
|
||||
if (read_val[0]=='T' || read_val[0]=='1') {
|
||||
if (read_val[0] == 'T' || read_val[0] == '1')
|
||||
{
|
||||
xtend = 1;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
/* Look for END keyword */
|
||||
if (buf_c[0] == 'E' &&
|
||||
buf_c[1] == 'N' &&
|
||||
buf_c[2] == 'D' &&
|
||||
buf_c[3] == ' ') {
|
||||
buf_c[1] == 'N' && buf_c[2] == 'D' && buf_c[3] == ' ')
|
||||
{
|
||||
found_it = 1;
|
||||
}
|
||||
buf_c += FITS_LINESZ;
|
||||
|
@ -562,14 +589,16 @@ static int qfits_cache_add(char * filename)
|
|||
*/
|
||||
qfits_cache_last++;
|
||||
/* Rotate buffer if needed */
|
||||
if (qfits_cache_last >= QFITS_CACHESZ) {
|
||||
if (qfits_cache_last >= QFITS_CACHESZ)
|
||||
{
|
||||
qfits_cache_last = 0;
|
||||
}
|
||||
/* Alias to current pointer in cache for easier reading */
|
||||
qc = &(qfits_cache[qfits_cache_last]);
|
||||
|
||||
/* Clean cache cell if needed */
|
||||
if (qc->name!=NULL) {
|
||||
if (qc->name != NULL)
|
||||
{
|
||||
free (qc->name);
|
||||
qc->name = NULL;
|
||||
free (qc->ohdr);
|
||||
|
@ -591,30 +620,33 @@ static int qfits_cache_add(char * filename)
|
|||
/* Last is the pointer to the last added extension, plus one. */
|
||||
last = 1;
|
||||
|
||||
if (xtend) {
|
||||
if (xtend)
|
||||
{
|
||||
/* Look for extensions */
|
||||
qdebug(
|
||||
printf("qfits: searching for extensions in %s\n", filename);
|
||||
qdebug (printf ("qfits: searching for extensions in %s\n", filename);
|
||||
);
|
||||
|
||||
/*
|
||||
* Register all extension offsets
|
||||
*/
|
||||
end_of_file = 0;
|
||||
while (end_of_file==0) {
|
||||
while (end_of_file == 0)
|
||||
{
|
||||
/*
|
||||
* Skip the previous data section if pixels were declared
|
||||
*/
|
||||
if (naxis>0) {
|
||||
if (naxis > 0)
|
||||
{
|
||||
/* Skip as many blocks as there are declared pixels */
|
||||
skip_blocks = data_bytes / FITS_BLOCK_SIZE;
|
||||
if ((data_bytes % FITS_BLOCK_SIZE)!=0) {
|
||||
if ((data_bytes % FITS_BLOCK_SIZE) != 0)
|
||||
{
|
||||
skip_blocks++;
|
||||
}
|
||||
seeked = fseek (in, skip_blocks * FITS_BLOCK_SIZE, SEEK_CUR);
|
||||
if (seeked<0) {
|
||||
qdebug(
|
||||
printf("qfits: error seeking file %s\n", filename);
|
||||
if (seeked < 0)
|
||||
{
|
||||
qdebug (printf ("qfits: error seeking file %s\n", filename);
|
||||
);
|
||||
free (qc->name);
|
||||
fclose (in);
|
||||
|
@ -626,8 +658,10 @@ static int qfits_cache_add(char * filename)
|
|||
|
||||
/* Look for extension start */
|
||||
found_it = 0;
|
||||
while ((found_it==0) && (end_of_file==0)) {
|
||||
if (fread(buf,1,FITS_BLOCK_SIZE,in)!=FITS_BLOCK_SIZE) {
|
||||
while ((found_it == 0) && (end_of_file == 0))
|
||||
{
|
||||
if (fread (buf, 1, FITS_BLOCK_SIZE, in) != FITS_BLOCK_SIZE)
|
||||
{
|
||||
/* Reached end of file */
|
||||
end_of_file = 1;
|
||||
break;
|
||||
|
@ -640,24 +674,24 @@ static int qfits_cache_add(char * filename)
|
|||
buf[3] == 'N' &&
|
||||
buf[4] == 'S' &&
|
||||
buf[5] == 'I' &&
|
||||
buf[6]=='O' &&
|
||||
buf[7]=='N' &&
|
||||
buf[8]=='=') {
|
||||
buf[6] == 'O' && buf[7] == 'N' && buf[8] == '=')
|
||||
{
|
||||
/* Got an extension */
|
||||
found_it = 1;
|
||||
off_hdr[last] = n_blocks - 1;
|
||||
}
|
||||
}
|
||||
if (end_of_file) break ;
|
||||
if (end_of_file)
|
||||
break;
|
||||
|
||||
/*
|
||||
* Look for extension END
|
||||
* Rewind one block backwards, END might be in same section as
|
||||
* XTENSION start.
|
||||
*/
|
||||
if (fseek(in, -FITS_BLOCK_SIZE, SEEK_CUR)==-1) {
|
||||
qdebug(
|
||||
printf("qfits: error fseeking file backwards\n");
|
||||
if (fseek (in, -FITS_BLOCK_SIZE, SEEK_CUR) == -1)
|
||||
{
|
||||
qdebug (printf ("qfits: error fseeking file backwards\n");
|
||||
);
|
||||
free (qc->name);
|
||||
fclose (in);
|
||||
|
@ -667,10 +701,12 @@ static int qfits_cache_add(char * filename)
|
|||
found_it = 0;
|
||||
data_bytes = 1;
|
||||
naxis = 0;
|
||||
while ((found_it==0) && (end_of_file==0)) {
|
||||
if (fread(buf,1,FITS_BLOCK_SIZE,in)!=FITS_BLOCK_SIZE) {
|
||||
qdebug(
|
||||
printf("qfits: XTENSION without END in %s\n", filename);
|
||||
while ((found_it == 0) && (end_of_file == 0))
|
||||
{
|
||||
if (fread (buf, 1, FITS_BLOCK_SIZE, in) != FITS_BLOCK_SIZE)
|
||||
{
|
||||
qdebug (printf
|
||||
("qfits: XTENSION without END in %s\n", filename);
|
||||
);
|
||||
end_of_file = 1;
|
||||
break;
|
||||
|
@ -679,41 +715,45 @@ static int qfits_cache_add(char * filename)
|
|||
|
||||
/* Browse current block */
|
||||
buf_c = buf;
|
||||
for (i=0 ; i<FITS_NCARDS ; i++) {
|
||||
for (i = 0; i < FITS_NCARDS; i++)
|
||||
{
|
||||
/* Look for BITPIX keyword */
|
||||
if (buf_c[0] == 'B' &&
|
||||
buf_c[1] == 'I' &&
|
||||
buf_c[2] == 'T' &&
|
||||
buf_c[3] == 'P' &&
|
||||
buf_c[4]=='I' &&
|
||||
buf_c[5]=='X' &&
|
||||
buf_c[6]==' ') {
|
||||
buf_c[4] == 'I' && buf_c[5] == 'X' && buf_c[6] == ' ')
|
||||
{
|
||||
read_val = qfits_getvalue (buf_c);
|
||||
data_bytes *= (int) atoi (read_val) / 8;
|
||||
if (data_bytes<0) data_bytes *= -1 ;
|
||||
} else
|
||||
if (data_bytes < 0)
|
||||
data_bytes *= -1;
|
||||
}
|
||||
else
|
||||
/* Look for NAXIS keyword */
|
||||
if (buf_c[0] == 'N' &&
|
||||
buf_c[1] == 'A' &&
|
||||
buf_c[2]=='X' &&
|
||||
buf_c[3]=='I' &&
|
||||
buf_c[4]=='S') {
|
||||
buf_c[2] == 'X' && buf_c[3] == 'I' && buf_c[4] == 'S')
|
||||
{
|
||||
|
||||
if (buf_c[5]==' ') {
|
||||
if (buf_c[5] == ' ')
|
||||
{
|
||||
/* NAXIS keyword */
|
||||
read_val = qfits_getvalue (buf_c);
|
||||
naxis = (int) atoi (read_val);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* NAXIS?? keyword (axis size) */
|
||||
read_val = qfits_getvalue (buf_c);
|
||||
data_bytes *= (int) atoi (read_val);
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
/* Look for END keyword */
|
||||
if (buf_c[0] == 'E' &&
|
||||
buf_c[1]=='N' &&
|
||||
buf_c[2]=='D' &&
|
||||
buf_c[3]==' ') {
|
||||
buf_c[1] == 'N' && buf_c[2] == 'D' && buf_c[3] == ' ')
|
||||
{
|
||||
/* Got the END card */
|
||||
found_it = 1;
|
||||
/* Update registered extension list */
|
||||
|
@ -737,16 +777,20 @@ static int qfits_cache_add(char * filename)
|
|||
qc->shdr = malloc (last * sizeof (int));
|
||||
qc->dsiz = malloc (last * sizeof (int));
|
||||
/* Store retrieved pointers in the cache */
|
||||
for (i=0 ; i<last ; i++) {
|
||||
for (i = 0; i < last; i++)
|
||||
{
|
||||
/* Offsets to start */
|
||||
qc->ohdr[i] = off_hdr[i];
|
||||
qc->data[i] = off_dat[i];
|
||||
|
||||
/* Sizes */
|
||||
qc->shdr[i] = off_dat[i] - off_hdr[i];
|
||||
if (i==last-1) {
|
||||
if (i == last - 1)
|
||||
{
|
||||
qc->dsiz[i] = (sta.st_size / FITS_BLOCK_SIZE) - off_dat[i];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
qc->dsiz[i] = off_hdr[i + 1] - off_dat[i];
|
||||
}
|
||||
}
|
||||
|
@ -757,8 +801,7 @@ static int qfits_cache_add(char * filename)
|
|||
qc->ctime = sta.st_ctime;
|
||||
qfits_cache_entries++;
|
||||
|
||||
qdebug(
|
||||
qfits_cache_dump();
|
||||
qdebug (qfits_cache_dump ();
|
||||
);
|
||||
/* Return index of the added file in the cache */
|
||||
return qfits_cache_last;
|
||||
|
|
|
@ -40,15 +40,18 @@
|
|||
@return string
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char * expkey_strupc(const char * s)
|
||||
static char *
|
||||
expkey_strupc (const char *s)
|
||||
{
|
||||
static char l[ASCIILINESZ + 1];
|
||||
int i;
|
||||
|
||||
if (s==NULL) return NULL ;
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
memset (l, 0, ASCIILINESZ + 1);
|
||||
i = 0;
|
||||
while (s[i] && i<ASCIILINESZ) {
|
||||
while (s[i] && i < ASCIILINESZ)
|
||||
{
|
||||
l[i] = (char) toupper ((int) s[i]);
|
||||
i++;
|
||||
}
|
||||
|
@ -76,16 +79,19 @@ static char * expkey_strupc(const char * s)
|
|||
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];
|
||||
char ws[81];
|
||||
char *token;
|
||||
|
||||
/* Bulletproof entries */
|
||||
if (keyword==NULL) return NULL ;
|
||||
if (keyword == NULL)
|
||||
return NULL;
|
||||
/* If regular keyword, copy the uppercased input and return */
|
||||
if (strstr(keyword, ".")==NULL) {
|
||||
if (strstr (keyword, ".") == NULL)
|
||||
{
|
||||
strcpy (expanded, expkey_strupc (keyword));
|
||||
return expanded;
|
||||
}
|
||||
|
@ -93,11 +99,13 @@ char * qfits_expand_keyword(const char * keyword)
|
|||
sprintf (expanded, "HIERARCH ESO");
|
||||
strcpy (ws, expkey_strupc (keyword));
|
||||
token = strtok (ws, ".");
|
||||
while (token!=NULL) {
|
||||
while (token != NULL)
|
||||
{
|
||||
strcat (expanded, " ");
|
||||
strcat (expanded, token);
|
||||
token = strtok (NULL, ".");
|
||||
}
|
||||
return expanded;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 et sw=4 tw=75 */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,7 +23,8 @@
|
|||
#define FITS_HEADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
@ -50,7 +51,8 @@ extern "C" {
|
|||
accessor functions.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct qfits_header {
|
||||
typedef struct qfits_header
|
||||
{
|
||||
void *first; /* Pointer to list start */
|
||||
void *last; /* Pointer to list end */
|
||||
int n; /* Number of cards in list */
|
||||
|
@ -99,12 +101,8 @@ qfits_header * qfits_header_default(void) ;
|
|||
are allowed to get NULL values.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void qfits_header_add(
|
||||
qfits_header * hdr,
|
||||
char * key,
|
||||
char * val,
|
||||
char * com,
|
||||
char * lin) ;
|
||||
void qfits_header_add (qfits_header * hdr,
|
||||
char *key, char *val, char *com, char *lin);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -122,13 +120,9 @@ void qfits_header_add(
|
|||
can be NULL, except after and key.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void qfits_header_add_after(
|
||||
qfits_header * hdr,
|
||||
void qfits_header_add_after (qfits_header * hdr,
|
||||
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.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void qfits_header_append(
|
||||
qfits_header * hdr,
|
||||
void qfits_header_append (qfits_header * hdr,
|
||||
const char *key,
|
||||
const char *val,
|
||||
const char * com,
|
||||
const char * lin) ;
|
||||
const char *com, const char *lin);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -312,13 +304,9 @@ char * qfits_header_findmatch(qfits_header * hdr, char * key) ;
|
|||
available in this module.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_header_getitem(
|
||||
qfits_header * hdr,
|
||||
int qfits_header_getitem (qfits_header * hdr,
|
||||
int idx,
|
||||
char * key,
|
||||
char * val,
|
||||
char * com,
|
||||
char * lin) ;
|
||||
char *key, char *val, char *com, char *lin);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -381,7 +369,8 @@ int qfits_header_getint(qfits_header * hdr, const char * key, int errval) ;
|
|||
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'.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_header_getboolean(qfits_header * hdr, const char * key, int errval) ;
|
||||
int qfits_header_getboolean (qfits_header * hdr, const char *key,
|
||||
int errval);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,8 @@
|
|||
of error.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_datamd5(char * filename)
|
||||
char *
|
||||
qfits_datamd5 (char *filename)
|
||||
{
|
||||
static char datamd5[MD5HASHSZ + 1];
|
||||
struct MD5Context ctx;
|
||||
|
@ -71,9 +72,11 @@ char * qfits_datamd5(char * filename)
|
|||
int check_fits;
|
||||
|
||||
/* Check entries */
|
||||
if (filename==NULL) return NULL ;
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
/* Open input file */
|
||||
if ((in=fopen(filename, "r"))==NULL) {
|
||||
if ((in = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
qfits_error ("cannot open file %s", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -82,9 +85,11 @@ char * qfits_datamd5(char * filename)
|
|||
in_header = 1;
|
||||
check_fits = 0;
|
||||
/* 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) {
|
||||
if (check_fits == 0)
|
||||
{
|
||||
/* Examine first characters in block */
|
||||
if (buf[0] != 'S' ||
|
||||
buf[1] != 'I' ||
|
||||
|
@ -92,29 +97,33 @@ char * qfits_datamd5(char * filename)
|
|||
buf[3] != 'P' ||
|
||||
buf[4] != 'L' ||
|
||||
buf[5] != 'E' ||
|
||||
buf[6]!=' ' ||
|
||||
buf[7]!=' ' ||
|
||||
buf[8]!='=') {
|
||||
buf[6] != ' ' || buf[7] != ' ' || buf[8] != '=')
|
||||
{
|
||||
qfits_error ("file [%s] is not FITS\n", filename);
|
||||
fclose (in);
|
||||
return NULL;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
check_fits = 1;
|
||||
}
|
||||
}
|
||||
if (in_header) {
|
||||
if (in_header)
|
||||
{
|
||||
buf_c = buf;
|
||||
for (i=0 ; i<FITS_NCARDS ; i++) {
|
||||
for (i = 0; i < FITS_NCARDS; i++)
|
||||
{
|
||||
if (buf_c[0] == 'E' &&
|
||||
buf_c[1]=='N' &&
|
||||
buf_c[2]=='D' &&
|
||||
buf_c[3]==' ') {
|
||||
buf_c[1] == 'N' && buf_c[2] == 'D' && buf_c[3] == ' ')
|
||||
{
|
||||
in_header = 0;
|
||||
break;
|
||||
}
|
||||
buf_c += FITS_LINESZ;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If current block is a data block */
|
||||
/* Try to locate an extension header */
|
||||
if (buf[0] == 'X' &&
|
||||
|
@ -123,30 +132,32 @@ char * qfits_datamd5(char * filename)
|
|||
buf[3] == 'N' &&
|
||||
buf[4] == 'S' &&
|
||||
buf[5] == 'I' &&
|
||||
buf[6]=='O' &&
|
||||
buf[7]=='N' &&
|
||||
buf[8]=='=') {
|
||||
buf[6] == 'O' && buf[7] == 'N' && buf[8] == '=')
|
||||
{
|
||||
in_header = 1;
|
||||
buf_c = buf;
|
||||
for (i=0 ; i<FITS_NCARDS ; i++) {
|
||||
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]==' ') {
|
||||
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 {
|
||||
}
|
||||
else
|
||||
{
|
||||
MD5Update (&ctx, (unsigned char *) buf, FITS_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (in);
|
||||
if (check_fits==0) {
|
||||
if (check_fits == 0)
|
||||
{
|
||||
/* Never went through the read loop: file is not FITS */
|
||||
qfits_error ("file [%s] is not FITS", filename);
|
||||
return NULL;
|
||||
|
@ -167,11 +178,7 @@ char * qfits_datamd5(char * filename)
|
|||
digest[8],
|
||||
digest[9],
|
||||
digest[10],
|
||||
digest[11],
|
||||
digest[12],
|
||||
digest[13],
|
||||
digest[14],
|
||||
digest[15]);
|
||||
digest[11], digest[12], digest[13], digest[14], digest[15]);
|
||||
return datamd5;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,12 +50,14 @@
|
|||
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];
|
||||
int i;
|
||||
|
||||
if (line==NULL) {
|
||||
if (line == NULL)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getkey: NULL input line\n");
|
||||
#endif
|
||||
|
@ -63,20 +65,24 @@ char * qfits_getkey(char * line)
|
|||
}
|
||||
|
||||
/* Special case: blank keyword */
|
||||
if (!strncmp(line, " ", 8)) {
|
||||
if (!strncmp (line, " ", 8))
|
||||
{
|
||||
strcpy (key, " ");
|
||||
return key;
|
||||
}
|
||||
/* Sort out special cases: HISTORY, COMMENT, END do not have = in line */
|
||||
if (!strncmp(line, "HISTORY ", 8)) {
|
||||
if (!strncmp (line, "HISTORY ", 8))
|
||||
{
|
||||
strcpy (key, "HISTORY");
|
||||
return key;
|
||||
}
|
||||
if (!strncmp(line, "COMMENT ", 8)) {
|
||||
if (!strncmp (line, "COMMENT ", 8))
|
||||
{
|
||||
strcpy (key, "COMMENT");
|
||||
return key;
|
||||
}
|
||||
if (!strncmp(line, "END ", 4)) {
|
||||
if (!strncmp (line, "END ", 4))
|
||||
{
|
||||
strcpy (key, "END");
|
||||
return key;
|
||||
}
|
||||
|
@ -84,8 +90,10 @@ char * qfits_getkey(char * line)
|
|||
memset (key, 0, 81);
|
||||
/* General case: look for the first equal sign */
|
||||
i = 0;
|
||||
while (line[i]!='=' && i<80) i++ ;
|
||||
if (i>=80) {
|
||||
while (line[i] != '=' && i < 80)
|
||||
i++;
|
||||
if (i >= 80)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getkey: cannot find equal sign\n");
|
||||
#endif
|
||||
|
@ -93,8 +101,10 @@ char * qfits_getkey(char * line)
|
|||
}
|
||||
i--;
|
||||
/* Equal sign found, now backtrack on blanks */
|
||||
while (line[i]==' ' && i>=0) i-- ;
|
||||
if (i<=0) {
|
||||
while (line[i] == ' ' && i >= 0)
|
||||
i--;
|
||||
if (i <= 0)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getkey: error backtracking on blanks\n");
|
||||
#endif
|
||||
|
@ -121,14 +131,16 @@ char * qfits_getkey(char * line)
|
|||
modify or try to free it.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_getvalue(char * line)
|
||||
char *
|
||||
qfits_getvalue (char *line)
|
||||
{
|
||||
static char value[81];
|
||||
int i;
|
||||
int from, to;
|
||||
int inq;
|
||||
|
||||
if (line==NULL) {
|
||||
if (line == NULL)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getvalue: NULL input line\n");
|
||||
#endif
|
||||
|
@ -138,7 +150,8 @@ char * qfits_getvalue(char * line)
|
|||
/* Special cases */
|
||||
|
||||
/* END has no associated value */
|
||||
if (!strncmp(line, "END ", 4)) {
|
||||
if (!strncmp (line, "END ", 4))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
|
@ -147,34 +160,44 @@ char * qfits_getvalue(char * line)
|
|||
*/
|
||||
memset (value, 0, 81);
|
||||
|
||||
if (!strncmp(line, "HISTORY ", 8) || !strncmp(line, " ", 8)) {
|
||||
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 */
|
||||
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-- ;
|
||||
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)) {
|
||||
}
|
||||
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 ;
|
||||
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-- ;
|
||||
while (line[to] == ' ')
|
||||
to--;
|
||||
|
||||
if (to<from) {
|
||||
if (to < from)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getvalue: inconsistent value search in COMMENT\n");
|
||||
#endif
|
||||
|
@ -188,16 +211,20 @@ char * qfits_getvalue(char * line)
|
|||
}
|
||||
/* General case - Get past the keyword */
|
||||
i = 0;
|
||||
while (line[i]!='=' && i<80) i++ ;
|
||||
if (i>80) {
|
||||
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) {
|
||||
while (line[i] == ' ' && i < 80)
|
||||
i++;
|
||||
if (i > 80)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getvalue: no value past the equal sign\n");
|
||||
#endif
|
||||
|
@ -207,7 +234,8 @@ char * qfits_getvalue(char * line)
|
|||
|
||||
/* Now value section: Look for the first slash '/' outside a string */
|
||||
inq = 0;
|
||||
while (i<80) {
|
||||
while (i < 80)
|
||||
{
|
||||
if (line[i] == '\'')
|
||||
inq = !inq;
|
||||
if (line[i] == '/')
|
||||
|
@ -218,8 +246,10 @@ char * qfits_getvalue(char * line)
|
|||
i--;
|
||||
|
||||
/* Backtrack on blanks */
|
||||
while (line[i]==' ' && i>=0) i-- ;
|
||||
if (i<0) {
|
||||
while (line[i] == ' ' && i >= 0)
|
||||
i--;
|
||||
if (i < 0)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getvalue: error backtracking on blanks\n");
|
||||
#endif
|
||||
|
@ -227,7 +257,8 @@ char * qfits_getvalue(char * line)
|
|||
}
|
||||
to = i;
|
||||
|
||||
if (to<from) {
|
||||
if (to < from)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getvalue: from>to?\n");
|
||||
printf ("line=[%s]\n", line);
|
||||
|
@ -253,14 +284,16 @@ char * qfits_getvalue(char * line)
|
|||
modify or try to free it.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_getcomment(char * line)
|
||||
char *
|
||||
qfits_getcomment (char *line)
|
||||
{
|
||||
static char comment[81];
|
||||
int i;
|
||||
int from, to;
|
||||
int inq;
|
||||
|
||||
if (line==NULL) {
|
||||
if (line == NULL)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getcomment: null line in input\n");
|
||||
#endif
|
||||
|
@ -268,16 +301,22 @@ char * qfits_getcomment(char * line)
|
|||
}
|
||||
|
||||
/* Special cases: END, HISTORY, COMMENT and blank have no comment */
|
||||
if (!strncmp(line, "END ", 4)) return NULL ;
|
||||
if (!strncmp(line, "HISTORY ", 8)) return NULL ;
|
||||
if (!strncmp(line, "COMMENT ", 8)) return NULL ;
|
||||
if (!strncmp(line, " ", 8)) return NULL ;
|
||||
if (!strncmp (line, "END ", 4))
|
||||
return NULL;
|
||||
if (!strncmp (line, "HISTORY ", 8))
|
||||
return NULL;
|
||||
if (!strncmp (line, "COMMENT ", 8))
|
||||
return NULL;
|
||||
if (!strncmp (line, " ", 8))
|
||||
return NULL;
|
||||
|
||||
memset (comment, 0, 81);
|
||||
/* Get past the keyword */
|
||||
i = 0;
|
||||
while (line[i]!='=' && i<80) i++ ;
|
||||
if (i>=80) {
|
||||
while (line[i] != '=' && i < 80)
|
||||
i++;
|
||||
if (i >= 80)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getcomment: no equal sign on line\n");
|
||||
#endif
|
||||
|
@ -287,7 +326,8 @@ char * qfits_getcomment(char * line)
|
|||
|
||||
/* Get past the value until the slash */
|
||||
inq = 0;
|
||||
while (i<80) {
|
||||
while (i < 80)
|
||||
{
|
||||
if (line[i] == '\'')
|
||||
inq = !inq;
|
||||
if (line[i] == '/')
|
||||
|
@ -295,7 +335,8 @@ char * qfits_getcomment(char * line)
|
|||
break;
|
||||
i++;
|
||||
}
|
||||
if (i>=80) {
|
||||
if (i >= 80)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getcomment: no slash found on line\n");
|
||||
#endif
|
||||
|
@ -303,14 +344,17 @@ char * qfits_getcomment(char * line)
|
|||
}
|
||||
i++;
|
||||
/* Get past the first blanks */
|
||||
while (line[i]==' ') i++ ;
|
||||
while (line[i] == ' ')
|
||||
i++;
|
||||
from = i;
|
||||
|
||||
/* Now backtrack from the end of the line to the first non-blank char */
|
||||
to = 79;
|
||||
while (line[to]==' ') to-- ;
|
||||
while (line[to] == ' ')
|
||||
to--;
|
||||
|
||||
if (to<from) {
|
||||
if (to < from)
|
||||
{
|
||||
#ifdef DEBUG_FITSHEADER
|
||||
printf ("qfits_getcomment: from>to?\n");
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#define FITSEP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* <dox> */
|
||||
|
|
|
@ -35,12 +35,15 @@
|
|||
/*-----------------------------------------------------------------------------
|
||||
Private to this module
|
||||
-----------------------------------------------------------------------------*/
|
||||
static int is_blank_line(char * s)
|
||||
static int
|
||||
is_blank_line (char *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0 ; i<(int)strlen(s) ; i++) {
|
||||
if (s[i]!=' ') return 0 ;
|
||||
for (i = 0; i < (int) strlen (s); i++)
|
||||
{
|
||||
if (s[i] != ' ')
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -70,7 +73,8 @@ static int is_blank_line(char * s)
|
|||
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 */
|
||||
return qfits_header_readext (filename, 0);
|
||||
|
@ -88,24 +92,25 @@ qfits_header * qfits_header_read(char * filename)
|
|||
a hdr file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_header * qfits_header_read_hdr(char * filename)
|
||||
qfits_header *
|
||||
qfits_header_read_hdr (char *filename)
|
||||
{
|
||||
qfits_header *hdr;
|
||||
FILE *in;
|
||||
char line[81];
|
||||
char * key,
|
||||
* val,
|
||||
* com ;
|
||||
char *key, *val, *com;
|
||||
int i, j;
|
||||
|
||||
/* Check input */
|
||||
if (filename==NULL) return NULL ;
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Initialise */
|
||||
key = val = com = NULL;
|
||||
|
||||
/* Open the file */
|
||||
if ((in=fopen(filename, "r"))==NULL) {
|
||||
if ((in = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
qfits_error ("cannot read [%s]", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -114,21 +119,27 @@ qfits_header * qfits_header_read_hdr(char * filename)
|
|||
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] = ' ' ;
|
||||
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")) {
|
||||
if (!strcmp (line, "END"))
|
||||
{
|
||||
line[3] = ' ';
|
||||
line[4] = (char) 0;
|
||||
}
|
||||
|
||||
/* Rule out blank lines */
|
||||
if (!is_blank_line(line)) {
|
||||
if (!is_blank_line (line))
|
||||
{
|
||||
|
||||
/* Get key, value, comment for the current line */
|
||||
key = qfits_getkey (line);
|
||||
|
@ -136,7 +147,8 @@ qfits_header * qfits_header_read_hdr(char * filename)
|
|||
com = qfits_getcomment (line);
|
||||
|
||||
/* If key or value cannot be found, trigger an error */
|
||||
if (key==NULL) {
|
||||
if (key == NULL)
|
||||
{
|
||||
qfits_header_destroy (hdr);
|
||||
fclose (in);
|
||||
return NULL;
|
||||
|
@ -148,11 +160,13 @@ qfits_header * qfits_header_read_hdr(char * filename)
|
|||
fclose (in);
|
||||
|
||||
/* The last key should be 'END' */
|
||||
if (strlen(key)!=3) {
|
||||
if (strlen (key) != 3)
|
||||
{
|
||||
qfits_header_destroy (hdr);
|
||||
return NULL;
|
||||
}
|
||||
if (key[0]!='E' || key[1]!='N' || key[2]!='D') {
|
||||
if (key[0] != 'E' || key[1] != 'N' || key[2] != 'D')
|
||||
{
|
||||
qfits_header_destroy (hdr);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -171,20 +185,18 @@ qfits_header * qfits_header_read_hdr(char * filename)
|
|||
object.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_header * qfits_header_read_hdr_string(
|
||||
unsigned char * hdr_str,
|
||||
int nb_char)
|
||||
qfits_header *
|
||||
qfits_header_read_hdr_string (unsigned char *hdr_str, int nb_char)
|
||||
{
|
||||
qfits_header *hdr;
|
||||
char line[81];
|
||||
char * key,
|
||||
* val,
|
||||
* com ;
|
||||
char *key, *val, *com;
|
||||
int ind;
|
||||
int i, j;
|
||||
|
||||
/* Check input */
|
||||
if (hdr_str==NULL) return NULL ;
|
||||
if (hdr_str == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Initialise */
|
||||
key = val = com = NULL;
|
||||
|
@ -194,23 +206,29 @@ qfits_header * qfits_header_read_hdr_string(
|
|||
|
||||
/* Go through the file */
|
||||
ind = 0;
|
||||
while (ind <= nb_char - 80) {
|
||||
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] = ' ' ;
|
||||
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")) {
|
||||
if (!strcmp (line, "END"))
|
||||
{
|
||||
line[3] = ' ';
|
||||
line[4] = (char) 0;
|
||||
}
|
||||
|
||||
/* Rule out blank lines */
|
||||
if (!is_blank_line(line)) {
|
||||
if (!is_blank_line (line))
|
||||
{
|
||||
|
||||
/* Get key, value, comment for the current line */
|
||||
key = qfits_getkey (line);
|
||||
|
@ -218,7 +236,8 @@ qfits_header * qfits_header_read_hdr_string(
|
|||
com = qfits_getcomment (line);
|
||||
|
||||
/* If key or value cannot be found, trigger an error */
|
||||
if (key==NULL) {
|
||||
if (key == NULL)
|
||||
{
|
||||
qfits_header_destroy (hdr);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -229,11 +248,13 @@ qfits_header * qfits_header_read_hdr_string(
|
|||
}
|
||||
|
||||
/* The last key should be 'END' */
|
||||
if (strlen(key)!=3) {
|
||||
if (strlen (key) != 3)
|
||||
{
|
||||
qfits_header_destroy (hdr);
|
||||
return NULL;
|
||||
}
|
||||
if (key[0]!='E' || key[1]!='N' || key[2]!='D') {
|
||||
if (key[0] != 'E' || key[1] != 'N' || key[2] != 'D')
|
||||
{
|
||||
qfits_header_destroy (hdr);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -255,16 +276,15 @@ qfits_header * qfits_header_read_hdr_string(
|
|||
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;
|
||||
int n_ext;
|
||||
char line[81];
|
||||
char *where;
|
||||
char *start;
|
||||
char * key,
|
||||
* val,
|
||||
* com ;
|
||||
char *key, *val, *com;
|
||||
int seg_start;
|
||||
int seg_size;
|
||||
size_t size;
|
||||
|
@ -274,30 +294,36 @@ qfits_header * qfits_header_readext(char * filename, int xtnum)
|
|||
return NULL;
|
||||
|
||||
/* Check that there are enough extensions */
|
||||
if (xtnum>0) {
|
||||
if (xtnum > 0)
|
||||
{
|
||||
n_ext = qfits_query_n_ext (filename);
|
||||
if (xtnum>n_ext) {
|
||||
if (xtnum > n_ext)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Memory-map the input file */
|
||||
start = falloc (filename, seg_start, &size);
|
||||
if (start==NULL) return NULL ;
|
||||
if (start == NULL)
|
||||
return NULL;
|
||||
|
||||
hdr = qfits_header_new ();
|
||||
where = start;
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
memcpy (line, where, 80);
|
||||
line[80] = (char) 0;
|
||||
|
||||
/* Rule out blank lines */
|
||||
if (!is_blank_line(line)) {
|
||||
if (!is_blank_line (line))
|
||||
{
|
||||
|
||||
/* Get key, value, comment for the current line */
|
||||
key = qfits_getkey (line);
|
||||
|
@ -305,7 +331,8 @@ qfits_header * qfits_header_readext(char * filename, int xtnum)
|
|||
com = qfits_getcomment (line);
|
||||
|
||||
/* If key or value cannot be found, trigger an error */
|
||||
if (key==NULL) {
|
||||
if (key == NULL)
|
||||
{
|
||||
qfits_header_destroy (hdr);
|
||||
hdr = NULL;
|
||||
break;
|
||||
|
@ -314,14 +341,13 @@ qfits_header * qfits_header_readext(char * filename, int xtnum)
|
|||
qfits_header_append (hdr, key, val, com, line);
|
||||
/* Check for END keyword */
|
||||
if (strlen (key) == 3)
|
||||
if (key[0]=='E' &&
|
||||
key[1]=='N' &&
|
||||
key[2]=='D')
|
||||
if (key[0] == 'E' && key[1] == 'N' && key[2] == 'D')
|
||||
break;
|
||||
}
|
||||
where += 80;
|
||||
/* 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);
|
||||
hdr = NULL;
|
||||
break;
|
||||
|
@ -341,7 +367,8 @@ qfits_header * qfits_header_readext(char * filename, int xtnum)
|
|||
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;
|
||||
int size;
|
||||
|
@ -349,16 +376,19 @@ void qfits_zeropad(char * filename)
|
|||
FILE *out;
|
||||
char *buf;
|
||||
|
||||
if (filename==NULL) return ;
|
||||
if (filename == NULL)
|
||||
return;
|
||||
|
||||
/* Get file size in bytes */
|
||||
if (stat(filename, &sta)!=0) {
|
||||
if (stat (filename, &sta) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
size = (int) sta.st_size;
|
||||
/* Compute number of zeros to pad */
|
||||
remaining = size % FITS_BLOCK_SIZE;
|
||||
if (remaining==0) return ;
|
||||
if (remaining == 0)
|
||||
return;
|
||||
remaining = FITS_BLOCK_SIZE - remaining;
|
||||
|
||||
/* Open file, dump zeros, exit */
|
||||
|
@ -381,14 +411,17 @@ void qfits_zeropad(char * filename)
|
|||
0 else. If the file does not exist, returns -1.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int is_fits_file(char *filename)
|
||||
int
|
||||
is_fits_file (char *filename)
|
||||
{
|
||||
FILE *fp;
|
||||
char *magic;
|
||||
int isfits;
|
||||
|
||||
if (filename==NULL) return -1 ;
|
||||
if ((fp = fopen(filename, "r"))==NULL) {
|
||||
if (filename == NULL)
|
||||
return -1;
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
qfits_error ("cannot open file [%s]", filename);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#define FITS_RW_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
@ -82,8 +83,7 @@ qfits_header * qfits_header_read_hdr(char * filename) ;
|
|||
object.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_header * qfits_header_read_hdr_string(
|
||||
unsigned char * hdr_str,
|
||||
qfits_header *qfits_header_read_hdr_string (unsigned char *hdr_str,
|
||||
int nb_char);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -89,12 +89,14 @@
|
|||
@endverbatim
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_get_dir_name(char * filename)
|
||||
char *
|
||||
qfits_get_dir_name (char *filename)
|
||||
{
|
||||
static char path[MAXNAMESZ];
|
||||
char *last_slash;
|
||||
|
||||
if (strlen(filename)>MAXNAMESZ) return NULL ;
|
||||
if (strlen (filename) > MAXNAMESZ)
|
||||
return NULL;
|
||||
strcpy (path, filename);
|
||||
/* Find last '/'. */
|
||||
last_slash = path != NULL ? strrchr (path, '/') : NULL;
|
||||
|
@ -138,7 +140,8 @@ char * qfits_get_dir_name(char * filename)
|
|||
@endverbatim
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_get_base_name(const char *filename)
|
||||
char *
|
||||
qfits_get_base_name (const char *filename)
|
||||
{
|
||||
char *p;
|
||||
p = strrchr (filename, '/');
|
||||
|
@ -176,16 +179,19 @@ char * qfits_get_base_name(const char *filename)
|
|||
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];
|
||||
char *lastdot;
|
||||
|
||||
if (strlen(filename)>MAXNAMESZ) return NULL ;
|
||||
if (strlen (filename) > MAXNAMESZ)
|
||||
return NULL;
|
||||
memset (path, MAXNAMESZ, 0);
|
||||
strcpy (path, filename);
|
||||
lastdot = strrchr (path, '.');
|
||||
if (lastdot == NULL) return path ;
|
||||
if (lastdot == NULL)
|
||||
return path;
|
||||
if ((!strcmp (lastdot, ".fits")) || (!strcmp (lastdot, ".FITS")) ||
|
||||
(!strcmp (lastdot, ".paf")) || (!strcmp (lastdot, ".PAF")) ||
|
||||
(!strcmp (lastdot, ".dat")) || (!strcmp (lastdot, ".DAT")) ||
|
||||
|
@ -219,7 +225,8 @@ char * qfits_get_root_name(char * filename)
|
|||
@endverbatim
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_get_ext_name(char * filename)
|
||||
char *
|
||||
qfits_get_ext_name (char *filename)
|
||||
{
|
||||
char *p;
|
||||
p = strrchr (filename, '.');
|
||||
|
@ -240,17 +247,20 @@ char * qfits_get_ext_name(char * filename)
|
|||
string which first character is a null character.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_get_login_name(void)
|
||||
char *
|
||||
qfits_get_login_name (void)
|
||||
{
|
||||
struct passwd *pw;
|
||||
static char name[32];
|
||||
|
||||
pw = getpwuid (getuid ());
|
||||
if (pw!=NULL) {
|
||||
if (pw != NULL)
|
||||
{
|
||||
strcpy (name, pw->pw_name);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
name[0] = 0;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#define GET_NAME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -38,25 +38,30 @@
|
|||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
/* Little endian ordering */
|
||||
typedef union _ieee_double_pattern_ {
|
||||
typedef union _ieee_double_pattern_
|
||||
{
|
||||
double d;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
unsigned int lsw;
|
||||
unsigned int msw;
|
||||
} p;
|
||||
} ieee_double_pattern;
|
||||
#else
|
||||
/* Big endian ordering */
|
||||
typedef union _ieee_double_pattern_ {
|
||||
typedef union _ieee_double_pattern_
|
||||
{
|
||||
double d;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
unsigned int msw;
|
||||
unsigned int lsw;
|
||||
} p;
|
||||
} ieee_double_pattern;
|
||||
#endif
|
||||
|
||||
typedef union _ieee_float_pattern_ {
|
||||
typedef union _ieee_float_pattern_
|
||||
{
|
||||
float f;
|
||||
int i;
|
||||
} ieee_float_pattern;
|
||||
|
@ -65,7 +70,8 @@ typedef union _ieee_float_pattern_ {
|
|||
Function codes
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
int _qfits_isnanf(float f)
|
||||
int
|
||||
_qfits_isnanf (float f)
|
||||
{
|
||||
ieee_float_pattern ip;
|
||||
int ix;
|
||||
|
@ -77,7 +83,8 @@ int _qfits_isnanf(float f)
|
|||
return (int) (((unsigned int) (ix)) >> 31);
|
||||
}
|
||||
|
||||
int _qfits_isinff(float f)
|
||||
int
|
||||
_qfits_isinff (float f)
|
||||
{
|
||||
ieee_float_pattern ip;
|
||||
int ix, t;
|
||||
|
@ -90,7 +97,8 @@ int _qfits_isinff(float f)
|
|||
return ~(t >> 31) & (ix >> 30);
|
||||
}
|
||||
|
||||
int _qfits_isnand(double d)
|
||||
int
|
||||
_qfits_isnand (double d)
|
||||
{
|
||||
ieee_double_pattern id;
|
||||
int hx, lx;
|
||||
|
@ -105,7 +113,8 @@ int _qfits_isnand(double d)
|
|||
return (int) (((unsigned int) hx) >> 31);
|
||||
}
|
||||
|
||||
int _qfits_isinfd(double d)
|
||||
int
|
||||
_qfits_isinfd (double d)
|
||||
{
|
||||
ieee_double_pattern id;
|
||||
int hx, lx;
|
||||
|
@ -138,6 +147,7 @@ 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 dinf_pat[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
|
||||
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, 0x7f };
|
||||
#else
|
||||
|
@ -150,16 +160,19 @@ static unsigned char fminf_pat[] = {0xff, 0x80, 0, 0};
|
|||
static unsigned char dminf_pat[] = { 0xff, 0xf0, 0, 0, 0, 0, 0, 0 };
|
||||
#endif
|
||||
|
||||
static void hexdump(void * p, int s)
|
||||
static void
|
||||
hexdump (void *p, int s)
|
||||
{
|
||||
unsigned char *c;
|
||||
int i;
|
||||
|
||||
c = (unsigned char *) p;
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
for (i=s-1 ; i>=0 ; i--) {
|
||||
for (i = s - 1; i >= 0; i--)
|
||||
{
|
||||
#else
|
||||
for (i=0 ; i<s ; i++) {
|
||||
for (i = 0; i < s; i++)
|
||||
{
|
||||
#endif
|
||||
printf ("%02x", c[i]);
|
||||
}
|
||||
|
@ -167,7 +180,8 @@ static void hexdump(void * p, int s)
|
|||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
float f;
|
||||
double d;
|
||||
|
@ -179,10 +193,12 @@ int main(void)
|
|||
hexdump (&f, sizeof (float));
|
||||
hexdump (&d, sizeof (double));
|
||||
|
||||
if (qfits_isnan(f)) {
|
||||
if (qfits_isnan (f))
|
||||
{
|
||||
printf ("f is NaN\n");
|
||||
}
|
||||
if (qfits_isnan(d)) {
|
||||
if (qfits_isnan (d))
|
||||
{
|
||||
printf ("d is NaN\n");
|
||||
}
|
||||
|
||||
|
@ -193,10 +209,12 @@ int main(void)
|
|||
hexdump (&f, sizeof (float));
|
||||
hexdump (&d, sizeof (double));
|
||||
|
||||
if (qfits_isinf(f)) {
|
||||
if (qfits_isinf (f))
|
||||
{
|
||||
printf ("f is Inf\n");
|
||||
}
|
||||
if (qfits_isinf(d)) {
|
||||
if (qfits_isinf (d))
|
||||
{
|
||||
printf ("d is Inf\n");
|
||||
}
|
||||
|
||||
|
@ -207,10 +225,12 @@ int main(void)
|
|||
hexdump (&f, sizeof (float));
|
||||
hexdump (&d, sizeof (double));
|
||||
|
||||
if (qfits_isinf(f)) {
|
||||
if (qfits_isinf (f))
|
||||
{
|
||||
printf ("f is (-)Inf\n");
|
||||
}
|
||||
if (qfits_isinf(d)) {
|
||||
if (qfits_isinf (d))
|
||||
{
|
||||
printf ("d is (-)Inf\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -46,22 +46,26 @@ static void byteReverse(unsigned char *buf, unsigned longs) ;
|
|||
/*
|
||||
* 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;
|
||||
do {
|
||||
do
|
||||
{
|
||||
t = (word32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
|
||||
((unsigned) buf[1] << 8 | buf[0]);
|
||||
*(word32 *) buf = t;
|
||||
buf += 4;
|
||||
} while (--longs);
|
||||
}
|
||||
while (--longs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
||||
* initialization constants.
|
||||
*/
|
||||
void MD5Init(struct MD5Context *ctx)
|
||||
void
|
||||
MD5Init (struct MD5Context *ctx)
|
||||
{
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
|
@ -76,7 +80,8 @@ void MD5Init(struct MD5Context *ctx)
|
|||
* Update context to reflect the concatenation of another buffer full
|
||||
* 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;
|
||||
|
||||
|
@ -91,11 +96,13 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
|
|||
|
||||
/* Handle any leading odd-sized chunks */
|
||||
|
||||
if (t) {
|
||||
if (t)
|
||||
{
|
||||
unsigned char *p = (unsigned char *) ctx->in + t;
|
||||
|
||||
t = 64 - t;
|
||||
if (len < t) {
|
||||
if (len < t)
|
||||
{
|
||||
memmove (p, buf, len);
|
||||
return;
|
||||
}
|
||||
|
@ -107,7 +114,8 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
|
|||
}
|
||||
/* Process data in 64-byte chunks */
|
||||
|
||||
while (len >= 64) {
|
||||
while (len >= 64)
|
||||
{
|
||||
memmove (ctx->in, buf, 64);
|
||||
byteReverse (ctx->in, 16);
|
||||
MD5Transform (ctx->buf, (word32 *) ctx->in);
|
||||
|
@ -124,7 +132,8 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
|
|||
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
* 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 char *p;
|
||||
|
@ -141,7 +150,8 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
|||
count = 64 - 1 - count;
|
||||
|
||||
/* 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);
|
||||
byteReverse (ctx->in, 16);
|
||||
|
@ -149,7 +159,9 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
|||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset (ctx->in, 0, 56);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Pad block to 56 bytes */
|
||||
memset (p, 0, count - 8);
|
||||
}
|
||||
|
@ -182,7 +194,8 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
|
|||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||
* 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;
|
||||
|
||||
|
@ -264,4 +277,5 @@ void MD5Transform(word32 buf[4], word32 const in[16])
|
|||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 et sw=4 tw=75 */
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
typedef unsigned int word32;
|
||||
|
||||
struct MD5Context {
|
||||
struct MD5Context
|
||||
{
|
||||
word32 buf[4];
|
||||
word32 bits[2];
|
||||
unsigned char in[64];
|
||||
|
|
|
@ -65,16 +65,15 @@ static char * qfits_strcrop(char * s) ;
|
|||
the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
FILE * qfits_paf_print_header(
|
||||
char * filename,
|
||||
FILE *
|
||||
qfits_paf_print_header (char *filename,
|
||||
char *paf_id,
|
||||
char * paf_desc,
|
||||
char * login_name,
|
||||
char * datetime)
|
||||
char *paf_desc, char *login_name, char *datetime)
|
||||
{
|
||||
FILE *paf;
|
||||
|
||||
if ((paf=fopen(filename, "w"))==NULL) {
|
||||
if ((paf = fopen (filename, "w")) == NULL)
|
||||
{
|
||||
qfits_error ("cannot create PAF file [%s]", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -107,9 +106,8 @@ FILE * qfits_paf_print_header(
|
|||
If the key is not found, this function returns NULL.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_paf_query(
|
||||
char * filename,
|
||||
char * key)
|
||||
char *
|
||||
qfits_paf_query (char *filename, char *key)
|
||||
{
|
||||
static char value[ASCIILINESZ];
|
||||
FILE *paf;
|
||||
|
@ -120,41 +118,50 @@ char * qfits_paf_query(
|
|||
int len;
|
||||
|
||||
/* Check inputs */
|
||||
if (filename==NULL || key==NULL) return NULL ;
|
||||
if (filename == NULL || key == NULL)
|
||||
return NULL;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Open file and read it */
|
||||
paf = fopen (filename, "r");
|
||||
if (paf==NULL) {
|
||||
if (paf == NULL)
|
||||
{
|
||||
qfits_error ("opening [%s]", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
found = 0;
|
||||
while (fgets(line, ASCIILINESZ, paf)!=NULL) {
|
||||
while (fgets (line, ASCIILINESZ, paf) != NULL)
|
||||
{
|
||||
sscanf (line, "%[^ ]", head);
|
||||
if (!strcmp(head, key)) {
|
||||
if (!strcmp (head, key))
|
||||
{
|
||||
/* Get value */
|
||||
sscanf (line, "%*[^ ] %[^;]", value);
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) return NULL ;
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
/* Remove trailing blanks */
|
||||
strcpy (val, qfits_strcrop (value));
|
||||
/* Get rid of possible quotes */
|
||||
len = strlen (val);
|
||||
if (val[0]=='\"' && val[len-1]=='\"') {
|
||||
if (val[0] == '\"' && val[len - 1] == '\"')
|
||||
{
|
||||
strncpy (value, val + 1, len - 2);
|
||||
value[len - 2] = (char) 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy (value, val);
|
||||
}
|
||||
return value;
|
||||
|
@ -170,27 +177,33 @@ char * qfits_paf_query(
|
|||
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;
|
||||
int is_paf;
|
||||
char line[ASCIILINESZ];
|
||||
|
||||
if (filename==NULL) return -1 ;
|
||||
if (filename == NULL)
|
||||
return -1;
|
||||
|
||||
/* Initialize is_paf */
|
||||
is_paf = 0;
|
||||
|
||||
/* Open file */
|
||||
if ((fp = fopen(filename, "r"))==NULL) {
|
||||
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 ;
|
||||
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;
|
||||
}
|
||||
|
@ -214,16 +227,19 @@ int qfits_is_paf_file(char * filename)
|
|||
(not re-entrant).
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char * qfits_strcrop(char * s)
|
||||
static char *
|
||||
qfits_strcrop (char *s)
|
||||
{
|
||||
static char l[ASCIILINESZ + 1];
|
||||
char *last;
|
||||
|
||||
if (s==NULL) return NULL ;
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
memset (l, 0, ASCIILINESZ + 1);
|
||||
strcpy (l, s);
|
||||
last = l + strlen (l);
|
||||
while (last > l) {
|
||||
while (last > l)
|
||||
{
|
||||
if (!isspace ((int) *(last - 1)))
|
||||
break;
|
||||
last--;
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#define PAFS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
@ -65,12 +66,10 @@ extern "C" {
|
|||
the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
FILE * qfits_paf_print_header(
|
||||
char * filename,
|
||||
FILE *qfits_paf_print_header (char *filename,
|
||||
char *paf_id,
|
||||
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.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_paf_query(
|
||||
char * filename,
|
||||
char * key) ;
|
||||
char *qfits_paf_query (char *filename, char *key);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -126,7 +126,8 @@ int main(int argc, char * argv[])
|
|||
@endcode
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct qfitsloader {
|
||||
typedef struct qfitsloader
|
||||
{
|
||||
|
||||
/** Private field to see if structure has been initialized */
|
||||
int _init;
|
||||
|
@ -215,7 +216,8 @@ typedef struct qfitsloader {
|
|||
could have been re-directed).
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct qfitsdumper {
|
||||
typedef struct qfitsdumper
|
||||
{
|
||||
|
||||
/** Name of the file to dump to, "STDOUT" to dump to stdout */
|
||||
char *filename;
|
||||
|
|
|
@ -43,10 +43,15 @@
|
|||
/* Type of a display function only defined for legibility here */
|
||||
typedef void (*qfits_err_dispfunc) (char *);
|
||||
/* Default display function prints out msg to stderr */
|
||||
static void qfits_err_display_stderr(char * s)
|
||||
{ fprintf(stderr, "qfits: %s\n", s); }
|
||||
static void
|
||||
qfits_err_display_stderr (char *s)
|
||||
{
|
||||
fprintf (stderr, "qfits: %s\n", s);
|
||||
}
|
||||
|
||||
/* Static control structure, completely private */
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
qfits_err_dispfunc disp[QFITS_ERR_MAXERRDISP];
|
||||
int n;
|
||||
int active;
|
||||
|
@ -64,7 +69,8 @@ static struct {
|
|||
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;
|
||||
|
||||
|
@ -73,8 +79,10 @@ static void qfits_err_main_display(char * msg)
|
|||
return;
|
||||
|
||||
/* Loop on all registered functions and call them */
|
||||
for (i=0 ; i<qfits_err_control.n ; i++) {
|
||||
if (qfits_err_control.disp[i]) {
|
||||
for (i = 0; i < qfits_err_control.n; i++)
|
||||
{
|
||||
if (qfits_err_control.disp[i])
|
||||
{
|
||||
qfits_err_control.disp[i] (msg);
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +99,8 @@ static void qfits_err_main_display(char * msg)
|
|||
messages using the registered functions, otherwise they do nothing.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_err_statget(void)
|
||||
int
|
||||
qfits_err_statget (void)
|
||||
{
|
||||
return qfits_err_control.active;
|
||||
}
|
||||
|
@ -114,7 +123,8 @@ int qfits_err_statget(void)
|
|||
@endcode
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_err_statset(int sta)
|
||||
int
|
||||
qfits_err_statset (int sta)
|
||||
{
|
||||
int prev;
|
||||
prev = qfits_err_control.active;
|
||||
|
@ -146,9 +156,11 @@ int qfits_err_statset(int sta)
|
|||
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;
|
||||
}
|
||||
|
@ -158,14 +170,16 @@ int qfits_err_register(qfits_err_dispfunc dispfn)
|
|||
}
|
||||
|
||||
/* Public warning/error functions */
|
||||
void qfits_warning(const char *fmt, ...)
|
||||
void
|
||||
qfits_warning (const char *fmt, ...)
|
||||
{
|
||||
char msg[QFITS_ERR_MSGSIZE];
|
||||
char all[QFITS_ERR_MSGSIZE];
|
||||
va_list ap;
|
||||
|
||||
/* Check if display is activated */
|
||||
if (qfits_err_control.active==0) {
|
||||
if (qfits_err_control.active == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
va_start (ap, fmt);
|
||||
|
@ -176,14 +190,17 @@ void qfits_warning(const char *fmt, ...)
|
|||
qfits_err_main_display (all);
|
||||
return;
|
||||
}
|
||||
void qfits_error(const char *fmt, ...)
|
||||
|
||||
void
|
||||
qfits_error (const char *fmt, ...)
|
||||
{
|
||||
char msg[QFITS_ERR_MSGSIZE];
|
||||
char all[QFITS_ERR_MSGSIZE];
|
||||
va_list ap;
|
||||
|
||||
/* Check if display is activated */
|
||||
if (qfits_err_control.active==0) {
|
||||
if (qfits_err_control.active == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
va_start (ap, fmt);
|
||||
|
|
|
@ -90,7 +90,8 @@ static char regex_cmp[] =
|
|||
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);
|
||||
}
|
||||
|
@ -108,7 +109,8 @@ char * qfits_query_hdr(char * filename, const char * keyword)
|
|||
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 *where;
|
||||
|
@ -124,7 +126,8 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
|||
size_t size;
|
||||
|
||||
/* Bulletproof entries */
|
||||
if (filename==NULL || keyword==NULL || xtnum<0) return NULL ;
|
||||
if (filename == NULL || keyword == NULL || xtnum < 0)
|
||||
return NULL;
|
||||
|
||||
/* Expand keyword */
|
||||
exp_key = qfits_expand_keyword (keyword);
|
||||
|
@ -133,7 +136,8 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
|||
* Find out offsets to the required extension
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
@ -142,7 +146,8 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
|||
*/
|
||||
|
||||
start = falloc (filename, seg_start, &size);
|
||||
if (start==NULL) return NULL ;
|
||||
if (start == NULL)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Look for keyword in header
|
||||
|
@ -151,29 +156,33 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
|||
bufcount = 0;
|
||||
where = start;
|
||||
len = (int) strlen (exp_key);
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
different = 0;
|
||||
for (i=0 ; i<len ; i++) {
|
||||
if (where[i]!=exp_key[i]) {
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (where[i] != exp_key[i])
|
||||
{
|
||||
different++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!different) {
|
||||
if (!different)
|
||||
{
|
||||
/* Get 2 chars after keyword */
|
||||
test1 = where[len];
|
||||
test2 = where[len + 1];
|
||||
/* If first subsequent character is the equal sign, bingo. */
|
||||
if (test1=='=') break ;
|
||||
if (test1 == '=')
|
||||
break;
|
||||
/* If subsequent char is equal sign, bingo */
|
||||
if (test1 == ' ' && (test2 == '=' || test2 == ' '))
|
||||
break;
|
||||
}
|
||||
/* Watch out for header end */
|
||||
if ((where[0] == 'E') &&
|
||||
(where[1]=='N') &&
|
||||
(where[2]=='D') &&
|
||||
(where[3]==' ')) {
|
||||
(where[1] == 'N') && (where[2] == 'D') && (where[3] == ' '))
|
||||
{
|
||||
/* Detected header end */
|
||||
fdealloc (start, seg_start, size);
|
||||
return NULL;
|
||||
|
@ -181,7 +190,8 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
|||
/* Forward one line */
|
||||
where += 80;
|
||||
bufcount += 80;
|
||||
if (bufcount>seg_size) {
|
||||
if (bufcount > seg_size)
|
||||
{
|
||||
/* File is damaged or not FITS: bailout */
|
||||
fdealloc (start, seg_start, size);
|
||||
return NULL;
|
||||
|
@ -203,7 +213,8 @@ char * qfits_query_ext(char * filename, const char * keyword, int xtnum)
|
|||
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);
|
||||
}
|
||||
|
@ -218,7 +229,8 @@ int qfits_query_n_ext(char * filename)
|
|||
and -1 if an error occurred.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_query_nplanes(char * filename, int extnum)
|
||||
int
|
||||
qfits_query_nplanes (char *filename, int extnum)
|
||||
{
|
||||
char *sval;
|
||||
int next;
|
||||
|
@ -226,35 +238,43 @@ int qfits_query_nplanes(char * filename, int extnum)
|
|||
int nplanes;
|
||||
|
||||
/* Check file existence */
|
||||
if (filename == NULL) return -1 ;
|
||||
if (filename == NULL)
|
||||
return -1;
|
||||
/* Check validity of extnum */
|
||||
next = qfits_query_n_ext (filename);
|
||||
if (extnum>next) {
|
||||
if (extnum > next)
|
||||
{
|
||||
qfits_error ("invalid extension specified");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Find the number of axes */
|
||||
naxes = 0;
|
||||
if ((sval = qfits_query_ext(filename, "NAXIS", extnum)) == NULL) {
|
||||
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 ;
|
||||
if ((naxes < 2) || (naxes > 3))
|
||||
return -1;
|
||||
|
||||
/* Two dimensions cube */
|
||||
if (naxes == 2) nplanes = 1 ;
|
||||
else {
|
||||
if (naxes == 2)
|
||||
nplanes = 1;
|
||||
else
|
||||
{
|
||||
/* For 3D cubes, get the third dimension size */
|
||||
if ((sval = qfits_query_ext(filename, "NAXIS3", extnum))==NULL) {
|
||||
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 ;
|
||||
if (nplanes < 1)
|
||||
nplanes = 0;
|
||||
}
|
||||
return nplanes;
|
||||
}
|
||||
|
@ -278,7 +298,8 @@ int qfits_query_nplanes(char * filename, int extnum)
|
|||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#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 int flip = 0;
|
||||
|
@ -286,7 +307,8 @@ char * qfits_pretty_string(char * s)
|
|||
int i, j;
|
||||
|
||||
/* bulletproof */
|
||||
if (s==NULL) return NULL ;
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Switch between static buffers */
|
||||
pretty = pretty_buf[flip];
|
||||
|
@ -295,20 +317,26 @@ char * qfits_pretty_string(char * s)
|
|||
flip = 0;
|
||||
|
||||
pretty[0] = (char) 0;
|
||||
if (s[0]!='\'') return s ;
|
||||
if (s[0] != '\'')
|
||||
return s;
|
||||
|
||||
/* skip first quote */
|
||||
i = 1;
|
||||
j = 0;
|
||||
/* trim left-side blanks */
|
||||
while (s[i]==' ') {
|
||||
if (i==(int)strlen(s)) break ;
|
||||
while (s[i] == ' ')
|
||||
{
|
||||
if (i == (int) strlen (s))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
if (i>=(int)(strlen(s)-1)) return pretty ;
|
||||
if (i >= (int) (strlen (s) - 1))
|
||||
return pretty;
|
||||
/* copy string, changing double quotes to single ones */
|
||||
while (i<(int)strlen(s)) {
|
||||
if (s[i]=='\'') {
|
||||
while (i < (int) strlen (s))
|
||||
{
|
||||
if (s[i] == '\'')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
pretty[j] = s[i];
|
||||
|
@ -319,10 +347,12 @@ char * qfits_pretty_string(char * s)
|
|||
pretty[j + 1] = (char) 0;
|
||||
/* trim right-side blanks */
|
||||
j = (int) strlen (pretty) - 1;
|
||||
while (pretty[j]==' ') j-- ;
|
||||
while (pretty[j] == ' ')
|
||||
j--;
|
||||
pretty[j + 1] = (char) 0;
|
||||
return pretty;
|
||||
}
|
||||
|
||||
#undef PRETTY_STRING_STATICBUFS
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
@ -334,12 +364,17 @@ char * qfits_pretty_string(char * s)
|
|||
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[0]==0) return 0 ;
|
||||
if ((int)strlen(s)>1) return 0 ;
|
||||
if (s[0]=='T' || s[0]=='F') return 1 ;
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (s[0] == 0)
|
||||
return 0;
|
||||
if ((int) strlen (s) > 1)
|
||||
return 0;
|
||||
if (s[0] == 'T' || s[0] == 'F')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -352,14 +387,18 @@ int qfits_is_boolean(char * s)
|
|||
Identifies if a FITS value is an integer.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_is_int(char * s)
|
||||
int
|
||||
qfits_is_int (char *s)
|
||||
{
|
||||
regex_t re_int;
|
||||
int status;
|
||||
|
||||
if (s==NULL) return 0 ;
|
||||
if (s[0]==0) return 0 ;
|
||||
if (regcomp(&re_int, ®ex_int[0], REG_EXTENDED|REG_NOSUB)!=0) {
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (s[0] == 0)
|
||||
return 0;
|
||||
if (regcomp (&re_int, ®ex_int[0], REG_EXTENDED | REG_NOSUB) != 0)
|
||||
{
|
||||
qfits_error ("internal error: compiling int rule");
|
||||
exit (-1);
|
||||
}
|
||||
|
@ -377,14 +416,18 @@ int qfits_is_int(char * s)
|
|||
Identifies if a FITS value is float.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_is_float(char * s)
|
||||
int
|
||||
qfits_is_float (char *s)
|
||||
{
|
||||
regex_t re_float;
|
||||
int status;
|
||||
|
||||
if (s==NULL) return 0 ;
|
||||
if (s[0]==0) return 0 ;
|
||||
if (regcomp(&re_float, ®ex_float[0], REG_EXTENDED|REG_NOSUB)!=0) {
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (s[0] == 0)
|
||||
return 0;
|
||||
if (regcomp (&re_float, ®ex_float[0], REG_EXTENDED | REG_NOSUB) != 0)
|
||||
{
|
||||
qfits_error ("internal error: compiling float rule");
|
||||
exit (-1);
|
||||
}
|
||||
|
@ -402,14 +445,18 @@ int qfits_is_float(char * s)
|
|||
Identifies if a FITS value is complex.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_is_complex(char * s)
|
||||
int
|
||||
qfits_is_complex (char *s)
|
||||
{
|
||||
regex_t re_cmp;
|
||||
int status;
|
||||
|
||||
if (s==NULL) return 0 ;
|
||||
if (s[0]==0) return 0 ;
|
||||
if (regcomp(&re_cmp, ®ex_cmp[0], REG_EXTENDED|REG_NOSUB)!=0) {
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (s[0] == 0)
|
||||
return 0;
|
||||
if (regcomp (&re_cmp, ®ex_cmp[0], REG_EXTENDED | REG_NOSUB) != 0)
|
||||
{
|
||||
qfits_error ("internal error: compiling complex rule");
|
||||
exit (-1);
|
||||
}
|
||||
|
@ -427,10 +474,13 @@ int qfits_is_complex(char * s)
|
|||
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[0]=='\'') return 1 ;
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (s[0] == '\'')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -450,13 +500,19 @@ int qfits_is_string(char * s)
|
|||
- 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 (qfits_is_boolean(s)) return QFITS_BOOLEAN ;
|
||||
if (qfits_is_int(s)) return QFITS_INT ;
|
||||
if (qfits_is_float(s)) return QFITS_FLOAT ;
|
||||
if (qfits_is_complex(s)) return QFITS_COMPLEX ;
|
||||
if (s == NULL)
|
||||
return QFITS_UNKNOWN;
|
||||
if (qfits_is_boolean (s))
|
||||
return QFITS_BOOLEAN;
|
||||
if (qfits_is_int (s))
|
||||
return QFITS_INT;
|
||||
if (qfits_is_float (s))
|
||||
return QFITS_FLOAT;
|
||||
if (qfits_is_complex (s))
|
||||
return QFITS_COMPLEX;
|
||||
return QFITS_STRING;
|
||||
}
|
||||
|
||||
|
@ -479,21 +535,22 @@ int qfits_get_type(char * s)
|
|||
main header in the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_get_hdrinfo(
|
||||
char * filename,
|
||||
int xtnum,
|
||||
int * seg_start,
|
||||
int * seg_size)
|
||||
int
|
||||
qfits_get_hdrinfo (char *filename, int xtnum, int *seg_start, int *seg_size)
|
||||
{
|
||||
if (filename == NULL || xtnum < 0
|
||||
|| (seg_start == NULL && seg_size == NULL))
|
||||
{
|
||||
if (filename==NULL || xtnum<0 || (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)
|
||||
return -1;
|
||||
}
|
||||
if (seg_size!=NULL) {
|
||||
if (seg_size != NULL)
|
||||
{
|
||||
*seg_size = qfits_query (filename, QFITS_QUERY_HDR_SIZE | xtnum);
|
||||
if (*seg_size < 0)
|
||||
return -1;
|
||||
|
@ -520,21 +577,22 @@ int qfits_get_hdrinfo(
|
|||
main header in the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_get_datinfo(
|
||||
char * filename,
|
||||
int xtnum,
|
||||
int * seg_start,
|
||||
int * seg_size)
|
||||
int
|
||||
qfits_get_datinfo (char *filename, int xtnum, int *seg_start, int *seg_size)
|
||||
{
|
||||
if (filename == NULL || xtnum < 0
|
||||
|| (seg_start == NULL && seg_size == NULL))
|
||||
{
|
||||
if (filename==NULL || xtnum<0 || (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)
|
||||
return -1;
|
||||
}
|
||||
if (seg_size!=NULL) {
|
||||
if (seg_size != NULL)
|
||||
{
|
||||
*seg_size = qfits_query (filename, QFITS_QUERY_DAT_SIZE | xtnum);
|
||||
if (*seg_size < 0)
|
||||
return -1;
|
||||
|
@ -550,9 +608,8 @@ int qfits_get_datinfo(
|
|||
@return Allocated string containing the card or NULL
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_query_card(
|
||||
char * filename,
|
||||
char * keyword)
|
||||
char *
|
||||
qfits_query_card (char *filename, char *keyword)
|
||||
{
|
||||
char *exp_key;
|
||||
int fd;
|
||||
|
@ -563,26 +620,25 @@ char * qfits_query_card(
|
|||
char *card;
|
||||
|
||||
/* Bulletproof entries */
|
||||
if (filename==NULL || keyword==NULL) return NULL ;
|
||||
if (filename == NULL || keyword == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Expand keyword */
|
||||
exp_key = qfits_expand_keyword (keyword);
|
||||
|
||||
/* Memory-map the FITS header of the input file */
|
||||
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;
|
||||
}
|
||||
fd = open (filename, O_RDWR);
|
||||
if (fd == -1) return NULL ;
|
||||
buf = (char*)mmap(0,
|
||||
hs,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
fd,
|
||||
0) ;
|
||||
if (buf == (char*)-1) {
|
||||
if (fd == -1)
|
||||
return NULL;
|
||||
buf = (char *) mmap (0, hs, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (buf == (char *) -1)
|
||||
{
|
||||
perror ("mmap");
|
||||
close (fd);
|
||||
return NULL;
|
||||
|
@ -593,16 +649,20 @@ char * qfits_query_card(
|
|||
memcpy (buf2, buf, hs);
|
||||
buf2[hs] = (char) 0;
|
||||
where = buf2;
|
||||
do {
|
||||
do
|
||||
{
|
||||
where = strstr (where, exp_key);
|
||||
if (where == NULL) {
|
||||
if (where == NULL)
|
||||
{
|
||||
close (fd);
|
||||
munmap (buf, hs);
|
||||
free (buf2);
|
||||
return NULL;
|
||||
}
|
||||
if ((where-buf2)%80) where++ ;
|
||||
} while ((where-buf2)%80) ;
|
||||
if ((where - buf2) % 80)
|
||||
where++;
|
||||
}
|
||||
while ((where - buf2) % 80);
|
||||
|
||||
where = buf + (int) (where - buf2);
|
||||
|
||||
|
@ -637,10 +697,8 @@ char * qfits_query_card(
|
|||
Returns 0 if everything worked Ok, -1 otherwise.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_replace_card(
|
||||
char * filename,
|
||||
const char * keyword,
|
||||
char * substitute)
|
||||
int
|
||||
qfits_replace_card (char *filename, const char *keyword, char *substitute)
|
||||
{
|
||||
char *exp_key;
|
||||
int fd;
|
||||
|
@ -651,7 +709,8 @@ int qfits_replace_card(
|
|||
|
||||
|
||||
/* Bulletproof entries */
|
||||
if (filename==NULL || keyword==NULL || substitute==NULL) return -1 ;
|
||||
if (filename == NULL || keyword == NULL || substitute == NULL)
|
||||
return -1;
|
||||
|
||||
/* Expand keyword */
|
||||
exp_key = qfits_expand_keyword (keyword);
|
||||
|
@ -660,21 +719,19 @@ int qfits_replace_card(
|
|||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
fd = open (filename, O_RDWR);
|
||||
if (fd == -1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
buf = (char*)mmap(0,
|
||||
hs,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
fd,
|
||||
0) ;
|
||||
if (buf == (char*)-1) {
|
||||
buf = (char *) mmap (0, hs, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (buf == (char *) -1)
|
||||
{
|
||||
perror ("mmap");
|
||||
close (fd);
|
||||
return -1;
|
||||
|
@ -685,16 +742,20 @@ int qfits_replace_card(
|
|||
memcpy (buf2, buf, hs);
|
||||
buf2[hs] = (char) 0;
|
||||
where = buf2;
|
||||
do {
|
||||
do
|
||||
{
|
||||
where = strstr (where, exp_key);
|
||||
if (where == NULL) {
|
||||
if (where == NULL)
|
||||
{
|
||||
close (fd);
|
||||
munmap (buf, hs);
|
||||
free (buf2);
|
||||
return -1;
|
||||
}
|
||||
if ((where-buf2)%80) where++ ;
|
||||
} while ((where-buf2)%80) ;
|
||||
if ((where - buf2) % 80)
|
||||
where++;
|
||||
}
|
||||
while ((where - buf2) % 80);
|
||||
|
||||
where = buf + (int) (where - buf2);
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#define SIMPLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
@ -235,11 +236,8 @@ int qfits_get_type(char * s) ;
|
|||
main header in the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_get_hdrinfo(
|
||||
char * filename,
|
||||
int xtnum,
|
||||
int * seg_start,
|
||||
int * seg_size) ;
|
||||
int qfits_get_hdrinfo (char *filename,
|
||||
int xtnum, int *seg_start, int *seg_size);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -260,11 +258,8 @@ int qfits_get_hdrinfo(
|
|||
main header in the file.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_get_datinfo(
|
||||
char * filename,
|
||||
int xtnum,
|
||||
int * seg_start,
|
||||
int * seg_size) ;
|
||||
int qfits_get_datinfo (char *filename,
|
||||
int xtnum, int *seg_start, int *seg_size);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -274,9 +269,7 @@ int qfits_get_datinfo(
|
|||
@return Allocated string containing the card or NULL
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_query_card(
|
||||
char * filename,
|
||||
char * keyword) ;
|
||||
char *qfits_query_card (char *filename, char *keyword);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -297,10 +290,8 @@ char * qfits_query_card(
|
|||
Returns 0 if everything worked Ok, -1 otherwise.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_replace_card(
|
||||
char * filename,
|
||||
const char * keyword,
|
||||
char * substitute) ;
|
||||
int qfits_replace_card (char *filename,
|
||||
const char *keyword, char *substitute);
|
||||
|
||||
/* </dox> */
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#define STATIC_SZ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* <dox> */
|
||||
|
|
|
@ -95,7 +95,8 @@ static long timer_to_time(time_t time_secs) ;
|
|||
Example: 19 Oct 2000 is returned as 20001019
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
long qfits_date_now (void)
|
||||
long
|
||||
qfits_date_now (void)
|
||||
{
|
||||
return (timer_to_date (time (NULL)));
|
||||
}
|
||||
|
@ -111,13 +112,13 @@ long qfits_date_now (void)
|
|||
Example: 15:36:12.84 is returned as 15361284
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
long qfits_time_now(void)
|
||||
long
|
||||
qfits_time_now (void)
|
||||
{
|
||||
struct timeval time_struct;
|
||||
|
||||
gettimeofday (&time_struct, 0);
|
||||
return (timer_to_time (time_struct.tv_sec)
|
||||
+ time_struct.tv_usec / 10000);
|
||||
return (timer_to_time (time_struct.tv_sec) + time_struct.tv_usec / 10000);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
@ -133,22 +134,28 @@ long qfits_time_now(void)
|
|||
(GMT).
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static long timer_to_date(time_t time_secs)
|
||||
static long
|
||||
timer_to_date (time_t time_secs)
|
||||
{
|
||||
struct tm *time_struct;
|
||||
|
||||
if (time_secs == 0) {
|
||||
if (time_secs == 0)
|
||||
{
|
||||
return 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Convert into a long value CCYYMMDD */
|
||||
time_struct = localtime (&time_secs);
|
||||
if (time_struct) {
|
||||
if (time_struct)
|
||||
{
|
||||
time_struct->tm_year += 1900;
|
||||
return (MAKE_DATE (time_struct->tm_year / 100,
|
||||
time_struct->tm_year % 100,
|
||||
time_struct-> tm_mon + 1,
|
||||
time_struct-> tm_mday));
|
||||
} else {
|
||||
time_struct->tm_mon + 1, time_struct->tm_mday));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (19700101);
|
||||
}
|
||||
}
|
||||
|
@ -167,21 +174,26 @@ static long timer_to_date(time_t time_secs)
|
|||
(GMT).
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static long timer_to_time(time_t time_secs)
|
||||
static long
|
||||
timer_to_time (time_t time_secs)
|
||||
{
|
||||
struct tm *time_struct;
|
||||
|
||||
if (time_secs == 0) {
|
||||
if (time_secs == 0)
|
||||
{
|
||||
return 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Convert into a long value HHMMSS00 */
|
||||
time_struct = localtime (&time_secs);
|
||||
if (time_struct) {
|
||||
if (time_struct)
|
||||
{
|
||||
return (MAKE_TIME (time_struct->tm_hour,
|
||||
time_struct-> tm_min,
|
||||
time_struct-> tm_sec,
|
||||
0));
|
||||
} else {
|
||||
time_struct->tm_min, time_struct->tm_sec, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -201,16 +213,15 @@ static long timer_to_time(time_t time_secs)
|
|||
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];
|
||||
long curdate;
|
||||
|
||||
curdate = qfits_date_now ();
|
||||
sprintf (date_iso8601, "%04d-%02d-%02d",
|
||||
GET_CCYEAR(curdate),
|
||||
GET_MONTH(curdate),
|
||||
GET_DAY(curdate));
|
||||
GET_CCYEAR (curdate), GET_MONTH (curdate), GET_DAY (curdate));
|
||||
return date_iso8601;
|
||||
}
|
||||
|
||||
|
@ -224,7 +235,8 @@ char * qfits_get_date_iso8601(void)
|
|||
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];
|
||||
long curdate;
|
||||
|
@ -237,14 +249,13 @@ char * qfits_get_datetime_iso8601(void)
|
|||
GET_CCYEAR (curdate),
|
||||
GET_MONTH (curdate),
|
||||
GET_DAY (curdate),
|
||||
GET_HOUR(curtime),
|
||||
GET_MINUTE(curtime),
|
||||
GET_SECOND(curtime));
|
||||
GET_HOUR (curtime), GET_MINUTE (curtime), GET_SECOND (curtime));
|
||||
return date_iso8601;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
printf ("date now %ld\n"
|
||||
"time now %ld\n"
|
||||
|
@ -252,8 +263,7 @@ int main(int argc, char *argv[])
|
|||
"date/time iso 8601 %s\n",
|
||||
qfits_date_now (),
|
||||
qfits_time_now (),
|
||||
qfits_get_date_iso8601(),
|
||||
qfits_get_datetime_iso8601());
|
||||
qfits_get_date_iso8601 (), qfits_get_datetime_iso8601 ());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
#define T_ISO8601_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
|
|
1163
qfits/src/tfits.c
1163
qfits/src/tfits.c
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,8 @@
|
|||
#define TFITS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
@ -55,7 +56,8 @@ extern "C" {
|
|||
@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_E,
|
||||
|
@ -262,12 +264,9 @@ qfits_header * qfits_table_ext_header_default(qfits_table *) ;
|
|||
qfits_table_close()
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_table * qfits_table_new(
|
||||
char * filename,
|
||||
qfits_table *qfits_table_new (char *filename,
|
||||
int table_type,
|
||||
int table_width,
|
||||
int nb_cols,
|
||||
int nb_raws) ;
|
||||
int table_width, int nb_cols, int nb_raws);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -293,8 +292,7 @@ qfits_table * qfits_table_new(
|
|||
@return -1 in error case, 0 otherwise
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_col_fill(
|
||||
qfits_col * qc,
|
||||
int qfits_col_fill (qfits_col * qc,
|
||||
int atom_nb,
|
||||
int atom_dec_nb,
|
||||
int atom_size,
|
||||
|
@ -305,9 +303,7 @@ int qfits_col_fill(
|
|||
char *disp,
|
||||
int zero_present,
|
||||
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.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
qfits_table * qfits_table_open(
|
||||
char * filename,
|
||||
int xtnum) ;
|
||||
qfits_table *qfits_table_open (char *filename, int xtnum);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -363,10 +357,8 @@ void qfits_table_close(qfits_table * t) ;
|
|||
the pixel loader here.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
unsigned char * qfits_query_column(
|
||||
qfits_table * th,
|
||||
int colnum,
|
||||
int * selection) ;
|
||||
unsigned char *qfits_query_column (qfits_table * th,
|
||||
int colnum, int *selection);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -380,11 +372,9 @@ unsigned char * qfits_query_column(
|
|||
Spares the overhead of the selection object allocation
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
unsigned char * qfits_query_column_seq(
|
||||
qfits_table * th,
|
||||
unsigned char *qfits_query_column_seq (qfits_table * th,
|
||||
int colnum,
|
||||
int start_ind,
|
||||
int nb_rows) ;
|
||||
int start_ind, int nb_rows);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -420,11 +410,9 @@ int qfits_compute_table_width(qfits_table * th) ;
|
|||
the pixel loader here.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void * qfits_query_column_data(
|
||||
qfits_table * th,
|
||||
void *qfits_query_column_data (qfits_table * th,
|
||||
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
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void * qfits_query_column_seq_data(
|
||||
qfits_table * th,
|
||||
void *qfits_query_column_seq_data (qfits_table * th,
|
||||
int colnum,
|
||||
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
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int * qfits_query_column_nulls(
|
||||
qfits_table * th,
|
||||
int *qfits_query_column_nulls (qfits_table * th,
|
||||
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
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_save_table_hdrdump(
|
||||
void ** array,
|
||||
qfits_table * table,
|
||||
qfits_header * fh) ;
|
||||
int qfits_save_table_hdrdump (void **array,
|
||||
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.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_table_append_xtension(
|
||||
FILE * outfile,
|
||||
qfits_table * t,
|
||||
void ** data) ;
|
||||
int qfits_table_append_xtension (FILE * outfile,
|
||||
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.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int qfits_table_append_xtension_hdr(
|
||||
FILE * outfile,
|
||||
int qfits_table_append_xtension_hdr (FILE * outfile,
|
||||
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
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char * qfits_table_field_to_string(
|
||||
qfits_table * table,
|
||||
char *qfits_table_field_to_string (qfits_table * table,
|
||||
int col_id,
|
||||
int row_id,
|
||||
int use_zero_scale) ;
|
||||
int row_id, int use_zero_scale);
|
||||
|
||||
/* </dox> */
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
/* Library version */
|
||||
static const char *
|
||||
_qfits_version = "5.4.0" ;
|
||||
static const char *_qfits_version = "5.4.0";
|
||||
|
||||
const char * qfits_version(void)
|
||||
const char *
|
||||
qfits_version (void)
|
||||
{
|
||||
return _qfits_version;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
514
qfits/sysconf.c
514
qfits/sysconf.c
|
@ -42,9 +42,11 @@
|
|||
|
||||
/* Global variable */
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
/* List of supported OS's */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
os_linux,
|
||||
os_cygwin,
|
||||
os_hp08,
|
||||
|
@ -99,7 +101,8 @@ struct {
|
|||
* Check that all files present in the list of names are
|
||||
* somewhere present in the list of paths.
|
||||
*/
|
||||
int config_findfiles(paths, names)
|
||||
int
|
||||
config_findfiles (paths, names)
|
||||
char **paths;
|
||||
char **names;
|
||||
{
|
||||
|
@ -110,19 +113,23 @@ int config_findfiles(paths, names)
|
|||
|
||||
/* Loop on all paths */
|
||||
i = 0;
|
||||
while (paths[i]) {
|
||||
while (paths[i])
|
||||
{
|
||||
printf ("searching in %s...\n", paths[i]);
|
||||
/* Loop on all file names */
|
||||
j = 0;
|
||||
nfound = 0;
|
||||
while (names[j]) {
|
||||
while (names[j])
|
||||
{
|
||||
sprintf (spath, "%s/%s", paths[i], names[j]);
|
||||
if (stat(spath, &sta)==0) {
|
||||
if (stat (spath, &sta) == 0)
|
||||
{
|
||||
nfound++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (j==nfound) {
|
||||
if (j == nfound)
|
||||
{
|
||||
printf ("found in %s\n", paths[i]);
|
||||
return i;
|
||||
}
|
||||
|
@ -133,17 +140,20 @@ int config_findfiles(paths, names)
|
|||
|
||||
|
||||
/* Guess local OS name and potentially release number */
|
||||
void detect_config()
|
||||
void
|
||||
detect_config ()
|
||||
{
|
||||
struct utsname name;
|
||||
int i;
|
||||
unsigned char c;
|
||||
int x;
|
||||
|
||||
if (config.sysname[0]==0) {
|
||||
if (config.sysname[0] == 0)
|
||||
{
|
||||
printf ("detecting local OS............. ");
|
||||
/* Get machine OS type and release number */
|
||||
if (uname(&name)==-1) {
|
||||
if (uname (&name) == -1)
|
||||
{
|
||||
printf ("error calling uname\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
@ -151,85 +161,120 @@ void detect_config()
|
|||
strcpy (config.sysname, name.sysname);
|
||||
strcpy (config.release, name.release);
|
||||
strcpy (config.machine, name.machine);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("forcing config for OS.......... %s %s",
|
||||
config.sysname,
|
||||
config.release);
|
||||
config.sysname, config.release);
|
||||
}
|
||||
|
||||
/* Lowercase everything */
|
||||
i = 0;
|
||||
while(config.sysname[i]!=0) {
|
||||
while (config.sysname[i] != 0)
|
||||
{
|
||||
config.sysname[i] = tolower (config.sysname[i]);
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(config.release[i]!=0) {
|
||||
while (config.release[i] != 0)
|
||||
{
|
||||
config.release[i] = tolower (config.release[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Switch on OS type and release number */
|
||||
if (strstr(config.sysname, "linux")!=NULL) {
|
||||
if (strstr (config.sysname, "linux") != NULL)
|
||||
{
|
||||
config.local_os = os_linux;
|
||||
printf (" - linux\n");
|
||||
} else if (strstr(config.sysname, "cygwin")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.sysname, "cygwin") != NULL)
|
||||
{
|
||||
config.local_os = os_cygwin;
|
||||
printf (" - cygwin\n");
|
||||
} else if (strstr(config.sysname, "hp")!=NULL) {
|
||||
if (strstr(config.release, "8.")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.sysname, "hp") != NULL)
|
||||
{
|
||||
if (strstr (config.release, "8.") != NULL)
|
||||
{
|
||||
config.local_os = os_hp08;
|
||||
printf (" - hpux_08\n");
|
||||
} else if (strstr(config.release, "9.")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.release, "9.") != NULL)
|
||||
{
|
||||
config.local_os = os_hp09;
|
||||
printf (" - hpux_09\n");
|
||||
} else if (strstr(config.release, "10.")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.release, "10.") != NULL)
|
||||
{
|
||||
config.local_os = os_hp10;
|
||||
printf (" - hpux_10\n");
|
||||
} else if (strstr(config.release, "11.")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.release, "11.") != NULL)
|
||||
{
|
||||
config.local_os = os_hp11;
|
||||
printf (" - hpux_11\n");
|
||||
}
|
||||
} else if ((strstr(config.sysname, "sun")!=NULL) ||
|
||||
(strstr(config.sysname, "solaris")!=NULL)) {
|
||||
}
|
||||
else if ((strstr (config.sysname, "sun") != NULL) ||
|
||||
(strstr (config.sysname, "solaris") != NULL))
|
||||
{
|
||||
config.local_os = os_solaris;
|
||||
printf (" - solaris\n");
|
||||
} else if (strstr(config.sysname, "irix")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.sysname, "irix") != NULL)
|
||||
{
|
||||
config.local_os = os_irix;
|
||||
printf (" - irix\n");
|
||||
} else if (strstr(config.sysname, "aix")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.sysname, "aix") != NULL)
|
||||
{
|
||||
config.local_os = os_aix;
|
||||
printf (" - aix\n");
|
||||
} else if (strstr(config.sysname, "osf")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.sysname, "osf") != NULL)
|
||||
{
|
||||
config.local_os = os_dec;
|
||||
printf (" - osf/1\n");
|
||||
} else if (strstr(config.sysname, "bsd")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.sysname, "bsd") != NULL)
|
||||
{
|
||||
config.local_os = os_bsd;
|
||||
printf (" - %s\n", config.sysname);
|
||||
} else if (strstr(config.sysname, "darwin")!=NULL) {
|
||||
}
|
||||
else if (strstr (config.sysname, "darwin") != NULL)
|
||||
{
|
||||
config.local_os = os_darwin;
|
||||
printf (" - %s\n", config.sysname);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("cannot identify your OS\n");
|
||||
printf ("Use the option --os=NAME to force an OS type\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* Find out about x86 architectures */
|
||||
if ((config.machine[0]=='i') && (strstr(config.machine, "86")!=NULL)) {
|
||||
if ((config.machine[0] == 'i') && (strstr (config.machine, "86") != NULL))
|
||||
{
|
||||
config.arch_x86 = 1;
|
||||
config.cpu_x86 = atoi (config.machine + 1);
|
||||
printf ("detected x86 architecture...... %d\n", config.cpu_x86);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
config.arch_x86 = 0;
|
||||
printf ("detected x86 architecture...... no\n");
|
||||
}
|
||||
|
||||
/* Compute number of bits in a byte on this machine */
|
||||
printf ("computing bits per byte........ ");
|
||||
c=1 ; i=0 ;
|
||||
while (c) {
|
||||
c<<=1 ; i++ ;
|
||||
c = 1;
|
||||
i = 0;
|
||||
while (c)
|
||||
{
|
||||
c <<= 1;
|
||||
i++;
|
||||
}
|
||||
config.bits_per_byte = i;
|
||||
printf ("%d\n", i);
|
||||
|
@ -240,9 +285,12 @@ void detect_config()
|
|||
x = (*(char *) &x);
|
||||
|
||||
config.big_endian = !x;
|
||||
if (config.big_endian) {
|
||||
if (config.big_endian)
|
||||
{
|
||||
printf ("big endian (motorola)\n");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("little endian (intel)\n");
|
||||
}
|
||||
|
||||
|
@ -250,7 +298,8 @@ void detect_config()
|
|||
}
|
||||
|
||||
/* Locate a program in the user's PATH */
|
||||
int locate_program(pname)
|
||||
int
|
||||
locate_program (pname)
|
||||
char *pname;
|
||||
{
|
||||
int i, j, lg;
|
||||
|
@ -258,52 +307,65 @@ int locate_program(pname)
|
|||
char buf[MAXSTRSZ];
|
||||
|
||||
path = getenv ("PATH");
|
||||
if (path!=NULL) {
|
||||
for (i=0; path[i]; ) {
|
||||
if (path != NULL)
|
||||
{
|
||||
for (i = 0; path[i];)
|
||||
{
|
||||
for (j = i; (path[j]) && (path[j] != ':'); j++);
|
||||
lg = j - i;
|
||||
strncpy (buf, path + i, lg);
|
||||
if (lg == 0) buf[lg++] = '.';
|
||||
if (lg == 0)
|
||||
buf[lg++] = '.';
|
||||
buf[lg++] = '/';
|
||||
strcpy (buf + lg, pname);
|
||||
if (access(buf, X_OK) == 0) {
|
||||
if (access (buf, X_OK) == 0)
|
||||
{
|
||||
printf ("using [%s]\n", buf);
|
||||
return 1;
|
||||
}
|
||||
buf[0] = 0;
|
||||
i = j;
|
||||
if (path[i] == ':') i++ ;
|
||||
if (path[i] == ':')
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No PATH variable: abort with an error */
|
||||
return -1;
|
||||
}
|
||||
/* If the buffer is still empty, the command was not found */
|
||||
if (buf[0] == 0) return 0 ;
|
||||
if (buf[0] == 0)
|
||||
return 0;
|
||||
/* Otherwise Ok */
|
||||
return 1;
|
||||
}
|
||||
|
||||
void make_config_make()
|
||||
void
|
||||
make_config_make ()
|
||||
{
|
||||
FILE *sysc;
|
||||
|
||||
/* Set compiler name */
|
||||
printf ("looking for a C compiler....... ");
|
||||
if (getenv("PATH")==NULL) {
|
||||
if (getenv ("PATH") == NULL)
|
||||
{
|
||||
printf ("error: undefined PATH variable, cannot locate a compiler\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* Open output sysconf */
|
||||
if ((sysc=fopen(MACROS_FILE, "w"))==NULL) {
|
||||
if ((sysc = fopen (MACROS_FILE, "w")) == NULL)
|
||||
{
|
||||
printf ("cannot create %s: aborting compilation", MACROS_FILE);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* In automatic mode, find out which compiler to use */
|
||||
if (config.compiler==COMPILER_AUTO) {
|
||||
switch (config.local_os) {
|
||||
if (config.compiler == COMPILER_AUTO)
|
||||
{
|
||||
switch (config.local_os)
|
||||
{
|
||||
|
||||
/* Use gcc under Linux, BSD, Cygwin & IRIX */
|
||||
case os_linux:
|
||||
|
@ -322,15 +384,19 @@ void make_config_make()
|
|||
|
||||
|
||||
/* Make sure the compiler can be found */
|
||||
if (config.compiler==COMPILER_CC) {
|
||||
if (locate_program("cc")!=1) {
|
||||
if (config.compiler == COMPILER_CC)
|
||||
{
|
||||
if (locate_program ("cc") != 1)
|
||||
{
|
||||
printf ("cannot locate cc\n");
|
||||
/* Try out with gcc */
|
||||
config.compiler = COMPILER_GCC;
|
||||
}
|
||||
}
|
||||
if (config.compiler==COMPILER_GCC) {
|
||||
if (locate_program("gcc")!=1) {
|
||||
if (config.compiler == COMPILER_GCC)
|
||||
{
|
||||
if (locate_program ("gcc") != 1)
|
||||
{
|
||||
printf ("cannot locate gcc\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
@ -338,37 +404,52 @@ void make_config_make()
|
|||
|
||||
|
||||
/* Set compiler name and cflags */
|
||||
switch (config.compiler) {
|
||||
switch (config.compiler)
|
||||
{
|
||||
|
||||
case COMPILER_CC:
|
||||
fprintf (sysc, "CC = cc\n");
|
||||
fprintf (sysc, "CFLAGS = ");
|
||||
if (config.xmemory_mode == 0) {
|
||||
if (config.xmemory_mode == 0)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode);
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=1 ");
|
||||
} else if (config.xmemory_mode == 1) {
|
||||
fprintf(sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode) ;
|
||||
fprintf(sysc, "-DXMEMORY_MAXPTRS=1 ") ;
|
||||
} else if (config.xmemory_mode == 2) {
|
||||
fprintf(sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode) ;
|
||||
if (config.max_ptrs > 0) {
|
||||
fprintf(sysc, "-DXMEMORY_MAXPTRS=%d ", config.max_ptrs) ;
|
||||
}
|
||||
} else if (config.xmemory_mode < 0) {
|
||||
if (config.max_ptrs > 0) {
|
||||
else if (config.xmemory_mode == 1)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode);
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=1 ");
|
||||
}
|
||||
else if (config.xmemory_mode == 2)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode);
|
||||
if (config.max_ptrs > 0)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=%d ", config.max_ptrs);
|
||||
}
|
||||
}
|
||||
switch (config.local_os) {
|
||||
else if (config.xmemory_mode < 0)
|
||||
{
|
||||
if (config.max_ptrs > 0)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=%d ", config.max_ptrs);
|
||||
}
|
||||
}
|
||||
switch (config.local_os)
|
||||
{
|
||||
case os_hp08:
|
||||
case os_hp09:
|
||||
case os_hp10:
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
printf ("threads not supported on this platform\n");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-Ae -g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-Ae -O\n");
|
||||
}
|
||||
fprintf (sysc, "RELOC = +z\n");
|
||||
|
@ -376,12 +457,16 @@ void make_config_make()
|
|||
break;
|
||||
|
||||
case os_hp11:
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
fprintf (sysc, "-lpthread ");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-O\n");
|
||||
}
|
||||
fprintf (sysc, "RELOC = +z\n");
|
||||
|
@ -389,12 +474,16 @@ void make_config_make()
|
|||
break;
|
||||
|
||||
case os_solaris:
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
fprintf (sysc, "-mt -lpthread ");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-xO5\n");
|
||||
}
|
||||
fprintf (sysc, "RELOC = -G\n");
|
||||
|
@ -402,12 +491,16 @@ void make_config_make()
|
|||
break;
|
||||
|
||||
case os_dec:
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
printf ("threads not supported on this platform\n");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-O\n");
|
||||
}
|
||||
fprintf (sysc, "RELOC =\n");
|
||||
|
@ -417,12 +510,16 @@ void make_config_make()
|
|||
case os_irix:
|
||||
case os_aix:
|
||||
case os_bsd:
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
printf ("threads not supported on this platform\n");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-O\n");
|
||||
}
|
||||
fprintf (sysc, "RELOC =\n");
|
||||
|
@ -432,12 +529,16 @@ void make_config_make()
|
|||
case os_cygwin:
|
||||
case os_linux:
|
||||
/* cc with Linux? Why not! */
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
fprintf (sysc, "-pthread ");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-O3\n");
|
||||
}
|
||||
fprintf (sysc, "RELOC = -fpic\n");
|
||||
|
@ -446,12 +547,16 @@ void make_config_make()
|
|||
|
||||
case os_darwin:
|
||||
/* Darwin uses gcc but calls it 'cc' */
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
fprintf (sysc, "-pthread ");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-O3\n");
|
||||
}
|
||||
fprintf (sysc, "RELOC = -fPIC\n");
|
||||
|
@ -469,31 +574,45 @@ void make_config_make()
|
|||
fprintf (sysc, "CC = gcc\n");
|
||||
fprintf (sysc, "CFLAGS = ");
|
||||
|
||||
if (config.xmemory_mode == 0) {
|
||||
if (config.xmemory_mode == 0)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode);
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=1 ");
|
||||
} else if (config.xmemory_mode == 1) {
|
||||
fprintf(sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode) ;
|
||||
fprintf(sysc, "-DXMEMORY_MAXPTRS=1 ") ;
|
||||
} else if (config.xmemory_mode == 2) {
|
||||
fprintf(sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode) ;
|
||||
if (config.max_ptrs > 0) {
|
||||
fprintf(sysc, "-DXMEMORY_MAXPTRS=%d ", config.max_ptrs) ;
|
||||
}
|
||||
} else if (config.xmemory_mode < 0) {
|
||||
if (config.max_ptrs > 0) {
|
||||
else if (config.xmemory_mode == 1)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode);
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=1 ");
|
||||
}
|
||||
else if (config.xmemory_mode == 2)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MODE=%d ", config.xmemory_mode);
|
||||
if (config.max_ptrs > 0)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=%d ", config.max_ptrs);
|
||||
}
|
||||
}
|
||||
if (config.with_threads) {
|
||||
else if (config.xmemory_mode < 0)
|
||||
{
|
||||
if (config.max_ptrs > 0)
|
||||
{
|
||||
fprintf (sysc, "-DXMEMORY_MAXPTRS=%d ", config.max_ptrs);
|
||||
}
|
||||
}
|
||||
if (config.with_threads)
|
||||
{
|
||||
fprintf (sysc, "-pthread ");
|
||||
}
|
||||
if (config.lint_compile) {
|
||||
if (config.lint_compile)
|
||||
{
|
||||
fprintf (sysc, " -Wall -pedantic ");
|
||||
}
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "-g%s\n", XMEMDEBUG);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "-O3\n");
|
||||
}
|
||||
if (config.local_os != os_cygwin)
|
||||
|
@ -507,18 +626,23 @@ void make_config_make()
|
|||
break;
|
||||
}
|
||||
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
printf (" in debug mode\n");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf (" all optimizations on\n");
|
||||
}
|
||||
if (config.lint_compile) {
|
||||
if (config.lint_compile)
|
||||
{
|
||||
printf (" with all warnings\n");
|
||||
}
|
||||
|
||||
/* LFLAGS */
|
||||
fprintf (sysc, "LFLAGS = ");
|
||||
switch (config.local_os) {
|
||||
switch (config.local_os)
|
||||
{
|
||||
|
||||
case os_hp10:
|
||||
case os_hp11:
|
||||
|
@ -531,7 +655,8 @@ void make_config_make()
|
|||
fprintf (sysc, "\n");
|
||||
|
||||
/* DYNSUF */
|
||||
switch (config.local_os) {
|
||||
switch (config.local_os)
|
||||
{
|
||||
case os_hp08:
|
||||
case os_hp09:
|
||||
case os_hp10:
|
||||
|
@ -550,9 +675,12 @@ void make_config_make()
|
|||
}
|
||||
|
||||
/* STRIP */
|
||||
if (config.debug_compile) {
|
||||
if (config.debug_compile)
|
||||
{
|
||||
fprintf (sysc, "STRIP = true\n");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (sysc, "STRIP = strip\n");
|
||||
}
|
||||
|
||||
|
@ -560,12 +688,14 @@ void make_config_make()
|
|||
fprintf (sysc, "TARGETS =");
|
||||
printf ("static library................. %s\n",
|
||||
config.lib_static ? "yes" : "no");
|
||||
if (config.lib_static) {
|
||||
if (config.lib_static)
|
||||
{
|
||||
fprintf (sysc, " static");
|
||||
}
|
||||
printf ("shared library................. %s\n",
|
||||
config.lib_dynamic ? "yes" : "no");
|
||||
if (config.lib_dynamic) {
|
||||
if (config.lib_dynamic)
|
||||
{
|
||||
fprintf (sysc, " dynamic");
|
||||
}
|
||||
fprintf (sysc, "\n");
|
||||
|
@ -580,12 +710,14 @@ void make_config_make()
|
|||
}
|
||||
|
||||
|
||||
void make_config_h()
|
||||
void
|
||||
make_config_h ()
|
||||
{
|
||||
FILE *out;
|
||||
|
||||
out = fopen (HEADER_FILE, "w");
|
||||
if (out==NULL) {
|
||||
if (out == NULL)
|
||||
{
|
||||
printf ("cannot create header file %s: aborting", HEADER_FILE);
|
||||
return;
|
||||
}
|
||||
|
@ -595,9 +727,7 @@ void make_config_h()
|
|||
"#ifndef _CONFIG_H_\n"
|
||||
"#define _CONFIG_H_\n"
|
||||
"\n"
|
||||
"%s",
|
||||
config.big_endian ? "#define WORDS_BIGENDIAN 1\n" : "\n"
|
||||
);
|
||||
"%s", config.big_endian ? "#define WORDS_BIGENDIAN 1\n" : "\n");
|
||||
|
||||
/* Generate SIZEOF macros for basic types */
|
||||
printf ("detecting basic size types\n");
|
||||
|
@ -610,12 +740,8 @@ void make_config_h()
|
|||
"#define SIZEOF_DOUBLE %d\n",
|
||||
sizeof (char),
|
||||
sizeof (short),
|
||||
sizeof(int),
|
||||
sizeof(long),
|
||||
sizeof(float),
|
||||
sizeof(double));
|
||||
printf(
|
||||
"sizeof(char)................... %d\n"
|
||||
sizeof (int), sizeof (long), sizeof (float), sizeof (double));
|
||||
printf ("sizeof(char)................... %d\n"
|
||||
"sizeof(short).................. %d\n"
|
||||
"sizeof(int).................... %d\n"
|
||||
"sizeof(long)................... %d\n"
|
||||
|
@ -623,31 +749,30 @@ void make_config_h()
|
|||
"sizeof(double)................. %d\n",
|
||||
sizeof (char),
|
||||
sizeof (short),
|
||||
sizeof(int),
|
||||
sizeof(long),
|
||||
sizeof(float),
|
||||
sizeof(double));
|
||||
sizeof (int), sizeof (long), sizeof (float), sizeof (double));
|
||||
|
||||
/* Do not output CHAR_BIT on AIX */
|
||||
if (config.local_os!=os_aix) {
|
||||
if (config.local_os != os_aix)
|
||||
{
|
||||
fprintf (out,
|
||||
"\n"
|
||||
"#ifndef CHAR_BIT\n"
|
||||
"#define CHAR_BIT\t%d\n"
|
||||
"#endif\n"
|
||||
"\n\n",
|
||||
config.bits_per_byte);
|
||||
"#endif\n" "\n\n", config.bits_per_byte);
|
||||
}
|
||||
|
||||
if (config.arch_x86) {
|
||||
if (config.arch_x86)
|
||||
{
|
||||
fprintf (out, "#define CPU_X86 %d\n", config.cpu_x86);
|
||||
}
|
||||
|
||||
if (config.with_threads) {
|
||||
if (config.with_threads)
|
||||
{
|
||||
fprintf (out, "#define HAS_PTHREADS 1\n");
|
||||
}
|
||||
fprintf (out, "\n");
|
||||
switch (config.local_os) {
|
||||
switch (config.local_os)
|
||||
{
|
||||
case os_hp08:
|
||||
case os_hp09:
|
||||
case os_hp10:
|
||||
|
@ -698,10 +823,10 @@ void make_config_h()
|
|||
|
||||
}
|
||||
|
||||
void help()
|
||||
void
|
||||
help ()
|
||||
{
|
||||
printf(
|
||||
"\n\n"
|
||||
printf ("\n\n"
|
||||
"***** qfits configure help\n"
|
||||
"Use: configure [options]\n"
|
||||
"\n"
|
||||
|
@ -748,12 +873,11 @@ void help()
|
|||
"\tdec - Dec OSF/1 or Tru64 Unix\n"
|
||||
"\tsolaris - Sun Solaris >=2.5\n"
|
||||
"\tbsd - BSD compatible Unix\n"
|
||||
"\tdarwin - Darwin (BSD compatible on Mac)\n"
|
||||
"\n"
|
||||
);
|
||||
"\tdarwin - Darwin (BSD compatible on Mac)\n" "\n");
|
||||
}
|
||||
|
||||
int main(argc, argv)
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
|
@ -775,68 +899,121 @@ int main(argc, argv)
|
|||
memset (config.release, 0, MAXSTRSZ);
|
||||
memset (config.machine, 0, MAXSTRSZ);
|
||||
|
||||
for (i=0 ; i<argc ; i++) {
|
||||
if (!strcmp(argv[i], "--help")) {
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (!strcmp (argv[i], "--help"))
|
||||
{
|
||||
help ();
|
||||
return 1;
|
||||
} else if (!strcmp(argv[i], "--debug")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--debug"))
|
||||
{
|
||||
config.debug_compile = 1;
|
||||
} else if (!strcmp(argv[i], "--with-cc")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--with-cc"))
|
||||
{
|
||||
config.compiler = COMPILER_CC;
|
||||
} else if (!strcmp(argv[i], "--with-gcc")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--with-gcc"))
|
||||
{
|
||||
config.compiler = COMPILER_GCC;
|
||||
} else if (!strcmp(argv[i], "--lint")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--lint"))
|
||||
{
|
||||
config.lint_compile = 1;
|
||||
} else if (!strcmp(argv[i], "--mt")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--mt"))
|
||||
{
|
||||
config.with_threads = 1;
|
||||
} else if (!strcmp(argv[i], "--enable-shared")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--enable-shared"))
|
||||
{
|
||||
config.lib_dynamic = 1;
|
||||
} else if (!strcmp(argv[i], "--disable-shared")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--disable-shared"))
|
||||
{
|
||||
config.lib_dynamic = 0;
|
||||
} else if (!strcmp(argv[i], "--enable-static")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--enable-static"))
|
||||
{
|
||||
config.lib_static = 1;
|
||||
} else if (!strcmp(argv[i], "--disable-static")) {
|
||||
}
|
||||
else if (!strcmp (argv[i], "--disable-static"))
|
||||
{
|
||||
config.lib_static = 0;
|
||||
} else if (!strncmp(argv[i], "--prefix=", 9)) {
|
||||
}
|
||||
else if (!strncmp (argv[i], "--prefix=", 9))
|
||||
{
|
||||
config.prefix = strchr (argv[i], '=') + 1;
|
||||
} else if (!strncmp(argv[i], "--max-ptrs=", 11)) {
|
||||
}
|
||||
else if (!strncmp (argv[i], "--max-ptrs=", 11))
|
||||
{
|
||||
sval = strchr (argv[i], '=') + 1;
|
||||
config.max_ptrs = (int) atoi (sval);
|
||||
} else if (!strncmp(argv[i], "--xmemory-mode=", 15)) {
|
||||
}
|
||||
else if (!strncmp (argv[i], "--xmemory-mode=", 15))
|
||||
{
|
||||
sval = strchr (argv[i], '=') + 1;
|
||||
config.xmemory_mode = (int) atoi (sval);
|
||||
} else if (!strncmp(argv[i], "--os=", 5)) {
|
||||
}
|
||||
else if (!strncmp (argv[i], "--os=", 5))
|
||||
{
|
||||
strcpy (sysname, argv[i] + 5);
|
||||
if (!strcmp(sysname, "linux")) {
|
||||
if (!strcmp (sysname, "linux"))
|
||||
{
|
||||
strcpy (config.sysname, "Linux");
|
||||
} else if (!strcmp(sysname, "cygwin")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "cygwin"))
|
||||
{
|
||||
strcpy (config.sysname, "CYGWIN");
|
||||
} else if (!strcmp(sysname, "hp08")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "hp08"))
|
||||
{
|
||||
strcpy (config.sysname, "HPUX");
|
||||
strcpy (config.release, "8.x");
|
||||
} else if (!strcmp(sysname, "hp09")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "hp09"))
|
||||
{
|
||||
strcpy (config.sysname, "HPUX");
|
||||
strcpy (config.release, "9.x");
|
||||
} else if (!strcmp(sysname, "hp10")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "hp10"))
|
||||
{
|
||||
strcpy (config.sysname, "HPUX");
|
||||
strcpy (config.release, "10.x");
|
||||
} else if (!strcmp(sysname, "hp11")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "hp11"))
|
||||
{
|
||||
strcpy (config.sysname, "HPUX");
|
||||
strcpy (config.release, "11.x");
|
||||
} else if (!strcmp(sysname, "irix")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "irix"))
|
||||
{
|
||||
strcpy (config.sysname, "IRIX64");
|
||||
} else if (!strcmp(sysname, "aix")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "aix"))
|
||||
{
|
||||
strcpy (config.sysname, "AIX");
|
||||
} else if (!strcmp(sysname, "dec")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "dec"))
|
||||
{
|
||||
strcpy (config.sysname, "Dec OSF/1 or Tru64");
|
||||
} else if (!strcmp(sysname, "solaris")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "solaris"))
|
||||
{
|
||||
strcpy (config.sysname, "Solaris");
|
||||
strcpy (config.release, ">= 2.5");
|
||||
} else if (!strcmp(sysname, "bsd")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "bsd"))
|
||||
{
|
||||
strcpy (config.sysname, "BSD compatible");
|
||||
} else if (!strcmp(sysname, "darwin")) {
|
||||
}
|
||||
else if (!strcmp (sysname, "darwin"))
|
||||
{
|
||||
strcpy (config.sysname, "Darwin");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("unsupported OS: %s\n", sysname);
|
||||
return -1;
|
||||
}
|
||||
|
@ -848,6 +1025,3 @@ int main(argc, argv)
|
|||
make_config_h ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue