#include #include /* * The function of this package is to provide a simple, uniform, * and somewhat flexible tool for producing printout (mostly, for * debugging purposes) from C code. The functions in the package * print data on two files, whose names are specified by the user * in a call to the function cprini (see below). Normally, one of * the files is "stdout", causing the data to be printed on the * screen. The second file is whatever the user likes; it will * contain a copy of whatever has been printed on the screen. * The author likes to name his file "fort.13", to match the default * FORTRAN name for output file 13. * * If cprini is called a second time, it will keep the old files * open, remembering their names; if it is called yet again * to switch back to the first set of files, it will not * reopen them but will pick up writing where it left off. * (This obsoletes the functions cprinstart and cprinstop, which * however are provided for compatibility reasons.) * * * The following functions are provided: * * cprini is the initialization function (see description below). * cprintff has exactly the same calling sequence as printf, but * prints on both files simultaneously. * * cprin, cprinf, cprin2, cprinq, and cprina are array printing * routines; their calling sequences are identical, except * for the types of data they print. Specifically, * cprin prints floating point data * cprinf prints integer data * cprin2 prints double precision data * cprinq prints extended precision data * cprina prints character data (but it is probably preferable to * use cprintff for this, instead.) * * Of these five functions, only cprin has a complete description * below (see); the rest are identical (except for the type of data * they print). * * cprinstop stops the printing on both files, until further notice, * to be given by a call to cprinstart * * cprinstart resumes printing previously suspended by a call the * cprinstop; if the printing had not been suspended, cprinstart * has no effect. * * cprclose closes files opened by cprini, in order to free up open file * slots (of which the system only provides a limited number). * */ void cprintff(char *s, ...); /* forward declaration */ /* * This function prints a real *4 array of length n, * preceded by a user message. A typical invocation * looks like * * cprin("printing real array a of length 10, a=",a,10); * * to print an array, or * * cprin("printing real array number a; a=",&a,1); * * to print a real number. * * Input parameters: * * mes - a character array to be printed * ap - the real array to be printed * n - the length of array arr * */ cprin(mes,ap,n) char *mes; int n; float *ap; { int i,c; if(mes) cprintff("%s\n",mes); for(i=0; iMBUFSIZE) lbuf=MBUFSIZE; if(fpcur[0]) fwrite(buf,lbuf,1,fpcur[0]); if(fpcur[1]) fwrite(buf,lbuf,1,fpcur[1]); } cprinstop() { istop=1; } cprinstart() { istop=0; }