Allink
v0.1
|
00001 #include "../include/VarDatFile.h" 00002 #include <stdarg.h> 00003 00004 VarDatFile::VarDatFile(int ExtNMax,int ExtNVar,int ExtNBin){ 00005 Init(); 00006 NMax = ExtNMax; 00007 NMaxPunti = NMax; 00008 NVar = ExtNVar; 00009 NBin = ExtNBin; 00010 Allocate(); 00011 sp = st[0]; 00012 } 00013 VarDatFile::VarDatFile(double **ExtSt,int ExtNMax,int ExtNVar,int ExtNBin){ 00014 Init(); 00015 NMax = ExtNMax; 00016 NMaxPunti = NMax; 00017 NVar = ExtNVar; 00018 NBin = ExtNBin; 00019 Allocate(); 00020 st = ExtSt; 00021 sp = st[0]; 00022 } 00023 // VarDatFile::VarDatFile(char *file,int NNBin){ 00024 // NMax = 0; 00025 // NVisMin = 0; 00026 // NVar=0; 00027 // NBin = NNBin; 00028 // FILE *InFile; 00029 // if((InFile = fopen(file,"r"))==0){ 00030 // printf("Non s'apre %s\n",file); 00031 // exit(0); 00032 // } 00033 // Init(); 00034 // int NCol = 0; 00035 // NVisMax = NMax = FileInfo(InFile,&NCol); 00036 // NVar = NCol; 00037 // Allocate(); 00038 // char cLine[STRLEN]; 00039 // double *dLine = (double *)calloc(NVar,sizeof(double)); 00040 // for(int v=0;v<NVar;v++) SetNMax[v] = NMax; 00041 // for(int l=0; l<NMax;l++){ 00042 // fgets(cLine,512,InFile); 00043 // if(ReadLine(cLine,dLine)){l--;continue;} 00044 // for(int v=0;v<NVar;v++){ 00045 // st[v][l] = dLine[v]; 00046 // if(l==0){ 00047 // sMin[v] = st[v][l]; 00048 // sMax[v] = st[v][l]; 00049 // } 00050 // if(sMin[v] > st[v][l]) 00051 // sMin[v] = st[v][l]; 00052 // if(sMax[v] < st[v][l]) 00053 // sMax[v] = st[v][l]; 00054 // } 00055 // } 00056 // free(dLine); 00057 // if(NVar > 1){ 00058 // CoordY = 1; 00059 // CoordX = 0; 00060 // RefAbsc[CoordX] = REF_ASC; 00061 // for(int v=1;v<NVar;v++) 00062 // RefAbsc[v] = CoordX; 00063 // } 00064 // else{ 00065 // CoordY = 0; 00066 // RefAbsc[CoordY] = REF_SEQ; 00067 // } 00068 // fclose(InFile); 00069 // sp = st[0]; 00070 // } 00071 VarDatFile::VarDatFile(char **FileList,int *Pos,int NFile,int NNBin){ 00072 NMax=0; 00073 NVar=0; 00074 Init(); 00075 NBin = NNBin; 00076 int *NMaxFile = (int *)calloc(NFile,sizeof(int)); 00077 int *NColFile = (int *)calloc(NFile+1,sizeof(int)); 00078 NColFile[0] = 0; 00079 for(int f=0;f<NFile;f++){ 00080 FILE *FileIn = fopen(FileList[Pos[f]],"r"); 00081 if(FileIn == 0){ 00082 printf("File %s not found\n",FileList[Pos[f]]); 00083 return; 00084 } 00085 int NCol = 0; 00086 NMaxFile[f] = FileInfo(FileIn,&NCol); 00087 NColFile[f+1] = NCol + NColFile[f]; 00088 if(NMaxFile[f] > NMax) NMax = NMaxFile[f]; 00089 NMaxPunti = NMax; 00090 NVar += NCol; 00091 fclose(FileIn); 00092 } 00093 Allocate(); 00094 char cLine[STRLEN]; 00095 double *dLine = (double *)calloc(NVar,sizeof(double)); 00096 for(int f=0;f<NFile;f++){ 00097 for(int v=NColFile[f];v<NColFile[f+1];v++) 00098 SetNMax[v] = NMaxFile[f]; 00099 FILE *FileIn = fopen(FileList[Pos[f]],"r"); 00100 for(int l=0;l<NMaxFile[f];l++){ 00101 if(!fgets(cLine,512,FileIn))break; 00102 if(ReadLine(cLine,dLine)){l--;continue;} 00103 for(int v=NColFile[f],vv=0;v<NColFile[f+1];v++,vv++){ 00104 st[v][l] = dLine[vv]; 00105 } 00106 } 00107 fclose(FileIn); 00108 if(NColFile[f+1]-NColFile[f] == 1){ 00109 RefAbsc[NColFile[f]] = NVar; 00110 } 00111 else { 00112 for(int v=NColFile[f];v<NColFile[f+1];v++){ 00113 RefAbsc[v] = NColFile[f]; 00114 } 00115 } 00116 } 00117 if(NVar == 1) Punta(0); 00118 else Punta(1); 00119 free(dLine); 00120 free(NMaxFile); 00121 free(NColFile); 00122 } 00123 void VarDatFile::Allocate(){ 00124 dInter = (double *)calloc(NBin,sizeof(*dInter)); 00125 dError = (double *)calloc(NBin,sizeof(*dError)); 00126 dInter1 = (double *)calloc(NBin,sizeof(*dInter)); 00127 sp = (double *)malloc(sizeof(double)); 00128 sType = (int *)calloc(NVar,sizeof(int)); 00129 SetNMax = (int *)calloc(NVar,sizeof(int)); 00130 sColor = (int *)calloc(NVar,sizeof(int)); 00131 sMin = (double *)calloc(NVar,sizeof(double)); 00132 sMax = (double *)calloc(NVar,sizeof(double)); 00133 sColor = (int *)calloc(NVar,sizeof(int)); 00134 RefAbsc = (int *)calloc(NVar,sizeof(int)); 00135 st = (double **)calloc(NVar+1,sizeof(double)); 00136 if(st == NULL){ 00137 printf("Could not allocate st \n"); 00138 exit(0); 00139 } 00140 //if( !st){printf("st non s'alloca\n");return ;} 00141 for(int v=0;v<NVar+1;v++){ 00142 st[v] = (double *)calloc(NMax,sizeof(double)); 00143 if(st[v] == NULL){ 00144 printf("Could not allocate st[%d] \n",v); 00145 exit(0); 00146 } 00147 //if( !st[v]){printf("st non s'alloca\n");return ;} 00148 } 00149 for(int n=0;n<NMax;n++){ 00150 st[NVar][n] = (double)n; 00151 } 00152 //sc = NULL; 00153 //sc = (char **)calloc(NVar,sizeof(char)); 00154 //if(!sc){printf("sc non s'alloca\n");return ;} 00155 for(int v=0;v<NVar;v++){ 00156 //sc[v] = (char *)calloc(120,sizeof(char)); 00157 //if(!sc[v]){printf("st non s'alloca\n");return ;} 00158 } 00159 } 00160 VarDatFile::~VarDatFile(){ 00161 for(int v=0;v<NVar;v++){ 00162 free(st[v]); 00163 //if(st[v]){printf("st %d is not freed\n",v);} 00164 } 00165 free(st); 00166 //if(st){printf("st is not freed\n");} 00167 for(int v=0;v<NVar;v++){ 00168 //free(sc[v]); 00169 //if(sc[v] != NULL){printf("sc %d is not freed\n",v);} 00170 } 00171 //free(sc);//if(sc != NULL){printf("sc is not freed\n");} 00172 free(sMin); 00173 free(sMax); 00174 free(sType); 00175 free(SetNMax); 00176 free(sColor); 00177 free(RefAbsc); 00178 sp = NULL; 00179 free(sp); 00180 free(dInter); 00181 free(dInter1); 00182 PuntiFree(); 00183 } 00184 void VarDatFile::Init(){ 00185 IfPuntiAlloc = 1; 00186 IfPuntiFree = 0; 00187 } 00188 //FIXME: there is still color, type... to be allocated 00189 int VarDatFile::Aggiungi(char *file){ 00190 FILE *InFile; 00191 if((InFile = fopen(file,"r"))==NULL){ 00192 printf("Non s'apre %s\n",file); 00193 return 1; 00194 } 00195 char cLine[512]; 00196 double **stTemp = (double **)calloc(NVar,sizeof(double)); 00197 if(stTemp == NULL){printf("stTemp non s'alloca\n");return 0;} 00198 for(int v=0;v<NVar;v++){ 00199 stTemp[v] = (double *)calloc(NMax,sizeof(double)); 00200 if( stTemp[v] == NULL){printf("stTemp non s'alloca\n");return 0;} 00201 } 00202 for(int v=0;v<NVar;v++){ 00203 for(int n=0;n<NMax;n++){ 00204 stTemp[v][n] = st[v][n];//sign[v*NMax+n]; 00205 } 00206 } 00207 int NVarOld = NVar; 00208 int NCol = 0; 00209 int nPoint = FileInfo(InFile,&NCol); 00210 NVar += NCol; 00211 if(nPoint > NMax) NMax = nPoint; 00212 NMaxPunti = NMax; 00213 { 00214 for(int v=0;v<NVarOld;v++){ 00215 free(st[v]); 00216 //free(sc[v]); 00217 } 00218 free(st); 00219 //free(sc); 00220 st = (double **)calloc(NVar,sizeof(double)); 00221 if( st == NULL){printf("st non s'alloca\n");return 0;} 00222 for(int v=0;v<NVar;v++){ 00223 st[v] = (double *)calloc(NMax,sizeof(double)); 00224 if( st[v] == NULL){printf("st non s'alloca\n");return 0;} 00225 } 00226 } 00227 // { 00228 // st = (double **)realloc(st,NVar*sizeof(double)); 00229 // for(int v=0;v<NVar;v++){ 00230 // st[v] = (double *)realloc(st[v],NMax*sizeof(double)); 00231 // } 00232 // } 00233 double *dLine = (double *)calloc(NVar,sizeof(double)); 00234 for(int l=0; l<NMax;l++){ 00235 fgets(cLine,512,InFile); 00236 if(ReadLine(cLine,dLine))continue; 00237 for(int v=NVarOld;v<NVar;v++){ 00238 st[v][l] = dLine[v-NVarOld]; 00239 if(sMin[v] > st[v][l]) 00240 sMin[v] = st[v][l]; 00241 if(sMax[v] < st[v][l]) 00242 sMax[v] = st[v][l]; 00243 } 00244 } 00245 GlobMax = sMax[0]; 00246 GlobMin = sMin[0]; 00247 for(int v=0;v<NVar;v++){ 00248 if(GlobMax < sMax[v]) 00249 GlobMax = sMax[v]; 00250 if(GlobMin > sMin[v]) 00251 GlobMin = sMin[v]; 00252 } 00253 for(int n=0;n<NMax;n++) 00254 for(int v=0;v<NVarOld;v++) 00255 st[v][n] = stTemp[v][n]; 00256 for(int v=0;v<NVarOld;v++) 00257 free(stTemp[v]); 00258 free(stTemp); 00259 free(dLine); 00260 fclose(InFile); 00261 PuntiFree(); 00262 //printf("Uscita\n"); 00263 return 0; 00264 } 00265 int VarDatFile::FileInfo(FILE *InFile,int *NCol){ 00266 int nPoint = 0; 00267 char cLine[STRSIZE]; 00268 for(int k=0;!(fgets(cLine,STRSIZE,InFile)==NULL);k++){ 00269 if(k == 0 && cLine[0] == '#'){ 00270 sprintf(Header,"%s",cLine); 00271 continue; 00272 } 00273 int iLen = (int) (strlen(cLine)); 00274 if(cLine[0] != '#' && cLine[0] != '\n') 00275 nPoint++; 00276 for(int i=0,var=1;i<iLen;i++){ 00277 if(cLine[i] == '#'){ 00278 break;//Comment 00279 } 00280 if(cLine[i] == '\n') break; 00281 if(i>0){ 00282 if( (cLine[i-1] == ' ' || cLine[i-1] == '\t' ) && 00283 (cLine[i] != ' ' && cLine[i] != '\t' )) 00284 var++; 00285 } 00286 if(*NCol < var) *NCol = var; 00287 } 00288 } 00289 rewind(InFile); 00290 return nPoint; 00291 } 00292 int VarDatFile::ReadLine(char *cLine,double *sLine){ 00293 int iLen = (int) (strlen(cLine)); 00294 if(cLine[0] == ' ' || cLine[0] == '\t'){ 00295 for(int i=0;i<iLen;i++){ 00296 if(cLine[i] != ' ' && cLine[i] != '\t'){ 00297 cLine += i; 00298 break; 00299 } 00300 } 00301 } 00302 sscanf(cLine,"%lf",sLine); 00303 for(int i=0,v=1;i<iLen;i++){ 00304 if(cLine[i]=='#') return 1; 00305 if(v>=NVar) return 0; 00306 if(cLine[i]==' ' || cLine[i] =='\n' || cLine[i]=='\t'){ 00307 sscanf(cLine+i,"%lf",sLine+v); 00308 //printf("%d) %d %s %lf\n",v,i,cLine+i,st[v]); 00309 i++; 00310 v++; 00311 } 00312 } 00313 return 0; 00314 } 00315 int VarDatFile::ReadLine(FILE *InFile, const char *Format, ...){ 00316 va_list ap; 00317 int NVariable; 00318 char line[256]; 00319 va_start(ap, Format); 00320 fgets(line, 256, InFile); 00321 NVariable = vsscanf(line, Format, ap); 00322 va_end(ap); 00323 return NVariable; 00324 } 00325 void VarDatFile::AverageOrdinate(int ElMin, int ElMax,double *Distr,double *xBound){ 00326 double *Count = (double *)calloc(NBin,sizeof(double)); 00327 for(int n=0;n<NMax;n++){ 00328 for(int v=0;v<NVar;v++){ 00329 if(IsAbscissa(v)) continue; 00330 if(isnan(st[v][n]))continue; 00331 int bx = (int)((Abscissa(v,n) - xBound[0])*xBound[1]*NBin); 00332 if(bx < 0 || bx >= NBin) continue; 00333 Distr[bx] += st[v][n]; 00334 Count[bx] += 1.; 00335 } 00336 } 00337 for(int bx=0;bx<NBin;bx++){ 00338 Distr[bx] /= Count[bx] > 0. ? Count[bx] : 1.; 00339 } 00340 free(Count); 00341 } 00342 MOMENTI VarDatFile::DistrSegnale(int ElMin, int ElMax,int IfNorm){ 00343 return Distribuzione(sp+ElMin,ElMax-ElMin,dInter,NBin,IfNorm); 00344 } 00345 MOMENTI VarDatFile::DistrLogSegnale(int ElMin, int ElMax,int IfNorm){ 00346 PuntiAlloc(); 00347 for(int n=0;n<NMax;n++){ 00348 Punti[n] = log10(sp[n]); 00349 } 00350 return Distribuzione(Punti+ElMin,ElMax-ElMin,dInter,NBin,IfNorm); 00351 } 00352 MOMENTI VarDatFile::DistrExpSegnale(int ElMin, int ElMax,int IfNorm){ 00353 PuntiAlloc(); 00354 for(int n=0;n<NMax;n++){ 00355 Punti[n] = exp(sp[n]); 00356 } 00357 return Distribuzione(Punti+ElMin,ElMax-ElMin,dInter,NBin,IfNorm); 00358 } 00359 MOMENTI VarDatFile::DistrSegnale(int ElMin, int ElMax,double *Border,int IfNorm){ 00360 return Distribuzione(sp+ElMin,ElMax-ElMin,dInter,NBin,Border,IfNorm); 00361 } 00362 MOMENTI VarDatFile::DistrSignErr(int ElMin, int ElMax,double *Border,int IfNorm){ 00363 return DistrErr(sp+ElMin,ElMax-ElMin,dInter,dError,NBin,Border,IfNorm); 00364 } 00365 void VarDatFile::DistrSignSample(int ElMin, int ElMax,double **Distr,int NSample,int IfNorm,double *xBound){ 00366 DistrSample(st[0]+ElMin,sp+ElMin,ElMax-ElMin,Distr,NBin,NSample,IfNorm,xBound); 00367 } 00368 MOMENTI VarDatFile::DistrGaussSegnale(int ElMin,int ElMax,int IfNorm){ 00369 return DistribuzioneGauss(sp+ElMin,ElMax-ElMin,dInter,dInter1,NBin,IfNorm); 00370 } 00371 MOMENTI VarDatFile::WeightAverageSet(int CoordY,int ElMin, int ElMax){ 00372 int CoordX = RefAbsc[CoordY]; 00373 MOMENTI m1 = WeightAverage(st[CoordX]+ElMin,sp+ElMin,ElMax-ElMin); 00374 return m1; 00375 } 00376 int VarDatFile::ElabSegnale(int ElMin,int ElMax){ 00377 PuntiAlloc(); 00378 // Elabora(sp+ElMin,Punti,ElMax-ElMin); 00379 ElabSt(sp+ElMin,Punti,ElMax-ElMin); 00380 return ElMax-ElMin; 00381 } 00382 int VarDatFile::AutocorSegnale(int ElMin,int ElMax){ 00383 PuntiAlloc(); 00384 Autocor(sp+ElMin,Punti,ElMax-ElMin); 00385 NMaxPunti = NMax/2; 00386 return NMaxPunti; 00387 } 00388 int VarDatFile::SpettroSegnale(int ElMin,int ElMax){ 00389 PuntiAlloc(); 00390 Spettro(sp+ElMin,Punti,ElMax-ElMin); 00391 NMaxPunti = NMax; 00392 return (int)( (NMax)); 00393 } 00394 void VarDatFile::SpeLine(int ElMin,int ElMax,int NBin,double *Spe){ 00395 #ifdef USE_FFTW 00396 double InvNBin = 1./(double)(NBin); 00397 fftw_complex *out = (fftw_complex *)fftw_malloc(NBin*sizeof(fftw_complex)); 00398 fftw_complex *in = (fftw_complex *)fftw_malloc(NBin*sizeof(fftw_complex)); 00399 fftw_plan plan = fftw_plan_dft_1d(NBin,in,out,FFTW_FORWARD,FFTW_ESTIMATE); 00400 fftw_plan plan2 = fftw_plan_dft_1d(NBin,out,in,FFTW_BACKWARD,FFTW_ESTIMATE); 00401 for(int v=0;v<NVar;v++){ 00402 if(IsAbscissa(v))continue; 00403 for(int n=0;n<NBin;n++) in[n][0] = st[v][n]; 00404 fftw_execute(plan); 00405 for(int n=0;n<NBin;n++){ 00406 Spe[n] += SQR(out[n][0]) + SQR(out[n][1]); 00407 } 00408 } 00409 fftw_free(out); 00410 fftw_free(in); 00411 #else 00412 printf("fftw not present\n"); 00413 #endif 00414 } 00415 int VarDatFile::NormalizzaInter(){ 00416 Normalizza(dInter,NBin); 00417 } 00418 int VarDatFile::NormalizzaSegnale(int ElMin,int ElMax){ 00419 int Campioni = NormalizeArea(sp+ElMin,ElMax-ElMin); 00420 return Campioni; 00421 } 00422 bool VarDatFile::RadiceSegnale(){ 00423 PuntiAlloc(); 00424 Radice(sp,Punti,NMax); 00425 return 1; 00426 } 00427 double VarDatFile::IntSegnale(){ 00428 PuntiAlloc(); 00429 return Integrazione(sp,Punti,NMax); 00430 } 00431 double VarDatFile::SumSegnale(int CoordY,int ElMin,int ElMax){ 00432 double Resp = 0.; 00433 int CoordX = RefAbsc[CoordY]; 00434 double Dx = (st[CoordX][ElMax]-st[CoordX][ElMin]); 00435 double NumInv = 1./(double)(ElMax-ElMin); 00436 for(int i=ElMin;i<ElMax;i++){ 00437 Resp += st[CoordY][ElMax]; 00438 } 00439 return Resp*Dx*NumInv; 00440 } 00441 void VarDatFile::SommaSegnali(){ 00442 PuntiAlloc(); 00443 for(int nm=0;nm<NMax;nm++){ 00444 Punti[nm] = 0.; 00445 for(int nv=0;nv<NVar;nv++){ 00446 if(IsAbscissa(nv)) continue; 00447 Punti[nm] += st[nv][nm]; 00448 } 00449 } 00450 } 00451 double VarDatFile::VarieSegnale(int ElMin,int ElMax){ 00452 if(NVar < 2) return 0.; 00453 PuntiAlloc(); 00454 double *temp1 = (double *)malloc(NMax*sizeof(double)); 00455 double *temp2 = (double *)malloc(NMax*sizeof(double)); 00456 double VolA=0.,VolB=0.; 00457 double VolFracA=0.,VolFracB=0.; 00458 double SqrGradCoeff=0.; 00459 for(int n=0;n<NMax;n++){ 00460 temp1[n] = 0.; 00461 temp2[n] = 0.; 00462 } 00463 double Coeff[4] = {1.,0.,0.,1.}; 00464 double MaxA=0.,MaxB=0.; 00465 for(int n=0;n<NMax;n++){ 00466 if(MaxA < st[1][n]) MaxA = st[1][n]; 00467 if(MaxB < st[2][n]) MaxB = st[2][n]; 00468 } 00469 for(int n=0;n<NMax;n++){ 00470 if(st[1][n] > MaxA*.5) 00471 VolA += 1.; 00472 if(st[2][n] > MaxB*.5) 00473 VolB += 1.; 00474 } 00475 VolFracA = VolA / (VolA + VolB); 00476 VolFracB = VolB / (VolA + VolB); 00477 SqrGradCoeff = 19.13/(24.*VolFracA*VolA)+3.04/(24.*VolFracB*VolB); 00478 sp = st[1]; 00479 DerO4(sp+ElMin,temp1,ElMax-ElMin); 00480 sp = st[2]; 00481 DerO4(sp+ElMin,temp2,ElMax-ElMin); 00482 for(int i=0;i<4;i++){ 00483 Coeff[i] *= SqrGradCoeff; 00484 } 00485 for(int n=0;n<NMax;n++){ 00486 Punti[n] = Coeff[0]*temp1[n]*temp1[n]; 00487 Punti[n] += Coeff[1]*temp1[n]*temp2[n]; 00488 Punti[n] += Coeff[2]*temp2[n]*temp1[n]; 00489 Punti[n] += Coeff[3]*temp2[n]*temp2[n]; 00490 Punti[n] /= 2.; 00491 } 00492 double Risp=0.; 00493 for(int n=75;n<125;n++){ 00494 Risp += Punti[n]; 00495 } 00496 free(temp1); 00497 free(temp2); 00498 return Risp; 00499 } 00500 RETTA VarDatFile::InterRettSegnale(int CoordY,int ElMin,int ElMax,int LogLog){ 00501 RETTA r1; 00502 double *Puntix; 00503 double *Puntiy; 00504 int CoordX = RefAbsc[CoordY]; 00505 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){ 00506 Puntix = (double *)calloc(ElMax-ElMin,sizeof(*Puntix)); 00507 for(int i=ElMin;i<ElMax;i++){ 00508 if(st[CoordX][i] > 0.) 00509 Puntix[i-ElMin] = log10(st[CoordX][i]); 00510 } 00511 } 00512 else{ 00513 Puntix = st[CoordX]+ElMin; 00514 } 00515 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00516 Puntiy = (double *)calloc(ElMax-ElMin,sizeof(*Puntiy)); 00517 for(int i=ElMin;i<ElMax;i++){ 00518 if(st[CoordY][i] > 0.) 00519 Puntiy[i-ElMin] = log10(st[CoordY][i]); 00520 } 00521 } 00522 else{ 00523 Puntiy = st[CoordY]+ElMin; 00524 } 00525 r1 = InterRett(Puntix,Puntiy,ElMax-ElMin); 00526 if(DIS_IF_TYPE(LogLog,DIS_LOGX)) free(Puntix); 00527 if(DIS_IF_TYPE(LogLog,DIS_LOGY)) free(Puntiy); 00528 return r1; 00529 } 00530 RETTA VarDatFile::InterExpSegnale(int CoordY,int ElMin,int ElMax,int LogLog){ 00531 RETTA r1; 00532 int CoordX = RefAbsc[CoordY]; 00533 r1 = InterExp(st[CoordX]+ElMin,st[CoordY]+ElMin,ElMax-ElMin); 00534 return r1; 00535 } 00536 MOMENTI VarDatFile::InterGaussSegnale(int CoordY,int ElMin,int ElMax,int LogLog){ 00537 int CoordX = RefAbsc[CoordY]; 00538 MOMENTI m1 = InterGauss(st[CoordX]+ElMin,st[CoordY]+ElMin,ElMax-ElMin); 00539 return m1; 00540 } 00541 PARABOLA VarDatFile::ParabolaSegnale(int CoordY,int ElMin,int ElMax,int LogLog){ 00542 PARABOLA p1; 00543 double *Puntix; 00544 double *Puntiy; 00545 int CoordX = RefAbsc[CoordY]; 00546 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){ 00547 Puntix = (double *)calloc(ElMax-ElMin,sizeof(*Puntix)); 00548 for(int i=ElMin;i<ElMax;i++){ 00549 if(st[CoordX][i] > 0.) 00550 Puntix[i] = log(st[CoordX][i]); 00551 } 00552 } 00553 else{ 00554 Puntix = st[CoordX]; 00555 } 00556 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00557 Puntiy = (double *)calloc(ElMax-ElMin,sizeof(*Puntix)); 00558 for(int i=ElMin;i<ElMax;i++){ 00559 if(st[CoordY][i] > 0.) 00560 Puntiy[i] = log10(st[CoordY][i]); 00561 } 00562 } 00563 else{ 00564 Puntiy = st[CoordY]; 00565 } 00566 p1 = MinimoParabola(Puntix+ElMin,Puntiy+ElMin,ElMax-ElMin); 00567 if(DIS_IF_TYPE(LogLog,DIS_LOGX)) 00568 free(Puntix); 00569 if(DIS_IF_TYPE(LogLog,DIS_LOGY)) 00570 free(Puntiy); 00571 return p1; 00572 } 00573 int VarDatFile::MediaMobSegnale(int n){ 00574 PuntiAlloc(); 00575 NMaxPunti = MediaMobile(sp,NMax,Punti,PuntiErr,n); 00576 return NMaxPunti; 00577 } 00578 int VarDatFile::WeightHistoSign(int NHisto){ 00579 int NBin = NMax; 00580 double **Histo = (double **)calloc(NHisto,sizeof(double)); 00581 for(int h=0;h<NHisto;h++){ 00582 Histo[h] = (double *)calloc(NBin,sizeof(double)); 00583 } 00584 for(int v=0,h=0;v<NVar;v++){ 00585 if(IsAbscissa(v)) continue; 00586 for(int b=0;b<NBin;b++){ 00587 Histo[h][b] = st[v][b]; 00588 } 00589 h++; 00590 } 00592 pMinMaxGlob(0,NBin); 00593 double Border[2] = {xGlobMin,xGlobMax}; 00594 double tolerance = 0.00001; 00595 double *NanoDist = (double *)calloc(NHisto,sizeof(double)); 00596 double *kSpring = (double *)calloc(NHisto,sizeof(double)); 00597 for(int h=0;h<NHisto;h++){ 00598 kSpring[h] = Histo[h][NBin-2]; 00599 NanoDist[h] = Histo[h][NBin-1]; 00600 } 00601 // NanoDist[1]=3.5; 00602 // NanoDist[2]=4.0; 00603 // NanoDist[3]=5.07; 00604 // NanoDist[4]=5.6; 00605 // NanoDist[5]=6.4; 00606 // NanoDist[6]=7.2; 00607 // NanoDist[7]=8; 00608 // NanoDist[8]=8.8; 00609 // NanoDist[9]=9.6; 00610 // NanoDist[10]=10.4; 00611 // NanoDist[11]=10.76; 00612 // NanoDist[12]=11.56; 00613 // NanoDist[13]=12.8; 00614 WeightHisto(Histo,Border,NBin-2,NHisto,tolerance,NanoDist,kSpring); 00615 for(int h=0;h<NHisto;h++) 00616 free(Histo[h]); 00617 free(Histo); 00618 free(NanoDist); 00619 free(kSpring); 00620 } 00621 int VarDatFile::CorrelaADuePunti(int n){ 00622 PuntiAlloc(); 00623 NMaxPunti = CorrelaDuePunti(sp,NMax,Punti,n); 00624 return NMaxPunti; 00625 } 00626 void VarDatFile::AutosimilaritaSegnale(int n){ 00627 PuntiAlloc(); 00628 Autosimilarita(sp,NMax,Punti,n); 00629 NMaxPunti = NMax; 00630 } 00631 void VarDatFile::CambiaNBin(int n){ 00632 if(n < 0) 00633 return; 00634 NBin = n; 00635 dInter = (double *)realloc(dInter,NBin*sizeof(double)); 00636 dInter1 = (double *)realloc(dInter1,NBin*sizeof(double)); 00637 } 00638 void VarDatFile::Punta(int n){ 00639 if(n < 0 || n > NVar) 00640 return; 00641 sp = st[n]; 00642 } 00643 void VarDatFile::Punta(double *spExt,int n){ 00644 if(n < 0 || n >= NVar) 00645 return; 00646 spExt = st[n]; 00647 } 00648 void VarDatFile::PuntaInt(double *spExt){ 00649 sp = spExt; 00650 } 00651 void VarDatFile::Punta(double **ExtSt,int n){ 00652 if(n <0 || n>NVar) 00653 return; 00654 st = ExtSt; 00655 sp = ExtSt[n]; 00656 } 00657 double VarDatFile::Val(int CoordY,int n){ 00658 #ifdef FILE_DEBUG 00659 if(n<0 || n>NMax-1 ){printf("Wrong row\n");return 0.;} 00660 if(CoordY<0 || v>NBin-1){printf("Wrong col\n"); return 0.;} 00661 #endif 00662 return st[CoordY][n]; 00663 } 00664 int VarDatFile::pNRow(int CoordY){ 00665 return SetNMax[CoordY]; 00666 } 00667 double VarDatFile::Abscissa(int CoordY,int n){ 00668 #ifdef FILE_DEBUG 00669 if(CoordY<0 || n>NMax-1){ printf("Wrong row\n");return 0.;} 00670 #endif 00671 return st[RefAbsc[CoordY]][n]; 00672 } 00673 double VarDatFile::pPunti(int n){ 00674 #ifdef FILE_DEBUG 00675 if(n<0 || n>NMax-1){ printf("Wrong row\n");return 0.;} 00676 if(IfPuntiAlloc) return 0.; 00677 #endif 00678 return Punti[n]; 00679 } 00680 double VarDatFile::pPuntiErr(int n){ 00681 #ifdef FILE_DEBUG 00682 if(n<0 || n>NMax-1){ printf("Wrong row\n");return 0.;} 00683 if(IfPuntiAlloc) return 0.; 00684 #endif 00685 return PuntiErr[n]; 00686 } 00687 char *VarDatFile::PrintHeader(){ 00688 return Header; 00689 } 00690 double VarDatFile::PuntiMin(){ 00691 #ifdef FILE_DEBUG 00692 if(IfPuntiAlloc) return 0.; 00693 #endif 00694 double Min = Punti[0]; 00695 for(int p=0;p<NMaxPunti;p++) 00696 if(Min > Punti[p]) 00697 Min = Punti[p]; 00698 return Min; 00699 } 00700 double VarDatFile::PuntiMax(){ 00701 #ifdef FILE_DEBUG 00702 if(IfPuntiAlloc) return 0.; 00703 #endif 00704 double Max = Punti[0]; 00705 for(int p=0;p<NMaxPunti;p++) 00706 if(Max < Punti[p]) 00707 Max = Punti[p]; 00708 return Max; 00709 } 00710 void VarDatFile::CambiaPunti(){ 00711 if(!IfPuntiFree) 00712 return; 00713 Punti1 = (double *)realloc(Punti1,NMaxPunti*sizeof(double)); 00714 for(int n=0;n<NMax;n++){ 00715 Punti1[n] = Punti[n]; 00716 } 00717 sp = Punti1; 00718 } 00719 void VarDatFile::Print(){ 00720 for(int c=0;c<NVar;c++){ 00721 printf("%d ",RefAbsc[c]); 00722 } 00723 printf("\n--------------\n"); 00724 for(int r=0;r<NMax;r++){ 00725 printf("%d) ",r); 00726 for(int c=0;c<NVar;c++){ 00727 if(IsAbscissa(r)) printf("%.5g ",Abscissa(r,c)); 00728 printf("%.5g ",st[r][c]); 00729 } 00730 printf("\n"); 00731 } 00732 } 00733 void VarDatFile::Sort(){ 00734 for(int i=0;i<NMax;i++){ 00735 for(int j=i;j>0;j--){ 00736 if(sp[j] < sp[j-1]) 00737 for(int n=0;n<NVar;n++){ 00738 Swap(j,j-1,st[n]); 00739 } 00740 else 00741 break; 00742 } 00743 } 00744 } 00745 void VarDatFile::ScriviPunti(char *file){ 00746 FILE *SALVA; 00747 if((SALVA = fopen(file,"w"))==0) 00748 printf("Non s'apre %s, Permessi?\n",file); 00749 for(int n=0;n<NMaxPunti;n++) 00750 fprintf(SALVA,"%lf %lf\n",Punti1[n],Punti[n]); 00751 fclose(SALVA); 00752 } 00753 void VarDatFile::ScriviFile(char *file,int CoordY,int LogLog,int NVisMin,int NVisMax){ 00754 FILE *SALVA; 00755 int CoordX = RefAbsc[CoordY]; 00756 if((SALVA = fopen(file,"w"))==0) 00757 printf("Non s'apre %s, Permessi?\n",file); 00758 for(int n=NVisMin;n<NVisMax;n++){ 00759 if(DIS_IF_TYPE(LogLog,DIS_LOGLOG)) 00760 fprintf(SALVA,"%lf %lf \n",log10(st[CoordX][n]),log10(st[CoordY][n])); 00761 else 00762 fprintf(SALVA,"%lf %lf \n",st[CoordX][n],st[CoordY][n]); 00763 } 00764 fclose(SALVA); 00765 } 00766 void VarDatFile::ScriviTutto(char *file,int LogLog,int NVisMin,int NVisMax){ 00767 FILE *SALVA; 00768 if((SALVA = fopen(file,"w"))==0) 00769 printf("Non s'apre %s, Permessi?\n",file); 00770 if(DIS_IF_TYPE(LogLog,DIS_LOGLOG)){ 00771 for(int n=NVisMin;n<NVisMax;n++){ 00772 for(int v=0;v<NVar;v++){ 00773 fprintf(SALVA,"%.4g ",log10(st[v][n])); 00774 } 00775 fprintf(SALVA,"\n"); 00776 } 00777 } 00778 else { 00779 for(int n=NVisMin;n<NVisMax;n++){ 00780 for(int v=0;v<NVar;v++){ 00781 fprintf(SALVA,"%.4g ",st[v][n]); 00782 } 00783 fprintf(SALVA,"\n"); 00784 } 00785 } 00786 fclose(SALVA); 00787 } 00788 void VarDatFile::RescaleToBulk(char *FName){ 00789 double *BulkVal = (double *)calloc(NVar,sizeof(double)); 00790 double Count = 0; 00791 int NCol = 0; 00792 for(int v=0;v<NVar;v++){ 00793 if(IsAbscissa(v)) continue; 00794 NCol++; 00795 } 00796 int NThick = (int)(NMax/(double)NCol); 00797 int Nx = NMax; 00798 for(int v=0;v<NVar;v++){ 00799 for(int nx=NMax/2;nx<3*(NMax/4);nx++){ 00800 if(isnan(st[v][nx]))continue; 00801 BulkVal[v] += st[v][nx]; 00802 Count += 1.; 00803 } 00804 } 00805 for(int v=0;v<NVar;v++){ 00806 BulkVal[v] /= Count > 0. ? Count/(double)NVar : 1.; 00807 BulkVal[v] = fabs(BulkVal[v]) > 0. ? 1./BulkVal[v] : 1.; 00808 } 00809 FILE *FWrite = fopen(FName,"w"); 00810 for(int nx=0;nx<NMax;nx++){ 00811 fprintf(FWrite,"%lf ",Abscissa(1,nx)); 00812 for(int v=1;v<NVar;v++){ 00813 fprintf(FWrite,"%lf ",st[v][nx]*BulkVal[v]); 00814 } 00815 fprintf(FWrite,"\n"); 00816 } 00817 fclose(FWrite); 00818 free(BulkVal); 00819 } 00820 void VarDatFile::ExportTxvl(char *FName,int NElMin,int NElMax){ 00821 FILE *FOut = fopen(FName,"w"); 00822 int p=0; 00823 pMinMaxGlob(0,NMax); 00824 double Dx = 1./(xGlobMax-xGlobMin); 00825 Dx = 0.05/1.; 00826 double Dz = 1./(GlobMax-GlobMin); 00827 fprintf(FOut,"# l(1 1 1) v[%d] d[part] \n",NMax/2); 00828 double *Cm = (double *)calloc(NVar,sizeof(double)); 00829 double CmTot = 0.; 00830 double *Bulk = (double *)calloc(NVar,sizeof(double)); 00831 int NBulk = NElMax-NElMin; 00832 for(int v=0;v<NVar;v++){ 00833 for(int n=0;n<NMax;n++){ 00834 if(n >= NBulk) Cm[v] += Val(v,n); 00835 } 00836 } 00837 for(int v=0;v<NVar;v++){ 00838 if(IsAbscissa(v)) continue; 00839 Cm[v] /= (double)(NMax-NBulk); 00840 CmTot += Cm[v]; 00841 } 00842 CmTot = CmTot/(double)(NVar-1); 00843 for(int v=0;v<NVar;v++){ 00844 Bulk[v] = .1/fabs(Cm[v]-CmTot); 00845 } 00846 for(int v=0;v<NVar;v++){ 00847 if(IsAbscissa(v)) continue; 00848 double OffSet = .6 - .2*(v-1); 00849 for(int n=0;n<NMax;n++){ 00850 double Zed = (Val(v,n)-Cm[v])*Bulk[v]+OffSet; 00851 if(Abscissa(v,n)*Dx > 1.) continue; 00852 fprintf(FOut,"{t[%d %d %d] x(%lf %lf %lf)}\n",p++,2,2,Abscissa(v,n)*Dx,.5,Zed); 00853 } 00854 } 00855 free(Cm); 00856 free(Bulk); 00857 fclose(FOut); 00858 } 00859 void VarDatFile::TecPlot(char *FName){ 00860 FILE *TecPlot = fopen(FName,"w"); 00861 double *BulkVal = (double *)calloc(NVar,sizeof(double)); 00862 double Count = 0; 00863 int NCol = 0; 00864 pMinMaxGlob(0,NMax); 00865 for(int v=0;v<NVar;v++){ 00866 if(IsAbscissa(v)) continue; 00867 NCol++; 00868 } 00869 int NThick = (int)(NMax/(double)NCol); 00870 int Nx = 2*(int)(NMax/3.); 00871 int Ny = Nx; 00872 for(int v=0;v<NVar;v++){ 00873 for(int nx=NMax/2;nx<3*(NMax/4);nx++){ 00874 if(isnan(st[v][nx]))continue; 00875 BulkVal[v] += st[v][nx]; 00876 Count += 1.; 00877 } 00878 } 00879 for(int v=0;v<NVar;v++){ 00880 BulkVal[v] /= Count > 0. ? Count/(double)NVar : 1.; 00881 printf("%d %lf\n",v,BulkVal[v]); 00882 BulkVal[v] = fabs(BulkVal[v]) > 0. ? 1./BulkVal[v] : 1.; 00883 } 00884 fprintf(TecPlot,"VARIABLES = \"R\", \"Z\", \"percentage\"\n"); 00885 fprintf(TecPlot,"ZONE J=%d, K=%d, F=POINT\n",Nx,Ny); 00886 double Int = .5*(xGlobMax-xGlobMin)/(double)(Ny); 00887 for(int nx=0,v=0;nx<Nx;nx++){ 00888 for(int ny=0;ny<Ny;ny++){ 00889 if((ny%(NThick/2))==0) v++; 00890 if(v >= NVar) v=0; 00891 if(IsAbscissa(v)) v++; 00892 double z = Val(v,nx)*BulkVal[v]; 00893 if(isnan(z)) z = 1.; 00894 fprintf(TecPlot,"%lf %lf %lf\n",Abscissa(v,nx),Int*ny,z); 00895 } 00896 } 00897 fclose(TecPlot); 00898 free(BulkVal); 00899 } 00900 void VarDatFile::PuntiAlloc(){ 00901 if(IfPuntiAlloc){ 00902 Punti = (double *)calloc(NMaxPunti,sizeof(*Punti)); 00903 if( Punti == NULL){printf("Punti non s'alloca\n");return ;} 00904 Punti1 = (double *)calloc(NMaxPunti,sizeof(*Punti)); 00905 if( Punti1 == NULL){printf("Punti non s'alloca\n");return ;} 00906 PuntiErr = (double *)calloc(NMaxPunti,sizeof(*Punti)); 00907 if( PuntiErr == NULL){printf("Punti non s'alloca\n");return ;} 00908 IfPuntiAlloc = 0; 00909 IfPuntiFree = 0; 00910 } 00911 } 00912 void VarDatFile::ImpSequence(int v){ 00913 RefAbsc[v] = NVar; 00914 } 00915 void VarDatFile::ImpSequence(){ 00916 for(int v=0;v<NVar;v++){ 00917 RefAbsc[v] = NVar; 00918 } 00919 } 00920 void VarDatFile::ImpCoordX(int vSet,int vAbs){ 00921 if(vAbs > NVar) return; 00922 if(IsAbscissa(vSet)) return; 00923 // one set refers to the sequence 00924 if(NVar == 1) RefAbsc[vSet] = NVar; 00925 // set to the sequence set 00926 else if(vAbs == REF_SEQ) RefAbsc[vSet] = NVar; 00927 else RefAbsc[vSet] = vAbs; 00928 } 00929 void VarDatFile::ImpCoordX(int vAbs){ 00930 if(vAbs > NVar || vAbs < REF_ASC) return; 00931 // one set refers to the sequence 00932 if(NVar == 1){ RefAbsc[0] = NVar;return;} 00933 for(int v=0;v<NVar;v++){ 00934 if(vAbs == REF_SEQ) RefAbsc[v] = NVar; 00935 else RefAbsc[v] = vAbs; 00936 } 00937 } 00938 void VarDatFile::ImpCoordY(int Ext){ 00939 if(Ext < NVar && Ext >= 0){ 00940 sp = st[Ext]; 00941 } 00942 } 00943 void VarDatFile::PuntiFree(){ 00944 if(IfPuntiFree){ 00945 free(Punti); 00946 IfPuntiAlloc = 1; 00947 } 00948 } 00949 double VarDatFile::pMaxGlob(int NVisMin,int NVisMax){ 00950 double Resp = st[0][0]; 00951 // set the initial value 00952 for(int v=0;v<NVar;v++){ 00953 if(IsAbscissa(v))continue; 00954 Resp = st[v][NVisMin]; 00955 } 00956 for(int v=0;v<NVar;v++){ 00957 if(IsAbscissa(v))continue; 00958 for(int n=NVisMin;n<NVisMax;n++){ 00959 if(n > pNRow(v)) continue; 00960 if(isnan(st[v][n]))continue; 00961 if(Resp < st[v][n]) 00962 Resp = st[v][n]; 00963 } 00964 } 00965 GlobMax = Resp; 00966 return Resp; 00967 } 00968 double VarDatFile::pMinGlob(int NVisMin,int NVisMax){ 00969 double Resp = st[0][0]; 00970 // set the initial value 00971 for(int v=0;v<NVar;v++){ 00972 if(IsAbscissa(v))continue; 00973 Resp = st[v][NVisMin]; 00974 } 00975 for(int v=0;v<NVar;v++){ 00976 if(IsAbscissa(v))continue; 00977 for(int n=NVisMin;n<NVisMax;n++){ 00978 if(n > pNRow(v)) continue; 00979 if(isnan(st[v][n])) continue; 00980 if(Resp > st[v][n]) 00981 Resp = st[v][n]; 00982 } 00983 } 00984 return Resp; 00985 } 00986 void VarDatFile::pMinMaxGlob(int NVisMin,int NVisMax){ 00987 double Border[4]; 00988 // set the initial value 00989 for(int v=0;v<NVar;v++){ 00990 if(!IsAbscissa(v)){ 00991 Border[0] = Abscissa(v,NVisMin); 00992 Border[1] = Abscissa(v,NVisMin); 00993 Border[2] = st[v][NVisMin]; 00994 Border[3] = st[v][NVisMin]; 00995 break; 00996 } 00997 } 00998 // find the borders 00999 for(int v=0;v<NVar;v++){ 01000 if(IsAbscissa(v)) continue; 01001 for(int n=NVisMin;n<NVisMax;n++){ 01002 if(n >= pNRow(v)) continue; 01003 if(isnan(st[v][n])) continue; 01004 if(Border[0] > Abscissa(v,n)) Border[0] = Abscissa(v,n); 01005 if(Border[1] < Abscissa(v,n)) Border[1] = Abscissa(v,n); 01006 if(Border[2] > st[v][n]) Border[2] = st[v][n]; 01007 if(Border[3] < st[v][n]) Border[3] = st[v][n]; 01008 } 01009 } 01010 xGlobMin = Border[0]; 01011 xGlobMax = Border[1]; 01012 GlobMin = Border[2]; 01013 GlobMax = Border[3]; 01014 } 01015 double VarDatFile::pxMaxGlob(int NVisMin,int NVisMax){ 01016 double Resp = st[0][NVisMin]; 01017 // set the initial value 01018 for(int v=0;v<NVar;v++){ 01019 if(RefAbsc[v] == NVar) return NVisMin; 01020 if(IsAbscissa(v)){ 01021 Resp = st[v][NVisMin]; 01022 break; 01023 } 01024 } 01025 for(int v=0;v<NVar;v++){ 01026 if(!IsAbscissa(v))continue; 01027 for(int n=NVisMin;n<NVisMax;n++){ 01028 if(n > pNRow(v)) continue; 01029 if(isnan(st[v][n]))continue; 01030 if(isinf(st[v][n]))continue; 01031 if(Resp < st[v][n]) 01032 Resp = st[v][n]; 01033 } 01034 } 01035 xGlobMax = Resp; 01036 printf("%lf\n",Resp); 01037 return Resp; 01038 } 01039 double VarDatFile::pxMinGlob(int NVisMin,int NVisMax){ 01040 double Resp = st[0][NVisMin]; 01041 // set the initial value 01042 for(int v=0;v<NVar;v++){ 01043 if(IsAbscissa(v)){ 01044 Resp = st[v][NVisMin]; 01045 break; 01046 } 01047 } 01048 for(int v=0;v<NVar;v++){ 01049 if(!IsAbscissa(v)) continue; 01050 for(int n=NVisMin;n<NVisMax;n++){ 01051 if(n >= pNRow(v)) continue; 01052 if(Resp > st[v][n]){ 01053 Resp = st[v][n]; 01054 } 01055 } 01056 } 01057 xGlobMin = Resp; 01058 return Resp; 01059 } 01060 double VarDatFile::pMaxGlobLog(int NVisMin,int NVisMax){ 01061 double Resp = st[0][NVisMin]; 01062 int IfContinue = 1; 01063 // set the initial value 01064 for(int v=0;v<NVar;v++){ 01065 if(IsAbscissa(v)) continue; 01066 for(int n=0;n<NMax;n++){ 01067 if(st[v][n] <= 0.) continue; 01068 Resp = st[v][n]; 01069 IfContinue = 0; 01070 break; 01071 } 01072 if(IfContinue) break; 01073 } 01074 for(int v=0;v<NVar;v++){ 01075 if(IsAbscissa(v)) continue; 01076 for(int n=NVisMin;n<NVisMax;n++){ 01077 if(st[v][n] <= 0.) continue; 01078 if(n >= pNRow(v)) continue; 01079 if(Resp < st[v][n]) Resp = st[v][n]; 01080 } 01081 } 01082 return log10(Resp > 0. ? Resp : 1.); 01083 } 01084 double VarDatFile::pMinGlobLog(int NVisMin,int NVisMax){ 01085 double Resp = st[0][NVisMin]; 01086 int IfContinue = 1; 01087 // set the initial value 01088 for(int v=0;v<NVar;v++){ 01089 if(IsAbscissa(v)) continue; 01090 for(int n=0;n<NMax;n++){ 01091 if(st[v][n] <= 0.) continue; 01092 Resp = st[v][n]; 01093 IfContinue = 0; 01094 break; 01095 } 01096 if(!IfContinue) break; 01097 } 01098 for(int v=0;v<NVar;v++){ 01099 if(IsAbscissa(v)) continue; 01100 for(int n=NVisMin;n<NVisMax;n++){ 01101 if(st[v][n] <= 0.) continue; 01102 if(n > pNRow(v)) continue; 01103 if(Resp > st[v][n]) Resp = st[v][n]; 01104 } 01105 } 01106 return log10(Resp > 0. ? Resp : 1.); 01107 } 01108 double VarDatFile::pMax(int CoordY,int NVisMin,int NVisMax){ 01109 double Resp = st[CoordY][NVisMin]; 01110 for(int n=NVisMin;n<NVisMax;n++){ 01111 if(Resp < st[CoordY][n]) 01112 Resp = st[CoordY][n]; 01113 } 01114 return Resp; 01115 } 01116 double VarDatFile::pMin(int CoordY,int NVisMin,int NVisMax){ 01117 double Resp = st[CoordY][NVisMin]; 01118 for(int n=NVisMin;n<NVisMax;n++){ 01119 if(Resp > st[CoordY][n]) 01120 Resp = st[CoordY][n]; 01121 } 01122 return Resp; 01123 } 01124 double VarDatFile::pMaxLog(int CoordY,int NVisMin,int NVisMax){ 01125 double Resp = st[CoordY][NVisMin]; 01126 for(int n=NVisMin;n<NVisMax;n++){ 01127 if(st[CoordY][n] <= 0.) continue; 01128 if(Resp < st[CoordY][n]) 01129 Resp = st[CoordY][n]; 01130 } 01131 return log10(Resp > 0. ? Resp : 1.); 01132 } 01133 double VarDatFile::pMinLog(int CoordY,int NVisMin,int NVisMax){ 01134 double Resp = 0.; 01135 for(int n=NVisMin;n<NVisMax;n++){ 01136 if(st[CoordY][n] <= 0.) continue; 01137 Resp = st[CoordY][n]; 01138 break; 01139 } 01140 for(int n=NVisMin;n<NVisMax;n++){ 01141 if(st[CoordY][n] <= 0.) continue; 01142 if(Resp > st[CoordY][n]) 01143 Resp = st[CoordY][n]; 01144 } 01145 return log10(Resp > 0. ? Resp : 1.); 01146 } 01147 void VarDatFile::setXFormula(char *str){ 01148 strcpy(XFormula,str); 01149 } 01150 void VarDatFile::setYFormula(char *str){ 01151 strcpy(YFormula,str); 01152 } 01153 void VarDatFile::Reverse(){ 01154 double Temp = 0.; 01155 for(int n=0;n<NMax/2;n++){ 01156 for(int v=0;v<NVar;v++){ 01157 Temp = st[v][n]; 01158 st[v][n] = st[v][NMax-n-1]; 01159 st[v][NMax-n-1] = Temp; 01160 } 01161 } 01162 } 01163 int VarDatFile::Smooth(double Fact,int CoordY,int NVisMin,int NVisMax){ 01164 int NOrder = 3+1; 01165 //still not working for Fact != 1. 01166 Fact = 1.; 01167 int NOut = (int)(NMax*Fact); 01168 NMaxPunti = NOut; 01169 int NSmooth = 2; 01170 double *sw = (double *)calloc(NOut,sizeof(double)); 01171 pMinMaxGlob(NVisMin,NVisMax); 01172 PuntiAlloc(); 01173 double Max=st[CoordY][0]; 01174 double Min=st[CoordY][0]; 01175 for(int n=0;n<NMax;n++){ 01176 if(Max < st[CoordY][n]) Max = st[CoordY][n]; 01177 if(Min > st[CoordY][n]) Min = st[CoordY][n]; 01178 } 01179 double DeltaIn=(Max-Min)/(double)(NMax-1); 01180 double DeltaOut=(Max-Min)/(double)(NOut-1); 01181 double *dArray = (double *)calloc(NMax+2*NOrder+2,sizeof(double)); 01182 int CoordX = RefAbsc[CoordY]; 01183 for(int vi=0;vi<NMax;vi++){ 01184 Punti1[vi] = st[CoordX][vi]; 01185 } 01186 for(int vi=0;vi<=NMax+2*NOrder;vi++){ 01187 if(vi<NOrder){ 01188 dArray[vi] = Min; 01189 } 01190 else if(vi > NMax){ 01191 dArray[vi] = (vi-NOrder+2)*DeltaIn+Min; 01192 } 01193 else { 01194 dArray[vi] = (vi-NOrder+1)*DeltaIn+Min; 01195 } 01196 } 01197 Punti[0] = st[CoordY][0]; 01198 Punti[NOut-1] = st[CoordY][NMax-1]; 01199 for(int vo=1;vo<NOut-1;vo++){ 01200 Punti[vo] = 0.; 01201 double x = DeltaOut*vo+Min; 01202 for(int vi=vo-1,vn=0;vi<vo+NOrder+1;vi++){ 01203 vn = vi; 01204 if(vi < 0){ 01205 vn = NMax + vi; 01206 } 01207 if(vi >= NMax){ 01208 vn = vi - NMax; 01209 } 01210 double Blendx = Blend(dArray,x,vn,NOrder); 01211 Punti[vo] += Blendx*st[CoordY][vn]; 01212 } 01213 } 01214 free(dArray); 01215 return NOut; 01216 } 01217 void VarDatFile::SmoothGauss(double Fact,int CoordY,int NVisMin,int NVisMax){ 01218 //still not working for Fact != 1. 01219 Fact = 1.; 01220 int NOut = (int)(NMax*Fact); 01221 NMaxPunti = NOut; 01222 pMinMaxGlob(NVisMin,NVisMax); 01223 PuntiAlloc(); 01224 int CoordX = RefAbsc[CoordY]; 01225 for(int n=0;n<NMax;n++){ 01226 Punti[n] = st[CoordY][n]; 01227 Punti1[n] = st[CoordX][n]; 01228 } 01229 Matrice Mask(5); 01230 Mask.FillGaussian(.5,3.); 01231 Mask.Print(); 01232 int NDim = 1; 01233 int IfMinImConv = 0; 01234 for(int v=0;v<NVar;v++){ 01235 if(IsAbscissa(v)) continue; 01236 Mask.ConvoluteMatrix(st[v],NVisMax-NVisMin,NDim,IfMinImConv); 01237 } 01238 } 01239 void VarDatFile::DoubleDistFluct(){ 01240 PuntiAlloc(); 01241 SigErr(NVar < 8,"Two files are with the coordinate positions are expected\n"); 01242 for(int n=0;n<NMax;n++){ 01243 if(n > pNRow(0)) continue; 01244 if(n > pNRow(1)) continue; 01245 double Dist = 0.; 01246 for(int d=0;d<3;d++){ 01247 Dist += SQR(st[1+d][n] - st[5+d][n]); 01248 } 01249 Dist = sqrt(Dist); 01250 Punti[n] = Dist; 01251 Punti1[n] = (double)n; 01252 } 01253 }