start development of tables routines

This commit is contained in:
eddyem 2019-03-26 21:04:30 +03:00
parent a7927fc570
commit 39e1ac994f
14 changed files with 282 additions and 181 deletions

View File

@ -9,17 +9,10 @@ project(${PROJ} VERSION ${PROJ_VERSION} LANGUAGES C)
# default flags
set(CMAKE_C_FLAGS "${CFLAGS} -O2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -Wextra -Wall -Werror -W")
set(CMAKE_C_FLAGS_RELEASE "")
set(CMAKE_C_FLAGS_DEBUG "-Wextra -Wall -Werror -W")
set(CMAKE_COLOR_MAKEFILE ON)
find_package(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
# cmake -DDEBUG=1 -> debugging
if(DEFINED DEBUG AND DEBUG EQUAL 1)
set(CMAKE_BUILD_TYPE "Debug")
@ -34,9 +27,9 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message("install to ${CMAKE_CURRENT_SOURCE_DIR}/install ")
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/install)
endif()
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_DEBUG})
else()
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_RELEASE})
#set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_DEBUG})
#else()
# set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_RELEASE})
endif()
message("Build type: ${CMAKE_BUILD_TYPE}")

View File

@ -15,14 +15,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef FITSMANIP_H__
#define FITSMANIP_H__
#include <fitsio.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#define Stringify(x) #x
#define OMP_FOR(x) _Pragma(Stringify(omp parallel for x))
#define OMP_FOR(...) _Pragma(Stringify(omp parallel for __VA_ARGS__))
#ifndef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#endif
@ -47,29 +49,6 @@ cfitsio.h BITPIX code values for FITS image types:
#define FLOAT_IMG -32
#define DOUBLE_IMG -64
*/
/*
// FilterType (not only convolution!)
typedef enum{
FILTER_NONE = 0 // simple start
,MEDIAN // median filter
,ADPT_MEDIAN // simple adaptive median
,LAPGAUSS // laplasian of gaussian
,GAUSS // gaussian
,SOBELH // Sobel horizontal
,SOBELV // -//- vertical
,SIMPLEGRAD // simple gradient (by Sobel)
,PREWITTH // Prewitt (horizontal) - simple derivative
,PREWITTV // -//- (vertical)
,SCHARRH // Scharr (modified Sobel)
,SCHARRV
,STEP // "posterisation"
} FType;
typedef struct{
double *data;
size_t size;
}Itmarray;
*/
/**
Keylist: all keys from given HDU
@ -103,12 +82,7 @@ typedef struct{
char tabname[FLEN_CARD]; // table name
table_column *columns; // array of structures 'table_column'
} FITStable;
/*
typedef struct{
size_t amount; // amount of tables in file
FITStable **tables; // array of pointers to tables
} FITStables;
*/
/**
FITS image
*/
@ -144,27 +118,6 @@ typedef struct{
FITSHDU *curHDU; // pointer to current HDU
} FITS;
/*
typedef struct _Filter{
char *name; // filter name
FType FilterType; // filter type
int w; // filter width
int h; // height
double sx; // x half-width
double sy; // y half-width (sx, sy - for Gaussian-type filters)
FITS* (*imfunc)(FITS *in, struct _Filter *f, Itmarray *i); // image function for given conversion type
} Filter;
// mathematical operations when there's no '-i' parameter (for >1 FITS-files)
typedef enum{
MATH_NONE = 0
,MATH_SUM // make sum of all files
,MATH_MEDIAN // calculate median by all files
,MATH_MEAN // calculate mean for all files
,MATH_DIFF // difference of first and rest files
} MathOper;
*/
void keylist_free(KeyList **list);
KeyList *keylist_add_record(KeyList **list, char *rec, int check);
KeyList *keylist_find_key(KeyList *list, char *key);
@ -219,3 +172,50 @@ void initomp();
// pointer to image conversion function
typedef FITS* (*imfuncptr)(FITS *in, Filter *f, Itmarray *i);
*/
/*
// FilterType (not only convolution!)
typedef enum{
FILTER_NONE = 0 // simple start
,MEDIAN // median filter
,ADPT_MEDIAN // simple adaptive median
,LAPGAUSS // laplasian of gaussian
,GAUSS // gaussian
,SOBELH // Sobel horizontal
,SOBELV // -//- vertical
,SIMPLEGRAD // simple gradient (by Sobel)
,PREWITTH // Prewitt (horizontal) - simple derivative
,PREWITTV // -//- (vertical)
,SCHARRH // Scharr (modified Sobel)
,SCHARRV
,STEP // "posterisation"
} FType;
typedef struct{
double *data;
size_t size;
}Itmarray;
*/
/*
typedef struct _Filter{
char *name; // filter name
FType FilterType; // filter type
int w; // filter width
int h; // height
double sx; // x half-width
double sy; // y half-width (sx, sy - for Gaussian-type filters)
FITS* (*imfunc)(FITS *in, struct _Filter *f, Itmarray *i); // image function for given conversion type
} Filter;
// mathematical operations when there's no '-i' parameter (for >1 FITS-files)
typedef enum{
MATH_NONE = 0
,MATH_SUM // make sum of all files
,MATH_MEDIAN // calculate median by all files
,MATH_MEAN // calculate mean for all files
,MATH_DIFF // difference of first and rest files
} MathOper;
*/
#endif // FITSMANIP_H__

