MED fichier
generateFilterArray.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2017 EDF R&D, CEA/DEN
4  * MED is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * MED is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with MED. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <med.h>
19 #define MESGERR 1
20 #include "med_utils.h"
21 #include <string.h>
22 
23 #include <unistd.h>
24 #include <time.h>
25 #include <assert.h>
26 #include <stdlib.h>
27 
28 static int cmp(const med_int *p1, const med_int *p2) { return *p1-*p2; }
29 
30 med_err generateFilterArray( const med_int nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue,
31  const med_size profilearraysize, const med_int * const profilearray, unsigned int seed,
32  med_int * const nentitiesfiltered, med_int **filterarray ) {
33 
34 
35  med_err _ret=-1;
36  med_int _nentitiesfiltered=0,_maxfilternentities=0;
37  med_int *_indexarray=NULL;
38  int _i=0;
39 
40  /*Taille du tableau des numéros d'entités à filtrer */
41  if ( profilearraysize ) {
42  _maxfilternentities = profilearraysize;
43  } else {
44  _maxfilternentities = nentities;
45  }
46 
47  /* Allocation du tableau de filtre */
48 
49  srandom(seed);
50  _nentitiesfiltered = 1 + (int) ((float)(_maxfilternentities) * (random() / (RAND_MAX + 1.0)));
51  /* _nentitiesfiltered = 2; */
52 
53  (*filterarray) = malloc(_nentitiesfiltered*sizeof(med_int));
54 
55 /* if ( profilearraysize) { */
56 /* _indexarray = malloc(_nentitiesfiltered*sizeof(med_int)); */
57 /* } else { */
58 /* _indexarray=(*filterarray); */
59 /* } */
60 
61  _indexarray=(*filterarray);
62 
63  for (_i=0; _i < _nentitiesfiltered; ++_i ) {
64  _indexarray[_i] = 1 + (int) ((double)(_maxfilternentities) * (random() / (RAND_MAX + 1.0)));
65  }
66 
67  /*N'enlève pas les doublons, mais celà fonctionne*/
68  qsort(_indexarray, _nentitiesfiltered, sizeof(med_int), (int(*)(const void *, const void *) ) cmp);
69 
70 /* for (_i=0; _i < _nentitiesfiltered; ++_i ) { */
71 /* ISCRUTE(_indexarray[_i]); */
72 /* } */
73 
74  /* Cette indirection ne doit jamais être faite car le tableau filtre contient des indices de profils.*/
75 /* if ( profilearraysize) */
76 /* for (_i=0; _i < _nentitiesfiltered; ++_i ) { */
77 /* (*filterarray)[_i] = profilearray[_indexarray[_i]]; */
78 /* ISCRUTE((*filterarray)[_i]); */
79 /* } */
80 
81  *nentitiesfiltered=_nentitiesfiltered;
82 
83  _ret=0;
84 
85  ERROR:
86 /* if ( profilearraysize) free(_indexarray); */
87 
88  return _ret;
89 
90 }
static int cmp(const med_int *p1, const med_int *p2)
int med_int
Definition: med.h:335
hsize_t med_size
Definition: med.h:322
herr_t med_err
Definition: med.h:325
med_err generateFilterArray(const med_int nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue, const med_size profilearraysize, const med_int *const profilearray, unsigned int seed, med_int *const nentitiesfiltered, med_int **filterarray)