Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
2de90bda
Commit
2de90bda
authored
Oct 23, 2015
by
Thomas Jahns
🤸
Browse files
Clarify purpose of function.
parent
7a5f5a24
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/stream_ieg.c
View file @
2de90bda
...
...
@@ -3,6 +3,7 @@
#endif
#include
<limits.h>
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
...
...
@@ -228,30 +229,38 @@ static void iegDefTime(int *pdb, int date, int time, int taxisID)
pdb
[
5
]
=
128
;
}
static
int
calc_resfac
(
double
xfirst
,
double
xlast
,
double
xinc
,
double
yfirst
,
double
ylast
,
double
yinc
)
/* find smallest power of 10 in [1000,10000000] that upon
* multiplication results in fractional part close to zero for all
* arguments */
static
double
calc_resfac
(
double
xfirst
,
double
xlast
,
double
xinc
,
double
yfirst
,
double
ylast
,
double
yinc
)
{
int
i
,
j
;
int
iresfac
=
1000
;
int
ifact
;
int
ifacarr
[
5
]
=
{
1000
,
10000
,
100000
,
1000000
,
10000000
};
double
vals
[
6
]
=
{
xfirst
,
xlast
,
xinc
,
yfirst
,
ylast
,
yinc
};
for
(
j
=
0
;
j
<
5
;
++
j
)
double
resfac
=
1000
.
0
;
enum
{
nPwrOf10
=
5
,
nMultTests
=
6
,
};
static
const
double
scaleFactors
[
nPwrOf10
]
=
{
1000
,
10000
,
100000
,
1000000
,
10000000
};
double
vals
[
nMultTests
]
=
{
xfirst
,
xlast
,
xinc
,
yfirst
,
ylast
,
yinc
};
for
(
size_t
j
=
0
;
j
<
nPwrOf10
;
++
j
)
{
ifact
=
ifacarr
[
j
];
for
(
i
=
0
;
i
<
6
;
++
i
)
double
scaleBy
=
scaleFactors
[
j
];
bool
fractionalScale
=
false
;
for
(
size_t
i
=
0
;
i
<
nMultTests
;
++
i
)
{
if
(
fabs
(
vals
[
i
]
*
ifact
-
round
(
vals
[
i
]
*
ifact
))
>
FLT_EPSILON
)
break
;
fractionalScale
=
fractionalScale
||
fabs
(
vals
[
i
]
*
scaleBy
-
round
(
vals
[
i
]
*
scaleBy
))
>
FLT_EPSILON
;
}
if
(
i
==
6
)
if
(
!
fractionalScale
)
{
i
resfac
=
ifact
;
resfac
=
scaleBy
;
break
;
}
}
return
(
i
resfac
);
return
(
resfac
);
}
static
...
...
@@ -328,8 +337,8 @@ void iegDefGrid(int *gdb, int gridID)
else
IEG_G_GridType
(
gdb
)
=
0
;
int
i
resfac
=
calc_resfac
(
xfirst
,
xlast
,
xinc
,
yfirst
,
ylast
,
yinc
);
double
resfac
=
(
double
)
i
resfac
;
double
resfac
=
calc_resfac
(
xfirst
,
xlast
,
xinc
,
yfirst
,
ylast
,
yinc
);
int
i
resfac
=
(
int
)
resfac
;
if
(
iresfac
==
1000
)
iresfac
=
0
;
IEG_G_ResFac
(
gdb
)
=
iresfac
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment