summaryrefslogtreecommitdiffstats
path: root/ast/ast_tester/testtime.f
blob: 39c4b9af7d70490f64a336713c7fae92af17f424 (plain)
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
      program testtime
      implicit none
      include 'SAE_PAR'
      include 'AST_PAR'
      include 'AST_ERR'

      character txt*40
      double precision xin, xout, xout2, ct, ctl, origin
      integer status, tf, tf1, tf2, fs, n, chr_len, nc
      status = sai__ok

      call ast_begin( status )

c      call ast_SetWatchId( 740050 )

c
c Test default attribute values
c
      tf = ast_timeframe( ' ', status )

      if( ast_getc( tf, 'System', status ) .ne. 'MJD' ) then
         write(*,*)  ast_getc( tf, 'System', status )
         call stopit( status, 'error 1' )
      endif

      if( ast_getd( tf, 'TimeOrigin', status ) .ne. 0.0 ) then
         write(*,*)  ast_getd( tf, 'TimeOrigin', status )
         call stopit( status, 'error 2' )
      endif

      if( ast_getc( tf, 'ObsLon', status ) .ne. 'E0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLon', status )
         call stopit( status, 'error 3' )
      endif

      if( ast_getc( tf, 'ObsLat', status ) .ne. 'N0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLat', status )
         call stopit( status, 'error 4' )
      endif

      if( ast_getc( tf, 'TimeScale', status ) .ne. 'TAI' ) then
         write(*,*)  ast_getc( tf, 'TimeScale', status )
         call stopit( status, 'error 5' )
      endif

      if( ast_getc( tf, 'AlignTimeScale', status ) .ne. 'TAI' ) then
         write(*,*)  ast_getc( tf, 'AlignTimeScale', status )
         call stopit( status, 'error 6' )
      endif

      if( ast_geti( tf, 'naxes', status ) .ne. 1 ) then
         write(*,*)  ast_getc( tf, 'Naxes', status )
         call stopit( status, 'error 7' )
      endif

      if( ast_getd( tf, 'Epoch', status ) .ne. 2000.0 ) then
         write(*,*)  ast_getd( tf, 'Epoch', status )
         call stopit( status, 'error 8' )
      endif

      if( ast_getc( tf, 'Label', status ) .ne.
     :                              'Modified Julian Date' ) then
         write(*,*)  ast_getc( tf, 'Label', status )
         call stopit( status, 'error 9' )
      endif

      if( ast_getc( tf, 'Symbol', status ) .ne. 'MJD' ) then
         write(*,*)  ast_getc( tf, 'Symbol', status )
         call stopit( status, 'error 10' )
      endif

      if( ast_getc( tf, 'Title', status ) .ne.
     :                              'Modified Julian Date' ) then
         write(*,*)  ast_getc( tf, 'Title', status )
         call stopit( status, 'error 11' )
      endif

      if( ast_getc( tf, 'unit', status ) .ne. 'd' ) then
         write(*,*)  ast_getc( tf, 'unit', status )
         call stopit( status, 'error 12' )
      endif

      if( ast_getc( tf, '  domain ', status ) .ne. 'TIME' ) then
         write(*,*)  ast_getc( tf, '  domain ', status )
         call stopit( status, 'error 13' )
      endif

      if( ast_getc( tf, 'alignSystem', status ) .ne. 'MJD' ) then
         write(*,*)  ast_getc( tf, 'alignSystem', status )
         call stopit( status, 'error 14' )
      endif

