Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
msc
sextractor
Commits
869e9a3f
Commit
869e9a3f
authored
Feb 25, 2023
by
Emmanuel Bertin
Browse files
Fix various CFITSIO issues.
parent
f579530e
Changes
9
Hide whitespace changes
Inline
Side-by-side
doc/src/conf.py
View file @
869e9a3f
...
@@ -81,7 +81,7 @@ language = None
...
@@ -81,7 +81,7 @@ language = None
# There are two options for replacing |today|: either, you set today to some
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# non-false value, then it is used:
#
#
today
=
'
Fri Sep 16
202
2
'
today
=
'
Sat Feb 25
202
3
'
#
#
# Else, today_fmt is used as the format for a strftime call.
# Else, today_fmt is used as the format for a strftime call.
#
#
...
...
src/check.c
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: SExtractor
* This file part of: SExtractor
*
*
* Copyright: (C) 1993-20
1
3
Emmanuel Bertin -- IAP/CNRS/UPMC
* Copyright: (C) 1993-20
2
3
CFHT/IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified: 2
3
/0
9
/20
1
3
* Last modified: 2
5
/0
2
/20
2
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -406,6 +406,7 @@ void reinitcheck(picstruct *field, checkstruct *check)
...
@@ -406,6 +406,7 @@ void reinitcheck(picstruct *field, checkstruct *check)
remove_tabs
(
cat
);
remove_tabs
(
cat
);
copy_tab_fromptr
(
field
->
tab
,
cat
,
0
);
copy_tab_fromptr
(
field
->
tab
,
cat
,
0
);
tab
=
cat
->
tab
;
tab
=
cat
->
tab
;
decomp_head
(
tab
);
tab
->
cat
=
cat
;
tab
->
cat
=
cat
;
if
(
check
->
next
<=
1
)
if
(
check
->
next
<=
1
)
prim_head
(
tab
);
prim_head
(
tab
);
...
...
src/field.c
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: SExtractor
* This file part of: SExtractor
*
*
* Copyright: (C) 1993-202
0
IAP/CNRS/SorbonneU
* Copyright: (C) 1993-202
3 CFHT/
IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified: 2
3
/0
9
/202
0
* Last modified: 2
5
/0
2
/202
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -70,25 +70,19 @@ picstruct *newfield(char *filename, int flags, int ext)
...
@@ -70,25 +70,19 @@ picstruct *newfield(char *filename, int flags, int ext)
field
->
cat
=
cat
;
field
->
cat
=
cat
;
nok
=
0
;
nok
=
0
;
tab
=
cat
->
tab
;
tab
=
cat
->
tab
;
#ifdef HAVE_CFITSIO
if
((
tab
->
isTileCompressed
)
||
if
(
tab
->
isTileCompressed
)
(
tab
->
naxis
>=
2
nok
++
;
#endif
if
(
tab
->
naxis
>=
2
&&
strncmp
(
tab
->
xtension
,
"BINTABLE"
,
8
)
&&
strncmp
(
tab
->
xtension
,
"BINTABLE"
,
8
)
&&
strncmp
(
tab
->
xtension
,
"ASCTABLE"
,
8
))
&&
strncmp
(
tab
->
xtension
,
"ASCTABLE"
,
8
))
)
nok
++
;
nok
++
;
ext2
=
ext
;
ext2
=
ext
;
for
(
ntab
=
cat
->
ntab
;
ext2
--
&&
ntab
--
;)
for
(
ntab
=
cat
->
ntab
;
ext2
--
&&
ntab
--
;)
{
{
tab
=
tab
->
nexttab
;
tab
=
tab
->
nexttab
;
#ifdef HAVE_CFITSIO
if
((
tab
->
isTileCompressed
)
||
if
(
tab
->
isTileCompressed
)
(
tab
->
naxis
>=
2
nok
++
;
&&
strncmp
(
tab
->
xtension
,
"BINTABLE"
,
8
)
#endif
&&
strncmp
(
tab
->
xtension
,
"ASCTABLE"
,
8
)))
if
(
tab
->
naxis
>=
2
&&
strncmp
(
tab
->
xtension
,
"BINTABLE"
,
8
)
&&
strncmp
(
tab
->
xtension
,
"ASCTABLE"
,
8
))
nok
++
;
nok
++
;
}
}
if
(
!
nok
)
if
(
!
nok
)
...
...
src/fits/fitsbody.c
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: AstrOmatic FITS/LDAC library
* This file part of: AstrOmatic FITS/LDAC library
*
*
* Copyright: (C) 1995-202
0
IAP/CNRS/SorbonneU
* Copyright: (C) 1995-202
3 CFHT/
IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
* along with AstrOmatic software.
* along with AstrOmatic software.
* If not, see <http://www.gnu.org/licenses/>.
* If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified: 2
6
/0
8
/202
0
* Last modified: 2
5
/0
2
/202
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -394,8 +394,8 @@ INPUT A pointer to the tab structure,
...
@@ -394,8 +394,8 @@ INPUT A pointer to the tab structure,
the number of elements to be read.
the number of elements to be read.
OUTPUT -.
OUTPUT -.
NOTES .
NOTES .
AUTHOR E. Bertin (
IAP
)
AUTHOR E. Bertin (
CFHT/IAP/CNRS/SorbonneU
)
VERSION 2
6
/0
8
/202
0
VERSION 2
5
/0
2
/202
3
***/
***/
void
read_body
(
tabstruct
*
tab
,
PIXTYPE
*
ptr
,
size_t
size
)
void
read_body
(
tabstruct
*
tab
,
PIXTYPE
*
ptr
,
size_t
size
)
{
{
...
@@ -439,7 +439,7 @@ void read_body(tabstruct *tab, PIXTYPE *ptr, size_t size)
...
@@ -439,7 +439,7 @@ void read_body(tabstruct *tab, PIXTYPE *ptr, size_t size)
bufdata
=
(
char
*
)
bufdata0
;
bufdata
=
(
char
*
)
bufdata0
;
#ifdef HAVE_CFITSIO
#ifdef HAVE_CFITSIO
if
(
tab
->
isTileCompressed
)
if
(
tab
->
isTileCompressed
&&
tab
->
infptr
)
readTileCompressed
(
tab
,
spoonful
,
(
void
*
)
bufdata0
);
readTileCompressed
(
tab
,
spoonful
,
(
void
*
)
bufdata0
);
else
else
QFREAD
(
bufdata
,
spoonful
*
tab
->
bytepix
,
cat
->
file
,
cat
->
filename
);
QFREAD
(
bufdata
,
spoonful
*
tab
->
bytepix
,
cat
->
file
,
cat
->
filename
);
...
...
src/fits/fitscat.c
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: AstrOmatic FITS/LDAC library
* This file part of: AstrOmatic FITS/LDAC library
*
*
* Copyright: (C) 1995-202
0
IAP/CNRS/SorbonneU
* Copyright: (C) 1995-202
3 CFHT/
IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
* along with AstrOmatic software.
* along with AstrOmatic software.
* If not, see <http://www.gnu.org/licenses/>.
* If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified: 2
6
/0
8
/202
0
* Last modified: 2
5
/0
2
/202
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -42,6 +42,8 @@
...
@@ -42,6 +42,8 @@
#include
"fitscat_defs.h"
#include
"fitscat_defs.h"
#include
"fitscat.h"
#include
"fitscat.h"
extern
float
*
fits_rand_value
;
char
fits_str
[
MAXCHAR
];
char
fits_str
[
MAXCHAR
];
/****** about_cat **************************************************************
/****** about_cat **************************************************************
...
@@ -168,29 +170,33 @@ int close_cat(catstruct *cat)
...
@@ -168,29 +170,33 @@ int close_cat(catstruct *cat)
}
}
#ifdef HAVE_CFITSIO
#ifdef HAVE_CFITSIO
/****** close_cfitsio **************************************************************
/****** close_cfitsio **********************************************************
PROTO int close_cfitsio(fitsfile **infptr)
Closes a file previously opened by cfitsio
PURPOSE Close a file previously opened by cfitsio
INPUT fitsfile structure.
OUTPUT RETURN_OK if everything went as expected (exit in error otherwise).
NOTES the fitsfile pointer is set to NULL;
AUTHOR E. Bertin (CFHT/IAP/CNRS/SorbonneU)
VERSION 25/02/2023
***/
***/
int
close_cfitsio
(
fitsfile
*
infptr
)
int
close_cfitsio
(
catstruct
*
cat
)
{
{
if
((
cat
)
&&
(
cat
->
infptr
))
{
if
(
infptr
!=
NULL
)
{
int
status
=
0
;
fits_close_file
(
cat
->
infptr
,
&
status
);
int
status
=
0
;
fits_close_file
(
infptr
,
&
status
);
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
fits_report_error
(
stderr
,
status
);
fits_report_error
(
stderr
,
status
);
error
(
EXIT_FAILURE
,
"Could not close FITS file with cfitsio: "
,
printf
(
"ERROR could not close FITS file with cfitsio
\n
"
);
cat
->
filename
);
}
}
else
{
else
{
// Successfully closed FITS file with cfitsio
//printf("Successfully closed FITS file with cfitsio\n")
;
cat
->
infptr
==
NULL
;
infptr
==
NULL
;
// Free random seed in CFITSIO.
}
QFREE
(
fits_rand_value
);
}
}
else
{
}
else
//printf("ERROR no cfitsio file to close\n")
;
return
RETURN_ERROR
;
}
return
RETURN_OK
;
}
}
#endif // HAVE_CFITSIO
#endif // HAVE_CFITSIO
...
@@ -202,8 +208,8 @@ INPUT Pointer to a catalog structure,
...
@@ -202,8 +208,8 @@ INPUT Pointer to a catalog structure,
Number of catalogs.
Number of catalogs.
OUTPUT -.
OUTPUT -.
NOTES Unallocated pointers should have been put to NULL.
NOTES Unallocated pointers should have been put to NULL.
AUTHOR E. Bertin (
IAP & Leiden observatory
)
AUTHOR E. Bertin (
CFHT/IAP/CNRS/SorbonneU
)
VERSION
0
5/
1
2/20
09
VERSION
2
5/
0
2/20
23
***/
***/
void
free_cat
(
catstruct
**
cat
,
int
ncat
)
void
free_cat
(
catstruct
**
cat
,
int
ncat
)
...
@@ -218,6 +224,10 @@ void free_cat(catstruct **cat, int ncat)
...
@@ -218,6 +224,10 @@ void free_cat(catstruct **cat, int ncat)
if
((
*
thecat
)
->
file
)
if
((
*
thecat
)
->
file
)
close_cat
(
*
thecat
);
close_cat
(
*
thecat
);
remove_tabs
(
*
thecat
);
remove_tabs
(
*
thecat
);
#ifdef HAVE_CFITSIO
// Free resources allocated for CFITSIO
close_cfitsio
(
*
thecat
);
#endif
free
(
*
(
thecat
++
));
free
(
*
(
thecat
++
));
}
}
...
@@ -338,8 +348,8 @@ PURPOSE Explores the whole FITS file
...
@@ -338,8 +348,8 @@ PURPOSE Explores the whole FITS file
INPUT catalog structure.
INPUT catalog structure.
OUTPUT RETURN_OK if at least one table was found, RETURN_ERROR otherwise.
OUTPUT RETURN_OK if at least one table was found, RETURN_ERROR otherwise.
NOTES Memory space for the array of fits structures is reallocated.
NOTES Memory space for the array of fits structures is reallocated.
AUTHOR E. Bertin (
IAP & Leiden observatory
)
AUTHOR E. Bertin (
CFHT/IAP/CNRS/SorbonneU
)
VERSION
14/1
2/20
0
2
VERSION
25/0
2/202
3
***/
***/
int
map_cat
(
catstruct
*
cat
)
int
map_cat
(
catstruct
*
cat
)
...
@@ -355,15 +365,7 @@ int map_cat(catstruct *cat)
...
@@ -355,15 +365,7 @@ int map_cat(catstruct *cat)
#ifdef HAVE_CFITSIO
#ifdef HAVE_CFITSIO
fitsfile
*
infptr
;
fitsfile
*
infptr
;
int
status
,
hdutype
,
hdunum
;
int
status
,
hdutype
,
hdunum
=
1
;
status
=
0
;
fits_open_file
(
&
infptr
,
cat
->
filename
,
READONLY
,
&
status
);
if
(
status
!=
0
)
{
fits_report_error
(
stderr
,
status
);
printf
(
"ERROR could not open FITS file with cfitsio: %s
\n
"
,
cat
->
filename
);
}
hdunum
=
1
;
int
any_tile_compressed
=
0
;
#endif // HAVE_CFITSIO
#endif // HAVE_CFITSIO
for
(
ntab
=
0
;
!
get_head
(
tab
);
ntab
++
)
for
(
ntab
=
0
;
!
get_head
(
tab
);
ntab
++
)
...
@@ -375,31 +377,22 @@ int map_cat(catstruct *cat)
...
@@ -375,31 +377,22 @@ int map_cat(catstruct *cat)
#ifdef HAVE_CFITSIO
#ifdef HAVE_CFITSIO
if
(
tab
->
isTileCompressed
)
{
if
(
tab
->
isTileCompressed
)
{
// Trigger CFITSIO file opening
any_tile_compressed
=
1
;
status
=
0
;
tab
->
hdunum
=
hdunum
;
if
(
!
cat
->
infptr
)
{
tab
->
infptr
=
infptr
;
fits_open_file
(
&
cat
->
infptr
,
cat
->
filename
,
READONLY
,
&
status
);
if
(
status
!=
0
)
{
status
=
0
;
fits_movabs_hdu
(
tab
->
infptr
,
tab
->
hdunum
,
&
hdutype
,
&
status
);
fits_report_error
(
stderr
,
status
);
if
(
status
!=
0
)
printf
(
"ERROR could not move to hdu %d in file %s
\n
"
,
tab
->
hdunum
,
cat
->
filename
);
error
(
EXIT_FAILURE
,
"Could not open FITS file with cfitsio: %s
\n
"
,
cat
->
filename
);
if
(
tab
->
tabsize
)
}
fseek
(
cat
->
file
,
infptr
->
Fptr
->
headstart
[
hdunum
],
SEEK_SET
);
}
}
tab
->
infptr
=
cat
->
infptr
;
// NOT tile-compressed
else
{
tab
->
infptr
=
NULL
;
if
(
tab
->
tabsize
)
QFSEEK
(
cat
->
file
,
PADTOTAL
(
tab
->
tabsize
),
SEEK_CUR
,
cat
->
filename
);
}
}
tab
->
hdunum
=
hdunum
++
;
hdunum
++
;
#endif // HAVE_CFITSIO
#else
if
(
tab
->
tabsize
)
if
(
tab
->
tabsize
)
QFSEEK
(
cat
->
file
,
PADTOTAL
(
tab
->
tabsize
),
SEEK_CUR
,
cat
->
filename
);
QFSEEK
(
cat
->
file
,
PADTOTAL
(
tab
->
tabsize
),
SEEK_CUR
,
cat
->
filename
);
#endif // HAVE_CFITSIO
if
(
prevtab
)
if
(
prevtab
)
{
{
...
@@ -414,12 +407,6 @@ int map_cat(catstruct *cat)
...
@@ -414,12 +407,6 @@ int map_cat(catstruct *cat)
QFTELL
(
cat
->
file
,
tab
->
headpos
,
cat
->
filename
);
QFTELL
(
cat
->
file
,
tab
->
headpos
,
cat
->
filename
);
}
}
#ifdef HAVE_CFITSIO
// we will not need CFitsIO, so close CFitsIO file pointer now
if
(
!
any_tile_compressed
)
close_cfitsio
(
infptr
);
#endif
cat
->
ntab
=
ntab
;
cat
->
ntab
=
ntab
;
free
(
tab
);
free
(
tab
);
if
(
prevtab
)
if
(
prevtab
)
...
...
src/fits/fitscat.h
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: AstrOmatic FITS/LDAC library
* This file part of: AstrOmatic FITS/LDAC library
*
*
* Copyright: (C) 1995-202
0
IAP/CNRS/SorbonneU
* Copyright: (C) 1995-202
3 CFHT/
IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
* along with AstrOmatic software.
* along with AstrOmatic software.
* If not, see <http://www.gnu.org/licenses/>.
* If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified: 2
6
/0
8
/202
0
* Last modified: 2
5
/0
2
/202
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -155,6 +155,9 @@ typedef struct structcat
...
@@ -155,6 +155,9 @@ typedef struct structcat
struct
structtab
*
tab
;
/* pointer to the first table */
struct
structtab
*
tab
;
/* pointer to the first table */
int
ntab
;
/* number of tables included */
int
ntab
;
/* number of tables included */
access_type_t
access_type
;
/* READ_ONLY or WRITE_ONLY */
access_type_t
access_type
;
/* READ_ONLY or WRITE_ONLY */
#ifdef HAVE_CFITSIO
fitsfile
*
infptr
;
/* a cfitsio pointer to the file */
#endif
}
catstruct
;
}
catstruct
;
/*-------------------------------- table ----------------------------------*/
/*-------------------------------- table ----------------------------------*/
...
@@ -195,12 +198,12 @@ typedef struct structtab
...
@@ -195,12 +198,12 @@ typedef struct structtab
int
nkey
;
/* number of keys */
int
nkey
;
/* number of keys */
int
swapflag
;
/* mapped to a swap file ? */
int
swapflag
;
/* mapped to a swap file ? */
char
swapname
[
MAXCHARS
];
/* name of the swapfile */
char
swapname
[
MAXCHARS
];
/* name of the swapfile */
unsigned
int
bodysum
;
/* Checksum of the FITS body */
unsigned
int
bodysum
;
/* Checksum of the FITS body */
int
isTileCompressed
;
/* is this a tile compressed image? */
#ifdef HAVE_CFITSIO
#ifdef HAVE_CFITSIO
fitsfile
*
infptr
;
/* a cfitsio pointer to the file */
fitsfile
*
infptr
;
/* a cfitsio pointer to the file */
int
hdunum
;
/* FITS HDU number for this 'table' */
int
hdunum
;
/* FITS HDU number for this 'table' */
int
isTileCompressed
;
/* is this a tile compressed image? */
long
currentElement
;
/* tracks the current image pixel */
long
currentElement
;
/* tracks the current image pixel */
#endif
#endif
}
tabstruct
;
}
tabstruct
;
...
@@ -283,7 +286,7 @@ extern int about_cat(catstruct *cat, FILE *stream),
...
@@ -283,7 +286,7 @@ extern int about_cat(catstruct *cat, FILE *stream),
blank_keys
(
tabstruct
*
tab
),
blank_keys
(
tabstruct
*
tab
),
close_cat
(
catstruct
*
cat
),
close_cat
(
catstruct
*
cat
),
#ifdef HAVE_CFITSIO
#ifdef HAVE_CFITSIO
close_cfitsio
(
fitsfile
*
infptr
),
close_cfitsio
(
catstruct
*
cat
),
#endif
#endif
copy_key
(
tabstruct
*
tabin
,
char
*
keyname
,
tabstruct
*
tabout
,
copy_key
(
tabstruct
*
tabin
,
char
*
keyname
,
tabstruct
*
tabout
,
int
pos
),
int
pos
),
...
@@ -329,6 +332,7 @@ extern int about_cat(catstruct *cat, FILE *stream),
...
@@ -329,6 +332,7 @@ extern int about_cat(catstruct *cat, FILE *stream),
tformof
(
char
*
str
,
t_type
ttype
,
int
n
),
tformof
(
char
*
str
,
t_type
ttype
,
int
n
),
tsizeof
(
char
*
str
),
tsizeof
(
char
*
str
),
update_head
(
tabstruct
*
tab
),
update_head
(
tabstruct
*
tab
),
decomp_head
(
tabstruct
*
tab
),
update_tab
(
tabstruct
*
tab
),
update_tab
(
tabstruct
*
tab
),
verify_checksum
(
tabstruct
*
tab
),
verify_checksum
(
tabstruct
*
tab
),
write_obj
(
tabstruct
*
tab
,
char
*
buf
),
write_obj
(
tabstruct
*
tab
,
char
*
buf
),
...
...
src/fits/fitshead.c
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: AstrOmatic FITS/LDAC library
* This file part of: AstrOmatic FITS/LDAC library
*
*
* Copyright: (C) 1995-202
2
IAP/CNRS/SorbonneU
* Copyright: (C) 1995-202
3 CFHT/
IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
* along with AstrOmatic software.
* along with AstrOmatic software.
* If not, see <http://www.gnu.org/licenses/>.
* If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified:
11
/0
3
/202
2
* Last modified:
25
/0
2
/202
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -100,85 +100,92 @@ PURPOSE Read the current FITS header basic keywords.
...
@@ -100,85 +100,92 @@ PURPOSE Read the current FITS header basic keywords.
INPUT pointer to catstruct.
INPUT pointer to catstruct.
OUTPUT -.
OUTPUT -.
NOTES -.
NOTES -.
AUTHOR E. Bertin (
IAP
)
AUTHOR E. Bertin (
CFHT/IAP/SorbonneU
)
VERSION
04/1
2/20
19
VERSION
25/0
2/20
23
***/
***/
void
readbasic_head
(
tabstruct
*
tab
)
void
readbasic_head
(
tabstruct
*
tab
)
{
{
char
str
[
88
];
char
str
[
88
];
char
key
[
12
],
name
[
16
],
bitpix_key
[
16
],
naxis_key
[
16
],
char
key
[
12
],
name
[
16
],
*
filename
;
*
bitpix_key
,
*
naxis_key
,
*
filename
;
int
i
;
int
i
,
bitpix
,
bytepix
,
naxis
,
naxisn
;
KINGSIZE_T
tabsize
;
KINGSIZE_T
tabsize
;
filename
=
(
tab
->
cat
?
tab
->
cat
->
filename
:
strcpy
(
name
,
"internal header"
));
filename
=
(
tab
->
cat
?
tab
->
cat
->
filename
:
strcpy
(
name
,
"internal header"
));
strncpy
(
bitpix_key
,
"BITPIX "
,
9
);
strncpy
(
naxis_key
,
"NAXIS "
,
9
);
#ifdef HAVE_CFITSIO
tab
->
isTileCompressed
=
(
fitsread
(
tab
->
headbuf
,
"ZIMAGE "
,
tab
->
isTileCompressed
=
(
fitsread
(
tab
->
headbuf
,
"ZIMAGE "
,
str
,
H_STRING
,
T_STRING
)
==
RETURN_OK
)
?
1
:
0
;
str
,
H_STRING
,
T_STRING
)
==
RETURN_OK
)
?
1
:
0
;
if
(
tab
->
isTileCompressed
)
{
strncpy
(
bitpix_key
,
"ZBITPIX "
,
9
);
if
(
fitsread
(
tab
->
headbuf
,
tab
->
isTileCompressed
?
"ZBITPIX "
:
"BITPIX "
,
strncpy
(
naxis_key
,
"ZNAXIS "
,
9
);
&
tab
->
bitpix
,
H_INT
,
T_LONG
)
==
RETURN_ERROR
)
}
#endif
if
(
fitsread
(
tab
->
headbuf
,
bitpix_key
,
&
tab
->
bitpix
,
H_INT
,
T_LONG
)
==
RETURN_ERROR
)
error
(
EXIT_FAILURE
,
"*Error*: Corrupted FITS header in "
,
filename
);
error
(
EXIT_FAILURE
,
"*Error*: Corrupted FITS header in "
,
filename
);
if
(
fitsread
(
tab
->
headbuf
,
naxis_key
,
&
tab
->
naxis
,
H_INT
,
T_LONG
)
if
(
fitsread
(
tab
->
headbuf
,
tab
->
isTileCompressed
?
"ZNAXIS "
:
"NAXIS "
,
==
RETURN_ERROR
)
&
tab
->
naxis
,
H_INT
,
T_LONG
)
==
RETURN_ERROR
)
error
(
EXIT_FAILURE
,
"*Error*: Corrupted FITS header in "
,
filename
);
error
(
EXIT_FAILURE
,
"*Error*: Corrupted FITS header in "
,
filename
);
tab
->
bytepix
=
tab
->
bitpix
>
0
?
(
tab
->
bitpix
/
8
)
:
(
-
tab
->
bitpix
/
8
);
tab
->
bytepix
=
tab
->
bitpix
>
0
?
(
tab
->
bitpix
/
8
)
:
(
-
tab
->
bitpix
/
8
);
tabsize
=
0
;
if
(
tab
->
naxis
>
0
)
{
if
(
tab
->
naxis
>
0
)
{
QFREE
(
tab
->
naxisn
);
QFREE
(
tab
->
naxisn
);
QMALLOC
(
tab
->
naxisn
,
int
,
tab
->
naxis
);
QMALLOC
(
tab
->
naxisn
,
int
,
tab
->
naxis
);
/*--get the size of the array*/
/*--get the size of the array*/
tabsize
=
1
;
for
(
i
=
0
;
i
<
tab
->
naxis
&&
i
<
999
;
i
++
)
{
for
(
i
=
0
;
i
<
tab
->
naxis
&&
i
<
999
;
i
++
)
sprintf
(
key
,
tab
->
isTileCompressed
?
"ZNAXIS%-2d"
:
"NAXIS%-3d"
,
i
+
1
);
{
#ifdef HAVE_CFITSIO
if
(
tab
->
isTileCompressed
)
sprintf
(
key
,
"ZNAXIS%-2d"
,
i
+
1
);
else
#endif
sprintf
(
key
,
"NAXIS%-3d"
,
i
+
1
);
if
(
fitsread
(
tab
->
headbuf
,
key
,
&
tab
->
naxisn
[
i
],
H_INT
,
T_LONG
)
if
(
fitsread
(
tab
->
headbuf
,
key
,
&
tab
->
naxisn
[
i
],
H_INT
,
T_LONG
)
==
RETURN_ERROR
)
==
RETURN_ERROR
)
error
(
EXIT_FAILURE
,
"*Error*: incoherent FITS header in "
,
filename
);
error
(
EXIT_FAILURE
,
"*Error*: inconsistent FITS header in "
,
filename
);
tabsize
*=
tab
->
naxisn
[
i
];
}
}
}
}
/*random groups parameters (optional)*/
/* In case of a non-primary header*/
tab
->
pcount
=
0
;
tab
->
xtension
[
0
]
=
(
char
)
'\0'
;
fitsread
(
tab
->
headbuf
,
"PCOUNT "
,
&
tab
->
pcount
,
H_INT
,
T_LONG
);
fitsread
(
tab
->
headbuf
,
"XTENSION"
,
tab
->
xtension
,
H_STRING
,
T_STRING
);
tab
->
extname
[
0
]
=
(
char
)
'\0'
;
fitsread
(
tab
->
headbuf
,
"EXTNAME "
,
tab
->
extname
,
H_STRING
,
T_STRING
);
#ifdef HAVE_CFITSIO
/* Number of fields (only for tables)*/
// CFITSIO TODO HACK
tab
->
tfields
=
0
;
if
(
tab
->
isTileCompressed
)
fitsread
(
tab
->
headbuf
,
"TFIELDS "
,
&
tab
->
tfields
,
H_INT
,
T_LONG
);
tab
->
pcount
=
0
;
#endif
/* Random groups parameters (optional)*/
tab
->
gcount
=
1
;
tab
->
gcount
=
1
;
fitsread
(
tab
->
headbuf
,
"GCOUNT "
,
&
tab
->
gcount
,
H_INT
,
T_LONG
);
fitsread
(
tab
->
headbuf
,
"GCOUNT "
,
&
tab
->
gcount
,
H_INT
,
T_LONG
);
tab
->
pcount
=
0
;
fitsread
(
tab
->
headbuf
,
"PCOUNT "
,
&
tab
->
pcount
,
H_INT
,
T_LONG
);
/*number of fields (only for tables)*/
/* Compute extension body size in bytes */
tab
->
tfields
=
0
;
if
(
tab
->
isTileCompressed
)
{
fitsread
(
tab
->
headbuf
,
"TFIELDS "
,
&
tab
->
tfields
,
H_INT
,
T_LONG
);
if
(
fitsread
(
tab
->
headbuf
,
"BITPIX "
,
&
bitpix
,
H_INT
,
T_LONG
)
==
RETURN_ERROR
)
/*in case of a non-primary header*/
error
(
EXIT_FAILURE
,
"*Error*: Corrupted FITS header in "
,
filename
);
tab
->
xtension
[
0
]
=
(
char
)
'\0'
;
bytepix
=
bitpix
>
0
?
(
bitpix
/
8
)
:
(
-
bitpix
/
8
);
fitsread
(
tab
->
headbuf
,
"XTENSION"
,
tab
->
xtension
,
H_STRING
,
T_STRING
);
tab
->
extname
[
0
]
=
(
char
)
'\0'
;
fitsread
(
tab
->
headbuf
,
"EXTNAME "
,
tab
->
extname
,
H_STRING
,
T_STRING
);
tab
->
tabsize
=
tab
->
bytepix
*
tab
->
gcount
*
((
size_t
)
tab
->
pcount
+
tabsize
);
if
(
fitsread
(
tab
->
headbuf
,
"NAXIS "
,
&
naxis
,
H_INT
,
T_LONG
)
==
RETURN_ERROR
)
error
(
EXIT_FAILURE
,
"*Error*: Corrupted FITS header in "
,
filename
);
if
((
naxis
))
{
tabsize
=
1
;
for
(
i
=
0
;
i
<
naxis
&&
i
<
999
;
i
++
)
{
naxisn
=
1
;
sprintf
(
key
,
"NAXIS%-3d"
,
i
+
1
);
if
(
fitsread
(
tab
->
headbuf
,
key
,
&
naxisn
,
H_INT
,
T_LONG
)
==
RETURN_ERROR
)
error
(
EXIT_FAILURE
,
"*Error*: inconsistent FITS header in "
,
filename
);
tabsize
*=
naxisn
;
}
}
else
tabsize
=
0
;
}
else
{
bytepix
=
tab
->
bytepix
;
if
((
tab
->
naxis
))
{
tabsize
=
1
;
for
(
i
=
0
;
i
<
tab
->
naxis
&&
i
<
999
;
i
++
)
tabsize
*=
tab
->
naxisn
[
i
];
}
else
tabsize
=
0
;
}
tab
->
tabsize
=
bytepix
*
tab
->
gcount
*
((
size_t
)
tab
->
pcount
+
tabsize
);
/* Scaling parameters for basic FITS integer arrays */
/* Scaling parameters for basic FITS integer arrays */
tab
->
bscale
=
1
.
0
;
tab
->
bscale
=
1
.
0
;
...
@@ -919,3 +926,49 @@ char *printftotdisp(char *cprintf, char *str)
...
@@ -919,3 +926,49 @@ char *printftotdisp(char *cprintf, char *str)
return
str
;
return
str
;
}
}
/****** decomp_head ***********************************************************
PROTO int decomp_head(tabstruct *tab)
PURPOSE Update a FITS header so that it now matches uncompressed data format.
INPUT Table structure.
OUTPUT RETURN_OK if tab is a compressed binary table,
or RETURN_ERROR otherwise.
NOTES The headbuf pointer in the tabstruct might be reallocated.
AUTHOR E. Bertin (CFHT/IAP/CNRS/SorbonneU)
VERSION 25/02/2023
***/
int
decomp_head
(
tabstruct
*
tab
)
{
#ifdef HAVE_CFITSIO
/* Update XTENSION, the extension type */
if
(
tab
->
isTileCompressed
&&
*
tab
->
xtension
)
{
strcpy
(
tab
->
xtension
,
"IMAGE"
);
addkeywordto_head
(
tab
,
"XTENSION"
,
"EXTENSION TYPE"
);
fitswrite
(
tab
->
headbuf
,
"XTENSION"
,
tab
->
xtension
,
H_STRING
,
T_STRING
);
addkeywordto_head
(
tab
,
"PCOUNT "
,
"required keyword; must = 0"
);
addkeywordto_head
(
tab
,
"GCOUNT "
,
"required keyword; must = 1"
);
tab
->
pcount
=
0
;
tab
->
gcount
=
1
;
fitswrite
(
tab
->
headbuf
,
"PCOUNT "
,
&
tab
->
pcount
,
H_INT
,
T_LONG
);
fitswrite
(
tab
->
headbuf
,
"GCOUNT "
,
&
tab
->
gcount
,
H_INT
,
T_LONG
);
tab
->
isTileCompressed
=
0
;
/*-- Remove all compression-related keywords */
removekeywordfrom_head
(
tab
,
"TFIELDS?"
);
removekeywordfrom_head
(
tab
,
"TTYPE???"
);
removekeywordfrom_head
(
tab
,
"TFORM???"
);
removekeywordfrom_head
(
tab
,
"ZIMAGE??"
);
removekeywordfrom_head
(
tab
,
"ZBITPIX?"
);
removekeywordfrom_head
(
tab
,
"ZNAXIS??"
);
removekeywordfrom_head
(
tab
,
"ZTILE???"
);
removekeywordfrom_head
(
tab
,
"ZCMPTYPE"
);
removekeywordfrom_head
(
tab
,
"ZNAME???"
);
removekeywordfrom_head
(
tab
,
"ZVAL????"
);
update_head
(
tab
);
return
RETURN_OK
;
}
else
#endif
return
RETURN_ERROR
;
}
src/fits/fitstab.c
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: AstrOmatic FITS/LDAC library
* This file part of: AstrOmatic FITS/LDAC library
*
*
* Copyright: (C) 1995-20
10 Emmanuel Bertin -- IAP/CNRS/UPMC
* Copyright: (C) 1995-20
23 CFHT/IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
* along with AstrOmatic software.
* along with AstrOmatic software.
* If not, see <http://www.gnu.org/licenses/>.
* If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified:
11
/0
9
/20
1
2
* Last modified:
25
/0
2
/202
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -35,6 +35,10 @@
...
@@ -35,6 +35,10 @@
#include
<stdlib.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
#ifdef HAVE_CFITSIO
#include CFITSIO_H
#endif
#include
"fitscat_defs.h"
#include
"fitscat_defs.h"
#include
"fitscat.h"
#include
"fitscat.h"
...
@@ -270,8 +274,8 @@ INPUT Pointer to the original catalog,
...
@@ -270,8 +274,8 @@ INPUT Pointer to the original catalog,
Position (1= first after the primary HDU, <=0 = at the end)
Position (1= first after the primary HDU, <=0 = at the end)
OUTPUT -.
OUTPUT -.
NOTES -.
NOTES -.
AUTHOR E. Bertin (IAP
& Leiden observatory
)
AUTHOR E. Bertin (IAP
/SorbonneU
)
VERSION 2
2
/0
6
/20
01
VERSION 2
5
/0
2
/20
23
***/
***/
void
copy_tab_fromptr
(
tabstruct
*
tabin
,
catstruct
*
catout
,
int
pos
)
void
copy_tab_fromptr
(
tabstruct
*
tabin
,
catstruct
*
catout
,
int
pos
)
...
@@ -318,6 +322,11 @@ void copy_tab_fromptr(tabstruct *tabin, catstruct *catout, int pos)
...
@@ -318,6 +322,11 @@ void copy_tab_fromptr(tabstruct *tabin, catstruct *catout, int pos)
prevtab
->
nexttab
=
nexttab
;
prevtab
->
nexttab
=
nexttab
;
nexttab
->
prevtab
=
prevtab
;
nexttab
->
prevtab
=
prevtab
;
#ifdef HAVE_CFITSIO
// Do not copy CFitsIO file pointer
tabout
->
infptr
=
NULL
;
#endif
return
;
return
;
}
}
...
@@ -396,8 +405,8 @@ PURPOSE Free memory associated to a table pointer.
...
@@ -396,8 +405,8 @@ PURPOSE Free memory associated to a table pointer.
INPUT Pointer to the table.
INPUT Pointer to the table.
OUTPUT -.
OUTPUT -.
NOTES -.
NOTES -.
AUTHOR E. Bertin (
IAP & Leiden observatory
)
AUTHOR E. Bertin (
CFHT/IAP/CNRS/SorbonneU
)
VERSION 2
8
/02/20
00
VERSION 2
5
/02/20
23
***/
***/
void
free_tab
(
tabstruct
*
tab
)
void
free_tab
(
tabstruct
*
tab
)
...
...
src/makeit.c
View file @
869e9a3f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* This file part of: SExtractor
* This file part of: SExtractor
*
*
* Copyright: (C) 1993-202
0
IAP/CNRS/SorbonneU
* Copyright: (C) 1993-202
3 CFHT/
IAP/CNRS/SorbonneU
*
*
* License: GNU General Public License
* License: GNU General Public License
*
*
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
*
*
* Last modified: 2
3
/0
9
/202
0
* Last modified: 2
5
/0
2
/202
3
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
...
@@ -282,12 +282,9 @@ void makeit()
...
@@ -282,12 +282,9 @@ void makeit()
{
{
/*---- Check for the next valid image extension */
/*---- Check for the next valid image extension */
if
((
imatab
->
naxis
<
2
)
if
((
imatab
->
naxis
<
2
)
||
!
strncmp
(
imatab
->
xtension
,
"BINTABLE"
,
8
)
||
!
(
imatab
->
isTileCompressed
||
strncmp
(
imatab
->
xtension
,
"BINTABLE"
,
8
)
)
||
!
strncmp
(
imatab
->
xtension
,
"ASCTABLE"
,
8
))
||
!
strncmp
(
imatab
->
xtension
,
"ASCTABLE"
,
8
))
#ifdef HAVE_CFITSIO
continue
;
if
(
!
imatab
->
isTileCompressed
)
#endif
continue
;
next
++
;
next
++
;
}
}
}
}
...
@@ -324,11 +321,8 @@ void makeit()
...
@@ -324,11 +321,8 @@ void makeit()
{
{
/*-- Check for the next valid image extension */
/*-- Check for the next valid image extension */
if
(
!
forcextflag
&&
((
imatab
->
naxis
<
2
)
if
(
!
forcextflag
&&
((
imatab
->
naxis
<
2
)
||
!
strncmp
(
imatab
->
xtension
,
"BINTABLE"
,
8
)
||
!
(
imatab
->
isTileCompressed
||
strncmp
(
imatab
->
xtension
,
"BINTABLE"
,
8
)
)
||
!
strncmp
(
imatab
->
xtension
,
"ASCTABLE"
,
8
)))
||
!
strncmp
(
imatab
->
xtension
,
"ASCTABLE"
,
8
)))
#ifdef HAVE_CFITSIO
if
(
!
imatab
->
isTileCompressed
)
#endif
continue
;
continue
;
nok
++
;
nok
++
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment