Sets the output file or the error message output file.
void
imsls_output_file (
IMSLS_SET_OUTPUT_FILE, FILE *ofile,
IMSLS_GET_OUTPUT_FILE, FILE
**pofile,
IMSLS_SET_ERROR_FILE, FILE *efile,
IMSLS_GET_ERROR_FILE, FILE
**pefile,
0)
IMSLS_SET_OUTPUT_FILE,
FILE *ofile
(Input)
Sets the output file to ofile.
Default: ofile = stdout
IMSLS_GET_OUTPUT_FILE,
FILE **pofile
(Output)
Sets the FILE pointed to by pofile to the current
output file.
IMSLS_SET_ERROR_FILE,
FILE *efile
(Input)
Sets the error message output file to efile.
Default: efile = stderr
IMSLS_GET_ERROR_FILE,
FILE **pefile
(Output)
Sets the FILE pointed to by pefile to the error
message output file.
This function allows the file used for printing by IMSL functions 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 imsls_output_file from within each thread. See Example 2 for more details.
This example opens the file myfile and sets the output file to this new file. Function imsls_f_write_matrix then writes to this file.
#include <stdio.h>
#include
<imsls.h>
main()
{
FILE
*ofile;
float x[] =
{3.0, 2.0, 1.0};
imsls_f_write_matrix ("x (default
file)", 1, 3, x, 0);
ofile = fopen("myfile",
"w");
imsls_output_file(IMSLS_SET_OUTPUT_FILE,
ofile,
0);
imsls_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 imsls_f_write_matrix from within each thread. Note that imsls_output_file is called from within each thread to change the default output file.
/* Disable IMSL signal trapping. */
imsls_error_options(IMSLS_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. */
imsls_output_file(IMSLS_SET_OUTPUT_FILE, file_ptr, 0);
/* Compute 5 random numbers. */
rand_nums = imsls_f_random_uniform(5, 0);
imsls_f_write_matrix("Random Numbers", 5, 1, rand_nums, 0);
if (rand_nums) free(rand_nums);
float x[] = {0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32,
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96,
/* Open a file to write the result in. */
file_ptr = fopen("ex2.out", "w");
/* Set the output file for this thread. */
imsls_output_file(IMSLS_SET_OUTPUT_FILE, file_ptr, 0);
table = imsls_f_table_oneway (n_observations, x, n_intervals, 0);
imsls_f_write_matrix("counts", 1, n_intervals, table, 0);
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |