OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
ql02raw.f
Go to the documentation of this file.
1 c This program reads a 22180-byte SeaWiFS formatted record and compresses
2 c the S/C ID, time tag, instrument telemetry and scan line data from 2-byte
3 c words to 10 bits. The data are written in 13860-byte records formatted
4 c as SeaWiFS minor frames. The leading and trailing frame synch words are
5 c filled with zeros.
6 
7  integer*2 ints(4),isync
8  integer*4 irec
9  byte inbuf(512),inrec(22180),outrec(13860),b10(5),bint(8)
10  byte frsync(7),ausync(125)
11  character*50 l0file
12  character*50 outfile
13  data outrec/13860*0/,ints/4*0/
14  data isync/5/
15  data frsync/x'a1',x'16',x'fd',x'71',x'9d',x'83',x'c9'/
16  data ausync/
17  * x'f8',x'bf',x'36',x'd6',x'bd',x'a1',x'11',x'57',x'11',x'd3',
18  * x'd0',x'4e',x'0a',x'db',x'de',x'37',x'19',x'9f',
19  * x'c9',x'93',x'a3',x'86',x'90',x'fb',x'63',
20  * x'12',x'c9',x'55',x'02',x'd5',x'a7',x'24',x'5d',
21  * x'88',x'6d',x'29',x'ba',x'df',x'f8',x'3b',
22  * x'f7',x'4b',x'67',x'34',x'c5',x'bb',x'd6',x'7b',
23  * x'00',x'42',x'60',x'ce',x'ed',x'4a',x'ea',
24  * x'76',x'63',x'd4',x'68',x'06',x'35',x'0a',x'99',
25  * x'be',x'f9',x'f4',x'd5',x'23',x'e5',x'c0',
26  * x'52',x'f8',x'fd',x'56',x'18',x'50',x'eb',x'fb',
27  * x'21',x'72',x'07',x'b8',x'48',x'3f',x'd1',
28  * x'47',x'89',x'e0',x'6b',x'1c',x'b0',x'46',x'46',
29  * x'c2',x'03',x'9e',x'44',x'd1',x'05',x'e9',
30  * x'2e',x'86',x'56',x'5a',x'30',x'25',x'16',x'6b',
31  * x'98',x'71',x'db',x'9c',x'57',x'd7',x'72',
32  * x'83',x'79',x'd5',x'e5',x'44',x'93',x'65',x'27',x'c3',x'cc'/
33 
34  equivalence(ints,bint)
35 
36  write(*,*) 'Enter Level 0 file name'
37  read (5,'(a50)') l0file
38  write(*,*) 'Enter Output file name'
39  read (5,'(a50)') outfile
40 
41  open(unit=11,file=l0file,access='direct',recl=22180,
42  * status='old',action='READ')
43  open(unit=12,file=outfile,access='direct',recl=13860)
44 
45 c Initialize output record with frame and auxillary synchs
46  do i=1,7
47  outrec(i) = frsync(i)
48  end do
49  do i=1,125
50  outrec(i+13735) = ausync(i)
51  end do
52 
53 c Skip header records
54  nrec = 0
55  irec = 2
56 
57 c Now loop through input records
58  dowhile(.true.)
59 
60 c Read a complete L0 record
61  read (11,err=999,rec=irec) inrec
62  irec = irec + 1
63  nrec = nrec + 1
64 
65 c Reverse bytes (not needed for linux)
66 c do i=1,22180,2
67 c bval = inrec(i)
68 c inrec(i) = inrec(i+1)
69 c inrec(i+1) = bval
70 c enddo
71 
72 c Remaining 10-bit data (instrument telemetry and scan line)
73  do l=1,2772
74  do i=1,8
75  bint(i) = inrec(i+(l-1)*8)
76  end do
77  call i2to10bit(ints,b10)
78  do i=1,5
79  outrec(i+(l-1)*5) = b10(i)
80  end do
81  end do
82 
83  write (12,rec=nrec) outrec
84 
85  if (mod(nrec,100) .eq. 0) then
86  write(*,*) 'Writing record ',nrec
87 c goto 999
88  endif
89 
90  end do
91 
92  999 continue
93 
94  stop
95  end
96 
97  subroutine i2to10bit(ints,bit10)
98 
99 c This subroutine compresses a 4-element I*2 array into a 5-element byte
100 c array, taking the 10 least significant bits of each integer.
101 
102  integer*2 ints(4)
103  byte bit10(5)
104  integer*2 m3fc,m003,m3f0,m3c0,m300,m00f,m03f,m0ff
105  data m3fc/1020/,m003/3/,m3f0/1008/,m00f/15/
106  data m3c0/960/,m03f/63/,m300/768/,m0ff/255/
107  bit10(1) = iand(ints(1),m3fc)/4
108  bit10(2) = iand(ints(1),m003)*64 + iand(ints(2),m3f0)/16
109  bit10(3) = iand(ints(2),m00f)*16 + iand(ints(3),m3c0)/64
110  bit10(4) = iand(ints(3),m03f)*4 + iand(ints(4),m300)/256
111  bit10(5) = iand(ints(4),m0ff)
112  return
113  end
subroutine i2to10bit(ints, bit10)
Definition: ql02raw.f:98