c
c Test dependency of default attribute values on System
c
      call ast_setc( tf, 'system', 'jd', status )

      if( ast_getc( tf, 'System', status ) .ne. 'JD' ) then
         write(*,*)  ast_getc( tf, 'System', status )
         call stopit( status, 'error 1b' )
      endif

      if( ast_getd( tf, 'TimeOrigin', status ) .ne. 0.0 ) then
         write(*,*)  ast_getd( tf, 'TimeOrigin', status )
         call stopit( status, 'error 2b' )
      endif

      if( ast_getc( tf, 'ObsLon', status ) .ne. 'E0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLon', status )
         call stopit( status, 'error 3b' )
      endif

      if( ast_getc( tf, 'ObsLat', status ) .ne. 'N0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLat', status )
         call stopit( status, 'error 4b' )
      endif

      if( ast_getc( tf, 'TimeScale', status ) .ne. 'TAI' ) then
         write(*,*)  ast_getc( tf, 'TimeScale', status )
         call stopit( status, 'error 5b' )
      endif

      if( ast_getc( tf, 'AlignTimeScale', status ) .ne. 'TAI' ) then
         write(*,*)  ast_getc( tf, 'AlignTimeScale', status )
         call stopit( status, 'error 6b' )
      endif

      if( ast_geti( tf, 'naxes', status ) .ne. 1 ) then
         write(*,*)  ast_getc( tf, 'Naxes', status )
         call stopit( status, 'error 7b' )
      endif

      if( ast_getd( tf, 'Epoch', status ) .ne. 2000.0 ) then
         write(*,*)  ast_getd( tf, 'Epoch', status )
         call stopit( status, 'error 8b' )
      endif

      if( ast_getc( tf, 'Label', status ) .ne.
     :                              'Julian Date' ) then
         write(*,*)  ast_getc( tf, 'Label', status )
         call stopit( status, 'error 9b' )
      endif

      if( ast_getc( tf, 'Symbol', status ) .ne. 'JD' ) then
         write(*,*)  ast_getc( tf, 'Symbol', status )
         call stopit( status, 'error 10b' )
      endif

      if( ast_getc( tf, 'Title', status ) .ne.
     :                              'Julian Date' ) then
         write(*,*)  ast_getc( tf, 'Title', status )
         call stopit( status, 'error 11b' )
      endif

      if( ast_getc( tf, 'unit', status ) .ne. 'd' ) then
         write(*,*)  ast_getc( tf, 'unit', status )
         call stopit( status, 'error 12b' )
      endif

      if( ast_getc( tf, '  domain ', status ) .ne. 'TIME' ) then
         write(*,*)  ast_getc( tf, '  domain ', status )
         call stopit( status, 'error 13b' )
      endif

      if( ast_getc( tf, 'alignSystem', status ) .ne. 'MJD' ) then
         write(*,*)  ast_getc( tf, 'alignSystem', status )
         call stopit( status, 'error 14b' )
      endif



      call ast_setc( tf, 'system', 'jepoch', status )

      if( ast_getc( tf, 'System', status ) .ne. 'JEPOCH' ) then
         write(*,*)  ast_getc( tf, 'System', status )
         call stopit( status, 'error 1c' )
      endif

      if( ast_getd( tf, 'TimeOrigin', status ) .ne. 0.0 ) then
         write(*,*)  ast_getd( tf, 'TimeOrigin', status )
         call stopit( status, 'error 2c' )
      endif

      if( ast_getc( tf, 'ObsLon', status ) .ne. 'E0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLon', status )
         call stopit( status, 'error 3c' )
      endif

      if( ast_getc( tf, 'ObsLat', status ) .ne. 'N0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLat', status )
         call stopit( status, 'error 4c' )
      endif

      if( ast_getc( tf, 'TimeScale', status ) .ne. 'TAI' ) then
         write(*,*)  ast_getc( tf, 'TimeScale', status )
         call stopit( status, 'error 5c' )
      endif

      if( ast_getc( tf, 'AlignTimeScale', status ) .ne. 'TAI' ) then
         write(*,*)  ast_getc( tf, 'AlignTimeScale', status )
         call stopit( status, 'error 6c' )
      endif

      if( ast_geti( tf, 'naxes', status ) .ne. 1 ) then
         write(*,*)  ast_getc( tf, 'Naxes', status )
         call stopit( status, 'error 7c' )
      endif

      if( ast_getd( tf, 'Epoch', status ) .ne. 2000.0 ) then
         write(*,*)  ast_getd( tf, 'Epoch', status )
         call stopit( status, 'error 8c' )
      endif

      if( ast_getc( tf, 'Label', status ) .ne.
     :                              'Julian Epoch' ) then
         write(*,*)  ast_getc( tf, 'Label', status )
         call stopit( status, 'error 9c' )
      endif

      if( ast_getc( tf, 'Symbol', status ) .ne. 'JEP' ) then
         write(*,*)  ast_getc( tf, 'Symbol', status )
         call stopit( status, 'error 10c' )
      endif

      if( ast_getc( tf, 'Title', status ) .ne.
     :                              'Julian Epoch' ) then
         write(*,*)  ast_getc( tf, 'Title', status )
         call stopit( status, 'error 11c' )
      endif

      if( ast_getc( tf, 'unit', status ) .ne. 'yr' ) then
         write(*,*)  ast_getc( tf, 'unit', status )
         call stopit( status, 'error 12c' )
      endif

      if( ast_getc( tf, '  domain ', status ) .ne. 'TIME' ) then
         write(*,*)  ast_getc( tf, '  domain ', status )
         call stopit( status, 'error 13c' )
      endif

      if( ast_getc( tf, 'alignSystem', status ) .ne. 'MJD' ) then
         write(*,*)  ast_getc( tf, 'alignSystem', status )
         call stopit( status, 'error 14c' )
      endif


      call ast_setc( tf, 'system', 'bepoch', status )

      if( ast_getc( tf, 'System', status ) .ne. 'BEPOCH' ) then
         write(*,*)  ast_getc( tf, 'System', status )
         call stopit( status, 'error 1d' )
      endif

      if( ast_getd( tf, 'TimeOrigin', status ) .ne. 0.0 ) then
         write(*,*)  ast_getd( tf, 'TimeOrigin', status )
         call stopit( status, 'error 2d' )
      endif

      if( ast_getc( tf, 'ObsLon', status ) .ne. 'E0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLon', status )
         call stopit( status, 'error 3d' )
      endif

      if( ast_getc( tf, 'ObsLat', status ) .ne. 'N0:00:00.00' ) then
         write(*,*)  ast_getc( tf, 'ObsLat', status )
         call stopit( status, 'error 4d' )
      endif

      if( ast_getc( tf, 'TimeScale', status ) .ne. 'TT' ) then
         write(*,*)  ast_getc( tf, 'TimeScale', status )
         call stopit( status, 'error 5d' )
      endif

      if( ast_getc( tf, 'AlignTimeScale', status ) .ne. 'TAI' ) then
         write(*,*)  ast_getc( tf, 'AlignTimeScale', status )
         call stopit( status, 'error 6d' )
      endif

      if( ast_geti( tf, 'naxes', status ) .ne. 1 ) then
         write(*,*)  ast_getc( tf, 'Naxes', status )
         call stopit( status, 'error 7d' )
      endif

      if( ast_getd( tf, 'Epoch', status ) .ne. 2000.0 ) then
         write(*,*)  ast_getd( tf, 'Epoch', status )
         call stopit( status, 'error 8d' )
      endif

      if( ast_getc( tf, 'Label', status ) .ne.
     :                              'Besselian Epoch' ) then
         write(*,*)  ast_getc( tf, 'Label', status )
         call stopit( status, 'error 9d' )
      endif

      if( ast_getc( tf, 'Symbol', status ) .ne. 'BEP' ) then
         write(*,*)  ast_getc( tf, 'Symbol', status )
         call stopit( status, 'error 10d' )
      endif

      if( ast_getc( tf, 'Title', status ) .ne.
     :                              'Besselian Epoch' ) then
         write(*,*)  ast_getc( tf, 'Title', status )
         call stopit( status, 'error 11d' )
      endif

      if( ast_getc( tf, 'unit', status ) .ne. 'yr' ) then
         write(*,*)  ast_getc( tf, 'unit', status )
         call stopit( status, 'error 12d' )
      endif

      if( ast_getc( tf, '  domain ', status ) .ne. 'TIME' ) then
         write(*,*)  ast_getc( tf, '  domain ', status )
         call stopit( status, 'error 13d' )
      endif

      if( ast_getc( tf, 'alignSystem', status ) .ne. 'MJD' ) then
         write(*,*)  ast_getc( tf, 'alignSystem', status )
         call stopit( status, 'error 14d' )
      endif

