Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit multiple input files on the accelsearch command line #120

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions clig/accelsearch.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 "accelsearch" 1 "09Jul20" "Clig-manuals" "Programmer's Manual"
.TH "accelsearch" 1 "10Jul20" "Clig-manuals" "Programmer's Manual"
.\" cligPart TITLE end

.\" cligPart NAME
Expand Down Expand Up @@ -41,7 +41,7 @@ accelsearch \- Search an FFT or short time series for pulsars using a Fourier do
[-otheropt]
[-noharmpolish]
[-noharmremove]
infile ...
[infiles ...]
.\" cligPart SYNOPSIS end

.\" cligPart OPTIONS
Expand Down Expand Up @@ -124,8 +124,8 @@ Use the alternative optimization (for testing/debugging).
Do not use 'harmpolish' by default.
.IP -noharmremove
Do not remove harmonically related candidates (never removed for numharm = 1).
.IP infile
Input file name(s) of the floating point .fft or .[s]dat file(s). '.inf' file(s) of the same name must also exist.
.IP infiles
One or more input file name(s) of the floating point .fft or .[s]dat file(s). '.inf' file(s) of the same name must also exist.
.\" cligPart OPTIONS end

.\" cligPart DESCRIPTION
Expand Down
3 changes: 1 addition & 2 deletions clig/accelsearch_cmd.cli
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ Flag -noharmremove noharmremove {Do not remove harmonically related candidate

# Rest of command line:

Rest infile {Input file name(s) of the floating point .fft or .[s]dat file(s). '.inf' file(s) of the same name must also exist} \
-c 1 16384
Rest infiles {One or more input file name(s) of the floating point .fft or .[s]dat file(s). '.inf' file(s) of the same name must also exist}
30 changes: 25 additions & 5 deletions src/accel_utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "accel.h"
#include "accelsearch_cmd.h"

#include <stdio.h>

#if defined (__GNUC__)
#define inline __inline__
#else
Expand Down Expand Up @@ -828,13 +830,27 @@ void output_fundamentals(fourierprops * props, GSList * list,
free(notes);
}

static void filecat(char *dest, char *src)
{
FILE *fp_dest, *fp_src;
char buf[4096];

fp_dest = chkfopen(dest, "a");
fp_src = chkfopen(src, "r");
while(!feof(fp_src) && !ferror(fp_src) && !ferror(fp_dest))
{
fwrite(buf, 1, fread(buf, 1, sizeof(buf), fp_src), fp_dest);
}
fclose(fp_dest);
fclose(fp_src);
}

void output_harmonics(GSList * list, accelobs * obs, infodata * idata)
{
int ii, jj, numcols = 15, numcands;
int widths[15] = { 5, 4, 5, 15, 11, 18, 13, 12, 9, 12, 9, 12, 10, 10, 20 };
int errors[15] = { 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 2, 2, 0 };
char tmpstr[30], ctrstr[30], notes[21], *command;
char tmpstr[30], ctrstr[30], notes[21];
accelcand *cand;
GSList *listptr;
fourierprops props;
Expand Down Expand Up @@ -960,10 +976,14 @@ void output_harmonics(GSList * list, accelobs * obs, infodata * idata)
}
fprintf(obs->workfile, "\n\n");
fclose(obs->workfile);
command = malloc(strlen(obs->rootfilenm) + strlen(obs->accelnm) + 20);
sprintf(command, "cat %s.inf >> %s", obs->rootfilenm, obs->accelnm);
system(command);
free(command);
{
char *infnm;

infnm = malloc(strlen(obs->rootfilenm) + 5);
sprintf(infnm, "%s.inf", obs->rootfilenm);
filecat(obs->accelnm, infnm);
free(infnm);
}
}


Expand Down
114 changes: 87 additions & 27 deletions src/accelsearch.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "accel.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

/*#undef USEMMAP*/

#ifdef USEMMAP
Expand Down Expand Up @@ -40,7 +47,7 @@ static void print_percent_complete(int current, int number, char *what, int rese
}
}

