-
Notifications
You must be signed in to change notification settings - Fork 0
/
renorm.c
88 lines (75 loc) · 2.56 KB
/
renorm.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
/*
* HISTORY:
* quick and dirty hack Linas Vepstas October 1989
* more hacks ever since -- Linas
*/
#include <endian.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "opers.h"
#include "fileio.h"
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
float scale_fact;
float offset;
if (argc < 3) {
fprintf (stderr, "Usage: %s <input file> <output file> [<scale factor>] [<offset>] \n", argv[0]);
return 1;
}
fprintf (stderr, "%s %s %s ", argv[0], argv[1], argv[2]);
if (4 <= argc) {
scale_fact = (float) atof (argv[3]);
fprintf (stderr, "%g ", scale_fact);
} else {
scale_fact = 1.0;
}
if (5 <= argc) {
offset = (float) atof (argv[4]);
fprintf (stderr, "%g ", offset);
} else {
offset = 0.0;
}
fprintf (stderr, "\n");
/*-----------------------------------------------*/
/* open input file */
const char* suff;
unsigned int data_width, data_height; /* data array dimensions */
float* data_in = read_floats(argv[1], &suff, &data_width, &data_height);
if (NULL == data_in)
{
fprintf (stderr, " Can't open input file %s \n", argv[1]);
return 2;
}
/*-----------------------------------------------*/
/* Strip out the path */
char * p = strdup(argv[0]);
char * name = strrchr(p, '/');
if (NULL == name) name = p;
else name++;
if (!strcmp ("takelog", name)) takelog (data_in, data_width, data_height);
else if (!strcmp ("recip", name)) recip (data_in, data_width, data_height);
else if (!strcmp ("abs", name)) absolval (data_in, data_width, data_height);
else if (!strcmp ("takeroot", name)) takeroot (data_in, data_width, data_height, scale_fact);
else if (!strcmp ("renorm", name)) expand (data_in, data_width, data_height, scale_fact, offset);
else if (!strcmp ("reclamp", name)) rescale (data_in, data_width, data_height, scale_fact);
else if (!strcmp ("clamp", name)) clamp (data_in, data_width, data_height, scale_fact, offset);
else if (!strcmp ("dump", name)) dump (data_in, data_width, data_height);
else
{
fprintf(stderr, "Error: unknown transform %s\n", name);
exit(1);
}
/*
aver = avg (data_in, data_width, data_height);
msq = sqdev (data_in, data_width, data_height);
msq = sqrt (msq);
printf ("yo average was %f rms %f \n", aver, msq);
expand (data_in, data_width, data_height, scale_fact/msq, aver);
*/
write_floats(argv[2], suff, data_in, data_width, data_height);
return 0;
}
/* --------------- END OF FILE ------------------------- */