c
c Test dump and load
c
      call checkDump( tf, 'CheckDump 1', status )

c
c Test CurrentTime method.
c
      call ast_set( tf, 'system=jepoch,unit=yr,timescale=utc,'//
     :              'timeorigin=0', status )
      n = 0

      write(*,*) '   Testing astCurrentTime: approx 1 second pause '//
     :           'following...'
      ctl = ast_currenttime( tf, status ) + 1.0D0/(86400.0D0*365.25D0)
      do while( ast_currenttime( tf, status ) .lt. ctl )
         n = n + 1
         if( n .gt. 2000000 ) then
            call stopit( status, 'error 15' )
            return
         end if
      end do
      write(*,*) '   1 second pause finished.'


c
c Test behaviour of TimeOrigin attribute
c
      tf = ast_timeframe( 'timescale=utc', status )
      origin = ast_currenttime( tf, status )
      call ast_setd( tf, 'TimeOrigin', origin, status )
      write(*,*) '   Testing TimeOrigin: approx 1 second pause '//
     :           'following...'
      n = 0
      do while( ast_currenttime( tf, status ) .lt.
     :          1.0D0/(86400.0D0*364.25D0) )
         n = n + 1
         if( n .gt. 2000000 ) then
            call stopit( status, 'error 16' )
            return
         end if
      end do
      write(*,*) '   1 second pause finished.'

      call ast_set( tf, 'unit=s', status )
      if( abs( ast_getd( tf, 'TimeOrigin', status ) -
     :         origin*86400.0D0 ) .gt. 0.01 ) then
         write(*,*) abs( ast_getd( tf, 'TimeOrigin', status ) -
     :                   origin*86400.0D0 )
         call stopit( status, 'error 17' )
      end if


