/*--------------------------------------------------------------------------*/ int ffcpfl(fitsfile *infptr, /* I - FITS file pointer to input file */ fitsfile *outfptr, /* I - FITS file pointer to output file */ int previous, /* I - copy any previous HDUs? */ int current, /* I - copy the current HDU? */ int following, /* I - copy any following HDUs? */ int *status) /* IO - error status */ /* copy all or part of the input file to the output file. */ { int hdunum, ii; if (*status > 0) return(*status); if (infptr == outfptr) return(*status = SAME_FILE); ffghdn(infptr, &hdunum); if (previous) { /* copy any previous HDUs */ for (ii=1; ii < hdunum; ii++) { ffmahd(infptr, ii, NULL, status); ffcopy(infptr, outfptr, 0, status); } } if (current && (*status <= 0) ) { /* copy current HDU */ ffmahd(infptr, hdunum, NULL, status); ffcopy(infptr, outfptr, 0, status); } if (following && (*status <= 0) ) { /* copy any remaining HDUs */ ii = hdunum + 1; while (1) { if (ffmahd(infptr, ii, NULL, status) ) { /* reset expected end of file status */ if (*status == END_OF_FILE) *status = 0; break; } if (ffcopy(infptr, outfptr, 0, status)) break; /* quit on unexpected error */ ii++; } } ffmahd(infptr, hdunum, NULL, status); /* restore initial position */ return(*status); }
/* * Process batch job. */ int batch (char *name) { char buf [256]; FILE *pd, *fd; if (f2access (SERVDIR, "bin/server", 1)) { syslog (LOG_ERR, "cannot execute %s/bin/server", SERVDIR); return (0); } sprintf (buf, "%s/bin/server", SERVDIR); pd = popen (buf, "w"); if (! pd) { syslog (LOG_ERR, "cannot run '%s'", buf); return (0); } fd = fopen (name, "r"); if (! fd) { syslog (LOG_ERR, "cannot read '%s'", name); pclose (pd); return (0); } ffcopy (fd, pd); fclose (fd); pclose (pd); sleep (1); return (1); }
main () { int ident, rez; char name [100]; /* catch signals */ sigcatch (); /* lock queue */ lock (QLOCKFILE); /* get next free queue ident */ ident = getident (); /* make queue file name */ sprintf (name, QFILENAME, ident); /* create queue file */ if (! freopen (name, "w", stdout)) { error ("cannot create %s", name); quit (); } /* save query into queue file */ rez = ffcopy (stdin, stdout); if (rez < 0) quit (); /* append name of query to queue active file */ enqueue (name); error ("batch %d queued", ident); unlock (QLOCKFILE); return (0); }
/* * Get content of active file into temp file, * then clean active file. * Leave temp file rewinded. */ int dequeue (FILE *actfd) { FILE *fd; /* open active file for reading */ fd = f2open (SERVDIR, "queueactive", "r"); if (! fd) return (1); /* no active jobs in queue */ /* copy active file to temp file */ if (ffcopy (fd, actfd) < 0) { fclose (fd); return (0); } fclose (fd); rewind (actfd); /* clean active file */ f2clean (SERVDIR, "queueactive"); return (1); }
void FSCOPY_U (fitsfile **infptr, fitsfile **outfptr, int *morekeys, int *status) { ffcopy (*infptr, *outfptr, *morekeys, status); }