int main(int argc, char *argv[])
static void accelsearch(Cmdline *cmd)
{
int ii, rstep;
double ttim, utim, stim, tott;
Expand All @@ -49,33 +56,11 @@ int main(int argc, char *argv[])
accelobs obs;
infodata idata;
GSList *cands = NULL;
Cmdline *cmd;

/* Prep the timer */

tott = times(&runtimes) / (double) CLK_TCK;

/* Call usage() if we have no command line arguments */

if (argc == 1) {
Program = argv[0];
printf("\n");
usage();
exit(1);
}

/* Parse the command line using the excellent program Clig */

cmd = parseCmdline(argc, argv);

#ifdef DEBUG
showOptionValues();
#endif

printf("\n\n");
printf(" Fourier-Domain Acceleration and Jerk Search Routine\n");
printf(" by Scott M. Ransom\n\n");

/* Create the accelobs structure */
create_accelobs(&obs, &idata, cmd, 1);

Expand Down Expand Up @@ -178,8 +163,8 @@ int main(int argc, char *argv[])
free_ffdotpows(fundamental);
startr = nextr;
}
}
}

/* Reset indices if needed and search for real */
startr = obs.rlo;
lastr = 0;
Expand Down Expand Up @@ -276,7 +261,7 @@ int main(int argc, char *argv[])

/* Write the harmonics to the output text file */
output_harmonics(cands, &obs, &idata);

/* Write the fundamental fourierprops to the cand file */
obs.workfile = chkfopen(obs.candnm, "wb");
chkfwrite(props, sizeof(fourierprops), numcands, obs.workfile);
Expand Down Expand Up @@ -310,5 +295,80 @@ int main(int argc, char *argv[])
free_accelobs(&obs);
g_slist_foreach(cands, free_accelcand, NULL);
g_slist_free(cands);
return (0);
}

int main(int argc, char *argv[])
{
int ii, err;
Cmdline *cmd;

/* Parse the command line using the excellent program Clig */
/* Call usage() if we have no command line arguments */
if (argc == 1 ||
(cmd = parseCmdline(argc, argv), cmd->argc < 1)) {
Program = argv[0];
printf("\n");
usage();
exit(1);
}

#ifdef DEBUG
showOptionValues();
#endif

printf("\n\n");
printf(" Fourier-Domain Acceleration and Jerk Search Routine\n");
printf(" by Scott M. Ransom\n\n");

for(ii = 0, err = 0; ii < cmd->argc && !err; ++ii)
{
int child_status;
pid_t pid;

/* So that fork doesn't duplicate buffer contents ...
workaround for child processes calling exit(3) instead of _exit(2)
*/
fflush(stdout);
fflush(stderr);

pid = fork();
if(pid == 0)
{
/* This is the child process that does the real work */
cmd->argc = 1;
cmd->argv[0] = cmd->argv[ii];
accelsearch(cmd);
/* TODO: All invocations of exit(3) by accelsearch(...) should be changed to use _exit(2) */
_exit(0);
}
/* This is the parent process, let's collect the child status and
stop on error.
*/
if(pid == -1)
{
fprintf(stderr, "\n%s: error calling worker process: ", argv[0]);
perror("fork");
err = -1;
}
else if(waitpid(pid, &child_status, 0) < 1)
{
fprintf(stderr, "\n%s: error calling worker process: ", argv[0]);
perror("waitpid");
err = -1;
}
else if(!WIFEXITED(child_status))
{
fprintf(stderr, "\n%s: worker process terminated abnormally,", argv[0]);
err = -1;
}
else if(err = WEXITSTATUS(child_status))
{
fprintf(stderr, "\n%s: error returned from worker process. Aborting ...", argv[0]);
}
if(err)
{
fprintf(stderr, " %d file%s left unprocessed.\n\n", cmd->argc - ii, cmd->argc - ii > 1 ? "s" : "");
}
}
return err;
}
Loading