TP Intégration Numérique
 All Files Functions
utils.c
Go to the documentation of this file.
1 
8 #include "utils.h"
9 
10 /* Prototype of the calloc function : */
11 /* void *calloc(size_t nmemb, size_t size); */
12 void *Calloc(size_t nmemb,size_t size){
13  void *ptr;
14  PRINT_VERBOSE("->");
15  ptr=calloc(nmemb,size);
16  assert(ptr != NULL);
17  PRINT_DEBUG("Calloc",ptr);
18  PRINT_VERBOSE("<-");
19  return ptr;
20 }
21 
22 /* Prototype of the calloc function : */
23 /* void void *malloc(size_t size); */
24 void *Malloc(size_t size){
25  void *ptr;
26  PRINT_VERBOSE("->");
27  ptr=malloc(size);
28  assert(ptr != NULL);
29  PRINT_DEBUG("Malloc",ptr);
30  PRINT_VERBOSE("<-");
31  return ptr;
32 }
33 
34 /* Prototype of the free function : */
35 /* void free(void *ptr); */
36 void Free(void *ptr){
37  PRINT_VERBOSE("->");
38  PRINT_DEBUG("Free",ptr);
39  free(ptr);
40  PRINT_VERBOSE("<-");
41 }
42 
43 void FREE(void **ptr){
44  PRINT_VERBOSE("->");
45  PRINT_DEBUG("FREE",*ptr);
46  free(*ptr);
47  *ptr==NULL;
48  PRINT_VERBOSE("<-");
49 }
50 
51 void printDoubleDynArray(double *X,int N,char *Name,char *format,int perline){
52  int i;
53  PRINT_VERBOSE("->");
54  printf("%s =",Name);
55  for (i=0;i<N;i++){
56  if (i%perline == 0)
57  if (i==N-1)
58  printf("\n value %d\n",i);
59  else
60  printf("\n values %d through %d\n",i,MIN(i+perline,N-1));
61  printf(" ");
62  printf(format,X[i]);
63  }
64  printf("\n");
65  PRINT_VERBOSE("<-");
66 }
67 
68 void saveDoubleDynArray(double *X,int N,char *FileName,char *format){
69  int i;
70  FILE *fid;
71  PRINT_VERBOSE("->");
72  fid = fopen(FileName,"w");
73  assert( fid != NULL);
74  for (i=0;i<N;i++){
75  fprintf(fid,format,X[i]);
76  fprintf(fid,"\n");
77  }
78  fclose(fid);
79  PRINT_VERBOSE("<-");
80 }
81 
82 void saveTwoDoubleDynArray(double *X,double *Y,int N,char *FileName,char *format){
83  int i;
84  FILE *fid;
85  PRINT_VERBOSE("->");
86  fid = fopen(FileName,"w");
87  assert( fid != NULL);
88  for (i=0;i<N;i++){
89  fprintf(fid,format,X[i],Y[i]);
90  fprintf(fid,"\n");
91  }
92  fclose(fid);
93 #ifdef VERBOSE
94  printf("%sverbose : %s [%s line %d]\n -> Data save in file %s%s\n",VERBOSECOLOR,__FUNCTION__,__FILE__,__LINE__,FileName,TEXTCOLOR_END);
95 #endif
96  PRINT_VERBOSE("<-");
97 }
98