Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/QUICKSTART
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ INSTALLATION

The following libraries are used by ROBOSPECT:

* libgsl : required. Tested to work with versions > v1.9.
* libgsl : required. Tested to work with versions > v2.0.
* libcfitsio : optional requirement to allow FITS image input.
* libplplotd : optional requirement to produce line fit plots.

Expand Down
43 changes: 26 additions & 17 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
/* Set up a default option structure. */
opts *alloc_options() {
opts *O = malloc(sizeof(opts));
if (O == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}

O->psf_width = 5.0; /* to remove */
O->continuum_box = 40.0;
Expand Down Expand Up @@ -72,9 +76,6 @@ void free_options (opts *O) {
}
O->log = stderr;
}
if (O->command_name) {
free(O->command_name);
}
if (O->command_line) {
free(O->command_line);
}
Expand Down Expand Up @@ -357,14 +358,18 @@ void usage_block(opts *O) {
char * get_time() {
time_t curtime = time(NULL);
char *output = malloc(32 * sizeof(char));
if (output == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
strftime(output,32,DATE_FORMAT,localtime(&curtime));
return(output);
}

void set_options(opts *O, int argc, char *argv[]) {
char c = 0;
int i = 0;
int j = 0;
int i, pos;
int command_line_len;
int opt_index;

/* Rework this to use a better argument list for long options */
Expand Down Expand Up @@ -409,18 +414,23 @@ void set_options(opts *O, int argc, char *argv[]) {
{0,0,0,0}
};

/* Store command name into the option struct. */
O->command_name = argv[0];

/* Store command line into the option struct. */
i = 0;
O->command_name = realloc(O->command_name,sizeof(char) * (i + strlen(argv[j]) + 2));
O->command_name = strcat(O->command_name,argv[j]);
for (j = 0; j < argc; j++) {
O->command_line = realloc(O->command_line,sizeof(char) * (i + strlen(argv[j]) + 2));
i = i + strlen(argv[j]) + 2;
if (j > 0) {
O->command_line = strcat(O->command_line," ");
}
O->command_line = strcat(O->command_line,argv[j]);
command_line_len = 0;
for (i = 0 ; i < argc; i++) {
command_line_len += strlen(argv[i]) + 1;
}
O->command_line = malloc(command_line_len + 1);
if (O->command_line == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
for (i = 0, pos = 0; i < argc; i++) {
pos += sprintf(O->command_line + pos, "%s ", argv[i]);
}

/* Parse options. */
while ((c = getopt_long(argc,argv,"hFf:e:E:w:p:V:r:R:T:i:d:L:C:N:M:D:v:P:lz:x:y:1AI2:Q:3:45:6:7:8:",
long_options,&opt_index)) != -1) {
Expand Down Expand Up @@ -564,8 +574,7 @@ void set_options(opts *O, int argc, char *argv[]) {

/* Load input file or read from stdin */
if (argv[optind] == NULL) {
O->infilename = malloc(32 * sizeof(char));
snprintf(O->infilename,32,"/dev/stdin");
O->infilename = "/dev/stdin";
}
else {
O->infilename = argv[optind];
Expand Down
2 changes: 1 addition & 1 deletion src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "robo.h"

char *generate_filename(opts *options, char *rule) {
char root[1024];
static char root[1024];
char order[16];
if ((options->max_order != 0)&&(strcasecmp(rule,"LOG") != 0)) {
snprintf(order,sizeof(order),"_order%03d",options->order);
Expand Down
44 changes: 44 additions & 0 deletions src/fileio/input_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,56 @@

data *alloc_data(int size) {
data *D = malloc(sizeof(data));
if (D == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
D->N = size;
D->x = malloc(size * sizeof(double));
if (D->x == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
D->y = malloc(size * sizeof(double));
if (D->y == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
D->e = malloc(size * sizeof(double));
if (D->e == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
D->yO= malloc(size * sizeof(double));
if (D->yO == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
return(D);
}

void realloc_data(data *D, int size) {
D->N = size;
D->x = realloc(D->x,size * sizeof(double));
if (D->x == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
D->y = realloc(D->y,size * sizeof(double));
if (D->y == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
D->e = realloc(D->e,size * sizeof(double));
if (D->e == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
D->yO= realloc(D->yO,size * sizeof(double));
if (D->yO == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
}

void free_data(data *D) {
Expand Down Expand Up @@ -189,12 +225,20 @@ data *read_data_fits(opts *options, int *N) {
fits_get_img_size(ff,naxis,lpixel,&status); FRE;
if (naxis == 1) {
image = malloc(lpixel[0] * sizeof(double));
if (image == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
fits_read_pix(ff,TDOUBLE,fpixel,lpixel[0],NULL,image,&naxis,&status); FRE;
lpixel[1] = 1;
}
else if (naxis == 2) {
fpixel[1] = options->order + 1; /* This probably should be correctly handled by a DISP-AXIS header. */
image = malloc(lpixel[0] * sizeof(double));
if (image == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
fits_read_pix(ff,TDOUBLE,fpixel,lpixel[0] ,NULL,image,&naxis,&status); FRE;
if (options->max_order == 0) {
options->max_order = lpixel[1] - 1;
Expand Down
30 changes: 25 additions & 5 deletions src/fileio/input_fitsWCS.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ typedef enum {

fits_WCS *read_fits_WCS(fitsfile *ff) {
fits_WCS *WCS = malloc(sizeof(fits_WCS));
if (WCS == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}

int i;
char value[80];
Expand All @@ -24,7 +28,8 @@ fits_WCS *read_fits_WCS(fitsfile *ff) {
char keyword[9];
char *fullspect;
char *token;
int k;
int k, pos;
int ret;

fits_read_keyword(ff,"WAT0_001",value,comment,&status); FRE;
if ((strcasecmp(value,"'system=world'") == 0)||(status != 0)) {
Expand Down Expand Up @@ -54,7 +59,15 @@ fits_WCS *read_fits_WCS(fitsfile *ff) {
}
WCS->N = atoi(value);
WCS->x0 = malloc(WCS->N * sizeof(double));
if (WCS->x0 == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
WCS->xd = malloc(WCS->N * sizeof(double));
if (WCS->xd == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}

fits_read_keyword(ff,"WAT1_001",value,NULL,&status); FRE;

Expand Down Expand Up @@ -88,13 +101,20 @@ fits_WCS *read_fits_WCS(fitsfile *ff) {
else if (S == SPECT_MULTISPEC) {
status = 0;
fullspect = malloc(WCS->N * 2 * 80);
if (fullspect == NULL) {
fprintf(stderr, "robospect: %s: %d: Cannot allocate memory\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}

for (k = 1; k < WCS->N * 2; k++) {
snprintf(keyword,sizeof(keyword),"WAT2_%03d",k);
for (k = 1, pos = 0; k < WCS->N * 2; k++) {
ret = snprintf(keyword, sizeof(keyword), "WAT2_%03d", k);
if (ret < 0) {
fprintf(stderr, "robospect: %s: %d: Buffer overflow\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
fits_read_key(ff,TSTRING,keyword,value,NULL,&status);
if (status == 0) {
/* This right here? This is fucking ridiculous. */
sprintf(fullspect,"%s%- 68s",fullspect,value);
pos += sprintf(&fullspect[pos], "%-68s", value);
}
else {
k = WCS->N * 3;
Expand Down
Loading