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 | IMAGE_EXPORT(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 | IMAGE_EXPORT(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 | IMAGE_EXPORT(void) generate_path_filename(char *path, char *filename, char *complete_filename, int maxlen) |
---|
69 | /* ---------------------------------------------------------------------------------------------------- */ |
---|
70 | { |
---|
71 | snprintf(complete_filename, maxlen, "%s%s", path, filename); |
---|
72 | } |
---|
73 | /* ------------------------------------------------------------------------------------------------------------------------------- */ |
---|
74 | IMAGE_EXPORT(void) generate_path_filename_extension(char *path, char *filename, char *extension, char *complete_filename, int maxlen) |
---|
75 | /* ------------------------------------------------------------------------------------------------------------------------------- */ |
---|
76 | { |
---|
77 | snprintf(complete_filename, maxlen, "%s%s.%s", path, filename, extension); |
---|
78 | } |
---|
79 | /* ---------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
80 | IMAGE_EXPORT(void) generate_path_filename_suffix_extension(char *path, char *filename, char *suffix, char *extension, char *complete_filename, int maxlen) |
---|
81 | /* ---------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
82 | { |
---|
83 | snprintf(complete_filename, maxlen, "%s%s%s.%s", path, filename, suffix, extension); |
---|
84 | } |
---|
85 | /* ----------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
86 | IMAGE_EXPORT(void) generate_path_filename_k_ndigit_extension(char *path, char *filename, int k, int ndigit, char *extension, char *complete_filename, int maxlen) |
---|
87 | /* ----------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
88 | { |
---|
89 | char *format = "%s%s%d.%s"; |
---|
90 | |
---|
91 | switch(ndigit) { |
---|
92 | case 0 : format = "%s%s%d.%s"; break; |
---|
93 | case 1 : format = "%s%s%01d.%s"; break; |
---|
94 | case 2 : format = "%s%s%02d.%s"; break; |
---|
95 | case 3 : format = "%s%s%03d.%s"; break; |
---|
96 | case 4 : format = "%s%s%04d.%s"; break; |
---|
97 | case 5 : format = "%s%s%05d.%s"; break; |
---|
98 | case 6 : format = "%s%s%06d.%s"; break; |
---|
99 | case 7 : format = "%s%s%07d.%s"; break; |
---|
100 | case 8 : format = "%s%s%08d.%s"; break; |
---|
101 | case 9 : format = "%s%s%09d.%s"; break; |
---|
102 | } |
---|
103 | snprintf(complete_filename, maxlen, format, path, filename, k, extension); |
---|
104 | } |
---|
105 | /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
106 | IMAGE_EXPORT(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) |
---|
107 | /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ |
---|
108 | { |
---|
109 | char *format = "%s%s%d_%d.%s"; |
---|
110 | |
---|
111 | switch(ndigit) { |
---|
112 | case 0 : format = "%s%s%d_%d.%s"; break; |
---|
113 | case 1 : format = "%s%s%01d_%01d.%s"; break; |
---|
114 | case 2 : format = "%s%s%02d_%02d.%s"; break; |
---|
115 | case 3 : format = "%s%s%03d_%03d.%s"; break; |
---|
116 | case 4 : format = "%s%s%04d_%04d.%s"; break; |
---|
117 | case 5 : format = "%s%s%05d_%05d.%s"; break; |
---|
118 | case 6 : format = "%s%s%06d_%06d.%s"; break; |
---|
119 | case 7 : format = "%s%s%07d_%07d.%s"; break; |
---|
120 | case 8 : format = "%s%s%08d_%08d.%s"; break; |
---|
121 | case 9 : format = "%s%s%09d_%09d.%s"; break; |
---|
122 | } |
---|
123 | snprintf(complete_filename, maxlen, format, path, filename, k, l, extension); |
---|
124 | } |
---|
125 | // ---------------------------------------------------------------------------- |
---|
126 | void select_display_positive_parameters(int iformat, char **format, char **str) |
---|
127 | // ---------------------------------------------------------------------------- |
---|
128 | { |
---|
129 | char *format1 = "%1d", *str1 = " "; |
---|
130 | char *format2 = "%2d", *str2 = " "; |
---|
131 | char *format3 = "%3d", *str3 = " "; |
---|
132 | char *format4 = "%4d", *str4 = " "; |
---|
133 | char *format5 = "%5d", *str5 = " "; |
---|
134 | char *format6 = "%6d", *str6 = " "; |
---|
135 | char *format7 = "%7d", *str7 = " "; |
---|
136 | char *format8 = "%8d", *str8 = " "; |
---|
137 | char *format9 = "%9d", *str9 = " "; |
---|
138 | |
---|
139 | switch(iformat) { |
---|
140 | case 1: *format = format1; *str = str1; break; |
---|
141 | case 2: *format = format2; *str = str2; break; |
---|
142 | case 3: *format = format3; *str = str3; break; |
---|
143 | case 4: *format = format4; *str = str4; break; |
---|
144 | case 5: *format = format5; *str = str5; break; |
---|
145 | case 6: *format = format6; *str = str6; break; |
---|
146 | case 7: *format = format7; *str = str7; break; |
---|
147 | case 8: *format = format8; *str = str8; break; |
---|
148 | case 9: *format = format9; *str = str9; break; |
---|
149 | default: *format = format3; *str = str3; break; |
---|
150 | } |
---|
151 | } |
---|