SDDSlib
Loading...
Searching...
No Matches
counter.c File Reference

Provides functions to sequence values over an n-dimensional grid. More...

#include "mdb.h"

Go to the source code of this file.

Functions

long advance_values (double *value, long *value_index, double *initial, double *step, long n_values, long *counter, long *max_count, long n_indices)
 Sequences an array of values systematically to cover an n-dimensional grid.
 
long advance_counter (long *counter, long *max_count, long n_indices)
 Advances the counter array based on maximum counts.
 

Detailed Description

Provides functions to sequence values over an n-dimensional grid.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file counter.c.

Function Documentation

◆ advance_counter()

long advance_counter ( long * counter,
long * max_count,
long n_indices )

Advances the counter array based on maximum counts.

Parameters
counterPointer to the counter array to be advanced.
max_countPointer to the array of maximum counts.
n_indicesNumber of indices in the counter.
Returns
Returns -1 if all counters have reached their maximum; otherwise, returns the index that was incremented.

Definition at line 51 of file counter.c.

51 {
52 long i;
53
54 for (i = 0; i < n_indices; i++)
55 if (counter[i] != (max_count[i] - 1))
56 break;
57 if (i == n_indices)
58 return (-1);
59
60 for (i = 0; i < n_indices; i++) {
61 if (counter[i] < (max_count[i] - 1)) {
62 counter[i]++;
63 break;
64 } else {
65 counter[i] = 0;
66 }
67 }
68 return (i);
69}

◆ advance_values()

long advance_values ( double * value,
long * value_index,
double * initial,
double * step,
long n_values,
long * counter,
long * max_count,
long n_indices )

Sequences an array of values systematically to cover an n-dimensional grid.

Parameters
valuePointer to the array of values to be updated.
value_indexPointer to the array of value indices.
initialPointer to the array of initial values.
stepPointer to the array of step sizes.
n_valuesNumber of values in the array.
counterPointer to the counter array.
max_countPointer to the maximum count array.
n_indicesNumber of indices.
Returns
Returns -1 if the counter cannot be advanced further; otherwise, returns the index of the counter that was changed.

Definition at line 31 of file counter.c.

32 {
33 long i, counter_changed;
34
35 if ((counter_changed = advance_counter(counter, max_count, n_indices)) < 0)
36 return (-1);
37
38 for (i = 0; i < n_values; i++)
39 value[i] = initial[i] + counter[value_index[i]] * step[i];
40 return (counter_changed);
41}
long advance_counter(long *counter, long *max_count, long n_indices)
Advances the counter array based on maximum counts.
Definition counter.c:51