1; -----------------------------------------------------------------------------
2;
3;  Copyright (C) 1997-2013  Krzysztof M. Gorski, Eric Hivon, Anthony J. Banday
4;
5;
6;
7;
8;
9;  This file is part of HEALPix.
10;
11;  HEALPix is free software; you can redistribute it and/or modify
12;  it under the terms of the GNU General Public License as published by
13;  the Free Software Foundation; either version 2 of the License, or
14;  (at your option) any later version.
15;
16;  HEALPix is distributed in the hope that it will be useful,
17;  but WITHOUT ANY WARRANTY; without even the implied warranty of
18;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19;  GNU General Public License for more details.
20;
21;  You should have received a copy of the GNU General Public License
22;  along with HEALPix; if not, write to the Free Software
23;  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24;
25;  For more information about HEALPix see http://healpix.sourceforge.net
26;
27; -----------------------------------------------------------------------------
28pro mollview, file_in, select_in, $
29              ASINH = asinh, $
30              BAD_COLOR = bad_color, $
31              BG_COLOR = bg_color, $
32              CHARSIZE = charsize, $
33              CHARTHICK = charthick, $
34              COLT = colt, $
35              COORD = coord, $
36              CROP = crop, $
37              CUSTOMIZE = customize, $
38              DEFAULT_SETTINGS = default_settings, $
39              EXECUTE = execute, $
40              FACTOR = factor, $
41              FITS = fits, $
42              FG_COLOR=fg_color, $
43              FLIP = flip, $
44              GAL_CUT = gal_cut, $
45              GIF = gif, $
46              GLSIZE = glsize, $
47              GRATICULE = graticule, $
48              HELP = help, $
49              HBOUND = hbound, $
50              HIST_EQUAL = hist_equal, $
51              HXSIZE = hxsize, $
52              IGLSIZE = iglsize, $
53              IGRATICULE=igraticule, $
54              JPEG=jpeg, $
55              LATEX=latex, $
56              LOG = log, $
57              MAP_OUT = map_out, $
58              MAX = max_set, $
59              MIN = min_set, $
60              NESTED = nested_online, $
61              NOBAR = nobar, $
62              NOLABELS = nolabels, $
63              NO_DIPOLE = no_dipole, $
64              NO_MONOPOLE = no_monopole, $
65              OFFSET = offset, $
66              ONLINE = online, $
67              OUTLINE = outline, $
68              PDF = pdf, $
69              PFONTS = pfonts, $
70              PNG = png, $
71              POLARIZATION = polarization, $
72              PREVIEW = preview, $
73              PS = ps, $
74              PXSIZE = pxsize, $
75              QUADCUBE = quadcube, $
76              RETAIN = retain, $
77              ROT = rot, $
78              SAVE = save, $
79              SILENT = silent, $
80              SILHOUETTE = silhouette, $
81              SUBTITLE = subtitle, $
82              TITLEPLOT = titleplot, $
83              TRANSPARENT = transparent, $
84              TRUECOLORS = truecolors, $
85              UNITS = units, $
86              WINDOW = window, $
87              XPOS = xpos, $
88              YPOS = ypos
89
90;+
91; NAME:
92;	MOLLVIEW, GNOMVIEW, CARTVIEW, ORTHVIEW
93;
94; PURPOSE:
95; 	tools to view a Mollweide/gnomic/cartesian/orthographic projection of maps binned
96;	in Healpix or COBE Quad-Cube pixelisation
97;
98; CALLING SEQUENCE:
99; 	xxxxVIEW, File, [Select, ] $
100;                       [ASINH=, $
101;                       BAD_COLOR=, BG_COLOR=, $
102;                       CHARSIZE=, COLT=, COORD=, CROP=, $
103;                       CUSTOMIZE=, $
104;                       DEFAULT_SETTINGS=, $
105;                       EXECUTE=, $
106;                       FACTOR=, FG_COLOR=, FITS=, FLIP=, $
107;                       GAL_CUT=, GIF=, GLSIZE=, GRATICULE=, $
108;                       HALF_SKY =, HBOUND =, HELP =, HIST_EQUAL=, HXSIZE=, $
109;                       IGLSIZE=, IGRATICULE=, $
110;                       JPEG=, $
111;                       LATEX=, LOG=, $
112;                       MAP_OUT=, MAX=, MIN=, $
113;                       NESTED=, NOBAR=, NOLABELS=, NOPOSITION=, $
114;                       NO_DIPOLE=, NO_MONOPOLE=, $
115;                       OFFSET =, ONLINE=, OUTLINE=, $
116;                       PFONTS=, PNG=, POLARIZATION=, PREVIEW=,$
117;                       PS=, PXSIZE=, PYSIZE=, $
118;                       QUADCUBE= , $
119;                       RESO_ARCMIN= , ROT=, $
120;                       SAVE=, SHADED=, SILENT=, SILHOUETTE=, STAGGER=, SUBTITLE=, $
121;                       TITLEPLOT=, TRANSPARENT=, TRUECOLORS= $
122;                       UNITS=, WINDOW=, XPOS=, YPOS=]
123;
124;  all the arguments and parameters are identical for all the
125;  routines, excepted stated otherwise.
126;
127;
128; INPUTS:
129; 	File =
130;          by default,           name of a FITS file containing
131;               the healpix map in an extension or in the image field
132;          if Online is set :    name of a variable containing
133;               the healpix map
134;          if Save is set   :    name of an IDL saveset file containing
135;               the healpix map stored under the variable  data
136;
137; OPTIONAL INPUTS:
138;       Select =  if the file read is a multi column BIN table, Select indicates
139;                 which column is to be plotted (the default is to plot the
140;                 first column containing some signal, as opposed to pixel index)
141;               can be either a name : value given in TTYPEi of the FITS file
142;                        NOT case sensitive and
143;                        can be truncated,
144;                        (only letters, digits and underscore are valid)
145;               or an integer        : number i of the column
146;                            containing the data, starting with 1
147;               (see the Examples below)
148;
149; OPTIONAL INPUT KEYWORDS:
150;
151;       ASINH: if set, the color table is altered in to emulate the effect of replacing
152;            the data by sinh^{-1}(data) in order to enhance the low contrast regions.
153;            Can be used in conjonction with FACTOR and OFFSET, but can not be
154;            used with /LOG nor /HIST_EQUAL
155;
156;       BAD_COLOR: color given to missing pixels (having
157;            !healpix.bad_value=-1.6375e30 or NaN value on input).
158;          The color can be provided as either:
159;           - a single integer in [0,255], specifying the index to be used in
160;             the color table chosen via COLT (in which the indexes 0, 1 and 2
161;             are reserved for black, white and grey respectively),
162;           - a 3 element vector, with each element in [0,255], specifying the
163;             amount of RED, GREEN and BLUE
164;           - a 7-character string, starting with '#', specifying the color in
165;             HTML Hexadecimal fashion (eg, '#ff0000' for red).
166;          Default: neutral grey (=2, =[175, 175, 175], ='#afafaf')
167;          See also: BG_COLOR, FG_COLOR, TRANSPARENT
168;
169;       BG_COLOR: color given to pixels outside the sphere
170;          See BAD_COLOR for expected format
171;          Default: white (=1, =[255, 255, 255], ='#ffffff')
172;          See also: BAD_COLOR, FG_COLOR, TRANSPARENT
173;
174;       CHARSIZE : overall multiplicative factor applied to the size of all
175;               characters appearing on the plot
176;                default = 1.0
177;
178;       CHARTHICK : character thickness (in TITLE, SUBTITLE and color bar labeling).
179;               Other characters thickness (such as graticule labels), can be
180;               controlled with !P.CHARTHICK.
181;                default = 1
182;
183; 	COLT : color table index:
184;              -Indexes [0,40] are reserved for standard IDL color tables, while
185;               [41,255] are used for user defined color tables read from disc (created and
186;               written to disc with MODIFYCT), if any.
187;              -Indexes 1001 (or 'planck1', case insensitive) and 1002 (or 'planck2')
188;               are reserved for Planck color tables 1 and 2 (see Planck_colors routine)
189;              -If the index does not match any existing table, or if it is
190;              above 255, the current
191;               table (modifiable with TVLCT, XLOADCT, XPALETTE, ...
192;               or eg, J.Davenport's cubehelix.pro implementation of D. Green cubehelix
193;               color scheme) is used instead.
194;              -If not set, the color table will be 33 (Blue-Red).
195;              -If colt<0, the IDL color table ABS(colt) is used, but the scale is
196;              reversed (ie a red to blue scale becomes a blue to red scale).
197;              (note: -0.1 can be used as negative 0)
198;          See also: BAD_COLOR, BG_COLOR, FG_COLOR
199;
200;       COORD : vector with 1 or 2 elements describing the coordinate system of the map
201;                either 'C' or 'Q' : Celestial2000 = eQuatorial,
202;                       'E'        : Ecliptic,
203;                       'G'        : Galactic
204;               if coord = ['x','y'] the map is rotated from system 'x' to system 'y'
205;               if coord = ['y'] the map is rotated to coordinate system 'y' (with the
206;               original system assumed to be Galactic unless indicated otherwise in the file)
207;                  see also : Rot
208;
209;       CROP : if set, the image produced (gif, jpeg, pdf, png, ps, X) only
210;               contains the projected map and not the title, color bar, ...
211;               (see also : GIF, JPEG, PDF, PNG, PS)
212;
213;       CUSTOMIZE: (input) IDL structure containing customization parameters
214;          whose default values are listed in DEFAULT_SETTINGS
215;           accept   aspos.x, aspos.y:               astronomical coordinates,
216;                    cbar.dx, cbar.dy:               color bar X and Y sizes,
217;                    cbar.spaces, cbar.ty:           management of text around color bar
218;                    cbar.box:                       thickness of box around color bar
219;                    cring.dx, cring.xll, cring.yll: color ring size and location
220;                    pdf.debug:                      if set to 1, and SILENT not set, will help debugging PDF generation
221;                    subtitle.x, subtitle.y, subtible.charsize: subtitle X,Y location and charsize
222;                    title.x, title.y, title.charsize:        title X and Y location
223;                    vscale.x, vscale.y:                X,Y location for polarization vector legend
224;
225;         eg   customize={cbar:{dx:1./3., dy:1./70.}, title:{x:0.5, y:0.95}, subtitle:{x:0.5, y:0.905}}
226;
227;       DEFAULT_SETTINGS: (output) IDL structure listing the default values
228;          of the plot settings, like the color bar size, title and subtitle location
229;          can be inspected with HELP_ST
230;
231;       EXECUTE: character string containing an IDL command to be executed in
232;                the plotting window
233;
234;       FACTOR : multiplicative factor to be applied to the data (default = 1.0)
235;               the data plotted is of the form FACTOR*(data + OFFSET)
236;               see also : OFFSET, LOG
237;
238;       FG_COLOR: color of title and subtile characters,
239;          graticule lines and labels, units, outlines ...
240;          See BAD_COLOR for expected format
241;          Default: black (=0, =[0, 0, 0], ='#000000')
242;          See also: BAD_COLOR, BG_COLOR
243;
244;       FITS : string containing the name of an output fits file with
245;       the projected map in the primary image
246;	      if set to 0 or not set : no .FITS done
247;	      if set to 1            : output the plot in plot_XXX.fits
248;                with XXX = azimequid, cartesian, gnomic, mollweide or orthographic
249;	      if set to a file name  : output the plot in that file
250;	   * For compatibility with standard FITS viewers (including STIFF),
251;        unobserved pixels, and pixels outside the sphere, take the value {\tt
252;        NaN} (ie {\tt !values.f\_nan} in IDL).
253;          * The resulting FITS file can be read in IDL with eg. map=readfits(filename).
254;          * In the case of orthographic projection, HALF_SKY must be set.
255;
256;       FLIP : if set, the longitude increases to the right, whereas by
257;               default (astro convention) it increases towards the left
258;
259;       GAL_CUT: (positive float) specifies the symmetric galactic cut in degree
260;             outside of which the the monopole and/or dipole fitting is done
261;             (see also: NO_DIPOLE, NO_MONOPOLE)
262;             ** mollview and orthview only **
263;
264;	GIF : string containing the name of a .GIF output
265;	      if set to 0 or not set : no .GIF done
266;	      if set to 1            : output the plot in plot_XXX.gif
267;                with XXX = azimequid, cartesian, gnomic, mollweide or orthographic
268;	      if set to a file name  : output the plot in that file
269;             (see also : CROP, JPEG, PNG, PDF, PS and PREVIEW)
270;
271;       GLSIZE : character size of the graticule labels in units of CHARSIZE
272;             can be a scalar (which applies to both parallel and meridian labels),
273;             or a 2 element vector (interpreted as [meridian_label_size, parallel_label_size])
274;             default: 0 (ie, no labeling of graticules)
275;             (see also: CHARSIZE, GRATICULE)
276;
277; 	GRATICULE : if set, puts a graticule with delta_long = delta_lat = default
278;         if graticule is set to a scalar > gmin delta_long = delta_lat = graticule
279;         if set to [x,y] with x,y > gmin then delta_long = x and delta_let = y
280;         ** cartview : default =  5, gmin =  0 **
281;         ** gnomview : default =  5, gmin =  0 **
282;         ** mollview : default = 45, gmin = 10 **
283;         ** orthview : default = 45, gmin = 10 **
284;         The graticule lines thickness is controlled with !P.THICK
285;
286;       HALF_SKY: if set, only shows only one half of the sky
287;          (centered on (0,0) or on the location parametrized by Rot) instead of the full sky
288;             ** orthview only **
289;
290;       HBOUND: scalar or vector of up to 3 elements.
291;          For Hbound[i]>0, overplot the boundaries of Healpix pixels
292;           for the resolution parameter Nside=hbound[i].
293;           The first Nside will be plotted with solid lines,
294;           the second one (if any) with dashes,
295;           the third one (if any) with dots. Obviously, better results are
296;           obtained for Hbounds elements in growing order.
297;           Since 0-valued boundaries are not plotted, but used for linestyle
298;           assignment, providing Hbound=[0,4] (or [0,0,4]) will
299;           plot Nside=4 boundaries with dashes (resp. dots), while Hbound=4 would plot the same
300;           boundaries with solid lines.
301;
302;       HELP : if set, the routine header is printed (by doc_library)
303;             and nothing else is done
304;
305;	HIST_EQUAL : if not set, uses linear color mapping and
306;                     		puts the level 0 in the middle
307;                     		of the color scale (ie, green for Blue-Red)
308;				unless MIN and MAX are not symmetric
309;	       	      if set,     uses a histogram equalized color mapping
310;			(useful for non gaussian data field)
311;                     (see also : LOG)
312;
313; 	HXSIZE: horizontal dimension (in cm) of the Hardcopy plot : Only for postscript printout
314;    		** mollview : default = 26 cm ~ 10 in **
315;               ** mollview : default = 15 cm         **
316;    		(useful for large color printer)
317;               (see also : PXSIZE)
318;
319;       IGLSIZE : character size of the input coordinates graticule labels in units of CHARSIZE
320;             either scalar or 2-element vector (see GLSIZE)
321;             default: 0 (ie, no labeling of graticules)
322;             (see also: CHARSIZE, IGRATICULE)
323;
324;       IGRATICULE: if set, puts a graticule in the input coordinates
325;          if both graticule and igraticule are set, these ones will
326;          be represented by dashes
327;
328;	JPEG : string containing the name of a (lossless) .JPEG output
329;	      if set to 0 or not set : no .JPEG done
330;	      if set to 1            : output the plot in plot_XXX.jpeg
331;                with XXX = azimequid, cartesian, gnomic, mollweide or orthographic
332;	      if set to a file name  : output the plot in that file
333;             (see also : CROP, GIF, PDF, PNG, PS and PREVIEW)
334;
335;       LATEX: if set to 1 or 2, enables LaTeX handling of character strings
336;         such as TITLEPLOT, SUBTITLE and UNITS
337;        - if set to 2, together with PS or PDF outputs, these strings (and the graticule labels)
338;          will be processed by genuine LaTeX and inserted in the final PS or PDF file
339;         using psfrag package
340;          (requires LaTeX and its color, geometry, graphicx and psfrag packages)
341;           PFONTS settings will be ignored
342;        - if set to 1, whatever the output is, LaTeX is partially emulated with TeXtoIDL routines
343;          shipped with HEALPix (no extra requirements)
344;           Can be used with PFONTS
345;         default: 0 (not set)
346;
347; 	LOG: display the log of map (see also : HIST)
348;         only applies to pixel with signal > 0.
349;         (see OFFSET to offset signal)
350;
351;       MAP_OUT : name of the IDL variable that will contain
352;         an un-altered projected map.
353;         Unobserved pixels, and pixels outside the sphere take
354;       value !healpix.bad_value=-1.6375e30
355;
356; 	MAX : max value plotted,
357;		every data point larger than MAX takes the same color as MAX
358;
359; 	MIN : min value plotted,
360;		every data point smaller than MIN takes the same color as MIN
361;
362;	NESTED: specify that the online file is ordered in the nested scheme
363;
364; 	NOBAR : if set, the color bar (or the color wheel used for POLARIZATION=2)
365;                     is hidden
366;
367;	NOLABELS : if set, no color bar label (min and max) is present
368;
369;	NOPOSITION : if set, the astronomical location of the map
370;	        central point is not indicated
371;               ** gnomview only **
372;
373;       NO_DIPOLE: if set to 1 (and GAL_CUT is not set)
374;                the best fit monopole *and* dipole over all valid pixels are removed
375;                * if GAL_CUT is set to b>0, the best monopole and dipole fit is done on all valid
376;                pixels with |galactic latitude|>b (in deg) and is removed from all
377;                pixels
378;             can not be used together with NO_MONOPOLE
379;             (see: GAL_CUT, NO_MONOPOLE)
380;               ** mollview and orthview only **
381;
382;       NO_MONOPOLE: if set to 1 (and GAL_CUT is not set)
383;                the best fit monopole over all valid pixels is removed
384;                * if GAL_CUT is set to b>0, the best monopole fit is done on all valid
385;                pixels with |galactic latitude|>b (in deg) and is removed from all
386;                pixels
387;             can not be used together with NO_DIPOLE
388;             (see: GAL_CUT, NO_DIPOLE)
389;               ** mollview and orthview only **
390;
391;       OFFSET: additive offset to apply to data (default = 0)
392;               the data plotted is of the form FACTOR*(data + OFFSET)
393;               can be used together with LOG
394;               see also : FACTOR, LOG
395;               Note : does NOT apply to polarization direction or amplitude
396;               when POLARIZATION=3. Will apply to polarization amplitude when POLARIZATION=1.
397;
398; 	ONLINE: if set, you can put directly A HEALPIX VECTOR on File (and
399;    		without header): useful when the vector is already
400;    		available on line, and avoid to have to write it on disk
401;    		just to be read by mollview
402;		N.B. : the content of file_in is NOT altered in the
403;		process
404;               **  can not be used with /SAVE  **    *** OBSOLETE ***
405;
406;       OUTLINE : single structure, or set of structures,
407;                 each containing the coordinates of one outline to be overplotted.
408;           Each structure should contain the following fields :
409;           - 'COORD' coordinate system (either, 'C', 'G', or 'E') of the contour
410;           - 'RA'  or longitude coordinates (array)
411;           - 'DEC' or lattitude coordinates (array of same size)
412;           and can optionally contain the fields
413;           - 'LINE[STYLE]' : +2 : black dashes
414;                           +1 : black dots
415;                            0 : black solid [default]
416;                           -1 : black dots on white background
417;                           -2 : black dashes on white background
418;           - 'PSY[M]' symbol used to represent vertices of outline
419;                    (same meaning as standard PSYM in IDL,
420;                     if 9<=abs(psym)<=46, D. Fanning's CGSYMCAT symbols
421;                     definition will be used, for example psym=9 is an open circle)
422;                    if <=0, the vertices are represented with the chosen symbols, and
423;                        connected, by arcs of geodesics.
424;                    if >0, only the vertices are shown
425;                    (default = 0)
426;           - 'SYM[SIZE]' symbol size (same meaning as SYMSIZE in IDL), (default = 1)
427;          The line and symbol thickness are controlled (indirectly) via !P.THICK.
428;          Outline can be either a single structure, or an array of structures,
429;          or a structure of structures
430;
431;	PDF : string containing the name of a PDF output
432;             if set to 0 or not set : output to screen
433;	      if set to 1            : output the plot in plot_XXX.pdf
434;                with XXX = azimequid, cartesian, gnomic, mollweide or orthographic
435;	      if set to a file name  : output the plot in that file
436;               (see: CROP, GIF, JPEG, PNG, PREVIEW and PS)
437;
438;      PFONTS:  2-element vector of integers [p0, p1] selecting the default IDL font
439;              of character strings such as theSubtitle, Title and Units.
440;          p_0 must be in {-1,0,1} and selects the origin of the fonts among
441;              -1:  Hershey Vector,
442;               0:  Device Specific,
443;               1:  True Type Fonts.
444;          p_1 must be in {2,...,20} and selects the starting font of the character strings.
445;              The font can be changed within each string with embedded formatting commands,
446;              as discussed on http://www.exelisvis.com/docs/Fonts_and_Colors.html.
447;          default=[-1,6], corresponding to the Hershey vector font of type 'Complex Roman',
448;            and is equivalent to typing
449;             !p.font=-1
450;            and prepending the Subtitle, Title and Units strings with '!6'.
451;          Note that PFONTS will be ignored if Latex=2 *and* PDF or PS are set.
452;
453;
454;	PNG : string containing the name of a .PNG output
455;	      if set to 0 or not set : no .PNG done
456;	      if set to 1            : output the plot in plot_XXX.png
457;                with XXX = azimequid, cartesian, gnomic, mollweide or orthographic
458;	      if set to a file name  : output the plot in that file
459;             (see also : CROP, GIF, JPEG, PDF, PNG, PS and PREVIEW)
460;
461;       POLARIZATION:
462;         if set to 0, no polarization information is plotted.
463;
464;         otherwise, and if the input data contains polarisation information
465;             (ie, Stokes parameter Q and U for each pixel)
466;
467;         if set to 1
468;             the AMPLITUDE P = sqrt( U^2 + Q^2 ) of the polarisation is plotted
469;
470;         if set to 2
471;             the ANGLE phi = 0.5*ATAN(U/Q) of the polarisation is plotted
472;             Note: the angles are color coded with a fixed color table (independant of Colt)
473;
474;         if set to 3 or [3, scale_factor, step_factor, thickness]
475;             -the temperature is color coded (with a color table defined by Colt)
476;             -and the polarisation is overplot as small rods.
477;             Polarization can be a 4-element vector (the first element being 3).
478;             The second element controls the average length of the rods (default=1),
479;             the third one controls their spacing (default=1),
480;             while the fourth one controls their thickness
481;             (which also depends in a device dependent manner on !P.THICK, default=1).
482;             Non positive values are replaced by 1.
483;
484;	PREVIEW : if set, there is a preview of the GIF, JPG, PDF, PostScript,
485;	         PNG file being produced
486;                    (see: CROP, GIF, JPEG, PDF, PNG and PS)
487;
488;	PS :  string containing the name of a PS output
489;             if set to 0 or not set : output to screen
490;	      if set to 1            : output the plot in plot_XXX.ps
491;                with XXX = azimequid, cartesian, gnomic, mollweide or orthographic
492;	      if set to a file name  : output the plot in that file
493;               (see: CROP, GIF, JPEG, PNG and PREVIEW)
494;
495; 	PXSIZE: number of horizontal screen_pixels / postscript_color_dots of the plot
496;    		** mollview : default = 800, gnomview and cartview : default = 500 **
497;    		(useful for high definition color printer)
498;
499; 	PYSIZE: number of vertical screen_pixels or postscript_color_dots of the plot
500;    		default = PXSIZE
501;    		(useful for high definition color printer)
502;                ** gnomview only **
503;
504;       RETAIN: backing store for graphics windows in {0,1,2}. Default=2
505;
506;       RESO_ARCMIN: resolution of the gnomic map in arcmin
507;       (default=1.5)
508;                ** gnomview only **
509;
510; 	ROT :   vector with 1, 2 or 3 elements specifing the rotation angles in DEGREE
511;               to apply to the map in the 'output' coordinate system (see coord)
512;             = ( lon0, [lat0, rat0])
513;               lon0 : longitude of the point to be put at the center of the plot
514;		       the longitude increases Eastward, ie to the left of the plot
515;                      (unless flip is set)
516; 		      =0 by default
517;               lat0 : latitude of the point to be put at the center of the plot
518; 		      =0 by default
519;               rot0 : anti clockwise rotation to apply to the sky around the
520;                     center (lon0, lat0) before projecting
521;                     =0 by default
522;
523; 	SAVE: if set, tells that the file is in IDL saveset format,
524;    		the variable saved should be DATA
525;                 ** can not be used with /ONLINE **
526;
527;       SHADED: if set, the orthographic sphere is shaded, using a Phong model, to emulate 3D viewing.
528;              The sphere is illuminated by isotropic ambiant light plus a single light source.
529;                 ** Can NOT be used with GIF. **
530;                   ** orthview only **
531;
532;       SILENT: if set, the code runs silently
533;
534;       SILHOUETTE: if set to a scalar or 2-element vector with silhouette[0] !=  0,
535;          a silhouette is drawn around the map.
536;          Its thickness is proportional to abs(silhouette[0])
537;           (and also depends in a device-dependent manner on !P.THICK)
538;          Its color is determined by abs(silhouette[1]) in [0,255] (defaulting to 0 = FG_COLOR)
539;             ** mollview and orthview only **
540;
541;       STAGGER: scalar or 2 element vector.
542;            - if stagger[0] is in ]0,2],
543;             3 copies of the same sphere centered at [-stagger[0], 0, stagger[0]]
544;             (expressed in radius units) along the plot horizontal axis are
545;             shown in ORTHOGRAPHIC projection
546;             - stagger[1] (if defined), defines the angle of rotation (in degrees) applied
547;               to the left and right partial spheres:
548;             the lhs sphere is rotated downward by the angle provided, while the rhs one
549;             is rotated upward. Rotations are swapped if FLIP is set.
550;               ** orthview only **
551;
552; 	SUBTITLE : String containing the subtitle to the plot (see TITLEPLOT)
553;
554; 	TITLEPLOT : String containing the title of the plot,
555;     		if not set the title will be File (see SUBTITLE)
556;
557;       TRANSPARENT: some pixels are transparent in the produced PNG file
558;            if set to 1: bad pixels (usually grey or BAD_COLOR) are transparent
559;            if set to 2: background pixels (usually white or BG_COLOR) are transparent
560;            if set to 3: all of the above
561;            only valid with PNG
562;
563;       TRUECOLORS: if the input data is of the form [Npix,3] then the 3 fields
564;            are respectively understood as {Red, Green, Blue} True Colors
565;
566;
567;	UNITS : character string containing the units, to be put on the right
568;		side of the color bar (see : NOBAR)
569;
570;       WINDOW: IDL window index (integer)
571;                 if WINDOW < 0: virtual window: no visible window opened. Can be
572;               used with PNG or GIF. The Z buffer will be used instead of the
573;               X server, allowing much faster production of the image over a slow network
574;                 if WINDOW in [0,31]: the specified IDL window with index WINDOW is used
575;               (or reused)
576;                 if WINDOW > 31: a free (=unused) window with a random index > 31 will be
577;               created and used : default
578
579;	XPOS : The X position on the screen of the lower left corner
580;	        of the window, in device coordinate
581;
582;	YPOS : The Y position on the screen of the lower left corner
583;               of the window, in device coordinate
584;
585; NOTES
586; 	this routine doesn't use the IDL map_set because it is precisely bugged for
587; 	the mollweide projection (at least in IDL 4.0)
588;
589; SIDE EFFECTS
590; 	this routine uses ghostview when PS and PREVIEW are selected
591;	or xv when GIF or PNG and PREVIEW are selected
592;
593; EXAMPLES
594;       ;to plot the signal of the COBE-DMR 4 year map at 53 GHz
595;       read_fits_sb, 'dmr_skymap_53a_4yr.fits', dmr53a, /merge  ; read it only one time
596;       mollview, dmr53a, /online, 'Sig', /quad
597;
598;       ;to plot it in Galactic coordinate instead of Ecliptic
599;       mollview, drm53a, /online, 'Sig', /quad, coord='g'
600;
601; COMMONS USED : view_data
602;
603; PROCEDURES USED:
604;       in the Healpix package :
605;	  index_word, read_fits_sb, vec2pix_ring, vec2pix_nest, euler_matrix
606;         see  http://www.tac.dk/~healpix
607;       it also requires the IDL astro library
608;         http://idlastro.gsfc.nasa.gov/homepage.html
609;       and the COBE analysis software
610;         http://www.gsfc.nasa.gov/astro/cobe/cgis.html
611;
612; MODIFICATION HISTORY:
613; 	October 1997, Eric Hivon, TAC
614; 	Nov, 5, 1997,  correction of some bugs for postscript output
615; 	13-Nov-97, H. Dole, IAS: save and log keywords
616;  	4-Dec-97, H. Dole, IAS: online keyword
617; 	16-Dec-97, E.H, TAC: added pxsize, hxsize, subtitle, nobar
618;	17-Dec-97, split the loop for projection, added nolabels
619;	March-98, E.H. added UNITS keyword
620;	April-May-98 E.H. added NESTED_ONLINE, XPOS, YPOS, NOPREVIEW
621;       March-99     E.H. Caltech, improved the GIF output
622;              modified to deal with structures
623;              added Select, COORD, ROT, QUADCUBE  suppressed LON0
624;       April-99     E.H. Caltech, improved graticule
625;       Nov-99         added flip
626;       Feb-00   added rmmonopole and dipole, changed common
627;       March-00   changed to no_monopole and no_dipole, changed common
628;       Sept-00    added polarisation plotting (Polarization)
629;       June-02  : EH, Caltech. Hacked G. Giardino's polview into cartview
630;       June-02    partial consolidation of gnomview/mollview/cartview
631;       Jan-07    added WINDOW keyword
632;       Jun-07:  edited doc header about default data to plot from cut sky file
633;       Sep-07:  added /SILENT
634;       Mar-08:  added GLSIZE and IGLSIZE
635;       Apr-08:  can deal with cut sky data set without creating full sky map
636;       Nov-08:  restore original color table and plot settings when exiting
637;       May-09:  added /SHADED to orthview, implemented EXECUTE in orthview, fix
638;              Min-Max for LOG, use Z buffer when window<0, added RETAIN keyword
639;       Oct-09:  added /TRUECOLORS to all routines and MAP_OUT= to Gnomview
640;       Apr-10:  accept array of structures in Outline; added MAP_OUT= to
641;          Cartview and Mollview
642;       Jan-12: added STAGGER to orthview; created azeqview; added JPEG to all
643;       Sep-13: added BAD_COLOR, BG_COLOR, FG_COLOR
644;       2015:   added PDF, LATEX and PFONTS
645;       2017-05: addition of CUSTOMIZE, DEFAULT_SETTINGS,
646;                improvement of GLSIZE and IGLSIZE
647;-
648
649defsysv, '!healpix', exists = exists
650if (exists ne 1) then init_healpix
651
652@viewcom ; define common
653data_plot = 0 ; empty common array
654; record original color table and PLOTS settings
655record_original_settings, original_settings
656
657loadsky                         ; cgis package routine, define rotation matrices
658projection = 'MOLLWEIDE'
659routine = 'mollview'
660
661uroutine = strupcase(routine)
662if keyword_set(help) then begin
663    doc_library,'mollview'
664    return
665endif
666
667if keyword_set(gif) then begin
668    message_gif, code=routine, error=error_gif
669    if (error_gif) then return
670endif
671
672if (n_params() lt 1 or n_params() gt 2) then begin
673    PRINT, 'Wrong number of arguments in '+uroutine
674    print,'Syntax : '
675    print, uroutine+', File, [Select, ]'
676    print,'              [ASINH=, '
677    print,'              BAD_COLOR=, BG_COLOR=, '
678    print,'              CHARSIZE=, CHARTHICK=, COLT=, COORD=, CROP=, '
679    print,'              EXECUTE=, '
680    print,'              FACTOR=, FG_COLOR=, FITS=, FLIP=, '
681    print,'              GAL_CUT=, GIF=, GLSIZE=, GRATICULE=, '
682    print,'              HBOUND=, HELP=, HIST_EQUAL=, HXSIZE=,'
683    print,'              IGLSIZE=, IGRATICULE=,'
684    print,'              JPEG=,'
685    print,'              LOG=, '
686    print,'              MAP_OUT=, MAX=, MIN=, '
687    print,'              NESTED=, NOBAR=, NOLABELS=, '
688    print,'              NO_DIPOLE=, NO_MONOPLE=, '
689    print,'              OFFSET=, ONLINE=, OUTLINE=,'
690    print,'              PDF=, PFONTS=, PNG=, POLARIZATION=, PREVIEW=, '
691    print,'              PS=, PXSIZE=, PYSIZE=, QUADCUBE= ,'
692    print,'              RETAIN=, ROT=,  '
693    print,'              SAVE=, SILENT=, SUBTITLE=, '
694    print,'              TITLEPLOT=, TRANSPARENT=, TRUECOLORS=, '
695    print,'              UNITS=, WINDOW=, XPOS=, YPOS=]'
696    print
697    print,' Type '+uroutine+', /help '
698    print,'   for an extended help'
699    return
700endif
701
702IF (undefined(file_in)) then begin
703    print,routine+': Undefined variable as 1st argument'
704    return
705endif
706do_flip = keyword_set(flip)
707
708if (!D.n_colors lt 4) then begin
709    print,' : Sorry ... not enough colors ('+strtrim(string(!d.n_colors),2)+') available'
710    return
711endif
712
713if (keyword_set(no_monopole) and keyword_set(no_dipole)) then begin
714    print,routine+': choose either NO_MONOPOLE or NO_DIPOLE'
715    print,'    (removal of best fit monopole only or best fit monopole+dipole)'
716    return
717endif
718
719polar_type = 0
720if keyword_set(polarization) then polar_type = polarization
721
722loaddata_healpix, $
723  file_in, select_in,$
724  data, pol_data, pix_type, pix_param, do_conv, do_rot, coord_in, coord_out, eul_mat, title_display, sunits, $
725  SAVE=save, ONLINE=online, NESTED=nested_online, UNITS=units, COORD=coord, FLIP=flip, $
726  ROT=rot, QUADCUBE=quadcube, LOG=log, ERROR=error, $
727  POLARIZATION=polarization, FACTOR=factor, OFFSET=offset, SILENT=silent, COMPRESS=1, PIXEL_LIST=pixel_list, $
728  TRUECOLORS=truecolors, DATA_TC=data_tc
729if error NE 0 then return
730
731data2moll, $
732  data, pol_data, pix_type, pix_param, do_conv, do_rot, coord_in, coord_out, eul_mat, $
733  planmap, Tmax, Tmin, color_bar, planvec, vector_scale, $
734  PXSIZE=pxsize, LOG=log, HIST_EQUAL=hist_equal, MAX=max_set, MIN=min_set, FLIP=flip,  $
735  NO_DIPOLE=no_dipole, NO_MONOPOLE=no_monopole, UNITS=sunits, DATA_plot = data_plot, GAL_CUT=gal_cut, $
736  POLARIZATION=polarization, SILENT=silent, PIXEL_LIST=pixel_list, ASINH=asinh, $
737  TRUECOLORS=truecolors, DATA_TC=data_tc, MAP_OUT = arg_present(map_out) ? map_out : -1, ROT=rot, FITS=fits
738
739proj2out, $
740  planmap, Tmax, Tmin, color_bar, 0., title_display, $
741  sunits, coord_out, do_rot, eul_mat, planvec, vector_scale, $
742  CHARSIZE=charsize, COLT=colt, CROP=crop, GIF = gif, GRATICULE = graticule, $
743  HXSIZE=hxsize, NOBAR = nobar, NOLABELS = nolabels, PNG = png, PREVIEW = preview, PS=ps, PXSIZE=pxsize, $
744  SUBTITLE = subtitle, TITLEPLOT = titleplot, XPOS = xpos, YPOS = ypos, $
745  POLARIZATION=polarization, OUTLINE=outline, /MOLL, FLIP=flip, COORD_IN=coord_in, IGRATICULE=igraticule, $
746  HBOUND = hbound, WINDOW = window, EXECUTE=execute, SILENT=silent, GLSIZE=glsize, $
747  IGLSIZE=iglsize, RETAIN=retain, TRUECOLORS=truecolors, TRANSPARENT=transparent, CHARTHICK=charthick, $
748  JPEG=jpeg, BAD_COLOR=bad_color, BG_COLOR=bg_color, FG_COLOR=fg_color, PDF=pdf, $
749  LATEX=latex, PFONTS=pfonts, CUSTOMIZE=CUSTOMIZE, DEFAULT_SETTINGS=default_settings, SILHOUETTE = silhouette
750
751
752w_num = !d.window
753; restore original color table and PLOTS settings
754record_original_settings, original_settings, /restore
755
756
757return
758end
759
760