Telluric spectra:
-----------------
Download from:
http://www.eso.org/sci/facilities/paranal/decommissioned/isaac/tools/spectroscopic_standards.html
KittPeak: H,J,K
Paranal: K, L, M

Code analysis of tellrem:
-------------------------
Download tellrem code from here:
(ftp://cdsarc.u-strasbg.fr/pub/cats/J/A+A/585/A113/)

Code modifications:
All tellrem_info common block definitions amended with variable names
tellrem_test_run.pro: fixed wrong code to determine package folder (CHU)
Added numlines.pro to package (no longer in idlastro)

Running the example in directory example_files
Setup:
cd /home/chummel/oyster/source/proprietary/tellrem/example_files
TAPE1 is a link to /usr/local/src/molecfit/data/hitran/aer_v_3.2
TAPE5 should be a copy of TAPE5.UserMan
The format of TAPE5 (lnfl input) has changed: now 47 molecules instead of 39
Run lnfl to to extract wavelength regions for specific molecules from TAPE1
Change (just foir this test) oyster.pro to look in tellrempackage/routines/for code.
Start oyster in tellrempackage/example_files
tellrem_test_run,'/home/chummel/oyster/source/proprietary/',
	'/usr/local/src/molecfit/bin/lblrtm',
	'/home/chummel/oyster/source/proprietary/tellrempackage/example_files/equ.atm'
After this run, one can also test with: tellrem,'test_info',telluricremovedspectra

getabundances -> fittell -> mpfitfun('tell',x,y,err) -> mpfitfun_eval <- tell <- runlblrtm
parinfo is a one-dimensional array of structures to provide a mechanism 
	for more sophisticated constraints to be placed on parameter values.
parinfo: passed by fittell to mpfitfun, 
	parinfo is used by mpfit to fill p=parameter vector by calling mpfit_parinfo
Structure element "value" is stored in parameters p:
p=[smoothing FWHM,velocity shift,slope,intercept,H2O,CH4, CO2]
p=[0.5,0.1,-5.8,2.0,1.0,1.0,1.0]: see getabundances.pro
Constraints:
.value   - starting value for parameter
.fixed   - parameter is fixed
.limited - a two-element array, if parameter is bounded on
           lower/upper side
.limits - a two-element array, lower/upper parameter bounds, if
          limited vale is set
.step   - step size in Jacobian calc, if greater than zero

PARINFO Example for a total of 5 parameters:
parinfo = replicate({value:0.D, fixed:0, limited:[0,0],limits:[0.D,0]}, 5)
parinfo[0].fixed = 1				: first parameter fixed (at 5.7, see below)
parinfo[4].limited[0] = 1			: last parameter is limited
parinfo[4].limits[0]  = 50.D			: lower limit of parameter value
parinfo[4].limits[1]  = 5000.D			: upper limit of parameter value
parinfo[*].value = [5.7D, 2.2, 500., 1.5, 2000.]: starting values

Velocity shift: in km/s, 1 km/s corresponds to 0.08 Angstrom (AA)

Adaptation to OYSTER:
---------------------
Location of GDAS data: 
ftp://ftp.eso.org/pub/dfs/pipelines/skytools/molecfit/GDAS/
cd ~/oyster/source/proprietary/tellrem/gdas
tar zxvf /usr/local/src/molecfit/share/molecfit/data/profiles/gdas/gdas_profiles_C-70.4-24.6.tar.gz
rm -f C-70.4-24.6D200[0-9]-??-??T??.gdas
rm -f C-70.4-24.6D201[0-6]-??-??T??.gdas

Reference files in tellrem/gravity:
TAPE1, TAPE3, TAPE5
TAPE3 must be created using lnfl with TAPE5 (copy of TAPE5.UserMan)

LBLRTM only computes wavenumber intervals of 2020 1/cm
With lambda[micron], wn=1e4/lambda
E.g., for H2O region, 2.41-2.45, wn_start-wn_end=70, much smaller than the limit

gravity_tellcorr,prepare=4 tasks to execute before calling tellrem:
Find suitable gdas file, compute dew points, and save in GDAS folder for tellrem

tellrem_info file: lines for gdas folder, equ.atm file, lblrtm executable, and GRAVITY data
Example:
/home/chummel/oyster/source/proprietary/tellrem/GDAS    ; folder with GDAS file
/home/chummel/oyster/source/proprietary/tellrem/equ.atm ; MIPAS model atmosphere
/usr/local/src/molecfit/bin/lblrtm                      ; LBLRTM executable
/data/gravity/scra/USR0017_2/U1_                        ; location of FITS file
SCI                                                     ; type of observation

tellrem call:
tellrem,'tellrem.info',telluricremovedspectra

tellrem code information:
tellrem.pro: main routine, does the following:
call tellremparams:
call tellremspectra: removes the telluric lines

Check airtovac routine: is needed for XSHOOTER, but not for GRAVITY

Running tellrem:
tellrem,'tellrem.info',telluricremovedspectra

tellrem GRAVITY version test: just use XSHOOTER NIR3 data:

Integration with Pollux template spectra for late type stars:
-------------------------------------------------------------
Interferometric calibrators are often K giants: remove lines!

plotpollux GUI can do the following:
Select a template spectrum
Read an observed GRAVITY spectrum of a calibrator
Find best-fit shift and smoothing kernel for template
Normalize observed spectrum with interpolated kernel (extension "_n")
The normalized calibrator spectrum only features telluric lines
Divide science by normalized calibrator spectrum: may not have same AM
This is the classig method

Alternative: do telluric correction of SCI and CAL separately w/tellrem
Normalize calibrator spectrum with POLLUX template and then divide SCI/CAL
This last step removes the wiggles due to poor flat fielding
This could be better than classic in case of AM difference SCI/CAL

ToDo: 

Fitting GRAVITY data:
---------------------
restore,'tellremparams.sav'

Lorentzian:
...........
Fit H2O
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       7.6040493      -47.443053       1.0445682  -0.00018993055  -6.1080469e-07      0.47716287       1.0000000       1.0000000
Bestnorm:        11.547028
Fit CO2
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       6.1658643      -46.450783       1.0873403   0.00030137571  -9.6761200e-07      0.47716287       1.0000000       1.1032094
Bestnorm:        6.6261807
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.4738622      -37.582042       1.0116671  -0.00015464772   2.4368588e-07      0.47716287       1.0000000      0.81778598
Bestnorm:        7.1771650
Fit CH4
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.9724594      -47.792120       1.0223597  -7.1244976e-05  -2.2421436e-07      0.47716287      0.87463389      0.96049769
Bestnorm:        4.9745497
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.5672502      -44.805180       1.0429166   3.8018017e-05   2.1854431e-08      0.47716287      0.70865062      0.96049769
Bestnorm:        3.9741680
Begin actual fit:
Region 1
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.6204979      -47.471787      0.96563968   0.00011996818   4.9999999e-06      0.47716287      0.79164226      0.96049769
Bestnorm:        4.5666867
Region 2
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.2760351      -45.198628       1.0776631  -9.1753483e-05  -5.9464234e-07      0.47716287      0.79164226      0.96049769
Bestnorm:        3.4670322
Region 3
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.4884209      -39.725754       1.0317546  -0.00014931911  -1.3576777e-07      0.47716287      0.79164226      0.96049769
Bestnorm:        6.6621085
Region 4
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.9569040      -37.079576       1.0020653  -0.00010190240  -3.5561121e-07      0.47716287      0.79164226      0.96049769
Bestnorm:        2.6279217
Region 5
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.0000000      -35.000000       1.0043296   0.00013828145  -1.2730394e-06      0.47716287      0.79164226      0.96049769
Bestnorm:        5.2628468
Region 6
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.2983404      -55.000000       1.0104553   0.00028559750   1.0504487e-06      0.47716287      0.79164226      0.96049769
Bestnorm:        22.038565
Region 7
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.9265069      -38.540204      0.99625418   0.00012108457   1.4769798e-06      0.47716287      0.79164226      0.96049769
Bestnorm:        6.3418889
Region 8
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.3554971      -52.200179       1.0249916   7.7671856e-05  -7.1341053e-07      0.47716287      0.79164226      0.96049769
Bestnorm:        4.6778006
Region 9
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.7388194      -44.122305       1.0062473  -0.00010457394   1.1036735e-06      0.47716287      0.79164226      0.96049769
Bestnorm:        11.436483
Region 10
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       6.3910405      -51.431353       1.0250950   7.3402457e-05  -5.9490542e-07      0.47716287      0.79164226      0.96049769
Bestnorm:        5.5944606
Region 11
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.4141369      -47.149142       1.0093024  -9.3029810e-05   6.6600950e-07      0.47716287      0.79164226      0.96049769
Bestnorm:        8.1799046
Region 12
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.5588744      -46.054137       1.0124569   5.4388524e-05   1.2076304e-06      0.47716287      0.79164226      0.96049769
Bestnorm:        8.0148506
Region 13
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       6.5653471      -44.671323       1.0589620   8.4564522e-05  -1.0589334e-06      0.47716287      0.79164226      0.96049769
Bestnorm:        4.8012861
Region 14
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       6.7777151      -43.962294       1.0597621   9.1105884e-05  -6.4401673e-07      0.47716287      0.79164226      0.96049769
Bestnorm:        6.8027665
Region 15
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       7.5101893      -44.651354       1.0521609  -0.00014926590  -8.5634001e-07      0.47716287      0.79164226      0.96049769


Gaussian:
.........
Fit H2O
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.4920682      -48.563699       1.0421713  -0.00020927191  -6.9108636e-07      0.45326369       1.0000000       1.0000000
Bestnorm:        13.299124
Fit CO2
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.6230123      -47.263732       1.0738404   0.00029663657  -1.0259689e-06      0.45326369       1.0000000       1.0752333
Bestnorm:        4.4857692
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.5818475      -38.410183       1.0138790  -0.00014016587   2.4415670e-07      0.45326369       1.0000000      0.81962805
Bestnorm:        6.6187225
Fit CH4
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.5562697      -48.469671       1.0206676  -8.2222590e-05  -2.0043791e-07      0.45326369      0.81669869      0.94743069
Bestnorm:        5.7108549
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.6644652      -44.256518       1.0386236   1.6736816e-05   4.9435558e-07      0.45326369      0.70408664      0.94743069
Bestnorm:        3.8868205
Begin actual fit:
Region 1
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.6948218      -48.108187      0.96561206   9.9248521e-05   4.6979354e-06      0.45326369      0.76039267      0.94743069
Bestnorm:        3.7642897
Region 2
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.5615077      -45.673378       1.0701556  -0.00010046869  -8.5801200e-08      0.45326369      0.76039267      0.94743069
Bestnorm:        3.8552489
Region 3
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.5867353      -38.315524       1.0344906  -0.00018418521  -1.8714733e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        5.8041226
Region 4
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.6172577      -39.649395       1.0011465  -0.00010582803  -3.1726133e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        2.6342050
Region 5
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.4867327      -44.086340       1.0043194   0.00014125609  -1.3065233e-06      0.45326369      0.76039267      0.94743069
Bestnorm:        5.3548390
Region 6
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.8972413      -55.000000       1.0106550   0.00028761506   1.0568458e-06      0.45326369      0.76039267      0.94743069
Bestnorm:        21.861137
Region 7
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.8150172      -35.000000      0.99396800   0.00012693185   1.6622570e-06      0.45326369      0.76039267      0.94743069
Bestnorm:        6.3862982
Region 8
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.5715843      -54.163490       1.0244196   6.6341019e-05  -6.5690050e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        4.8137391
Region 9
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.5801907      -41.311273       1.0062536  -8.4393441e-05   1.2079013e-06      0.45326369      0.76039267      0.94743069
Bestnorm:        11.448298
Region 10
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.5120128      -49.609964       1.0247215   5.1395520e-05  -8.8026824e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        5.5330318
Region 11
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.6749236      -49.461084       1.0084943  -9.5290421e-05   7.0913848e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        8.5392125
Region 12
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.6573116      -46.884307       1.0122885   3.8626247e-05   8.6148305e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        7.7448374
Region 13
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.7198163      -44.036869       1.0522968   8.6773496e-05  -8.9752649e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        4.1526404
Region 14
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       4.6506261      -44.761352       1.0564481   0.00010472952  -3.9867746e-07      0.45326369      0.76039267      0.94743069
Bestnorm:        6.8547246
Region 15
      smooth,           Dv (km/s),   Y-intercept,     slope,         curvature,         water,         methane,        co2
       5.5000000      -46.406700       1.0477563  -0.00014300355  -8.8407308e-07      0.45326369      0.76039267      0.94743069



Line width: ~5 AA, corresponding to   2.643 AA/element: 1.9 pix

Best fit v=-45 km/s, convolve lblrtm model with Gaussian width 5 AA
