Historical changes to PFLAGs
----------------------------


Changes have been made to the editing process for shipboard adcp
within a codas database. An explanation of the old method and the
new follows.

OLD:

::

 Within the database the following data entries are set by various
 editing routines:
	PROFILE_FLAGS   0-->good
			        1-->bad; set for individual bins by BADBIN;
                   		recognized by adcpsect and profstat

	ANCILLARY_2
		max_amp_bin: set by DBUPDATE using information in
		   bottom.asc

		last_good_bin:
		   set to -l by DBUPATE using badprf.asc;
		   set to specific bin by BOTMPAS3 and LAST_85 for
			profile with max_amp_bin set and the two
			neighboring profiles

	ACCESS_VARIABLES  set for an entire profile;

		first_good_bin

		last_good_bin:
		   set to specific bin by BOTMPAS3 and LAST_85
		   set to -1 by DBUPDATE using badprf.asc

		recognized by adcpsect but not profstat

..

In the data processing mask bits are turned on when badbin,
botmpas3, and last85 are run. Once the botmpas3 bit has been
set to 1 no futher editing of the profiles within that block
will be applied. There is no message that additional badbins,
badprfs, or bottom flags are not added.

In this scheme, there is no handshaking between the profile flags
and the access variables; i.e., when the last portion of a profile
is bad due to bottom interference and last_good_bin is set, those bins
still have good values in the profile flags and get extracted by profstat.

NEW:

The data entries remain the same as described above but now there is a
correspondence between the profile flags and access variables, with
some additional changes.

::

	PROFILE_FLAGS
            0-->good
			1-->bad; set for individual bins by BADBIN;
			2-->bad, based on percent good minimum set
				by setflags
			4-->bad, based on last good bin, set by
				DBUPDATE with bottom.asc or badbin.asc
			5-->bad, 1+4
			6-->bad, 2+4
		recognized by adcpsect and profstat

..

Here is the new sequence of steps and programs with their effects:

1. Use matlab editing routines as before to create various ``*asc`` files.
A change to the matlab plotting routines now results in bins
with PG < 30 no longer being displayed.

2. Use BADBIN & DBUPDATE as before for badbin.asc, bottom.asc, and
badprf.asc.  Now DBUPDATE sets in ANCILLARY_2 max_amp_bin, last_good_bin,
AND bottom_sought (data processing mask bit 8), and clears
bottom_max_good_bin (data processing mask bit 9), which allows further
editing to be applied to the profiles.

3. Run SET_LGB ../adcpdb/database to set last_good_bin in ANCILLARY_2
and ACCESS_VARIABLES and bit 9 (bottom_max_good_bin) in data processing
mask  IF bottom_sought is true and bottom_max_good_bin is false to
85% of the minimum of the max_amp_bin from the bottom flagged profile and
the two adjacent ones (replacing botmpas3 and last_85).  This is done only
for profiles where the ACCESS_VARIABLE last_good_bin is not set to -1
(ie, those not flagged using badprf.asc).

4. Run SETFLAGS SETFLAGS.CNT with PERCENT_GOOD threshold set to 30 and the
option set_range_bit. This will set bits to the flag value 2 in
PROFILE_FLAGS everywhere that PG falls below the minimum given and
use last_good_bin in ACCESS_VARIALBES to set the corresponding bin flags
and range_bit to 4 (or the sum of 4 and previous flag values).


SETFLAGS can be run to clear all or selected profile flags in a specified
time range with these options: clear_range_bit, clear_glitch_bit,
clear_pg_bit, clear_all_bits, and clear_range. The first four clear bits
within PROFILE_FLAGS, while clear_range sets ACCESS_VARIABLES first_good_bin
and last_good_bin back to original default: 1 and number of bins.

If you need to clear max_amp_bin, you must do it using the form of
bottom.asc with value in column 8 set to the maximum number of bins
(see last_good_bin in ACCESS_VARIABLES for a profile with no bottom
flagging to get this value).

For old databases, use SETPMASK or SET_BIT to clear bits 8 and 9 (the new
values bottom_sought and bottom_max_good_bin) before reapplying the editing.
For SETPMASK, use NOT_BOTTOM_SOUGHT and NOT_BOTTOM_MGB.

Parameter input control files for SETFLAGS and SETPMASK can be found in
the programs directory tree under codas3/cntfiles.