Rewrite formatted data input routines to conform to SPSS data formats
[pspp-builds.git] / tests / formats / time-in.sh
1 #! /bin/sh
2
3 TEMPDIR=/tmp/pspp-tst-$$
4 mkdir -p $TEMPDIR
5 trap 'cd /; rm -rf $TEMPDIR' 0
6
7 # ensure that top_builddir  are absolute
8 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 top_builddir=`cd $top_builddir; pwd`
11 PSPP=$top_builddir/src/ui/terminal/pspp
12
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 fail()
20 {
21     echo $activity
22     echo FAILED
23     exit 1;
24 }
25
26
27 no_result()
28 {
29     echo $activity
30     echo NO RESULT;
31     exit 2;
32 }
33
34 pass()
35 {
36     exit 0;
37 }
38
39 cd $TEMPDIR
40
41 activity="write program to generate PSPP syntax and data"
42 cat > time-in.pl <<'EOF'
43 #! /usr/bin/perl
44
45 use strict;
46 use warnings;
47
48 our $next = 1;
49
50 my @formats = (["time", "+H:M", "+H:M:S"],
51                ["dtime", "+D H:M", "+D H:M:S"]);
52
53 my @times = (#  D  HH  MM     SS
54              [  0,  0,  0,  0.00],
55              [  1,  4, 50, 38.68],
56              [  5, 12, 31, 35.82],
57              [  0, 12, 47, 53.41],
58              [  3,  1, 26,  0.69],
59              [  1, 20, 58, 11.19],
60              [ 12,  7, 36,  5.98],
61              [ 52, 15, 43, 49.27],
62              [  7,  4, 25,  9.24],
63              [  0,  6, 49, 27.89],
64              [ 20,  2, 57, 52.56],
65              [555, 16, 45, 44.12],
66              [120, 21, 30, 57.27],
67              [  0,  4, 25,  9.98],
68              [  3,  6, 49, 27.24],
69              [  5,  2, 57, 52.13],
70              [  0, 16, 45, 44.35],
71              [  1, 21, 30, 57.32],
72              [ 10, 22, 30,  4.27],
73              [ 22,  1, 56, 51.18]);
74
75 open (SYNTAX, '>', 'time-in.pspp') or die "time-in.pspp: create: $!\n";
76 for my $format (@formats) {
77     my ($name) = @$format;
78     print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
79     print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
80     print SYNTAX "EXECUTE.\n";
81 }
82 close (SYNTAX);
83
84 for my $format (@formats) {
85     my ($fmt_name, @templates) = @$format;
86     my ($fn) = "$fmt_name.data";
87     open (DATA, '>', $fn) or die "$fn: create: $!\n";
88     select DATA;
89     for my $template (@templates) {
90         for my $time (@times) {
91             print_time_with_template ($time, $template) for 1...10;
92         }
93     }
94     close (DATA);
95 }
96
97 sub print_time_with_template {
98     my ($time, $template) = @_;
99     my ($day, $hour, $minute, $second) = @$time;
100     for my $c (split ('', $template)) {
101         if ($c eq '+') {
102             print +pick ('', '-', '+');
103         } elsif ($c eq 'D') {
104             printf (+pick ('%d', '%02d'), $day);
105             $day = 0;
106         } elsif ($c eq 'H') {
107             printf (+pick ('%d', '%02d'), $hour + 24 * $day);
108         } elsif ($c eq 'M') {
109             printf (+pick ('%d', '%02d'), $minute);
110         } elsif ($c eq 'S') {
111             printf (+pick ('%.0f', '%02.0f', '%.1f', '%.2f'), $second);
112         } elsif ($c eq ':') {
113             print +pick (' ', ':');
114         } elsif ($c eq ' ') {
115             print ' ';
116         } else {
117             die;
118         }
119     }
120     print "\n";
121 }
122
123 sub pick {
124    return $_[int (my_rand ($#_ + 1))];
125 }
126
127 sub my_rand {
128     my ($modulo) = @_;
129     $next = ($next * 1103515245 + 12345) % (2**32);
130     return int ($next / 65536) % $modulo;
131 }
132 EOF
133 if [ $? -ne 0 ] ; then no_result ; fi
134
135 activity="generate PSPP syntax and data"
136 $PERL time-in.pl
137 if [ $? -ne 0 ] ; then no_result ; fi
138
139 activity="run program"
140 $SUPERVISOR $PSPP --testing-mode time-in.pspp
141 if [ $? -ne 0 ] ; then no_result ; fi
142
143 activity="compare time.out output"
144 diff -u time.out - <<EOF
145               .00
146               .00
147               .00
148               .00
149               .00
150               .00
151               .00
152               .00
153               .00
154               .00
155         103800.00
156        -103800.00
157         103800.00
158         103800.00
159         103800.00
160         103800.00
161        -103800.00
162         103800.00
163        -103800.00
164         103800.00
165         477060.00
166         477060.00
167        -477060.00
168         477060.00
169         477060.00
170         477060.00
171         477060.00
172        -477060.00
173         477060.00
174        -477060.00
175         -46020.00
176          46020.00
177          46020.00
178         -46020.00
179          46020.00
180         -46020.00
181          46020.00
182          46020.00
183         -46020.00
184          46020.00
185         264360.00
186         264360.00
187         264360.00
188         264360.00
189         264360.00
190         264360.00
191        -264360.00
192        -264360.00
193         264360.00
194         264360.00
195         161880.00
196        -161880.00
197        -161880.00
198         161880.00
199         161880.00
200         161880.00
201         161880.00
202         161880.00
203         161880.00
204        -161880.00
205       -1064160.00
206        1064160.00
207        1064160.00
208        1064160.00
209        1064160.00
210        1064160.00
211       -1064160.00
212        1064160.00
213       -1064160.00
214        1064160.00
215       -4549380.00
216       -4549380.00
217        4549380.00
218       -4549380.00
219        4549380.00
220        4549380.00
221       -4549380.00
222        4549380.00
223       -4549380.00
224       -4549380.00
225        -620700.00
226         620700.00
227         620700.00
228         620700.00
229        -620700.00
230        -620700.00
231         620700.00
232         620700.00
233         620700.00
234        -620700.00
235          24540.00
236          24540.00
237         -24540.00
238         -24540.00
239         -24540.00
240         -24540.00
241         -24540.00
242          24540.00
243         -24540.00
244          24540.00
245        1738620.00
246        1738620.00
247        1738620.00
248        1738620.00
249       -1738620.00
250        1738620.00
251        1738620.00
252        1738620.00
253       -1738620.00
254        1738620.00
255       48012300.00
256       48012300.00
257       48012300.00
258       48012300.00
259      -48012300.00
260       48012300.00
261      -48012300.00
262      -48012300.00
263      -48012300.00
264       48012300.00
265       10445400.00
266       10445400.00
267       10445400.00
268       10445400.00
269      -10445400.00
270       10445400.00
271      -10445400.00
272       10445400.00
273      -10445400.00
274       10445400.00
275          15900.00
276          15900.00
277         -15900.00
278          15900.00
279          15900.00
280          15900.00
281          15900.00
282         -15900.00
283          15900.00
284         -15900.00
285         283740.00
286        -283740.00
287         283740.00
288         283740.00
289        -283740.00
290        -283740.00
291        -283740.00
292         283740.00
293         283740.00
294        -283740.00
295        -442620.00
296         442620.00
297         442620.00
298         442620.00
299         442620.00
300         442620.00
301         442620.00
302         442620.00
303         442620.00
304        -442620.00
305         -60300.00
306          60300.00
307          60300.00
308         -60300.00
309         -60300.00
310         -60300.00
311         -60300.00
312          60300.00
313         -60300.00
314          60300.00
315        -163800.00
316         163800.00
317        -163800.00
318         163800.00
319         163800.00
320        -163800.00
321         163800.00
322         163800.00
323         163800.00
324         163800.00
325         945000.00
326         945000.00
327        -945000.00
328        -945000.00
329         945000.00
330        -945000.00
331         945000.00
332         945000.00
333         945000.00
334         945000.00
335       -1907760.00
336       -1907760.00
337        1907760.00
338        1907760.00
339        1907760.00
340       -1907760.00
341       -1907760.00
342       -1907760.00
343        1907760.00
344        1907760.00
345               .00
346               .00
347               .00
348               .00
349               .00
350               .00
351               .00
352               .00
353               .00
354               .00
355         103839.00
356         103839.00
357        -103838.70
358        -103839.00
359         103839.00
360         103839.00
361        -103838.68
362         103839.00
363        -103838.70
364         103838.68
365         477096.00
366         477096.00
367         477096.00
368        -477096.00
369        -477096.00
370        -477096.00
371        -477096.00
372         477095.80
373         477095.80
374         477095.80
375          46073.41
376          46073.00
377         -46073.00
378          46073.41
379          46073.41
380          46073.40
381          46073.00
382         -46073.41
383          46073.41
384          46073.40
385        -264361.00
386         264361.00
387        -264360.70
388         264360.70
389         264360.70
390        -264361.00
391         264360.70
392         264360.70
393        -264361.00
394         264361.00
395         161891.20
396         161891.19
397         161891.00
398         161891.19
399         161891.00
400         161891.00
401         161891.20
402         161891.00
403         161891.19
404         161891.20
405       -1064166.00
406        1064166.00
407        1064166.00
408        1064165.98
409       -1064165.98
410       -1064166.00
411       -1064165.98
412        1064166.00
413        1064165.98
414        1064166.00
415        4549429.27
416       -4549429.00
417        4549429.30
418       -4549429.00
419        4549429.00
420        4549429.00
421       -4549429.27
422        4549429.27
423        4549429.00
424        4549429.00
425        -620709.24
426        -620709.00
427         620709.00
428         620709.20
429        -620709.00
430        -620709.20
431         620709.24
432        -620709.24
433         620709.24
434         620709.20
435         -24567.90
436          24567.89
437          24568.00
438          24568.00
439         -24568.00
440          24568.00
441         -24567.90
442          24568.00
443          24567.90
444          24568.00
445       -1738673.00
446        1738672.60
447       -1738672.60
448        1738672.60
449        1738672.56
450        1738673.00
451        1738673.00
452        1738673.00
453       -1738673.00
454        1738672.56
455      -48012344.00
456       48012344.00
457       48012344.00
458      -48012344.12
459      -48012344.10
460       48012344.00
461       48012344.00
462       48012344.10
463       48012344.00
464       48012344.12
465      -10445457.30
466       10445457.00
467       10445457.30
468       10445457.00
469       10445457.27
470      -10445457.00
471       10445457.00
472      -10445457.27
473       10445457.30
474       10445457.27
475         -15910.00
476          15910.00
477          15910.00
478         -15909.98
479          15909.98
480          15909.98
481         -15910.00
482         -15909.98
483          15910.00
484          15910.00
485        -283767.00
486         283767.00
487        -283767.00
488         283767.20
489         283767.24
490        -283767.00
491        -283767.00
492         283767.20
493         283767.00
494        -283767.20
495         442672.13
496        -442672.13
497         442672.10
498         442672.00
499         442672.10
500         442672.00
501        -442672.00
502        -442672.10
503         442672.13
504        -442672.13
505          60344.40
506          60344.40
507          60344.40
508          60344.40
509         -60344.35
510          60344.35
511         -60344.35
512          60344.00
513          60344.00
514          60344.00
515         163857.32
516        -163857.30
517         163857.30
518        -163857.32
519         163857.00
520         163857.32
521        -163857.32
522         163857.00
523         163857.32
524        -163857.00
525         945004.00
526         945004.30
527         945004.30
528         945004.00
529         945004.00
530         945004.30
531         945004.00
532         945004.27
533        -945004.00
534         945004.00
535       -1907811.00
536        1907811.20
537        1907811.00
538       -1907811.00
539        1907811.00
540        1907811.18
541        1907811.20
542       -1907811.20
543       -1907811.00
544        1907811.20
545 EOF
546 if [ $? -ne 0 ] ; then fail ; fi
547
548 activity="compare dtime.out output"
549 diff -u dtime.out - <<EOF
550               .00
551               .00
552               .00
553               .00
554               .00
555               .00
556               .00
557               .00
558               .00
559               .00
560         103800.00
561         103800.00
562        -103800.00
563        -103800.00
564         103800.00
565         103800.00
566         103800.00
567         103800.00
568         103800.00
569         103800.00
570         477060.00
571         477060.00
572         477060.00
573         477060.00
574         477060.00
575        -477060.00
576        -477060.00
577        -477060.00
578         477060.00
579         477060.00
580         -46020.00
581          46020.00
582          46020.00
583          46020.00
584          46020.00
585          46020.00
586          46020.00
587         -46020.00
588          46020.00
589          46020.00
590        -264360.00
591        -264360.00
592         264360.00
593        -264360.00
594         264360.00
595         264360.00
596        -264360.00
597         264360.00
598         264360.00
599         264360.00
600         161880.00
601         161880.00
602        -161880.00
603         161880.00
604         161880.00
605         161880.00
606        -161880.00
607         161880.00
608        -161880.00
609         161880.00
610       -1064160.00
611       -1064160.00
612        1064160.00
613       -1064160.00
614       -1064160.00
615        1064160.00
616        1064160.00
617        1064160.00
618        1064160.00
619       -1064160.00
620        4549380.00
621       -4549380.00
622        4549380.00
623        4549380.00
624        4549380.00
625        4549380.00
626        4549380.00
627        4549380.00
628       -4549380.00
629       -4549380.00
630        -620700.00
631        -620700.00
632         620700.00
633         620700.00
634        -620700.00
635         620700.00
636         620700.00
637         620700.00
638        -620700.00
639         620700.00
640         -24540.00
641          24540.00
642          24540.00
643         -24540.00
644          24540.00
645         -24540.00
646          24540.00
647          24540.00
648         -24540.00
649          24540.00
650       -1738620.00
651        1738620.00
652        1738620.00
653        1738620.00
654       -1738620.00
655       -1738620.00
656        1738620.00
657        1738620.00
658        1738620.00
659        1738620.00
660       48012300.00
661      -48012300.00
662       48012300.00
663       48012300.00
664      -48012300.00
665       48012300.00
666       48012300.00
667       48012300.00
668       48012300.00
669       48012300.00
670       10445400.00
671       10445400.00
672      -10445400.00
673       10445400.00
674       10445400.00
675       10445400.00
676       10445400.00
677       10445400.00
678       10445400.00
679       10445400.00
680          15900.00
681          15900.00
682          15900.00
683          15900.00
684          15900.00
685          15900.00
686         -15900.00
687          15900.00
688          15900.00
689         -15900.00
690         283740.00
691        -283740.00
692         283740.00
693         283740.00
694         283740.00
695        -283740.00
696         283740.00
697         283740.00
698        -283740.00
699         283740.00
700         442620.00
701         442620.00
702         442620.00
703         442620.00
704         442620.00
705         442620.00
706         442620.00
707         442620.00
708         442620.00
709         442620.00
710          60300.00
711          60300.00
712         -60300.00
713         -60300.00
714          60300.00
715         -60300.00
716         -60300.00
717          60300.00
718         -60300.00
719         -60300.00
720         163800.00
721        -163800.00
722         163800.00
723         163800.00
724         163800.00
725         163800.00
726         163800.00
727         163800.00
728        -163800.00
729         163800.00
730        -945000.00
731        -945000.00
732         945000.00
733         945000.00
734         945000.00
735         945000.00
736         945000.00
737         945000.00
738         945000.00
739         945000.00
740        1907760.00
741        1907760.00
742        1907760.00
743        1907760.00
744        1907760.00
745        1907760.00
746        1907760.00
747        1907760.00
748        1907760.00
749        1907760.00
750               .00
751               .00
752               .00
753               .00
754               .00
755               .00
756               .00
757               .00
758               .00
759               .00
760        -103839.00
761         103838.70
762         103839.00
763         103838.70
764         103839.00
765         103838.68
766        -103838.68
767         103838.70
768         103838.68
769         103838.70
770        -477096.00
771         477096.00
772         477095.82
773         477096.00
774        -477095.82
775        -477096.00
776         477095.82
777         477095.80
778         477096.00
779         477095.82
780          46073.00
781          46073.40
782         -46073.40
783          46073.00
784          46073.41
785         -46073.00
786          46073.00
787          46073.00
788         -46073.00
789         -46073.00
790         264361.00
791         264360.70
792         264361.00
793         264360.70
794        -264361.00
795         264360.69
796         264360.70
797         264360.69
798        -264360.70
799        -264360.69
800         161891.20
801         161891.00
802         161891.20
803         161891.00
804        -161891.00
805         161891.00
806         161891.00
807         161891.00
808         161891.00
809         161891.19
810       -1064166.00
811       -1064165.98
812        1064166.00
813        1064165.98
814       -1064166.00
815        1064165.98
816       -1064166.00
817        1064166.00
818       -1064166.00
819        1064166.00
820        4549429.00
821        4549429.27
822        4549429.00
823        4549429.27
824        4549429.27
825        4549429.30
826        4549429.27
827       -4549429.00
828        4549429.30
829        4549429.30
830         620709.24
831         620709.00
832        -620709.00
833         620709.24
834        -620709.00
835        -620709.24
836        -620709.24
837         620709.20
838        -620709.00
839         620709.24
840          24567.89
841          24567.90
842          24567.89
843          24568.00
844          24568.00
845         -24567.89
846          24567.90
847          24567.90
848         -24567.90
849         -24568.00
850        1738672.60
851        1738673.00
852       -1738672.56
853       -1738672.60
854        1738673.00
855       -1738672.60
856       -1738673.00
857       -1738672.56
858        1738672.60
859        1738672.56
860      -48012344.00
861      -48012344.10
862       48012344.10
863       48012344.00
864       48012344.12
865      -48012344.10
866       48012344.00
867       48012344.12
868       48012344.00
869      -48012344.10
870       10445457.00
871       10445457.27
872      -10445457.00
873      -10445457.00
874       10445457.00
875      -10445457.00
876       10445457.27
877      -10445457.00
878       10445457.00
879      -10445457.27
880         -15909.98
881         -15910.00
882         -15910.00
883         -15910.00
884          15910.00
885          15910.00
886          15910.00
887          15909.98
888          15910.00
889          15910.00
890        -283767.00
891        -283767.00
892         283767.00
893         283767.24
894        -283767.24
895        -283767.24
896        -283767.24
897         283767.00
898         283767.00
899         283767.00
900        -442672.13
901        -442672.00
902         442672.00
903         442672.00
904         442672.10
905        -442672.00
906         442672.00
907         442672.13
908         442672.13
909         442672.00
910          60344.35
911          60344.40
912          60344.00
913          60344.00
914          60344.35
915         -60344.00
916          60344.00
917          60344.00
918         -60344.35
919         -60344.00
920         163857.00
921         163857.00
922        -163857.00
923         163857.00
924         163857.30
925         163857.00
926        -163857.00
927         163857.32
928         163857.00
929         163857.00
930         945004.27
931         945004.30
932        -945004.30
933        -945004.30
934         945004.00
935         945004.00
936         945004.30
937        -945004.30
938         945004.00
939         945004.00
940        1907811.00
941       -1907811.20
942        1907811.18
943       -1907811.00
944        1907811.18
945        1907811.18
946       -1907811.00
947       -1907811.00
948        1907811.00
949        1907811.20
950 EOF
951 if [ $? -ne 0 ] ; then fail ; fi
952
953 pass