Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
cdo
Commits
ecbf5106
Commit
ecbf5106
authored
Dec 25, 2017
by
Uwe Schulzweida
Browse files
Declare find_element() static.
parent
1673358d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/interpol.cc
View file @
ecbf5106
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
* @param nelem length of the sorted list
* @param nelem length of the sorted list
* @param x the element to find a position for
* @param x the element to find a position for
*/
*/
static
long
find_element
(
double
x
,
long
nelem
,
const
double
*
restrict
array
)
long
find_element
(
double
x
,
long
nelem
,
const
double
*
restrict
array
)
{
{
long
ii
;
long
ii
;
...
@@ -29,10 +30,10 @@ long find_element(double x, long nelem, const double *restrict array)
...
@@ -29,10 +30,10 @@ long find_element(double x, long nelem, const double *restrict array)
if
(
array
[
0
]
<
array
[
nelem
-
1
]
)
// ascending order
if
(
array
[
0
]
<
array
[
nelem
-
1
]
)
// ascending order
{
{
/
*
return the length of the array if x is out of bounds
*/
/
/
return the length of the array if x is out of bounds
if
(
x
<
array
[
0
]
||
x
>
array
[
nelem
-
1
]
)
return
nelem
;
if
(
x
<
array
[
0
]
||
x
>
array
[
nelem
-
1
]
)
return
nelem
;
/
*
search for the interval in which x fits
*/
/
/
search for the interval in which x fits
// implementation: binary search algorithm
// implementation: binary search algorithm
for
(
ii
=
1
;
ii
<
nelem
;
++
ii
)
for
(
ii
=
1
;
ii
<
nelem
;
++
ii
)
{
{
...
@@ -41,7 +42,7 @@ long find_element(double x, long nelem, const double *restrict array)
...
@@ -41,7 +42,7 @@ long find_element(double x, long nelem, const double *restrict array)
// faster!
// faster!
mid
=
(
first
+
last
)
>>
1
;
mid
=
(
first
+
last
)
>>
1
;
/
*
return the bigger interval border of the interval in which x fits
*/
/
/
return the bigger interval border of the interval in which x fits
// if ( x >= array[mid-1] && x <= array[mid] ) break;
// if ( x >= array[mid-1] && x <= array[mid] ) break;
// faster!
// faster!
if
(
!
(
x
<
array
[
mid
-
1
]
||
x
>
array
[
mid
])
)
break
;
if
(
!
(
x
<
array
[
mid
-
1
]
||
x
>
array
[
mid
])
)
break
;
...
@@ -55,10 +56,10 @@ long find_element(double x, long nelem, const double *restrict array)
...
@@ -55,10 +56,10 @@ long find_element(double x, long nelem, const double *restrict array)
}
}
else
else
{
{
/
*
return the length of the array if x is out of bounds
*/
/
/
return the length of the array if x is out of bounds
if
(
x
<
array
[
nelem
-
1
]
||
x
>
array
[
0
]
)
return
nelem
;
if
(
x
<
array
[
nelem
-
1
]
||
x
>
array
[
0
]
)
return
nelem
;
/
*
search for the interval in which x fits
*/
/
/
search for the interval in which x fits
// implementation: binary search algorithm
// implementation: binary search algorithm
for
(
ii
=
1
;
ii
<
nelem
;
++
ii
)
for
(
ii
=
1
;
ii
<
nelem
;
++
ii
)
{
{
...
@@ -67,7 +68,7 @@ long find_element(double x, long nelem, const double *restrict array)
...
@@ -67,7 +68,7 @@ long find_element(double x, long nelem, const double *restrict array)
// faster!
// faster!
mid
=
(
first
+
last
)
>>
1
;
mid
=
(
first
+
last
)
>>
1
;
/
*
return the bigger interval border of the interval in which x fits
*/
/
/
return the bigger interval border of the interval in which x fits
// if ( x >= array[mid] && x <= array[mid-1] ) break;
// if ( x >= array[mid] && x <= array[mid-1] ) break;
// faster!
// faster!
if
(
!
(
x
<
array
[
mid
]
||
x
>
array
[
mid
-
1
])
)
break
;
if
(
!
(
x
<
array
[
mid
]
||
x
>
array
[
mid
-
1
])
)
break
;
...
@@ -93,12 +94,12 @@ long find_element(double x, long nelem, const double *array)
...
@@ -93,12 +94,12 @@ long find_element(double x, long nelem, const double *array)
if ( array[0] < array[nelem-1] )
if ( array[0] < array[nelem-1] )
{
{
for ( ii = 1; ii < nelem; ii++ )
for ( ii = 1; ii < nelem; ii++ )
if ( x >= array[ii-1] && x <= array[ii] ) break;
if ( x >= array[ii-1] && x <= array[ii] ) break;
}
}
else
else
{
{
for ( ii = 1; ii < nelem; ii++ )
for ( ii = 1; ii < nelem; ii++ )
if ( x >= array[ii] && x <= array[ii-1] ) break;
if ( x >= array[ii] && x <= array[ii-1] ) break;
}
}
return ii;
return ii;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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