Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology |
||
3 | * |
||
4 | * This program is free software; you can redistribute it and/or modify |
||
5 | * it under the terms of the GNU General Public License as published by |
||
6 | * the Free Software Foundation; either version 2 of the License, or |
||
7 | * (at your option) any later version. |
||
8 | * |
||
9 | * This program is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU General Public License for more details. |
||
13 | * |
||
14 | * You should have received a copy of the GNU General Public License |
||
15 | * along with this program; if not, write to the Free Software |
||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
17 | * |
||
18 | */ |
||
19 | |||
20 | //#include <ports/stdio.h> |
||
21 | #include <stdlib.h> |
||
22 | |||
23 | #include <ports/fftw-int.h> |
||
24 | |||
25 | /**************** import/export using file ***************/ |
||
26 | /* |
||
27 | static void file_emitter(char c, void *data) |
||
28 | { |
||
29 | putc(c, (FILE *) data); |
||
30 | } |
||
31 | |||
32 | void fftw_export_wisdom_to_file(FILE *output_file) |
||
33 | { |
||
34 | if (output_file) |
||
35 | fftw_export_wisdom(file_emitter, (void *) output_file); |
||
36 | } |
||
37 | |||
38 | static int file_get_input(void *data) |
||
39 | { |
||
40 | return getc((FILE *) data); |
||
41 | } |
||
42 | |||
43 | fftw_status fftw_import_wisdom_from_file(FILE *input_file) |
||
44 | { |
||
45 | if (!input_file) |
||
46 | return FFTW_FAILURE; |
||
47 | return fftw_import_wisdom(file_get_input, (void *) input_file); |
||
48 | } |
||
49 | */ |
||
50 | /*************** import/export using string **************/ |
||
51 | |||
52 | static void emission_counter(char c, void *data) |
||
53 | { |
||
54 | int *counter = (int *) data; |
||
55 | |||
56 | ++*counter; |
||
57 | } |
||
58 | |||
59 | static void string_emitter(char c, void *data) |
||
60 | { |
||
61 | char **output_string = (char **) data; |
||
62 | |||
63 | *((*output_string)++) = c; |
||
64 | **output_string = 0; |
||
65 | } |
||
66 | |||
67 | char *fftw_export_wisdom_to_string(void) |
||
68 | { |
||
69 | int string_length = 0; |
||
70 | char *s, *s2; |
||
71 | |||
72 | fftw_export_wisdom(emission_counter, (void *) &string_length); |
||
73 | |||
74 | s = (char *) fftw_malloc(sizeof(char) * (string_length + 1)); |
||
75 | if (!s) |
||
76 | return 0; |
||
77 | s2 = s; |
||
78 | |||
79 | fftw_export_wisdom(string_emitter, (void *) &s2); |
||
80 | |||
81 | if (s + string_length != s2) |
||
82 | fftw_die("Unexpected output string length!"); |
||
83 | |||
84 | return s; |
||
85 | } |
||
86 | |||
87 | static int string_get_input(void *data) |
||
88 | { |
||
89 | char **input_string = (char **) data; |
||
90 | |||
91 | if (**input_string) |
||
92 | return *((*input_string)++); |
||
93 | else |
||
94 | return 0; |
||
95 | } |
||
96 | |||
97 | fftw_status fftw_import_wisdom_from_string(const char *input_string) |
||
98 | { |
||
99 | const char *s = input_string; |
||
100 | |||
101 | if (!input_string) |
||
102 | return FFTW_FAILURE; |
||
103 | return fftw_import_wisdom(string_get_input, (void *) &s); |
||
104 | } |