Allink  v0.1
VarDatFile.cpp
1 #include "../include/VarDatFile.h"
2 #include <stdarg.h>
3 
4 VarDatFile::VarDatFile(int ExtNMax,int ExtNVar,int ExtNBin){
5  Init();
6  NMax = ExtNMax;
7  NMaxPunti = NMax;
8  NVar = ExtNVar;
9  NBin = ExtNBin;
10  Allocate();
11  sp = st[0];
12 }
13 VarDatFile::VarDatFile(double **ExtSt,int ExtNMax,int ExtNVar,int ExtNBin){
14  Init();
15  NMax = ExtNMax;
16  NMaxPunti = NMax;
17  NVar = ExtNVar;
18  NBin = ExtNBin;
19  Allocate();
20  st = ExtSt;
21  sp = st[0];
22 }
23 // VarDatFile::VarDatFile(char *file,int NNBin){
24 // NMax = 0;
25 // NVisMin = 0;
26 // NVar=0;
27 // NBin = NNBin;
28 // FILE *InFile;
29 // if((InFile = fopen(file,"r"))==0){
30 // printf("Non s'apre %s\n",file);
31 // exit(0);
32 // }
33 // Init();
34 // int NCol = 0;
35 // NVisMax = NMax = FileInfo(InFile,&NCol);
36 // NVar = NCol;
37 // Allocate();
38 // char cLine[STRLEN];
39 // double *dLine = (double *)calloc(NVar,sizeof(double));
40 // for(int v=0;v<NVar;v++) SetNMax[v] = NMax;
41 // for(int l=0; l<NMax;l++){
42 // fgets(cLine,512,InFile);
43 // if(ReadLine(cLine,dLine)){l--;continue;}
44 // for(int v=0;v<NVar;v++){
45 // st[v][l] = dLine[v];
46 // if(l==0){
47 // sMin[v] = st[v][l];
48 // sMax[v] = st[v][l];
49 // }
50 // if(sMin[v] > st[v][l])
51 // sMin[v] = st[v][l];
52 // if(sMax[v] < st[v][l])
53 // sMax[v] = st[v][l];
54 // }
55 // }
56 // free(dLine);
57 // if(NVar > 1){
58 // CoordY = 1;
59 // CoordX = 0;
60 // RefAbsc[CoordX] = REF_ASC;
61 // for(int v=1;v<NVar;v++)
62 // RefAbsc[v] = CoordX;
63 // }
64 // else{
65 // CoordY = 0;
66 // RefAbsc[CoordY] = REF_SEQ;
67 // }
68 // fclose(InFile);
69 // sp = st[0];
70 // }
71 VarDatFile::VarDatFile(char **FileList,int *Pos,int NFile,int NNBin){
72  NMax=0;
73  NVar=0;
74  Init();
75  NBin = NNBin;
76  int *NMaxFile = (int *)calloc(NFile,sizeof(int));
77  int *NColFile = (int *)calloc(NFile+1,sizeof(int));
78  NColFile[0] = 0;
79  for(int f=0;f<NFile;f++){
80  FILE *FileIn = fopen(FileList[Pos[f]],"r");
81  if(FileIn == 0){
82  printf("File %s not found\n",FileList[Pos[f]]);
83  return;
84  }
85  int NCol = 0;
86  NMaxFile[f] = FileInfo(FileIn,&NCol);
87  NColFile[f+1] = NCol + NColFile[f];
88  if(NMaxFile[f] > NMax) NMax = NMaxFile[f];
89  NMaxPunti = NMax;
90  NVar += NCol;
91  fclose(FileIn);
92  }
93  Allocate();
94  char cLine[STRLEN];
95  double *dLine = (double *)calloc(NVar,sizeof(double));
96  for(int f=0;f<NFile;f++){
97  for(int v=NColFile[f];v<NColFile[f+1];v++)
98  SetNMax[v] = NMaxFile[f];
99  FILE *FileIn = fopen(FileList[Pos[f]],"r");
100  for(int l=0;l<NMaxFile[f];l++){
101  if(!fgets(cLine,512,FileIn))break;
102  if(ReadLine(cLine,dLine)){l--;continue;}
103  for(int v=NColFile[f],vv=0;v<NColFile[f+1];v++,vv++){
104  st[v][l] = dLine[vv];
105  }
106  }
107  fclose(FileIn);
108  if(NColFile[f+1]-NColFile[f] == 1){
109  RefAbsc[NColFile[f]] = NVar;
110  }
111  else {
112  for(int v=NColFile[f];v<NColFile[f+1];v++){
113  RefAbsc[v] = NColFile[f];
114  }
115  }
116  }
117  if(NVar == 1) Punta(0);
118  else Punta(1);
119  free(dLine);
120  free(NMaxFile);
121  free(NColFile);
122 }
123 void VarDatFile::Allocate(){
124  dInter = (double *)calloc(NBin,sizeof(*dInter));
125  dError = (double *)calloc(NBin,sizeof(*dError));
126  dInter1 = (double *)calloc(NBin,sizeof(*dInter));
127  sp = (double *)malloc(sizeof(double));
128  sType = (int *)calloc(NVar,sizeof(int));
129  SetNMax = (int *)calloc(NVar,sizeof(int));
130  sColor = (int *)calloc(NVar,sizeof(int));
131  sMin = (double *)calloc(NVar,sizeof(double));
132  sMax = (double *)calloc(NVar,sizeof(double));
133  sColor = (int *)calloc(NVar,sizeof(int));
134  RefAbsc = (int *)calloc(NVar,sizeof(int));
135  st = (double **)calloc(NVar+1,sizeof(double));
136  if(st == NULL){
137  printf("Could not allocate st \n");
138  exit(0);
139  }
140  //if( !st){printf("st non s'alloca\n");return ;}
141  for(int v=0;v<NVar+1;v++){
142  st[v] = (double *)calloc(NMax,sizeof(double));
143  if(st[v] == NULL){
144  printf("Could not allocate st[%d] \n",v);
145  exit(0);
146  }
147  //if( !st[v]){printf("st non s'alloca\n");return ;}
148  }
149  for(int n=0;n<NMax;n++){
150  st[NVar][n] = (double)n;
151  }
152  //sc = NULL;
153  //sc = (char **)calloc(NVar,sizeof(char));
154  //if(!sc){printf("sc non s'alloca\n");return ;}
155  for(int v=0;v<NVar;v++){
156  //sc[v] = (char *)calloc(120,sizeof(char));
157  //if(!sc[v]){printf("st non s'alloca\n");return ;}
158  }
159 }
161  for(int v=0;v<NVar;v++){
162  free(st[v]);
163  //if(st[v]){printf("st %d is not freed\n",v);}
164  }
165  free(st);
166  //if(st){printf("st is not freed\n");}
167  for(int v=0;v<NVar;v++){
168  //free(sc[v]);
169  //if(sc[v] != NULL){printf("sc %d is not freed\n",v);}
170  }
171  //free(sc);//if(sc != NULL){printf("sc is not freed\n");}
172  free(sMin);
173  free(sMax);
174  free(sType);
175  free(SetNMax);
176  free(sColor);
177  free(RefAbsc);
178  sp = NULL;
179  free(sp);
180  free(dInter);
181  free(dInter1);
182  PuntiFree();
183 }
184 void VarDatFile::Init(){
185  IfPuntiAlloc = 1;
186  IfPuntiFree = 0;
187 }
188 //FIXME: there is still color, type... to be allocated
189 int VarDatFile::Aggiungi(char *file){
190  FILE *InFile;
191  if((InFile = fopen(file,"r"))==NULL){
192  printf("Non s'apre %s\n",file);
193  return 1;
194  }
195  char cLine[512];
196  double **stTemp = (double **)calloc(NVar,sizeof(double));
197  if(stTemp == NULL){printf("stTemp non s'alloca\n");return 0;}
198  for(int v=0;v<NVar;v++){
199  stTemp[v] = (double *)calloc(NMax,sizeof(double));
200  if( stTemp[v] == NULL){printf("stTemp non s'alloca\n");return 0;}
201  }
202  for(int v=0;v<NVar;v++){
203  for(int n=0;n<NMax;n++){
204  stTemp[v][n] = st[v][n];//sign[v*NMax+n];
205  }
206  }
207  int NVarOld = NVar;
208  int NCol = 0;
209  int nPoint = FileInfo(InFile,&NCol);
210  NVar += NCol;
211  if(nPoint > NMax) NMax = nPoint;
212  NMaxPunti = NMax;
213  {
214  for(int v=0;v<NVarOld;v++){
215  free(st[v]);
216  //free(sc[v]);
217  }
218  free(st);
219  //free(sc);
220  st = (double **)calloc(NVar,sizeof(double));
221  if( st == NULL){printf("st non s'alloca\n");return 0;}
222  for(int v=0;v<NVar;v++){
223  st[v] = (double *)calloc(NMax,sizeof(double));
224  if( st[v] == NULL){printf("st non s'alloca\n");return 0;}
225  }
226  }
227  // {
228  // st = (double **)realloc(st,NVar*sizeof(double));
229  // for(int v=0;v<NVar;v++){
230  // st[v] = (double *)realloc(st[v],NMax*sizeof(double));
231  // }
232  // }
233  double *dLine = (double *)calloc(NVar,sizeof(double));
234  for(int l=0; l<NMax;l++){
235  fgets(cLine,512,InFile);
236  if(ReadLine(cLine,dLine))continue;
237  for(int v=NVarOld;v<NVar;v++){
238  st[v][l] = dLine[v-NVarOld];
239  if(sMin[v] > st[v][l])
240  sMin[v] = st[v][l];
241  if(sMax[v] < st[v][l])
242  sMax[v] = st[v][l];
243  }
244  }
245  GlobMax = sMax[0];
246  GlobMin = sMin[0];
247  for(int v=0;v<NVar;v++){
248  if(GlobMax < sMax[v])
249  GlobMax = sMax[v];
250  if(GlobMin > sMin[v])
251  GlobMin = sMin[v];
252  }
253  for(int n=0;n<NMax;n++)
254  for(int v=0;v<NVarOld;v++)
255  st[v][n] = stTemp[v][n];
256  for(int v=0;v<NVarOld;v++)
257  free(stTemp[v]);
258  free(stTemp);
259  free(dLine);
260  fclose(InFile);
261  PuntiFree();
262  //printf("Uscita\n");
263  return 0;
264 }
265 int VarDatFile::FileInfo(FILE *InFile,int *NCol){
266  int nPoint = 0;
267  char cLine[STRSIZE];
268  for(int k=0;!(fgets(cLine,STRSIZE,InFile)==NULL);k++){
269  if(k == 0 && cLine[0] == '#'){
270  sprintf(Header,"%s",cLine);
271  continue;
272  }
273  int iLen = (int) (strlen(cLine));
274  if(cLine[0] != '#' && cLine[0] != '\n')
275  nPoint++;
276  for(int i=0,var=1;i<iLen;i++){
277  if(cLine[i] == '#'){
278  break;//Comment
279  }
280  if(cLine[i] == '\n') break;
281  if(i>0){
282  if( (cLine[i-1] == ' ' || cLine[i-1] == '\t' ) &&
283  (cLine[i] != ' ' && cLine[i] != '\t' ))
284  var++;
285  }
286  if(*NCol < var) *NCol = var;
287  }
288  }
289  rewind(InFile);
290  return nPoint;
291 }
292 int VarDatFile::ReadLine(char *cLine,double *sLine){
293  int iLen = (int) (strlen(cLine));
294  if(cLine[0] == ' ' || cLine[0] == '\t'){
295  for(int i=0;i<iLen;i++){
296  if(cLine[i] != ' ' && cLine[i] != '\t'){
297  cLine += i;
298  break;
299  }
300  }
301  }
302  sscanf(cLine,"%lf",sLine);
303  for(int i=0,v=1;i<iLen;i++){
304  if(cLine[i]=='#') return 1;
305  if(v>=NVar) return 0;
306  if(cLine[i]==' ' || cLine[i] =='\n' || cLine[i]=='\t'){
307  sscanf(cLine+i,"%lf",sLine+v);
308  //printf("%d) %d %s %lf\n",v,i,cLine+i,st[v]);
309  i++;
310  v++;
311  }
312  }
313  return 0;
314 }
315 int VarDatFile::ReadLine(FILE *InFile, const char *Format, ...){
316  va_list ap;
317  int NVariable;
318  char line[256];
319  va_start(ap, Format);
320  fgets(line, 256, InFile);
321  NVariable = vsscanf(line, Format, ap);
322  va_end(ap);
323  return NVariable;
324 }
325 void VarDatFile::AverageOrdinate(int ElMin, int ElMax,double *Distr,double *xBound){
326  double *Count = (double *)calloc(NBin,sizeof(double));
327  for(int n=0;n<NMax;n++){
328  for(int v=0;v<NVar;v++){
329  if(IsAbscissa(v)) continue;
330  if(isnan(st[v][n]))continue;
331  int bx = (int)((Abscissa(v,n) - xBound[0])*xBound[1]*NBin);
332  if(bx < 0 || bx >= NBin) continue;
333  Distr[bx] += st[v][n];
334  Count[bx] += 1.;
335  }
336  }
337  for(int bx=0;bx<NBin;bx++){
338  Distr[bx] /= Count[bx] > 0. ? Count[bx] : 1.;
339  }
340  free(Count);
341 }
342 MOMENTI VarDatFile::DistrSegnale(int ElMin, int ElMax,int IfNorm){
343  return Distribuzione(sp+ElMin,ElMax-ElMin,dInter,NBin,IfNorm);
344 }
345 MOMENTI VarDatFile::DistrLogSegnale(int ElMin, int ElMax,int IfNorm){
346  PuntiAlloc();
347  for(int n=0;n<NMax;n++){
348  Punti[n] = log10(sp[n]);
349  }
350  return Distribuzione(Punti+ElMin,ElMax-ElMin,dInter,NBin,IfNorm);
351 }
352 MOMENTI VarDatFile::DistrExpSegnale(int ElMin, int ElMax,int IfNorm){
353  PuntiAlloc();
354  for(int n=0;n<NMax;n++){
355  Punti[n] = exp(sp[n]);
356  }
357  return Distribuzione(Punti+ElMin,ElMax-ElMin,dInter,NBin,IfNorm);
358 }
359 MOMENTI VarDatFile::DistrSegnale(int ElMin, int ElMax,double *Border,int IfNorm){
360  return Distribuzione(sp+ElMin,ElMax-ElMin,dInter,NBin,Border,IfNorm);
361 }
362 MOMENTI VarDatFile::DistrSignErr(int ElMin, int ElMax,double *Border,int IfNorm){
363  return DistrErr(sp+ElMin,ElMax-ElMin,dInter,dError,NBin,Border,IfNorm);
364 }
365 void VarDatFile::DistrSignSample(int ElMin, int ElMax,double **Distr,int NSample,int IfNorm,double *xBound){
366  DistrSample(st[0]+ElMin,sp+ElMin,ElMax-ElMin,Distr,NBin,NSample,IfNorm,xBound);
367 }
368 MOMENTI VarDatFile::DistrGaussSegnale(int ElMin,int ElMax,int IfNorm){
369  return DistribuzioneGauss(sp+ElMin,ElMax-ElMin,dInter,dInter1,NBin,IfNorm);
370 }
371 MOMENTI VarDatFile::WeightAverageSet(int CoordY,int ElMin, int ElMax){
372  int CoordX = RefAbsc[CoordY];
373  MOMENTI m1 = WeightAverage(st[CoordX]+ElMin,sp+ElMin,ElMax-ElMin);
374  return m1;
375 }
376 int VarDatFile::ElabSegnale(int ElMin,int ElMax){
377  PuntiAlloc();
378  // Elabora(sp+ElMin,Punti,ElMax-ElMin);
379  ElabSt(sp+ElMin,Punti,ElMax-ElMin);
380  return ElMax-ElMin;
381 }
382 int VarDatFile::AutocorSegnale(int ElMin,int ElMax){
383  PuntiAlloc();
384  Autocor(sp+ElMin,Punti,ElMax-ElMin);
385  NMaxPunti = NMax/2;
386  return NMaxPunti;
387 }
388 int VarDatFile::SpettroSegnale(int ElMin,int ElMax){
389  PuntiAlloc();
390  Spettro(sp+ElMin,Punti,ElMax-ElMin);
391  NMaxPunti = NMax;
392  return (int)( (NMax));
393 }
394 void VarDatFile::SpeLine(int ElMin,int ElMax,int NBin,double *Spe){
395 #ifdef USE_FFTW
396  double InvNBin = 1./(double)(NBin);
397  fftw_complex *out = (fftw_complex *)fftw_malloc(NBin*sizeof(fftw_complex));
398  fftw_complex *in = (fftw_complex *)fftw_malloc(NBin*sizeof(fftw_complex));
399  fftw_plan plan = fftw_plan_dft_1d(NBin,in,out,FFTW_FORWARD,FFTW_ESTIMATE);
400  fftw_plan plan2 = fftw_plan_dft_1d(NBin,out,in,FFTW_BACKWARD,FFTW_ESTIMATE);
401  for(int v=0;v<NVar;v++){
402  if(IsAbscissa(v))continue;
403  for(int n=0;n<NBin;n++) in[n][0] = st[v][n];
404  fftw_execute(plan);
405  for(int n=0;n<NBin;n++){
406  Spe[n] += SQR(out[n][0]) + SQR(out[n][1]);
407  }
408  }
409  fftw_free(out);
410  fftw_free(in);
411 #else
412  printf("fftw not present\n");
413 #endif
414 }
416  Normalizza(dInter,NBin);
417 }
418 int VarDatFile::NormalizzaSegnale(int ElMin,int ElMax){
419  int Campioni = NormalizeArea(sp+ElMin,ElMax-ElMin);
420  return Campioni;
421 }
423  PuntiAlloc();
424  Radice(sp,Punti,NMax);
425  return 1;
426 }
428  PuntiAlloc();
429  return Integrazione(sp,Punti,NMax);
430 }
431 double VarDatFile::SumSegnale(int CoordY,int ElMin,int ElMax){
432  double Resp = 0.;
433  int CoordX = RefAbsc[CoordY];
434  double Dx = (st[CoordX][ElMax]-st[CoordX][ElMin]);
435  double NumInv = 1./(double)(ElMax-ElMin);
436  for(int i=ElMin;i<ElMax;i++){
437  Resp += st[CoordY][ElMax];
438  }
439  return Resp*Dx*NumInv;
440 }
442  PuntiAlloc();
443  for(int nm=0;nm<NMax;nm++){
444  Punti[nm] = 0.;
445  for(int nv=0;nv<NVar;nv++){
446  if(IsAbscissa(nv)) continue;
447  Punti[nm] += st[nv][nm];
448  }
449  }
450 }
451 double VarDatFile::VarieSegnale(int ElMin,int ElMax){
452  if(NVar < 2) return 0.;
453  PuntiAlloc();
454  double *temp1 = (double *)malloc(NMax*sizeof(double));
455  double *temp2 = (double *)malloc(NMax*sizeof(double));
456  double VolA=0.,VolB=0.;
457  double VolFracA=0.,VolFracB=0.;
458  double SqrGradCoeff=0.;
459  for(int n=0;n<NMax;n++){
460  temp1[n] = 0.;
461  temp2[n] = 0.;
462  }
463  double Coeff[4] = {1.,0.,0.,1.};
464  double MaxA=0.,MaxB=0.;
465  for(int n=0;n<NMax;n++){
466  if(MaxA < st[1][n]) MaxA = st[1][n];
467  if(MaxB < st[2][n]) MaxB = st[2][n];
468  }
469  for(int n=0;n<NMax;n++){
470  if(st[1][n] > MaxA*.5)
471  VolA += 1.;
472  if(st[2][n] > MaxB*.5)
473  VolB += 1.;
474  }
475  VolFracA = VolA / (VolA + VolB);
476  VolFracB = VolB / (VolA + VolB);
477  SqrGradCoeff = 19.13/(24.*VolFracA*VolA)+3.04/(24.*VolFracB*VolB);
478  sp = st[1];
479  DerO4(sp+ElMin,temp1,ElMax-ElMin);
480  sp = st[2];
481  DerO4(sp+ElMin,temp2,ElMax-ElMin);
482  for(int i=0;i<4;i++){
483  Coeff[i] *= SqrGradCoeff;
484  }
485  for(int n=0;n<NMax;n++){
486  Punti[n] = Coeff[0]*temp1[n]*temp1[n];
487  Punti[n] += Coeff[1]*temp1[n]*temp2[n];
488  Punti[n] += Coeff[2]*temp2[n]*temp1[n];
489  Punti[n] += Coeff[3]*temp2[n]*temp2[n];
490  Punti[n] /= 2.;
491  }
492  double Risp=0.;
493  for(int n=75;n<125;n++){
494  Risp += Punti[n];
495  }
496  free(temp1);
497  free(temp2);
498  return Risp;
499 }
500 RETTA VarDatFile::InterRettSegnale(int CoordY,int ElMin,int ElMax,int LogLog){
501  RETTA r1;
502  double *Puntix;
503  double *Puntiy;
504  int CoordX = RefAbsc[CoordY];
505  if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
506  Puntix = (double *)calloc(ElMax-ElMin,sizeof(*Puntix));
507  for(int i=ElMin;i<ElMax;i++){
508  if(st[CoordX][i] > 0.)
509  Puntix[i-ElMin] = log10(st[CoordX][i]);
510  }
511  }
512  else{
513  Puntix = st[CoordX]+ElMin;
514  }
515  if(DIS_IF_TYPE(LogLog,DIS_LOGY)){
516  Puntiy = (double *)calloc(ElMax-ElMin,sizeof(*Puntiy));
517  for(int i=ElMin;i<ElMax;i++){
518  if(st[CoordY][i] > 0.)
519  Puntiy[i-ElMin] = log10(st[CoordY][i]);
520  }
521  }
522  else{
523  Puntiy = st[CoordY]+ElMin;
524  }
525  r1 = InterRett(Puntix,Puntiy,ElMax-ElMin);
526  if(DIS_IF_TYPE(LogLog,DIS_LOGX)) free(Puntix);
527  if(DIS_IF_TYPE(LogLog,DIS_LOGY)) free(Puntiy);
528  return r1;
529 }
530 RETTA VarDatFile::InterExpSegnale(int CoordY,int ElMin,int ElMax,int LogLog){
531  RETTA r1;
532  int CoordX = RefAbsc[CoordY];
533  r1 = InterExp(st[CoordX]+ElMin,st[CoordY]+ElMin,ElMax-ElMin);
534  return r1;
535 }
536 MOMENTI VarDatFile::InterGaussSegnale(int CoordY,int ElMin,int ElMax,int LogLog){
537  int CoordX = RefAbsc[CoordY];
538  MOMENTI m1 = InterGauss(st[CoordX]+ElMin,st[CoordY]+ElMin,ElMax-ElMin);
539  return m1;
540 }
541 PARABOLA VarDatFile::ParabolaSegnale(int CoordY,int ElMin,int ElMax,int LogLog){
542  PARABOLA p1;
543  double *Puntix;
544  double *Puntiy;
545  int CoordX = RefAbsc[CoordY];
546  if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
547  Puntix = (double *)calloc(ElMax-ElMin,sizeof(*Puntix));
548  for(int i=ElMin;i<ElMax;i++){
549  if(st[CoordX][i] > 0.)
550  Puntix[i] = log(st[CoordX][i]);
551  }
552  }
553  else{
554  Puntix = st[CoordX];
555  }
556  if(DIS_IF_TYPE(LogLog,DIS_LOGY)){
557  Puntiy = (double *)calloc(ElMax-ElMin,sizeof(*Puntix));
558  for(int i=ElMin;i<ElMax;i++){
559  if(st[CoordY][i] > 0.)
560  Puntiy[i] = log10(st[CoordY][i]);
561  }
562  }
563  else{
564  Puntiy = st[CoordY];
565  }
566  p1 = MinimoParabola(Puntix+ElMin,Puntiy+ElMin,ElMax-ElMin);
567  if(DIS_IF_TYPE(LogLog,DIS_LOGX))
568  free(Puntix);
569  if(DIS_IF_TYPE(LogLog,DIS_LOGY))
570  free(Puntiy);
571  return p1;
572 }
574  PuntiAlloc();
575  NMaxPunti = MediaMobile(sp,NMax,Punti,PuntiErr,n);
576  return NMaxPunti;
577 }
579  int NBin = NMax;
580  double **Histo = (double **)calloc(NHisto,sizeof(double));
581  for(int h=0;h<NHisto;h++){
582  Histo[h] = (double *)calloc(NBin,sizeof(double));
583  }
584  for(int v=0,h=0;v<NVar;v++){
585  if(IsAbscissa(v)) continue;
586  for(int b=0;b<NBin;b++){
587  Histo[h][b] = st[v][b];
588  }
589  h++;
590  }
592  pMinMaxGlob(0,NBin);
593  double Border[2] = {xGlobMin,xGlobMax};
594  double tolerance = 0.00001;
595  double *NanoDist = (double *)calloc(NHisto,sizeof(double));
596  double *kSpring = (double *)calloc(NHisto,sizeof(double));
597  for(int h=0;h<NHisto;h++){
598  kSpring[h] = Histo[h][NBin-2];
599  NanoDist[h] = Histo[h][NBin-1];
600  }
601  // NanoDist[1]=3.5;
602  // NanoDist[2]=4.0;
603  // NanoDist[3]=5.07;
604  // NanoDist[4]=5.6;
605  // NanoDist[5]=6.4;
606  // NanoDist[6]=7.2;
607  // NanoDist[7]=8;
608  // NanoDist[8]=8.8;
609  // NanoDist[9]=9.6;
610  // NanoDist[10]=10.4;
611  // NanoDist[11]=10.76;
612  // NanoDist[12]=11.56;
613  // NanoDist[13]=12.8;
614  WeightHisto(Histo,Border,NBin-2,NHisto,tolerance,NanoDist,kSpring);
615  for(int h=0;h<NHisto;h++)
616  free(Histo[h]);
617  free(Histo);
618  free(NanoDist);
619  free(kSpring);
620 }
622  PuntiAlloc();
623  NMaxPunti = CorrelaDuePunti(sp,NMax,Punti,n);
624  return NMaxPunti;
625 }
627  PuntiAlloc();
628  Autosimilarita(sp,NMax,Punti,n);
629  NMaxPunti = NMax;
630 }
632  if(n < 0)
633  return;
634  NBin = n;
635  dInter = (double *)realloc(dInter,NBin*sizeof(double));
636  dInter1 = (double *)realloc(dInter1,NBin*sizeof(double));
637 }
638 void VarDatFile::Punta(int n){
639  if(n < 0 || n > NVar)
640  return;
641  sp = st[n];
642 }
643 void VarDatFile::Punta(double *spExt,int n){
644  if(n < 0 || n >= NVar)
645  return;
646  spExt = st[n];
647 }
648 void VarDatFile::PuntaInt(double *spExt){
649  sp = spExt;
650 }
651 void VarDatFile::Punta(double **ExtSt,int n){
652  if(n <0 || n>NVar)
653  return;
654  st = ExtSt;
655  sp = ExtSt[n];
656 }
657 double VarDatFile::Val(int CoordY,int n){
658 #ifdef FILE_DEBUG
659  if(n<0 || n>NMax-1 ){printf("Wrong row\n");return 0.;}
660  if(CoordY<0 || v>NBin-1){printf("Wrong col\n"); return 0.;}
661 #endif
662  return st[CoordY][n];
663 }
664 int VarDatFile::pNRow(int CoordY){
665  return SetNMax[CoordY];
666 }
667 double VarDatFile::Abscissa(int CoordY,int n){
668 #ifdef FILE_DEBUG
669  if(CoordY<0 || n>NMax-1){ printf("Wrong row\n");return 0.;}
670 #endif
671  return st[RefAbsc[CoordY]][n];
672 }
673 double VarDatFile::pPunti(int n){
674 #ifdef FILE_DEBUG
675  if(n<0 || n>NMax-1){ printf("Wrong row\n");return 0.;}
676  if(IfPuntiAlloc) return 0.;
677 #endif
678  return Punti[n];
679 }
680 double VarDatFile::pPuntiErr(int n){
681 #ifdef FILE_DEBUG
682  if(n<0 || n>NMax-1){ printf("Wrong row\n");return 0.;}
683  if(IfPuntiAlloc) return 0.;
684 #endif
685  return PuntiErr[n];
686 }
688  return Header;
689 }
691 #ifdef FILE_DEBUG
692  if(IfPuntiAlloc) return 0.;
693 #endif
694  double Min = Punti[0];
695  for(int p=0;p<NMaxPunti;p++)
696  if(Min > Punti[p])
697  Min = Punti[p];
698  return Min;
699 }
701 #ifdef FILE_DEBUG
702  if(IfPuntiAlloc) return 0.;
703 #endif
704  double Max = Punti[0];
705  for(int p=0;p<NMaxPunti;p++)
706  if(Max < Punti[p])
707  Max = Punti[p];
708  return Max;
709 }
711  if(!IfPuntiFree)
712  return;
713  Punti1 = (double *)realloc(Punti1,NMaxPunti*sizeof(double));
714  for(int n=0;n<NMax;n++){
715  Punti1[n] = Punti[n];
716  }
717  sp = Punti1;
718 }
720  for(int c=0;c<NVar;c++){
721  printf("%d ",RefAbsc[c]);
722  }
723  printf("\n--------------\n");
724  for(int r=0;r<NMax;r++){
725  printf("%d) ",r);
726  for(int c=0;c<NVar;c++){
727  if(IsAbscissa(r)) printf("%.5g ",Abscissa(r,c));
728  printf("%.5g ",st[r][c]);
729  }
730  printf("\n");
731  }
732 }
734  for(int i=0;i<NMax;i++){
735  for(int j=i;j>0;j--){
736  if(sp[j] < sp[j-1])
737  for(int n=0;n<NVar;n++){
738  Swap(j,j-1,st[n]);
739  }
740  else
741  break;
742  }
743  }
744 }
745 void VarDatFile::ScriviPunti(char *file){
746  FILE *SALVA;
747  if((SALVA = fopen(file,"w"))==0)
748  printf("Non s'apre %s, Permessi?\n",file);
749  for(int n=0;n<NMaxPunti;n++)
750  fprintf(SALVA,"%lf %lf\n",Punti1[n],Punti[n]);
751  fclose(SALVA);
752 }
753 void VarDatFile::ScriviFile(char *file,int CoordY,int LogLog,int NVisMin,int NVisMax){
754  FILE *SALVA;
755  int CoordX = RefAbsc[CoordY];
756  if((SALVA = fopen(file,"w"))==0)
757  printf("Non s'apre %s, Permessi?\n",file);
758  for(int n=NVisMin;n<NVisMax;n++){
759  if(DIS_IF_TYPE(LogLog,DIS_LOGLOG))
760  fprintf(SALVA,"%lf %lf \n",log10(st[CoordX][n]),log10(st[CoordY][n]));
761  else
762  fprintf(SALVA,"%lf %lf \n",st[CoordX][n],st[CoordY][n]);
763  }
764  fclose(SALVA);
765 }
766 void VarDatFile::ScriviTutto(char *file,int LogLog,int NVisMin,int NVisMax){
767  FILE *SALVA;
768  if((SALVA = fopen(file,"w"))==0)
769  printf("Non s'apre %s, Permessi?\n",file);
770  if(DIS_IF_TYPE(LogLog,DIS_LOGLOG)){
771  for(int n=NVisMin;n<NVisMax;n++){
772  for(int v=0;v<NVar;v++){
773  fprintf(SALVA,"%.4g ",log10(st[v][n]));
774  }
775  fprintf(SALVA,"\n");
776  }
777  }
778  else {
779  for(int n=NVisMin;n<NVisMax;n++){
780  for(int v=0;v<NVar;v++){
781  fprintf(SALVA,"%.4g ",st[v][n]);
782  }
783  fprintf(SALVA,"\n");
784  }
785  }
786  fclose(SALVA);
787 }
788 void VarDatFile::RescaleToBulk(char *FName){
789  double *BulkVal = (double *)calloc(NVar,sizeof(double));
790  double Count = 0;
791  int NCol = 0;
792  for(int v=0;v<NVar;v++){
793  if(IsAbscissa(v)) continue;
794  NCol++;
795  }
796  int NThick = (int)(NMax/(double)NCol);
797  int Nx = NMax;
798  for(int v=0;v<NVar;v++){
799  for(int nx=NMax/2;nx<3*(NMax/4);nx++){
800  if(isnan(st[v][nx]))continue;
801  BulkVal[v] += st[v][nx];
802  Count += 1.;
803  }
804  }
805  for(int v=0;v<NVar;v++){
806  BulkVal[v] /= Count > 0. ? Count/(double)NVar : 1.;
807  BulkVal[v] = fabs(BulkVal[v]) > 0. ? 1./BulkVal[v] : 1.;
808  }
809  FILE *FWrite = fopen(FName,"w");
810  for(int nx=0;nx<NMax;nx++){
811  fprintf(FWrite,"%lf ",Abscissa(1,nx));
812  for(int v=1;v<NVar;v++){
813  fprintf(FWrite,"%lf ",st[v][nx]*BulkVal[v]);
814  }
815  fprintf(FWrite,"\n");
816  }
817  fclose(FWrite);
818  free(BulkVal);
819 }
820 void VarDatFile::ExportTxvl(char *FName,int NElMin,int NElMax){
821  FILE *FOut = fopen(FName,"w");
822  int p=0;
823  pMinMaxGlob(0,NMax);
824  double Dx = 1./(xGlobMax-xGlobMin);
825  Dx = 0.05/1.;
826  double Dz = 1./(GlobMax-GlobMin);
827  fprintf(FOut,"# l(1 1 1) v[%d] d[part] \n",NMax/2);
828  double *Cm = (double *)calloc(NVar,sizeof(double));
829  double CmTot = 0.;
830  double *Bulk = (double *)calloc(NVar,sizeof(double));
831  int NBulk = NElMax-NElMin;
832  for(int v=0;v<NVar;v++){
833  for(int n=0;n<NMax;n++){
834  if(n >= NBulk) Cm[v] += Val(v,n);
835  }
836  }
837  for(int v=0;v<NVar;v++){
838  if(IsAbscissa(v)) continue;
839  Cm[v] /= (double)(NMax-NBulk);
840  CmTot += Cm[v];
841  }
842  CmTot = CmTot/(double)(NVar-1);
843  for(int v=0;v<NVar;v++){
844  Bulk[v] = .1/fabs(Cm[v]-CmTot);
845  }
846  for(int v=0;v<NVar;v++){
847  if(IsAbscissa(v)) continue;
848  double OffSet = .6 - .2*(v-1);
849  for(int n=0;n<NMax;n++){
850  double Zed = (Val(v,n)-Cm[v])*Bulk[v]+OffSet;
851  if(Abscissa(v,n)*Dx > 1.) continue;
852  fprintf(FOut,"{t[%d %d %d] x(%lf %lf %lf)}\n",p++,2,2,Abscissa(v,n)*Dx,.5,Zed);
853  }
854  }
855  free(Cm);
856  free(Bulk);
857  fclose(FOut);
858 }
859 void VarDatFile::TecPlot(char *FName){
860  FILE *TecPlot = fopen(FName,"w");
861  double *BulkVal = (double *)calloc(NVar,sizeof(double));
862  double Count = 0;
863  int NCol = 0;
864  pMinMaxGlob(0,NMax);
865  for(int v=0;v<NVar;v++){
866  if(IsAbscissa(v)) continue;
867  NCol++;
868  }
869  int NThick = (int)(NMax/(double)NCol);
870  int Nx = 2*(int)(NMax/3.);
871  int Ny = Nx;
872  for(int v=0;v<NVar;v++){
873  for(int nx=NMax/2;nx<3*(NMax/4);nx++){
874  if(isnan(st[v][nx]))continue;
875  BulkVal[v] += st[v][nx];
876  Count += 1.;
877  }
878  }
879  for(int v=0;v<NVar;v++){
880  BulkVal[v] /= Count > 0. ? Count/(double)NVar : 1.;
881  printf("%d %lf\n",v,BulkVal[v]);
882  BulkVal[v] = fabs(BulkVal[v]) > 0. ? 1./BulkVal[v] : 1.;
883  }
884  fprintf(TecPlot,"VARIABLES = \"R\", \"Z\", \"percentage\"\n");
885  fprintf(TecPlot,"ZONE J=%d, K=%d, F=POINT\n",Nx,Ny);
886  double Int = .5*(xGlobMax-xGlobMin)/(double)(Ny);
887  for(int nx=0,v=0;nx<Nx;nx++){
888  for(int ny=0;ny<Ny;ny++){
889  if((ny%(NThick/2))==0) v++;
890  if(v >= NVar) v=0;
891  if(IsAbscissa(v)) v++;
892  double z = Val(v,nx)*BulkVal[v];
893  if(isnan(z)) z = 1.;
894  fprintf(TecPlot,"%lf %lf %lf\n",Abscissa(v,nx),Int*ny,z);
895  }
896  }
897  fclose(TecPlot);
898  free(BulkVal);
899 }
901  if(IfPuntiAlloc){
902  Punti = (double *)calloc(NMaxPunti,sizeof(*Punti));
903  if( Punti == NULL){printf("Punti non s'alloca\n");return ;}
904  Punti1 = (double *)calloc(NMaxPunti,sizeof(*Punti));
905  if( Punti1 == NULL){printf("Punti non s'alloca\n");return ;}
906  PuntiErr = (double *)calloc(NMaxPunti,sizeof(*Punti));
907  if( PuntiErr == NULL){printf("Punti non s'alloca\n");return ;}
908  IfPuntiAlloc = 0;
909  IfPuntiFree = 0;
910  }
911 }
913  RefAbsc[v] = NVar;
914 }
916  for(int v=0;v<NVar;v++){
917  RefAbsc[v] = NVar;
918  }
919 }
920 void VarDatFile::ImpCoordX(int vSet,int vAbs){
921  if(vAbs > NVar) return;
922  if(IsAbscissa(vSet)) return;
923  // one set refers to the sequence
924  if(NVar == 1) RefAbsc[vSet] = NVar;
925  // set to the sequence set
926  else if(vAbs == REF_SEQ) RefAbsc[vSet] = NVar;
927  else RefAbsc[vSet] = vAbs;
928 }
929 void VarDatFile::ImpCoordX(int vAbs){
930  if(vAbs > NVar || vAbs < REF_ASC) return;
931  // one set refers to the sequence
932  if(NVar == 1){ RefAbsc[0] = NVar;return;}
933  for(int v=0;v<NVar;v++){
934  if(vAbs == REF_SEQ) RefAbsc[v] = NVar;
935  else RefAbsc[v] = vAbs;
936  }
937 }
938 void VarDatFile::ImpCoordY(int Ext){
939  if(Ext < NVar && Ext >= 0){
940  sp = st[Ext];
941  }
942 }
944  if(IfPuntiFree){
945  free(Punti);
946  IfPuntiAlloc = 1;
947  }
948 }
949 double VarDatFile::pMaxGlob(int NVisMin,int NVisMax){
950  double Resp = st[0][0];
951  // set the initial value
952  for(int v=0;v<NVar;v++){
953  if(IsAbscissa(v))continue;
954  Resp = st[v][NVisMin];
955  }
956  for(int v=0;v<NVar;v++){
957  if(IsAbscissa(v))continue;
958  for(int n=NVisMin;n<NVisMax;n++){
959  if(n > pNRow(v)) continue;
960  if(isnan(st[v][n]))continue;
961  if(Resp < st[v][n])
962  Resp = st[v][n];
963  }
964  }
965  GlobMax = Resp;
966  return Resp;
967 }
968 double VarDatFile::pMinGlob(int NVisMin,int NVisMax){
969  double Resp = st[0][0];
970  // set the initial value
971  for(int v=0;v<NVar;v++){
972  if(IsAbscissa(v))continue;
973  Resp = st[v][NVisMin];
974  }
975  for(int v=0;v<NVar;v++){
976  if(IsAbscissa(v))continue;
977  for(int n=NVisMin;n<NVisMax;n++){
978  if(n > pNRow(v)) continue;
979  if(isnan(st[v][n])) continue;
980  if(Resp > st[v][n])
981  Resp = st[v][n];
982  }
983  }
984  return Resp;
985 }
986 void VarDatFile::pMinMaxGlob(int NVisMin,int NVisMax){
987  double Border[4];
988  // set the initial value
989  for(int v=0;v<NVar;v++){
990  if(!IsAbscissa(v)){
991  Border[0] = Abscissa(v,NVisMin);
992  Border[1] = Abscissa(v,NVisMin);
993  Border[2] = st[v][NVisMin];
994  Border[3] = st[v][NVisMin];
995  break;
996  }
997  }
998  // find the borders
999  for(int v=0;v<NVar;v++){
1000  if(IsAbscissa(v)) continue;
1001  for(int n=NVisMin;n<NVisMax;n++){
1002  if(n >= pNRow(v)) continue;
1003  if(isnan(st[v][n])) continue;
1004  if(Border[0] > Abscissa(v,n)) Border[0] = Abscissa(v,n);
1005  if(Border[1] < Abscissa(v,n)) Border[1] = Abscissa(v,n);
1006  if(Border[2] > st[v][n]) Border[2] = st[v][n];
1007  if(Border[3] < st[v][n]) Border[3] = st[v][n];
1008  }
1009  }
1010  xGlobMin = Border[0];
1011  xGlobMax = Border[1];
1012  GlobMin = Border[2];
1013  GlobMax = Border[3];
1014 }
1015 double VarDatFile::pxMaxGlob(int NVisMin,int NVisMax){
1016  double Resp = st[0][NVisMin];
1017  // set the initial value
1018  for(int v=0;v<NVar;v++){
1019  if(RefAbsc[v] == NVar) return NVisMin;
1020  if(IsAbscissa(v)){
1021  Resp = st[v][NVisMin];
1022  break;
1023  }
1024  }
1025  for(int v=0;v<NVar;v++){
1026  if(!IsAbscissa(v))continue;
1027  for(int n=NVisMin;n<NVisMax;n++){
1028  if(n > pNRow(v)) continue;
1029  if(isnan(st[v][n]))continue;
1030  if(isinf(st[v][n]))continue;
1031  if(Resp < st[v][n])
1032  Resp = st[v][n];
1033  }
1034  }
1035  xGlobMax = Resp;
1036  printf("%lf\n",Resp);
1037  return Resp;
1038 }
1039 double VarDatFile::pxMinGlob(int NVisMin,int NVisMax){
1040  double Resp = st[0][NVisMin];
1041  // set the initial value
1042  for(int v=0;v<NVar;v++){
1043  if(IsAbscissa(v)){
1044  Resp = st[v][NVisMin];
1045  break;
1046  }
1047  }
1048  for(int v=0;v<NVar;v++){
1049  if(!IsAbscissa(v)) continue;
1050  for(int n=NVisMin;n<NVisMax;n++){
1051  if(n >= pNRow(v)) continue;
1052  if(Resp > st[v][n]){
1053  Resp = st[v][n];
1054  }
1055  }
1056  }
1057  xGlobMin = Resp;
1058  return Resp;
1059 }
1060 double VarDatFile::pMaxGlobLog(int NVisMin,int NVisMax){
1061  double Resp = st[0][NVisMin];
1062  int IfContinue = 1;
1063  // set the initial value
1064  for(int v=0;v<NVar;v++){
1065  if(IsAbscissa(v)) continue;
1066  for(int n=0;n<NMax;n++){
1067  if(st[v][n] <= 0.) continue;
1068  Resp = st[v][n];
1069  IfContinue = 0;
1070  break;
1071  }
1072  if(IfContinue) break;
1073  }
1074  for(int v=0;v<NVar;v++){
1075  if(IsAbscissa(v)) continue;
1076  for(int n=NVisMin;n<NVisMax;n++){
1077  if(st[v][n] <= 0.) continue;
1078  if(n >= pNRow(v)) continue;
1079  if(Resp < st[v][n]) Resp = st[v][n];
1080  }
1081  }
1082  return log10(Resp > 0. ? Resp : 1.);
1083 }
1084 double VarDatFile::pMinGlobLog(int NVisMin,int NVisMax){
1085  double Resp = st[0][NVisMin];
1086  int IfContinue = 1;
1087  // set the initial value
1088  for(int v=0;v<NVar;v++){
1089  if(IsAbscissa(v)) continue;
1090  for(int n=0;n<NMax;n++){
1091  if(st[v][n] <= 0.) continue;
1092  Resp = st[v][n];
1093  IfContinue = 0;
1094  break;
1095  }
1096  if(!IfContinue) break;
1097  }
1098  for(int v=0;v<NVar;v++){
1099  if(IsAbscissa(v)) continue;
1100  for(int n=NVisMin;n<NVisMax;n++){
1101  if(st[v][n] <= 0.) continue;
1102  if(n > pNRow(v)) continue;
1103  if(Resp > st[v][n]) Resp = st[v][n];
1104  }
1105  }
1106  return log10(Resp > 0. ? Resp : 1.);
1107 }
1108 double VarDatFile::pMax(int CoordY,int NVisMin,int NVisMax){
1109  double Resp = st[CoordY][NVisMin];
1110  for(int n=NVisMin;n<NVisMax;n++){
1111  if(Resp < st[CoordY][n])
1112  Resp = st[CoordY][n];
1113  }
1114  return Resp;
1115 }
1116 double VarDatFile::pMin(int CoordY,int NVisMin,int NVisMax){
1117  double Resp = st[CoordY][NVisMin];
1118  for(int n=NVisMin;n<NVisMax;n++){
1119  if(Resp > st[CoordY][n])
1120  Resp = st[CoordY][n];
1121  }
1122  return Resp;
1123 }
1124 double VarDatFile::pMaxLog(int CoordY,int NVisMin,int NVisMax){
1125  double Resp = st[CoordY][NVisMin];
1126  for(int n=NVisMin;n<NVisMax;n++){
1127  if(st[CoordY][n] <= 0.) continue;
1128  if(Resp < st[CoordY][n])
1129  Resp = st[CoordY][n];
1130  }
1131  return log10(Resp > 0. ? Resp : 1.);
1132 }
1133 double VarDatFile::pMinLog(int CoordY,int NVisMin,int NVisMax){
1134  double Resp = 0.;
1135  for(int n=NVisMin;n<NVisMax;n++){
1136  if(st[CoordY][n] <= 0.) continue;
1137  Resp = st[CoordY][n];
1138  break;
1139  }
1140  for(int n=NVisMin;n<NVisMax;n++){
1141  if(st[CoordY][n] <= 0.) continue;
1142  if(Resp > st[CoordY][n])
1143  Resp = st[CoordY][n];
1144  }
1145  return log10(Resp > 0. ? Resp : 1.);
1146 }
1147 void VarDatFile::setXFormula(char *str){
1148  strcpy(XFormula,str);
1149 }
1150 void VarDatFile::setYFormula(char *str){
1151  strcpy(YFormula,str);
1152 }
1154  double Temp = 0.;
1155  for(int n=0;n<NMax/2;n++){
1156  for(int v=0;v<NVar;v++){
1157  Temp = st[v][n];
1158  st[v][n] = st[v][NMax-n-1];
1159  st[v][NMax-n-1] = Temp;
1160  }
1161  }
1162 }
1163 int VarDatFile::Smooth(double Fact,int CoordY,int NVisMin,int NVisMax){
1164  int NOrder = 3+1;
1165  //still not working for Fact != 1.
1166  Fact = 1.;
1167  int NOut = (int)(NMax*Fact);
1168  NMaxPunti = NOut;
1169  int NSmooth = 2;
1170  double *sw = (double *)calloc(NOut,sizeof(double));
1171  pMinMaxGlob(NVisMin,NVisMax);
1172  PuntiAlloc();
1173  double Max=st[CoordY][0];
1174  double Min=st[CoordY][0];
1175  for(int n=0;n<NMax;n++){
1176  if(Max < st[CoordY][n]) Max = st[CoordY][n];
1177  if(Min > st[CoordY][n]) Min = st[CoordY][n];
1178  }
1179  double DeltaIn=(Max-Min)/(double)(NMax-1);
1180  double DeltaOut=(Max-Min)/(double)(NOut-1);
1181  double *dArray = (double *)calloc(NMax+2*NOrder+2,sizeof(double));
1182  int CoordX = RefAbsc[CoordY];
1183  for(int vi=0;vi<NMax;vi++){
1184  Punti1[vi] = st[CoordX][vi];
1185  }
1186  for(int vi=0;vi<=NMax+2*NOrder;vi++){
1187  if(vi<NOrder){
1188  dArray[vi] = Min;
1189  }
1190  else if(vi > NMax){
1191  dArray[vi] = (vi-NOrder+2)*DeltaIn+Min;
1192  }
1193  else {
1194  dArray[vi] = (vi-NOrder+1)*DeltaIn+Min;
1195  }
1196  }
1197  Punti[0] = st[CoordY][0];
1198  Punti[NOut-1] = st[CoordY][NMax-1];
1199  for(int vo=1;vo<NOut-1;vo++){
1200  Punti[vo] = 0.;
1201  double x = DeltaOut*vo+Min;
1202  for(int vi=vo-1,vn=0;vi<vo+NOrder+1;vi++){
1203  vn = vi;
1204  if(vi < 0){
1205  vn = NMax + vi;
1206  }
1207  if(vi >= NMax){
1208  vn = vi - NMax;
1209  }
1210  double Blendx = Blend(dArray,x,vn,NOrder);
1211  Punti[vo] += Blendx*st[CoordY][vn];
1212  }
1213  }
1214  free(dArray);
1215  return NOut;
1216 }
1217 void VarDatFile::SmoothGauss(double Fact,int CoordY,int NVisMin,int NVisMax){
1218  //still not working for Fact != 1.
1219  Fact = 1.;
1220  int NOut = (int)(NMax*Fact);
1221  NMaxPunti = NOut;
1222  pMinMaxGlob(NVisMin,NVisMax);
1223  PuntiAlloc();
1224  int CoordX = RefAbsc[CoordY];
1225  for(int n=0;n<NMax;n++){
1226  Punti[n] = st[CoordY][n];
1227  Punti1[n] = st[CoordX][n];
1228  }
1229  Matrice Mask(5);
1230  Mask.FillGaussian(.5,3.);
1231  Mask.Print();
1232  int NDim = 1;
1233  int IfMinImConv = 0;
1234  for(int v=0;v<NVar;v++){
1235  if(IsAbscissa(v)) continue;
1236  Mask.ConvoluteMatrix(st[v],NVisMax-NVisMin,NDim,IfMinImConv);
1237  }
1238 }
1240  PuntiAlloc();
1241  SigErr(NVar < 8,"Two files are with the coordinate positions are expected\n");
1242  for(int n=0;n<NMax;n++){
1243  if(n > pNRow(0)) continue;
1244  if(n > pNRow(1)) continue;
1245  double Dist = 0.;
1246  for(int d=0;d<3;d++){
1247  Dist += SQR(st[1+d][n] - st[5+d][n]);
1248  }
1249  Dist = sqrt(Dist);
1250  Punti[n] = Dist;
1251  Punti1[n] = (double)n;
1252  }
1253 }
void Sort()
Sort with respect to a coordinate.
Definition: VarDatFile.cpp:733
double pPunti(int n)
Value of the elaborated array at position.
Definition: VarDatFile.cpp:673
int SpettroSegnale(int NElMin, int NElMax)
Calculate the spectrum.
Definition: VarDatFile.cpp:388
int pNRow(int CoordY)
Print the maximum number of data for the column.
Definition: VarDatFile.cpp:664
void ScriviPunti(char *file)
Writes the content of the elaborated array.
Definition: VarDatFile.cpp:745
double pMinLog(int CoordY, int NVisMin, int NVisMax)
Print the minimum of the column.
void SommaSegnali()
Sums all the yCoordinates.
Definition: VarDatFile.cpp:441
void Radice(double *st, double *sw, int N)
Compute the root of the signal.
VarDatFile(char *file, int NBin)
Moltiplication factor for a scaled set (MediaMob)
int ElabSegnale(int NElMin, int NElMax)
Do a generic elaboration.
Definition: VarDatFile.cpp:376
void DerO4(double *st, double *sw, int NMass)
Derivate O(4) of.
int FileInfo(FILE *InFIle, int *NCol)
Reads information contained in the file.
Definition: VarDatFile.cpp:265
double Integrazione(double *Punti, double *sw, int NMass)
Integral of.
void AverageOrdinate(int ElMin, int ElMax, double *Distr, double *xBound)
Average of all ordinate.
Definition: VarDatFile.cpp:325
double pMinGlobLog(int NVisMin, int NVisMax)
Print the minimum of all sets.
void Print()
Prints the content in memory.
Definition: VarDatFile.cpp:719
Parabolas coefficients.
MOMENTI InterGaussSegnale(int CoordY, int NElMin, int NElMax, int LogLog)
Computes a Gaussian fit.
Definition: VarDatFile.cpp:536
double pPuntiErr(int n)
Value of the error array at postion.
Definition: VarDatFile.cpp:680
PARABOLA MinimoParabola(double a, double b, double *Px, double *Py, int NMass)
Minimum of the Parabola between.
int AutocorSegnale(int NElMin, int NElMax)
Autocorrelation of the signal.
Definition: VarDatFile.cpp:382
RETTA InterRettSegnale(int CoordY, int NElMin, int NElMax, int LogLog)
Computes a liner fit.
Definition: VarDatFile.cpp:500
double pMinGlob(int NVisMin, int NVisMax)
Print the minimum of all sets.
Definition: VarDatFile.cpp:968
void ElabSt(double *st, double *sw, int NMass)
Pointer to a function which operates on.
Definition: Matematica.h:130
void Punta(int n)
Points to a different column.
Definition: VarDatFile.cpp:638
void SpeLine(int ElMin, int ElMax, int NBin, double *Spe)
Spectrum of a sequence of lines.
Definition: VarDatFile.cpp:394
MOMENTI Distribuzione(const double *st, int NMass)
Moments of a signal.
int WeightHistoSign(int NHisto)
Weighted histogram analysis.
Definition: VarDatFile.cpp:578
MOMENTI WeightAverage(const double *sx, const double *sy, int NMax)
Calculate the weighted average.
double * sp
Points to a column of st.
Definition: VarDatFile.h:291
void ConvoluteMatrix(double *Plot, int NGrid, int NDim, int IfMinImConv)
Convolute with a matrix.
double PuntiMax()
Print the maximum of.
Definition: VarDatFile.cpp:700
double pMaxGlob(int NVisMin, int NVisMax)
Print the maximum of all sets.
Definition: VarDatFile.cpp:949
MOMENTI WeightAverageSet(int CoordY, int ElMin, int ElMax)
Weighted distribution.
Definition: VarDatFile.cpp:371
double pMax(int CoordY, int NVisMin, int NVisMax)
Print the maximum of the column.
char * PrintHeader()
Print the header.
Definition: VarDatFile.cpp:687
void PuntaInt(double *sp)
Point the internal pointer to an external memory.
Definition: VarDatFile.cpp:648
Linear interpolation.
int ReadLine(char *cLine, double *Value)
Reads a single line.
Definition: VarDatFile.cpp:292
double PuntiMin()
Print the minimum of.
Definition: VarDatFile.cpp:690
Moments of a distribution.
RETTA InterExp(double *Px, double *Py, int NMass)
Exponential interpolation.
void ImpCoordY(int Ext)
Set the column for the y array.
Definition: VarDatFile.cpp:938
void VarieSegnale()
Points the function Elab to the square gradient, probably not working.
Definition: VarDatFile.h:154
void WeightHisto(double **hist, double *Border, int NBin, int NHisto, double tolerance, double *OrPos, double *kSpring)
Weighted histogram analysis.
void DoubleDistFluct()
Distribution of distances.
double pMaxLog(int CoordY, int NVisMin, int NVisMax)
Print the maximum of the column.
MOMENTI DistrErr(const double *st, int NMass, double *Intervalli, double *Err, int Valori, double *Confine, int IfNorm)
Moments and histogram of a signal between two values.
void ImpSequence()
Set the natural sequence as abscissa for all sets.
Definition: VarDatFile.cpp:915
PARABOLA ParabolaSegnale(int CoordY, int NElMin, int NElMax, int LogLog)
Computes a parabolic fit.
Definition: VarDatFile.cpp:541
double pMaxGlobLog(int NVisMin, int NVisMax)
Print the maximum of all sets.
int NormalizeArea(double *st, int NMass)
Normalize.
void Swap(int i, int j, double *Sign)
Swap to indices.
void setXFormula(char *str)
Set the value of XFormula.
bool RadiceSegnale()
Transforms the signal into its square root.
Definition: VarDatFile.cpp:422
void DistrSample(double *Px, double *Py, int NMax, double **Distr, int NBin, const int NSample, int IfNorm, double *xBound)
Compare the distribution of a sample of data.
void DistrSignSample(int ElMin, int ElMax, double **Distr, int NSample, int IfNorm, double *xBound)
Distributions of data organized in different samples.
Definition: VarDatFile.cpp:365
double IntSegnale()
Numerical integration of the signal.
Definition: VarDatFile.cpp:427
~VarDatFile()
Freeing.
Definition: VarDatFile.cpp:160
void ImpCoordX(int vAbs)
Set the columns for the x array.
Definition: VarDatFile.cpp:929
MOMENTI DistribuzioneGauss(const double *st, int NMass, double *Intervalli, double *dInt, int Valori, int IfNorm)
Look for the Gaussian distribution.
int CorrelaDuePunti(double *st, int NMass, double *sw, int Punti)
Two points correlation.
void RescaleToBulk(char *FName)
Rescale to bulk.
Definition: VarDatFile.cpp:788
MOMENTI DistrExpSegnale(int NElMin, int NElMax, int IfNorm)
Exponential distribution of a signal.
Definition: VarDatFile.cpp:352
void FillGaussian(double Sigma, double CutOff)
Fill the entries for the Gauss blur.
MOMENTI DistrGaussSegnale(int ElMin, int ElMax, int IfNorm)
Tests a gaussian distribution of the signal.
Definition: VarDatFile.cpp:368
int NBin
Number of point of the distribution.
Definition: VarDatFile.h:201
void Reverse()
Reverse the sets.
void AutosimilaritaSegnale(int)
Selfsimilarity.
Definition: VarDatFile.cpp:626
double Val(int CoordY, int n)
Value at the position.
Definition: VarDatFile.cpp:657
int IsAbscissa(int Col)
If the column is an ascissa.
Definition: VarDatFile.h:256
void ScriviFile(char *file, int CoordY, int LogLog, int NVisMin, int NVisMax)
Writes the content of the pointed vector.
Definition: VarDatFile.cpp:753
Matrice computes the algebric operations on matrices.
void ExportTxvl(char *FName, int NElMin, int NElMax)
Export in the txvl file format.
Definition: VarDatFile.cpp:820
void setYFormula(char *str)
Set the value of YFormula.
MOMENTI InterGauss(double *Px, double *Py, int NMass)
Gaussian interpolation.
void SmoothGauss(double Fact, int CoordY, int NVisMin, int NVisMax)
Smooth the line.
int NormalizzaInter()
Normalize the intervals.
Definition: VarDatFile.cpp:415
void CambiaNBin(int)
Reallocate the pointer dInter dInter1.
Definition: VarDatFile.cpp:631
double pxMinGlob(int NVisMin, int NVisMax)
Print the abscissa minimum of all sets.
int CorrelaADuePunti(int dist)
To point correlation at a distance dist.
Definition: VarDatFile.cpp:621
int Smooth(double Fact, int CoordY, int NVisMin, int NVisMax)
Smooth the line.
void TecPlot(char *FName)
Export a contour plot.
Definition: VarDatFile.cpp:859
double pxMaxGlob(int NVisMin, int NVisMax)
Print the abscissa maximum of all sets.
double SumSegnale(int CoordY, int NElMin, int NElMax)
Sum the values between ElMin and ElMax.
Definition: VarDatFile.cpp:431
void CambiaPunti()
Copies Punti in Punti1 to store the information of the already elaborated array, to be fixed...
Definition: VarDatFile.cpp:710
MOMENTI DistrLogSegnale(int NElMin, int NElMax, int IfNorm)
Logarithmic distribution of a signal.
Definition: VarDatFile.cpp:345
int Aggiungi(char *file)
Add the content of the file into the memory.
Definition: VarDatFile.cpp:189
void pMinMaxGlob(int NVisMin, int NVisMax)
Find the borders globally.
Definition: VarDatFile.cpp:986
void Autocor(bool *st, double *sAuto, int N)
Compute the autocorrelation of a boolean signal.
void PuntiFree()
Free Punti if it is allocated.
Definition: VarDatFile.cpp:943
double Blend(const double *dPoint, double x, int nPoint, int nOrder)
For the BSpline.
double Abscissa(int CoordY, int n)
Value of the Abscissa at position.
Definition: VarDatFile.cpp:667
int NormalizzaSegnale(int NElMin, int NElMax)
Normalize the signal.
Definition: VarDatFile.cpp:418
RETTA InterExpSegnale(int CoordY, int NElMin, int NElMax, int LogLog)
Computes a exponential fit.
Definition: VarDatFile.cpp:530
void Print()
Print the entries.
int Normalizza(double *st, int NMass)
Normalize.
double pMin(int CoordY, int NVisMin, int NVisMax)
Print the minimum of the column.
MOMENTI DistrSignErr(int NElMin, int NElMax, double *Border, int IfNorm)
Distribution of a signal with error.
Definition: VarDatFile.cpp:362
void Spettro(double *st, double *sw, int NMass)
Compute the spectrum.
MOMENTI DistrSegnale(int NElMin, int NElMax, int IfNorm)
Distribution of a signal.
Definition: VarDatFile.cpp:342
void Autosimilarita(double *st, int NMass, double *sw, int Valori)
Self similarity.
void PuntiAlloc()
Allocates.
Definition: VarDatFile.cpp:900
void ScriviTutto(char *file, int LogLog, int NVisMin, int NVisMax)
Writes all the content in memory.
Definition: VarDatFile.cpp:766
void MediaMobile(double *st, int NMass, double *sw, int Parti)
Running average.
RETTA InterRett(double *Px, double *Py, int NMass)
Linear interpolation.
int MediaMobSegnale(int)
Running average.
Definition: VarDatFile.cpp:573