1 | /* --------------- */ |
---|
2 | /* --- nrio0.c --- */ |
---|
3 | /* --------------- */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved |
---|
7 | * Univ Paris Sud XI, CNRS |
---|
8 | * |
---|
9 | * Distributed under the Boost Software License, Version 1.0 |
---|
10 | * see accompanying file LICENSE.txt or copy it at |
---|
11 | * http://www.boost.org/LICENSE_1_0.txt |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <stddef.h> |
---|
16 | #include <stdlib.h> |
---|
17 | |
---|
18 | #include "mypredef.h" |
---|
19 | #include "nrtype.h" |
---|
20 | #include "nrdef.h" |
---|
21 | #include "nrmacro.h" |
---|
22 | #include "nrkernel.h" |
---|
23 | |
---|
24 | #include "nralloc1.h" |
---|
25 | #include "nrio0.h" |
---|
26 | |
---|
27 | /* --------------------------------------------------------------------------------------------------- */ |
---|
28 | void generate_filename_k_ndigit(char * filename, int k, int ndigit, char * complete_filename, int maxlen) |
---|
29 | /* --------------------------------------------------------------------------------------------------- */ |
---|
30 | { |
---|
31 | char * format = "%s%d.txt"; |
---|
32 | |
---|
33 | switch (ndigit) { |
---|
34 | case 0 : format = "%s%d.txt"; break; |
---|
35 | case 1 : format = "%s%01d.txt"; break; |
---|
36 | case 2 : format = "%s%02d.txt"; break; |
---|
37 | case 3 : format = "%s%03d.txt"; break; |
---|
38 | case 4 : format = "%s%04d.txt"; break; |
---|
39 | case 5 : format = "%s%05d.txt"; break; |
---|
40 | case 6 : format = "%s%06d.txt"; break; |
---|
41 | case 7 : format = "%s%07d.txt"; break; |
---|
42 | case 8 : format = "%s%08d.txt"; break; |
---|
43 | case 9 : format = "%s%09d.txt"; break; |
---|
44 | } |
---|
45 | snprintf(complete_filename, maxlen, format, filename, k); |
---|
46 | } |
---|
47 | /* ------------------------------------------------------------------------------------------------------------------------------------------ */ |
---|
48 | void generate_filename_k_ndigit_extension(char * filename, int k, int ndigit, char * extension, char * complete_filename, int maxlen) |
---|
49 | /* ------------------------------------------------------------------------------------------------------------------------------------------ */ |
---|
50 | { |
---|
51 | char * format = "%s%d.%s"; |
---|
52 | |
---|
53 | switch (ndigit) { |
---|
54 | case 0 : format = "%s%d.%s"; break; |
---|
55 | case 1 : format = "%s%01d.%s"; break; |
---|
56 | case 2 : format = "%s%02d.%s"; break; |
---|
57 | case 3 : format = "%s%03d.%s"; break; |
---|
58 | case 4 : format = "%s%04d.%s"; break; |
---|
59 | case 5 : format = "%s%05d.%s"; break; |
---|
60 | case 6 : format = "%s%06d.%s"; break; |
---|
61 | case 7 : format = "%s%07d.%s"; break; |
---|
62 | case 8 : format = "%s%08d.%s"; break; |
---|
63 | case 9 : format = "%s%09d.%s"; break; |
---|
64 | } |
---|
65 | snprintf(complete_filename, maxlen, format, filename, k, extension); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | /* ---------------------------------------------------------------------------------------------------- */ |
---|
70 | void generate_path_filename(char * path, char * filename, char * complete_filename, int maxlen) |
---|
71 | /* ---------------------------------------------------------------------------------------------------- */ |
---|
72 | { |
---|
73 | snprintf(complete_filename, maxlen, "%s%s", path, filename); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | /* ------------------------------------------------------------------------------------------------------------------------------- */ |
---|
78 | void generate_path_filename_extension(char * path, char * filename, char * extension, char * complete_filename, int maxlen) |
---|
79 | /* ------------------------------------------------------------------------------------------------------------------------------- */ |
---|
80 | { |
---|
81 | snprintf(complete_filename, maxlen, "%s%s.%s", path, filename, extension); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /* ---------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
86 | void generate_path_filename_suffix_extension(char * path, char * filename, char * suffix, char * extension, char * complete_filename, int maxlen) |
---|
87 | /* ---------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
88 | { |
---|
89 | snprintf(complete_filename, maxlen, "%s%s%s.%s", path, filename, suffix, extension); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | /* ----------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
94 | void generate_path_filename_k_ndigit_extension(char * path, char * filename, int k, int ndigit, char * extension, char * complete_filename, int maxlen) |
---|
95 | /* ----------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
96 | { |
---|
97 | char * format = "%s%s%d.%s"; |
---|
98 | |
---|
99 | switch(ndigit) { |
---|
100 | case 0 : format = "%s%s%d.%s"; break; |
---|
101 | case 1 : format = "%s%s%01d.%s"; break; |
---|
102 | case 2 : format = "%s%s%02d.%s"; break; |
---|
103 | case 3 : format = "%s%s%03d.%s"; break; |
---|
104 | case 4 : format = "%s%s%04d.%s"; break; |
---|
105 | case 5 : format = "%s%s%05d.%s"; break; |
---|
106 | case 6 : format = "%s%s%06d.%s"; break; |
---|
107 | case 7 : format = "%s%s%07d.%s"; break; |
---|
108 | case 8 : format = "%s%s%08d.%s"; break; |
---|
109 | case 9 : format = "%s%s%09d.%s"; break; |
---|
110 | } |
---|
111 | snprintf(complete_filename, maxlen, format, path, filename, k, extension); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
116 | void generate_path_filename_k_ndigit_l_extension(char * path, char * filename, int k, int ndigit, int l, char * extension, char * complete_filename, int maxlen) |
---|
117 | /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
118 | { |
---|
119 | char * format = "%s%s%d_%d.%s"; |
---|
120 | |
---|
121 | switch (ndigit) { |
---|
122 | case 0 : format = "%s%s%d_%d.%s"; break; |
---|
123 | case 1 : format = "%s%s%01d_%01d.%s"; break; |
---|
124 | case 2 : format = "%s%s%02d_%02d.%s"; break; |
---|
125 | case 3 : format = "%s%s%03d_%03d.%s"; break; |
---|
126 | case 4 : format = "%s%s%04d_%04d.%s"; break; |
---|
127 | case 5 : format = "%s%s%05d_%05d.%s"; break; |
---|
128 | case 6 : format = "%s%s%06d_%06d.%s"; break; |
---|
129 | case 7 : format = "%s%s%07d_%07d.%s"; break; |
---|
130 | case 8 : format = "%s%s%08d_%08d.%s"; break; |
---|
131 | case 9 : format = "%s%s%09d_%09d.%s"; break; |
---|
132 | } |
---|
133 | snprintf(complete_filename, maxlen, format, path, filename, k, l, extension); |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | // ------------------------------------------------------------------------------ |
---|
138 | void select_display_positive_parameters(int iformat, char ** format, char ** str) |
---|
139 | // ------------------------------------------------------------------------------ |
---|
140 | { |
---|
141 | char * format1 = "%1d", * str1 = " "; |
---|
142 | char * format2 = "%2d", * str2 = " "; |
---|
143 | char * format3 = "%3d", * str3 = " "; |
---|
144 | char * format4 = "%4d", * str4 = " "; |
---|
145 | char * format5 = "%5d", * str5 = " "; |
---|
146 | char * format6 = "%6d", * str6 = " "; |
---|
147 | char * format7 = "%7d", * str7 = " "; |
---|
148 | char * format8 = "%8d", * str8 = " "; |
---|
149 | char * format9 = "%9d", * str9 = " "; |
---|
150 | |
---|
151 | switch (iformat) { |
---|
152 | case 1: *format = format1; *str = str1; break; |
---|
153 | case 2: *format = format2; *str = str2; break; |
---|
154 | case 3: *format = format3; *str = str3; break; |
---|
155 | case 4: *format = format4; *str = str4; break; |
---|
156 | case 5: *format = format5; *str = str5; break; |
---|
157 | case 6: *format = format6; *str = str6; break; |
---|
158 | case 7: *format = format7; *str = str7; break; |
---|
159 | case 8: *format = format8; *str = str8; break; |
---|
160 | case 9: *format = format9; *str = str9; break; |
---|
161 | default: *format = format3; *str = str3; break; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | // Local Variables: |
---|
166 | // tab-width: 4 |
---|
167 | // c-basic-offset: 4 |
---|
168 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
169 | // indent-tabs-mode: nil |
---|
170 | // End: |
---|
171 | |
---|
172 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
173 | |
---|