; This procedure reads a data file of underwater travel times, ; calculates temperature, current speed, etc., and saves them to ; disk. ; Input file: CUR60801.007 ; Output file: CUS60801.007 ; Note: Data format changed as of PINK 3.14. PRO calc6a,filename COMMON files,infile,lunin,outfile,lunout IF (n_params() eq 0) THEN quit1 infile = filename ; Move command-line argument to common block. init ; initialization, define common blocks. readfile ; Read through the input file, storing results in ; memory. calcfile ; Calculations done after entire file is in memory. writeout ; Output results. END ;******************* Functions ******************** ;********** FUNCTION csea(temperature, salinity) ********** ; This procedure calculates the ; speed of sound at the surface of the ocean, as a function of ; t (temperature, in degrees Celsius) and s (salinity, in parts ; per thousand). From Urick, Principles of Underwater Sound, ; ed. 3, p. 113, ex Medwin et al. FUNCTION csea,t,s c = 1449.2 + 4.6*t - 5.5e-2*t^2 + 2.9e-4*t^3 $ + (1.34-1.e-2*t)*(s-35) return,c END ;********* FUNCTION tsea(c, salinity) ********** ; This procedure calculates the ; temperature at the surface of the ocean, as a function of ; c (sound speed, in m/s) and S (salinity, in parts per ; thousand). From Urick, Principles of Underwater Sound, ed. 3, ; p. 113, ex Medwin et al. I have added a recursive solution to ; the cubic equation. RWB, June 15, 1995. FUNCTION tsea,c,s t = 13. t = ( c - 1449.2 - 1.34*(s-35.) + .055*t^2 - .00029*t^3 )/ $ ( 4.6 - .01*(s-35.) ) t = ( c - 1449.2 - 1.34*(s-35.) + .055*t^2 - .00029*t^3 )/ $ ( 4.6 - .01*(s-35.) ) t = ( c - 1449.2 - 1.34*(s-35.) + .055*t^2 - .00029*t^3 )/ $ ( 4.6 - .01*(s-35.) ) t = ( c - 1449.2 - 1.34*(s-35.) + .055*t^2 - .00029*t^3 )/ $ ( 4.6 - .01*(s-35.) ) t = ( c - 1449.2 - 1.34*(s-35.) + .055*t^2 - .00029*t^3 )/ $ ( 4.6 - .01*(s-35.) ) t = ( c - 1449.2 - 1.34*(s-35.) + .055*t^2 - .00029*t^3 )/ $ ( 4.6 - .01*(s-35.) ) t = ( c - 1449.2 - 1.34*(s-35.) + .055*t^2 - .00029*t^3 )/ $ ( 4.6 - .01*(s-35.) ) RETURN, t END ;******************* End of Functions ******************** ;********** PRO init ********** ; This procedure initializes arrays and control flags. PRO init COMMON files,infile,lunin,outfile,lunout COMMON calcdat1,tsampa1,tsampb1,tAss1,tBss1,tAav1,tBav1, $ rmsAss1,rmsBss1,rveco,ttmp,cvss1,ctmpss1,cvav1, $ ctmpav1,salss1,salav1,day1 COMMON calcdat2, $ tsampa2,tsampb2,tAss2,tBss2,rmsAss2,rmsBss2,yAss2,yBss2, $ tAav2,tBav2,rmsAav2,rmsBav2,yAav2,yBav2,teAav2,teBav2, $ yeAav2,yeBav2,sig0A2,sig0B2,day2 COMMON calcdat3,tsampa3,tsampb3, $ tAss3,tBss3,rmsAss3,rmsBss3,yAss3,yBss3,tAav3,tBav3, $ rmsAav3,rmsBav3,yAav3,yBav3,teAav3,teBav3,yeAav3, $ yeBav3,sig0A3,sig0B3,tAf3,tBf3,rmsAf3,rmsBf3, $ yAf3,yBf3,teAf3,teBf3,yeAf3,yeBf3,day3 ;***** Quantities measured or calculated for every sample. ***** ; tsampa1 (first half of sample time) ; tsampb1 (second half of sample time) ; tAss1 (single-shot phase time, forward sound direction) ; tBss1 (single-shot phase time, reverse sound direction) ; tAav1 (average-waveform phase time, forward direction) ; tBav1 (average-waveform phase time, reverse direction) ; rmsAss1 (rms single-shot signal, forward direction) ; rmsBss1 (rms single-shot signal, reverse direction) ; rveco (thermistor resistance) ; ttmp (thermistor temperature) ; cvss1 (current velocity from single-shot phase time) ; ctmpss1 (temperature from single-shot phase time) ; cvav1 (current velocity from average-waveform phase time) ; ctmpav1 (temperature from average-waveform phase time) ; salss1 (salinity from single-shot phase time) ; salav1 (salinity from average-waveform phase time) ; day1 (sample time) ;***** Quantities measured or calculated every IADDAVER samples, ;***** when the envelope of the averaged waveform is found. ; tsampa2 ; tsampb2 ; tAss2 ; tBss2 ; rmsAss2 ; rmsBss2 ; yAss2 ; yBss2 ; tAav2 ; tBav2 ; rmsAav2 ; rmsBav2 ; yAav2 ; yBav2 ; teAav2 ; teBav2 ; yeAav2 ; yeBav2 ; sig0A2 ; sig0B2 ; day2 ;***** Quantities determined when the full cross-correlation ;***** calculation is done, generally at the ORE pause. ; tsampa3 ; tsampb3 ; tAsse ; tBss3 ; rmsAss3 ; rmsBss3 ; yAss3 ; yBss3 ; tAav3 ; tBav3 ; rmsAav3 ; rmsBav3 ; yAav3 ; yBav3 ; teAav3 ; teBav3 ; yeAav3 ; yeBav3 ; tAf3 ; tBf3 ; rmsAf3 ; rmsBf3 ; yAf3 ; yBf3 ; teAf3 ; teBf3 ; yeAf3 ; yeBf3 ; day3 COMMON data01,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01,$ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 COMMON data02,isamp02,tsamp02a,tsamp02b,tAss02,rmsAss02,yAss02,tAav02, $ rmsAav02,yAav02,teAav02,yeAav02,sig0A02,iterA02, $ tBss02,rmsBss02,yBss02,tBav02, $ rmsBav02,yBav02,teBav02,yeBav02,sig0B02,iterB02 COMMON data03,iready,psamp03,isamp03,tsamp03a,tsamp03b,jdir, $ nback,ichange,xenvoff,sigerr0,xerrav,sigerrn,xjump,tcorr COMMON data06,isamp06,tsamp06a,tsamp06b, $ tAss06,rmsAss06,yAss06,tAav06,rmsAav06,yAav06,teAav06,yeAav06, $ tAf06,rmsAf06,yAf06,teAf06,yeAf06,sig0A06,iterA06, $ tBss06,rmsBss06,yBss06,tBav06,rmsBav06,yBav06,teBav06,yeBav06, $ tBf06,rmsBf06,yBf06,teBf06,yeBf06,sig0B06,iterB06 COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 COMMON controlb,nfile0,nfile,itag COMMON param,d0 ;***** Initialize control flags. iprint = fix(1) ; controls the quantity of printout. ijump = fix(0) ; indicates an on-line jump after last sample. iprd03 = fix(0) ; counter used in printing header, in datard03. icorjmp =fix(0) ; enables backward straight-line correction ; after a jump is detected on line. iuncorr = fix(1) ; enables reversing of on-line jump correction. n1=10000; maximum number of samples. n1=16384; maximum number of samples, as of August 2000. n2=n1/8; maximum number of DATA02 (envelope) records. n3=n1/50; maximum number of DATA03 (full cc) records (just a guess). i2=-1; counter of DATA02 records. i3=-1; counter of DATA03 records. d0 = 220. ; 3-Mi. Slough value. ;***** Read in data-acquisition paramters from a disk file. getparam ;***** Set up arrays for the quantities calculated for every ;***** sample: tsampa1=lonarr(n1) tsampb1=lonarr(n1) tAss1=fltarr(n1) tBss1=fltarr(n1) tAav1=fltarr(n1) tBav1=fltarr(n1) rmsAss1=fltarr(n1) rmsBss1=fltarr(n1) rveco=fltarr(n1) ttmp=fltarr(n1) cvss1=fltarr(n1) ctmpss1=fltarr(n1) cvav1=fltarr(n1) ctmpav1=fltarr(n1) salss1=fltarr(n1) salav1=fltarr(n1) day1=dblarr(n1) ;***** Set up arrays for DATA02 information. tsampa2=lonarr(n2) tsampb2=lonarr(n2) tAss2=fltarr(n2) tBss2=fltarr(n2) rmsAss2=fltarr(n2) rmsBss2=fltarr(n2) yAss2=fltarr(n2) yBss2=fltarr(n2) tAav2=fltarr(n2) tBav2=fltarr(n2) rmsAav2=fltarr(n2) rmsBav2=fltarr(n2) yAav2=fltarr(n2) yBav2=fltarr(n2) teAav2=fltarr(n2) teBav2=fltarr(n2) yeAav2=fltarr(n2) yeBav2=fltarr(n2) sig0A2=fltarr(n2) sig0B2=fltarr(n2) day2=dblarr(n2) ;***** Set up arrays for DATA06 information. tsampa3=lonarr(n3) tsampb3=lonarr(n3) tAss3=fltarr(n3) tBss3=fltarr(n3) rmsAss3=fltarr(n3) rmsBss3=fltarr(n3) yAss3=fltarr(n3) yBss3=fltarr(n3) tAav3=fltarr(n3) tBav3=fltarr(n3) rmsAav3=fltarr(n3) rmsBav3=fltarr(n3) yAav3=fltarr(n3) yBav3=fltarr(n3) teAav3=fltarr(n3) teBav3=fltarr(n3) yeAav3=fltarr(n3) yeBav3=fltarr(n3) sig0A3=fltarr(n3) sig0B3=fltarr(n3) tAf3=fltarr(n3) tBf3=fltarr(n3) rmsAf3=fltarr(n3) rmsBf3=fltarr(n3) yAf3=fltarr(n3) yBf3=fltarr(n3) teAf3=fltarr(n3) teBf3=fltarr(n3) yeAf3=fltarr(n3) yeBf3=fltarr(n3) day3=dblarr(n3) ;***** Definition of variables, DATA01. isamp01=long(1) ; sample number tsamp01a=long(1) ; first half of sample time tsamp01b=long(1) ; second half of sample time tAss01=float(1.) ; single-shot phase time, direction A. tAav01=float(1.) ; averaged-waveform phase time, direction A. rmsAss01=float(1.) ; rms of single-shot waveform, direction A. iterA01=fix(1) ; number of iterations, direction A. tBss01=float(1.) ; single-shot phase time, direction A. tBav01=float(1.) ; averaged-waveform phase time, direction A. rmsBss01=float(1.) ; rms of single-shot waveform, direction A. iterB01=fix(1) ; number of iterations, direction A. rveco01 = float(1.) ; thermistor resistance tveco01 = float(1.) ; temperature from the thermistor ;***** Definition of variables, DATA02. isamp02=long(1) ; sample number tsamp02a=long(1) ; first half of sample time tsamp02b=long(1) ; second half of sample time tAss02=float(1.) ; single-shot phase time, direction A. rmsAss02=float(1.) ; rms of single-shot waveform, direction A. yAss02=float(1.) ; single-shot cc amplitude, direction A. tAav02=float(1.) ; averaged-waveform phase time, direction A. rmsAav02=float(1.) ; rms of single-shot waveform, direction A. yAav02=float(1.) ; single-shot cc amplitude, direction A. teAav02=float(1.) ; rms of single-shot waveform, direction A. yeAav02=float(1.) ; rms of single-shot waveform, direction A. sig0A02=float(1.) ; rms of single-shot waveform, direction A. iterA02=fix(1) ; number of iterations, direction A. tBss02=float(1.) ; single-shot phase time, direction A. rmsBss02=float(1.) ; rms of single-shot waveform, direction A. yBss02=float(1.) ; single-shot cc amplitude, direction A. tBav02=float(1.) ; averaged-waveform phase time, direction A. rmsBav02=float(1.) ; rms of single-shot waveform, direction A. yBav02=float(1.) ; single-shot cc amplitude, direction A. teBav02=float(1.) ; rms of single-shot waveform, direction A. yeBav02=float(1.) ; rms of single-shot waveform, direction A. sig0B02=float(1.) ; rms of single-shot waveform, direction A. iterB02=fix(1) ; number of iterations, direction A. ;***** Definition of variables, DATA03. ; Variables are arrays with two values, for the two directions. iready = intarr(2) psamp03 = lonarr(2) isamp03 = lonarr(2) tsamp03a = lonarr(2) tsamp03b = lonarr(2) jdir = intarr(2) nback = intarr(2) ichange = lonarr(2) xenvoff = fltarr(2) sigerr0 = fltarr(2) xerrav = fltarr(2) sigerrn = fltarr(2) xjump = fltarr(2) tcorr = fltarr(2) iready(0) = 0 iready(1) = 0 ;***** Definition of variables, DATA06. isamp06=long(1) ; sample number tsamp06a=long(1) ; first half of sample time tsamp06b=long(1) ; second half of sample time tAss06=float(1.) ; single-shot phase time, direction A. rmsAss06=float(1.) ; rms of single-shot waveform, direction A. yAss06=float(1.) ; single-shot cc amplitude, direction A. tAav06=float(1.) ; average-waveform phase time, direction A. rmsAav06=float(1.) ; rms of average waveform, direction A. yAav06=float(1.) ; average-waveform cc amplitude, direction A. teAav06=float(1.) ; average-waveform envelope time, direction A. yeAav06=float(1.) ; average-waveform cc amplitude, direction A. tAf06=float(1.) ; full-cc phase time, direction A. rmsAf06=float(1.) ; rms of full-cc waveform, direction A. yAf06=float(1.) ; full-cc amplitude, direction A. teAf06=float(1.) ; full-cc envelope time, direction A. yeAf06=float(1.) ; full-cc amplitude, direction A. sig0A06=float(1.) ; envelope error, direction A. iterA06=fix(1) ; number of iterations, direction A. tBss06=float(1.) ; single-shot phase time, direction B. rmsBss06=float(1.) ; rms of single-shot waveform, direction B. yBss06=float(1.) ; single-shot cc amplitude, direction B. tBav06=float(1.) ; average-waveform phase time, direction B. rmsBav06=float(1.) ; rms of average waveform, direction B. yBav06=float(1.) ; average-waveform cc amplitude, direction B. teBav06=float(1.) ; average-waveform envelope time, direction B. yeBav06=float(1.) ; average-waveform cc amplitude, direction B. tBf06=float(1.) ; full-cc phase time, direction B. rmsBf06=float(1.) ; rms of full-cc waveform, direction B. yBf06=float(1.) ; full-cc amplitude, direction B. teBf06=float(1.) ; full-cc envelope time, direction B. yeBf06=float(1.) ; full-cc amplitude, direction B. sig0B06=float(1.) ; envelope error, direction B. iterB06=fix(1) ; number of iterations, direction B. END ;********** PRO getparam ********** ; This procedure reads a file named parlist, containing the run ; numbers of the parameter files on this directory. The file ; parameter file corresponding to the given run number is opened, ; and is scanned for some parameters needed in the calculations. PRO getparam COMMON files,infile,lunin,outfile,lunout COMMON param,d0 str1='' parlistf = strmid(infile,0,strlen(infile)-12)+'parlist' nrun=fix(strmid(infile,strlen(infile)-3,3)) irun=9999 openr,lun1,parlistf,/get_lun while eof(lun1) eq 0 DO BEGIN readf,lun1,"i3",irun if irun le nrun then npar = irun ENDWHILE close,lun1 free_lun,lun1 nparstr=strtrim(string(npar),2) IF strlen(nparstr) eq 2 THEN nparstr='0'+nparstr IF strlen(nparstr) eq 1 THEN nparstr='00'+nparstr parfile=strmid(infile,0,strlen(infile)-12) + 'par' + $ strmid(infile,strlen(infile)-9,6)+nparstr openr,lun1,parfile,/get_lun d0=0. parname='' valstr='' WHILE eof(lun1) eq 0 DO BEGIN readf,lun1,"$(2a10)",valstr,parname if parname eq 'd0 ' THEN d0 = float(valstr) ENDWHILE print,'From parameter file ',parfile,', d0 = ',d0 close,lun1 free_lun,lun1 END ;********** PRO readfile ********** ; This procedure reads through a file of data written by the on-line ; data-acquisition program. It handles data records of various types. PRO readfile COMMON files,infile,lunin,outfile,lunout openinf ; open input file. WHILE eof(lunin) eq 0 DO BEGIN; Loop over one file of data. read1line calc1line print1line ENDWHILE closeinf ; close input file. END ;********** PRO read1line ********** ; The data from the on-line program is unformatted binary. Records ; start with a six-character ASCII tag, followed with an integer ; byte count, for bytes of data still to come in the record. ; Each record terminates with a CR-LF (included in the byte count). ; In this routine the first eight bytes of a record are read. ; Control is then passed to a separate routine for each type ; of data. ; RWB, June 10, 1996 PRO read1line COMMON files,infile,lunin,outfile,lunout COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 ; tag Type of data ; data01 Results for one sample. ; data02 Results from envelope calculation. ; data03 Jump" records ; data04 highest peak ; data05 fitted peak (x,y) ; data06 Results from full CC calculation. tagstring = 'data01' ; Just defines the string. nbyte = fix(0) ; Ditto. readu,lunin,tagstring readu,lunin,nbyte byteorder,nbyte,/sswap IF tagstring eq 'data01' THEN data01rd $ ELSE IF tagstring eq 'data02' THEN data02rd $ ELSE IF tagstring eq 'data03' THEN data03rd $ ELSE IF tagstring eq 'data04' THEN data04rd $ ELSE IF tagstring eq 'data05' THEN data05rd $ ELSE IF tagstring eq 'data06' THEN data06rd $ ELSE dataxxrd END ;********** PRO data01rd ********** ; This procedure reads in a record of type DATA01. This record ; type is written after each sample is processed on line. PRO data01rd COMMON files,infile,lunin,outfile,lunout COMMON data01,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01,$ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 if nbyte ne 50 THEN print,'ERROR: WRONG BYTE COUNT, DATA01: ',nbyte ;***** All the variables to be read have to be pre-defined, so that ;***** the right number of bytes will be read in. ; isamp01=long(1) ; sample number ; tsamp01a=long(1) ; first half of sample time ; tsamp01b=long(1) ; second half of sample time ; tAss01=float(1.) ; single-shot phase time, direction A. ; tAav01=float(1.) ; averaged-waveform phase time, direction A. ; rmsAss01=float(1.) ; rms of single-shot waveform, direction A. ; iterA01=fix(1) ; number of iterations, direction A. ; tBss01=float(1.) ; single-shot phase time, direction A. ; tBav01=float(1.) ; averaged-waveform phase time, direction A. ; rmsBss01=float(1.) ; rms of single-shot waveform, direction A. ; iterB01=fix(1) ; number of iterations, direction A. ; rveco01 = float(1.) ; thermistor resistance ; tveco01 = float(1.) ; temperature from the thermistor icrlf = fix(3338) crlf = icrlf ; just so crlf is defined. readu,lunin,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01, $ tBss01,tBav01,rmsBss01,iterB01, $ rveco01,tveco01,crlf ; Read in the sample record. IF crlf ne 3338 THEN print,'crlf = ',crlf,'; should = 3338' ;***** The byte orders have to be switched, going from PC to UNIX. byteorder,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,/lswap byteorder,tBss01,tBav01,rmsBss01,rveco01,tveco01,/lswap byteorder,iterA01,iterB01,/sswap IF iprint ge 3 THEN BEGIN print,' isamp01 tsamp01a tsamp01b tAss01', $ ' tAav01 rmsAss01 iterA01' print,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01 print,' rveco01 tveco01 tBss01', $ ' tBav01 rmsBss01 iterB01' print,' ',rveco01,tveco01,tBss01,tBav01,rmsBss01,iterB01 ENDIF END ;********** PRO data02rd ********** ; This procedure reads in a record of type DATA02. This record ; type is written after each on-line envelope calculation, every ; IADDAVER samples. PRO data02rd COMMON files,infile,lunin,outfile,lunout COMMON data02,isamp02,tsamp02a,tsamp02b,tAss02,rmsAss02,yAss02,tAav02, $ rmsAav02,yAav02,teAav02,yeAav02,sig0A02,iterA02, $ tBss02,rmsBss02,yBss02,tBav02, $ rmsBav02,yBav02,teBav02,yeBav02,sig0B02,iterB02 COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 if nbyte ne 90 THEN print,'ERROR: WRONG BYTE COUNT, DATA02: ',nbyte i2=min([i2+1,n2-1]) ;***** All the variables to be read have to be pre-defined, so that ;***** the right number of bytes will be read in. ; isamp02=long(1) ; sample number ; tsamp02a=long(1) ; first half of sample time ; tsamp02b=long(1) ; second half of sample time ; tAss02=float(1.) ; single-shot phase time, direction A. ; rmsAss02=float(1.) ; rms of single-shot waveform, direction A. ; yAss02=float(1.) ; single-shot cc amplitude, direction A. ; tAav02=float(1.) ; averaged-waveform phase time, direction A. ; rmsAav02=float(1.) ; rms of single-shot waveform, direction A. ; yAav02=float(1.) ; single-shot cc amplitude, direction A. ; teAav02=float(1.) ; rms of single-shot waveform, direction A. ; yeAav02=float(1.) ; rms of single-shot waveform, direction A. ; sig0A02=float(1.) ; rms of single-shot waveform, direction A. ; iterA02=fix(1) ; number of iterations, direction A. ; tBss02=float(1.) ; single-shot phase time, direction A. ; rmsBss02=float(1.) ; rms of single-shot waveform, direction A. ; yBss02=float(1.) ; single-shot cc amplitude, direction A. ; tBav02=float(1.) ; averaged-waveform phase time, direction A. ; rmsBav02=float(1.) ; rms of single-shot waveform, direction A. ; yBav02=float(1.) ; single-shot cc amplitude, direction A. ; teBav02=float(1.) ; rms of single-shot waveform, direction A. ; yeBav02=float(1.) ; rms of single-shot waveform, direction A. ; sig0B02=float(1.) ; rms of single-shot waveform, direction A. ; iterB02=fix(1) ; number of iterations, direction A. icrlf = fix(3338) crlf = icrlf ; just so crlf is defined. readu,lunin,isamp02,tsamp02a,tsamp02b, $ tAss02,rmsAss02,yAss02,tAav02, $ rmsAav02,yAav02,teAav02,yeAav02,sig0A02,iterA02, $ tBss02,rmsBss02,yBss02,tBav02, $ rmsBav02,yBav02,teBav02,yeBav02,sig0B02,iterB02,crlf IF crlf ne 3338 THEN print,'crlf = ',crlf,'; should = 3338' ;***** The byte orders have to be switched, going from PC to UNIX. byteorder,isamp02,tsamp02a,tsamp02b,tAss02,rmsAss02,yAss02,/lswap byteorder,tAav02,rmsAav02,yAav02,teAav02,yeAav02,sig0A02,/lswap byteorder,tBss02,rmsBss02,yBss02,/lswap byteorder,tBav02,rmsBav02,yBav02,teBav02,yeBav02,sig0B02,/lswap byteorder,iterA02,iterB02,/sswap IF iprint ge 3 THEN BEGIN print,' isamp02 tsamp02a tsamp02b tAss02', $ ' rmsAss02 yAss02 tAav02' print,isamp02,tsamp02a,tsamp02b,tAss02,rmsAss02,yAss02,tAav02 print,' rmsAav02 yAav02 teAav02 yeAav02', $ ' sig0A02 iterA02' print,rmsAav02,yAav02,teAav02,yeAav02,sig0A02,iterA02 print,' tBss02', $ ' rmsBss02 yBss02 tBav02' print,' ', $ tBss02,rmsBss02,yBss02,tBav02 print,' rmsBav02 yBav02 teBav02 yeBav02', $ ' sig0B02 iterB02' print,rmsBav02,yBav02,teBav02,yeBav02,sig0B02,iterB02 ENDIF END ;********** PRO data03rd ********** ; This routine reads in a record of type DATA03. This record is ; written each time that the on-line program changes the phase ; time to follow the envelope time. ; For a given sample, there could be a jump for either ; direction, or for both. So, all the parameters in the DATA03 ; common block are two-dimensional arrays. PRO data03rd COMMON files,infile,lunin,outfile,lunout COMMON data03,iready,psamp03,isamp03,tsamp03a,tsamp03b,jdir, $ nback,ichange,xenvoff,sigerr0,xerrav,sigerrn,xjump,tcorr COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 if nbyte ne 42 THEN print,'ERROR: WRONG BYTE COUNT, DATA03' ijump=1 ; Flag used when the next sample is read. ;***** Definition of variables, DATA03. ; Variables are arrays with two values, for the two directions. ; iready = intarr(2) ; psamp03 = lonarr(2) ; isamp03 = lonarr(2) ; tsamp03a = lonarr(2) ; tsamp03b = lonarr(2) ; jdir = intarr(2) ; nback = intarr(2) ; ichange = lonarr(2) ; xenvoff = fltarr(2) ; sigerr0 = fltarr(2) ; xerrav = fltarr(2) ; sigerrn = fltarr(2) ; xjump = fltarr(2) ; tcorr = fltarr(2) ; iready(0) = 0 ; iready(1) = 0 ;***** Define type of variables to be read in. isam03=long(1) tsam03a=long(1) tsam03b=long(1) jdi=fix(0) nbac=fix(0) ichang=long(0.) xenvof=float(0.) siger0=float(0.) xerra=float(0.) sigern=float(0.) xjum=float(0.) crlf = fix(1) ; CR-LF at end of record readu,lunin,isam03,tsam03a,tsam03b,jdi,nbac,ichang,$ xenvof,siger0,xerra,sigern,xjum,crlf ; Read the record IF crlf ne 3338 THEN print,'crlf = ',crlf,'; should = 3338' ;***** Byte-swapping. byteorder,xenvof,siger0,xerra,sigern,xjum,/lswap byteorder,isam03,tsam03a,tsam03b,ichang,/lswap byteorder,jdi,nbac,/sswap iready(jdi)=fix(1) isamp03(jdi) = isam03 tsamp03a(jdi) = tsam03a tsamp03b(jdi) = tsam03b jdir(jdi) = jdi nback(jdi) = nbac ichange(jdi) = ichang xenvoff(jdi) = xenvof sigerr0(jdi) = siger0 xerrav(jdi) = xerra sigerrn(jdi) = sigern xjump(jdi) = xjum ;***** tcorr(jdi) is the total accumulated ;***** correction that has been applied ;***** by the on-line data acquisition program, generally ;***** trying to bring it into agreement with the ;***** averaged envelope time. ;***** A positive tcorr means that the phase time ;***** was DECREASED. ;***** We are accumulating it so as to be able to ;***** undo their effect as desired. ;***** xjump is in digitization units, or ;***** half-microseconds, as long as we stick with a ;***** 2-MHz digitization rate. tcorr is in micro- ;***** seconds. tcorr(jdi) = tcorr(jdi) + xjump(jdi)/2. IF iprint ge 0 THEN BEGIN IF iprd03 mod 10 eq 0 THEN print, $ 'isamp tsamp03a tsamp03b jdir nback ichange xenvoff' + $ ' sigerr0 xerrav sigerrn xjump tcorr' print,'$(i5,2i12,i5,i6,i8,f8.1,f7.1,f8.3,f8.1,f6.1,f7.1)',$ isamp03(jdi),tsamp03a(jdi),tsamp03b(jdi),jdir(jdi),nback(jdi),$ ichange(jdi),xenvoff(jdi),sigerr0(jdi),xerrav(jdi),sigerrn(jdi),$ xjump(jdi),tcorr(jdi) ENDIF iprd03 = iprd03 + 1 END ;********** PRO data04rd ********** ; This procedure reads data records of type DATA04. These records are ; usually written only for the last sample of a run. One of these ; records contains information on a single peak in the cross-correlation ; function. A series of records are written, corresponding to ; contiguous peaks. They are meant to cover the region where the ; envelope peaks, so that an off-line analysis can be done. ; The format for one record of this type is: ; isample long integer ; tpeak double ; jdir integer 0 or 1 for directions A and B ; npeak integer peak number PRO data04rd COMMON data04,isamp04,tsamp04a,tsamp04b,jdir,npeak,ipeak COMMON data05,xpk,ypk COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 COMMON files,infile,lunin,outfile,lunout ; tag itag ; data01 101 ; data03 103 ; data04 104 ; data05 105 if nbyte ne 18 THEN print,'ERROR: WRONG BYTE COUNT, DATA04; nbyte = ' $ ,nbyte,'; should equal 14.' isam04=long(1) tsam04a=long(1) tsam04b=long(1) jdi=fix(0) npek=fix(0) crlf = fix(1) ; CR-LF at end of record readu,lunin,isam04,tsam04a,tsam04b,jdi,npek,crlf IF crlf ne 3338 THEN print,'crlf = ',crlf,'; should = 3338' byteorder,isam04,tsam04a,tsam04b,/lswap byteorder,jdi,npek,crlf,/sswap isamp04 = isam04 tsamp04a = tsam04a tsamp04b = tsam04b jdir = jdi npeak = npek IF iprint ge 0 THEN BEGIN print,' isamp04 tsamp04a tsamp04b jdir npeak' print,'$(a6,i5,2i12,i3,i4)',$ tagstring,isamp04,tsamp04a,tsamp04b,jdir,npeak ENDIF ipeak=0 ; Will be used for DATA05 to count peaks. IF jdir eq 0 THEN BEGIN xpk = fltarr(2,npeak) ypk = fltarr(2,npeak) ENDIF END ;********** PRO data05rd ********** PRO data05rd COMMON files,infile,lunin,outfile,lunout COMMON data04,isamp04,tsamp04a,tsamp04b,jdir,npeak,ipeak COMMON data05,xpk,ypk COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 buffer = '' str1='' sampstr = '9999' nb = 8*npeak + 2 ; expected number of bytes. if nbyte ne nb THEN print,'ERROR: WRONG BYTE COUNT, DATA05; nbyte = ' $ ,nbyte,'; should equal ',nb xpeak=float(1.) ypeak=float(1.) xpk=fltarr(2,npeak) ypk=fltarr(2,npeak) crlf = fix(1) ; CR-LF at end of record FOR ipeak=0,npeak-1 DO BEGIN readu,lunin,xpeak,ypeak byteorder,xpeak,ypeak,/lswap IF iprint ge 3 THEN BEGIN print,'$(a6,i3,x,f10.5,f10.1)',$ tagstring,ipeak,xpeak,ypeak read,buffer ENDIF xpk(jdir,ipeak) = xpeak ypk(jdir,ipeak) = ypeak END readu,lunin,crlf IF crlf ne 3338 THEN print,'crlf = ',crlf,'; should = 3338' ;***** OUTPUT SECTION ******; IF jdir eq 1 THEN BEGIN peakfile = infile strput,peakfile,'epk',strlen(peakfile)-12 strput,peakfile,'0000',strlen(peakfile)-8 sampstr=strtrim(string(isamp04),1) strput,peakfile,sampstr,strlen(peakfile)-strlen(sampstr)-4 print,'File name for peak data = ',peakfile wdsk,npeak,peakfile,1,/new wdsk,xpk,peakfile,2 wdsk,ypk,peakfile,3 ENDIF END ;********** PRO data06rd ********** ; This procedure reads in a record of type DATA06. This record ; type is written after each full-length cross-correlation ; calculation, normally at the time of an ORE pause. PRO data06rd COMMON files,infile,lunin,outfile,lunout COMMON data06,isamp06,tsamp06a,tsamp06b, $ tAss06,rmsAss06,yAss06,tAav06,rmsAav06,yAav06,teAav06,yeAav06, $ tAf06,rmsAf06,yAf06,teAf06,yeAf06,sig0A06,iterA06, $ tBss06,rmsBss06,yBss06,tBav06,rmsBav06,yBav06,teBav06,yeBav06, $ tBf06,rmsBf06,yBf06,teBf06,yeBf06,sig0B06,iterB06 COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 if nbyte ne 130 THEN print,'ERROR: WRONG BYTE COUNT, DATA06: ',nbyte i3=min([i3+1,n3-1]) ;***** All the variables to be read have to be pre-defined, so that ;***** the right number of bytes will be read in. ; isamp06=long(1) ; sample number ; tsamp06a=long(1) ; first half of sample time ; tsamp06b=long(1) ; second half of sample time ; tAss06=float(1.) ; single-shot phase time, direction A. ; rmsAss06=float(1.) ; rms of single-shot waveform, direction A. ; yAss06=float(1.) ; single-shot cc amplitude, direction A. ; tAav06=float(1.) ; average-waveform phase time, direction A. ; rmsAav06=float(1.) ; rms of average waveform, direction A. ; yAav06=float(1.) ; average-waveform cc amplitude, direction A. ; teAav06=float(1.) ; average-waveform envelope time, direction A. ; yeAav06=float(1.) ; average-waveform cc amplitude, direction A. ; tAf06=float(1.) ; full-cc phase time, direction A. ; rmsAf06=float(1.) ; rms of full-cc waveform, direction A. ; yAf06=float(1.) ; full-cc amplitude, direction A. ; teAf06=float(1.) ; full-cc envelope time, direction A. ; yeAf06=float(1.) ; full-cc amplitude, direction A. ; sig0A06=float(1) ; envelope error, direction A. ; iterA06=fix(1) ; number of iterations, direction A. ; tBss06=float(1.) ; single-shot phase time, direction B. ; rmsBss06=float(1.) ; rms of single-shot waveform, direction B. ; yBss06=float(1.) ; single-shot cc amplitude, direction B. ; tBav06=float(1.) ; average-waveform phase time, direction B. ; rmsBav06=float(1.) ; rms of average waveform, direction B. ; yBav06=float(1.) ; average-waveform cc amplitude, direction B. ; teBav06=float(1.) ; average-waveform envelope time, direction B. ; yeBav06=float(1.) ; average-waveform cc amplitude, direction B. ; tBf06=float(1.) ; full-cc phase time, direction B. ; rmsBf06=float(1.) ; rms of full-cc waveform, direction B. ; yBf06=float(1.) ; full-cc amplitude, direction B. ; teBf06=float(1.) ; full-cc envelope time, direction B. ; yeBf06=float(1.) ; full-cc amplitude, direction B. ; sig0B06=float(1) ; envelope error, direction B. ; iterB06=fix(1) ; number of iterations, direction B. icrlf = fix(3338) crlf = icrlf ; just so crlf is defined. readu,lunin,isamp06,tsamp06a,tsamp06b,tAss06,rmsAss06,yAss06,tAav06, $ rmsAav06,yAav06,teAav06,yeAav06,tAf06,rmsAf06,yAf06,teAf06,yeAf06, $ sig0A06,iterA06, $ tBss06,rmsBss06,yBss06,tBav06, $ rmsBav06,yBav06,teBav06,yeBav06,tBf06,rmsBf06,yBf06,teBf06,yeBf06, $ sig0B06,iterB06,crlf; Read in the record. IF crlf ne 3338 THEN print,'crlf = ',crlf,'; should = 3338' ;***** The byte orders have to be switched, going from PC to UNIX. byteorder,isamp06,tsamp06a,tsamp06b,tAss06,rmsAss06,yAss06,/lswap byteorder,tAav06,rmsAav06,yAav06,teAav06,yeAav06,tAf06,/lswap byteorder,rmsAf06,yAf06,teAf06,yeAf06,sig0A06,/lswap byteorder,tBss06,rmsBss06,yBss06,/lswap byteorder,tBav06,rmsBav06,yBav06,teBav06,yeBav06,tBf06,/lswap byteorder,rmsBf06,yBf06,teBf06,yeBf06,sig0B06,/lswap byteorder,iterA06,iterB06,/sswap IF iprint ge 3 THEN BEGIN print,' isamp06 tsamp06a tsamp06b' print,isamp06,tsamp06a,tsamp06b print,' tAss06 rmsAss06 yAss06' print,tAss06,rmsAss06,yAss06 print,' tAav06 rmsAav06 yAav06 teAav06 yeAav06' print,tAav06,rmsAav06,yAav06,teAav06,yeAav06 print,' tAf06 rmsAf06 yAf06 teAf06 yeAf06', $ ' sig0A06 iterA06' print,tAf06,rmsAf06,yAf06,teAf06,yeAf06,sig0A06,iterA06 print,' tBss06', $ ' rmsBss06 yBss06' print,tBss06,rmsBss06,yBss06 print,' tBav06 rmsBav06 yBav06 teBav06 yeBav06' print,tBav06,rmsBav06,yBav06,teBav06,yeBav06 print,' tBf06 rmsBf06 yBf06 teBf06 yeBf06', $ ' sig0B06 iterB06' print,tBf06,rmsBf06,yBf06,teBf06,yeBf06,sig0B06,iterB06 ENDIF END ;********** PRO dataxxrd ********** ; This procedure trys to deal with unknown data types. PRO dataxxrd COMMON files,infile,lunin,outfile,lunout COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 print,'****** Unknown Data Type ****** tag = ',tagstring, $ ', nbyte = ',nbyte ijunk = intarr((nbyte-2)/2) ; Initialize array for the unknown data. crlf = ifix(1) ; initialize readu,lunin,ijunk,crlf IF crlf eq 3338 THEN BEGIN print,'Unknown data terminated correctly with CR-LF. The data,', $ ' in integer format, are:' print,ijunk ENDIF ELSE print,'!!!!!! Unknown data did not terminate with CR-LF!!!', $ ' We are lost!' END ;********* PRO calc1line ********** ; This procedure steers the calculations which are done record- ; by-record as the input file is read. (calcfile does calculations ; after the end of the input file is detected.) PRO calc1line COMMON files,infile,lunin,outfile,lunout COMMON data01,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01,$ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 COMMON data03,iready,psamp03,isamp03,tsamp03a,tsamp03b,jdir, $ nback,ichange,xenvoff,sigerr0,xerrav,sigerrn,xjump,tcorr COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 IF tagstring eq 'data01' THEN BEGIN data01ca IF ijump ne 0 and icorjmp ne 0 THEN $ data03ca ; ijump ne 0 means the on-line computer just ; made a correction to the phase time. icorjmp ; ne 0 selects error correction by straight- ; line interpolation. data03ca does this. ENDIF $ ELSE IF tagstring eq 'data02' THEN data02ca $ ELSE IF tagstring eq 'data06' THEN data06ca END ;********* PRO data01ca ********* ; This procedure transfers single-sample results to arrays. It ; also un-does offsets introduced by the on-line steering. PRO data01ca COMMON calcdat1,tsampa1,tsampb1,tAss1,tBss1,tAav1,tBav1, $ rmsAss1,rmsBss1,rveco,ttmp,cvss1,ctmpss1,cvav1, $ ctmpav1,salss1,salav1,day1 COMMON data01,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01,$ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 COMMON data03,iready,psamp03,isamp03,tsamp03a,tsamp03b,jdir, $ nback,ichange,xenvoff,sigerr0,xerrav,sigerrn,xjump,tcorr COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 COMMON files,infile,lunin,outfile,lunout ;***** iuncorr ne 0 means to reverse the effect of the on-line "steering" ;***** of the phase time in trying to follow the envelope time. tcorr ;***** is the accumulated correction which was SUBTRACTED by the on-line ;***** program. tsampa1(isamp01)=tsamp01a tsampb1(isamp01)=tsamp01b tAss1(isamp01)=tAss01 tBss1(isamp01) = tBss01 tAav1(isamp01) = tAav01 tBav1(isamp01) = tBav01 rmsAss1(isamp01) = rmsAss01 rmsBss1(isamp01) = rmsBss01 rveco(isamp01) = rveco01 ttmp(isamp01) = tveco01 IF iuncorr THEN BEGIN tAss1(isamp01) = tAss01+tcorr(0) tBss1(isamp01) = tBss01+tcorr(1) tAav1(isamp01) = tAav01+tcorr(0) tBav1(isamp01) = tBav01+tcorr(1) ENDIF END ;********* PRO data02ca ********* ; This procedure transfers envelope results to arrays. It ; also un-does offsets introduced by the on-line steering. PRO data02ca COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 COMMON calcdat2, $ tsampa2,tsampb2,tAss2,tBss2,rmsAss2,rmsBss2,yAss2,yBss2, $ tAav2,tBav2,rmsAav2,rmsBav2,yAav2,yBav2,teAav2,teBav2, $ yeAav2,yeBav2,sig0A2,sig0B2,day2 COMMON data02,isamp02,tsamp02a,tsamp02b,tAss02,rmsAss02,yAss02,tAav02, $ rmsAav02,yAav02,teAav02,yeAav02,sig0A02,iterA02, $ tBss02,rmsBss02,yBss02,tBav02, $ rmsBav02,yBav02,teBav02,yeBav02,sig0B02,iterB02 COMMON data03,iready,psamp03,isamp03,tsamp03a,tsamp03b,jdir, $ nback,ichange,xenvoff,sigerr0,xerrav,sigerrn,xjump,tcorr tsampa2(i2)=tsamp02a tsampb2(i2)=tsamp02b tAss2(i2) = tAss02 tBss2(i2) = tBss02 tAav2(i2) = tAav02 tBav2(i2) = tBav02 ;***** iuncorr ne 0 means to reverse the effect of the on-line "steering" ;***** of the phase time in trying to follow the envelope time. tcorr ;***** is the accumulated correction which was SUBTRACTED by the on-line ;***** program. IF iuncorr THEN BEGIN tAss2(i2) = tAss02+tcorr(0) tBss2(i2) = tBss02+tcorr(1) tAav2(i2) = tAav02+tcorr(0) tBav2(i2) = tBav02+tcorr(1) ENDIF rmsAss2(i2) = rmsAss02 rmsBss2(i2) = rmsBss02 yAss2(i2) = yAss02 yBss2(i2) = yBss02 rmsAav2(i2) = rmsAav02 rmsBav2(i2) = rmsBav02 yAav2(i2) = yAav02 yBav2(i2) = yBav02 teAav2(i2) = teAav02 teBav2(i2) = teBav02 yeAav2(i2) = yeAav02 yeBav2(i2) = yeBav02 sig0A2(i2) = sig0A02 sig0B2(i2) = sig0B02 END ;********* PRO data06ca ********* ; This procedure transfers full-cc results to arrays. It ; also un-does offsets introduced by the on-line steering. PRO data06ca COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 COMMON calcdat3,tsampa3,tsampb3, $ tAss3,tBss3,rmsAss3,rmsBss3,yAss3,yBss3,tAav3,tBav3, $ rmsAav3,rmsBav3,yAav3,yBav3,teAav3,teBav3,yeAav3, $ yeBav3,sig0A3,sig0B3,tAf3,tBf3,rmsAf3,rmsBf3, $ yAf3,yBf3,teAf3,teBf3,yeAf3,yeBf3,day3 COMMON data03,iready,psamp03,isamp03,tsamp03a,tsamp03b,jdir, $ nback,ichange,xenvoff,sigerr0,xerrav,sigerrn,xjump,tcorr COMMON data06,isamp06,tsamp06a,tsamp06b, $ tAss06,rmsAss06,yAss06,tAav06,rmsAav06,yAav06,teAav06,yeAav06, $ tAf06,rmsAf06,yAf06,teAf06,yeAf06,sig0A06,iterA06, $ tBss06,rmsBss06,yBss06,tBav06,rmsBav06,yBav06,teBav06,yeBav06, $ tBf06,rmsBf06,yBf06,teBf06,yeBf06,sig0B06,iterB06 tsampa3(i3)=tsamp06a tsampb3(i3)=tsamp06b tAss3(i3) = tAss06 tBss3(i3) = tBss06 tAav3(i3) = tAav06 tBav3(i3) = tBav06 ;***** iuncorr ne 0 means to reverse the effect of the on-line "steering" ;***** of the phase time in trying to follow the envelope time. tcorr ;***** is the accumulated correction which was SUBTRACTED by the on-line ;***** program. IF iuncorr THEN BEGIN tAss3(i3) = tAss06+tcorr(0) tBss3(i3) = tBss06+tcorr(1) tAav3(i3) = tAav06+tcorr(0) tBav3(i3) = tBav06+tcorr(1) ENDIF tAf3(i3) = tAf06 tBf3(i3) = tBf06 rmsAss3(i3) = rmsAss06 rmsBss3(i3) = rmsBss06 yAss3(i3) = yAss06 yBss3(i3) = yBss06 rmsAav3(i3) = rmsAav06 rmsBav3(i3) = rmsBav06 yAav3(i3) = yAav06 yBav3(i3) = yBav06 teAav3(i3) = teAav06 teBav3(i3) = teBav06 yeAav3(i3) = yeAav06 yeBav3(i3) = yeBav06 rmsAf3(i3) = rmsAf06 rmsBf3(i3) = rmsBf06 yAf3(i3) = yAf06 yBf3(i3) = yBf06 teAf3(i3) = teAf06 teBf3(i3) = teBf06 yeAf3(i3) = yeAf06 yeBf3(i3) = yeBf06 sig0A3(i3) = sig0A06 sig0B3(i3) = sig0B06 END ;********* PRO print1line ********** ; This procedure prints a line to the console, if desired, for each ; record read in. PRO print1line COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 IF tagstring eq 'data01' THEN data01pr END ; ********** PRO data01pr ********** ; This procedure does console printout for DATA01 records. PRO data01pr COMMON data01,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01,$ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 if isamp01 eq 0 THEN print,' isamp tAss tAav'+ $ ' rmsAss iterA tBss tBav rmsBss iterB rveco tveco' if isamp01 le 10 THEN $ print,'$(i5,3f9.3,i3,3f9.3,i3,2f7.3)',$ isamp01,tAss01,tAav01,rmsAss01,iterA01, $ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 END ;********** PRO calcfile ********** ; The importance of this routine will grow in the future. PRO calcfile COMMON controla,tagstring,nbyte,iprint,ijump,iprd03,icorjmp, $ iuncorr,n1,n2,n3,i2,i3 COMMON files,infile,lunin,outfile,lunout COMMON param,d0 COMMON calcdat1,tsampa1,tsampb1,tAss1,tBss1,tAav1,tBav1, $ rmsAss1,rmsBss1,rveco,ttmp,cvss1,ctmpss1,cvav1, $ ctmpav1,salss1,salav1,day1 COMMON calcdat2, $ tsampa2,tsampb2,tAss2,tBss2,rmsAss2,rmsBss2,yAss2,yBss2, $ tAav2,tBav2,rmsAav2,rmsBav2,yAav2,yBav2,teAav2,teBav2, $ yeAav2,yeBav2,sig0A2,sig0B2,day2 COMMON calcdat3,tsampa3,tsampb3, $ tAss3,tBss3,rmsAss3,rmsBss3,yAss3,yBss3,tAav3,tBav3, $ rmsAav3,rmsBav3,yAav3,yBav3,teAav3,teBav3,yeAav3, $ yeBav3,sig0A3,sig0B3,tAf3,tBf3,rmsAf3,rmsBf3, $ yAf3,yBf3,teAf3,teBf3,yeAf3,yeBf3,day3 ; ta (phase time, forward sound direction) ; tb (phase time, reverse sound direction) ; tenva (envelope time, forward direction) ; tenvb (envelope time, reverse direction) ; vc (current speed) ; ttmp (temperature from thermistor) ; ctmp (temperature from sound speed) ; ampla (amplitude, forward direction) ; amplb (amplitude, reverse direction) ; sal (salinity) ; tsample (time in days since start of 1970) COMMON data01,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01,$ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 COMMON data03,iready,psamp03,isamp03,tsamp03a,tsamp03b,jdir, $ nback,ichange,xenvoff,sigerr0,xerrav,sigerrn,xjump,tcorr ; Truncate the arrays, just in case this was not a ; complete run. tsampa1=tsampa1(0:isamp01) tsampb1=tsampb1(0:isamp01) tAss1=tAss1(0:isamp01) tBss1=tBss1(0:isamp01) tAav1=tAav1(0:isamp01) tBav1=tBav1(0:isamp01) rmsAss1=rmsAss1(0:isamp01) rmsBss1=rmsBss1(0:isamp01) rveco=rveco(0:isamp01) ttmp=ttmp(0:isamp01) day1=dblarr(isamp01+1) ;***** Envelope data. i2=max([i2,0]) tsampa2=tsampa2(0:i2) tsampb2=tsampb2(0:i2) tAss2=tAss2(0:i2) tBss2=tBss2(0:i2) rmsAss2=rmsAss2(0:i2) rmsBss2=rmsBss2(0:i2) yAss2=yAss2(0:i2) yBss2=yBss2(0:i2) tAav2=tAav2(0:i2) tBav2=tBav2(0:i2) rmsAav2=rmsAav2(0:i2) rmsBav2=rmsBav2(0:i2) yAav2=yAav2(0:i2) yBav2=yBav2(0:i2) teAav2=teAav2(0:i2) teBav2=teBav2(0:i2) yeAav2=yeAav2(0:i2) yeBav2=yeBav2(0:i2) sig0A2=sig0A2(0:i2) sig0B2=sig0B2(0:i2) day2=dblarr(i2+1) ;***** Full cc data. i3=max([i3,0]) tsampa3=tsampa3(0:i3) tsampb3=tsampb3(0:i3) tAss3=tAss3(0:i3) tBss3=tBss3(0:i3) rmsAss3=rmsAss3(0:i3) rmsBss3=rmsBss3(0:i3) yAss3=yAss3(0:i3) yBss3=yBss3(0:i3) tAav3=tAav3(0:i3) tBav3=tBav3(0:i3) rmsAav3=rmsAav3(0:i3) rmsBav3=rmsBav3(0:i3) yAav3=yAav3(0:i3) yBav3=yBav3(0:i3) teAav3=teAav3(0:i3) teBav3=teBav3(0:i3) yeAav3=yeAav3(0:i3) yeBav3=yeBav3(0:i3) tAf3=tAf3(0:i3) tBf3=tBf3(0:i3) rmsAf3=rmsAf3(0:i3) rmsBf3=rmsBf3(0:i3) yAf3=yAf3(0:i3) yBf3=yBf3(0:i3) teAf3=teAf3(0:i3) teBf3=teBf3(0:i3) yeAf3=yeAf3(0:i3) yeBf3=yeBf3(0:i3) sig0A3=sig0A3(0:i3) sig0B3=sig0B3(0:i3) day3=dblarr(i3+1) ; This maneuver reverses the byte order for a ; double-precision floating-point number. Maybe later I ; can find out how to do it better. openw,lun2,'tsamp.tmp',/get_lun FOR i=0,isamp01 DO writeu,lun2,tsampb1(i),tsampa1(i) ; write in reversed order. FOR i=0,i2 DO writeu,lun2,tsampb2(i),tsampa2(i) ; write in reversed order. FOR i=0,i3 DO writeu,lun2,tsampb3(i),tsampa3(i) ; write in reversed order. close,lun2 openr,lun2,'tsamp.tmp' readu,lun2,day1; Double precision, bytes in correct order. readu,lun2,day2; Double precision, bytes in correct order. readu,lun2,day3; Double precision, bytes in correct order. close,lun2 free_lun,lun2 day1=day1/100./86400.; Convert from units of 10 ms to days. day2=day2/100./86400.; Convert from units of 10 ms to days. day3=day3/100./86400.; Convert from units of 10 ms to days. IF iuncorr THEN BEGIN ;***** Shift the phase times all together, to align with ;***** the values at the end of the run, which are probably ;***** closer to the envelope values. tAss1 = tAss1 - tcorr(0) ; single-shot time. tBss1 = tBss1 - tcorr(1) tAav1 = tAav1 - tcorr(0); waveform-averaging time. tBav1 = tBav1 - tcorr(1) tAss2 = tAss2 - tcorr(0) ; single-shot time. tBss2 = tBss2 - tcorr(1) tAav2 = tAav2 - tcorr(0); waveform-averaging time. tBav2 = tBav2 - tcorr(1) tAss3 = tAss3 - tcorr(0) ; single-shot time. tBss3 = tBss3 - tcorr(1) tAav3 = tAav3 - tcorr(0); waveform-averaging time. tBav3 = tBav3 - tcorr(1) ENDIF ; da0 and db0 are the nominal baseline lengths, in directions A and B. ; da0 = 228.2647; based on 748.9 feet: Mike Simpson, USGS, Feb. 6 1996 ; db0 = 228.2647 da0 = d0 ; Use the baseline read from the parameter file. db0 = d0 ; RWB, November 8, 1997 ; temp0 and sal0 correspond to ta=0, tb=0. temp0 = 12.35 sal0 = 0. c0 = csea(temp0,sal0); 14,35 -> 1503.62 m/s IF iprint ge 3 THEN print,'temp, salinity, c = ', $ temp0,sal0,c0 ;***** Now recalculate everything that depends on the phase times. ; t0 is the cross-correlation offset, in msec. ldate=long(strmid(infile,strlen(infile)-9,5)) ;***** Take care of the y2k problem, up to 2005. ldate1 = ((ldate+50000) mod 100000) + 50000 t0 = 200. ; Value before Jan 5 1996. IF ldate1 ge 60105 THEN t0 = 500. IF ldate1 ge 60320 THEN t0 = 1000. IF iprint ge 3 THEN print,'ldate1, t0 = ',ldate1,t0 ;***** Single-shot. ca = da0/(da0/c0 + (tAss1-t0)*1.e-6) cb = db0/(db0/c0 + (tAss1+tBss1-2.*t0)*1.e-6) cvss1 = (ca - cb)/2. cc = (ca + cb)/2. ;***** Calculate the temperature from the speed of sound, assuming ;***** a constant speed of sound. ctmpss1 = tsea(cc,sal0) ; temperature assuming salinity doesn't change. ;***** Now calculate the salinity, using both the thermistor ;***** temperature and measured speed of sound. salss1 = 35. - (1449.2 - cc + 4.6*ttmp -$ .055*ttmp^2 + .00029*ttmp^3)/$ (1.34 - .01*ttmp) if min(ttmp) le 5. or max(ttmp) ge 25. THEN salss1(*) = 35. ;***** Average-waveform. ca = da0/(da0/c0 + (tAav1-t0)*1.e-6) cb = db0/(db0/c0 + (tAav1+tBav1-2.*t0)*1.e-6) cvav1 = (ca - cb)/2. cc = (ca + cb)/2. ;***** Calculate the temperature from the speed of sound, assuming ;***** a constant speed of sound. ctmpav1 = tsea(cc,sal0) ; temperature assuming salinity doesn't change. ;***** Now calculate the salinity, using both the thermistor ;***** temperature and measured speed of sound. salav1 = 35. - (1449.2 - cc + 4.6*ttmp -$ .055*ttmp^2 + .00029*ttmp^3)/$ (1.34 - .01*ttmp) if min(ttmp) le 5. or max(ttmp) ge 25. THEN salav1(*) = 35. print,'Results from calcfile, for last sample of run:' print,'ss - cv,ctmp,ttmp,sal:',cvss1(isamp01),ctmpss1(isamp01), $ ttmp(isamp01),salss1(isamp01) print,'av - cv,ctmp,ttmp,sal:',cvav1(isamp01),ctmpav1(isamp01), $ ttmp(isamp01),salav1(isamp01) END ;********** PRO writeout ********** ; This procedure writes out results of the calculations to a ; disk file. ; The results consist of a number of arrays. The number of ; elements in each array is equal to the number of samples in ; the run (usually 10000). Output is done using WDSK. The ; arrays, in order, are: ; PRO writeout COMMON data01,isamp01,tsamp01a,tsamp01b,tAss01,tAav01,rmsAss01,iterA01,$ tBss01,tBav01,rmsBss01,iterB01,rveco01,tveco01 COMMON files,infile,lunin,outfile,lunout COMMON calcdat1,tsampa1,tsampb1,tAss1,tBss1,tAav1,tBav1, $ rmsAss1,rmsBss1,rveco,ttmp,cvss1,ctmpss1,cvav1, $ ctmpav1,salss1,salav1,day1 COMMON calcdat2, $ tsampa2,tsampb2,tAss2,tBss2,rmsAss2,rmsBss2,yAss2,yBss2, $ tAav2,tBav2,rmsAav2,rmsBav2,yAav2,yBav2,teAav2,teBav2, $ yeAav2,yeBav2,sig0A2,sig0B2,day2 COMMON calcdat3,tsampa3,tsampb3, $ tAss3,tBss3,rmsAss3,rmsBss3,yAss3,yBss3,tAav3,tBav3, $ rmsAav3,rmsBav3,yAav3,yBav3,teAav3,teBav3,yeAav3, $ yeBav3,sig0A3,sig0B3,tAf3,tBf3,rmsAf3,rmsBf3, $ yAf3,yBf3,teAf3,teBf3,yeAf3,yeBf3,day3 print,'Number of samples read = ',isamp01+1 ; Write out the arrays, one by one. ;***** Sample arrays. wdsk,tAss1,outfile,1,/new wdsk,tBss1,outfile,2 wdsk,tAav1,outfile,3 wdsk,tBav1,outfile,4 wdsk,rmsAss1,outfile,5 wdsk,rmsBss1,outfile,6 wdsk,rveco,outfile,7 wdsk,ttmp,outfile,8 wdsk,cvss1,outfile,9 wdsk,ctmpss1,outfile,10 wdsk,cvav1,outfile,11 wdsk,ctmpav1,outfile,12 wdsk,salss1,outfile,13 wdsk,salav1,outfile,14 wdsk,day1,outfile,15 ;***** Envelope arrays. wdsk,tAss2,outfile,16 wdsk,tBss2,outfile,17 wdsk,rmsAss2,outfile,18 wdsk,rmsBss2,outfile,19 wdsk,yAss2,outfile,20 wdsk,yBss2,outfile,21 wdsk,tAav2,outfile,22 wdsk,tBav2,outfile,23 wdsk,rmsAav2,outfile,24 wdsk,rmsBav2,outfile,25 wdsk,yAav2,outfile,26 wdsk,yBav2,outfile,27 wdsk,teAav2,outfile,28 wdsk,teBav2,outfile,29 wdsk,yeAav2,outfile,30 wdsk,yeBav2,outfile,31 wdsk,sig0A2,outfile,32 wdsk,sig0B2,outfile,33 wdsk,day2,outfile,34 ;***** Full cc arrays. wdsk,tAss3,outfile,35 wdsk,tBss3,outfile,36 wdsk,rmsAss3,outfile,37 wdsk,rmsBss3,outfile,38 wdsk,yAss3,outfile,39 wdsk,yBss3,outfile,40 wdsk,tAav3,outfile,41 wdsk,tBav3,outfile,42 wdsk,rmsAav3,outfile,43 wdsk,rmsBav3,outfile,44 wdsk,yAav3,outfile,45 wdsk,yBav3,outfile,46 wdsk,teAav3,outfile,47 wdsk,teBav3,outfile,48 wdsk,yeAav3,outfile,49 wdsk,yeBav3,outfile,50 wdsk,tAf3,outfile,51 wdsk,tBf3,outfile,52 wdsk,rmsAf3,outfile,53 wdsk,rmsBf3,outfile,54 wdsk,yAf3,outfile,55 wdsk,yBf3,outfile,56 wdsk,teAf3,outfile,57 wdsk,teBf3,outfile,58 wdsk,yeAf3,outfile,59 wdsk,yeBf3,outfile,60 wdsk,sig0A3,outfile,61 wdsk,sig0B3,outfile,62 wdsk,day3,outfile,63 print,'isamp tssa tssb twaa twab rmsA rmsB ctmp ttmp', $ ' cvss sal day since 1970' ipr2=n_elements(tass1)-1 ipr1=max([0,ipr2-9]) FOR i=ipr1,ipr2 DO print, $ '$(x,i4,4f7.1,2f5.1,2f5.1,2f6.2,f14.7)', $ i,tAss1(i),tBss1(i),tAav1(i),tBav1(i),rmsAss1(i),rmsBss1(i), $ ctmpss1(i),ttmp(i),cvss1(i),salss1(i),day1(i) END ;********** PRO openinf ********** ; This procedure opens the input file and creates the name for ; the output file. The input files ; are CURnnnnn files; the output files are CUSnnnnn files. PRO openinf COMMON files,infile,lunin,outfile,lunout ; Open the output file. print,'infile = ', infile openr,lunin,infile,/get_lun ; Create the name for the output file. It will be used ; by WDSK, which handles opening and closeing the file. outfile = infile; strput,outfile,'s',strlen(outfile)-10 print,'outfile = ',outfile END ;********** PRO closeinf ********** ; This procedure closes the input file. PRO closeinf COMMON files,infile,lunin,outfile,lunout close,lunin free_lun,lunin END ;********** PRO quit1 ********** ; This procedure exits the program if the calling sequence ; is incorrect. PRO quit1 print,"Syntax: calca," print,' = name of input data file' print,' Example: calca,"/home1/stars/bland/nautdat/cur50511.001"' print,'New format of output files (CUS60801.004 etc.):' print,' First, data taken every sample.' print,'TASS1(nsamp)' print,'TBSS1(nsamp)' print,'TAAV1(nsamp)' print,'TBAV1(nsamp)' print,'RMSASS1(nsammp)' print,'RMSBSS1(nsammp)' print,'CVSS1(nsamp)' print,'TMPCSS1(nsamp)' print,'CVAV1(nsamp)' print,'TMPCAV1(nsamp)' print,'DAY1(nsamp)' STOP END