-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_master_turbulence_screen_pow.c
169 lines (151 loc) · 5.69 KB
/
make_master_turbulence_screen_pow.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
/**
* @file make_master_turbulence_screen_pow.c
* @brief Create master turbulence screen following power law index
*
*
*/
#include <math.h>
#include "CommandLineInterface/CLIcore.h"
// required for create_2Dimage_ID
#include "COREMOD_arith/COREMOD_arith.h"
#include "COREMOD_memory/COREMOD_memory.h"
#include "fft/fft.h"
#include "image_gen/image_gen.h"
// ==========================================
// Forward declaration(s)
// ==========================================
errno_t AtmosphericTurbulence_make_master_turbulence_screen_pow(
const char *ID_name1, const char *ID_name2, uint32_t size, float power);
// ==========================================
// Command line interface wrapper function(s)
// ==========================================
/** @brief Example CLI function
*
* Command Line Interface (CLI) wrapper to function\n
* This is referred to as a "CLI function", written to connect a command
* on the CLI prompt to a function.\n
* A CLI function will check arguments entered on the prompt, and pass
* them to the function.
*
* Naming conventions:
* - CLI function <modulename>__<function>__cli()
* - Execution function <modulename>__<function>()
*
*
*
* ### Checking if arguments are valid
*
* Each argument is checked by calling CLI_checkarg(i, argtype), which
* checks if argument number <i> conforms to type <argtype>.\n
*
* Types are defined in CLIcore.h. Common types are:
* - CLIARG_FLOAT floating point number
* - CLIARG_LONG integer (int or long)
* - CLIARG_STR_NOT_IMG string, not existing image
* - CLIARG_IMG existing image
* - CLIARG_STR string
*/
static errno_t AtmosphericTurbulence_make_master_turbulence_screen_pow__cli()
{
if(0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) +
CLI_checkarg(2, CLIARG_STR_NOT_IMG) + CLI_checkarg(3, CLIARG_INT64) +
CLI_checkarg(4, CLIARG_FLOAT64) ==
0)
{
// If arguments meet requirements, command is executed
//
AtmosphericTurbulence_make_master_turbulence_screen_pow(
data.cmdargtoken[1].val.string,
data.cmdargtoken[2].val.string,
data.cmdargtoken[3].val.numl,
data.cmdargtoken[4].val.numf);
return CLICMD_SUCCESS;
}
else
{
// If arguments do not pass test, errror code returned
return CLICMD_INVALID_ARG;
}
}
// ==========================================
// Register CLI command(s)
// ==========================================
errno_t AtmosphericTurbulence_make_master_turbulence_screen_pow_addCLIcmd()
{
RegisterCLIcommand(
"mkturbscreenpow",
__FILE__,
AtmosphericTurbulence_make_master_turbulence_screen_pow__cli,
"creates master turbulence screens with power law index",
"<screen1> <screen2> <size> <powindex>",
"mkturbscreenpow scr1 scr2 512 1.7",
"AtmosphericTurbulence_make_master_turbulence_screen_pow(const char "
"*ID_name1, const char "
"*ID_name2, uint32_t size, float power)");
return RETURN_SUCCESS;
}
// By convention, function name starts with <modulename>__
//
errno_t AtmosphericTurbulence_make_master_turbulence_screen_pow(
const char *ID_name1, const char *ID_name2, uint32_t size, float power)
{
imageID ID;
uint32_t ii;
uint32_t jj;
float value, C1, C2;
long cnt;
long Dlim = 3;
make_rnd("tmppha", size, size, "");
arith_image_cstmult("tmppha", 2.0 * PI, "tmppha1");
delete_image_ID("tmppha", DELETE_IMAGE_ERRMODE_WARNING);
make_dist("tmpd", size, size, size / 2, size / 2);
make_rnd("tmpg", size, size, "-gauss");
arith_image_cstpow("tmpd", power, "tmpd1");
delete_image_ID("tmpd", DELETE_IMAGE_ERRMODE_WARNING);
arith_image_div("tmpg", "tmpd1", "tmpamp");
delete_image_ID("tmpg", DELETE_IMAGE_ERRMODE_WARNING);
delete_image_ID("tmpd1", DELETE_IMAGE_ERRMODE_WARNING);
arith_set_pixel("tmpamp", 0.0, size / 2, size / 2);
mk_complex_from_amph("tmpamp", "tmppha1", "tmpc", 0);
delete_image_ID("tmpamp", DELETE_IMAGE_ERRMODE_WARNING);
delete_image_ID("tmppha1", DELETE_IMAGE_ERRMODE_WARNING);
permut("tmpc");
do2dfft("tmpc", "tmpcf");
delete_image_ID("tmpc", DELETE_IMAGE_ERRMODE_WARNING);
mk_reim_from_complex("tmpcf", "tmpo1", "tmpo2", 0);
delete_image_ID("tmpcf", DELETE_IMAGE_ERRMODE_WARNING);
/* compute the scaling factor in the power law of the structure function */
fft_structure_function("tmpo1", "strf");
ID = image_ID("strf");
value = 0.0;
cnt = 0;
for(ii = 1; ii < Dlim; ii++)
for(jj = 1; jj < Dlim; jj++)
{
value += log10(data.image[ID].array.F[jj * size + ii]) -
power * log10(sqrt(ii * ii + jj * jj));
/* printf("%ld %ld %f\n",ii,jj,log10(data.image[ID].array.F[jj*size+ii])-5.0/3.0*log10(sqrt(ii*ii+jj*jj)));*/
cnt++;
}
delete_image_ID("strf", DELETE_IMAGE_ERRMODE_WARNING);
C1 = pow(10.0, value / cnt);
fft_structure_function("tmpo2", "strf");
ID = image_ID("strf");
value = 0.0;
cnt = 0;
for(ii = 1; ii < Dlim; ii++)
for(jj = 1; jj < Dlim; jj++)
{
value += log10(data.image[ID].array.F[jj * size + ii]) -
power * log10(sqrt(ii * ii + jj * jj));
cnt++;
}
delete_image_ID("strf", DELETE_IMAGE_ERRMODE_WARNING);
C2 = pow(10.0, value / cnt);
/* printf("%f %f\n",C1,C2);*/
arith_image_cstmult("tmpo1", 1.0 / sqrt(C1), ID_name1);
arith_image_cstmult("tmpo2", 1.0 / sqrt(C2), ID_name2);
delete_image_ID("tmpo1", DELETE_IMAGE_ERRMODE_WARNING);
delete_image_ID("tmpo2", DELETE_IMAGE_ERRMODE_WARNING);
return RETURN_SUCCESS;
}