MED fichier
generateFilterArray.c
Aller à la documentation de ce fichier.
1/* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2020 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
28static int cmp(const med_int *p1, const med_int *p2) { return *p1-*p2; }
29
30med_err generateFilterArray( const med_size nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue,
31 const med_size profilearraysize, const med_int * const profilearray,
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 struct tm *_tm ;
40 time_t _tt=time(0);
41
42 _tm = localtime(&_tt);
43
44
45 /*Taille du tableau des numéros d'entités à filtrer */
46 if ( profilearraysize ) {
47 _maxfilternentities = profilearraysize;
48 } else {
49 _maxfilternentities = nentities;
50 }
51
52 /* Allocation du tableau de filtre */
53
54 srandom((*_tm).tm_sec * (*_tm).tm_min );
55 _nentitiesfiltered = 1 + (int) ((float)(_maxfilternentities) * (random() / (RAND_MAX + 1.0)));
56 /* _nentitiesfiltered = 2; */
57
58 (*filterarray) = malloc(_nentitiesfiltered*sizeof(med_int));
59
60/* if ( profilearraysize) { */
61/* _indexarray = malloc(_nentitiesfiltered*sizeof(med_int)); */
62/* } else { */
63/* _indexarray=(*filterarray); */
64/* } */
65
66 _indexarray=(*filterarray);
67
68 for (_i=0; _i < _nentitiesfiltered; ++_i ) {
69 _indexarray[_i] = 1 + (int) ((double)(_maxfilternentities) * (random() / (RAND_MAX + 1.0)));
70 }
71
72 /*N'enlève pas les doublons, mais celà fonctionne*/
73 qsort(_indexarray, _nentitiesfiltered, sizeof(med_int), (int(*)(const void *, const void *) ) cmp);
74
75/* for (_i=0; _i < _nentitiesfiltered; ++_i ) { */
76/* ISCRUTE(_indexarray[_i]); */
77/* } */
78
79 /* Cette indirection ne doit jamais être faite car le tableau filtre contient des indices de profils.*/
80/* if ( profilearraysize) */
81/* for (_i=0; _i < _nentitiesfiltered; ++_i ) { */
82/* (*filterarray)[_i] = profilearray[_indexarray[_i]]; */
83/* ISCRUTE((*filterarray)[_i]); */
84/* } */
85
86 *nentitiesfiltered=_nentitiesfiltered;
87
88 _ret=0;
89
90 ERROR:
91/* if ( profilearraysize) free(_indexarray); */
92
93 return _ret;
94
95}
med_err generateFilterArray(const med_size nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue, const med_size profilearraysize, const med_int *const profilearray, med_int *const nentitiesfiltered, med_int **filterarray)
static int cmp(const med_int *p1, const med_int *p2)
int med_int
Definition: med.h:333
hsize_t med_size
Definition: med.h:320
herr_t med_err
Definition: med.h:323