View File

@ -5,6 +5,6 @@ includedir=${prefix}/include
Name: @PROJ@
Description: Library with a lot of usefull snippets
Version: @VERSION@
Version: @PROJ_VERSION@
Libs: -L${libdir} -l@PROJ@
Cflags: -I${includedir}

View File

@ -1,8 +1,9 @@
cmake_minimum_required(VERSION 3.9)
project(examples)
include_directories(../)
link_libraries(usefull_macros FITSmanip cfitsio m)
link_libraries(FITSmanip cfitsio m)
#add_executable(fitsstat fitsstat.c)
add_executable(keylist keylist.c)
add_executable(imstat imstat.c)
add_executable(listtable listtable.c)

47
examples/Readme.md Normal file
View File

@ -0,0 +1,47 @@
Examples
========
## common.h
Common files for all
## imstat.c
Usage: imstat [args] input files
Get statistics and modify images from first image HDU of each input file
Where args are:
-a, --add=arg add some value (double, or 'mean', 'std', 'min', 'max')
-h, --help show this help
-m, --multiply=arg multiply by some value (double, operation run after adding)
-o, --outfile=arg output file name (collect all input files)
-z, --rmneg remove negative values (assign them to 0)
## keylist.c
Usage: keylist [args] infile.fits
Where args are:
-a, --addrec add record to first HDU (you can add more than one record in once, point more -a)
-c, --contents show short file contents
-h, --help show this help
-i, --infile=arg input file name (you can also point it without any keys)
-l, --list list all keywords
-m, --modify modify values of given keys (each param should be "key = new_value")
-o, --output=arg save result to file (else save to same file)
Contains example of protected file writing (blocking all possible signals).
## listtable.c
Usage: listtable [args]
Where args are:
-h, --help show this help
-i, --fitsname=arg name of input file
-l, --list list all tables in file
-o, --outfile=arg output file name

View File

