SDDSlib
Loading...
Searching...
No Matches
counter.c
Go to the documentation of this file.
1/**
2 * @file counter.c
3 * @brief Provides functions to sequence values over an n-dimensional grid.
4 *
5 * @copyright
6 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
7 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
8 *
9 * @license
10 * This file is distributed under the terms of the Software License Agreement
11 * found in the file LICENSE included with this distribution.
12 *
13 * @author M. Borland, C. Saunders, R. Soliday
14 */
15
16#include "mdb.h"
17
18/**
19 * @brief Sequences an array of values systematically to cover an n-dimensional grid.
20 *
21 * @param value Pointer to the array of values to be updated.
22 * @param value_index Pointer to the array of value indices.
23 * @param initial Pointer to the array of initial values.
24 * @param step Pointer to the array of step sizes.
25 * @param n_values Number of values in the array.
26 * @param counter Pointer to the counter array.
27 * @param max_count Pointer to the maximum count array.
28 * @param n_indices Number of indices.
29 * @return Returns -1 if the counter cannot be advanced further; otherwise, returns the index of the counter that was changed.
30 */
31long advance_values(double *value, long *value_index, double *initial, double *step, long n_values,
32 long *counter, long *max_count, long n_indices) {
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}
42
43/**
44 * @brief Advances the counter array based on maximum counts.
45 *
46 * @param counter Pointer to the counter array to be advanced.
47 * @param max_count Pointer to the array of maximum counts.
48 * @param n_indices Number of indices in the counter.
49 * @return Returns -1 if all counters have reached their maximum; otherwise, returns the index that was incremented.
50 */
51long advance_counter(long *counter, long *max_count, long n_indices) {
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}
long advance_counter(long *counter, long *max_count, long n_indices)
Advances the counter array based on maximum counts.
Definition counter.c:51
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.
Definition counter.c:31