$DEBUG PROGRAM PREPACS c 06-mar-09 desiderio c from DAPCS_PREPACS c (older versions of prepacs did not calculate checksums, c and were adapted from code written on board the c thompson during a cruise.) c c traps out bad data values which c result in runtime execution errors: c ref = 0 causes a divide by 0, c sig = 0 causes log(0). c c command line format: c prepacs devfilename binaryfilename outfilename [switch] c c prepacs processes acs binary files to give a tab-delimited c acs ascii data file with time in msec in the first column c and with one row of tab-delimited column headings preceding c the data. it is functionally identical to wetview in its c calculation of acs parameters except that: c (1) prepacs processes all the acs packets, and does not c skip the first 2 packets as does wetview; c (2) prepacs handles the acs timestamps (which have units c of msec) with no loss of significance; wetview handles c time in units of 10s of msec, and seems to truncate the c acs timestamps (and truncates the 3rd packet's timestamp c to use as time = 0). c therefore, for a given line of data, the acs time calculated by c prepacs will be about 500 msec later (2 packets' worth) than c that calculated by wetview. c c the optional switch is of the form: c +nul : (or no switch); default; c neither aux nor dark channels written out c +aux : 4 auxiliary acs values written out c +dark : dark values written out c +all : both auxiliary and dark values written out c +wet : equivalent to +all, but in addition, the appropriate c dev file information is prepended to the output data c file so that the file can be replayed in wetview. c c the 4 auxiliary channels are: c (1) internal temperature [degC]; c (2) seems to always be 0. include for possible future use; c (3) depth [meters] (according to wetlabs manuals); c (4) external temperature [degC]. c c dependences: all subroutines are included in this code unit, c and are also organized in the order encountered (as listed c below) after the main program. some of the subroutines may c differ from those of the same name in other programs. c prepacs [main] c prepacs_command_line_format c process_switch c read_acs_dev_file c find_first_packet c check_checksum c check_serial_number c calc_timestamp c write_outfile_header c find_packet c check_checksum c calc_timestamp c badpacket_diagnostics c parse_packet c get_ca_counts c calc_scalar_data c calc_int_temp_compensation c write_out_data c c upper case is used for calls to the above subroutines. c calls in lower case are to procedures intrinsic to fortran. c c much of variable transfer between routines is handled by named c common block constructs. c c raw acs binary files consist (mostly) of unsigned 2-byte integers c utilizing big-end ordering of the bytes, which is reversed from c the way pc computers store integers (little-end ordering). since c this version of fortran (fortran 90) does not support unsigned c integers of any type, the fastest and simplest way to convert c the binary data is to swap their bytes and write them into the c least significant bytes of 4-byte integers using an EQUIVALENCE c construct: c c integer*1 binaryvalue(2) ! rawdatum to be converted c integer*1 dummy(4) ! a 4-element array of 1-byte integers c integer*4 datum ! converted value c equivalence (dummy,datum) ! assigns dummy and datum to same memory location c dummy = 0 ! make sure all bits of dummy (and datum) are 0. c dummy(1) = binaryvalue(2) ! swap bytes into least significant c dummy(2) = binaryvalue(1) ! (first two) bytes of datum c c datum now has the desired value, *without* coding an explicit assignment c statement of the type: datum = ____ .