Info Node: (fftw.info)Importing and Exporting Wisdom
(fftw.info)Importing and Exporting Wisdom
Importing and Exporting Wisdom
------------------------------
void fftw_export_wisdom_to_file(FILE *output_file);
fftw_status fftw_import_wisdom_from_file(FILE *input_file);
`fftw_export_wisdom_to_file' writes the `wisdom' to `output_file',
which must be a file open for writing. `fftw_import_wisdom_from_file'
reads the `wisdom' from `input_file', which must be a file open for
reading, and returns `FFTW_SUCCESS' if successful and `FFTW_FAILURE'
otherwise. In both cases, the file is left open and must be closed by
the caller. It is perfectly fine if other data lie before or after the
`wisdom' in the file, as long as the file is positioned at the
beginning of the `wisdom' data before import.
char *fftw_export_wisdom_to_string(void);
fftw_status fftw_import_wisdom_from_string(const char *input_string)
`fftw_export_wisdom_to_string' allocates a string, exports the
`wisdom' to it in `NULL'-terminated format, and returns a pointer to
the string. If there is an error in allocating or writing the data, it
returns `NULL'. The caller is responsible for deallocating the string
(with `fftw_free') when she is done with it.
`fftw_import_wisdom_from_string' imports the `wisdom' from
`input_string', returning `FFTW_SUCCESS' if successful and
`FFTW_FAILURE' otherwise.
Exporting `wisdom' does not affect the store of `wisdom'. Imported
`wisdom' supplements the current store rather than replacing it (except
when there is conflicting `wisdom', in which case the older `wisdom' is
discarded). The format of the exported `wisdom' is "nerd-readable"
LISP-like ASCII text; we will not document it here except to note that
it is insensitive to white space (interested users can contact us for
more details).
Note:FFTW Reference, for more information, and for a description
of how you can implement `wisdom' import/export for other media besides
files and strings.
The following is a brief example in which the `wisdom' is read from
a file, a plan is created (possibly generating more `wisdom'), and then
the `wisdom' is exported to a string and printed to `stdout'.
{
fftw_plan plan;
char *wisdom_string;
FILE *input_file;
/* open file to read wisdom from */
input_file = fopen("sample.wisdom", "r");
if (FFTW_FAILURE == fftw_import_wisdom_from_file(input_file))
printf("Error reading wisdom!\n");
fclose(input_file); /* be sure to close the file! */
/* create a plan for N=64, possibly creating and/or using wisdom */
plan = fftw_create_plan(64,FFTW_FORWARD,
FFTW_MEASURE | FFTW_USE_WISDOM);
/* ... do some computations with the plan ... */
/* always destroy plans when you are done */
fftw_destroy_plan(plan);
/* write the wisdom to a string */
wisdom_string = fftw_export_wisdom_to_string();
if (wisdom_string != NULL) {
printf("Accumulated wisdom: %s\n",wisdom_string);
/* Just for fun, destroy and restore the wisdom */
fftw_forget_wisdom(); /* all gone! */
fftw_import_wisdom_from_string(wisdom_string);
/* wisdom is back! */
fftw_free(wisdom_string); /* deallocate it since we're done */
}
}
automatically generated byinfo2wwwversion 1.2.2.9