-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynopUnit.pas
1898 lines (1642 loc) · 54.1 KB
/
SynopUnit.pas
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
992
993
994
995
996
997
998
999
1000
unit SynopUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ComCtrls, ExtCtrls;
type
stlpec = array of char;
matica = array of stlpec;
PoleCol = array of integer; //nove poradie stlpcov
PoleBlank = array of integer; //blank columns
PoleSub = array of integer; //subdivisions(statistika)
PolePruh = array of string; //pole stringov[1..rmax]
PoleCelPer = array of real; //pole celkovych percent[1..rmax]
procedure nastav_adresar;
procedure synop1_proc(vstupny_txt:string);
procedure synop2_proc(vstupny_txt:string);
procedure synop3_proc(vstupny_txt:string);
procedure synop4_proc(vstupny_txt:string);
procedure synop5_proc(vstupny_txt:string);
procedure synop6_proc(vstupny_txt:string);
implementation
uses FytopackUnit;
var new,old,final:matica; //m[stlpec,riadok]
rmax,smax,nocins,nobc,nos,sort,convert:integer;
pc:PoleCol;
pb:PoleBlank;
ps:PoleSub;
pp:PolePruh;
line1:string;//prvy riadok synon.dat
subor:string;//vstupny subor napr.: C:\Fytopack\synon.dat
a:string;//adresar v ktorom je exe file
asl:string;//asl=a+'\'
procedure nastav_adresar;
begin
a:=FytopackForm.a;
asl:=FytopackForm.asl;
end;
////////////////////////////////////////////////////////////////////////////////
procedure read_constants(synopin_txt,vstupny_txt:string;
var rmax,smax,nocins,nos:integer);
var syn,tin:TextFile;
line,rows,col:string;
begin
AssignFile(syn,synopin_txt);Reset(syn);
AssignFile(tin,vstupny_txt);Reset(tin);
readln(syn);//preskoci nazov
////////////////////////////////synopin.dat
readln(syn,line);
line:=copy(line,34,MaxInt);
line:=Trim(line);
nocins:=StrToInt(line);//pocet stlpcov v novom poradi
readln(syn,line);
line:=copy(line,34,MaxInt);
line:=Trim(line);
nos:=StrToInt(line);//pocet subdivisions
readln(syn,line);
line:=copy(line,34,MaxInt);
line:=Trim(line);
sort:=StrToInt(line);//sort: 0 or 1
/////////////////////////////vstupny subor: napr.:synon.dat
readln(tin,line);
col:=copy(line,7,4);
rows:=copy(line,12,4);
smax:=StrToInt(trim(col));
rmax:=StrToInt(trim(rows));
CloseFile(tin);
CloseFile(syn);
end;
procedure read_pos_of_col_sub(vstupny_txt:string;
var PCol:PoleCol;
var PSub:PoleSub);
var tin,temp1,temp2:TextFile;//dva pomocne subory
poc:integer;
c:char;
s:string;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(temp1,'temp1.txt');Rewrite(temp1);
readln(tin);//preskocenie prvych 4 riadkov
readln(tin);
readln(tin);
readln(tin);
////////////////////////////////napisanie temp1->nahradenie medzier
while not Eof(tin) do begin // novymi riadkami
if Eoln(tin) then
begin
readln(tin);
writeln(temp1);
end
else
begin
read(tin,c);
if c=' ' then
writeln(temp1)
else
write(temp1,c);
end;
end;
CloseFile(tin);
/////////////////////napisnie temp2-> v kazdom riadku jedno cislo
Reset(temp1);
AssignFile(temp2,'temp2.txt'); Rewrite(temp2);
while not Eof(temp1) do begin
readln(temp1,s);
if (length(s)<>0) then writeln(temp2,s);
end;
Reset(temp2);
//////////////////array of columns in new sequence
poc:=1;
while (poc<=nocins) do begin
readln(temp2,s);
PCol[poc]:=StrToInt(s);
inc(poc);
end;
/////////////////array OF SUBDIVISIONS
poc:=1;
while (poc<=nos) do begin
readln(temp2,s);
PSub[poc]:=StrToInt(s);
inc(poc);
end;
CloseFile(temp1);
CloseFile(temp2);
DeleteFile('temp1.txt');
DeleteFile('temp2.txt');
end;
procedure read_pos_of_sub(vstupny_txt:string;var PSub:PoleSub);
var tin,temp1,temp2:TextFile;//dva pomocne subory
poc:integer;
c:char;
s:string;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(temp1,'temp1.txt');Rewrite(temp1);
readln(tin);//preskocenie prvych 4 riadkov
readln(tin);
readln(tin);
readln(tin);
////////////////////////////////napisanie temp1->nahradenie medzier
while not Eof(tin) do begin // novymi riadkami
if Eoln(tin) then
begin
readln(tin);
writeln(temp1);
end
else
begin
read(tin,c);
if c=' ' then
writeln(temp1)
else
write(temp1,c);
end;
end;
CloseFile(tin);
/////////////////////napisnie temp2-> v kazdom riadku jedno cislo
Reset(temp1);
AssignFile(temp2,'temp2.txt'); Rewrite(temp2);
while not Eof(temp1) do begin
readln(temp1,s);
if (length(s)<>0) then writeln(temp2,s);
end;
Reset(temp2);
/////////////////array OF SUBDIVISIONS
poc:=1;
while (poc<=nos) do begin
readln(temp2,s);
PSub[poc]:=StrToInt(s);
inc(poc);
end;
CloseFile(temp1);
CloseFile(temp2);
DeleteFile('temp1.txt');
DeleteFile('temp2.txt');
end;
procedure read_numbers_only(vstupny_txt,vystupny_txt:string);
var tin,tout:TextFile;
c:char;
i:integer;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(tout,vystupny_txt);Rewrite(tout);
readln(tin);
for i:=1 to 10 do
read(tin,c);
while not Eof(tin) do begin
if Eoln(tin) then
begin
readln(tin);
for i:=1 to 10 do
read(tin,c);
writeln(tout);
end
else
begin
read(tin,c);
write(tout,c);
end;
end;
CloseFile(tin);
CloseFile(tout);
end;
//nacita znaky z tin do pola m[s,r]
procedure scan(var m:matica;stlpce_max:integer;vstupny_txt:string);
var c:char;
s,r:integer;
tin:TextFile;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
for r:=1 to rmax do begin
for s:=1 to stlpce_max do begin
read(tin,c);
m[s,r]:=c;
end;
readln(tin);
end;
CloseFile(tin);
end;
procedure vypis(pole:matica;stlpce_max:integer;vystupny_txt:string);
var s,r:integer;
tout:TextFile;
begin
AssignFile(tout,vystupny_txt);Rewrite(tout);
for r:=1 to rmax do begin
for s:=1 to stlpce_max do begin
write(tout,pole[s,r]);
end;
writeln(tout);
end;
CloseFile(tout);
end;
procedure prehod_stlpce(var new:matica; old:matica; pc:PoleCol);
var s,r:integer;
begin
for r:=1 to rmax do begin
for s:=1 to nocins do begin
new[s,r]:=old[pc[s],r];
end;
end;
end;
procedure celkove_percenta(var p:PolePruh;var pcp:PoleCelPer;m:matica);
var s,r,poc,per,priem,suma:integer;
//t:TextFile;
begin
for r:=1 to rmax do begin
poc:=0;
suma:=0;
for s:=1 to nocins do begin
if m[s,r]<>'0' then begin
inc(poc);
suma:=suma+StrToInt(new[s,r]);
end;
end;
pcp[r]:=(poc/nocins)*100;//nezaokruhlene realne cislo
per:=round((poc/nocins)*100+0.00000000001);//nahor zaokruhlene percenta
if poc=0 then priem:=0;
if poc<>0 then priem:=round(suma/poc+0.0000000000001);//zaokruhlovanie nahor
if (per<=9) then p[r]:=' '+IntToStr(per)+'% '+IntToStr(priem);
if (per>=10)and (per<=99) then p[r]:=' '+IntToStr(per)+'% '+IntToStr(priem);
if (per>=100) then p[r]:=' '+IntToStr(per)+'% '+IntToStr(priem);
end;
{
AssignFile(t,asl+'pcp.txt');Rewrite(t);
for r:=1 to rmax do begin
writeln(t,FloatToStr(pcp[r]));
end;
CloseFile(t);
}
end;
procedure read_names(var p:PolePruh;vstupny_txt:string);
var tin:TextFile;
i:integer;
line:string;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
readln(tin);
for i:=1 to rmax do begin
readln(tin,line);
p[i]:=copy(line,1,9);
end;
CloseFile(tin);
end;
procedure append(vstupno_vystupny_txt:string; PPruh:PolePruh);
var temp,t:TextFile;
s:string;
i:integer;
begin
AssignFile(t,vstupno_vystupny_txt);Reset(t);
AssignFile(temp,'temp3.txt');Rewrite(temp);
for i:=1 to rmax do begin
readln(t,s);
writeln(temp,s+PPruh[i]);
end;
CloseFile(t);
CloseFile(temp);
DeleteFile(vstupno_vystupny_txt);
RenameFile('temp3.txt',vstupno_vystupny_txt);
end;
procedure statistika(vystupny_txt:string;new:matica;ps:PoleSub);
var i,lo,hi,r,s:integer;
t:TextFile;
pruh:PolePruh;
//pomocna procedura pre percenta
procedure go(new:matica;lo,hi:integer;vystupny_txt:string);
var s,r:integer;
poc,per,priem,suma:integer;
pp:PolePruh;
begin
SetLength(pp,rmax+1);
for r:=1 to rmax do //nulovanie pola stringov
pp[r]:='';
//napisanie stlpcov od lo do hi
for r:=1 to rmax do begin
for s:=lo to hi do begin
if convert=0 then //ak je convert=0 znaky sa len opisu
pp[r]:=pp[r]+new[s,r];
if convert=1 then begin //ak je convert=1 robi sa konverzia
if new[s,r]='0' then pp[r]:=pp[r]+'.';
if new[s,r]='1' then pp[r]:=pp[r]+'R';
if new[s,r]='2' then pp[r]:=pp[r]+'+';
if new[s,r]='3' then pp[r]:=pp[r]+'1';
if new[s,r]='4' then pp[r]:=pp[r]+'M';
if new[s,r]='5' then pp[r]:=pp[r]+'A';
if new[s,r]='6' then pp[r]:=pp[r]+'B';
if new[s,r]='7' then pp[r]:=pp[r]+'3';
if new[s,r]='8' then pp[r]:=pp[r]+'4';
if new[s,r]='9' then pp[r]:=pp[r]+'5';
end;
end;
end;
append(vystupny_txt,pp);//prilepenie plneho pola do suboru vystupny_txt
for r:=1 to rmax do//nulovanie pola stringov (od 1 do pocet riadkov)
pp[r]:='';
//naplnenie pola stringov statistikou pre stlpce lo az hi
for r:=1 to rmax do begin
poc:=0;
suma:=0;
for s:=lo to hi do begin
if new[s,r]<>'0' then begin
inc(poc);
suma:=suma+StrToInt(new[s,r]);
end;
end;
per:=round((poc/(hi-lo+1))*100+0.00000000000001);//aby zaokhruhloval nahor
if poc=0 then priem:=0;
if poc<>0 then priem:=round(suma/poc+0.000000000001);//aby zaokhruhloval nahor
if (per<=9) then pp[r]:=' '+IntToStr(per)+'% '+IntToStr(priem)+' ';
if (per>=10)and (per<=99) then pp[r]:=' '+IntToStr(per)+'% '+IntToStr(priem)+' ';
if (per>=100) then pp[r]:=' '+IntToStr(per)+'% '+IntToStr(priem)+' ';
end;
append(vystupny_txt,pp);//prilepenie plneho pola stringov do suboru vystupny_txt
//////////////////////////////////////////
end;
begin
AssignFile(t,vystupny_txt); Rewrite(t);//zmazanie t
CloseFile(t);
SetLength(pruh,rmax+1);
for i:=1 to nos do begin
if (i=1) then lo:=1;
if (i>=2) then lo:=ps[i-1]+1;
hi:=ps[i];
go(new,lo,hi,vystupny_txt);
end;
//////////////////////////pripisanie koncovych stlpcov
//ktore su bez statistiky
for r:=1 to rmax do
pruh[r]:='';
for r:=1 to rmax do begin
for s:=(hi+1) to nocins do begin
pruh[r]:=pruh[r]+new[s,r];
end;
end;
append(vystupny_txt,pruh);
end;
{
pc: 10 9 8 7 6 5 4 3 2 <-nove poradie stlpcov(fytin.txt)
pb: 10 6 <-chcem medzery za stlpcom cislo 10 a 6 (fytin.txt)
compute_new_pb(new_pb,pb,pc);
new_pb: 1 5 <-medzery budu vlozene za prvy a piaty stlpec v poradi
->nasleduje compute_pb_after_insertion_of_stat;
(dalsie prepocitavanie suradnic medzier po vlozeni statistik)
}
procedure compute_new_pb(var new_sorted_pb:PoleBlank;fytin_pb:PoleBlank;pc:PoleCol);
var i,j:integer;
new_uns_pb:PoleBlank;
//sort:len cislice,okrem 0,jedno cislo maximalne raz!!!
procedure sort(var sorted:PoleBlank;uns:PoleBlank);
var i,j,lo,hi:integer;
begin
SetLength(sorted,nobc+1);
lo:=maxint;
hi:=0;
for j:=1 to nobc do begin
for i:=1 to nobc do begin
if (uns[i]<lo) and (uns[i]>hi) then lo:=uns[i];
end;
sorted[j]:=lo;
hi:=lo;
lo:=maxint;
end;
end;
begin
SetLength(new_uns_pb,nobc+1);
for j:=1 to nobc do begin
for i:=1 to nocins do begin
if fytin_pb[j]=pc[i] then new_uns_pb[j]:=i;
end;
end;
sort(new_sorted_pb,new_uns_pb);
end;
{
pc: 10 9 8 7 6 5 4 3 2 <-nove poradie stlpcov(fytin.txt)
ps: 8 4 2 <-chcem statistiku za stlpcom cislo 8,4 a 2 (fytin.txt)
compute_new_ps(new_ps,ps,pc);
new_ps: 3 7 9 <-statistiky budu vlozene za treti,siedmy a deviaty stlpec v poradi
}
procedure compute_new_ps(var new_sorted_ps:PoleSub;fytin_ps:PoleSub;pc:PoleCol);
var i,j:integer;
new_uns_ps:PoleSub;
//sort:len cislice,okrem 0,jedno cislo maximalne raz!!!
procedure sort(var sorted:PoleSub;uns:PoleSub);
var i,j,lo,hi:integer;
begin
SetLength(sorted,nos+1);
lo:=maxint;
hi:=0;
for j:=1 to nos do begin
for i:=1 to nos do begin
if (uns[i]<lo) and (uns[i]>hi) then lo:=uns[i];
end;
sorted[j]:=lo;
hi:=lo;
lo:=maxint;
end;
end;
begin
SetLength(new_uns_ps,nos+1);
for j:=1 to nos do begin
for i:=1 to nocins do begin
if fytin_ps[j]=pc[i] then new_uns_ps[j]:=i;
end;
end;
sort(new_sorted_ps,new_uns_ps);
end;
//treba zmenit nocins na vacsie cislo!!!
procedure write_blank(vystupny_txt:string;m:matica;pb:PoleBlank);
var i,lo,hi,r,s:integer;
t:TextFile;
pruh:PolePruh;
//pomocna procedura
procedure go(new:matica;lo,hi:integer;vystupny_txt:string);
var s,r:integer;
pp:PolePruh;
begin
SetLength(pp,rmax+1);
SetLength(new,smax+1,rmax+1);
for r:=1 to rmax do
pp[r]:='';
for r:=1 to rmax do begin
for s:=lo to hi do begin
pp[r]:=pp[r]+new[s,r];
end;
end;
append(vystupny_txt,pp);
for r:=1 to rmax do //pridanie stlpcu medzier
pp[r]:=' ';
append(vystupny_txt,pp);
end;
begin
AssignFile(t,vystupny_txt); Rewrite(t);//zmazanie t
CloseFile(t);
SetLength(pruh,rmax+1);
for i:=1 to nobc do begin
if (i=1) then lo:=1;
if (i>=2) then lo:=pb[i-1]+1;
hi:=pb[i];
go(m,lo,hi,vystupny_txt);
end;
//////////////////////////pripisanie koncovych stlpcov
//ktore su bez statistiky
for r:=1 to rmax do
pruh[r]:='';
for r:=1 to rmax do begin
for s:=(hi+1) to smax do begin
pruh[r]:=pruh[r]+m[s,r];
end;
end;
append(vystupny_txt,pruh);
end;
//after insertion,before insertion of statistics
procedure compute_pb_after_insertion_of_stat(var after_ins:PoleBlank;
before_ins:PoleBlank;
ps:PoleSub);
var i,j,poc:integer;
begin
for j:=1 to nobc do begin
poc:=0;
for i:=1 to nos do begin
if ps[i]<before_ins[j] then inc(poc);
end;
after_ins[j]:=before_ins[j]+poc*8;
end;
end;
//meni aj poradie pcp!
procedure sort_according_percent(vystupny_txt,vstupny_txt:string;pcp:PoleCelPer);
var tin,tout:TextFile;
i,j:integer;
p1,p2:array of string;
lor,hir:real;//lo real,hi real
los,his:string; //lo string,hi string
pcp2:PoleCelPer;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(tout,vystupny_txt);Rewrite(tout);
SetLength(p1,rmax+1);
SetLength(p2,rmax+1);
SetLength(pcp2,rmax+1);
for i:=1 to rmax do
readln(tin,p1[i]);
//zoradenie p1 od najmensieho percenta po najvacsie
for j:=1 to (rmax-1) do begin
for i:=j to rmax do begin
if pcp[j]>pcp[i] then begin
lor:=pcp[i];hir:=pcp[j];
pcp[j]:=lor;pcp[i]:=hir;
los:=p1[i];his:=p1[j];
p1[j]:=los;p1[i]:=his;
end;
end;
end;
j:=rmax; //zoradenie p2 od najvacsieho percenta po najmensie
for i:=1 to rmax do begin
p2[i]:=p1[j];
pcp2[i]:=pcp[j];
dec(j);
end;
for i:=1 to rmax do //zapisanie p2 do vystup_txt
writeln(tout,p2[i]);
for i:=1 to rmax do//pcp musi byt od najvacsieho po najmensie
pcp[i]:=pcp2[i];
CloseFile(tin);
CloseFile(tout);
end;
//odstranenie riadkov s nulovou celkovou statistikou
procedure remove_null_per(vstupny_txt,vystupny_txt:string;pcp:PoleCelPer);
var line:string;
t,tin,tout:Textfile;
i:integer;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(tout,vystupny_txt);Rewrite(tout);
for i:=1 to high(pcp) do begin
readln(tin,line);
if pcp[i]<>0 then writeln(tout,line);//opise len riadky s nenulovym percentom
end;
CloseFile(tin);
CloseFile(tout);
end;
////////////////////////////////////////////////////////////////////////////////
procedure FYT;//hlavna procedura
var new_ps:PoleSub;
new_pb:PoleBlank;
aft_ins_pb:PoleBlank;
pcp:PoleCelPer; //celkove percenta(pole realnych cisel)
pn:PolePruh;//pole mien
pwb:PolePruh;//pole with_blank
i,r:integer;//riadok
tin,tout:TextFile;
s:string;
begin
///////////////////////prehodenie stlpcov do noveho poradia,statistika,konverzia
read_constants('synopin.dat','synon.dat',rmax,smax,nocins,nos);
if nocins=0 then begin//specialny pripad:ak nocins=0 tak sa poradie stlpcov
SetLength(pc,smax+1);//nemeni
SetLength(new,smax+1,rmax+1);
end;
if nocins>0 then begin
SetLength(pc,nocins+1);
SetLength(new,nocins+1,rmax+1);
end;
SetLength(pb,nobc+1);
SetLength(ps,nos+1);
SetLength(pp,rmax+1);//celkove percenta (text)
SetLength(pcp,rmax+1);//celkove percenta (real cisla)
SetLength(pn,rmax+1);
SetLength(pwb,rmax+1);
SetLength(new_ps,nos+1);
SetLength(new_pb,nobc+1);
SetLength(old,smax+1,rmax+1);
if nocins>0 then read_pos_of_col_sub('synopin.dat',pc,ps);
if nocins=0 then begin
read_pos_of_sub('synopin.dat',ps);
for i:=1 to smax do//poradie sa nemeni
pc[i]:=i;
nocins:=smax;
end;
read_numbers_only('synon.dat','matrix.txt');
read_names(pn,'synon.dat');//citanie mien
scan(old,smax,'matrix.txt');
prehod_stlpce(new,old,pc);
celkove_percenta(pp,pcp,new);
compute_new_ps(new_ps,ps,pc);
statistika('statistika.txt',new,new_ps);//napisanie suboru so statistikou
//kazdy riadok je ukonceny medzerou
////////////////////////////////////////////////////////////////// blank columns
if (nobc>0) then begin
smax:=nocins+8*nos;//jedna statistika je dlha 8 stlpcov
SetLength(final,smax+1,rmax+1);
scan(final,smax,'statistika.txt');
compute_new_pb(new_pb,pb,pc);
SetLength(aft_ins_pb,nobc+1);
compute_pb_after_insertion_of_stat(aft_ins_pb,new_pb,new_ps);
write_blank('with_blank.txt',final,aft_ins_pb);//napisanie suboru so statistikou //a s blank columns
end;
if (nobc=0) then begin //kopirovanie statistika.txt do with_blank.txt
AssignFile(tin,'statistika.txt');Reset(tin);
AssignFile(tout,'with_blank.txt');Rewrite(tout);
while not Eof(tin) do begin
readln(tin,s);
writeln(tout,s);
end;
CloseFile(tin);
CloseFile(tout);
end;
//////////////////////////////////////pridanie mien a celkovych percent(string)
append('with_blank.txt',pp);//prilepenie celkovej statistiky
AssignFile(tin,'with_blank.txt');Reset(tin);
for r:=1 to rmax do //nacitanie suboru do pola stringov
readln(tin,pwb[r]);
CloseFile(tin);
AssignFile(tout,'complete.txt');Rewrite(tout);
for r:=1 to rmax do //vypis pola stringov do suboru
writeln(tout,pn[r]);
CloseFile(tout);
append('complete.txt',pwb); //v subore complete.txt je uz vsetko okrem prveho
//riadku synon.txt
/////////////////////////////////// triedenie complete.txt podla celkovych percent
AssignFile(tin,'synon.dat');Reset(tin);//nacitanie prveho riadku zo synon.dat
readln(tin,line1);
CloseFile(tin);
if sort=1 then sort_according_percent('fyt1.dat','complete.txt',pcp);
//kopirovanie complete.txt
if sort=0 then begin
AssignFile(tin,'complete.txt');Reset(tin);
AssignFile(tout,'fyt1.dat');Rewrite(tout);
writeln(tout,line1);//prvy riadok zo synon.dat
while not Eof(tin) do begin
readln(tin,s);
writeln(tout,s);
end;
CloseFile(tin);
CloseFile(tout);
end;
remove_null_per('fyt1.dat','fyt.dat',pcp);//odstranenie riadkov s nulovou celkovou
//statistikou
DeleteFile('matrix.txt');
DeleteFile('statistika.txt');
DeleteFile('with_blank.txt');
DeleteFile('complete.txt');
DeleteFile('fyt1.dat');
///////////////////////////////////////////////////////////////////////////////
end;
procedure statistika1(vstupny_txt,vystupny_txt:string;ps:PoleSub);
var tin,tout:TextFile;
line:string;
i,j,lo,poc,freq:integer;
min,max,k:integer;
Smin,Smax,s:string;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(tout,vystupny_txt);Rewrite(tout);
while not Eof(tin) do begin
readln(tin,line);
lo:=1;
s:='';
for j:=1 to high(ps) do begin
poc:=0;
min:=MaxInt;
max:=-MaxInt;
for i:=lo to ps[j] do begin
if ( (line[i]>='1') and (line[i]<='9') ) then begin
inc(poc);
k:=StrToInt(line[i]);
if k<min then min:=k;
if k>max then max:=k;
end;
end;
freq:=Round( (poc/(ps[j]-lo+1))*100+0.0000000000000001 );
if freq=0 then begin
min:=0;
max:=0;
end;
if min=0 then Smin:='.';if max=0 then Smax:='.';
if min=1 then Smin:='r';if max=1 then Smax:='r';
if min=2 then Smin:='+';if max=2 then Smax:='+';
if min=3 then Smin:='1';if max=3 then Smax:='1';
if min=4 then Smin:='m';if max=4 then Smax:='m';
if min=5 then Smin:='a';if max=5 then Smax:='a';
if min=6 then Smin:='b';if max=6 then Smax:='b';
if min=7 then Smin:='3';if max=7 then Smax:='3';
if min=8 then Smin:='4';if max=8 then Smax:='4';
if min=9 then Smin:='5';if max=9 then Smax:='5';
if freq=100 then
s:=s+(' '+IntToStr(freq)+' '+Smin+Smax);
if ( (freq>9) and (freq<100) ) then
s:=s+(' '+IntToStr(freq)+' '+Smin+Smax);
if (freq<10) then
s:=s+(' '+IntToStr(freq)+' '+Smin+Smax);
lo:=ps[j]+1;
end;
writeln(tout,s);
end;
CloseFile(tin);
CloseFile(tout);
end;
procedure statistika2(vstupny_txt,vystupny_txt:string;ps:PoleSub);
var tin,tout:TextFile;
line:string;
i,j,lo,poc:integer;
freq:real;
s:string;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(tout,vystupny_txt);Rewrite(tout);
while not Eof(tin) do begin//pre vsetky riadky
readln(tin,line);
lo:=1;
s:=' ';
for j:=1 to high(ps) do begin
poc:=0;
for i:=lo to ps[j] do begin //pocet nenulovych hodnot
if ( (line[i]>='1') and (line[i]<='9') ) then inc(poc);
end;
freq:=(poc/(ps[j]-lo+1))*100;
//konverzia
if (freq=0) then s:=s+'0';
if ( (freq>0) and (freq<=10) ) then s:=s+'1';
if ( (freq>10) and (freq<=20) ) then s:=s+'2';
if ( (freq>20) and (freq<=30) ) then s:=s+'3';
if ( (freq>30) and (freq<=40) ) then s:=s+'4';
if ( (freq>40) and (freq<=50) ) then s:=s+'5';
if ( (freq>50) and (freq<=60) ) then s:=s+'6';
if ( (freq>60) and (freq<=70) ) then s:=s+'7';
if ( (freq>70) and (freq<=80) ) then s:=s+'8';
if ( (freq>80) and (freq<=100) ) then s:=s+'9';
lo:=ps[j]+1;
end;
writeln(tout,s);
end;
CloseFile(tin);
CloseFile(tout);
end;
procedure statistika3(vstupny_txt,vystupny_txt:string;ps:PoleSub);
var tin,tout:TextFile;
line:string;
i,j,lo,poc,freq:integer;
sum,priem:integer;
s:string;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(tout,vystupny_txt);Rewrite(tout);
while not Eof(tin) do begin
readln(tin,line);
lo:=1;
s:=' ';
for j:=1 to high(ps) do begin
poc:=0;
sum:=0;
for i:=lo to ps[j] do begin
if ( (line[i]>='1') and (line[i]<='9') ) then begin
inc(poc);
sum:=sum+StrToInt(line[i]);
end;
end;
freq:=Round( (poc/(ps[j]-lo+1))*100 );
if poc=0 then priem:=0;
if poc<>0 then priem:=Round(sum/poc+0.0000000000000001);//zaokruhlovanie nahor
if freq=100 then
s:=s+(' '+IntToStr(freq)+' '+IntToStr(priem));
if ( (freq>9) and (freq<100) ) then
s:=s+(' '+IntToStr(freq)+' '+IntToStr(priem));
if (freq<10) then
s:=s+(' '+IntToStr(freq)+' '+IntToStr(priem));
lo:=ps[j]+1;
end;
writeln(tout,s);
end;
CloseFile(tin);
CloseFile(tout);
end;
//vracia piaty riadok
function statistika3_line5(vstupny_txt:string;ps:PoleSub):string;
var i,j,lo:integer;
tin:TextFile;
line:string;
poc,priem:integer;//poc-pocet nenulovych hodnot v segmente
begin
AssignFile(tin,vstupny_txt);Reset(tin);
lo:=1;
Result:='';
for i:=1 to high(ps) do begin
Reset(tin);
poc:=0;
while not Eof(tin) do begin
readln(tin,line);
for j:=lo to ps[i] do begin
if line[j]<>'0' then inc(poc);
end;
end;
priem:=Round( poc/((ps[i]-lo+1)) );
Result:=Result+Format('%7s',[IntToStr(priem)]);
lo:=ps[i]+1;
end;
CloseFile(tin);
Result:='Aver.sp-no'+copy(Result,3,MaxInt);
end;
procedure statistika4(vstupny_txt,vystupny_txt:string;ps:PoleSub);
var tin,tout:TextFile;
line:string;
i,j,lo,poc,freq:integer;
s:string;
begin
AssignFile(tin,vstupny_txt);Reset(tin);
AssignFile(tout,vystupny_txt);Rewrite(tout);
while not Eof(tin) do begin
readln(tin,line);
lo:=1;
s:=' ';
for j:=1 to high(ps) do begin
poc:=0;
for i:=lo to ps[j] do begin
if ( (line[i]>='1') and (line[i]<='9') ) then inc(poc);
end;
freq:=Round( (poc/(ps[j]-lo+1))*100+0.0000000000000001 );//nahor
if freq=100 then
s:=s+' '+IntToStr(freq);
if ( (freq>9) and (freq<100) ) then
s:=s+' '+IntToStr(freq);
if (freq<10) then
s:=s+' '+IntToStr(freq);
lo:=ps[j]+1;
end;
writeln(tout,s);
end;
CloseFile(tin);
CloseFile(tout);
end;
//to iste ako statistika3 len namiesto priemeru median
procedure statistika5(vstupny_txt,vystupny_txt:string;ps:PoleSub);
var tin,tout:TextFile;
line:string;
i,j,lo,poc,freq:integer;
sum,n:integer;
s,median,riadok:string;
function sort_string(uns:string):string;//vysledok napr.:0013555788
var i,j:integer;
memory:char;
begin
for i:=1 to Length(uns)-1 do begin
for j:=i+1 to Length(uns) do begin
if uns[i]>uns[j] then begin
memory:=uns[i];
uns[i]:=uns[j];
uns[j]:=memory;
end;
end;
end;