Yet Another eXchange Tool  DO_NOT_EDIT_HERE
xt_stripe.c
Go to the documentation of this file.
1 
12 /*
13  * Keywords:
14  * Maintainer: Jörg Behrens <behrens@dkrz.de>
15  * Moritz Hanke <hanke@dkrz.de>
16  * Thomas Jahns <jahns@dkrz.de>
17  * URL: https://doc.redmine.dkrz.de/yaxt/html/
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are
21  * met:
22  *
23  * Redistributions of source code must retain the above copyright notice,
24  * this list of conditions and the following disclaimer.
25  *
26  * Redistributions in binary form must reproduce the above copyright
27  * notice, this list of conditions and the following disclaimer in the
28  * documentation and/or other materials provided with the distribution.
29  *
30  * Neither the name of the DKRZ GmbH nor the names of its contributors
31  * may be used to endorse or promote products derived from this software
32  * without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
38  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #ifdef HAVE_CONFIG_H
48 #include <config.h>
49 #endif
50 
51 #include "xt/xt_core.h"
52 #include "xt/xt_stripe.h"
53 
54 #include "core/ppm_xfuncs.h"
55 #include "instr.h"
56 #include "ensure_array_size.h"
57 
58 void xt_convert_indices_to_stripes(const Xt_int *restrict indices,
59  int num_indices,
60  struct Xt_stripe **stripes,
61  int * num_stripes) {
62 
63  INSTR_DEF(instr,"xt_idxstripes_convert_to_stripes")
64  INSTR_START(instr);
65 
66  struct Xt_stripe *restrict temp_stripes = NULL;
67  size_t temp_stripes_array_size = 0;
68  size_t num_temp_stripes = 0;
69 
70  if (num_indices > 0) {
71  size_t i = 0;
72 
73  while(i < (size_t)num_indices) {
74  ++num_temp_stripes;
75 
76  ENSURE_ARRAY_SIZE(temp_stripes, temp_stripes_array_size, num_temp_stripes);
77 
78  size_t j = 1;
79 
80  Xt_int stride = 1;
81  if (i + j < (size_t)num_indices) {
82  stride = (Xt_int)(indices[i + 1] - indices[i]);
83  do {
84  ++j;
85  } while ((i + j) < (size_t)num_indices
86  && indices[i] + (Xt_int)j * stride == indices[i + j]);
87  }
88  j-= ((i + j + 1 < (size_t)num_indices)
89  && ((indices[i + j - 1] == indices[i + j] - 1)
90  & (indices[i + j] == indices[i + j + 1] - 1)));
91 
92  temp_stripes[num_temp_stripes-1].start = indices[i];
93  temp_stripes[num_temp_stripes-1].stride = stride;
94  temp_stripes[num_temp_stripes-1].nstrides = (int)j;
95 
96  i = i + j;
97  }
98  }
99 
100  *stripes = xrealloc(temp_stripes, num_temp_stripes * sizeof(*temp_stripes));
101  *num_stripes = (int)num_temp_stripes;
102  INSTR_STOP(instr);
103 }
104 
105 
106 /*
107  * Local Variables:
108  * c-basic-offset: 2
109  * coding: utf-8
110  * indent-tabs-mode: nil
111  * show-trailing-whitespace: t
112  * require-trailing-newline: t
113  * End:
114  */
base definitions header file
#define INSTR_START(T)
Definition: instr.h:68
add versions of standard API functions not returning on error
#define xrealloc(ptr, size)
Definition: ppm_xfuncs.h:67
XT_INT Xt_int
Definition: xt_core.h:68
void xt_convert_indices_to_stripes(const Xt_int *restrict indices, int num_indices, struct Xt_stripe **stripes, int *num_stripes)
Definition: xt_stripe.c:58
#define ENSURE_ARRAY_SIZE(arrayp, curr_array_size, req_size)
Xt_int stride
Definition: xt_stripe.h:56
#define INSTR_DEF(T, S)
Definition: instr.h:66
#define INSTR_STOP(T)
Definition: instr.h:69