@ -1,30 +0,0 @@
/*
* This file is part of the FITSmaniplib project.
* Copyright 2019 Edward V. Emelianov <edward.emelianoff@gmail.com>, <eddy@sao.ru>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
int main(){
setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "C");
#if defined GETTEXT_PACKAGE && defined LOCALEDIR
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
textdomain(GETTEXT_PACKAGE);
#endif
return 0;
}

View File

@ -38,8 +38,8 @@ typedef struct{
/*
* here are global parameters initialisation
*/
int help;
glob_pars G = {
static int help;
static glob_pars G = {
.mult = 1.,
};
@ -47,7 +47,7 @@ glob_pars G = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
myoption cmdlnopts[] = {
static myoption cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"outfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.outfile), _("output file name (collect all input files)")},
@ -71,9 +71,9 @@ typedef struct{
* @param argv - copy of argv from main
* @return allocated structure with global parameters
*/
glob_pars *parse_args(int argc, char **argv){
static glob_pars *parse_args(int argc, char **argv){
int i;
char *helpstring = "Usage: %%s [args] input files\n"
char *helpstring = "Usage: %s [args] input files\n"
"Get statistics and modify images from first image HDU of each input file\n"
"\tWhere args are:\n";
change_helpstring(helpstring);
@ -89,7 +89,7 @@ glob_pars *parse_args(int argc, char **argv){
return &G;
}
imgstat *get_imgstat(double *dimg, long totpix){
static imgstat *get_imgstat(double *dimg, long totpix){
static imgstat st;
if(!dimg || !totpix) return &st; // return some trash if wrong data
st.min = dimg[0];
@ -108,12 +108,12 @@ imgstat *get_imgstat(double *dimg, long totpix){
return &st;
}
void printstat(imgstat *stat){
static void printstat(imgstat *stat){
green("Statistics:\n");
printf("MEAN=%g\nSTD=%g\nMIN=%g\nMAX=%g\n", stat->mean, stat->std, stat->min, stat->max);
}
bool addsomething(FITSimage *img, double *dimg, imgstat *stat){
static bool addsomething(FITSimage *img, double *dimg, imgstat *stat){
if(!G.add || !img || !stat) return FALSE;
// parser:
char *eptr;
@ -136,7 +136,7 @@ bool addsomething(FITSimage *img, double *dimg, imgstat *stat){
return TRUE;
}
bool multbysomething(FITSimage *img, double *dimg){
static bool multbysomething(FITSimage *img, double *dimg){
if(!img || !dimg) return FALSE;
if(fabs(G.mult) < 2*DBL_EPSILON) return FALSE;
DBG("multiply by %g", G.mult);
@ -146,7 +146,7 @@ bool multbysomething(FITSimage *img, double *dimg){
return TRUE;
}
bool process_fitsfile(char *inname, FITS *output){
static bool process_fitsfile(char *inname, FITS *output){
DBG("File %s", inname);
bool mod = FALSE;
FITS *f = FITS_read(inname);

View File

@ -38,8 +38,8 @@ typedef struct{
/*
* here are global parameters initialisation
*/
int help;
glob_pars G; /* = {
static int help;
static glob_pars G; /* = {
;
};*/
@ -47,14 +47,14 @@ glob_pars G; /* = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
myoption cmdlnopts[] = {
static myoption cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"contents",NO_ARGS, NULL, 'c', arg_none, APTR(&G.contents), _("show short file contents")},
{"list", NO_ARGS, NULL, 'l', arg_none, APTR(&G.list), _("list all keywords")},
{"addrec", MULT_PAR, NULL, 'a', arg_string, APTR(&G.addrec), _("add record to first HDU (you can add more than one record in once, point more -a)")},
{"output", NEED_ARG, NULL, 'o', arg_string, APTR(&G.outfile), _("save result to file (else save to same file)")},
{"modify", MULT_PAR, NULL, 'm', arg_string, APTR(&G.modify), _("modify values values of given keys (each param should be \"key = new_value\")")},
{"modify", MULT_PAR, NULL, 'm', arg_string, APTR(&G.modify), _("modify values of given keys (each param should be \"key = new_value\")")},
{"infile", NEED_ARG, NULL, 'i', arg_string, APTR(&G.fitsname), _("input file name (you can also point it without any keys)")},
end_option
};
@ -66,9 +66,9 @@ myoption cmdlnopts[] = {
* @param argv - copy of argv from main
* @return allocated structure with global parameters
*/
glob_pars *parse_args(int argc, char **argv){
static glob_pars *parse_args(int argc, char **argv){
int i;
char *helpstring = "Usage: %%s [args] infile.fits\n\n\tWhere args are:\n";
char *helpstring = "Usage: %s [args] infile.fits\n\n\tWhere args are:\n";
change_helpstring(helpstring);
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
@ -81,13 +81,13 @@ glob_pars *parse_args(int argc, char **argv){
return &G;
}
void ch(int s){
static void ch(int s){
signal(s, SIG_IGN);
printf("signal: %d\n", s);
signal(s, ch);
}
void print_imgHDU(FITSimage *image){
static void print_imgHDU(FITSimage *image){
printf("Image: naxis=%d, totpix=%ld, ", image->naxis, image->totpix);
printf("naxes=(");
for(int i = 0; i < image->naxis; ++i)

86
examples/listtable.c Normal file
View File

@ -0,0 +1,86 @@
/*
* This file is part of the FITSmaniplib project.
* Copyright 2019 Edward V. Emelianov <edward.emelianoff@gmail.com>, <eddy@sao.ru>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
typedef struct{
char *fitsname; // input file name
char *outfile; // output file name
int list; // list tables
} glob_pars;
/*
* here are global parameters initialisation
*/
static int help;
static glob_pars G;
/*
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
static myoption cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"fitsname",NEED_ARG, NULL, 'i', arg_string, APTR(&G.fitsname), _("name of input file")},
{"list", NO_ARGS, NULL, 'l', arg_none, APTR(&G.list), _("list all tables in file")},
{"outfile", NEED_ARG, NULL, 'o', arg_none, APTR(&G.outfile), _("output file name")},
end_option
};
/**
* Parse command line options and return dynamically allocated structure
* to global parameters
* @param argc - copy of argc from main
* @param argv - copy of argv from main
* @return allocated structure with global parameters
*/
static glob_pars *parse_args(int argc, char **argv){
int i;
char *helpstring = "Usage: %s [args]\n\n\tWhere args are:\n";
change_helpstring(helpstring);
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
if(argc > 0){
for (i = 0; i < argc; i++)
printf("Ignore extra argument: %s\n", argv[i]);
}
return &G;
}
int main(int argc, char *argv[]){
FITS *ofits = NULL;
initial_setup();
parse_args(argc, argv);
if(!G.fitsname) ERRX(_("No input filename given!"));
DBG("Open file %s", G.fitsname);
if(G.outfile){
ofits = MALLOC(FITS, 1);
ofits->filename = G.outfile;
}
FITS *f = FITS_read(G.fitsname);
if(G.list) table_print_all(f);
if(ofits){
green("\nWrite to output file %s\n", ofits->filename);
FITS_write(ofits->filename, ofits);
}
return 0;
}

83
fits.c
View File

@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "local.h"
#include "FITSmanip.h"
#include "local.h"
#include <errno.h>
#include <libgen.h> // dirname, basename
@ -315,11 +315,11 @@ KeyList *keylist_read(FITS *fits){
void table_free(FITStable **tbl){
if(!tbl || !*tbl) return;
FITStable *intab = *tbl;
size_t i, N = intab->ncols;
int i, N = intab->ncols;
for(i = 0; i < N; ++i){
table_column *col = &(intab->columns[i]);
if(col->coltype == TSTRING && col->width){
size_t r, R = col->repeat;
long r, R = col->repeat;
void **cont = (void**) col->contents;
for(r = 0; r < R; ++r) free(*(cont++));
}
@ -335,16 +335,16 @@ void table_free(FITStable **tbl){
* @return pointer to copy of table
*/
FITStable *table_copy(FITStable *intab){
if(!intab || intab->ncols == 0 || intab->nrows == 0) return NULL;
if(!intab || intab->ncols <= 0 || intab->nrows <= 0) return NULL;
FITStable *tbl = MALLOC(FITStable, 1);
memcpy(tbl, intab, sizeof(FITStable));
size_t ncols = intab->ncols, col;
int ncols = intab->ncols, col;
tbl->columns = MALLOC(table_column, ncols);
memcpy(tbl->columns, intab->columns, sizeof(table_column)*ncols);
table_column *ocurcol = tbl->columns, *icurcol = intab->columns;
for(col = 0; col < ncols; ++col, ++ocurcol, ++icurcol){
if(ocurcol->coltype == TSTRING && ocurcol->width){ // string array - copy all
size_t r, R = ocurcol->repeat;
long r, R = ocurcol->repeat;
char **oarr = (char**)ocurcol->contents, **iarr = (char**)icurcol->contents;
for(r = 0; r < R; ++r, ++oarr, ++iarr){
*oarr = strdup(*iarr);
@ -361,6 +361,7 @@ FITStable *table_copy(FITStable *intab){
* @return
*/
FITStable *table_read(FITS *fits){
FNAME();
int ncols, i, fst = 0;
long nrows;
char extname[FLEN_VALUE];
@ -374,7 +375,6 @@ FITStable *table_read(FITS *fits){
DBG("Table named %s with %ld rows and %d columns", extname, nrows, ncols);
FITStable *tbl = table_new(extname);
if(!tbl) return NULL;
fits->curHDU->contents.table = tbl;
for(i = 1; i <= ncols; ++i){
int typecode;
long repeat, width;
@ -390,9 +390,8 @@ FITStable *table_read(FITS *fits){
if(!array) ERRX("malloc");
int anynul;
int64_t nullval = 0;
int j;
for(j = 0; j < repeat; ++j){
fits_read_col(fp, typecode, i, j=1, 1, 1, (void*)nullval, array, &anynul, &fst);
for(int j = 0; j < repeat; ++j){
fits_read_col(fp, typecode, i, 1, 1, 1, (void*)nullval, array, &anynul, &fst);
if(fst){
FITS_reporterr(&fst);
WARNX(_("Can't read column %d row %d!"), i, j);
@ -427,7 +426,6 @@ FITStable *table_read(FITS *fits){
FITStable *table_new(char *tabname){
FITStable *tab = MALLOC(FITStable, 1);
snprintf(tab->tabname, FLEN_CARD, "%s", tabname);
DBG("add new table: %s", tabname);
return tab;
}
@ -444,11 +442,12 @@ FITStable *table_addcolumn(FITStable *tbl, table_column *column){
FNAME();
if(!tbl || !column || !column->contents) return NULL;
long nrows = column->repeat;
int width = column->width;
long width = column->width;
if(tbl->nrows < nrows) tbl->nrows = nrows;
size_t datalen = nrows * width, cols = ++tbl->ncols;
size_t datalen = nrows * width;
int cols = ++tbl->ncols;
char *curformat = column->format;
DBG("add column; width: %d, nrows: %ld, name: %s", width, nrows, column->colname);
DBG("add column; width: %ld, nrows: %ld, name: %s", width, nrows, column->colname);
/*void convchar(){ // count maximum length of strings in array
char **charr = (char**)column->contents, *dptr = charr;
size_t n, N = column->repeat;
@ -458,7 +457,7 @@ FITStable *table_addcolumn(FITStable *tbl, table_column *column){
else{ ++len; }
}
}*/
#define CHKLEN(type) do{if(width != sizeof(type)) datalen = sizeof(type) * nrows;}while(0)
#define CHKLEN(type) do{if(width != sizeof(type)) datalen = sizeof(type) * (size_t)nrows;}while(0)
switch(column->coltype){
case TBIT:
snprintf(curformat, FLEN_FORMAT, "%ldX", nrows);
@ -475,9 +474,9 @@ FITStable *table_addcolumn(FITStable *tbl, table_column *column){
case TSTRING:
if(width == 0){
snprintf(curformat, FLEN_FORMAT, "%ldA", nrows);
datalen = nrows;
datalen = (size_t)nrows + 1;
}else
snprintf(curformat, FLEN_FORMAT, "%ldA%d", nrows, width);
snprintf(curformat, FLEN_FORMAT, "%ldA%ld", nrows, width);
break;
case TSHORT:
snprintf(curformat, FLEN_FORMAT, "%ldI", nrows);
@ -501,11 +500,11 @@ FITStable *table_addcolumn(FITStable *tbl, table_column *column){
break;
case TCOMPLEX:
snprintf(curformat, FLEN_FORMAT, "%ldM", nrows);
if(width != sizeof(float)*2) datalen = sizeof(float) * nrows * 2;
if(width != sizeof(float)*2) datalen = sizeof(float) * (size_t)nrows * 2;
break;
case TDBLCOMPLEX:
snprintf(curformat, FLEN_FORMAT, "%ldM", nrows);
if(width != sizeof(double)*2) datalen = sizeof(double) * nrows * 2;
if(width != sizeof(double)*2) datalen = sizeof(double) * (size_t)nrows * 2;
break;
case TINT:
snprintf(curformat, FLEN_FORMAT, "%ldJ", nrows);
@ -528,8 +527,8 @@ FITStable *table_addcolumn(FITStable *tbl, table_column *column){
return NULL;
}
#undef CHKLEN
DBG("new size: %ld, old: %ld", sizeof(table_column)*cols, sizeof(table_column)*(cols-1));
if(!(tbl->columns = realloc(tbl->columns, sizeof(table_column)*cols))) ERRX("malloc");
DBG("new size: %ld, old: %zd", sizeof(table_column)*cols, sizeof(table_column)*(cols-1));
if(!(tbl->columns = realloc(tbl->columns, sizeof(table_column)*(size_t)cols))) ERRX("malloc");
table_column *newcol = &(tbl->columns[cols-1]);
memcpy(newcol, column, sizeof(table_column));
newcol->contents = calloc(datalen, 1);
@ -589,14 +588,14 @@ void table_print(FITStable *tbl){
printf("%zd\t", ((int64_t*)col->contents)[r]);
break;
case TFLOAT:
printf("%g\t", ((float*)col->contents)[r]);
printf("%g\t", (double)((float*)col->contents)[r]);
break;
case TDOUBLE:
printf("%g\t", ((double*)col->contents)[r]);
break;
case TCOMPLEX:
fpair = (float*)col->contents + 2*r;
printf("%g %s %g*i\t", fpair[0], fpair[1] > 0 ? "+" : "-", fpair[1]);
printf("%g %s %g*i\t", (double)fpair[0], fpair[1] > 0 ? "+" : "-", (double)fpair[1]);
break;
case TDBLCOMPLEX:
dpair = (double*)col->contents + 2*r;
@ -622,9 +621,9 @@ void table_print(FITStable *tbl){
* @param fits - pointer to given file structure
*/
void table_print_all(FITS *fits){
size_t i, N = fits->NHDUs+1;
if(N == 0) return;
for(i = 1; i < N; ++i){
if(fits->NHDUs < 1) return;
int N = fits->NHDUs+1;
for(int i = 1; i < N; ++i){
if(fits->HDUs[i].hdutype == BINARY_TBL || fits->HDUs[i].hdutype == ASCII_TBL)
table_print(fits->HDUs[i].contents.table);
}
@ -642,6 +641,7 @@ bool table_write(FITS *file){
if(hdutype != BINARY_TBL || hdutype != ASCII_TBL)
return FALSE;
FITStable *tbl = file->curHDU->contents.table;
if(tbl->ncols < 1 || tbl->nrows < 1) return FALSE;
size_t c, cols = tbl->ncols;
char **columns = MALLOC(char*, cols);
char **formats = MALLOC(char*, cols);
@ -686,6 +686,7 @@ bool table_write(FITS *file){
* @return pointer to new HDU or NULL in case of error
*/
FITSHDU *FITS_addHDU(FITS *fits){
if(fits->NHDUs < 0) fits->NHDUs = 0;
int hdunum = fits->NHDUs + 1;
// add 1 to `hdunum` because HDU numbering starts @1
FITSHDU *newhdu = realloc(fits->HDUs, sizeof(FITSHDU)*(1+hdunum));
@ -791,7 +792,7 @@ FITS *FITS_read(char *filename){
break;
case ASCII_TBL:
DBG("ASCII table");
//table_read(img, fp);
curHDU->contents.table = table_read(fits);
break;
default:
WARNX(_("Unknown HDU type"));
@ -972,7 +973,7 @@ int image_datatype_size(int bitpix, int *dtype){
* @return allocated memory
*/
void *image_data_malloc(long totpix, int pxbytes){
if(!pxbytes || !totpix) return NULL;
if(pxbytes <= 0 || totpix <= 0) return NULL;
void *data = calloc(totpix, pxbytes);
DBG("Allocate %zd members of size %d", totpix, pxbytes);
if(!data) ERR("calloc()");
@ -981,16 +982,16 @@ void *image_data_malloc(long totpix, int pxbytes){
/**
* @brief image_new - create an empty image without headers, assign BITPIX to "bitpix"
* @param naxis - number of dimensions
* @param naxes - sizes by each dimension
* @param bitpix - BITPIX for given image
* @param naxis - number of dimensions
* @param naxes (i) - sizes by each dimension
* @param bitpix - BITPIX for given image
* @return allocated structure or NULL
*/
FITSimage *image_new(int naxis, long *naxes, int bitpix){
FITSimage *out = MALLOC(FITSimage, 1);
int dtype, pxsz = image_datatype_size(bitpix, &dtype);
long totpix = 0;
if(naxis){ // not empty image
if(naxis > 0){ // not empty image
totpix = 1;
for(int i = 0; i < naxis; ++i) if(naxes[i]) totpix *= naxes[i];
out->data = image_data_malloc(totpix, pxsz);
@ -998,10 +999,10 @@ FITSimage *image_new(int naxis, long *naxes, int bitpix){
FREE(out);
return NULL;
}
out->naxes = MALLOC(long, naxis);
memcpy(out->naxes, naxes, sizeof(long)*naxis);
}
out->totpix = totpix;
out->naxes = MALLOC(long, naxis);
memcpy(out->naxes, naxes, sizeof(long)*naxis);
out->naxis = naxis;
out->pxsz = pxsz;
out->bitpix = bitpix;
@ -1011,42 +1012,42 @@ FITSimage *image_new(int naxis, long *naxes, int bitpix){
// function for qsort
static int cmpdbl(const void *d1, const void *d2){
register double D1 = *(double*)d1, D2 = *(double*)d2;
register double D1 = *(const double*)d1, D2 = *(const double*)d2;
if(fabs(D1 - D2) < DBL_EPSILON) return 0;
if(D1 > D2) return 1;
else return -1;
}
// functions to convert double to different datatypes
static void convu8(FITSimage *img, double *dimg){
static void convu8(FITSimage *img, const double *dimg){
uint8_t *dptr = (uint8_t*) img->data;
OMP_FOR()
for(long i = 0; i < img->totpix; ++i){
dptr[i] = (uint8_t) dimg[i];
}
}
static void convu16(FITSimage *img, double *dimg){
static void convu16(FITSimage *img, const double *dimg){
uint16_t *dptr = (uint16_t*) img->data;
OMP_FOR()
for(long i = 0; i < img->totpix; ++i){
dptr[i] = (uint16_t) dimg[i];
}
}
static void convu32(FITSimage *img, double *dimg){
static void convu32(FITSimage *img, const double *dimg){
uint32_t *dptr = (uint32_t*) img->data;
OMP_FOR()
for(long i = 0; i < img->totpix; ++i){
dptr[i] = (uint32_t) dimg[i];
}
}
static void convu64(FITSimage *img, double *dimg){
static void convu64(FITSimage *img, const double *dimg){
uint64_t *dptr = (uint64_t*) img->data;
OMP_FOR()
for(long i = 0; i < img->totpix; ++i){
dptr[i] = (uint64_t) dimg[i];
}
}
static void convf(FITSimage *img, double *dimg){
static void convf(FITSimage *img, const double *dimg){
float *dptr = (float*) img->data;
OMP_FOR()
for(long i = 0; i < img->totpix; ++i){
@ -1078,7 +1079,7 @@ FITSimage *image_rebuild(FITSimage *img, double *dimg){
FREE(sr);
DBG("min: %g, max: %g, mindiff: %g", min, max, mindiff);
int bitpix = -64; // double by default
void (*convdata)(FITSimage*, double*) = NULL;
void (*convdata)(FITSimage*, const double*) = NULL;
if(isint)do{ // check which integer type will suits better
DBG("INTEGER?");
if(min < 0){ isint = FALSE; break;} // TODO: correct with BZERO

View File

@ -15,7 +15,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <float.h> // xx_EPSILON etc.
#include <linux/limits.h> // PATH_MAX
#if defined GETTEXT
#include <libintl.h>

Binary file not shown.

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-22 22:46+0300\n"
"POT-Creation-Date: 2019-03-26 20:09+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -35,56 +35,56 @@ msgstr ""
msgid "strdup() failed!"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:384
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:385
#, c-format
msgid "Can't read column %d!"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:398
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:399
#, c-format
msgid "Can't read column %d row %d!"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:407
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:408
msgid "Can't read table data type"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:411
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:412
msgid "Can't read table data unit"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:527
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:528
msgid "Unsupported column data type!"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:662
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:664
#, c-format
msgid "Can't write table %s!"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:672
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:674
#, c-format
msgid "Can't write column %s!"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:770
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:773
msgid "Can't read HDU"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:797
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:800
msgid "Unknown HDU type"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:915
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:918
#, c-format
msgid "Can't get real path for %s, use cfitsio to rewrite"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1113
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1214
#, c-format
msgid "Found %d pixels with undefined value"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1154
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1255
msgid "Undefined image type, cant convert to double"
msgstr ""

View File

@ -7,7 +7,7 @@
msgid ""
msgstr "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-22 22:46+0300\n"
"POT-Creation-Date: 2019-03-26 20:09+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -26,45 +26,45 @@ msgstr "
msgid "Can't copy data"
msgstr "îÅ ÍÏÇÕ ÓËÏÐÉÒÏ×ÁÔØ ÄÁÎÎÙÅ"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:915
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:918
#, c-format
msgid "Can't get real path for %s, use cfitsio to rewrite"
msgstr "îÅ ÍÏÇÕ ÏÐÒÅÄÅÌÉÔØ ÐÕÔØ (realpath) Ë %s, ÉÓÐÏÌØÚÕÀ cfitsio ÄÌÑ "
"ÐÅÒÅÚÁÐÉÓÉ"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:770
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:773
msgid "Can't read HDU"
msgstr "îÅ ÍÏÇÕ ÐÒÏÞÅÓÔØ HDU"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:398
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:399
#, c-format
msgid "Can't read column %d row %d!"
msgstr "îÅ ÍÏÇÕ ÐÒÏÞÅÓÔØ ÓÔÏÌÂÅà %d ÓÔÒÏËÕ %d"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:384
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:385
#, c-format
msgid "Can't read column %d!"
msgstr "îÅ ÍÏÇÕ ÐÒÏÞÅÓÔØ ÓÔÏÌÂÅà %d!"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:407
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:408
msgid "Can't read table data type"
msgstr "îÅ ÍÏÇÕ ÐÒÏÞÅÓÔØ ÔÉÐ ÄÁÎÎÙÈ ÔÁÂÌÉÃÙ"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:411
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:412
msgid "Can't read table data unit"
msgstr "îÅ ÍÏÇÕ ÐÒÏÞÅÓÔØ ÅÄÉÎÉÃÙ ÉÚÍÅÒÅÎÉÑ ÄÁÎÎÙÈ ÔÁÂÌÉÃÙ"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:672
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:674
#, c-format
msgid "Can't write column %s!"
msgstr "îÅ ÍÏÇÕ ÚÁÐÉÓÁÔØ ÓÔÏÌÂÅà %s!"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:662
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:664
#, c-format
msgid "Can't write table %s!"
msgstr "îÅ ÍÏÇÕ ÚÁÐÉÓÁÔØ ÔÁÂÌÉÃÕ %s!"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1113
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1214
#, c-format
msgid "Found %d pixels with undefined value"
msgstr "îÁÊÄÅÎÏ %d ÐÉËÓÅÌÅÊ Ó ÎÅÏÐÒÅÄÅÌÅÎÎÙÍÉ ÚÎÁÞÅÎÉÑÍÉ"
@ -73,15 +73,15 @@ msgstr "
msgid "No keywords in given HDU"
msgstr "÷ ÄÁÎÎÏÍ HDU ËÌÀÞÉ ÏÔÓÕÔÓÔ×ÕÀÔ"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1154
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:1255
msgid "Undefined image type, cant convert to double"
msgstr ""
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:797
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:800
msgid "Unknown HDU type"
msgstr "îÅÉÚ×ÅÓÔÎÙÊ ÔÉÐ HDU"
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:527
#: /home/eddy/C-files/FITSmaniplib/sharedlib_template/fits.c:528
msgid "Unsupported column data type!"
msgstr "îÅÐÏÄÄÅÒÖÉ×ÁÅÍÙÊ ÔÉÐ ÄÁÎÎÙÈ ÓÔÏÌÂÃÁ!"