c MIRO_READ_DATA.ASC c Program to read a MIRO Archive science or engineering file and c output an ascii listing of all columns (including a selected portion c of the data column) of one or more records. c There is also an option to output averaged data to a text file for plotting c purposes. For spectroscopic (CTS) data, this is an average spectrum, while c for continuum (MM or SMM) data, this is a time series of averages of packets c of 200 measurements. (The average is of the records between the specified c starting and ending record numbers.) c Author: Lucas Kamp, 3 Nov. 2006 c Revisions: c 11 Jun. 2008 - select Cal state & Mirror pos for average spectra c 29 Aug. 2008 - added test for MSB/LSB platform; added Help text on MIRO c data formats c 23 Dec. 2008 - removed tabs for PDS c 13 May 2009 - removed GMT field (column 14) from Level-3 Continuum file c 18 May 2009 - added options to output time series for Cont data and to select c powermode c 28 Sep 2009 - fixed cts_cal flag for raw science files c 02 Oct 2009 - added option for odd-even selection of Cal CTS data to avoid c problem with gain variation in A/D converter pairs c 08 Oct 2009 - extended option for sub-selection of Cal CTS data to one in 4 c bins (since there are 4 A/D converters); fixed bug in computation c of average spectral counts; added header to CTS .lis file; c reversed definitions of hot and cold load flags c 15 Oct 2009 - fixed bug in 'file exists' error msg; added option to list c sky pos'ns for cont. data; also to list all samples and to c skip duplicate records, which caused strange features to appear c in the data when plotted sequentially by PDS reviewer c 19 Oct 2009 - fixed some non F77-standard items: 'file' vs 'name' in open(), c 'double precision' vs 'real*8'; remaining non-std: '_' character, c 'integer*2', '!' comment -- fixing these would be supererogatory c 30 Oct 2009 - fixed some minor blemishes c 18 Nov 2009 - fixed format of level-2 Cont unaveraged data; allow for the c fact that Cont packets can have fewer than 200 samples c 23 Aug 2010 - added option for UTC field in Level-3 files c HOW TO USE THIS PROGRAM: c The user is interactively prompted for the following inputs: c - filename (may include directory specification). c - starting and ending record (row) numbers to print out. c - format of output: c 1 = formatted as the appropriate data type. c 0 = unformatted (hex printout). c -1 = Ascii output option: no print output; instead an ascii list of the c averaged data values will be listed to a file with the same name c as the input file (but always in the current directory) but ".lis" c as filetype, one entry per line. (This option is not available c for Engineering files.) c - (Ascii option only) which cal mode to use. c - (Ascii option, cal=0 only) which mirror position to use. c - (Ascii option, cal=1 only) which power mode to use. c - (non-Ascii option only) starting data item to print out; 4 items of c the data array will be printed out, starting with this one. In the case c of Engineering files, this specifies the starting Engineering item to c print out, and only 4 of the 58 items will be printed. c To build this program, rename it to a file extension suitable for the local c compiler and execute the compilation. E.g., on Sun Solaris, rename it to c MIRO_READ_DATA.f and do: c f77 -o MIRO_READ_DATA MIRO_READ_DATA.f c (On some compilers, numerous Warning messages will be generated by the c compiler, due to the implementation of routine BSWAP in this code; these c can safely be ignored.) c It should be emphasized that program MIRO_READ_DATA is intended only as c supplementary documentation and an example for understanding the structure c of MIRO data. A more useful tool for processing MIRO data is the READPDS c IDL package provided by PDS; for this, see: c http://pdssbn.astro.umd.edu/nodehtml/software.shtml c DESCRIPTION OF MIRO DATA FORMATS: c The contents of the MIRO data files are fully defined by the *.FMT files c in the LABEL directories of the archives. Here, a brief explanation is c provided of the science-data portion of CTS and Continuum files. (The c Engineering files are not discussed further as they are not likely to be c of interest to the general user.) c It is important to understand that the Data colum of the MIRO science files c contains a large data array in each row. In the CTS files, this contains c a complete spectrum, whereas in the Continuum files this is a packet of c data in time order. The name of the Data column is SPECTRAL_DATA in the c CTS files, but simply D in the Continuum files. c The layout of a MIRO science file can be viewed as a 2-D array with N c rows (where N is the value of the FILE_RECORDS keyword in the label), each c row containing M entries, with a "header" on the left-hand side, consisting c of the columns preceding the Data column of the table). c For Level-3 CTS files: M = 4250 spectral items and the header contains c 18 items; c for Level-2 CTS files: M = 4096 spectral items and the header contains c 10 items, one of which is itself an array of 24 items; c for all Continuum files: M = 200 data items and the header contains 12 c items. c UTC field: this was added in August 2010, to Level-3 files only. So, c these files generated after this date will have one more header item than c is listed above. c When program MIRO_READ_DATA is used in the "formatted output" mode, it c prints, for each row, one entry each for the header columns and then four c entries for the Data column, starting with the "starting data item #" that c the program prompts for. (Four was picked for the number of entries c arbitrarily, just to give a representative sample.) c When the program is run in "Ascii output" mode, then it prints all c entries of the Data column to a file, suitably averaged. This allows the c user to save these data for purposes of plotting or analyisis. For CTS c data, the output is a spectrum, averaged over all the rows specified. c For Continuum data, the output is a time series, with each entry being the c average of the 200 data items in one row. c A very important item is the Cal/No-cal flag in Column 6. When this c flag is 0, then the data are for a calibration sequence. For the CTS c data, calibration data are are brightness temperatures; furthermore, the c targets are either sky, cold load or warm load, depending on the value of c the Mirror position flag in column 2. However, when the Cal/No-cal flag c is 1, then the data are difference spectra between the two LO states, so c will be close to zero on average. Only the Cal=1 data (and the Sky data c for Cal=0) are the observational data for the target body. (It is c unfortunate that Cal=0 means calibration, but this is a historical c accident and cannot now be changed.) c Frequency calibration: the total bandwidth of MIRO is 180 MHz, with the c frequency going inversely with the bin (channel) number of the CTS spectra, c in an approximately linear fashion. The exact dependence is dependent on c the temperature, which is why the number of bins are increased from 4096 c for the raw data to 4250 for the calibrated data. This is described in c the document CTS_FREQUENCY_CALIBRATION.PDF in the DOCUMENT directories of c the Level-3 archives. This also describes how the true frequencies of the c lines observed (which span 33 GHz, far more than the nominal bandwidth) are c mapped into the CTS spectrum. Discontinuities between the eight regions of c the different mappings appear as smooth transitions, because of the design c of the CTS. Data in the transition regions between these bands are not c usable. implicit none character*132 fname ! name of the MIRO science or engineering file c All MIRO data files are Table files. The following section lists the c variables in each row for the various file types. c The variable naming convention follows the names given in the .FMT files c in the LABEL directories of the Archive. c all files have this as the first item: double precision time ! column 1 c variables for Level 2 CONTINUUM data (see CONT_LEVEL_2_FORMAT.FMT): c (variable names have the names from the FMT file, prefixed with "cont_") double precision cont_time1 ! column 2 double precision cont_time2 ! column 3 double precision cont_time3 ! column 4 byte cont_mirpos ! column 5 byte cont_powermode ! column 6 byte cont_summation ! column 7 byte cont_nd ! column 8 integer cont_nd_int ! to convert cont_nd to unsigned integer integer*2 cont_mmsubtraction ! column 9 integer*2 cont_smmsubtraction ! column 10 integer*2 cont_calmode ! column 11 integer*2 cont_sp ! column 12 integer*2 cont_d(200) ! column 13 c additional variables for Level 3 CONTINUUM data (see c CONT_LEVEL_3_FORMAT.FMT): character*19 cont_utc ! column 5 (subsequent columns add 1) real cont_3_d(200) ! column 13 c variables for Level 2 SPECTROSCOPIC data (see CTS_LEVEL_2_FORMAT.FMT): c (variable names have the names from the FMT file, prefixed with "cts_") byte cts_mirpos ! column 2 byte cts_powermode ! column 3 byte cts_integration ! column 4 byte cts_smoothing ! column 5 byte cts_cal ! column 6 byte cts_lo ! column 7 byte cts_numpll ! column 8 byte cts_plldata(24) ! column 9 integer cts_plldata_int(24) ! to convert cts_plldata to unsigned integer byte cts_asteroid ! column 10 integer cts_spectral_data(4096) ! column 11 c additional variables for Level 3 SPECTROSCOPIC data (see c CTS_LEVEL_3_FORMAT.FMT) character*19 cts_utc ! column 2 (subsequent columns add 1) ! cts_asteroid is in column 8 real cts_spect_t1 ! column 9 character*1 cts_type ! column 10 byte cts_status ! column 11 character*1 cts_method ! column 12 byte cts_pll ! column 13 integer cts_pll_int ! to convert cts_pll to unsigned integer real cts_ra ! column 14 real cts_dec ! column 15 real cts_vel ! column 16 real cts_s0 ! column 17 real cts_s1 ! column 18 real cts_3_spectral_data(4250)! column 19 c variables for Level 2 ENGINEERING data (see ENG_LEVEL_2_FORMAT.FMT): real eng_data(58) ! columns 2-59 byte eng_mirpos ! column 60 byte eng_powermode ! column 61 integer*2 eng_sucr0 ! column 62 integer*2 eng_sucr16 ! column 63 integer*2 eng_addr100 ! column 64 c other variables: integer codmac ! CODMAC processing level integer ityp ! file type: 1=MM, 2=SUBMM, 3=CTS, 4=ENG integer iutc ! flag for UTC field integer ncol ! number of columns in the table file integer nbyt ! bytes per row in the table file integer ndat ! data items per row in the table file integer irec1 ! starting record number to list or average integer irec2 ! ending record number to list or average integer irec ! loop variable integer ifmt ! output format option integer ical ! desired calibration mode integer mpos ! desired mirror position integer pmode ! desired power mode integer item1 ! starting data item to print out integer item2 ! ending data item to print out character*132 ofname ! output filename (if ifmt = -1) real avspec(4250) ! average for ifmt=-1 option if CTS real cave ! average for ifmt=-1 option if Continuum double precision prev_time, c_time, dc_time ! auxiliary variables for ifmt=-1 if Continuum integer c_opt, icont ! auxiliary variable integer nave ! number of spectra averaged integer nduptimes ! number packets integer icol(64) ! column numbers (for headers) integer i,j,ios ! auxiliary variables integer i1,idel ! loop control variables integer imsbtest ! for MSB/LSB test byte bmsbtest(4) ! for MSB/LSB test equivalence (imsbtest,bmsbtest) logical msb ! flag for MSB/LSB logical found c first, do the test on what sort of platform we have: imsbtest = 1 if (bmsbtest(3).eq.1 .or. bmsbtest(4).eq.1) then msb = .true. else msb = .false. endif 1 print*,' enter name of data file:' read(5,1001) fname ! parse the name to get the level and file type i = index(fname,'MIRO_') if (i.lt.1) then print*,' invalid instrument id' go to 1 endif read(fname(i+5:i+5),1024) codmac if (codmac.lt.2 .or. codmac.gt.3) then print*,' invalid CODMAC level' go to 1 endif ! for Level-3 files, determine if UTC is present: if (codmac.eq.3) then print*,' enter 1 if UTC field is present, 0 otherwise:' read(5,*) iutc endif ! parse the data type and assign format parameters: if (index(fname,'_MM_').gt.1) then ityp = 1 ncol = 13 ndat = 200 if (codmac.eq.2) then nbyt = 444 else nbyt = 844 if (iutc.eq.1) then nbyt = nbyt+19 ncol = ncol+1 endif endif elseif (index(fname,'_SUBMM_').gt.1) then ityp = 2 ncol = 13 ndat = 200 if (codmac.eq.2) then nbyt = 444 else nbyt = 844 if (iutc.eq.1) then nbyt = nbyt+19 ncol = ncol+1 endif endif elseif (index(fname,'_CTS_').gt.1) then ityp = 3 if (codmac.eq.2) then ncol = 11 nbyt = 16424 ndat = 4096 else ncol = 19 nbyt = 17043 ndat = 4250 if (iutc.eq.1) then nbyt = nbyt+19 ncol = ncol+1 endif endif elseif (index(fname,'_HSK_').gt.1) then ityp = 4 nbyt = 248 ncol = 64 ndat = 58 ! actually # of Eng. fields else print*,' invalid data type' go to 1 endif ! open the input file: inquire( file=fname, exist=found) if (.not.found) then print*,' file does not exist: ', fname call exit(0) endif open( 1, file=fname, status='old', access='direct', & form='unformatted', recl=nbyt) print*,' enter start/end record #s to print:' read(5,*) irec1, irec2 print*,' enter 0 for unformatted listing, 1 for formatted,' print*,' or -1 to create ASCII data file (not ENG):' read(5,*) ifmt if (ifmt.lt.0 .and. ityp.eq.4) then print*,' Option not available for ENG, format=0 assumed' ifmt = 0 endif if (ifmt.lt.0) then ! generate output filename and open it: i = index(fname,'MIRO_') j = index(fname,'.DAT')-1 ofname = fname(i:j)//".lis" ! first, make sure it doesn't already exist: inquire( file=ofname, exist=found) if (found) then print*,' file ',ofname(1:j-i+5), & ' already exists, please rename or delete it' call exit(0) endif open( unit=2, file=ofname, status='new') i1 = 1 idel = 1 pmode = 0 mpos = 0 if (ityp.lt.3) then print*,' enter cal mode (0=cal, 1=no cal) or' print*,' 2 for all Sky pos.:' else print*,' enter cal mode (0=cal, 1=no cal):' endif read(5,*) ical if (ical.eq.0) then print*,' enter mirror pos. (0=all, 1=sky, 2=hot, 3=cold):' read(5,*) mpos if (ityp.eq.3) then print*,' option to sub-select bins for A/D gain effect --' print*,' enter 0 for all bins, 1 for odd only, 2 for' print*,' even only, 3 for only 1 in every 4:' read(5,*) i if (i.gt.0) idel = 2 if (i.gt.2) idel = 4 if (i.eq.2) i1 = 2 endif else print*,' enter Power Mode. (0=all, 1=CTS/2C, 2=CTS/SMM, & 3=2C, 4=SMM, 5=MM):' read(5,*) pmode endif if (ityp.lt.3) then icont = 0 print*,' enter 0 for packet averages, 1 for every sample:' read(5,*) c_opt endif else print*,' enter starting data item # to print out:' read(5,*) item1 if (item1.lt.1) item1 = 1 if (item1.gt.ndat-3) item1 = ndat-3 item2 = item1+3 write(6,1025) irec1, irec2, fname endif ! generate the column numbers: do i=1,64 icol(i) = i enddo if (ifmt.lt.0) then ! initialize if (ityp.eq.3) then nave = 0 do i=1,ndat avspec(i) = 0.0 enddo if (irec1.eq.irec2) then write(2,1028) irec1 else if (ical.eq.1) then write(2,1029) irec1, irec2 else write(2,1030) irec1, irec2, mpos endif endif write(2,1022) else write(2,1027) endif endif nduptimes = 0 prev_time = 0.0 do irec = irec1,irec2 if (ityp.le.2) then if (codmac.eq.2) then read(1,rec=irec,iostat=ios) time, cont_time1, cont_time2, & cont_time3, cont_mirpos, cont_powermode, cont_summation, & cont_nd, cont_mmsubtraction, cont_smmsubtraction, & cont_calmode, cont_sp, cont_d if (ios.lt.0) go to 100 ! EOF if (.not.msb) then call bswap(time,8) call bswap(cont_time1,8) call bswap(cont_time2,8) call bswap(cont_time3,8) call bswap(cont_mmsubtraction,2) call bswap(cont_smmsubtraction,2) call bswap(cont_calmode,2) call bswap(cont_sp,2) do i = 1,200 call bswap(cont_d(i),2) enddo endif ! this is the only byte item that can overflow into the sign ! bit: cont_nd_int = cont_nd if (cont_nd_int.lt.0) cont_nd_int = cont_nd_int+256 if (ifmt.lt.0) then if ((cont_calmode.eq.ical .or. ical.eq.2) .and. & (mpos.eq.0 .or. cont_mirpos.eq.mpos .or. & (ical.eq.2 .and. cont_mirpos.eq.1)) .and. & (pmode.eq.0 .or. cont_powermode.eq.pmode) .and. & (time.ne.prev_time)) then if (c_opt.lt.1) then cave = 0.0 do i=1,cont_nd_int cave = cave+cont_d(i) enddo cave = cave/float(cont_nd_int) write(2,1026) irec, time, cave else if (cont_time1.gt.0.0) then dc_time = 0.01*(cont_time1-time) else dc_time = 0.05 ! this is the best we can do endif c_time = time-dc_time do i=1,cont_nd_int icont = icont+1 c_time = c_time+dc_time write(2,1031) icont, c_time, cont_d(i) enddo endif endif elseif (ifmt.eq.0) then if (irec.eq.irec1) write(6,1012) (icol(i),i=1,ncol) write(6,1002) time, cont_time1, cont_time2, cont_time3, & cont_mirpos, cont_powermode, cont_summation, cont_nd, & cont_mmsubtraction, cont_smmsubtraction, cont_calmode, & cont_sp, (cont_d(i),i=item1,item2) else ! ifmt=1 if (irec.eq.irec1) write(6,1013) (icol(i),i=1,ncol) write(6,1003) time, cont_time1, cont_time2, cont_time3, & cont_mirpos, cont_powermode, cont_summation, & cont_nd_int, cont_mmsubtraction, cont_smmsubtraction, & cont_calmode, cont_sp, (cont_d(i),i=item1,item2) endif else ! codmac=3 if (iutc.eq.1) then read(1,rec=irec,iostat=ios) time, cont_time1, cont_time2, & cont_time3, cont_utc, cont_mirpos, & cont_powermode, cont_summation, & cont_nd, cont_mmsubtraction, cont_smmsubtraction, & cont_calmode, cont_sp, cont_3_d else read(1,rec=irec,iostat=ios) time, cont_time1, cont_time2, & cont_time3, cont_mirpos, & cont_powermode, cont_summation, & cont_nd, cont_mmsubtraction, cont_smmsubtraction, & cont_calmode, cont_sp, cont_3_d endif if (ios.lt.0) go to 100 ! EOF if (.not.msb) then call bswap(time,8) call bswap(cont_time1,8) call bswap(cont_time2,8) call bswap(cont_time3,8) call bswap(cont_mmsubtraction,2) call bswap(cont_smmsubtraction,2) call bswap(cont_calmode,2) call bswap(cont_sp,2) do i = 1,200 call bswap(cont_3_d(i),4) enddo endif cont_nd_int = cont_nd if (cont_nd_int.lt.0) cont_nd_int = cont_nd_int+256 if (ifmt.lt.0) then if ((cont_calmode.eq.ical .or. ical.eq.2) .and. & (mpos.eq.0 .or. cont_mirpos.eq.mpos .or. & (ical.eq.2 .and. cont_mirpos.eq.1)) .and. & (pmode.eq.0 .or. cont_powermode.eq.pmode) .and. & (time.ne.prev_time)) then if (c_opt.lt.1) then cave = 0.0 do i=1,cont_nd_int cave = cave+cont_3_d(i) enddo cave = cave/float(cont_nd_int) i = irec-irec1+1 write(2,1026) irec, time, cave else if (cont_time1.gt.0.0) then dc_time = 0.01*(cont_time1-time) else dc_time = 0.05 ! this is the best we can do endif c_time = time-dc_time do i=1,cont_nd_int icont = icont+1 c_time = c_time+dc_time write(2,1032) icont, c_time, cont_3_d(i) enddo endif endif elseif (ifmt.eq.0) then if (irec.eq.irec1) then if (iutc.eq.1) then write(6,1033) (icol(i),i=1,ncol) else write(6,1014) (icol(i),i=1,ncol) endif endif if (iutc.eq.1) then write(6,1034) time, cont_time1, cont_time2, & cont_time3, cont_utc, cont_mirpos, cont_powermode, & cont_summation, cont_nd, cont_mmsubtraction, & cont_smmsubtraction, cont_calmode, cont_sp, & (cont_3_d(i),i=item1,item2) else write(6,1004) time, cont_time1, cont_time2, & cont_time3, cont_mirpos, cont_powermode, & cont_summation, cont_nd, cont_mmsubtraction, & cont_smmsubtraction, cont_calmode, cont_sp, & (cont_3_d(i),i=item1,item2) endif else ! ifmt=1 if (irec.eq.irec1) then if (iutc.eq.1) then write(6,1035) (icol(i),i=1,ncol) else write(6,1015) (icol(i),i=1,ncol) endif endif if (iutc.eq.1) then write(6,1036) time, cont_time1, cont_time2, cont_time3, & cont_utc, cont_mirpos, cont_powermode, cont_summation, & cont_nd_int, cont_mmsubtraction, cont_smmsubtraction, & cont_calmode, cont_sp, (cont_3_d(i),i=item1,item2) else write(6,1005) time, cont_time1, cont_time2, cont_time3, & cont_mirpos, cont_powermode, cont_summation, & cont_nd_int, cont_mmsubtraction, cont_smmsubtraction, & cont_calmode, cont_sp, (cont_3_d(i),i=item1,item2) endif endif endif endif if (ityp.eq.3) then if (codmac.eq.2) then read(1,rec=irec,iostat=ios) time, cts_mirpos, & cts_powermode, cts_integration, cts_smoothing, cts_cal, & cts_lo, cts_numpll, cts_plldata, cts_asteroid, & cts_spectral_data ! in raw science files, cts_cal is bit 0 only: i = cts_cal/2 if (2*i.eq.cts_cal) then cts_cal = 0 else cts_cal = 1 endif if (ios.lt.0) go to 100 ! EOF if (.not.msb) then call bswap(time,8) do i = 1,4096 call bswap(cts_spectral_data(i),4) enddo endif if (ifmt.lt.0) then if (cts_cal.eq.ical .and. & (mpos.eq.0 .or. cts_mirpos.eq.mpos) .and. & (pmode.eq.0 .or. cts_powermode.eq.pmode)) then nave = nave+1 do i=1,ndat avspec(i) = avspec(i)+cts_spectral_data(i) enddo endif elseif (ifmt.eq.0) then if (irec.eq.irec1) write(6,1016) (icol(i),i=1,ncol) write(6,1006) time, cts_mirpos, cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_numpll, cts_plldata, & cts_asteroid, (cts_spectral_data(i),i=item1,item2) else ! ifmt=1 ! this is the only byte item that can overflow into the sign ! bit: do i=1,24 cts_plldata_int(i) = cts_plldata(i) if (cts_plldata_int(i).lt.0) & cts_plldata_int(i) = cts_plldata_int(i)+256 enddo if (irec.eq.irec1) write(6,1017) (icol(i),i=1,ncol) write(6,1007) time, cts_mirpos, cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_numpll, cts_plldata_int, & cts_asteroid, (cts_spectral_data(i),i=item1,item2) endif else ! codmac=3 if (iutc.eq.1) then read(1,rec=irec,iostat=ios) time, cts_utc, cts_mirpos, & cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_asteroid, cts_spect_t1, cts_type, cts_status, & cts_method, cts_pll, cts_ra, cts_dec, cts_vel, cts_s0, & cts_s1, cts_3_spectral_data else read(1,rec=irec,iostat=ios) time, cts_mirpos, cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_asteroid, cts_spect_t1, cts_type, cts_status, & cts_method, cts_pll, cts_ra, cts_dec, cts_vel, cts_s0, & cts_s1, cts_3_spectral_data endif if (ios.lt.0) go to 100 ! EOF if (.not.msb) then call bswap(time,8) call bswap(cts_spect_t1,4) call bswap(cts_ra,4) call bswap(cts_dec,4) call bswap(cts_vel,4) call bswap(cts_s0,4) call bswap(cts_s1,4) do i = 1,4250 call bswap(cts_3_spectral_data(i),4) enddo endif if (ifmt.lt.0) then if (cts_cal.eq.ical .and. & (mpos.eq.0 .or. cts_mirpos.eq.mpos)) then nave = nave+1 do i=1,ndat avspec(i) = avspec(i)+cts_3_spectral_data(i) enddo endif elseif (ifmt.eq.0) then if (irec.eq.irec1) then if (iutc.eq.1) then write(6,1037) (icol(i),i=1,ncol) else write(6,1018) (icol(i),i=1,ncol) endif endif if (irec.eq.irec1) then write(6,1038) time, cts_utc, cts_mirpos, cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_asteroid, cts_spect_t1, cts_type, cts_status, & cts_method, cts_pll, cts_ra, cts_dec, cts_vel, & cts_s0, cts_s1, (cts_3_spectral_data(i),i=item1,item2) else write(6,1008) time, cts_mirpos, cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_asteroid, cts_spect_t1, cts_type, cts_status, & cts_method, cts_pll, cts_ra, cts_dec, cts_vel, & cts_s0, cts_s1, (cts_3_spectral_data(i),i=item1,item2) endif else ! ifmt=1 ! this is the only byte item that can overflow into the sign ! bit: cts_pll_int = cts_pll if (cts_pll_int.lt.0) cts_pll_int = cts_pll_int+256 if (irec.eq.irec1) then if (iutc.eq.1) then write(6,1039) (icol(i),i=1,ncol) else write(6,1019) (icol(i),i=1,ncol) endif endif if (iutc.eq.1) then write(6,1040) time, cts_utc, cts_mirpos, cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_asteroid, cts_spect_t1, cts_type, cts_status, & cts_method, cts_pll_int, cts_ra, cts_dec, cts_vel, & cts_s0, cts_s1, (cts_3_spectral_data(i),i=item1,item2) else write(6,1009) time, cts_mirpos, cts_powermode, & cts_integration, cts_smoothing, cts_cal, cts_lo, & cts_asteroid, cts_spect_t1, cts_type, cts_status, & cts_method, cts_pll_int, cts_ra, cts_dec, cts_vel, & cts_s0, cts_s1, (cts_3_spectral_data(i),i=item1,item2) endif endif endif endif if (ityp.eq.4) then read(1,rec=irec,iostat=ios) time, eng_data, eng_mirpos, & eng_powermode, eng_sucr0, eng_sucr16, eng_addr100 if (ios.lt.0) go to 100 ! EOF if (.not.msb) then call bswap(time,8) do i = 1,58 call bswap(eng_data(i),4) enddo call bswap(eng_sucr0,2) call bswap(eng_sucr16,2) call bswap(eng_addr100,2) endif if (ifmt.eq.0) then i = 1 if (irec.eq.irec1) write(6,1020) i, item1+1, item1+2, & item1+3, item1+4, (icol(j),j=60,ncol) write(6,1010) time, (eng_data(i),i=item1,item2), eng_mirpos, & eng_powermode, eng_sucr0, eng_sucr16, eng_addr100 else ! ifmt=1 i = 1 if (irec.eq.irec1) write(6,1021) i, item1+1, item1+2, & item1+3, item1+4, (icol(j),j=60,ncol) write(6,1011) time, (eng_data(i),i=item1,item2), eng_mirpos, & eng_powermode, eng_sucr0, eng_sucr16, eng_addr100 endif endif if (time.eq.prev_time) nduptimes = nduptimes+1 prev_time = time enddo 100 if (ifmt.lt.0) then if (ityp.eq.3) then print*,' # of spectra averaged = ', nave do i=i1,ndat,idel avspec(i) = avspec(i)/float(nave) write(2,1023) i, avspec(i) enddo endif if (nduptimes.gt.0) print*,' # of duplicate packets = ', & nduptimes close(2) endif close(1) call exit(0) 1001 format(a132) 1002 format(' ITEMS: ', 4z17.16, 4z3.2, 8z5.4) 1003 format(' ITEMS: ', 1p4e17.9, 8i4, 4i6) 1004 format(' ITEMS: ', 4z17.16, 4z3.2, 4z5.4, 4z9.8, 1x, 13z2.2) 1005 format(' ITEMS: ', 1p4e17.9, 8i4, 1p4e11.3) 1006 format(' ITEMS: ', z17.16, 32z3.2, 4z9.8) 1007 format(' ITEMS: ', 1pe17.9, 32i4, 4i12) 1008 format(' ITEMS: ', z17.16, 7z3.2, z9.8, 4z3.2, 9z9.8) 1009 format(' ITEMS: ', 1pe17.9, 7i4, 1pe11.3, a2, i4, a2, i4, & 1p9e11.3) 1010 format(' ITEMS: ', z17.16, 4z9.8, 2z3.2, 3z5.4) 1011 format(' ITEMS: ', 1pe17.9, 1p4e11.3, 2i4, 3i6) 1012 format(' COL.#:',i11,3i17,i10,3i3,i4,4i5) 1013 format(' COL.#:',i11,3i17,i11,7i4,i5) 1014 format(' COL.#:',i11,3i17,i10,3i3,i4,3i5,i7,28x,i10) 1015 format(' COL.#:',i11,3i17,i11,7i4,i8,28x,i10) 1016 format(' COL.#:',i11,i10,7i3,69x,i3,i6) 1017 format(' COL.#:',i11,i11,7i4,92x,i4,i8) 1018 format(' COL.#:',i11,i10,6i3,i7,i5,3i3,i7,5i9) 1019 format(' COL.#:',i11,i11,6i4,i7,i6,i4,2i3,i8,5i11) 1020 format(' COL.#:',i11,i13,3i9,i6,i3,i4,2i5) 1021 format(' COL.#:',i11,i14,3i11,i7,i4,3i6) 1022 format(' SEQ.# DATA ITEM') 1023 format(i6,1pe13.5) 1024 format(i1) 1025 format(' Listing of rows ', i5,' to ', i5,' for file ', a132) 1026 format(i8,0pf14.1,1pe13.5) 1027 format(' REC# SMJT(sec) DATA ITEM') 1028 format(' Spectrum #',i6) 1029 format(' Average of spectra from #',i6,' to ',i6,'. Cal=1') 1030 format(' Average of spectra from #',i6,' to ',i6, & '. Cal=0, MirPos=',i1) 1031 format(i8,0pf14.1,i7) 1032 format(i8,0pf16.3,1pe13.5) 1033 format(' COL.#:',i11,3i17,i20,i10,3i3,i4,3i5,i7,28x,i10) 1034 format(' ITEMS: ', 4z17.16, a20, 4z3.2, 4z5.4, 4z9.8, 1x, 13z2.2) 1035 format(' COL.#:',i11,3i17,i20,i11,7i4,i8,28x,i10) 1036 format(' ITEMS: ', 1p4e17.9, a20, 8i4, 1p4e11.3) 1037 format(' COL.#:',i11,i20,i10,6i3,i7,i5,3i3,i7,5i9) 1038 format(' ITEMS: ', z17.16, a20, 7z3.2, z9.8, 4z3.2, 9z9.8) 1039 format(' COL.#:',i11,i20,i11,6i4,i7,i6,i4,2i3,i8,5i11) 1040 format(' ITEMS: ', 1pe17.9, a20, 7i4, 1pe11.3, a2, i4, a2, i4, & 1p9e11.3) end subroutine bswap(b,n) c swap bytes in 2, 4 or 8-byte words byte b(8),b1(8) do i = 1,n b1(n+1-i) = b(i) enddo do i = 1,n b(i) = b1(i) enddo return end