-
Notifications
You must be signed in to change notification settings - Fork 2
/
addxwnmr2pipe.c
206 lines (180 loc) · 5.11 KB
/
addxwnmr2pipe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
xyza2pipe - a cross conversion environment of NMR spectra
Copyright 2017 Masashi Yokochi
https://github.com/yokochi47/xyza2pipe
forked from http://fermi.pharm.hokudai.ac.jp/olivia/
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "xyza2pipe.h"
static const char *usage[] = {
"addxwnmr2pipe -i/--in1 inTemplate1(2D/3D/4D) -j/--in2 inTemplate2(2D/3D/4D) > stdout\n", "Optional Arguments:\n",
" -a/--add inTemplate1 + inTemplate2 (default)\n", " -s/--sub inTemplate1 - inTemplate2\n",
" -m/--mul inTemplate1 * inTemplate2\n",
" --c1 Scale factor for inTemplate1 (default=1.0)\n", " --c2 Scale factor for inTemplate2 (default=1.0)\n",
" --xLAB X-Axis Label\n", " --yLAB Y-Axis Label\n", " --zLAB Z-Axis Label\n", " --aLAB A-Axis Label\n",
" --xCAR X-Axis Center [ppm]\n", " --yCAR Y-Axis Center [ppm]\n", " --zCAR Z-Axis Center [ppm]\n",
" --aCAR A-Axis Center [ppm]\n\n", ""
};
int main(int argc, char *argv[])
{
char axis_option = 'x';
char filename1[MAXLONGNAME] = { "" }, filename2[MAXLONGNAME] = { "" };
int l, opt_idx = 0;
float c1 = 1.0, c2 = 1.0;
enum_combine_opr opr_code = COMBINE_ADD;
static struct option options[] = {
{"in1", required_argument, 0, 'i'},
{"in2", required_argument, 0, 'j'},
{"c1", required_argument, 0, 3},
{"c2", required_argument, 0, 4},
{"add", no_argument, 0, 'a'},
{"sub", no_argument, 0, 's'},
{"mul", no_argument, 0, 'm'},
{"xLAB", required_argument, 0, 6},
{"yLAB", required_argument, 0, 7},
{"zLAB", required_argument, 0, 8},
{"aLAB", required_argument, 0, 9},
{"xCAR", required_argument, 0, 10},
{"yCAR", required_argument, 0, 11},
{"zCAR", required_argument, 0, 12},
{"aCAR", required_argument, 0, 13},
{0}
};
while (1) {
l = getopt_long(argc, argv, "i:j:asmd", options, &opt_idx);
if (l == -1)
break;
switch (l) {
case 0:
if (options[opt_idx].flag != 0)
break;
fprintf(stderr, "option %s", options[opt_idx].name);
if (optarg)
fprintf(stderr, " with arg %s", optarg);
fputc('\n', stderr);
break;
case 'i':
if (optarg)
strncpy(filename1, optarg, MAXLONGNAME);
break;
case 'j':
if (optarg)
strncpy(filename2, optarg, MAXLONGNAME);
break;
case 'a':
opr_code = COMBINE_ADD;
break;
case 's':
opr_code = COMBINE_SUB;
break;
case 'm':
opr_code = COMBINE_MUL;
break;
case 3:
c1 = atof(optarg);
break;
case 4:
c2 = atof(optarg);
break;
case 6:
if (optarg) {
usrlabel = 1;
strncpy(axislabel[0], optarg, MAXAXISNAME);
}
break;
case 7:
if (optarg) {
usrlabel = 1;
strncpy(axislabel[1], optarg, MAXAXISNAME);
}
break;
case 8:
if (optarg) {
usrlabel = 1;
strncpy(axislabel[2], optarg, MAXAXISNAME);
}
break;
case 9:
if (optarg) {
usrlabel = 1;
strncpy(axislabel[3], optarg, MAXAXISNAME);
}
break;
case 10:
usrshift = 1;
usrcenter[0] = atof(optarg);
break;
case 11:
usrshift = 1;
usrcenter[1] = atof(optarg);
break;
case 12:
usrshift = 1;
usrcenter[2] = atof(optarg);
break;
case 13:
usrshift = 1;
usrcenter[3] = atof(optarg);
break;
case '?': /* getopt_long already printed an error message. */
break;
}
}
if (argc == 3) {
strncpy(filename1, argv[1], MAXLONGNAME);
strncpy(filename2, argv[2], MAXLONGNAME);
}
else if (optind < argc) {
fprintf(stderr, "non-option ARGV-elements: ");
while (optind < argc)
fprintf(stderr, "%s ", argv[optind++]);
fputc('\n', stderr);
return EXIT_FAILURE;
}
if (filename1[0] == 0 || filename2[0] == 0) {
l = 0;
while (strcmp(usage[l], "") != 0)
fprintf(stderr, "%s", usage[l++]);
return EXIT_FAILURE;
}
if (checkxwnmr(filename1) != 0)
return EXIT_FAILURE;
_dimension = dimension;
memcpy(&(datasize_orig[0]), &(datasize[0]), dimension * sizeof(int));
if (checkxwnmr(filename2) != 0)
return EXIT_FAILURE;
if (dimension != _dimension) {
fprintf(stderr, "addxwnmr2pipe error: unmatch dimension number.\n");
return EXIT_FAILURE;
}
for (l = 0; l < dimension; l++) {
if (datasize[l] != datasize_orig[l]) {
fprintf(stderr, "addxwnmr2pipe error: unmatch data size.\n");
return EXIT_FAILURE;
}
}
cnvhdr(axis_option, 'f');
if (isatty(STDOUT_FILENO)) {
fprintf(stderr, "addxwnmr2pipe error: output to terminal.\n");
return EXIT_FAILURE;
}
switch (dimension) {
case 2:
return pushaddxwnmr2d(filename1, filename2, c1, c2, opr_code);
case 3:
return pushaddxwnmr3d(filename1, filename2, c1, c2, opr_code);
case 4:
return pushaddxwnmr4d(filename1, filename2, c1, c2, opr_code);
default:
fprintf(stderr, "addxwnmr2pipe error: unsupported dimension number.\n");
return EXIT_FAILURE;
}
}