c
c  Test conversions between basic systems with arbitrary offsets
c
      tf1 = ast_timeframe( 'system=mjd,timeorigin=53000', status )
      tf2 = ast_timeframe( 'system=jd,timeorigin=2453000.5', status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 18' )
      else if( .not. ast_isaunitmap( ast_getMapping( fs, AST__BASE,
     :                                         AST__CURRENT,
     :                                         status ), status ) ) then
         call stopit( status, 'error 19' )
      end if



      tf1 = ast_timeframe( 'system=mjd,timescale=UTC,timeorigin=53000',
     :                     status )
      tf2 = ast_timeframe( 'system=bepoch,timeorigin=2004', status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 20' )
      else
         xin = 100.0D0
         call ast_tran1( fs, 1, xin, .true., xout, status )
         if( abs( xout - 0.2600974092354136D0 ) .gt. 1.0D-10 ) then
            call stopit( status, 'error 21' )
         end if
         call ast_tran1( fs, 1, xout, .false., xin, status )
         if( abs( xin  - 100.0D0 ) .gt. 1.0D-6 ) then
            call stopit( status, 'error 21b' )
         end if
      end if


      tf1 = ast_timeframe( 'system=bepoch,timeorigin=0', status )
      if( status .eq.sai__OK ) then
         call err_mark
         call ast_set( tf1, 'TimeScale=TAI', status )
         if( status .eq. AST__ATTIN ) then
            call err_annul( status )
         else
            call stopit( status, 'error 21b' );
         endif

         call ast_set( tf1, 'Unit=s', status )
         if( status .eq. AST__ATTIN ) then
            call err_annul( status )
         else
            call stopit( status, 'error 21c' );
         endif
         call err_rlse
      endif

      tf2 = ast_timeframe( 'system=jepoch,timescale=tai,'//
     :                     'timeorigin=100.0', status )
      call ast_set( tf2, 'unit=d', status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 22' )
      else
         xin = 100.0D0
         call ast_tran1( fs, 1, xin, .true., xout, status )
         if( abs( xout - 14.35534169996282 ) .gt. 1.0D-6 ) then
            call stopit( status, 'error 23' )
         end if
         call ast_tran1( fs, 1, xout, .false., xin, status )
         if( abs( xin  - 100.0D0 ) .gt. 1.0D-6 ) then
            call stopit( status, 'error 23b' )
         end if
      end if

c Besselian epoch offset from B2000 [TT, yr]
      call ast_set( tf1, 'timeorigin=2000', status )

c Julian date offset from 2450000.5 days [TDB, h]
      call ast_set( tf2, 'system=JD,timescale=TDB,unit=h,'//
     :              'timeorigin=2450000.5 d', status )

      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 24' )
      else
         xin = 0.1
         call ast_tran1( fs, 1, xin, .true., xout, status )
         if( abs( xout - 37933.38284478387D0) .gt. 1.0D-5 ) then
            call stopit( status, 'error 25' )
         end if
         call ast_tran1( fs, 1, xout, .false., xin, status )
         if( abs( xin  - 0.1 ) .gt. 1.0D-10 ) then
            call stopit( status, 'error 25b' )
         end if
      end if


c
c Test Formatting and unformatting
c
      tf1 = ast_timeframe( 'system=jepoch,timeorigin=2005.0', status )

      txt = ast_format( tf1, 1, 100.0D0, status )
      if( txt .ne. '100' ) then
         write(*,*) ast_format( tf1, 1, 100.0D0, status )
         call stopit( status, 'error 26' )
      end if
      nc = ast_unformat( tf1, 1, txt, xout, status )
      if( nc .ne. len( txt ) .or. xout .ne. 100.0D0 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 26b' )
      end if



      call ast_set( tf1, 'format=iso', status )
      txt = ast_format( tf1, 1, 1.0D0, status )
      if( txt .ne. '2006-01-01' ) then
         write(*,*) ast_format( tf1, 1, 1.0D0, status )
         call stopit( status, 'error 27' )
      end if

      nc = ast_unformat( tf1, 1, txt, xout, status )
      if( nc .ne. len( txt ) .or. xout .ne. 1.0D0 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 27b' )
      end if



      call ast_set( tf1, 'format=iso.0', status )
      txt = ast_format( tf1, 1, 1.0D0, status )
      if( txt .ne. '2006-01-01 00:00:00' ) then
         write(*,*) ast_format( tf1, 1, 1.0D0, status )
         call stopit( status, 'error 28' )
      end if

      nc = ast_unformat( tf1, 1, txt, xout, status )
      if( nc .ne. len( txt ) .or. xout .ne. 1.0D0 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 28b' )
      end if



      call ast_set( tf1, 'unit=s,format=iso.2', status )
      txt = ast_format( tf1, 1, 10.0D0, status )
      if( txt .ne. '2004-12-31 18:00:10.00' ) then
         write(*,*) ast_format( tf1, 1, 10.0D0, status )
         call stopit( status, 'error 29' )
      end if

      nc = ast_unformat( tf1, 1, txt, xout, status )
      if( nc .ne. len( txt ) .or.
     :    abs( xout - 10.0D0 ) .gt. 1.0E-3 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 29b' )
      end if



      txt = ast_format( tf1, 1, 10.12D0, status )
      if( txt .ne. '2004-12-31 18:00:10.12' ) then
         write(*,*) ast_format( tf1, 1, 10.12D0, status )
         call stopit( status, 'error 30' )
      end if

      nc = ast_unformat( tf1, 1, txt, xout, status )
      if( nc .ne. len( txt ) .or.
     :    abs( xout - 10.12D0 ) .gt. 1.0E-3 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 30b' )
      end if


      call ast_set( tf1, 'timescale=utc', status )
      xin = ast_currenttime( tf1, status )
      txt = ast_format( tf1, 1, xin, status )
      write(*,*) '   Current system time (UTC): ',
     :           txt( : chr_len( txt ) )
      nc = ast_unformat( tf1, 1, txt(:20), xout, status )
      if( nc .ne. 20 .or. abs( xout - xin ) .gt. 1.0E-3 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 30c' )
      end if

      tf1 = ast_timeframe( 'system=jepoch,timeorigin=2005.0', status )
      nc = ast_unformat( tf1, 1, 'J2005.0', xout, status )
      if( nc .ne. 7 .or. xout .ne. 0.0D0 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 31' )
      end if

      nc = ast_unformat( tf1, 1, 'J2010.0', xout, status )
      if( nc .ne. 7 .or. xout .ne. 5.0D0 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 32' )
      end if

      nc = ast_unformat( tf1, 1, '2005-jun-1 12:30 lunch time', xout,
     :                   status )
      if( nc .ne. 17 .or. abs( xout - 0.415525896D0 ) .gt. 1.0E-7 ) then
         write(*,*) nc, xout
         call stopit( status, 'error 33' )
      end if

      call ast_set( tf1, 'timescale=utc', status )
      nc = ast_unformat( tf1, 1, 'B2001.5 lunch time', xout,
     :                   status )
      if( nc .ne. 8 .or.
     :    abs( xout + 3.50131054408916D0 ) .gt. 1.0E-10 ) then
         write(*,*) nc, xout, abs( xout + 3.50131054408916D0 )
         call stopit( status, 'error 34' )
      end if






      tf1 = ast_timeframe( 'system=mjd,timescale=tai', status )
      nc = ast_unformat( tf1, 1, "1977-01-01 00:00:00", xin, status )


      tf2 = ast_timeframe( 'system=mjd,timescale=tai,format=iso.6',
     :                     status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 35' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status )
         txt = ast_format( tf2, 1, xout, status )
         if( txt .ne. '1977-01-01 00:00:00.000000' ) then
            write(*,*) txt( :chr_len(txt) )
            call stopit( status, 'error 36' )
         end if
      end if

      tf2 = ast_timeframe( 'system=mjd,timescale=utc,format=iso.6',
     :                     status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 37' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status )
         txt = ast_format( tf2, 1, xout, status )
         if( txt .ne. '1976-12-31 23:59:45.000000' ) then
            write(*,*) txt( :chr_len(txt) )
            call stopit( status, 'error 38' )
         end if
      end if

      tf2 = ast_timeframe( 'system=mjd,timescale=tt,format=iso.6',
     :                     status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 39' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status )
         txt = ast_format( tf2, 1, xout, status )
         if( txt .ne. '1977-01-01 00:00:32.184000' ) then
            write(*,*) txt( :chr_len(txt) )
            call stopit( status, 'error 40' )
         end if
      end if

      tf2 = ast_timeframe( 'system=mjd,timescale=tdb,format=iso.6',
     :                     status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 41' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status )
         txt = ast_format( tf2, 1, xout, status )
         if( txt .ne. '1977-01-01 00:00:32.183935' ) then
            write(*,*) txt( :chr_len(txt) )
            call stopit( status, 'error 42' )
         end if
      end if

      tf2 = ast_timeframe( 'system=mjd,timescale=tcb,format=iso.6',
     :                     status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 43' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status )
         txt = ast_format( tf2, 1, xout, status )
         if( txt .ne. '1977-01-01 00:00:32.184000' ) then
            write(*,*) txt( :chr_len(txt) )
            call stopit( status, 'error 44' )
         end if
      end if

      tf2 = ast_timeframe( 'system=mjd,timescale=tcg,format=iso.6',
     :                     status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 45' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status )
         txt = ast_format( tf2, 1, xout, status )
         if( txt .ne. '1977-01-01 00:00:32.184000' ) then
            write(*,*) txt( :chr_len(txt) )
            call stopit( status, 'error 46' )
         end if
      end if




      tf1 = ast_timeframe( 'system=mjd,timescale=gmst,ObsLon=90,'//
     :                     'ObsLat=0,timeorigin=53000.0', status )
      tf2 = ast_timeframe( 'system=mjd,timescale=lmst,ObsLon=90,'//
     :                     'ObsLat=0,timeorigin=53000.0', status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 47' )
      else
         xin = 1.0D0
         call ast_tran1( fs, 1, xin, .true., xout, status )
         if( xout .ne. 1.25D0 ) then
            write(*,*) xout
            call stopit( status, 'error 48' )
         end if
         call ast_tran1( fs, 1, xout, .false., xin, status )
         if( xin .ne. 1.0D0 ) then
            write(*,*) xin
            call stopit( status, 'error 48b' )
         end if
      end if


*  Test use of DUT1
      tf1 = ast_timeframe( 'system=mjd,timescale=tdb,dut1=0.1', status )
      tf2 = ast_timeframe( 'system=mjd,timescale=last,dut1=0.1',
     :                      status )
      fs = ast_convert( tf1, tf2, ' ', status )
      if( fs .eq. AST__NULL ) then
         call stopit( status, 'error 49' )
      else
         xin = 53991.675D0
         call ast_tran1( fs, 1, xin, .true., xout, status )
         if( abs(xout - 53998.65344633732D0) .gt. 1.0D-8 ) then
            write(*,*) xout
            call stopit( status, 'error 50' )
         end if
         call ast_tran1( fs, 1, xout, .false., xin, status )
         if( abs( xin - 53991.675D0 ) .gt. 1.0D-8 ) then
            write(*,*) xin
            call stopit( status, 'error 51' )
         end if
      end if


* Test use of DTAI
      tf1 = ast_timeframe( 'system=mjd,timescale=tai', status )
      tf2 = ast_timeframe( 'system=mjd,timescale=utc', status )

      fs = ast_convert( tf1, tf2, ' ', status )

      xin = 57844.0D0

      if (fs .eq. AST__NULL ) then
         call stopit( status, 'error 52' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status)
         if (abs(((xin - xout) * 86400.0D0) - 37.0D0) .gt. 1.0D-3) then
            write(*,*) xout
            call stopit( status, 'error 53' )
         endif
         call checkdump( fs, 'CheckDump 2', status )
      end if

      call ast_setd( tf2, 'dtai', 40.0D0, status )

      fs = ast_convert( tf1, tf2, ' ', status )

      if (fs .eq. AST__NULL ) then
         call stopit( status, 'error 54' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status)
         if (abs(((xin - xout) * 86400.0D0) - 40.0D0) .gt. 1.0D-3) then
            write(*,*) xout
            call stopit( status, 'error 55' )
         endif
         call checkdump( fs, 'CheckDump 3', status )
      end if



      tf1 = ast_timeframe( 'system=mjd,timescale=tt', status )
      tf2 = ast_timeframe( 'system=mjd,timescale=tdb,dtai=37.0',
     :                     status )

      fs = ast_convert( tf1, tf2, ' ', status )

      if (fs .eq. AST__NULL ) then
         call stopit( status, 'error 56' )
      else
         call ast_tran1( fs, 1, xin, .true., xout, status)
         call checkdump( fs, 'CheckDump 4', status )
      end if

      call ast_clear( tf2, 'dtai', status )

      fs = ast_convert( tf1, tf2, ' ', status )

      if (fs .eq. AST__NULL ) then
         call stopit( status, 'error 57' )
      else
         call ast_tran1( fs, 1, xin, .true., xout2, status)
         if( xout .ne. xout2 ) then
            call stopit( status, 'error 58' )
         end if
      end if






      call ast_end( status )
c      call ast_listissued( 'testtime' )



      if( status .eq. sai__ok ) then
         write(*,*) 'All timeFrame tests passed'
      else
         write(*,*) 'timeFrame tests failed'
      end if

      end

      subroutine stopit( status, text )
      implicit none
      include 'SAE_PAR'
      integer status
      character text*(*)

      if( status .ne. sai__ok ) return
      status = sai__error
      write(*,*) text

      end


      subroutine checkdump( obj, text, status )
      implicit none
      include 'SAE_PAR'
      include 'AST_PAR'
      character text*(*)
      integer obj, status, next, end, ch, result, ll, overlap, map,
     :        map1, map2
      external mysource, mysink
      character buf*25000

      common /ss1/ buf
      common /ss2/ next, end, ll

      if( status .ne. sai__ok ) return

      ch = ast_channel( mysource, mysink, ' ', status )


      ll = 110
      next = 1
      if( ast_write( ch, obj, status ) .ne.1 ) then
         write(*,*) text
         call stopit( status, 'Cannot write supplied object to '//
     :                'channel' )
      end if

      next = 1
      result = ast_read( ch, status )
      if( result .eq. ast__null ) then
         write(*,*) text
         call stopit( status, 'Cannot read object from channel' )
      end if


      if( ast_isatimeframe( obj, status ) ) then
         if( ast_getd( obj, 'timeorigin', status ) .ne.
     :       ast_getd( result, 'timeorigin', status ) .or.
     :       ast_getc( obj, 'timescale', status ) .ne.
     :       ast_getc( result, 'timescale', status ) .or.
     :       ast_getc( obj, 'ObsLon', status ) .ne.
     :       ast_getc( result, 'ObsLon', status ) .or.
     :       ast_getc( obj, 'ObsLat', status ) .ne.
     :       ast_getc( result, 'ObsLat', status ) .or.
     :       ast_getc( obj, 'Dtai', status ) .ne.
     :       ast_getc( result, 'Dtai', status ) ) then
            call ast_Show( obj, status )
            call ast_Show( result, status )
            write(*,*) text
            call stopit( status, 'Object has changed' )
         end if
      else if( ast_isamapping( obj, status ) ) then
         if( ast_isaframeset( obj, status ) ) then
            map1 = ast_getmapping( obj, ast__base, ast__current,
     :                             status )
            map2 = ast_getmapping( result, ast__base, ast__current,
     :                             status )
         else
            map1 = ast_clone( obj, status )
            map2 = ast_clone( result, status )
         end if

         call ast_invert( map2, status )
         map = ast_simplify( ast_cmpmap( map1, map2, .true., ' ',
     :                                   status ),
     :                       status )
         if( .not. ast_isaunitmap( map, status ) ) then
            write(*,*) text
            call ast_show( map1, status )
            call ast_invert( map2, status )
            call ast_show( map2, status )

            call stopit( status, 'Mapping has changed' )
         endif
      end if

      end

      subroutine sink1( status )
      implicit none
      include 'SAE_PAR'
      include 'AST_PAR'

      logical fsfound, done
      common /sink1com/ fsfound, done

      integer status, l
      character line*200

      if( status .ne. sai__ok ) return
      call ast_getline( line, l, status )

      if( index( line( : l ),'Unc =' ) .GT. 0 ) then
         done = .true.

      else if( .not. done .and.
     :         index( line( : l ),'FrameSet' ) .GT. 0 ) then
         fsfound= .true.
      end if

      end

      subroutine mysource( status )
      implicit none
      include 'SAE_PAR'
      include 'AST_PAR'
      integer status, next, end, ll
      character buf*25000

      common /ss1/ buf
      common /ss2/ next, end, ll

      if( status .ne. sai__ok ) return

      if( next .ge. end ) then
         call ast_putline( buf, -1, status )
      else
         call ast_putline( buf( next : ), ll, status )
      endif

      next = next + ll

      end

      subroutine mysink( status )
      implicit none
      include 'SAE_PAR'
      include 'AST_PAR'
      integer status, next, end, f, l, ll
      character buf*25000
      character line*1000

      common /ss1/ buf
      common /ss2/ next, end, ll

      if( status .ne. sai__ok ) return

      line = ' '
      call ast_getline( line, l, status )
      call chr_fandl( line( : l ), f, l )
      buf( next : ) = line( f : l )
      l = l - f + 1

      if( next + ll - 1 .ge. 25000 ) then
         write(*,*)
         call stopit( status, 'Buffer overflow in mysink!!' )
      else if( l .gt. ll ) then
         write(*,*)
         write(*,*) buf( next : next + l)
         write(*,*) 'Line length ',l
         call stopit( status, 'Line overflow in mysink!!' )
      else
         end = next + l
         buf( end : next + ll - 1 ) = ' '
      endif

      next = next + ll

      end