program rieg2txt ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c program to read riegl 2dd raw data c used to check problematic data c c input: c c rieglfile c ihr, rmin c ifirst, ilast, lout, lheader c c 6 first characters in rieglfile must be hhmmss (UTC start time) c ifirst and ilast are the actual scans read c (2001: 40 Hz scan rate). c c lout=false gives survey/check of file c lheader=true for normal 2dd header, false for 2002 non-2dd files c c (c) Rene Forsberg/National Survey and Cadastre (KMS) c 22 jun 2001, 14 may 2002, 18 jan 2003 c updated dec 2007 for LF95 fortran c updated oct 2011 for ".log"-files (5 bytes only pr meas) c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc implicit real*8(a-h,o-z) character*72 ifile logical lout,lheader,lspike c integer*1 sync(2) integer*2 syncseq equivalence (sync(1),syncseq) integer*1 iampl integer*1 brange(4),bang(4),btime(4) integer*4 irange,iang,itime equivalence(brange(1),irange),(bang(1),iang),(btime(1),itime) irange = 0 iang = 0 itime = 0 c c program input c ------------- c write(*,*) 'input: Riegl file' read(*,'(a)') ifile write(*,*) ifile write(*,*) 'input hr,min,firstscan,lastscan,lheader' read(*,*) ihr,rmin,ifirst,ilast,lout,lheader c open(10,file=ifile,form='unformatted', .access='direct',recl=1,status='old') if (lout) open(20,file='rieg2txt.out',status='unknown') c irec = 1 nscan = 0 igpssec = 0 timer0 = 0 dechr0 = ihr + rmin/60.d0 dechrp = 0 c c read riegl header c if (lheader) then call readhdr(npscan,rangefak,anglefak,timerfak,nbytes,irec) else npscan = 208 rangefak = 0.008 anglefak = 0.01 timerfak = 0.00001 irec = 1675 endif c c expected time dif - 40 Hz assumed c ihz = 40 dt = 1.d0/ihz/(4*npscan) dtscan = 1.d0/ihz dtscan1 = dtscan - npscan*dt c c read line data c byte order is dos .. modify for unix/sun use c position directly on first wanted scan c write(*,11) dechr0 11 format(' file start epoch:',f9.5) if (ifirst.lt.1) ifirst = 1 irec = irec + (ifirst-1)*(npscan*nbytes+2) iscan = ifirst igpssec = igpssec + ifirst/40 if (ifirst.gt.0) write(*,*) .'(note: thr approximate when skipping scans - 40 Hz assumed)' write(*,*) 'central scan points every 2 min:' write(*,*) c c scan record loop c 20 read(10,rec=irec) sync(1) read(10,rec=irec+1) sync(2) c irec=irec+2 if (syncseq.ne.npscan*nbytes) .write(*,*) '*** warning - syncseq not ok',syncseq,npscan*nbytes do 30 i = 1,npscan if (nbytes.eq.8) then read(10,rec=irec,err=90) brange(1) read(10,rec=irec+1,err=90) brange(2) read(10,rec=irec+2,err=90) iampl read(10,rec=irec+3,err=90) bang(1) read(10,rec=irec+4,err=90) bang(2) read(10,rec=irec+5,err=90) btime(1) read(10,rec=irec+6,err=90) btime(2) read(10,rec=irec+7,err=90) btime(3) irec = irec+8 elseif (nbytes.eq.5) then read(10,rec=irec) brange(1) read(10,rec=irec+1) brange(2) c read(10,rec=irec+2) btime(1) c read(10,rec=irec+3) btime(2) c read(10,rec=irec+4) btime(3) read(10,rec=irec+2) iampl read(10,rec=irec+3) bang(1) read(10,rec=irec+4) bang(2) irec = irec+5 itime = 0 else stop '*** header nbytes wrong' endif c range = irange*rangefak vgon = 2*mod(iang,10000)*anglefak timer = itime*timerfak c c check for outliers in timer c if (i.eq.1) then timere = timer0+dtscan1 if (nscan.eq.0) timere = timer tol = 0.03 else timere = timer0+dt tol = 0.001 endif c timero = timer if (abs(timere-timer).gt.tol) then if (timere-timer.gt.1-tol) then igpssec = igpssec+1 else c write(*,15) iscan,i,timer,timere 15 format(' *** timer data gap/error scan:',i7,i5,2f9.5) if (.not.lspike.and.i.gt.1) then timer = timere lspike = .true. else lspike = .false. endif endif endif c timer0 = timer dechr = dechr0 + (igpssec+timer)/3600 c if (lout) . write(20,22) iscan,i,range,iampl,vgon,igpssec,timero,dechr 22 format(i7,i4,f9.3,i4,f9.3,i6,f9.5,f11.7) c if (dechr-dechrp.gt.0.0333333.and.i.eq.105) then dechrp = dechr write(*,22) iscan,i,range,iampl,vgon,igpssec,timer,dechr endif 30 continue nscan = nscan+1 iscan = iscan+1 c if (nscan.le.ilast-ifirst) goto 20 goto 91 c 90 write(*,*) '- end of file' 91 write(*,92) dechr 92 format(' last epoch read: ',f9.5) write(*,93) nscan 93 format(' number of scans output on rieg2txt.out:',i7) end c subroutine readhdr(npscan,rangefak,anglefak,timerfak,nbytes, .irec) cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c r e a d h d r c c reads header in Riegl 2dd-data from unit 10 c cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc implicit real*8(a-h,o-z) integer*1 hdr(47) integer*4 wsize integer*2 wsize1,wsize2,bytespl,meassize,meascount real*4 rangeunit,angleunit,timerunit equivalence (hdr(1),wsize1),(hdr(2),wsize2), .(hdr(5),bytespl),(hdr(11),meassize), .(hdr(13),meascount),(hdr(35),rangeunit),(hdr(39),angleunit), .(hdr(43),timerunit) c do j = 1,47 read(10,rec=irec,err=90) hdr(j) irec = irec+1 enddo wsize = wsize2*256**2 + wsize1 npscan = meascount nbytes = meassize rangefak = rangeunit anglefak = angleunit timerfak = timerunit c write(*,15) wsize,bytespl,meassize,meascount, .rangeunit,angleunit,timerunit 15 format(/' RIEGL HEADER bytes:',i4,', bytes pr scan:',i5, .' bytes pr meas:',i5,/' measurements per scan:',i5/ .' range,angle and timer units:',4f12.6) write(*,*) c if (hdr(47).ne.4) .write(*,*) '*** warning: header angleid is not 4 !!' irec = 48 return 90 stop '*** end of file met in header' end