
$LIBS=/export/cluster2/pp/
$FGMROOT=/home/FGM/

raw data input: $LIBS/input/pegasus/*.(NS|BS)
                                       |  |                             
                                       |  Burst Science                 
                                       Normal Science                   

                - contains: Bx, By, Bz, t, resolution, range, ?..?


####### A #######  Prepare to calibrate range 2 (spin plane offset) and rc

(A1) Produce log files
     
     - listfgm.pl -m month
         input:   raw data files
         output:  $FGMROOT/log/cd_log/YY_MM/CnYYMMDD_B.(NS|BS)log
         content: range changes, gaps
     
(A2) Chose 5 min interval from csds (quicklook, 6 hr overview)

                            - range 2  (B < 64 nT)
                            - quiet
                            - data available for all 4 sc

(A3) Write (by hand) $FGMROOT/cfg/uncal_YYMM.txt file used for offset (2) 
     and HH (r>2) calibration. (or uncal.txt at second iteration)

     - content:   sc  range  day  hr_begin  min_begin
               

(A4) Produce uncal files for range 2 (ASCII input files for calibration)
     
     - mkuncal.pl -m month
         input:   raw data, $FGMROOT/cfg/uncal_YYMM.txt from (A3)
         output:  $FGMROOT/data/uncal/YY_MM/cn(i)_YYMMDD...uncal  |
                                               |                  |-> 5 min.
                                               inboard sensor     |
         content: Bx, By, Bz, |B|, range, ...


(A5) Produce uncal files for range changes

     - findRC.pl -m month
         input:   log files from (A1) , raw data
         output:  $FGMROOT/data/uncal/YY_MM/
                  uncal*(rNtoM|MfN).uncal
                          |__|_|_|__________ M,N = {2,3,4,5,6,7}, N<M
         content: same format as range uncal files



####### B #######  Calibrate range 2 -- 1st iteration (initialization)

(B1) Produce calibration files

     - edit $FGMROOT/cfg/cls_ini.cfg 
     - run cls_ini.pro, sc                  (sc=1,4)  
         input:   *.uncal files from (A4)     
         output:  $FGMROOT/data/dcalf/*.(fgmcal|cfgnew)
                                           |       |
                                           |       parameters for GUI 
                                           correction matrices elements
         content: calibration parameters
     
(B2) Produce *.cal files (on libs)

     - copy *.(fgmcal|cgfnew) to libs (calfiles2libs.pl -m month)
     - makecal.pl -m month -b day_begin -e day_end
         input:   *.fgmcal from (B1), raw data, ...
         output:  $LIBS/output/cal/*.cal
                  $LIBS/output/cal/specpictures/*.png
         content: calibrated data file (ASCII) -- same format as *.uncal
                  and dynamic spectra


####### C #######  Check initial calibration result

(C1) Produce spectra -- if not produced by makecal.pl (B2)

     - run fgm_spectra.pro
         input:   cal files from (B2)
         output:  $LIBS/output/cal/specpictures/*.png
         content: time series and
                  dynamic spectra for |B|, Byz, Bx - (ignore)
                                       |____|   |
                                         |      for spin angle
                                         |      (not for C1, not for range 2)
                                         |
                                         overall calibration,
                                         range changes, and higher harmonics
(C2) Examine spectra with KHF

     - look for: 'bad' 5 min choice for r2           |
                 higher harmonics  (r3, r4, r5)      |- look at B_yz and |B| 
                 range changes - look at time series |
                 ____|____    
                |    |    |    
               2->3 3->4 4->5         
                |    |    |         
           ignore check  check      
                             
(C3) Write down necessary adjustements


####### D #######  Re-calibrate r2 (by hand)

(D1) Produce new uncal files when necessary (A2,A3,A4) - r2 and HH (r>2)

(D2) Calibrate r2 (offset_sc)
  
  - edit $FGMROOT/cfg/cls.cfg 
  - run cls.pro, sc (GUI)
         input:   last cal param saved in $DCAL/cal?_1d.neu file
                  $LIBS/output/uncal/YY_MM/*.uncal (A4)
         output:  $DCAL/dailycalf/c?_YYMMDD_hhmm*.cfgnew, *.fgmcal
         content: calibration parameters
 
  * [select input file] (open r2 uncal: $LIBS/output/uncal/YY_MM/*r2.uncal)
  * [calibration] -> [show cal]              (opens parameter table)
  * [calibration] -> [spin plane offset]
  * [update] -> [sc offset] (updates offset_sc values (y and z values))  
  * [save]                                   (cgfnew, fgmcal)


####### E #######  Calibrate range changes (by hand)


(E1) Produce range changes plots (B time series around the rc)

     - run $FGMROOT/idl/plot_rc.pro, sc, yymmdd
         input:   log files, rc uncal files
         output:  $LIBS/output/cfcal/cf_Cn_YYMMDD.ps, 
                  $LIBS/output/cfcal/cf_cn_YYMMDD_rMN.cal
         content: - ps file, |B|, Byz, Bx
                  - cal file, same format as uncal and cal files

(E2) Examine rc plots

         look for: - discontinuity in Bx and Byz
                   - spin tone amplitude changes in Byz and |B|
                   - mean slope discontinuity in Byz

(E3) Calibrate for rc

     - open rc file: $LIBS/output/uncal/YY_MM/*rNtoM.uncal

     - fix the jump in Bx:
             adjust first (x) value of offset_rM
                                               |
                                               higher range
             (add difference higher - lower )
     
     - fix the amplitude change
              - range N spin tone:
                * [calibration]->[spin plane offset]
                * [update] -> [range change] 
                  (updates offset_sc values (y and z values))
              - range M spin tone:
                open next rc file (*rMfN)
                * [calibration]->[spin plane offset]
                * [update] -> [range change]
                  (adds the difference to values 2 and 3 of offset_rM)

     - adjust r2 again (spacecraft ofset) (D2)
     * [save]   
     - check time series plot (range change plot)
     

####### F ####### Calibrate higher harmonics (by hand)

    - produce uncal file (5 min) for the higher harmonics
      (edit uncal.txt and run mkuncal.pl script)
      
    - open (select input file) the uncal file in cls.pro
    
    - * [Calib] -> [spin plane angle]
    - * [update] -> [higher harmonic] 
        (this updates values of Matrix_N (last line, last two columns))
                                       |
                                       range
     - adjust r2 again (spacecraft ofset) (D2)
     * [save]   

####### G ####### Next day (D) (E) (F)

####### H ####### Check calibration (goto B2)

####### I ####### Archive calibration results

     - archive.pl -m month 
     
---------------------

NOTES

+imchalib+

1. ranges: 0 < r2 < 64 < r3 < 256 < r4 < 1024 < r5 < 4096 < r6 < 16348 < r7 < ..




