-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmf_inout.c
991 lines (799 loc) · 29.3 KB
/
mf_inout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
/* ===================================
** mf_inout.c
** started on Wed Jan 24 19:11:25 2007
** ===================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <inout.h>
#include <io_grafic.h>
#include <mfractal.h>
#include <mf_inout.h>
/***************************************************************************/
int Dh_read( char *name_in, double *h, double *Dh, double *errDh ) {
/***************************************************************************/
double **series;
int dims,dimt;
int it, Nh;
FILE *canal;
/* first open and read the dimension of the file */
TrackNull( canal=fopen(name_in,"rt"), "Error opening file in 'r' mode" );
dims = column_serie_temp(canal);
dimt = line_serie_temp(canal);
if((h==NULL) || (Dh==NULL) || (errDh==NULL)) {
/* We just want to return the dimension */
if((dims>3) && (dimt>0)) Nh = dimt;
else Nh = ERROR;
} else {
/* We do read the data */
TrackNullAlloc( series=matrix2D(dims,dimt) );
read_serie_temp( canal, dims, dimt, series );
if((dims>3) && (dimt>0)) {
Nh = dimt;
for( it=0; it<Nh; it++ ) {
h[it] = series[0][it];
Dh[it] = series[1][it];
errDh[it] = series[2][it];
}
} else Nh = ERROR;
}
/* Memory release and end */
fclose(canal);
if((h!=NULL) && (Dh!=NULL) && (errDh!=NULL))
free_matrix2D(series,dims);
return Nh;
} // end of load_Dh
/***************************************************************************/
int Dh_write( char *name, int Nr, double *h, double *Dh, double *errDh ) {
/***************************************************************************/
FILE *canal;
int ip;
TrackNull( canal=fopen(name,"wt"), "Error opening file in 'w' mode" );
for( ip=0; ip<Nr; ip++ ) {
Dh_th = theoretical_Dh(h[ip]);
fprintf(canal,"%f %f %f %f\n",h[ip],Dh[ip],errDh[ip],Dh_th);
}
fclose(canal);
return OK;
}
/***************************************************************************/
int line_serie_temp( FILE *canal ) {
/***************************************************************************/
int pass=TRUE;
int dimt;
TrackEOF( fseek(canal,0,SEEK_SET), "Error with fseek positioning");
for( dimt=0; pass; dimt++ ) {
column_serie_temp(canal);
if(fgetc(canal) == EOF) pass = FALSE;
}
TrackEOF( fseek(canal,0,SEEK_SET), "Error with fseek positioning");
return dimt;
} // end of line_serie_temp
/***************************************************************************/
int column_serie_temp( FILE *canal ) {
/***************************************************************************/
char camp[MAXNAMELENGTH];
int status, pass=TRUE;
int dims;
for( dims=0; pass; dims++ )
if((fscanf(canal,"%s",camp)==EOF) ||
((status=fgetc(canal))==EOF) ||
(status==0x0a))
pass = FALSE;
return dims;
} // end of column_serie_temp
/***************************************************************************/
int read_serie_temp( FILE *canal, int dims, int dimt, double **series ) {
/***************************************************************************/
char camp[MAXNAMELENGTH];
float data;
int it,is,pass=TRUE;
for( it=0; (it<dimt)&&pass; it++ )
for( is=0; (is<dims)&&pass; is++ ) {
if(fscanf(canal,"%s",camp) == EOF) pass=FALSE;
IF(pass) {
sscanf(campo,"%f",&data);
series[0][is][it] = (double)data;
}
}
return OK;
} // end of read_serie_temp
/***************************************************************************/
int write_geomap ( char *name, double **Q ) {
/***************************************************************************/
FILE *canal;
int ileffs,inums;
TrackNull( canal=fopen(name,"wt"), "Error opening file in 'w' mode" );
for(inums=0;inums<Nnums;inums++) {
for(ileffs=0;ileffs<Nleffs;ileffs++)
fprintf(canal,"%f ",Q[inums][ileffs]);
fprintf(canal,"\n");
}
fclose(canal);
return OK;
} // end of write_geomap
/***************************************************************************/
int write_typemap ( char *name, double **Q ) {
/***************************************************************************/
FILE *canal;
int dim1,dim2;
int i1= 0,i2;
TrackNull( canal=fopen(name,"wt"), "Error opening file in 'w' mode" );
#ifdef _PARSE_FRACTAL_PARAMETERS_
if(p_frac->type_mfsim == TYPLOGPOISSON)
#else
if(TYPE_MFSIM == TYPLOGPOISSON)
#endif /*!_PARSE_FRACTAL_PARAMETERS_*/
{
dim1 = 1, dim2 = NLPs;
fprintf(canal,"%f ",Q[i1][0]);
for(i2=1;i2<dim2;i2++) {
if(codinfs[i2-1 ]>codinfs[i2]) fprintf(canal,"\n");
fprintf(canal,"% f ",Q[i1][i2]);
}
} else {
dim1 = Nmeans, dim2 = Nsigmas;
for(i1=0;i1<dim1;i1++) {
for(i2=0;i2<dim2;i2++)
fprintf(canal,"%f ",Q[i1][i2]);
fprintf(canal,"\n");
}
}
fclose(canal);
return OK;
} // end of write_typemap
/***************************************************************************/
int visualise_gris_pieces( int dimx, int dimy, char *dext,
double m, double M, double delta_h,
double **data) {
/***************************************************************************/
char name[MAXNAMELENGTH];
char ***manifold,***excluded;
double singmax;
int nn;
int ix,iy,ip;
double blout;
#ifdef _PARSE_IO_PARAMETERS_
blout=p_io->block_out;
#else
blout=BLOCKOUT;
#endif /*!_PARSE_IO_PARAMETERS_*/
nn = (M-m) / delta_h;
TrackNullAlloc( manifold=cmatrix3D(nn,dimy,dimx) );
TrackNullAlloc( excluded=cmatrix3D(2,dimy,dimx) );
for(iy=0;iy<dimy;iy++)
for(ix=0;ix<dimx;ix++) {
for(ip=0;ip<nn;ip++) manifold[ip][iy][ix]= (char)255; // C0;
excluded[0][iy][ix]= (char)255; // C0;
excluded[1][iy][ix]= (char)255; // C0;
ip=(int) floor((data[iy][ix]-m)/delta_h);
// ip=(int) floor(0.5*(data[iy][ix]-m)/delta_h+.5);
if((ip>=0)&&(ip<nn)) manifold[ip][iy][ix] = (char)0; // CP;
if(data[iy][ix]<m-delta_h) excluded[0][iy][ix] = (char)0; // CP;
if(data[iy][ix]>M-delta_h) excluded[1][iy][ix] = (char)0; // CP;
}
/* The manifolds are represented */
for(ip=0;ip<nn;ip++) {
sprintf(name,"manifold.%02d.%s.gif",ip,dext); // manifold
write_mask_block(dimx,dimy,blout,name,manifold[ip]);
}
sprintf(name,"excluded-.%s.gif",dext); // excluded-
write_mask_block(dimx,dimy,blout,name,excluded[0]);
sprintf(name,"excluded+.%s.gif",dext); // excluded+
write_mask_block(dimx,dimy,blout,name,excluded[1]);
/* Freeing memory before closign the loop */
free_cmatrix3D(excluded,2,dimy);
free_cmatrix3D(manifold,nn,dimy);
return OK;
} // end of visualise_gris_pieces
/********** A VOIR *********/
/***************************************************************************/
int lecture_image( int dimx, int dimy, int dimxinrim, int dimyinrim,
int dimv, int dimz, int iz, int bd, char *name_in,
char *ext, double ***signal, double *med_cr) {
/***************************************************************************/
char name[90];
double **aux,***auxt;
int levels;
int ix,iy,ic;
if(FOTO) {
if(XMAX*YMAX>0) {
auxt=matrix3D(dimv,dimyinrim,dimxinrim);
aux=matrix2D(YMAX,XMAX);
if(dimv==3) levels=read_color_block(dimxinrim,dimyinrim,1,name_in,auxt,med_cr);
else levels=read_foto_gris(dimxinrim,dimyinrim,name_in,aux);
for(ic=0;ic<dimv;ic++) {
paddwindow(dimxinrim,dimyinrim,X0,Y0,XMAX,YMAX,auxt[ic],aux);
coarseres(dimx,dimy,BLOCK,aux,signal[ic]);
med_cr[ic]=anorma(dimx,dimy,signal[ic],NULL);
}
free_matrix3D(auxt,dimv,dimyinrim);
free_matrix2D(aux,YMAX);
} else {
if(dimv==3) {
for(ic=0;ic<dimv;ic++) fill0(dimx,dimy,signal[ic],NULL);
levels=read_color_block(dimx,dimy,BLOCK,name_in,signal,med_cr);
} else if(dimv==1){
fill0(dimx,dimy,signal[0],NULL);
aux=matrix2D(dimyinrim,dimxinrim);
levels=read_foto_gris(dimxinrim,dimyinrim,name_in,aux);
coarseres(dimxinrim,dimyinrim,BLOCK,aux,signal[0]);
free_matrix2D(aux,dimyinrim);
med_cr[0]=anorma(dimx,dimy,signal[0],NULL);
}
}
} else {
if(XMAX*YMAX>0) {
auxt=matrix3D(dimv,YMAX,XMAX);
levels=read_inrimage_window(dimxinrim,dimyinrim,dimv,dimz,iz,bd,
X0,Y0,XMAX,YMAX,name_in,auxt);
for(ic=0;ic<dimv;ic++)
coarseres(XMAX,YMAX,BLOCK,auxt[ic],signal[ic]);
free_matrix3D(auxt,dimv,YMAX);
} else {
auxt=matrix3D(dimv,dimyinrim,dimxinrim);
levels=read_inrimage(dimxinrim,dimyinrim,dimv,dimz,iz,bd,name_in,auxt);
for(ic=0;ic<dimv;ic++)
coarseres(dimxinrim,dimyinrim,BLOCK,auxt[ic],signal[ic]);
free_matrix3D(auxt,dimv,dimyinrim);
}
for(ic=0;ic<dimv;ic++)
med_cr[ic]=anorma(dimx,dimy,signal[ic],NULL);
}
if (ORIGVISU) /* Visualize normalized original signal */
write_foto(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"norma",ext,signal);
return(levels);
} // end of lecture_image
/***************************************************************************/
void write_corte( int dimx, int dimy, int dimv, int xeff, int yeff,
char *ext, int *levels, double *med_cr, double **meang,
char ***msm, double ***gx, double ***gy) {
/***************************************************************************/
/* Called by the main */
/***************************************************************************/
FILE *canal;
char name[90];
int ic;
for(ic=0;ic<dimv;ic++) {
if(dimv==1) sprintf(name,"mux.%s.dat",ext);
else sprintf(name,"mux.%s-V%02d.dat",ext,ic);
write(xeff,yeff,name,gx[ic]);
if(dimv==1) sprintf(name,"muy.%s.dat",ext);
else sprintf(name,"muy.%s-V%02d.dat",ext,ic);
write(xeff,yeff,name,gy[ic]);
if(dimv==1) sprintf(name,"mean.%s.dat",ext);
else sprintf(name,"mean.%s-V%02d.dat",ext,ic);
canal=fopen(name,"wb");
fwrite(levels,sizeof(int),1,canal);
fwrite(&(med_cr[ic]),sizeof(double),1,canal);
fwrite(&(meang[ic][0]),sizeof(double),1,canal);
fwrite(&(meang[ic][1]),sizeof(double),1,canal);
fclose(canal);
/* It is necessary to rewrite the file 'contour' to fit the correct
* size */
if(dimv==1) sprintf(name,"contour.%s.gif",ext,ic);
else sprintf(name,"contour.%s-V%02d.gif",ext,ic);
write_mask_block(dimx,dimy,1.,name,msm[ic]);
}
} // end of write_corte
/***************************************************************************/
void read_corte( int dimx, int dimy, int dimv, int xeff, int yeff,
char *ext, int *levels, double *med_cr, double **meang,
char ***msm, double ***gx, double ***gy) {
/***************************************************************************/
/* Called by the main */
/***************************************************************************/
FILE *canal;
char name[90];
int ic;
for(ic=0;ic<dimv;ic++) {
if(dimv==1) sprintf(name,"mux.%s.dat",ext);
else sprintf(name,"mux.%s-V%02d.dat",ext,ic);
read(xeff,yeff,name,gx[ic]);
if(dimv==1) sprintf(name,"muy.%s.dat",ext);
else sprintf(name,"muy.%s-V%02d.dat",ext,ic);
read(xeff,yeff,name,gy[ic]);
if(dimv==1) sprintf(name,"mean.%s.dat",ext);
else sprintf(name,"mean.%s-V%02d.dat",ext,ic);
canal=fopen(name,"rb");
fread(levels,sizeof(int),1,canal);
fread(&(med_cr[ic]),sizeof(double),1,canal);
fread(&(meang[ic][0]),sizeof(double),1,canal);
fread(&(meang[ic][1]),sizeof(double),1,canal);
fclose(canal);
if(dimv==1) sprintf(name,"contour.%s.gif",ext);
else sprintf(name,"contour.%s-V%02d.gif",ext,ic);
read_gif_rgb(dimx,dimy,0,name,msm[ic],msm[ic],msm[ic]);
}
} // end of read_corte
/***************************************************************************/
int write_expon_density( double *prob, double *mm, int N,
char *ext, char *name_in ) {
/***************************************************************************/
double h;
int ip;
FILE *canal;
int nbox =
#ifdef _PARSE_FRACTAL_PARAMETERS_
p_frac->nbox;
#else
NBOX;
#endif /*!_PARSE_FRACTAL_PARAMETERS_*/
TrackNullAlloc( canal=fopen(name,"wt") );
for( ip=0; ip<=nbox; ip++ ) {
h = mm[0] + ((double)ip) / nbox * (mm[1]-mm[0]);
prob[ip] = prob[ip] * nbox / ((double)N*(mm[1]-mm[0]));
fprintf(canal,"%f %f\n",h,prob[ip]);
}
fclose(canal);
return OK;
} // end of write_expon_density
/***************************************************************************/
void phase_color( double mx, double my, char *Red, char *Green, char *Blue) {
/***************************************************************************/
/* Called by prepare_sources_fase_block
* Color representation of the space of phases:
*
* \pi/2
* \ | /
* \ | /
* \ BLUE /
* \ | /
* \ | /
* \pi--- GREEN ---0--- RED --- 0
* / | \
* / | \
* / \
* / YELLOW \
* / \
*
*/
/***************************************************************************/
double theta;
if((fabs(mx)>1e-30)||(fabs(my)>1e-30)) {
theta=anguphase_colorlo(mx,my);
if((theta<=M_PI/4.)||(theta>=7.*M_PI/4.)) {
*Red=(char)255;
*Green=(char)0;
*Blue=(char)0;
} else if(theta<=3.*M_PI/4.) {
*Red=(char)0;
*Green=(char)0;
*Blue=(char)255;
} else if(theta<=5.*M_PI/4) {
*Red=(char)0;
*Green=(char)255;
*Blue=(char)0;
} else {
*Red=(char)255;
*Green=(char)255;
*Blue=(char)0;
}
} else {
*Red=(char)0;
*Green=(char)0;
*Blue=(char)0;
}
} // end of phase_color
/***************************************************************************/
void write_multifractal( int dimx, int dimy, int dimv, int dimz,
int iz, /* int xeff, int yeff, */char*ext,
char ***msm, double ***signal ) {
/***************************************************************************/
double ***expon;
FILE *canal;
char name[90];
int ic;
if( (expon=matrix3D( dimv, dimy, dimx )) == NULL)
exit(-1);
if(dimz>1) sprintf(name, "histo_mf_%s-Z%d.fi", ext, iz);
else sprintf(name, "histo_mf_%s.fi", ext );
canal=fopen(name,"wt");
for(ic=0;ic<dimv;ic++)
multimf_histo(dimx,dimy, canal,
msm[ic],signal[ic], expon[ic]);
fclose(canal);
write_foto(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"sing_fractal",ext,expon);
free_matrix3D(expon,dimv, dimy);
} // end of write_multifractal
/***************************************************************************/
void vuelcaresult( int dimx, int dimy, double sc0, double qs,
double minimo, double maximo, int N,
const char *name_wv, double **expon, char *ext) {
/***************************************************************************/
double per;
per=100.*((double)N)/((double)dimx*dimy);
WarningV("Analysis obtained for %s wavelet\n",name_wv);
WarningVV("minimum scale %f scale quantum %f\n\n",sc0,qs);
Warning("Results:\n\n");
WarningVV("Minimal exponent %f; Maximal exponent %f:\n\n",
minimo,maximo);
WarningV("Percentage of good points: %f %%\n",per);
} // end of vuelcaresult
/***************************************************************************/
void process_sources( int dimx, int dimy, int xeff, int yeff,
double **gx, double **gy) {
/***************************************************************************/
double **mod;
int ix,iy;
mod=matrix2D(yeff,xeff);
for(iy=0;iy<dimy;iy++) {
for(ix=0;ix<dimx;ix++) {
mod[iy][ix]=sqrt(gx[iy][ix]*gx[iy][ix]+gy[iy][ix]*gy[iy][ix]);
if(mod[iy][ix]>1e-30) mod[iy][ix]=log(mod[iy][ix]);
else mod[iy][ix]=-30.*log(10.);
}
}
filtro(xeff,yeff,0.,2.,mod);
write_foto_4(xeff,yeff,"prueba.gif",mod);
free_matrix2D(mod,yeff);
} // end of process_sources
/***************************************************************************/
void write_histogram( char *name, double minimo, double maximo,
double *prob ) {
/***************************************************************************/
FILE *canal;
double x;
int ip;
canal=fopen(name,"wt");
for(ip=0;ip<=NBOX;ip++) {
x=minimo+((double)ip)/NBOX*(maximo-minimo);
fprintf(canal,"%f %f\n",x,prob[ip]);
}
fclose(canal);
} // end of write_histogram
/***************************************************************************/
void represent_sources( int dimx, int dimy, int dimv, int dimz, int iz, char *ext,
double ***gx, double ***gy) {
/***************************************************************************/
/* Represents the vectorial field of sources by its norm and its orientation.
* =========================================================================
* Called by compute_sources */
/***************************************************************************/
char ***Red,***Green,***Blue;
double ***mod;
int ic;
/* Calcul et representation du mode */
mod=matrix3D(dimv,dimy,dimx);
for(ic=0;ic<dimv;ic++)
prepare_sources_mod(dimx,dimy,1,gx[ic],gy[ic],mod[ic]);
write_foto(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"sources",ext,mod);
free_matrix3D(mod,dimv,dimy);
/* Calcul et representation de l'orientation */
Red=cmatrix3D(dimv,dimy,dimx);
Green=cmatrix3D(dimv,dimy,dimx);
Blue=cmatrix3D(dimv,dimy,dimx);
for(ic=0;ic<dimv;ic++)
prepare_sources_fase_block(dimx,dimy,1,gx[ic],gy[ic],
Red[ic],Green[ic],Blue[ic]);
write_foto_RGB(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"sources_vec",ext,Red,Green,Blue);
/* Liberation des memoires */
free_cmatrix3D(Red,dimv,dimy);
free_cmatrix3D(Green,dimv,dimy);
free_cmatrix3D(Blue,dimv,dimy);
} // end of represent_sources
/***************************************************************************/
void represent_sources_mod( int dimx, int dimy, char *ext, int silog,
double **mux, double **muy) {
/***************************************************************************/
/* Represents the norm of the vectorial field of sources
* =========================================================================
* Called by the main */
/***************************************************************************/
char name[90];
double **aux;
double buffx,buffy;
double maximo,minimo;
int ix,iy;
aux=matrix2D(dimy,dimx);
maximo=-1e30;
minimo=1e30;
for(ix=0;ix<dimx;ix++)
for(iy=0;iy<dimy;iy++) {
buffx=mux[iy][ix];
buffy=muy[iy][ix];
aux[iy][ix]=sqrt(buffx*buffx+buffy*buffy);
if(silog) {
if(aux[iy][ix]>1e-30) {
maximo=fMax(maximo,log(aux[iy][ix]));
minimo=fMin(minimo,log(aux[iy][ix]));
}
}
}
if(silog)
for(ix=0;ix<dimx;ix++)
for(iy=0;iy<dimy;iy++) {
if(aux[iy][ix]>1e-30)
aux[iy][ix]=log(aux[iy][ix])-minimo;
else aux[iy][ix]=0.;
}
strcpy(name,"sources.");
strcat(name,ext);
strcat(name,".gif");
write_foto_block(dimx,dimy,BLOUT,name,aux);
free_matrix2D(aux,dimy);
} // end of represent_sources_mod
/***************************************************************************/
void prepare_sources_mod( int dimx, int dimy, int silog,
double **mux, double **muy, double **mod ) {
/***************************************************************************/
/* Computes the norm of a vectorial field (eventually log-representtion).
* Used for the representtion of the sources.
* =========================================================================
* Called by represent_sources */
/***************************************************************************/
double buffx,buffy;
double maximo,minimo;
int ix,iy;
for(iy=0;iy<dimy;iy++)
for(ix=0;ix<dimx;ix++) {
mod[iy][ix]=sqrt(mux[iy][ix]*mux[iy][ix]+muy[iy][ix]*muy[iy][ix]);
if(silog) {
if(mod[iy][ix]>1e-30)
mod[iy][ix]=log(mod[iy][ix]);
else mod[iy][ix]=-30*log(10.);
}
}
} // end of prepare_sources_mod
/***************************************************************************/
void represent_sources_fase( int dimx, int dimy, char *ext,
double **mux, double **muy) {
/***************************************************************************/
/* Represents the orientation of the vectorial field of sources
* =========================================================================
* Called by the main */
/***************************************************************************/
char name[90];
char **Red,**Green,**Blue;
int dimxf,dimyf;
dimxf=BLOUT*dimx;
dimyf=BLOUT*dimy;
Red=cmatrix2D(dimyf,dimxf);
Green=cmatrix2D(dimyf,dimxf);
Blue=cmatrix2D(dimyf,dimxf);
prepare_sources_fase_block(dimx,dimy,BLOUT,mux,muy,Red,Green,Blue);
strcpy(name,"sources_vec.");
strcat(name,ext);
strcat(name,".gif");
write_RGB_block(dimxf,dimyf,1.,name,Red,Green,Blue);
free_cmatrix2D(Red,dimyf);
free_cmatrix2D(Green,dimyf);
free_cmatrix2D(Blue,dimyf);
} // end of represent_sources_fase
/***************************************************************************/
void prepare_sources_fase_block( int dimx, int dimy, double block, double **mux,
double **muy, char **Red, char **Green, char **Blue) {
/***************************************************************************/
/* Computes the orientation of a vectorial field. Used for the representtion
* of the sources.
* =========================================================================
* Called by the represent_sources_fase */
/***************************************************************************/
char aR,aG,aB;
double mx,my;
int beff;
int xmax,ymax;
int ix,iy;
int ibx,iby;
if(block>=1.) {
beff=(int) block;
for(ix=0;ix<dimx;ix++)
for(iy=0;iy<dimy;iy++) {
phase_color(mux[iy][ix],muy[iy][ix],&aR,&aG,&aB);
for(iby=0;iby<beff;iby++)
for(ibx=0;ibx<beff;ibx++) {
Red[iy][ix]=aR;
Green[iy][ix]=aG;
Blue[iy][ix]=aB;
}
}
} else {
beff=(int)(1./block);
xmax=dimx/beff;
ymax=dimy/beff;
for(iy=0;iy<ymax;iy++)
for(ix=0;ix<xmax;ix++) {
mx= my= 0.;
for(iby=0;iby<beff;iby++)
for(ibx=0;ibx<beff;ibx++) {
mx+=mux[iy][ix];
my+=muy[iy][ix];
}
mx=mx/((double)(beff*beff));
my=my/((double)(beff*beff));
phase_color(mux[iy][ix],muy[iy][ix],&(Red[iy][ix]),&(Green[iy][ix]),
&(Blue[iy][ix]));
/* ou:
phase_color(mx,my,&(Red[iy][ix]),&(Green[iy][ix]), &(Blue[iy][ix]));
* ??? */
}
}
} // end of prepare_sources_fase_block
/***************************************************************************/
int write_multifractal_histo( int dimx, int dimy, /* int xeff, int yeff, */
FILE *canal, char **msm, double **signal,
double **expon ) {
/***************************************************************************/
int nbox;
#ifdef _PARSE_FRACTAL_PARAMETERS_
nbox = p_frac->nbox;
#else
nbox = NBOX;
#endif /*!_PARSE_FRACTAL_PARAMETERS_*/
if(canal != NULL) {
for(ip=0;ip<=nbox;ip++) {
a = minh + (maxh-minh) / ((double)nbox)*((double)ip);
fprintf(canal,"%f %f %f %f\n",a,histoh[0][ip],
histoh[1][ip],histoh[2][ip]);
}
fprintf(canal,"\n");
}
} // end of write_multifractal_histo
/***************************************************************************/
void save_sources( int dimx, int dimy, int dimv, int dimz, int iz, char *ext,
double ***gx, double ***gy) {
/***************************************************************************/
/* Saves the vectorial field of sources.
* =========================================================================
* Called by the main program. */
/***************************************************************************/
char name[90];
int ic;
write_foto(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"sources_x",ext,gx);
write_foto(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"sources_y",ext,gy);
} // end of save_sources
/***************************************************************************/
void represent_sources_angulo( int dimx, int dimy, int dimv, int dimz, int iz, char *ext,
double ***gx, double ***gy) {
/***************************************************************************/
/* Represents the vectorial field of sources by its norm and its orientation.
* =========================================================================
* Called by compute_sources */
/***************************************************************************/
char name[90];
double ***mod, ***ang;
double mm[2];
int ic;
mod=matrix3D(dimv,dimy,dimx);
for(ic=0;ic<dimv;ic++)
prepare_sources_mod(dimx,dimy,1,gx[ic],gy[ic],mod[ic]);
write_foto(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"sources",ext,mod);
free_matrix3D(mod,dimv,dimy);
ang=matrix3D(dimv,dimy,dimx);
for(ic=0;ic<dimv;ic++) {
prepare_sources_angulo( dimx, dimy, 1, gx[ic], gy[ic], ang[ic] );
/* extrema(dimx, dimy,ang[ic] ,mm, NULL); */
}
write_foto(VIDEO,BLOUT,dimx,dimy,dimv,dimz,iz,"sources_vec",ext,ang);
free_matrix3D(ang,dimv,dimy);
} // end of represent_sources_angulo
/***************************************************************************/
void prepare_sources_angulo( int dimx, int dimy, double block,
double **mux, double **muy, double **ang ) {
/***************************************************************************/
double mx,my;
int beff;
int xmax,ymax;
int ix,iy;
int ibx,iby;
double a;
if(block>=1.) {
beff=(int) block;
for(ix=0;ix<dimx;ix++)
for(iy=0;iy<dimy;iy++) {
a=angulo(mux[iy][ix],muy[iy][ix]);
for(iby=0;iby<beff;iby++)
for(ibx=0;ibx<beff;ibx++)
ang[iy][ix]=a;
}
} else {
beff=(int)(1./block);
xmax=dimx/beff;
ymax=dimy/beff;
for(iy=0;iy<ymax;iy++)
for(ix=0;ix<xmax;ix++) {
mx= my= 0.;
for(iby=0;iby<beff;iby++)
for(ibx=0;ibx<beff;ibx++) {
mx+=mux[iy][ix];
my+=muy[iy][ix];
}
mx=mx/((double)(beff*beff));
my=my/((double)(beff*beff));
ang[iy][ix]=angulo(mux[iy][ix],muy[iy][ix]);
/* ou
ang[iy][ix]=angulo(mx,my);
* ??? */
}
}
} // end of prepare_sources_angulo
/***************************************************************************
void visualize_color( int dimx, int dimy, char *dext, double **expon,
const char *name_wv) {
char name[90];
char **Red,**Green,**Blue;
double h0,h1,rep;
int ix,iy;
h0=-0.5;
h1=1.;
Red=cmatrix2D(dimy,dimx);
Green=cmatrix2D(dimy,dimx);
Blue=cmatrix2D(dimy,dimx);
for(iy=0;iy<dimy;iy++) {
for(ix=0;ix<dimx;ix++) {
rep=(expon[iy][ix]-h0)/(h1-h0);
if(rep<0.) rep=0.;
if(rep>1.) rep=1.;
paleta(rep,&(Red[iy][ix]),&(Green[iy][ix]),&(Blue[iy][ix]));
}
}
sprintf(name,"sing_total.%s.%s.ppm",dext,name_wv);
write_ppm(dimx,dimy,1,name,Red,Green,Blue);
free_cmatrix2D(Red,dimy);
free_cmatrix2D(Green,dimy);
free_cmatrix2D(Blue,dimy);
}
***************************************************************************/
/***************************************************************************
void visualize_gris( int dimx, int dimy, char *dext,double **expon,
const char *name_wv) {
char name[90];
double **aux;
double h0,h1;
int ix,iy;
h0=-0.5;
h1=.5;
aux=matrix2D(dimy,dimx);
for(iy=0;iy<dimy;iy++) {
for(ix=0;ix<dimx;ix++) {
aux[iy][ix]=-expon[iy][ix];
if(aux[iy][ix]>-h0) aux[iy][ix]=-h0;
if(aux[iy][ix]<-h1) aux[iy][ix]=-h1;
}
}
sprintf(name,"sing_total.%s.%s.gif",dext,name_wv);
write_foto_4(dimx,dimy,name,aux);
free_matrix2D(aux,dimy);
}
***************************************************************************/
/***************************************************************************
double visualize_gris_pieces( int dimx, int dimy, double h_inf, double delta_h,
char *dext,
double **expon, const char *name_wv) {
char name[90];
char ***manifold,***excluded;
double singmax;
int ix,iy,ip;
singmax=h_inf+NSING*2*delta_h;
fprintf(stderr,"First represented singularity: %f\n",h_inf);
fprintf(stderr,"First excluded singularity: %f\n",singmax);
manifold=cmatrix3D(NSING,dimy,dimx);
excluded=cmatrix3D(2,dimy,dimx);
for(iy=0;iy<dimy;iy++) {
for(ix=0;ix<dimx;ix++) {
for(ip=0;ip<NSING;ip++) manifold[ip][iy][ix]=C0;
excluded[0][iy][ix]=C0;
excluded[1][iy][ix]=C0;
ip=(int) floor(0.5*(expon[iy][ix]-h_inf)/delta_h+.5);
if((ip>=0)&&(ip<NSING)) manifold[ip][iy][ix]=CP;
if(expon[iy][ix]<h_inf-delta_h) excluded[0][iy][ix]=CP;
if(expon[iy][ix]>singmax-delta_h) excluded[1][iy][ix]=CP;
}
}
// The manifolds are represented
for(ip=0;ip<NSING;ip++) {
sprintf(name,"manifold_%02d.%s.%s.gif",ip,dext,name_wv);
write_binary_block(dimx,dimy,BLOUT,name,manifold[ip]);
}
sprintf(name,"excluded-.%s.%s.gif",dext,name_wv);
write_binary_block(dimx,dimy,BLOUT,name,excluded[0]);
sprintf(name,"excluded+.%s.%s.gif",dext,name_wv);
write_binary_block(dimx,dimy,BLOUT,name,excluded[1]);
// Freeing memory before closign the loop
free_cmatrix3D(excluded,2,dimy);
free_cmatrix3D(manifold,NSING,dimy);
return singmax;
}
***************************************************************************/