USAGE:
          xcorr-vs-time [DIRECTIVES] [options] <campaign>
 
 PURPOSE:
          Plots cross-correlation versus time
          by segmenting a campaign. There are two levels of segments,
          segments proper, and sub-segments.
          Segments are at project level.
          Sub-segments divide projects into ~equal-length stretches
          so that x-correlation is based on a roughly constant
          sample size.

          Plots scatter diagrams before and after regression w.r.t.
          seismometric acceleration.

          Plots autocovariance for inspection whether one drop
          affects the next.

          Prepares a time series that can be used as a seismic
          correction to AG drops: d/ag4sub-${ym}-${agdt}s.ts
          (under directives +P[S] , plot/scatter-plot).
          There's a script:
             cd ~/TD/a/Allcamps
             reduce-ag-zacc <AGSG-mc-file> [<ZACC-file>]

          Obs! xcorr-vs-time needs a precursor job prep-ag-seism
 

 
 Incomplete:
          Choice of sampling interval for parallel seis
          consistent with xcorr-length?
 
          LIKEG-data needed for parallel SCG
          There is code in ../SCG

          A first check to ascertain input files exist
          with expected names. Prompting and suggestions.
 
          Problems arise with gaps in the seismogram records.
          Must avoid interference with files by using marks $ym;
          should use placeholder files, skip commands that want
          to use them and instead create further placeholder files.
          For instance, tmp/tmp-rms-4-02.ts was made in 2016 but
          picked up in the processing of $ym=1908a . Thus
          tmp/tmp-rms-4-02.ts -> tmp/$ym-rms-4-02.ts
          There is certainly more to mark with $ym. 
 
          To avoid interference of campaigns, the resulting
          files should systematically bear $ym in their names
          or paths. So far, this has only been coded for the
          corr and corr.ts files.

         
 
 DIRECTIVES: (use `+´ as a delimiter between multiple dir's)
 
  xx      - Do only the intro

  SCG     - Generate parallel SCG xcorr's (needs LIKEG-seismo;
            presently deprecated)
  [N]AG   - do with AG data (N : generate new data)
  [N]ZA   - do with seismometer Z-acceleration (N : new data)   
  Z[A]W   - use specific tse-sections to weed out problems
              in gcf-files.
 ZA[W]-RP - skip reprocessing the AG data (outliers and weedout
             in .ra.ts and .dw.ts). Useful when variants of the
            GCF-*-ZACC<gmrk>-10s-ts files have been made.
            Then, use options
              -gm <gmrk>  to retrieve these files
              -m <mrk>    to give products unique names and locations
 
  X       - do the cross-correlation.
            As of current this won't work without +STD
 
  P       - plot
  PT      - plot only the xcorr-vs-time diagram.
  PS      - prepare scatter plot data and plot.
            Creates also the seismic corrections to the AG data,
            d/ag4sub-${ym}-$dt.ts
  PSO     - only plot scatter (facilitates experimenting
              with -YR option.
  PSA     - only the autocorrelation plot
 
  +GO     - Don't prompt for confirmation.
            With making new segments:

              If you are certain that segmenting was successful,
              the command files from segmenting are copied under
              file names segm-<yymm>.cmd and seissegm-<yymm>.cmd
              Else the program will exit so you can check.
            With X and without +GO you are prompted to check
              calculation of cross-correlation of each segment.
 
  +R      - Re-use the segmentation (else make a new one)
 
  FIT     - Do fitxym test. Calculates a-priori error factors;
              to actually use them you need the -u option or
              directive STD+U
.
              The factors are written to a file
              apriori-<ym>.err (ym is 2-dig.year + month + camp.-letter)
              The test runs with a-priori factor 1 (if directive contains +W)
              or 15 (if not). To use a different factor, specify -ey <factor>
  FIT+U   - Use the test results in a second round of fitxym
              (sidelines option -u).
 
  STD     - Do fitxym with RMS-derived weights from Seismograms ...
  X+STD+W     ... and, in addition, with the Std Dev's from the AG; then
  +W          ... must be given already at data generation (NZA)

 


 OPTIONS:     (D) = in effect under directive D                [default]
 
  -m <mrk>    - appended to $ym to uniquely mark an
                analysis variant. Default is
                $XCORR_MRK from the environment                        []
  -gm <gmrk>  - appended to ZACC in GCF*ZACC-10Hz.ts file names,
                the data source for seismograms                        []   

  -dur   #n   - segment duration n , in hours (X)                      [6]


  -zadeci <s> - tsf-edit target in ./deci.tse for decimation of
                seism. Zacc  (NZA)                                    [D2]


  -cal   #v   - calibration value for seismometer
(NZA)              [1.0]

  -scutm #n   - cut margin for seismogram in seconds (NZA)           [200]


  -corrl #n   - length for xcorr, in sampling units  (X)             [200]


  -segl  #n   - segment length in AG data file must be longer
                 than n samples (param. m in segmenting.awk) (! +R)  [200]
 
  -wr         - AG-data is weighted residual .wr.ts     
                  (Must be decided from the start and
                  kept for the whole suite of runs) (NAG)         [.ra.ts]
 

  -ey    #y   - use a-priori error y in fitxym -Ey  (FIT)           [15.0]
                  Under directive +W the default is ...              [1.0]

  -ez    #z   - error in seism. Zacc = z×RMS (X+STD)                [/10.]
 

  -u          - multiply a-priori error with the factors
                  determined in the fitxym test (P PS)     [use const. #y]        
 
  -sel        - Do scatter plots on *selected* segments (P PS). 
                  The segment numbers are expected in a source
                  file named  corrfs-sel-${ym}.set
                  Here is a recipe to select by RMS-reduction:

                select4scatplot <ym> 0.03
                  (script is still more or less a stub)
 
  -YR #yr #tix  
              - Range -yr/yr and tick specification for scatter
                  plots (AG-values are along the y-axis).
                  (P PS PSO)
.

  -force-deci - In effect in autocorrelation plot (P PS PSA):
                  Force decimation. Applicable to sparse files,
                  i.e. those that have a basic sampling interval
                  that is shorter than the AG's drop interval.
                  This option must be accompanied with environment
                  parameters:
                setenv ACV_D #n
                setenv ACV_R `calc #n -1`
                  See autoc.tse,DECI .
                  The first setting specifies the decimation rate,
                  the other one the sample-and-hold length of the
                  REPAIR command.

   [N]Z[A]W instructions:
                File ~/Seismo/gcf/weed.tse contains sections with targets WEED${ym}ap${q} with
                instructions to e.g. delete a range of samples.  ${q refers to a  file segment; code with two decimal places, e.g.
                    TSF EDIT WEED1606ap03
                The updated file replaces the original; thus you need to do this only once for every directive  NZA
                How is the weed.tse file filled? Obviously, you can plot a section with tsd and produce DEL commands
                (for instance straddling an earthquake signature) in the graphic window using
                C -> B E -> Z -> C -> B E -> D and confirm with any char > 31
                After program end, fetch the tsfedit commands from fort.7
 
 FILES:
             - (possibly incomplete. Many *.log files, also in
                ~/tslist-logs/ . Result files o/*.rsl .
               The list below shows files that are re-imported

               ${ym} is the shortname of the campaign
 
                  segm-${ym}${mrk}.cmd  - ... and ...
              seissegm-${
ym}
${mrk}.cmd  - segmentation parameters.
                  agfs-${ym}${mrk}.set  - file names for segments of AG data.
                  agws-${ym}${mrk}.set  - file names for segments of AG std-devs.
                corrfs-${ym}${mrk}.set  - file names for subsegments (mostly).
           corrfs-take-${ym}${mrk}.set  - selection of successful RMS reductions.
               facsubs-${ym}${mrk}.set  - the regression coefficients.
          regress_test-${ym}${mrk}.rsl  - the results of fitxym under directive FIT.
            rms-reduct-${ym}${mrk}.rsl  - the rms reduction (positive means success).
           seiscut-mrg-${ym}${mrk}.set  - tslist options to cut seism files with margins. 
                seisfs-${ym}${mrk}.set  - file names for segments of Seis data
                                          (e.g. seisfs-1502b.set)
.
 
 EXAMPLES:
           This is a package of 3 commands:
           (1)   xcorr-vs-time NAG+NZA      -dur 3 201106b
           (2)   xcorr-vs-time AG+GO        -dur 3 201106b
           (3)   xcorr-vs-time X+P+R+STD+GO -dur 3 201106b
 
           add these for realistic a-priori values
  Compute  (4)   xcorr-vs-time FIT+R        -dur 3 201405a
  Use      (5)   xcorr-vs-time P+R -u       -dur 3 201405a
  or       (4')  xcorr-vs-time FIT+P+R -u   -dur 3 201405a
 
           Processing with standard deviations:
           (1)   xcorr-vs-time NAG+NZA+STD+W  -dur 3 201405a
           (2)   xcorr-vs-time X+R+STD+W+GO   -dur 3 201405a
           (3)   xcorr-vs-time FIT+R+STD+W+GO -dur 3 201405a
           (4)   select4scatplot 1405a
           (5)   xcorr-vs-time PS+R+STD+W+GO -u -dur 3 -sel -YR 800 a200f50 201405a

           For 202006a:
           (1)   xcorr-vs-time NZA+NAG 
           (2)   xcorr-vs-time ZAW-RP+X+P+R+STD+FIT+U+GO -dur 3 202006a |\
                    tee xcorr-202006a:ZAW-RP+X+P+R+STD+FIT+U+GO:-CDR.log 

 Winning strategy for 201806a:
(p1)   prep-ag-seismo D   201806a
(p2)   prep-ag-seismo T   201806a
(p3)   prep-ag-seismo X+P 201806a
 (1)   xcorr-vs-time NAG+NZA+W+GO           -dur 3 201806
 (2)   xcorr-vs-time FIT+STD+P+R+GO -ey 60. -dur 3 201806a



 
 USAGE:
          prep-ag-seismo [directives] [-split #n] <campaign>

 PURPOSE:
       
Prepares for seismometer correction or timing of AG-drop series.
          A pre-runner to xcorr-vs-time
          At a few points the user is prompted to eventually break the process,
          e.g. if files are missing or their assembly has failed.
         
          Optionally plots cross-correlation series for each project

 DIRECTIVES:

  D  - Assemble calibrated seismogram ts-files from Gyyyy.ddd/* .ts
       in AG/d , one for each (sub-)project.
       (not sure if we can use mc-files).
       -split 1 for two sub-projects per project,
       -split 2 for four etc.
  R  - Assemble from .gcf, create  ts-files in Gyyyy.ddd/*10Hz.ts
       using gcf2ts-hourly.
 DRQ - Test file availability and exit
  T  - Detrend - a necessary stage
  F  - Assemble with a false time for testing
  X  - Compute cross-correlations
 XP  - Plot the cross-correlation series
 XF  - .. also for false time
 ..  - Produce an overview and exit
 
 -split #n
       The prep-ag-seismo process is run in parts; thus the same split
       option must be specified at each instance.
       Not correct! We have started to deposit a one-line source script
       under directives D and R, 
       a script that reports the settings to the subsequent process scripts
         reduce-ag-scatter
         plot-xcorr-vs-time
       (not tested as of 2016-07-15)
 
 OTHER OPTIONS:
  -ym #YYMM<x>  - the short campaign mark, YYMM of the campaign by default.
                  If more than one campaign takes place in the same month,
                  use a unique mark <x> (like the last character of the
                  campaign. Can also be used to process alternatives.
  -pngdir <d>   - added to ~/www/4me/ag , preferably a slightly different
                  name of the campaign designating an analysis variant.
                  Similar reason as with -ym , but here for the png-destination
                  By default, the first 6 characters of the campaign.
 
  -ACC          - use filenames containing -ACC instead of -ZACC
 
 FILES:
  AG/d/seis-ZAcc4-${ym}p$n-10Hz.ts
  d/scg-cal-${ym}p$n.dtr.ra.ts
  o/seis-Z-ag-${ym}p$p.corr
 
  ~/TD/a/Allcamps/o/scg-cal-$camp.ra.ts
 
   Uses xcorr-zz seismo-file AG-file
   For a test with a series of spikes in Gaussian noise, see
   xcorr-test.tse (HOW.TO at the end).
 
 EXAMPLE:
   A suite of runs, one directive at a time
prep-ag-seismo DRQ 201806a
prep-ag-seismo D   201806a
prep-ag-seismo T   201806a
prep-ag-seismo X   201806a
prep-ag-seismo X+P 201806a


reduce-ag-scatter

and a script to add the microseisms to the Allcamps/lpfu/ ts-files.