subroutine difference(diff,ndiff,ref,nref,rec) c This subroutine reconstructs 12 bit full words from 6 bit difference words. c Reconstruction of a series of difference words is verified against the c reference word occurring in parallel with the last difference of the series. c The last series of reconstructed full words can not be verified without c knowledge of the first reference and difference words from the immediate c following record. This routine currently does not have this information. c The last series of reconstructed words are not verified against a c reference word. c Data and variable definitions: c Input data: c diff difference word (fill = 255) c ndiff number of difference words c ref reference words (fill = 0) c nref number of reference words c Output data: c rec reconstructed full words (fill = 0) c Local variables: c iratio number of difference words per reference word c err reconstruction error flag c ALGORITHM: c Given N = nref, M = ndiff and n = M/N ... c RECONSTRUCTION: x(1) = R(1), x(j) = x(j-1) + D(j), j=2,M c VERIFICATION: R(k) = R(k-1) + SUM(D(j+(k-2)*n)), where j=2,n+1 and k=2,N c Example: R(2) = R(1) + ( D(2) + D(3) + ... + D(n) + D(n+1) ) c REF R R R c 1 2 ... N=nref c | | | c REC x x x x x x x x x x x x x x x x x x x x ... x x x x x x x x x x c 1 2 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . M=ndiff c c DIFF D D D D D D D D D D D D D D D D D D D D ... D D D D D D D D D D c 1 2 3 . . . . . . n n c + c 1 c Generic differencing routine to replace mode specific routines c written by Sandy Kramer, code 692, 12/11/96 integer*2 diff(3,ndiff),rec(3,ndiff),ref(3,nref) logical*1 err(3,nref) iratio = ndiff/nref do iax = 1,3 c first reconstructed word is equal to first reference word iref = 1 rec(iax,1) = ref(iax,1) err(iax,1) = .false. do i = 2,ndiff c flag bad data if ( diff(iax,i).eq.255 .or. ref(iax,iref).eq.0 ) then err(iax,iref) = .true. end if c accumulate sums to reconstruct full words rec(iax,i) = rec(iax,i-1) + diff(iax,i) c verify reconstruction if ( mod(i-1,iratio).eq.0 ) then iref = iref + 1 err(iax,iref) = .false. if ( rec(iax,i).ne.ref(iax,iref) ) then if ( ref(iax,iref).ne.0 ) err(iax,iref-1) = .true. rec(iax,i) = ref(iax,iref) end if end if end do c remove error flagged reconstructed words do i = 1,ndiff iref = (i-1)/iratio + 1 if ( err(iax,iref) ) rec(iax,i) = 0 c if ( iax.eq.3 ) then c write(6,800) iref,ref(1,iref),ref(2,iref),ref(3,iref), c & i,diff(1,i),diff(2,i),diff(3,i) c & i,rec(1,i),rec(2,i),rec(3,i), c end if end do end do return 800 format(12(1x,i5)) end