File: fcblib_defines.m4

package info (click to toggle)
cbflib 0.9.7%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 65,244 kB
  • sloc: ansic: 131,361; python: 22,780; sh: 3,048; makefile: 2,086; yacc: 659; java: 223; f90: 214; xml: 210; cpp: 58
file content (896 lines) | stat: -rw-r--r-- 44,714 bytes parent folder | download | duplicates (3)
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
m4_define(`fcb_not_first',`')m4_dnl
m4_define(`fcb_is_last',`is_last')m4_dnl
m4_dnl Error codes:
m4_define(`fcb_errcode_CBF_FORMAT',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FORMAT            = int(Z''`00000001''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !      1')m4_dnl
m4_define(`fcb_errcode_CBF_ALLOC',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_ALLOC             = int(Z''`00000002''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !      2')m4_dnl
m4_define(`fcb_errcode_CBF_ARGUMENT',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_ARGUMENT          = int(Z''`00000004''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !      4')m4_dnl
m4_define(`fcb_errcode_CBF_ASCII',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_ASCII             = int(Z''`00000008''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !      8')m4_dnl
m4_define(`fcb_errcode_CBF_BINARY',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_BINARY            = int(Z''`00000010''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !     16')m4_dnl
m4_define(`fcb_errcode_CBF_BITCOUNT',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_BITCOUNT          = int(Z''`00000020''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !     32')m4_dnl
m4_define(`fcb_errcode_CBF_ENDOFDATA',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_ENDOFDATA         = int(Z''`00000040''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !     64')m4_dnl
m4_define(`fcb_errcode_CBF_FILECLOSE',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FILECLOSE         = int(Z''`00000080''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !    128')m4_dnl
m4_define(`fcb_errcode_CBF_FILEOPEN',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FILEOPEN          = int(Z''`00000100''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !    256')m4_dnl
m4_define(`fcb_errcode_CBF_FILEREAD',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FILEREAD          = int(Z''`00000200''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !    512')m4_dnl
m4_define(`fcb_errcode_CBF_FILESEEK',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FILESEEK          = int(Z''`00000400''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !   1024')m4_dnl
m4_define(`fcb_errcode_CBF_FILETELL',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FILETELL          = int(Z''`00000800''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !   2048')m4_dnl
m4_define(`fcb_errcode_CBF_FILEWRITE',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FILEWRITE         = int(Z''`00001000''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !   4096')m4_dnl
m4_define(`fcb_errcode_CBF_IDENTICAL',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_IDENTICAL         = int(Z''`00002000''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !   8192')m4_dnl
m4_define(`fcb_errcode_CBF_NOTFOUND',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_NOTFOUND          = int(Z''`00004000''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !  16384')m4_dnl
m4_define(`fcb_errcode_CBF_OVERFLOW',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_OVERFLOW          = int(Z''`00008000''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !  32768')m4_dnl
m4_define(`fcb_errcode_CBF_UNDEFINED',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_UNDEFINED         = int(Z''`00010000''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !  65536')m4_dnl
m4_define(`fcb_errcode_CBF_NOTIMPLEMENTED',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_NOTIMPLEMENTED    = int(Z''`00020000''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` ! 131072')m4_dnl
m4_define(`fcb_errcode_LIST_ALL',
m4_define(`fcb_is_last',`')m4_dnl
!
      !     Definitions of CBF error code parameters
      !
      fcb_errcode_CBF_FORMAT
m4_define(`fcb_not_first',`not_first')m4_dnl
        fcb_errcode_CBF_ALLOC
        fcb_errcode_CBF_ARGUMENT
        fcb_errcode_CBF_ASCII
        fcb_errcode_CBF_BINARY
        fcb_errcode_CBF_BITCOUNT
        fcb_errcode_CBF_ENDOFDATA
        fcb_errcode_CBF_FILECLOSE
        fcb_errcode_CBF_FILEOPEN
        fcb_errcode_CBF_FILEREAD
        fcb_errcode_CBF_FILESEEK
        fcb_errcode_CBF_FILETELL
        fcb_errcode_CBF_FILEWRITE
        fcb_errcode_CBF_IDENTICAL
        fcb_errcode_CBF_NOTFOUND
        fcb_errcode_CBF_OVERFLOW
        fcb_errcode_CBF_UNDEFINED
m4_define(`fcb_is_last',`is_last')m4_dnl
        fcb_errcode_CBF_NOTIMPLEMENTED
m4_define(`fcb_not_first',`')m4_dnl
)m4_dnl
m4_dnl
m4_dnl Possible parameter values for ENCODING are:
m4_define(`fcb_param_ENC_NONE',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')ENC_NONE         = int(Z''`0001''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Use BINARY encoding')m4_dnl
m4_define(`fcb_param_ENC_BASE64',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')ENC_BASE64       = int(Z''`0002''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Use BASE64 encoding')m4_dnl
m4_define(`fcb_param_ENC_BASE32k',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')ENC_BASE32K      = int(Z''`0004''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Use X-BASE32K encoding')m4_dnl
m4_define(`fcb_param_ENC_QP',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')ENC_QP           = int(Z''`0008''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Use QUOTED-PRINTABLE encoding')m4_dnl
m4_define(`fcb_param_ENC_BASE10',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')ENC_BASE10       = int(Z''`0010''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Use BASE10 encoding')m4_dnl
m4_define(`fcb_param_ENC_BASE16',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')ENC_BASE16       = int(Z''`0020''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Use BASE16 encoding')m4_dnl
m4_define(`fcb_param_ENC_BASE8',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')ENC_BASE8        = int(Z''`0040''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Use BASE8  encoding')m4_dnl
m4_define(`fcb_param_ENC_LIST_ALL',
m4_define(`fcb_is_last',`')m4_dnl
!
      !     Definitions of CBF encodings parameters
      !
      fcb_param_ENC_NONE
m4_define(`fcb_not_first',`not_first')m4_dnl
        fcb_param_ENC_BASE64
        fcb_param_ENC_BASE32k
        fcb_param_ENC_QP
        fcb_param_ENC_BASE10
        fcb_param_ENC_BASE16
m4_define(`fcb_is_last',`is_last')m4_dnl
        fcb_param_ENC_BASE8
m4_define(`fcb_not_first',`')m4_dnl
)m4_dnl
m4_dnl
m4_dnl Possible parameter values for COMPRESSION are:
m4_dnl
m4_define(`fcb_param_CBF_INTEGER',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_INTEGER      = int(Z''`0010''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Uncompressed integer')m4_dnl
m4_define(`fcb_param_CBF_FLOAT',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FLOAT        = int(Z''`0020''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Uncompressed IEEE floating point')m4_dnl
m4_define(`fcb_param_CBF_CANONICAL',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_CANONICAL    = int(Z''`0050''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Canonical compression')m4_dnl
m4_define(`fcb_param_CBF_PACKED',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_PACKED       = int(Z''`0060''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Packed compression')m4_dnl
m4_define(`fcb_param_CBF_PACKED_V2',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_PACKED_V2    = int(Z''`0090''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Packed compression')m4_dnl
m4_define(`fcb_param_CBF_BYTE_OFFSET',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_BYTE_OFFSET  = int(Z''`0070''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Byte Offset Compression')m4_dnl
m4_define(`fcb_param_CBF_PREDICTOR',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_PREDICTOR    = int(Z''`0080''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Predictor_Huffman Compression')m4_dnl
m4_define(`fcb_param_CBF_NONE',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_NONE         = int(Z''`0040''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !No compression flag')m4_dnl
m4_define(`fcb_param_CBF_COMPRESSION_MASK',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_COMPRESSION_MASK =     &
                           int(Z''`00FF''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Mask to sep compressiontype from flags')m4_dnl
m4_define(`fcb_param_CBF_FLAG_MASK',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FLAG_MASK    = int(Z''`0F00''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Mask to sep flags from compression type')m4_dnl
m4_define(`fcb_param_CBF_UNCORRELATED_SECTIONS',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_UNCORRELATED_SECTIONS =&
                           int(Z''`0100''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Flag for uncorrelated sections')m4_dnl
m4_define(`fcb_param_CBF_FLAT_IMAGE',
`m4_ifelse(fcb_not_first,`',``INTEGER,PARAMETER:: &
        '',``'')CBF_FLAT_IMAGE   = int(Z''`0200''`)m4_ifelse(fcb_is_last,`is_last',`   ',``, &'')'` !Flag for flat (linear) images')m4_dnl
m4_define(`fcb_param_CBF_LIST_ALL',
m4_define(`fcb_is_last',`')m4_dnl
!
      !     Definitions of CBF compression parameters
      !
      fcb_param_CBF_INTEGER
m4_define(`fcb_not_first',`not_first')m4_dnl
        fcb_param_CBF_FLOAT
        fcb_param_CBF_CANONICAL
        fcb_param_CBF_PACKED
        fcb_param_CBF_PACKED_V2
        fcb_param_CBF_BYTE_OFFSET
        fcb_param_CBF_PREDICTOR
        fcb_param_CBF_NONE
        fcb_param_CBF_COMPRESSION_MASK
        fcb_param_CBF_FLAG_MASK
        fcb_param_CBF_UNCORRELATED_SECTIONS
m4_define(`fcb_is_last',`is_last')m4_dnl
        fcb_param_CBF_FLAT_IMAGE
m4_define(`fcb_not_first',`')m4_dnl
)m4_dnl
m4_dnl
m4_dnl fcblib function interfaces
m4_dnl
m4_define(`fcb_interface_FCB_ATOL_WCNT',
      `INTERFACE
      INTEGER(8) FUNCTION FCB_ATOL_WCNT(ARRAY,N,CNT)
!-----------------------------------------------------------------------
!     Converts bytes in ARRAY to an INTEGER(8), consuming CNT bytes
!-----------------------------------------------------------------------
      INTEGER,  INTENT(OUT):: CNT
      INTEGER,   INTENT(IN):: N
      INTEGER(1),INTENT(IN):: ARRAY(N)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_CI_STRNCMPARR',
      `INTERFACE
      INTEGER FUNCTION FCB_CI_STRNCMPARR(STRING, ARRAY, N, LIMIT)
!-----------------------------------------------------------------------
! Compares up to LIMIT characters of STRING and ARRAY case insensitive
!-----------------------------------------------------------------------
      CHARACTER(LEN=*),INTENT(IN):: STRING
      INTEGER,         INTENT(IN):: N,LIMIT
      INTEGER(1),      INTENT(IN):: ARRAY(N)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_DECOMPRESS_PACKED_I2',
      `INTERFACE
      INTEGER FUNCTION FCB_DECOMPRESS_PACKED_I2 (ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2,      &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,  &
        REC_IN_FILE,BUFFER)
      INTEGER(8),   INTENT(IN):: DIM1,DIM2 
      INTEGER(2),  INTENT(OUT):: ARRAY(DIM1,DIM2)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN, COMPRESSION
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_DECOMPRESS_PACKED_I4',
      `INTERFACE
      INTEGER FUNCTION FCB_DECOMPRESS_PACKED_I4 (ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2,  &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,                   &
        REC_IN_FILE,BUFFER)
      INTEGER(8),   INTENT(IN):: DIM1,DIM2 
      INTEGER(4),  INTENT(OUT):: ARRAY(DIM1,DIM2)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN, COMPRESSION
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_DECOMPRESS_PACKED_3D_I2',
      `INTERFACE
      INTEGER FUNCTION FCB_DECOMPRESS_PACKED_3D_I2 (ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2, DIM3,  &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,                   &
        REC_IN_FILE,BUFFER)
      INTEGER(8),   INTENT(IN):: DIM1,DIM2,DIM3 
      INTEGER(2),  INTENT(OUT):: ARRAY(DIM1,DIM2,DIM3)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN, COMPRESSION
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_DECOMPRESS_PACKED_3D_I4',
      `INTERFACE
      INTEGER FUNCTION FCB_DECOMPRESS_PACKED_3D_I4 (ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2, DIM3,  &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,                   &
        REC_IN_FILE,BUFFER)
      INTEGER(8),   INTENT(IN):: DIM1,DIM2,DIM3 
      INTEGER(4),  INTENT(OUT):: ARRAY(DIM1,DIM2,DIM3)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN, COMPRESSION
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_EXIT_BINARY',
      `INTERFACE
      INTEGER FUNCTION FCB_EXIT_BINARY(TAPIN,LAST_CHAR,FCB_BYTES_IN_REC,&
                                      BYTE_IN_FILE,REC_IN_FILE,BUFFER,  &
                                      PADDING )
!-----------------------------------------------------------------------
!     Skip to end of binary section that was just read
!-----------------------------------------------------------------------
      INTEGER,   INTENT(IN)   :: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: BYTE_IN_FILE,REC_IN_FILE
      INTEGER(1),INTENT(INOUT):: LAST_CHAR,BUFFER(FCB_BYTES_IN_REC)
      INTEGER(8),INTENT(IN)   :: PADDING
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_NBLEN_ARRAY',
      `INTERFACE
      INTEGER FUNCTION FCB_NBLEN_ARRAY(ARRAY, ARRAYLEN)
!-----------------------------------------------------------------------
!     Returns the non-blank length of an array
!-----------------------------------------------------------------------
      INTEGER,    INTENT(IN):: ARRAYLEN
      INTEGER(1), INTENT(IN):: ARRAY(ARRAYLEN)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_NEXT_BINARY',
      `INTERFACE
      INTEGER FUNCTION FCB_NEXT_BINARY(TAPIN,LAST_CHAR,FCB_BYTES_IN_REC,&
                                      BYTE_IN_FILE,REC_IN_FILE,BUFFER,  &
                                      ENCODING,SIZE,ID,DIGEST,          &
                                      COMPRESSION,BITS,VORZEICHEN,REELL,&
                                      BYTEORDER,DIMOVER,DIM1,DIM2,DIM3, &
                                      PADDING )
!-----------------------------------------------------------------------
!     Skip to the next binary and parse MIME header.
!-----------------------------------------------------------------------
      INTEGER,   INTENT(IN)   :: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: BYTE_IN_FILE,REC_IN_FILE
      INTEGER(1),INTENT(INOUT):: LAST_CHAR,BUFFER(FCB_BYTES_IN_REC)
      INTEGER,   INTENT(OUT)  :: ENCODING,SIZE,ID,COMPRESSION,BITS,  &
                                 VORZEICHEN,REELL
      CHARACTER(*), INTENT(OUT):: BYTEORDER,DIGEST
      INTEGER(8),      INTENT(OUT):: DIMOVER
      INTEGER(8),      INTENT(OUT):: DIM1
      INTEGER(8),      INTENT(OUT):: DIM2
      INTEGER(8),      INTENT(OUT):: DIM3
      INTEGER(8),      INTENT(OUT):: PADDING

      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_OPEN_CIFIN',
      `INTERFACE
      INTEGER FUNCTION FCB_OPEN_CIFIN(FILNAM,TAPIN,LAST_CHAR,                &
      FCB_BYTES_IN_REC,BYTE_IN_FILE,REC_IN_FILE,BUFFER)
!-----------------------------------------------------------------------
! --  Open CBF file named FILNAM and connect to unit number TAPIN
!-----------------------------------------------------------------------
!     We have chosen to use the direct access method to read the file
!     with explicit buffer handling. This approach is general but
!     clumpsy. Rather than putting the buffer and its control variables
!     into COMMON these are passed as local arguments to make the routines
!     inherently ''`threadsafe''` in a parallel programming environment.
!     Note also, that a reading error could occur for the last record
!     if it did not fill a full block. This could be avoided if the
!     images were padded with a sufficient number of additional bytes
!     (arbitrary values) after the end of the valid binary data.
!
!     The more natural method would use byte stream I/O which is,
!     unfortunately, only an extension of Fortran 90 that has been
!     implemented in some compilers (like the Intel ifort) but
!     not in all (like the SGI IRIX f90).
!     For BSD style opens, there is a special variant on the direct
!     access open with a recl of 1 to give byte-by-byte access.
!-----------------------------------------------------------------------
! FILNAM   - Name of the file countaining the image              (GIVEN)
! TAPIN    - Fortran device unit number assigned to image file   (GIVEN)
! LAST_CHAR - 
!            Last character read                                (RESULT)
! FCB_BYTES_IN_REC -
!            Number of bytes in a record                         (GIVEN)
! BYTE_IN_FILE -
!            Byte (counting from 1) of the byte to read         (RESULT)
! REC_IN_FILE -
!            Record (counting from 1) of next record to read    (RESULT)
! BUFFER -   Array of length FCB_BYTES_IN_REC                    (GIVEN)
!-----------------------------------------------------------------------
      IMPLICIT                   NONE
      CHARACTER(len=*),INTENT(IN) :: FILNAM
      INTEGER,         INTENT(IN) :: TAPIN,FCB_BYTES_IN_REC
      INTEGER(1),      INTENT(OUT):: LAST_CHAR
      INTEGER,         INTENT(OUT):: BYTE_IN_FILE,REC_IN_FILE
      INTEGER(1),    INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl

m4_dnl
m4_define(`fcb_interface_FCB_READ_BITS',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_BITS(TAPIN,FCB_BYTES_IN_REC,BUFFER,     &
				     REC_IN_FILE,BYTE_IN_FILE,BCOUNT,BBYTE,             &
				     BITCOUNT,IINT,LINT)
!-----------------------------------------------------------------------
! Get integer value starting at BYTE_IN_FILE from file TAPIN
! continuing through BITCOUNT bits, with sign extension.  
! (first byte is BYTE_IN_FILE=1)
!-----------------------------------------------------------------------
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      INTEGER,   INTENT(INOUT):: BCOUNT
      INTEGER(1),INTENT(INOUT):: BBYTE
      INTEGER,      INTENT(IN):: BITCOUNT
      INTEGER,      INTENT(IN):: LINT
      INTEGER(4),  INTENT(OUT):: IINT(LINT)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_BYTE',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_BYTE(TAPIN,FCB_BYTES_IN_REC,BUFFER,     &
				     REC_IN_FILE,BYTE_IN_FILE,IBYTE)
!-----------------------------------------------------------------------
! Get byte number BYTE_IN_FILE from file  (first byte is BYTE_IN_FILE=1)
!-----------------------------------------------------------------------
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      INTEGER(1),  INTENT(OUT):: IBYTE
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_LINE',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_LINE(TAPIN,LAST_CHAR,FCB_BYTES_IN_REC,  &
			 BYTE_IN_FILE,REC_IN_FILE,BUFFER,LINE,N,LINELEN)
!-----------------------------------------------------------------------
!     Reads successive bytes into byte array LINE(N), stopping at N,
!     error or first CR(Z''`0D''`) or LF(Z''`0A''`), discarding a LF after a CR.
!-----------------------------------------------------------------------
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC,N
      INTEGER,   INTENT(INOUT):: BYTE_IN_FILE,REC_IN_FILE
      INTEGER,     INTENT(OUT):: LINELEN
      INTEGER(1),INTENT(INOUT):: LAST_CHAR,BUFFER(FCB_BYTES_IN_REC)
      INTEGER(1),  INTENT(OUT):: LINE(N)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_IMAGE_I2',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_IMAGE_I2(ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2, PADDING,                &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,                     &
        REC_IN_FILE,BUFFER)
      
!-----------------------------------------------------------------------
! Reads a 16-bit integer twos complement 2D image
!
! compressed by a BYTE_OFFSET algorithm by W. Kabsch based
! on a proposal by A. Hammersley or
! compressed by a PACKED algorithm by J. P. Abrahams as
! used in CCP4, with modifications by P. Ellis and
! H. J. Bernstein.
!
! The BYTE-OFFSET algorithm is a slightly simplified version of
! that described in Andy Hammersley''`s web page
! (http://www.esrf.fr/computing/Forum/imgCIF/cbf_definition.html)
!
!-----------------------------------------------------------------------
! ARRAY    - Image                                              (RESULT)
! NELEM    - The number of elements to be read                   (GIVEN)
! NELEM_READ
!          - The number of elements actually read               (RESULT)
! ELSIGN   - Flag for signed (1) OR unsigned (0) data            (GIVEN)
! COMPRESSION
!          - The actual compression of the image                (RESULT)
! DIM1     - The fastest dimension of ARRAY                      (GIVEN)
! DIM2     - The slowest dimension                               (GIVEN)
! TAPIN    - Fortran device unit number assigned to image file   (GIVEN)
! FCB_BYTES_IN_REC
!          - The number of bytes in each bufferload to read      (GIVEN)
! BYTE_IN_FILE
!          - The position in the file of the next byte to read   (GIVEN,
!                                                                RESULT)
! REC_IN_FILE
!          - The record number from 1 of the block in BUFFER     (GIVEN,
!                                                                RESULT)
! BUFFER   - Buffer of bytes read from the file                  (GIVEN,
!                                                                RESULT)
! PADDING  - Pad bytes after the binary                         (RESULT)
!
! Returns (as function value)                                   (RESULT)
!             CBF_FORMAT (=1): 
!                cannot handle this CBF format (not implemented)
!             0: No error
!-----------------------------------------------------------------------
      INTEGER(8),   INTENT(IN):: DIM1,DIM2
      INTEGER(2),  INTENT(OUT):: ARRAY(DIM1,DIM2)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN
      INTEGER,     INTENT(OUT):: COMPRESSION
      INTEGER(8),  INTENT(OUT):: PADDING
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_IMAGE_I4',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_IMAGE_I4(ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2, PADDING,                &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,                     &
        REC_IN_FILE,BUFFER)
      
!-----------------------------------------------------------------------
! Reads a 32-bit integer twos complement 2D image
!
! compressed by a BYTE_OFFSET algorithm by W. Kabsch based
! on a proposal by A. Hammersley or
! compressed by a PACKED algorithm by J. P. Abrahams as
! used in CCP4, with modifications by P. Ellis and
! H. J. Bernstein.
!
! The BYTE-OFFSET algorithm is a slightly simplified version of
! that described in Andy Hammersley''`s web page
! (http://www.esrf.fr/computing/Forum/imgCIF/cbf_definition.html)
!
!-----------------------------------------------------------------------
! ARRAY    - Image                                              (RESULT)
! NELEM    - The number of elements to be read                   (GIVEN)
! NELEM_READ
!          - The number of elements actually read               (RESULT)
! ELSIGN   - Flag for signed (1) OR unsigned (0) data            (GIVEN)
! COMPRESSION
!          - The actual compression of the image                (RESULT)
! DIM1     - The fastest dimension of ARRAY                      (GIVEN)
! DIM2     - The slowest dimension                               (GIVEN)
! TAPIN    - Fortran device unit number assigned to image file   (GIVEN)
! FCB_BYTES_IN_REC
!          - The number of bytes in each bufferload to read      (GIVEN)
! BYTE_IN_FILE
!          - The position in the file of the next byte to read   (GIVEN,
!                                                                RESULT)
! REC_IN_FILE
!          - The record number from 1 of the block in BUFFER     (GIVEN,
!                                                                RESULT)
! BUFFER   - Buffer of bytes read from the file                  (GIVEN,
!                                                                RESULT)
! PADDING  - Pad bytes after the binary                         (RESULT)
!
! Returns (as function value)                                   (RESULT)
!             CBF_FORMAT (=1): 
!                cannot handle this CBF format (not implemented)
!             0: No error
!-----------------------------------------------------------------------
      INTEGER(8),   INTENT(IN):: DIM1,DIM2
      INTEGER(4),  INTENT(OUT):: ARRAY(DIM1,DIM2)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN
      INTEGER,     INTENT(OUT):: COMPRESSION
      INTEGER(8),  INTENT(OUT):: PADDING
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_IMAGE_3D_I2',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_IMAGE_3D_I2(ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2, DIM3, PADDING,        &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,                   &
        REC_IN_FILE,BUFFER)
      
!-----------------------------------------------------------------------
! Reads a 16-bit integer twos complement 3D image
!
! compressed by a BYTE_OFFSET algorithm by W. Kabsch based
! on a proposal by A. Hammersley or
! compressed by a PACKED algorithm by J. P. Abrahams as
! used in CCP4, with modifications by P. Ellis and
! H. J. Bernstein.
!
! The BYTE-OFFSET algorithm is a slightly simplified version of
! that described in Andy Hammersley''`s web page
! (http://www.esrf.fr/computing/Forum/imgCIF/cbf_definition.html)
!
!-----------------------------------------------------------------------
! ARRAY    - Image                                              (RESULT)
! NELEM    - The number of elements to be read                   (GIVEN)
! NELEM_READ
!          - The number of elements actually read               (RESULT)
! ELSIGN   - Flag for signed (1) OR unsigned (0) data            (GIVEN)
! COMPRESSION
!          - The actual compression of the image                (RESULT)
! DIM1     - The fastest dimension of ARRAY                      (GIVEN)
! DIM2     - The slowest dimension                               (GIVEN)
! TAPIN    - Fortran device unit number assigned to image file   (GIVEN)
! FCB_BYTES_IN_REC
!          - The number of bytes in each bufferload to read      (GIVEN)
! BYTE_IN_FILE
!          - The position in the file of the next byte to read   (GIVEN,
!                                                                RESULT)
! REC_IN_FILE
!          - The record number from 1 of the block in BUFFER     (GIVEN,
!                                                                RESULT)
! BUFFER   - Buffer of bytes read from the file                  (GIVEN,
!                                                                RESULT)
! PADDING  - Pad bytes after the binary                         (RESULT)
!
! Returns (as function value)                                   (RESULT)
!             CBF_FORMAT (=1): 
!                cannot handle this CBF format (not implemented)
!             0: No error
!-----------------------------------------------------------------------
      INTEGER(8),   INTENT(IN):: DIM1,DIM2,DIM3
      INTEGER(2),  INTENT(OUT):: ARRAY(DIM1,DIM2,DIM3)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN
      INTEGER,     INTENT(OUT):: COMPRESSION
      INTEGER(8),  INTENT(OUT):: PADDING
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_IMAGE_3D_I4',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_IMAGE_3D_I4(ARRAY,NELEM,NELEM_READ, &
        ELSIGN, COMPRESSION, DIM1, DIM2, DIM3, PADDING,        &
        TAPIN,FCB_BYTES_IN_REC,BYTE_IN_FILE,                   &
        REC_IN_FILE,BUFFER)
      
!-----------------------------------------------------------------------
! Reads a 32-bit integer twos complement 3D image
!
! compressed by a BYTE_OFFSET algorithm by W. Kabsch based
! on a proposal by A. Hammersley or
! compressed by a PACKED algorithm by J. P. Abrahams as
! used in CCP4, with modifications by P. Ellis and
! H. J. Bernstein.
!
! The BYTE-OFFSET algorithm is a slightly simplified version of
! that described in Andy Hammersley''`s web page
! (http://www.esrf.fr/computing/Forum/imgCIF/cbf_definition.html)
!
!-----------------------------------------------------------------------
! ARRAY    - Image                                              (RESULT)
! NELEM    - The number of elements to be read                   (GIVEN)
! NELEM_READ
!          - The number of elements actually read               (RESULT)
! ELSIGN   - Flag for signed (1) OR unsigned (0) data            (GIVEN)
! COMPRESSION
!          - The actual compression of the image                (RESULT)
! DIM1     - The fastest dimension of ARRAY                      (GIVEN)
! DIM2     - The slowest dimension                               (GIVEN)
! TAPIN    - Fortran device unit number assigned to image file   (GIVEN)
! FCB_BYTES_IN_REC
!          - The number of bytes in each bufferload to read      (GIVEN)
! BYTE_IN_FILE
!          - The position in the file of the next byte to read   (GIVEN,
!                                                                RESULT)
! REC_IN_FILE
!          - The record number from 1 of the block in BUFFER     (GIVEN,
!                                                                RESULT)
! BUFFER   - Buffer of bytes read from the file                  (GIVEN,
!                                                                RESULT)
! PADDING  - Pad bytes after the binary                         (RESULT)
!
! Returns (as function value)                                   (RESULT)
!             CBF_FORMAT (=1): 
!                cannot handle this CBF format (not implemented)
!             0: No error
!-----------------------------------------------------------------------
      INTEGER(8),   INTENT(IN):: DIM1,DIM2,DIM3
      INTEGER(4),  INTENT(OUT):: ARRAY(DIM1,DIM2,DIM3)
      INTEGER(8),  INTENT(OUT):: NELEM_READ
      INTEGER(8),   INTENT(IN):: NELEM
      INTEGER,      INTENT(IN):: ELSIGN
      INTEGER,     INTENT(OUT):: COMPRESSION
      INTEGER(8),  INTENT(OUT):: PADDING
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_INTEGER',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_INTEGER(TAPIN,FCB_BYTES_IN_REC,BUFFER,     &
				     REC_IN_FILE,BYTE_IN_FILE,BCOUNT,BBYTE,                &
				     VALSIGN,BITCOUNT,IINT,LINT)
!-----------------------------------------------------------------------
! Get integer value starting at BYTE_IN_FILE from file TAPIN
! continuing through BITCOUNT bits, with optional sign extension.  
! (first byte is BYTE_IN_FILE=1)
!-----------------------------------------------------------------------
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC
      INTEGER,   INTENT(INOUT):: REC_IN_FILE,BYTE_IN_FILE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC)
      INTEGER,   INTENT(INOUT):: BCOUNT
      INTEGER(1),INTENT(INOUT):: BBYTE
      INTEGER,      INTENT(IN):: VALSIGN,BITCOUNT
      INTEGER,      INTENT(IN):: LINT
      INTEGER(4),  INTENT(OUT):: IINT(LINT)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_READ_XDS_I2',
      `INTERFACE
      INTEGER FUNCTION FCB_READ_XDS_I2(FILNAM,TAPIN,NX,NY,IFRAME,JFRAME)
!-----------------------------------------------------------------------
! Reads a 32 bit integer two''`s complement image compressed by a
! BYTE-OFFSET algorithm. W. Kabsch,  Version 9-2006
!
! REVISED 1-2007, H. J. Bernstein to conform to CBFlib_0.7.7
! (http://www.bernstein-plus-sons.com/software/CBF)
!
! The BYTE-OFFSET algorithm is a slightly simplified version of
! that described in Andy Hammersley''`s web page
! (http://www.esrf.fr/computing/Forum/imgCIF/cbf_definition.html)
!
!-----------------------------------------------------------------------
! FILNAM   - Name of the file countaining the image              (GIVEN)
! TAPIN    - Fortran device unit number assigned to image file   (GIVEN)
!   NX     - Number of "fast" pixels of the image                (GIVEN)
!   NY     - Number of "slow" pixels of the image                (GIVEN)
! IFRAME   - 16 bit coded image as needed by XDS                (RESULT)
! JFRAME   - 32 bit scratch array                               (RESULT)
! Returns (as function value)                                   (RESULT)
!             1: cannot handle this CBF format (not implemented)
!             0: No error
!            -1: Cannot determine endian architecture of this machine
!            -2: Cannot open image file
!            -3: Wrong image format
!            -4: Cannot read image
!-----------------------------------------------------------------------
      IMPLICIT                       NONE
      CHARACTER(len=*),INTENT(IN) :: FILNAM
      INTEGER,         INTENT(IN) :: TAPIN,NX,NY
      INTEGER(2),      INTENT(OUT):: IFRAME(NX*NY)
      INTEGER(4),      INTENT(OUT):: JFRAME(NX,NY)
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_SKIP_WHITESPACE',
      `INTERFACE
      INTEGER FUNCTION FCB_SKIP_WHITESPACE(TAPIN,LAST_CHAR,             &
		       FCB_BYTES_IN_REC,BYTE_IN_FILE,REC_IN_FILE,BUFFER,&
		       LINE,N,LINELEN,ICUR,FRESH_LINE)
!-----------------------------------------------------------------------
!     Skips forward on the current LINE of size N with data in
!     LINE(1:LINELEN) from the current position ICUR moving over
!     whitespace and comments, reading new lines into LINE if
!     needed. The flag FRESH_LINE indicates that a fresh line
!     should be read on entry.
!-----------------------------------------------------------------------
      INTEGER,      INTENT(IN):: TAPIN,FCB_BYTES_IN_REC,N
      INTEGER,   INTENT(INOUT):: BYTE_IN_FILE,REC_IN_FILE,LINELEN,ICUR, &
				 FRESH_LINE
      INTEGER(1),INTENT(INOUT):: BUFFER(FCB_BYTES_IN_REC),LINE(N),      &
				 LAST_CHAR
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_UPDATE_JPA_POINTERS_I2',
      `INTERFACE
      INTEGER FUNCTION FCB_UPDATE_JPA_POINTERS_I2(TRAIL_INDEX_ARRAY,&
        NDIM1, NDIM2, ARRAY, DIM1, DIM2, AVERAGE, COMPRESSION)      
      INTEGER(8),INTENT(INOUT):: TRAIL_INDEX_ARRAY(4), NDIM1, NDIM2 
      INTEGER(8),   INTENT(IN):: DIM1,DIM2
      INTEGER(2),   INTENT(IN):: ARRAY(DIM1,DIM2)
      INTEGER(4),  INTENT(OUT):: AVERAGE
      INTEGER,      INTENT(IN):: COMPRESSION
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_UPDATE_JPA_POINTERS_I4',
      `INTERFACE
      INTEGER FUNCTION FCB_UPDATE_JPA_POINTERS_I4(TRAIL_INDEX_ARRAY,&
        NDIM1, NDIM2, ARRAY, DIM1, DIM2, AVERAGE, COMPRESSION)
      INTEGER(8),INTENT(INOUT):: TRAIL_INDEX_ARRAY(4), NDIM1, NDIM2 
      INTEGER(8),   INTENT(IN):: DIM1,DIM2
      INTEGER(4),   INTENT(IN):: ARRAY(DIM1,DIM2)
      INTEGER(4),  INTENT(OUT):: AVERAGE
      INTEGER,      INTENT(IN):: COMPRESSION
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_UPDATE_JPA_POINTERS_3D_I2',
      `INTERFACE
      INTEGER FUNCTION FCB_UPDATE_JPA_POINTERS_3D_I2(TRAIL_INDEX_ARRAY,&
        NDIM1, NDIM2, NDIM3, ARRAY, DIM1, DIM2, DIM3, AVERAGE, COMPRESSION)
      INTEGER(8),INTENT(INOUT):: TRAIL_INDEX_ARRAY(8), NDIM1, NDIM2, NDIM3
      INTEGER(8),   INTENT(IN):: DIM1,DIM2,DIM3
      INTEGER(2),   INTENT(IN):: ARRAY(DIM1,DIM2,DIM3)
      INTEGER(4),  INTENT(OUT):: AVERAGE
      INTEGER,      INTENT(IN):: COMPRESSION
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_define(`fcb_interface_FCB_UPDATE_JPA_POINTERS_3D_I4',
      `INTERFACE
      INTEGER FUNCTION FCB_UPDATE_JPA_POINTERS_3D_I4(TRAIL_INDEX_ARRAY,&
        NDIM1, NDIM2, NDIM3, ARRAY, DIM1, DIM2, DIM3, AVERAGE, COMPRESSION)
      
      IMPLICIT                   NONE
      INTEGER(8),INTENT(INOUT):: TRAIL_INDEX_ARRAY(8), NDIM1, NDIM2, NDIM3
      INTEGER(8),   INTENT(IN):: DIM1,DIM2,DIM3
      INTEGER(4),   INTENT(IN):: ARRAY(DIM1,DIM2,DIM3)
      INTEGER(4),  INTENT(OUT):: AVERAGE
      INTEGER,      INTENT(IN):: COMPRESSION
      END FUNCTION
!-----------------------------------------------------------------------
      END INTERFACE')m4_dnl
m4_dnl
m4_dnl macro version of cbf file open to be used both in the library
m4_dnl and in applications that wish to avoid the long argument list
m4_dnl
m4_dnl The macro should be called with 3 arguments
m4_dnl     $1 should give any additional parameters to OPEN
m4_dnl        such as ERR=120 or IOSTAT=IOS
m4_dnl     $2 should give any additional parameters for the
m4_dnl        first read such as ERR=140 or IOSTAT=IOS
m4_dnl     $3 should give any the action to take if the file
m4_dnl        does not begin with "###CBF: "
m4_define(`fcb_macro_FCB_OPEN_CIFIN',
``!-----------------------------------------------------------------------
! --  Open CBF file named FILNAM and connect to unit number TAPIN
!-----------------------------------------------------------------------
!     We have chosen to use the direct access method to read the file
!     with explicit buffer handling. This approach is general but
!     clumpsy. Rather than putting the buffer and its control variables
!     into COMMON these are passed as local arguments to make the routines
!     inherently '''``threadsafe'''`` in a parallel programming environment.
!     Note also, that a reading error could occur for the last record
!     if it did not fill a full block. This could be avoided if the
!     images were padded with a sufficient number of additional bytes
!     (arbitrary values) after the end of the valid binary data.
!
!     The more natural method would use byte stream I/O which is,
!     unfortunately, only an extension of Fortran 90 that has been
!     implemented in some compilers (like the Intel ifort) but
!     not in all (like the SGI IRIX f90).
!     For BSD style opens, there is a special variant on the direct
!     access open with a recl of 1 to give byte-by-byte access.
!-----------------------------------------------------------------------
      INQUIRE(IOLENGTH=FCB_RECORD_SIZE)BUFFER
      OPEN(UNIT=TAPIN,FILE=TRIM(FILNAM),STATUS='''``OLD'''``,ACTION='''``READ'''``,     &
        ACCESS='''``DIRECT'''``,FORM='''``UNFORMATTED'''``,RECL=FCB_RECORD_SIZE,        &
        $1)
      ! *** DEBUG *** PRINT *, "RECL: ", FCB_RECORD_SIZE
      DO BYTE_IN_FILE = 1, FCB_BYTES_IN_REC
        BUFFER(BYTE_IN_FILE) = 0
      END DO
      READ(TAPIN,REC=1,$2)BUFFER     !Read the first record' 
m4_ifelse($3,`',`',`      IF (FCB_CI_STRNCMPARR("###CBF: ",BUFFER,FCB_BYTES_IN_REC,8).NE.0) &
       '$3` !Check for presence of the CBF-format keyword')`
      REC_IN_FILE=1
      BYTE_IN_FILE=0
      LAST_CHAR=0
'')m4_dnl
m4_define(`fcb_interface_LIST_ALL',`
!
      !     Definitions of fcblib interfaces
      !
      fcb_interface_FCB_ATOL_WCNT
      fcb_interface_FCB_CI_STRNCMPARR
      fcb_interface_FCB_DECOMPRESS_PACKED_I2
      fcb_interface_FCB_DECOMPRESS_PACKED_I4
      fcb_interface_FCB_DECOMPRESS_PACKED_3D_I2
      fcb_interface_FCB_DECOMPRESS_PACKED_3D_I4
      fcb_interface_FCB_EXIT_BINARY
      fcb_interface_FCB_NBLEN_ARRAY
      fcb_interface_FCB_NEXT_BINARY
      fcb_interface_FCB_OPEN_CIFIN
      fcb_interface_FCB_READ_BITS
      fcb_interface_FCB_READ_BYTE
      fcb_interface_FCB_READ_INTEGER
      fcb_interface_FCB_READ_LINE
      fcb_interface_FCB_READ_XDS_I2
      fcb_interface_FCB_SKIP_WHITESPACE
      fcb_interface_FCB_UPDATE_JPA_POINTERS_I2
      fcb_interface_FCB_UPDATE_JPA_POINTERS_I4
      fcb_interface_FCB_UPDATE_JPA_POINTERS_3D_I2
      fcb_interface_FCB_UPDATE_JPA_POINTERS_3D_I4
')