Sets the output file or the error message output file.
void
imsl_output_file (
IMSL_SET_OUTPUT_FILE, FILE
*ofile,
IMSL_GET_OUTPUT_FILE, FILE **pofile,
IMSL_SET_ERROR_FILE,
FILE *efile,
IMSL_GET_ERROR_FILE, FILE **pefile,
0)
IMSL_SET_OUTPUT_FILE,
FILE *ofile
(Input)
Set the output file to ofile.
Default: ofile = stdout
IMSL_GET_OUTPUT_FILE,
FILE **pfile
(Output)
Set the FILE pointed to by pfile to the current
output file.
IMSL_SET_ERROR_FILE,
FILE *efile
(Input)
Set the error message output file to efile.
Default: efile = stderr
IMSL_GET_ERROR_FILE,
FILE **pefile
(Output)
Set the FILE pointed to by pefile to the error
message output file.
This function allows the file used for printing by IMSL routines to be changed.
If multiple threads are used then default settings are
valid for each thread. When using threads it is possible to set different output
files for each thread by calling imsl_output_file in
Chapter 15 of the
IMSL Stat Numerical Libraries from within each thread. See Example 2
for details.
This example opens the file myfile
and changes the output file to this new file.
The function imsl_f_write_matrix
then writes to this file.
#include <stdio.h>
#include
<imsl.h>
main()
{
FILE *ofile;
float x[] = {3.0, 2.0,
1.0};
imsl_f_write_matrix ("x (default file)", 1, 3,
x, 0);
ofile = fopen("myfile",
"w");
imsl_output_file(IMSL_SET_OUTPUT_FILE,
ofile,
0);
imsl_f_write_matrix ("x (myfile)", 1, 3, x, 0);
}
The following example illustrates how to direct output from IMSL routines that run in separate threads to different files. First, two threads are created, each calling a different IMSL function, then the results are printed by calling imsl_f_write_matrix from within each thread. Note that imsl_output_file is called from within each thread to change the default output file.
/* Disable IMSL signal trapping. */
imsl_error_options(IMSL_SET_SIGNAL_TRAPPING, 0, 0);
if (pthread_create(&thread1, NULL ,ex1, (void *)NULL) != 0)
perror("pthread_create"), exit(1);
if (pthread_create(&thread2, NULL ,ex2, (void *)NULL) != 0)
perror("pthread_create"), exit(1);
/* Wait for threads to finish. */
if (pthread_join(thread1, NULL) != 0)
perror("pthread_join"),exit(1);
if (pthread_join(thread2, NULL) != 0)
perror("pthread_join"),exit(1);
/* Open a file to write the result in. */
file_ptr = fopen("ex1.out", "w");
/* Set the output file for this thread. */
imsl_output_file(IMSL_SET_OUTPUT_FILE, file_ptr, 0);
/* Compute 5 random numbers. */
rand_nums = imsl_f_random_uniform(5, 0);
imsl_f_write_matrix("Random Numbers", 5, 1, rand_nums, 0);
if (rand_nums) free(rand_nums);
/* Open a file to write the result in. */
file_ptr = fopen("ex2.out", "w");
/* Set the output file for this thread. */
imsl_output_file(IMSL_SET_OUTPUT_FILE, file_ptr, 0);
x = imsl_f_lin_sol_gen (n, a, b, 0);
imsl_f_write_matrix ("Solution, x, of Ax = b", 1, 3, x, 0);
|
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |