Skip to content

Commit

Permalink
Allow very long (>4Gpt) files to be written
Browse files Browse the repository at this point in the history
  • Loading branch information
scottransom committed Sep 26, 2017
1 parent 70ccc57 commit e0c8a3d
Show file tree
Hide file tree
Showing 6 changed files with 700 additions and 734 deletions.
4 changes: 2 additions & 2 deletions clig/toas2dat.1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.\" it edited by clig, remove the respective pair of cligPart-lines.
.\"
.\" cligPart TITLE
.TH "toas2dat" 1 "12Mar10" "Clig-manuals" "Programmer's Manual"
.TH "toas2dat" 1 "26Sep17" "Clig-manuals" "Programmer's Manual"
.\" cligPart TITLE end

.\" cligPart NAME
Expand All @@ -37,7 +37,7 @@ file
.IP -n
The number of bins in the output time series,
.br
1 Int value between 0 and oo.
1 Long value between 0 and oo.
.IP -dt
Time interval in seconds for output time bins,
.br
Expand Down
2 changes: 1 addition & 1 deletion clig/toas2dat_cmd.cli
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Commandline full_cmd_line

# Options (in order you want them to appear)

Int -n numout {The number of bins in the output time series} \
Long -n numout {The number of bins in the output time series} \
-r 0 oo -m
Double -dt dt {Time interval in seconds for output time bins} \
-r 0 oo -m
Expand Down
4 changes: 2 additions & 2 deletions docs/toas2dat.1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.\" it edited by clig, remove the respective pair of cligPart-lines.
.\"
.\" cligPart TITLE
.TH "toas2dat" 1 "12Mar10" "Clig-manuals" "Programmer's Manual"
.TH "toas2dat" 1 "26Sep17" "Clig-manuals" "Programmer's Manual"
.\" cligPart TITLE end

.\" cligPart NAME
Expand All @@ -37,7 +37,7 @@ file
.IP -n
The number of bins in the output time series,
.br
1 Int value between 0 and oo.
1 Long value between 0 and oo.
.IP -dt
Time interval in seconds for output time bins,
.br
Expand Down
2 changes: 1 addition & 1 deletion include/toas2dat_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
typedef struct s_Cmdline {
/***** -n: The number of bins in the output time series */
char numoutP;
int numout;
long numout;
int numoutC;
/***** -dt: Time interval in seconds for output time bins */
char dtP;
Expand Down
45 changes: 22 additions & 23 deletions src/toas2dat.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,37 @@ int compare_doubles(const void *a, const void *b)
return (*da > *db) - (*da < *db);
}

int read_toas(FILE * toafile, double **toas)
int read_toas(FILE *infile, double **toas)
/* Read a text file containing ASCII text TOAs. */
/* The number of TOAs read is returned. */
/* Lines beginning with '#' are ignored. */
{
char line[200];
int ii, numtoa;
double dtmp;
char line[80], *sptr = NULL;
int ii=0, numtoa=0;

/* Read the input file once to count TOAs */

numtoa = 0;
while (!feof(toafile)) {
fgets(line, 200, toafile);
if (line[0] == '#')
continue;
else
numtoa++;
while (1) {
sptr = fgets(line, 80, infile);
if (!feof(infile) && sptr != NULL && sptr[0] != '\n') {
if (line[0] != '#' && sscanf(line, "%lf", &dtmp) == 1)
numtoa++;
} else {
break;
}
}
numtoa--;

*toas = (double *) malloc(sizeof(double) * numtoa);

/* Rewind and read the TOAs for real */

rewind(toafile);
ii = 0;
while (ii < numtoa) {
fgets(line, 200, toafile);
if (line[0] == '#')
continue;
else {
sscanf(line, "%lf\n", &(*toas)[ii]);
ii++;
rewind(infile);
while (1) {
sptr = fgets(line, 80, infile);
if (!feof(infile) && sptr != NULL && sptr[0] != '\n') {
if (line[0] != '#' && sscanf(line, "%lf", &(*toas)[ii]) == 1)
ii++;
} else {
break;
}
}
return numtoa;
Expand Down Expand Up @@ -147,7 +146,7 @@ int main(int argc, char *argv[])
/* Allocate our output array */

fdata = (float *) malloc(sizeof(float) * WORKLEN);
printf("\nWriting time series of %d points of\n", cmd->numout);
printf("\nWriting time series of %ld points of\n", cmd->numout);
printf("length %f seconds to '%s'.\n\n", cmd->dt, cmd->outfile);

/* Sort the TOAs */
Expand Down
Loading

0 comments on commit e0c8a3d

Please sign in to comment.