WikiStart: utildocs.txt

File utildocs.txt, 50.8 KB (added by pcr, 13 years ago)

documentation for general utility procedures

Line 
1
2----- Documentation for Util\angular_dist.pro -----
3 NAME:
4        ANGULAR_DIST
5
6 AUTHOR:
7       pierre.cruzalebes@oca.eu
8
9 PURPOSE:
10       compute angular distance between 2 targets defined by their equatorial coordinates
11       using the haversine formula.
12
13 CATEGORY:
14       utilities
15
16 CALLING SEQUENCE:
17        ANG_DIST = ANGULAR_DIST(COORD1,COORD2)
18
19 INPUTS:
20        COORD1 = coordinates (RA/DEC, both in deg) of the first target (complex type).
21        COORD2 = coordinates (RA/DEC, both in deg) of the second target (complex type).
22
23 OUTPUTS:
24        Function result = ANG_DIST = angular distance (in deg).
25
26 OPTIONAL OUTPUT PARAMETER:
27        NONE.
28
29 COMMON BLOCKS:
30        NONE.
31
32 SIDE EFFECTS:
33        NONE.
34
35 RESTRICTIONS:
36        NONE.
37
38 PROCEDURE:
39
40 LOCAL PROCEDURE CALLED:
41        NONE.
42
43 LOCAL FUNCTION USED:
44        COSD
45       HAVD
46
47 LOCAL SYSTEM VARIABLE USED:
48        NONE
49
50 REVISION HISTORY:
51       Written by pcr 2009/01/28
52       last modification by pcr 2010/02/04
53
54----- Documentation for Util\bisp_proj.pro -----
55 NAME:
56        BISP_PROJ
57
58 AUTHOR:
59       pierre.cruzalebes@oca.eu
60
61 PURPOSE:
62        bispectrum projection using simple baseline triplet average and trapezoidal wavelength integration with regular segments
63
64 CATEGORY:
65       utilities
66
67 CALLING SEQUENCE:
68        Y_PROJ = BISP_PROJ(N_TRI,N_VALT,N_INT,N_VALS,Y_VAL)
69
70 INPUTS:
71       N_TRI = nber of triplets.
72       N_VALT = nber of values per triplet.
73       N_INT = nber of spectral intervals.
74       N_VALS = nber of values per spectral interval.
75        Y_VAL = Row vector of N_TRI*N_VALT*N_INT*N_VALS*N_PAR function complex values
76
77 OUTPUT:
78        Function result = Y_PROJ = Array of (N_TRI*N_INT,N_PAR) projected complex values.
79
80 OPTIONAL OUTPUT PARAMETERS:
81        NONE.
82
83 COMMON BLOCKS:
84        NONE.
85
86 SIDE EFFECTS:
87        NONE.
88
89 RESTRICTIONS:
90        NONE.
91
92 PROCEDURE:
93
94 LOCAL PROCEDURE CALLED:
95        NONE
96
97 LOCAL FUNCTION USED:
98        REGUTRAP
99
100 LOCAL SYSTEM VARIABLE USED:
101        NONE
102
103 REVISION HISTORY:
104       Written by pcr 2008/05/02
105        last modification by pcr 2010/05/29
106
107----- Documentation for Util\bprecess.pro -----
108 NAME:
109       BPRECESS
110
111 PURPOSE:
112       Precess positions from J2000.0 (FK5) to B1950.0 (FK4)
113
114 CATEGORY:
115       Utilities
116
117 EXPLANATION:
118       Calculates the mean place of a star at B1950.0 on the FK4 system from
119       the mean place at J2000.0 on the FK5 system.
120
121 CALLING SEQUENCE:
122       bprecess, ra, dec, ra_1950, dec_1950
123
124 INPUTS:
125       RA,DEC - Input J2000 right ascension and declination in *degrees*.
126               Scalar or N element vector
127
128 OUTPUTS:
129       RA_1950, DEC_1950 - The corresponding B1950 right ascension and
130               declination in *degrees*.    Same number of elements as
131               RA,DEC but always double precision.
132
133 OPTIONAL INPUT-OUTPUT KEYWORDS
134       NONE
135
136 NOTES:
137       The algorithm is taken from the Explanatory Supplement to the
138       Astronomical Almanac 1992, page 186.
139       Also see Aoki et al (1983), A&A, 128,263
140
141       BPRECESS distinguishes between the following two cases:
142       (1) The proper motion is known and non-zero
143       (2) the proper motion is unknown or known to be exactly zero (i.e.
144               extragalactic radio sources).   In this case, the reverse of
145               the algorithm in Appendix 2 of Aoki et al. (1983) is used to
146               ensure that the output proper motion is  exactly zero. Better
147               precision can be achieved in this case by inputting the EPOCH
148               of the original observations.
149
150       The error in using the IDL procedure PRECESS for converting between
151       B1950 and J1950 can be up to 12", mainly in right ascension.   If
152       better accuracy than this is needed then BPRECESS should be used.
153
154       An unsystematic comparison of BPRECESS with the IPAC precession
155       routine (http://nedwww.ipac.caltech.edu/forms/calculator.html) always
156       gives differences less than 0.15".
157
158 REVISION HISTORY:
159       Written,    W. Landsman                October, 1992
160       Vectorized, W. Landsman                February, 1994
161       Treat case where proper motion not known or exactly zero  November 1994
162       Handling of arrays larger than 32767   Lars L. Christensen, march, 1995
163       Converted to IDL V5.0   W. Landsman   September 1997
164       Fixed bug where A term not initialized for vector input
165            W. Landsman        February 2000
166       Adapted for SPIDAST P. Cruzalèbes March 2010 with calls to SIND & COSD
167
168
169----- Documentation for Util\complex2real.pro -----
170 NAME:
171        COMPLEX2REAL
172
173 AUTHOR:
174       pierre.cruzalebes@oca.eu
175
176 PURPOSE:
177        function converting n-dim complex vector into 2n-dim real
178
179 CATEGORY:
180       utilities
181
182 CALLING SEQUENCE:
183        RY = COMPLEX2REAL(CY)
184
185 INPUTS:
186       CY = input complex vector.
187
188 OUTPUT:
189        Function result = RY = output real vector.
190
191 OPTIONAL OUTPUT PARAMETERS:
192        NONE.
193
194 COMMON BLOCKS:
195        NONE.
196
197 SIDE EFFECTS:
198        NONE.
199
200 RESTRICTIONS:
201        NONE.
202
203 PROCEDURE:
204
205 LOCAL PROCEDURE CALLED:
206        NONE
207
208 LOCAL FUNCTION USED:
209        NONE
210
211 LOCAL SYSTEM VARIABLE USED:
212        NONE
213
214 REVISION HISTORY:
215       Written by pcr 2008/07/01
216        last modification by pcr 2010/02/04
217
218----- Documentation for Util\ct2lst.pro -----
219 NAME:
220     CT2LST
221
222 PURPOSE:
223     Convert from Local Civil Time to Local Mean Sidereal Time.
224
225 CATEGORY:
226     Utilities
227
228 CALLING SEQUENCE:
229     CT2LST, Lng, Tme, Lst
230
231 INPUTS:
232     Lng  - The longitude in degrees (east of Greenwich) of the place for
233            which the local sidereal time is desired, scalar.   The Greenwich
234            mean sidereal time (GMST) can be found by setting Lng = 0.
235     Tme  - The Julian date of time in question, scalar
236
237 OPTIONAL INPUTS:
238      None
239
240 OUTPUTS:
241       Lst   The Local Sidereal Time for the date/time specified in hours.
242
243 RESTRICTIONS:
244       None
245
246 PROCEDURE:
247       The Julian date of the day and time is question is used to determine
248       the number of days to have passed since 0 Jan 2000.  This is used
249       in conjunction with the GST of that date to extrapolate to the current
250       GST; this is then used to get the LST.    See Astronomical Algorithms
251       by Jean Meeus, p. 84 (Eq. 11-4) for the constants used.
252
253 EXAMPLE:
254       The Web site  http://tycho.usno.navy.mil/sidereal.html contains more
255       info on sidereal time, as well as an interactive calculator.
256
257 PROCEDURES USED:
258       none
259
260 REVISION HISTORY:
261     Adapted from the FORTRAN program GETSD by Michael R. Greason, STX,
262               27 October 1988.
263     Use IAU 1984 constants Wayne Landsman, HSTX, April 1995, results
264               differ by about 0.1 seconds 
265     Longitudes measured *east* of Greenwich   W. Landsman    December 1998
266     Time zone now measure positive East of Greenwich W. Landsman July 2008
267     Remove debugging print statement  W. Landsman April 2009
268     Adapted for SPIDAST by P. Cruzalèbes March 2010
269
270----- Documentation for Util\date_conv.pro -----
271 NAME:
272     DATE_CONV
273
274 PURPOSE:
275     Perform conversion of dates to one of six possible formats.
276
277 CATEGORY:
278     Utilities
279
280 EXPLANATION:
281     The following date formats are allowed
282
283       format 1: real*8 scalar encoded as:
284               year*1000 + day + hour/24. + min/24./60 + sec/24./60/60
285               where day is the day of year (1 to 366)
286       format 2: Vector encoded as:
287               date(0) = year (eg. 2005)
288               date(1) = day of year (1 to 366)
289               date(2) = hour
290               date(3) = minute
291               date(4) = second
292       format 3: string (ascii text) encoded as
293               DD-MON-YEAR HH:MM:SS.SS
294               (eg.  14-JUL-2005 15:25:44.23)
295            OR
296               YYYY-MM-DD HH:MM:SS.SS  (ISO standard)
297               (eg.  1987-07-14 15:25:44.23 or 1987-07-14T15:25:44.23)
298                   
299       format 4: three element vector giving spacecraft time words
300       from a Hubble Space Telescope (HST) telemetry packet.   Based on
301       total number of secs since midnight, JAN. 1, 1979
302
303       format 5: Julian day. As this is also a scalar, like format 1,
304        the distinction between the two on input is made based on their
305        value. Numbers > 2300000 are interpreted as Julian days.
306
307 CALLING SEQUENCE
308       results = DATE_CONV( DATE, TYPE )
309
310 INPUTS:
311       DATE - input date in one of the possible formats. Must be scalar.
312       TYPE - type of output format desired.  If not supplied then
313               format 3 (real*8 scalar) is used.
314                       valid values:
315                       'REAL'  - format 1
316                       'VECTOR' - format 2
317                       'STRING' - format 3
318                       'FITS' - YYYY-MM-DDTHH:MM:SS.SS'
319                       'JULIAN' - Julian date
320                       'MODIFIED' - Modified Julian date (JD-2400000.5)
321               TYPE can be abbreviated to the single character strings 'R',
322               'V', 'S', 'F', 'J', and 'M'.
323               Nobody wants to convert TO spacecraft time (I hope!)
324 OUTPUTS:
325       The converted date is returned as the function value.
326
327 HISTORY:
328      version 1  D. Lindler  July, 1987
329      adapted for IDL version 2  J. Isensee  May, 1990
330      Made year 2000 compliant; allow ISO format input  jls/acc Oct 1998
331      DJL/ACC Jan 1998, Modified to work with dates such as 6-JAN-1996 where
332               day of month has only one digit.
333      DJL, Nov. 2000, Added input/output format YYYY-MM-DDTHH:MM:SS.SS
334      Replace spaces with '0' in output FITS format  W.Landsman April 2006
335      Added Julian date capabilities on input and output.  M.Perrin, July 2007
336      Adapted for SPIDAST, P. Cruzalèbes March 2010
337
338----- Documentation for Util\daycnv.pro -----
339 NAME:
340       DAYCNV
341
342 PURPOSE:
343       Converts Julian dates to Gregorian calendar dates
344
345 CATEGORY:
346       Utilities
347
348 CALLING SEQUENCE:
349       DAYCNV, XJD, YR, MN, DAY, HR
350
351 INPUTS:
352       XJD = Julian date, positive double precision scalar or vector
353
354 OUTPUTS:
355       YR = Year (Integer)
356       MN = Month (Integer)
357       DAY = Day (Integer)
358       HR = Hours and fractional hours (Real).   If XJD is a vector,
359               then YR,MN,DAY and HR will be vectors of the same length.
360
361 WARNING:
362       Be sure that the Julian date is specified as double precision to
363       maintain accuracy at the fractional hour level.
364
365 METHOD:
366       Uses the algorithm of Fliegel and Van Flandern (1968) as reported in
367       the "Explanatory Supplement to the Astronomical Almanac" (1992), p. 604
368       Works for all Gregorian calendar dates with XJD > 0, i.e., dates after
369       -4713 November 23.
370
371 REVISION HISTORY:
372       Converted to IDL from Yeoman's Comet Ephemeris Generator,
373       B. Pfarr, STX, 6/16/88
374       Converted to IDL V5.0   W. Landsman   September 1997
375       Adapted for SPIDAST, P. Cruzalèbes March 2010
376
377----- Documentation for Util\deg2dms.pro -----
378 NAME:
379   DEG2DMS
380
381 AUTHOR:
382   pierre.cruzalebes@oca.eu
383
384 PURPOSE:
385   convert angle in decimal degree to deg:min:sec
386
387 CATEGORY:
388   utilities
389
390 INPUT KEYWORD:
391   D = scalar value of angle to convert
392
393 OUTPUT KEYWORD:
394   DMS = string chain '+-deg:min:sec'
395
396 LOCAL PROCEDURE CALLED:
397   NONE
398
399 LOCAL FUNCTION USED:
400   NONE
401
402 LOCAL SYSTEM VARIABLE USED:
403   NONE
404
405 REVISION HISTORY:
406   Written by pcr 2010/03/16
407   last modification by pcr 2010/03/17
408
409----- Documentation for Util\deg2hms.pro -----
410 NAME:
411   DEG2HMS
412
413 AUTHOR:
414   pierre.cruzalebes@oca.eu
415
416 CATEGORY:
417   utilities
418
419 PURPOSE:
420   convert angle in decimal degree to hour:min:sec
421
422 INPUT KEYWORD:
423   D = scalar value of angle to convert
424
425 OUTPUT KEYWORD:
426   HMS = string chain '+-hour:min:sec'
427
428 LOCAL PROCEDURE CALLED:
429   NONE
430
431 LOCAL FUNCTION USED:
432   NONE
433
434 LOCAL SYSTEM VARIABLE USED:
435   NONE
436
437 REVISION HISTORY:
438   Written by pcr 2010/03/17
439
440----- Documentation for Util\euler.pro -----
441 NAME:
442     EULER
443
444 PURPOSE:
445     Transform between Galactic, celestial, and ecliptic coordinates.
446
447 CATEGORY:
448     Utilities
449
450 EXPLANATION:
451
452 CALLING SEQUENCE:
453      EULER, AI, BI, AO, BO, SELECT
454
455 INPUTS:
456       AI - Input Longitude in DEGREES.
457       BI - Input Latitude in DEGREES.
458       SELECT - Integer (1-6) specifying type of coordinate transformation.
459
460      SELECT   From          To        |   SELECT      From            To
461       1     RA-Dec (2000)  Galactic   |     4       Ecliptic      RA-Dec
462       2     Galactic       RA-DEC     |     5       Ecliptic      Galactic
463       3     RA-Dec         Ecliptic   |     6       Galactic      Ecliptic
464
465 OUTPUTS:
466       AO - Output Longitude in DEGREES, always double precision
467       BO - Output Latitude in DEGREES, always double precision
468
469 OPTIONAL INPUT KEYWORD:
470
471 LOCAL PROCEDURE CALLED:
472        NONE
473
474 LOCAL FUNCTION USED:
475        NONE
476
477 LOCAL SYSTEM VARIABLE USED:
478        NONE
479
480 EXAMPLE:
481
482 REVISION HISTORY:
483       Written W. Landsman,  February 1987
484       Adapted from Fortran by Daryl Yentis NRL
485       Made J2000 the default, added /FK4 keyword  W. Landsman December 1998
486       Add option to specify SELECT as a keyword W. Landsman March 2003
487       Use less virtual memory for large input arrays W. Landsman June 2008
488       Added /RADIAN input keyword  W. Landsman   Sep 2008
489       Adapted by P. Cruzalèbes Mar 2010
490
491----- Documentation for Util\extract_proheader.pro -----
492 NAME:
493        EXTRACT_PROHEADER
494
495 AUTHOR:
496       pierre.cruzalebes@oca.eu
497
498 PURPOSE:
499       extract the content of the header of a specified procedure
500
501 CATEGORY:
502       utilities
503
504 CALLING SEQUENCE:
505        HEAD = EXTRACT_PROHEADER(PRO_NAME)
506
507 INPUTS:
508        PRO_NAME = name of the procedure
509
510 OUTPUTS:
511        Function result = HEAD = procedure header
512
513 OPTIONAL OUTPUT PARAMETER:
514        NONE
515
516 COMMON BLOCKS:
517        NONE
518
519 SIDE EFFECTS:
520        NONE
521
522 REQUIREMENTS:
523       header part must start with ';+' and end with ';-'
524
525 PROCEDURE:
526
527 LOCAL PROCEDURE CALLED:
528        NONE
529
530 LOCAL FUNCTION USED:
531        NONE
532
533 LOCAL SYSTEM VARIABLE USED:
534        MAX_HEADER
535
536 REVISION HISTORY:
537      Written by pcr 2010/02/05
538      last modification by pcr 2010/03/29
539
540----- Documentation for Util\functproj.pro -----
541 NAME:
542        FUNCTPROJ
543
544 AUTHOR:
545       pierre.cruzalebes@oca.eu
546
547 PURPOSE:
548        function projection using simple baseline average
549       and trapezoidal wavelength integration with regular segments
550
551 CATEGORY:
552       utilities
553
554 CALLING SEQUENCE:
555        Y_PROJ = FUNCTPROJ(N_BAS,N_VALB,N_INT,N_VALS,Y_VAL)
556
557 INPUTS:
558       N_BAS = nber of baselines.
559       N_VALB = nber of values per baseline.
560       N_INT = nber of spectral intervals.
561       N_VALS = nber of values per spectral interval.
562        Y_VAL = 2-dim array of (N_BAS*N_VALB*N_INT*NVALS,N_PAR) function values.
563
564 OUTPUT:
565        Function result = Y_PROJ = Array of (N_BAS*N_INT,N_PAR) projected values.
566
567 OPTIONAL OUTPUT PARAMETERS:
568        NONE.
569
570 COMMON BLOCKS:
571        NONE.
572
573 SIDE EFFECTS:
574        NONE.
575
576 RESTRICTIONS:
577        NONE.
578
579 PROCEDURE:
580
581 LOCAL PROCEDURE CALLED:
582        NONE
583
584 LOCAL FUNCTION USED:
585        REGUTRAP
586
587 LOCAL SYSTEM VARIABLE USED:
588        NONE
589
590 REVISION HISTORY:
591       Written by pcr 2006/11/22
592        Last moddification by pcr 2010/05/29
593
594----- Documentation for Util\gaussian.pro -----
595 NAME:
596        GAUSSIAN
597 
598 AUTHOR:
599       pierre.cruzalebes@oca.eu
600
601 PURPOSE:
602       compute three-parameter Gaussian function.
603
604 CATEGORY:
605       Utilities
606
607 CALLING SEQUENCE:
608        Y = GAUSSIAN(X,X0,GAMMA,I)
609
610 INPUTS:
611        X = row vector of values to be evaluated.
612        X0 = location parameter, specifying location of peak of function.
613       GAMMA = scale parameter, specifying half-width at half-maximum (HWHM).
614       I = height of peak (amplitude).
615
616 OUTPUTS:
617        Function result = Y = Gaussian function of X (same dim as X).
618
619 OPTIONAL OUTPUT PARAMETER:
620        NONE.
621
622 COMMON BLOCKS:
623        NONE.
624
625 SIDE EFFECTS:
626        NONE.
627
628 RESTRICTIONS:
629        NONE.
630
631 PROCEDURE:
632       Y=I*EXP(-Z^2/2), where Z=(X-X0)/GAMMA
633
634 LOCAL PROCEDURE CALLED:
635        NONE
636
637 LOCAL FUNCTION USED:
638        NONE
639
640 LOCAL SYSTEM VARIABLE USED:
641        EPSILON
642
643 REVISION HISTORY:
644       Written by pcr 2009/01/28
645        last modification by pcr 2010/07/23
646
647----- Documentation for Util\get_syn_ref.pro -----
648 NAME:
649      GET_SYN_REF
650
651 AUTHOR:
652      pierre.cruzalebes@oca.eu
653
654 PURPOSE:
655      GET WAVELENGTH AND FLUX FROM A SYNTHETIC EXITANCE FILE
656      TO RETURN THE REFERENCE EXITANCE (INTEGRATED OVER GIVEN
657      SPECTRAL BANDWITHS)
658      AND OPTIONALLY GET WAVELENGTH, IMPACT PARAMETER, AND INTENSITY
659      FROM A CONVERTED SYNTHETIC RADIANCE FILE TO RETURN THE REFERENCE RADIANCE
660      (INTEGRATED OVER THE SAME BANDWITHS).
661      PROCEDURE USED BY FIT_MODEL, FIT_SED, CREATE_DATA, AND TEST_MODEL
662      WITH SYNTHETIC MODEL (E.G. MARCS)
663
664 CATEGORY:
665      UTILITIES
666
667 CALLING SEQUENCE:
668      GET_SYN_REF,NAME_EM,WVL,WVL_MIN,WVL_MAX,EM0,REF_FLUX,NAME_LU,WVL_MEAS,
669           RIP,REF_INT,ROSS2LD
670
671 INPUTS:
672      NAME_EM = SYNTHETIC EXITANCE FILE NAME.
673      WVL = ROW VECTOR OF WAVELENGTHS.
674      WVL_MIN = ROW VECTOR OF BANDWIDTH LOWER LIMITS, SAME SIZE AS WVL.
675      WVL_MAX = ROW VECTOR OF BANDWIDTH UPPER LIMITS, SAME SIZE AS WVL.
676      EM0 = ROW VECTOR OF THEORETICAL EXITANCE (USED WHEN NO SYNTHETIC
677             FLUX IN BANDWIDTH), SAME SIZE AS WVL.
678 OUTPUTS:
679      REF_FLUX  = ROW VECTOR OF REFERENCE FLUX, SAME SIZE AS WVL.
680
681 OPTIONAL INPUT PARAMETERS:
682      NAME_LU = SYNTHETIC RADIANCE FILE NAME (STRING).
683      WVL_MEAS = ROW VECTOR OF MEASURED WAVELENGTHS.
684
685 OPTIONAL OUTPUT PARAMETERS:
686      RIP = ROW VECTOR OF ROSSELAND TO LIMB-DARKENED PHOTETER CONVERSION FACTOR
687           + IMPACT PARAMETERS.
688      REF_INT = (LENGTH(WVL),LENGTH(RIP)) ARRAY OF REFERENCE RADIANCES.
689
690 COMMON BLOCKS:
691      NONE.
692
693 SIDE EFFECTS:
694      NONE.
695
696 RESTRICTIONS:
697      NONE.
698
699 PROCEDURE:
700      SEE CODE.
701
702 LOCAL PROCEDURE CALLED:
703      NONE
704
705 LOCAL FUNCTION USED:
706      TRAP
707
708 LOCAL SYSTEM VARIABLE USED:
709      LUMIN_STEP
710      NB_RES_STEP
711
712 REVISION HISTORY:
713      Written by pcr 2007/10/09
714      last modification by pcr 2011/01/13
715
716----- Documentation for Util\get_wave_list.pro -----
717 NAME:
718   GET_WAVE_LIST
719
720 AUTHOR:
721   pierre.cruzalebes@oca.eu
722
723 PURPOSE:
724   extract wavelength lists from closure phase or AMBER input data
725
726 CATEGORY:
727   utilities
728
729 INPUTS:
730   needs text input file (in OBS_PATH/INP/ directory) with :
731        - nber of data file(s) containing wavelength information
732        (1 data file = 1 band)
733        - input data file name(s) (1 file per row)
734        - output wavelength file name(s) (in same row)
735        - if needed: closure phase format ('clos')
736
737 REQUIREMENTS:
738   for closure phase data:
739      data read in calibrator closure phase data file(s) (in subdirectory
740      of OBS_PATH/) must be in ASCII format and contain :
741        - wavelength [nm], closure phase and err. [deg]
742   for AMBER data (default):
743      data read in calibrator bispectral data file(s) (in subdirectory of
744      OBS_PATH/) must be in ASCII format and contain :
745        - wavelength [nm], nber of sel. fr. or weight, Re(bisp) and err.,
746        Im(bisp) and err. [photoel^3]
747
748 OUTPUTS:
749    data written in output wavelength file(s) (in the same subdirectory
750    of OBS_PATH/) are (in this order, one row per spectral channel) :
751        - wavelength and bandwidth [m] for each band
752
753 LOCAL PROCEDURE CALLED:
754        RESET_PLOT
755
756 LOCAL FUNCTION USED:
757        EXTRACT_PROHEADER
758
759 LOCAL SYSTEM VARIABLE USED:
760        NB_LAMBDA_MAX
761        OBS_PATH
762        SPEC_RES
763        SPIDAST_PATH
764
765 REVISION HISTORY:
766    Written by pcr 2010/02/07
767    last modification by pcr 2010/04/01
768
769----- Documentation for Util\heliocor.pro -----
770 NAME:
771    HELIOCOR
772
773 PURPOSE:
774   compute heliocentric velocity correction
775
776 CATEGORY:
777   utilities
778
779 CALLING SEQUENCE
780   HELIOCOR,obslong,obslat,ra,dec,pmra,pmdec,rjd,vhel,vlsr
781 
782 INPUTS:
783   vhel: heliocentric velocity correction [km/s]
784   vlsr: velocity correction to local standard of rest [km/s]
785
786 KEYWORDS:
787    OBSLON: observatory longitude [deg]
788    OBSLAT: observatory latitude [deg]
789    RA:     right ascension J2000 [deg]
790    DEC:    declination J2000 [deg]
791    PMRA:   proper motion in RA [deg]
792    PMDEC:   proper motion in DEC [deg]
793    RJD:     reduced Julian date (= JD - 2400000)
794
795 LOCAL PROCEDURE CALLED:
796   CT2LST
797   DEG2DMS
798   DEG2HMS
799   EULER
800   PRECESS
801   SUNPOS
802
803 LOCAL FUNCTION USED:
804   ANGULAR_DIST
805   COSD
806   DATE_CONV
807   SIND
808
809 LOCAL SYSTEM VARIABLE USED:
810   NONE
811
812 REVISION HISTORY:
813    Adapted to SPIDAST by pcr 2010/03/12
814    from http://www.astro.washington.edu/docs/idl/cgi-bin/getpro/library31.html?HELIOCOR
815    last modification by pcr 2010/03/17
816
817----- Documentation for Util\helio_jd.pro -----
818 NAME:
819      HELIO_JD
820
821 PURPOSE:
822      Convert geocentric (reduced) Julian date to heliocentric Julian date
823
824 CATEGORY:
825      Utilities
826
827 EXPLANATION:
828      This procedure correct for the extra light travel time between the Earth
829      and the Sun.
830
831       An online calculator for this quantity is available at
832       http://www.physics.sfasu.edu/astro/javascript/hjd.html
833
834 CALLING SEQUENCE:
835       jdhelio = HELIO_JD( date, ra, dec)
836
837 INPUTS
838       date - reduced Julian date (= JD - 2400000), scalar or vector, MUST
839               be double precision
840       ra,dec - scalars giving right ascension and declination in DEGREES
841               Equinox is J2000
842
843 OUTPUTS:
844       jdhelio - heliocentric reduced Julian date.
845
846 OPTIONAL INPUT KEYWORDS
847       NONE
848
849 Wayne Warren (Raytheon ITSS) has compared the results of HELIO_JD with the
850 FORTRAN subroutines in the STARLINK SLALIB library (see
851 http://star-www.rl.ac.uk/).
852                                                  Time Diff (sec)
853      Date               RA(2000)   Dec(2000)  STARLINK      IDL
854
855 1999-10-29T00:00:00.0  21 08 25.  -67 22 00.  -59.0        -59.0
856 1999-10-29T00:00:00.0  02 56 33.4 +00 26 55.  474.1        474.1
857 1940-12-11T06:55:00.0  07 34 41.9 -00 30 42.  366.3        370.2
858 1992-02-29T03:15:56.2  12 56 27.4 +42 10 17.  350.8        350.9
859 2000-03-01T10:26:31.8  14 28 36.7 -20 42 11.  243.7        243.7
860 2100-02-26T09:18:24.2  08 26 51.7 +85 47 28.  104.0        108.8
861 PROCEDURES CALLED:
862       bprecess, xyz, zparcheck, sind, cosd, tand
863
864 REVISION HISTORY:
865       Algorithm from the book Astronomical Photometry by Henden, p. 114
866       Written,   W. Landsman       STX     June, 1989
867       Make J2000 default equinox, add B1950, /TIME_DIFF keywords, compute
868       variation of the obliquity      W. Landsman   November 1999
869       Adapted for SPIDAST, P. Cruzalèbes March 2010
870
871----- Documentation for Util\juldate.pro -----
872 NAME:
873     JULDATE
874
875 PURPOSE:
876     Convert from calendar to Reduced Julian Date
877
878 CATEGORY:
879     Utilities
880
881 EXPLANATION:
882     Julian Day Number is a count of days elapsed since Greenwich mean noon
883     on 1 January 4713 B.C.  The Julian Date is the Julian day number
884     followed by the fraction of the day elapsed since the preceding noon.
885
886     This procedure duplicates the functionality of the JULDAY() function in
887     in the standard IDL distribution, but also allows interactive input and
888     gives output as Reduced Julian date (=JD - 2400000.5)
889     (Also note that prior to V5.1 there was a bug in JULDAY() that gave
890     answers offset by 0.5 days.)
891
892 CALLING SEQUENCE:
893     JULDATE, date, jd
894
895 INPUT:
896     DATE -  3 to 6-element vector containing year,month (1-12),day, and
897              optionally hour, minute, and second all specified as numbers
898              (Universal Time).   Year should be supplied with all digits.
899              Years B.C should be entered as negative numbers (and note that
900              Year 0 did not exist).  If Hour, minute or seconds are not
901              supplied, they will default to 0.
902
903  OUTPUT:
904       JD - Reduced Julian date, double precision scalar.  To convert to
905               Julian Date, add 2400000.5
906
907  OPTIONAL INPUT KEYWORD:
908       NONE
909
910  RESTRICTIONS:
911       The procedure HELIO_JD can be used after JULDATE, if a heliocentric
912       Julian date is required.
913
914  PROCEDURE USED:
915       NONE
916
917  REVISION HISTORY
918       Adapted from IUE RDAF (S. Parsons)                      8-31-87
919       Algorithm from Sky and Telescope April 1981
920       Added /PROMPT keyword, W. Landsman    September 1992
921       Converted to IDL V5.0   W. Landsman   September 1997
922       Make negative years correspond to B.C. (no year 0), work for year 1582
923       Disallow 2 digit years.    W. Landsman    March 2000
924       Adapted for SPIDAST, P. Cruzalèbes March 2010
925
926----- Documentation for Util\lorentzian.pro -----
927 NAME:
928        LORENTZIAN
929
930 AUTHOR:
931       pierre.cruzalebes@oca.eu
932
933 PURPOSE:
934       compute three-parameter Lorentzian function.
935
936 CATEGORY:
937       utilities
938
939 CALLING SEQUENCE:
940        Y = LORENTZIAN(X,X0,GAMMA,I)
941
942 INPUTS:
943        X = row vector of values to be evaluated.
944        X0 = location parameter, specifying location of peak of function.
945       GAMMA = scale parameter, specifying half-width at half-maximum (HWHM).
946       I = height of peak (amplitude).
947
948 OUTPUTS:
949        Function result = Y = Lorentzian function of X (same dim as X).
950
951 OPTIONAL OUTPUT PARAMETER:
952        NONE.
953
954 COMMON BLOCKS:
955        NONE.
956
957 SIDE EFFECTS:
958        NONE.
959
960 RESTRICTIONS:
961        NONE.
962
963 PROCEDURE:
964
965 LOCAL PROCEDURE CALLED:
966        NONE
967
968 LOCAL FUNCTION USED:
969        NONE
970
971 LOCAL SYSTEM VARIABLE USED:
972        NONE
973
974 MODIFICATION HISTORY:
975      Written by pcr 2009/01/28
976      last modification by pcr 2009/02/01
977
978----- Documentation for Util\make_tab3.pro -----
979 NAME:
980        MAKE_TAB3
981
982 AUTHOR:
983       pierre.cruzalebes@oca.eu
984
985 PURPOSE:
986        create triple index table
987
988 CATEGORY:
989       utilities
990
991 CALLING SEQUENCE:
992        TAB = MAKE_TAB3(N_TRI)
993
994 INPUTS:
995       N_TRI = nber of baseline triplets.
996
997 OUTPUT:
998        Function result = TAB = Array of ((N_TRI+1)*3) baseline indexes
999        (first column = N_OUV, N_PAIR, N_TRI).
1000
1001 OPTIONAL OUTPUT PARAMETERS:
1002        NONE.
1003
1004 COMMON BLOCKS:
1005        NONE.
1006
1007 SIDE EFFECTS:
1008        NONE.
1009
1010 RESTRICTIONS:
1011        NONE.
1012
1013 PROCEDURE:
1014
1015 LOCAL PROCEDURE CALLED:
1016        NONE
1017
1018 LOCAL FUNCTION USED:
1019        NONE
1020
1021 LOCAL SYSTEM VARIABLE USED:
1022        NONE
1023
1024 REVISION HISTORY:
1025      Written by pcr 2008/05/04
1026      Last modification by pcr 2008/12/22
1027
1028----- Documentation for Util\min_pdr_radius.pro -----
1029 NAME:
1030        MIN_PDR_RADIUS
1031
1032 AUTHOR:
1033       pierre.cruzalebes@oca.eu
1034
1035 PURPOSE:
1036        MEASURE LOCATION DEFINED BY MINIMUM OF FIRST PARTIAL DERIVATIVE
1037       (INFLEXION POINT) OF NORMALIZED RADIAL RADIANCE DISTRIBUTION
1038       (MUST BE DECREASING).
1039        FUNCTION USED BY CONVERT_LIMB_DATA, FIT_MODEL, CREATE_DATA,
1040       AND TEST_MODEL WITH SYNTHETIC MODEL (E.G. MARCS)
1041
1042 CATEGORY:
1043        UTILITIES
1044
1045 CALLING SEQUENCE:
1046       RADIUS = MIN_PDR_RADIUS(RIP,REF_INT)
1047
1048 INPUTS:
1049       RIP = ROW VECTOR OF IMPACT PARAMETERS (OF LENGTH NB_RIP).
1050        REF_INT = 2-DIM ARRAY OF NORMALIZED REFERENCE INTENSITIES
1051       (OF SIZE NB_LAMBDA*NB_RIP).
1052
1053 OUTPUTS:
1054        RADIUS  = ROW VECTOR OF RADIUS (OF LENGTH NB_LAMBDA).
1055
1056 OPTIONAL INPUT PARAMETERS:
1057        NONE.
1058
1059 OPTIONAL OUTPUT PARAMETERS:
1060       NONE.
1061
1062 COMMON BLOCKS:
1063        NONE.
1064
1065 SIDE EFFECTS:
1066        NONE.
1067
1068 RESTRICTIONS:
1069        NONE.
1070
1071 PROCEDURE:
1072
1073 LOCAL PROCEDURE CALLED:
1074        NONE
1075
1076 LOCAL FUNCTION USED:
1077        NONE
1078
1079 LOCAL SYSTEM VARIABLE USED:
1080       MAX_LONG
1081
1082 REVISION HISTORY:
1083      Written by pcr 2008/12/07
1084      Last modification by pcr 2010/03/25
1085
1086----- Documentation for Util\plot_spectra.pro -----
1087 NAME:
1088       plot_spectra
1089
1090 AUTHOR:
1091       pierre.cruzalebes@oca.eu
1092
1093 PURPOSE:
1094       plot synthetic spectral radiant exitance files
1095
1096 CATEGORY:
1097       utility
1098
1099 INPUTS:
1100       need text input file with:
1101           - nber of files to plot
1102           - names of the exitance files to plot
1103
1104 LOCAL PROCEDURE CALLED:
1105        RESET_PLOT
1106
1107 LOCAL FUNCTION USED:
1108        none
1109
1110 LOCAL SYSTEM VARIABLE USED:
1111        OBS_PATH
1112        SYNTHE_PATH
1113
1114 REVISION HISTORY:
1115       Written by pcr 2008/04/27
1116
1117----- Documentation for Util\precess.pro -----
1118 NAME:
1119      PRECESS
1120
1121 PURPOSE:
1122      Precess coordinates from J2000.0 to EQUINOX.
1123
1124 CATEGORY:
1125      Utilities
1126
1127 EXPLANATION:
1128      The (RA,DEC) system is FK5 based on epoch J2000.0
1129
1130
1131 CALLING SEQUENCE:
1132      PRECESS, ra, dec, equinox
1133
1134 INPUTS:
1135      RA - Input right ascension (scalar or vector) in DEGREES
1136      DEC - Input declination in DEGREES (scalar or vector)
1137      EQUINOX - Equinox of precessed coordinates.
1138
1139 OUTPUTS:
1140      The input RA and DEC are modified by PRECESS to give the
1141      values after precession.
1142
1143 OPTIONAL INPUTS:
1144      NONE
1145
1146 OPTIONAL INPUT KEYWORDS:
1147      NONE
1148
1149 RESTRICTIONS:
1150       Accuracy of precession decreases for declination values near 90
1151       degrees.  PRECESS should not be used more than 2.5 centuries from
1152       2000 on the FK5 system
1153
1154 PROCEDURE:
1155       Algorithm from Computational Spherical Astronomy by Taff (1983),
1156       p. 24. (FK4). FK5 constants from "Astronomical Almanac Explanatory
1157       Supplement 1992, page 104 Table 3.211.1.
1158
1159 PROCEDURE CALLED:
1160       Function PREMAT - computes precession matrix
1161
1162 REVISION HISTORY
1163       Written, Wayne Landsman, STI Corporation  August 1986
1164       Correct negative output RA values   February 1989
1165       Added /PRINT keyword      W. Landsman   November, 1991
1166       Provided FK5 (J2000.0)  I. Freedman   January 1994
1167       Precession Matrix computation now in PREMAT   W. Landsman June 1994
1168       Added /RADIAN keyword                         W. Landsman June 1997
1169       Converted to IDL V5.0   W. Landsman   September 1997
1170       Correct negative output RA values when /RADIAN used    March 1999
1171       Work for arrays, not just vectors  W. Landsman    September 2003
1172       Adapted for SPIDAST P. Cruzalèbes March 2010
1173
1174----- Documentation for Util\premat.pro -----
1175 NAME:
1176       PREMAT
1177
1178 PURPOSE:
1179       Return the precession matrix needed to go from J2000. to EQUINOX.
1180
1181 CATEGORY:
1182       Utilities
1183
1184 EXPLANATION:
1185       This matrix is used by the procedures PRECESS to precess
1186       astronomical coordinates using FK5 (J2000.0) precession angles
1187
1188 CALLING SEQUENCE:
1189       matrix = PREMAT( equinox )
1190
1191 INPUTS:
1192       EQUINOX - Equinox of precessed coordinates.
1193
1194 OUTPUT:
1195      matrix - double precision 3 x 3 precession matrix, used to precess
1196               equatorial rectangular coordinates
1197
1198 OPTIONAL INPUT KEYWORDS:
1199       NONE
1200
1201 PROCEDURE:
1202       FK5 constants from "Astronomical Almanac Explanatory
1203       Supplement 1992, page 104 Table 3.211.1.
1204
1205 REVISION HISTORY
1206       Written, Wayne Landsman, HSTX Corporation, June 1994
1207       Converted to IDL V5.0   W. Landsman   September 1997
1208       Adapted for SPIDAST P. Cruzalèbes March 2010
1209
1210----- Documentation for Util\regutrap.pro -----
1211 NAME:
1212        REGUTRAP
1213
1214 AUTHOR:
1215       pierre.cruzalebes@oca.eu
1216
1217 PURPOSE:
1218       function average using composite trapezoidal 1D rule with uniform grid
1219       (if input function = 2D array => integration on second dim only)
1220
1221 CATEGORY:
1222       utilities
1223
1224 CALLING SEQUENCE:
1225        Y_TRAP = REGUTRAP(Y)
1226
1227 INPUTS:
1228        Y = Row vector or 2D array of function values (can be complex).
1229
1230 OUTPUTS:
1231        Function result = Y_TRAP = averaged value or vector (can be complex).
1232
1233 OPTIONAL OUTPUT PARAMETERS:
1234        NONE.
1235
1236 COMMON BLOCKS:
1237        NONE.
1238
1239 SIDE EFFECTS:
1240        NONE.
1241
1242 RESTRICTIONS:
1243        NONE.
1244
1245 PROCEDURE:
1246
1247 LOCAL PROCEDURE CALLED:
1248        NONE
1249
1250 LOCAL FUNCTION USED:
1251        NONE
1252
1253 LOCAL SYSTEM VARIABLE USED:
1254        NONE
1255
1256 REVISION HISTORY:
1257        Written by pcr 2007/01/07
1258       last modification by pcr 2011/01/15
1259
1260----- Documentation for Util\regutrap2.pro -----
1261 NAME:
1262        REGUTRAP
1263
1264 AUTHOR:
1265       pierre.cruzalebes@oca.eu
1266
1267 PURPOSE:
1268       function average using composite trapezoidal 2D rule with uniform grid
1269       (if input function = 3D array => integration on second and third dim only)
1270
1271 CATEGORY:
1272       utilities
1273
1274 CALLING SEQUENCE:
1275        Z_TRAP = REGUTRAP2(Z)
1276
1277 INPUTS:
1278        Z = 2D or 3D array of function values (can be complex).
1279
1280 OUTPUTS:
1281        Function result = Z_TRAP = averaged value or vector (can be complex).
1282
1283 OPTIONAL OUTPUT PARAMETERS:
1284        NONE.
1285
1286 COMMON BLOCKS:
1287        NONE.
1288
1289 SIDE EFFECTS:
1290        NONE.
1291
1292 RESTRICTIONS:
1293        NONE.
1294
1295 PROCEDURE:
1296
1297 LOCAL PROCEDURE CALLED:
1298        NONE
1299
1300 LOCAL FUNCTION USED:
1301        NONE
1302
1303 LOCAL SYSTEM VARIABLE USED:
1304        NONE
1305
1306 REVISION HISTORY:
1307        Written by pcr 2011/01/15
1308       last modification by pcr 2011/01/15
1309
1310----- Documentation for Util\reset_plot.pro -----
1311 NAME:
1312        RESET_PLOT
1313
1314 AUTHOR:
1315       pierre.cruzalebes@oca.eu
1316
1317 PURPOSE:
1318        RESET VARIABLES USED FOR PLOT
1319
1320 CATEGORY:
1321        UTILITY
1322
1323 CALLING SEQUENCE:
1324        RESET_PLOT
1325
1326 INPUTS:
1327        NONE
1328
1329 OUTPUTS:
1330        NONE
1331
1332 COMMON BLOCKS:
1333        NONE
1334
1335 SIDE EFFECTS:
1336        NONE
1337
1338 RESTRICTIONS:
1339        NONE
1340
1341 PROCEDURE:
1342        SEE CODE
1343
1344 LOCAL PROCEDURE CALLED:
1345        NONE
1346
1347 LOCAL FUNCTION USED:
1348        NONE
1349
1350 LOCAL SYSTEM VARIABLE USED:
1351        NONE
1352
1353 REVISION HISTORY:
1354       Written by pcr 2007/10/19
1355        last modification by pcr 2009/03/15
1356
1357----- Documentation for Util\sunpos.pro -----
1358 NAME:
1359       SUNPOS
1360
1361 PURPOSE:
1362       Compute RA and Dec of Sun at given date.
1363
1364 CATEGORY:
1365       Utilities
1366
1367 CALLING SEQUENCE:
1368       SUNPOS, jd, ra, dec, elong, obliquity
1369
1370 INPUTS:
1371       jd    - The Julian date of the day (and time), scalar or vector
1372               usually double precision
1373
1374 OUTPUTS:
1375       ra    - The right ascension of the sun at that date in DEGREES
1376               double precision, same number of elements as jd
1377       dec   - The declination of the sun at that date in DEGREES
1378       elong - Ecliptic longitude of the sun at that date in DEGREES.
1379       obliquity - the obliquity of the ecliptic, in DEGREES
1380
1381 OPTIONAL INPUT KEYWORD:
1382       NONE
1383
1384 NOTES:
1385       Patrick Wallace (Rutherford Appleton Laboratory, UK) has tested the
1386       accuracy of a C adaptation of the sunpos.pro code and found the
1387       following results.   From 1900-2100 SUNPOS  gave 7.3 arcsec maximum
1388       error, 2.6 arcsec RMS.  Over the shorter interval 1950-2050 the figures
1389       were 6.4 arcsec max, 2.2 arcsec RMS.
1390
1391       The returned RA and Dec are in the given date's equinox.
1392
1393       Procedure was extensively revised in May 1996, and the new calling
1394       sequence is incompatible with the old one.
1395
1396 METHOD:
1397       Uses a truncated version of Newcomb's Sun.    Adapted from the IDL
1398       routine SUN_POS by CD Pike, which was adapted from a FORTRAN routine
1399       by B. Emerson (RGO).
1400
1401 MODIFICATION HISTORY:
1402       Written by Michael R. Greason, STX, 28 October 1988.
1403       Accept vector arguments, W. Landsman     April,1989
1404       Eliminated negative right ascensions.  MRG, Hughes STX, 6 May 1992.
1405       Rewritten using the 1993 Almanac.  Keywords added.  MRG, HSTX,
1406               10 February 1994.
1407       Major rewrite, improved accuracy, always return values in degrees
1408       W. Landsman  May, 1996
1409       Added /RADIAN keyword,    W. Landsman       August, 1997
1410       Converted to IDL V5.0   W. Landsman   September 1997
1411       Adapted for SPIDAST P. Cruzalèbes March 2010 with calls to SIND & COSD
1412
1413----- Documentation for Util\sym.pro -----
1414 NAME:
1415        SYM
1416
1417 AUTHOR:
1418        Martin Schultz
1419
1420 PURPOSE:
1421        define a standard sequence of plotting symbols
1422
1423 CATEGORY:
1424        utilities
1425
1426 CALLING SEQUENCE:
1427        PLOT,X,Y,PSYM=SYM(NUMBER)
1428
1429 INPUTS:
1430        NUMBER    ->   symbol number
1431               0 : dot
1432               1 : filled circle
1433               2 : filled upward triangle
1434               3 : filled downward triangle
1435               4 : filled diamond
1436               5 : filled square
1437               6 : open circle
1438               7 : open upward triangle
1439               8 : open downward triangle
1440               9 : open diamond
1441              10 : open square
1442              11 : plus
1443              12 : X
1444              13 : star
1445              14 : filled rightfacing triangle
1446              15 : filled leftfacing triangle
1447              16 : open rightfacing triangle
1448              17 : open leftfacing triangle
1449
1450 KEYWORD PARAMETERS:
1451        none
1452
1453 OUTPUTS:
1454        function returns the symbol number to be used with PSYM= in the
1455        PLOT command
1456
1457 REQUIREMENTS:
1458        none
1459
1460 NOTES:
1461        This function produces a side effect in that the USERSYM procedure
1462        is used to create a symbol definition. It's meant for usage within
1463        the PLOT, OPLOT, etc. command
1464
1465 EXAMPLE:
1466        PLOT,X,Y,PSYM=SYM(0),SYMSIZE=3
1467                produces a plot with dots (standard symbol 3)
1468        FOR I=0,17 DO OPLOT,X+1,Y,PSYM=SYM(I),COLOR=I
1469                overplots 17 curves each with its own symbol
1470
1471 REVISION HISTORY:
1472        mgs, 22 Aug 1997: VERSION 1.00
1473        mgs, 10 Sep 1999: - added SHOWSYM procedure
1474
1475 Copyright (C) 1997, Martin Schultz, Harvard University
1476 This software is provided as is without any warranty
1477 whatsoever. It may be freely used, copied or distributed
1478 for non-commercial purposes. This copyright notice must be
1479 kept with any copy of this software. If this software shall
1480 be used commercially or sold as part of a larger package,
1481 please contact the author to arrange payment.
1482 Bugs and comments should be directed to mgs@io.harvard.edu
1483 with subject "IDL routine sym"
1484
1485----- Documentation for Util\trap.pro -----
1486 NAME:
1487        TRAP
1488
1489 AUTHOR:
1490       pierre.cruzalebes@oca.eu
1491
1492 PURPOSE:
1493       function average using composite trapezoidal 1D rule with non-uniform grid
1494       (if input function = 2D array => integration on second dim only)
1495
1496 CATEGORY:
1497       utilities.
1498
1499 CALLING SEQUENCE:
1500        Y_TRAP = TRAP(X,Y)
1501
1502 INPUTS:
1503        X = Row vector of independent variables.
1504        Y = Row vector (same dimension as X) or 2D array (second dim same as X)
1505       of function values (can be complex).
1506
1507 OUTPUTS:
1508        Function result = Y_TRAP = averaged value or vector (can be complex).
1509
1510 OPTIONAL OUTPUT PARAMETERS:
1511        NONE.
1512
1513 COMMON BLOCKS:
1514        NONE.
1515
1516 SIDE EFFECTS:
1517        NONE.
1518
1519 RESTRICTIONS:
1520        NONE.
1521
1522 PROCEDURE:
1523
1524 LOCAL PROCEDURE CALLED:
1525        NONE
1526
1527 LOCAL FUNCTION USED:
1528        NONE
1529
1530 LOCAL SYSTEM VARIABLE USED:
1531        EPSILON
1532
1533 REVISION HISTORY:
1534      Written by pcr 2007/01/07
1535      Last modification by pcr 2011/01/15
1536
1537----- Documentation for Util\trap2.pro -----
1538 NAME:
1539        TRAP2
1540
1541 AUTHOR:
1542       pierre.cruzalebes@oca.eu
1543
1544 PURPOSE:
1545       function average using composite trapezoidal 2D rule with non-uniform grid
1546       (if input function = 3D array => integration on second and third dim only)
1547
1548 CATEGORY:
1549       utilities.
1550
1551 CALLING SEQUENCE:
1552        Z_TRAP = TRAP2(X,Y,Z)
1553
1554 INPUTS:
1555        X = Row vector of (N_VALX) independent variables in x-direction.
1556        Y = Row vector of (N_VALY) independent variables in y-direction.
1557        Z = 2D (N_VALX,N_VALY) or 3D (second dim=N_VALX, third dim=N_VALY)
1558       array of function values (can be complex).
1559
1560 OUTPUTS:
1561        Function result = Z_TRAP = averaged value or vector (can be complex).
1562
1563 OPTIONAL OUTPUT PARAMETERS:
1564        NONE.
1565
1566 COMMON BLOCKS:
1567        NONE.
1568
1569 SIDE EFFECTS:
1570        NONE.
1571
1572 RESTRICTIONS:
1573        NONE.
1574
1575 PROCEDURE:
1576
1577 LOCAL PROCEDURE CALLED:
1578        NONE
1579
1580 LOCAL FUNCTION USED:
1581        NONE
1582
1583 LOCAL SYSTEM VARIABLE USED:
1584        EPSILON
1585
1586 REVISION HISTORY:
1587      Written by pcr 2011/01/15
1588      Last modification by pcr 2011/01/19
1589
1590----- Documentation for Util\trapez_fourier.pro -----
1591 NAME:
1592        TRAPEZ_FOURIER
1593
1594 AUTHOR:
1595       pierre.cruzalebes@oca.eu
1596
1597 PURPOSE:
1598        EVALUATE THE 2D TRAPEZOIDAL DISCRETE FOURIER TRANSFORM
1599       ON THE SECOND AND THIRD DIMENSIONS OF A 3D FUNCTION AND OPTIONALLY RETURN THE VALUES
1600       OF ITS PARTIAL DERIVATIVES VS FUNCTION PARAMETER(S) (INCLUDING ANGULAR DIAM).
1601
1602 CATEGORY:
1603        UTILITIES.
1604
1605 CALLING SEQUENCE:
1606        TRAPEZ_FOURIER,FREQ,PARAM,IDIM,RIP_X,RIP_Y,FUNCT,TF,PDER_FUNCT,PDER_TF
1607
1608 INPUTS:
1609        FREQ = VECTOR OF (NB_LAMBDA) COMPLEX SPATIAL FREQUENCIES
1610             (REAL PART => X-DIRECTION, IMAGINARY PART => Y-DIRECTION) .
1611        PARAM = ROW VECTOR OF (NB_PAR) MODEL PARAMETERS.
1612       IDIM = INDEX OF FUNCTION PARAMETER USED AS ANGULAR DIAMETER.
1613        RIP_X = VECTOR OF (NB_X) RELATIVE IMPACT PARAMETERS IN X-DIRECTION.
1614        RIP_Y = VECTOR OF (NB_Y) RELATIVE IMPACT PARAMETERS IN Y-DIRECTION.
1615        FUNCT = 3-DIM ARRAY OF (NB_LAMBDA*NB_X*NB_Y) VALUES OF FUNCTION TO TRANSFORM
1616       (2D TRANSFORMATION DONE ON SECOND AND THIRD DIM ONLY).
1617
1618 OUTPUTS:
1619        TF = COMPLEX VALUE OF THE TRAPEZOIDAL FOURIER TRANSFORM AT EACH WAVELENGTH.
1620
1621 OPTIONAL INPUT:
1622        PDER_FUNCT = 4D ARRAY OF (NB_LAMBDA*NB_X*NB_Y*NB_PAR) COMPLEX VALUES
1623                OF PARTIAL DERIVATIVES OF FUNCTION. PDER_FUNCT(I,J,JJ,K) = DERIVATIVE
1624                AT ITH WAVELENGTH AND 2D IMPACT PARAMETER(J,JJ)
1625               W/RESPECT TO KTH FUNCTION PARAMETER.
1626
1627 OPTIONAL OUTPUT PARAMETERS:
1628        PDER_TF = 2D ARRAY OF (NB_LAMBDA*NP_PAR) COMPLEX VALUES OF
1629                PARTIAL DERIVATIVES OF FOURIER TRANSFORM.  PDER_TF(I,K) = DERIVATIVE
1630                AT ITH WAVELENGTH W/RESPECT TO KTH FUNCTION PARAMETER.
1631
1632 COMMON BLOCKS:
1633        NONE.
1634
1635 SIDE EFFECTS:
1636        NONE.
1637
1638 RESTRICTIONS:
1639        NONE.
1640
1641 PROCEDURE:
1642        TF(LAMBDA) = TRAP2(RIP_X,RIP_Y,FUNCT(LAMBDA,RIP_X,RIP_Y)*EXP(-iZ))
1643                      *DRIP_X*DRIP_Y*DIAM^2/4/PI
1644        WHERE:  Z=(RIP_X*DOUBLE(FREQ(LAMBDA))+RIP_Y*IMAGINARY(FREQ(LAMBDA)))*DIAM*PI
1645               DIAM=PARAM(IDIM)
1646                DRIP_X=RIP_X(NB_RIP_X-1)-RIP_X(0)
1647                DRIP_Y=RIP_Y(NB_RIP_Y-1)-RIP_Y(0)
1648
1649     IF PARAM NE DIAM :
1650        PDER_TF(LAMBDA,PARAM) = TRAP2(RIP_X,RIP_Y,PDER_FUNCT(LAMBDA,RIP_X,RIP_Y,PARAM)*EXP(-iZ))
1651                                 *DRIP_X*DRIP_Y*DIAM^2/4/PI
1652     IF PARAM EQ DIAM :
1653        PDER_TF(LAMBDA,DIAM) =( TRAP2(RIP_X,RIP_Y,PDER_FUNCT(LAMBDA,RIP_X,RIP_Y,DIAM)*EXP(-iZ))
1654                           -i*TRAP2(RIP_X,RIP_Y,Z*FUNCT(LAMBDA,RIP_X,RIP_Y)*EXP(-iZ))/DIAM )
1655                               *DRIP_X*DRIP_Y*DIAM^2/4/PI
1656
1657 LOCAL PROCEDURE CALLED:
1658        NONE
1659 LOCAL FUNCTION USED:
1660        TRAP2
1661
1662 LOCAL SYSTEM VARIABLE USED:
1663       EPSILON
1664        MAS2RADIAN
1665
1666 REVISION HISTORY:
1667       Written by pcr 2011/01/14
1668        Last modification by pcr 2011/01/17
1669
1670----- Documentation for Util\trapez_hankel.pro -----
1671 NAME:
1672        TRAPEZ_HANKEL
1673
1674 AUTHOR:
1675       pierre.cruzalebes@oca.eu
1676
1677 PURPOSE:
1678        EVALUATE THE 1D TRAPEZOIDAL DISCRETE HANKEL (FOURIER-BESSEL) TRANSFORM
1679       ON THE SECOND DIMENSION OF A 2D FUNCTION AND OPTIONALLY RETURN THE VALUES
1680       OF ITS PARTIAL DERIVATIVES VS FUNCTION PARAMETER(S) (INCLUDING ANGULAR DIAM).
1681
1682 CATEGORY:
1683        UTILITIES.
1684
1685 CALLING SEQUENCE:
1686        TRAPEZ_HANKEL,FREQ,PARAM,IDIM,RIP,FUNCT,TH,PDER_FUNCT,PDER_TH
1687
1688 INPUTS:
1689        FREQ = SPATIAL FREQUENCY VECTOR (OF LENGTH NB_LAMBDA).
1690        PARAM = ROW VECTOR OF MODEL PARAMETERS (OF LENGTH NB_PAR).
1691       IDIM = INDEX OF FUNCTION PARAMETER USED AS ANGULAR DIAMETER.
1692        RIP = RELATIVE IMPACT PARAMETER VECTOR (OF LENGTH NB_RIP).
1693        FUNCT = ARRAY OF (NB_LAMBDA*NB_RIP) VALUES OF FUNCTION TO TRANSFORM
1694       (1D TRANSFORMATION DONE ON SECOND DIM ONLY).
1695
1696 OUTPUTS:
1697        TH = VALUE OF TRAPEZOIDAL HANKEL TRANSFORM AT EACH WAVELENGTH.
1698
1699 OPTIONAL INPUT:
1700        PDER_FUNCT = 3D ARRAY CONTAINING THE
1701                PARTIAL DERIVATIVES OF FUNCTION. PDER_FUNCT(I,J,K) = DERIVATIVE
1702                AT ITH WAVELENGTH AND JTH IMPACT PARAM W/RESPECT TO KTH FUNCT PARAM.
1703
1704 OPTIONAL OUTPUT PARAMETERS:
1705        PDER_TH = 2D ARRAY CONTAINING THE
1706                PARTIAL DERIVATIVES OF TRANSFORM.  PDER_H(I,K) = DERIVATIVE
1707                AT ITH WAVELENGTH W/RESPECT TO KTH FUNCT PARAM.
1708
1709 COMMON BLOCKS:
1710        NONE.
1711
1712 SIDE EFFECTS:
1713        NONE.
1714
1715 RESTRICTIONS:
1716        NONE.
1717
1718 PROCEDURE:
1719        TH(LAMBDA) = TRAP(RIP,RIP*J0(Z)*FUNCT(LAMBDA,RIP))*DRIP*DIAM^2/2
1720        WHERE:  Z=RIP*FREQ(LAMBDA)*DIAM*PI
1721               J0=BESSEL FUNCTION ORDER 0 FIRST KIND
1722               DIAM=PARAM(IDIM)
1723                DRIP=RIP(NB_RIP-1)-RIP(0)
1724    IF PARAM NE DIAM :
1725        PDER_TH(LAMBDA,PARAM) = TRAP(RIP,RIP*J0*PDER_FUNCT(LAMBDA,RIP,PARAM))*DIAM^2/2*DRIP
1726    IF PARAM EQ DIAM :
1727       PDER_TH(LAMBDA,DIAM) = (  TRAP(RIP,RIP*J0(Z)*PDER_FUNCT(LAMBDA,RIP,DIAM))
1728                      +TRAP(RIP,RIP*JJ(Z)*FUNCT(LAMBDA,RIP))*2/DIAM )*DRIP*DIAM^2/2
1729                WHERE: JJ(Z)=J0(Z)-Z*J1(Z)/2 , J1=BESSEL FUNCTION ORDER 1 FIRST KIND
1730
1731 LOCAL PROCEDURE CALLED:
1732        NONE
1733 LOCAL FUNCTION USED:
1734        TRAP
1735
1736 LOCAL SYSTEM VARIABLE USED:
1737       EPSILON
1738        MAS2RADIAN
1739
1740 REVISION HISTORY:
1741       Written by pcr 2007/09/03
1742        Last modification by pcr 2011/01/17
1743
1744----- Documentation for Util\trigo_deg_lib.pro -----
1745 NAME:
1746   TRIGO_DEG_LIB
1747
1748 CATEGORY:
1749   utilities
1750
1751 AUTHOR:
1752   pierre.cruzalebes@oca.eu
1753
1754 REVISION HISTORY:
1755   Written by pcr 2010/10/04
1756
1757----- Documentation for Util\value_locate.pro -----
1758 NAME:
1759   VALUE_LOCATE
1760
1761 AUTHOR:
1762   Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
1763   craigm@lheamail.gsfc.nasa.gov
1764
1765 PURPOSE:
1766   Locate one or more values in a reference array (IDL LE 5.2 compatibility)
1767
1768 CATEGORY:
1769   Utilities
1770
1771 CALLING SEQUENCE:
1772   INDICES = VALUE_LOCATE(REF, VALUES)
1773
1774 DESCRIPTION:
1775   VALUE_LOCATE locates the positions of given values within a
1776   reference array.  The reference array need not be regularly
1777   spaced.  This is useful for various searching, sorting and
1778   interpolation algorithms.
1779
1780   The reference array should be a monotonically increasing or
1781   decreasing list of values which partition the real numbers.  A
1782   reference array of NBINS numbers partitions the real number line
1783   into NBINS+1 regions, like so:
1784
1785
1786 REF:           X[0]         X[1]   X[2] X[3]     X[NBINS-1]
1787      <----------|-------------|------|---|----...---|--------------->
1788 INDICES:  -1           0          1    2       3        NBINS-1
1789
1790
1791   VALUE_LOCATE returns which partition each of the VALUES falls
1792   into, according to the figure above.  For example, a value between
1793   X[1] and X[2] would return a value of 1.  Values below X[0] return
1794   -1, and above X[NBINS-1] return NBINS-1.  Thus, besides the value
1795   of -1, the returned INDICES refer to the nearest reference value
1796   to the left of the requested value.
1797
1798   If the reference array is monotonically decreasing then the
1799   partitions are numbered starting at -1 from the right instead (and
1800   the returned INDICES refer to the nearest reference value to the
1801   *right* of the requested value).  If the reference array is
1802   neither monotonically increasing or decreasing the results of
1803   VALUE_LOCATE are undefined.
1804
1805   VALUE_LOCATE appears as a built-in function in IDL v5.3 and later.
1806   This version of VALUE_LOCATE should work under IDL v4 and later,
1807   and is intended to provide a portable solution for users who do
1808   not have the latest version of IDL.  The algrorithm in this file
1809   is slower but not terribly so, than the built-in version.
1810
1811   Users should be able to place this file in their IDL path safely:
1812   under IDL 5.3 and later, the built-in function will take
1813   precedence; under IDL 5.2 and earlier, this function will be used.
1814
1815 INPUTS:
1816   REF - the reference array of monotonically increasing or
1817         decreasing values.
1818   VALUES - a scalar value or array of values to be located in the
1819            reference array.
1820
1821 KEYWORDS:
1822   NONE
1823
1824 RETURNS:
1825   An array of indices between -1L and NBINS-1.  If VALUES is an
1826   array then the returned array will have the same dimensions.
1827
1828 SEE ALSO:
1829   VALUE_LOCATE (IDL 5.3 and later)
1830
1831 REVISION HISTORY:
1832   Written and documented, 21 Jan 2001
1833   Case of XBINS having only one element, CM, 29 Apr 2001
1834   Handle case of VALUES exactly hitting REF points, CM, 13 Oct 2001
1835 
1836  $Id: value_locate.pro,v 1.5 2001/10/13 17:59:34 craigm Exp $
1837
1838 Copyright (C) 2001, Craig Markwardt
1839 This software is provided as is without any warranty whatsoever.
1840 Permission to use, copy, modify, and distribute modified or
1841 unmodified copies is granted, provided this copyright and disclaimer
1842 are included unchanged.
1843       Adapted for SPIDAST, P. Cruzalèbes March 2010
1844
1845----- Documentation for Util\xyz.pro -----
1846 NAME:
1847       XYZ
1848
1849 PURPOSE:
1850       Calculate geocentric X,Y, and Z  and velocity coordinates of the Sun
1851
1852 CATEGORY:
1853       Utilities
1854
1855 EXPLANATION:
1856       Calculates geocentric X,Y, and Z vectors and velocity coordinates
1857       (dx, dy and dz) of the Sun.   (The positive X axis is directed towards
1858       the equinox, the y-axis, towards the point on the equator at right
1859       ascension 6h, and the z axis toward the north pole of the equator).
1860       Typical position accuracy is <1e-4 AU (15000 km).
1861
1862 CALLING SEQUENCE:
1863       XYZ, date, x, y, z
1864
1865 INPUT:
1866       date: reduced julian date (=JD - 2400000), scalar or vector
1867
1868 OUTPUT:
1869       x,y,z: scalars or vectors giving heliocentric rectangular coordinates
1870                 (in A.U) for each date supplied.    Note that sqrt(x^2 + y^2
1871                 + z^2) gives the Earth-Sun distance for the given date.
1872       equinox of output is 1950.
1873
1874 OPTIONAL KEYWORD INPUT:
1875       NONE
1876
1877 PROCEDURE CALLS:
1878       COSD, SIND
1879
1880 REVISION HISTORY
1881       Original algorithm from Almanac for Computers, Doggett et al. USNO 1978
1882       Adapted from the book Astronomical Photometry by A. Henden
1883       Written  W. Landsman   STX       June 1989
1884       Correct error in X coefficient   W. Landsman HSTX  January 1995
1885       Added velocities, more terms to positions and EQUINOX keyword,
1886          some minor adjustments to calculations
1887          P. Plait/ACC March 24, 1999
1888       Adapted for SPIDAST, P. Cruzalèbes March 2010
1889
1890----- Documentation for Util\ydn2md.pro -----
1891 NAME:
1892       YDN2MD
1893
1894 PURPOSE:
1895       Convert from year and day number of year to month and day of month.
1896
1897 CATEGORY:
1898       Utilities
1899
1900 CALLING SEQUENCE:
1901       YDN2MD,yr,dy,m,d
1902
1903 INPUTS:
1904       yr = 4 digit year (like 1988), integer scalar
1905       dy = day number in year (like 310), integer scalar or vector
1906
1907
1908 OUTPUTS:
1909       m = month number (1-12, e.g. 11 = Nov)
1910       d = day of month (like 5).         
1911       Note: On error returns m = d = -1.
1912
1913
1914 REVISION HISTORY:
1915       Adapted from Johns Hopkins University/Applied Physics Laboratory
1916       Update to use VALUE_LOCATE,   W. Landsman    January 2001
1917       Adapted for SPIDAST, P. Cruzalèbes March 2010
1918
1919----- Documentation for Util\zparcheck.pro -----
1920 NAME:
1921       ZPARCHECK
1922
1923 PURPOSE:
1924       Routine to check user parameters to a procedure
1925
1926 CATEGORY:
1927       Utilities
1928
1929 CALLING SEQUENCE:
1930       zparcheck, progname, parameter, parnum, types, dimens, [ message ]
1931
1932 INPUTS:
1933       progname  - scalar string name of calling procedure
1934       parameter - parameter passed to the routine
1935       parnum    - integer parameter number
1936       types     - integer scalar or vector of valid types
1937                1 - byte        2 - integer   3 - int*4
1938                4 - real*4      5 - real*8    6 - complex
1939                7 - string      8 - structure 9 - double complex
1940               10 - pointer    11 - object ref 12 - Unsigned integer
1941               13 - unsigned int*4
1942               14 - int*8 
1943               15 - Unsigned int*8
1944       dimens   - integer scalar or vector giving number
1945                     of allowed dimensions.
1946 OPTIONAL INPUT:
1947       message - string message describing the parameter to be printed if an
1948               error is found
1949
1950 OUTPUTS:
1951       none
1952
1953 SIDE EFFECTS:
1954       If an error in the parameter is a message is printed
1955       a RETALL issued
1956
1957 REVISION HISTORY
1958       version 1  D. Lindler  Dec. 86
1959       documentation updated.  M. Greason, May 1990.
1960       Recognize double complex datatype    W. Landsman   September 1995
1961       Converted to IDL V5.0   W. Landsman   September 1997
1962       Check for new data types (e.g. unsigned) W. Landsman February 2000
1963       Adapted for SPIDAST P. Cruzalèbes March 2010 with calls to SIND & COSD
1964