public void writeSVGFile(System.IO.DirectoryInfo path)
        {
            double min_wl = this.min_wavelength;
            double max_wl = this.max_wavelength;
            int resolution = this.resolution;
            int canvaswidth = this.figure_size_width;
            int canvasheight = this.figure_size_height;

            /* base square positioning on the direction. Since spots have to be placed in a line,
             * it makes sense to start the axis along which it lies at zero towards the length or height
             * of the axis. The spots will be placed along other axis, which is therefore centered about
             * that axis (-0.5*width/length; 0.5*width/length). */
            Scientrace.Location squareloc = ( this.isHorizontal() ?
                                        (Scientrace.Vector.y1vector()*canvasheight*-0.5).toLocation() :
                                        (Scientrace.Vector.x1vector()*canvaswidth*-0.5).toLocation() );

            Scientrace.Rectangle legendSquare = new Scientrace.Rectangle(null, null,
                squareloc,
                (Scientrace.Vector.x1vector()*canvaswidth).tryToNonzeroVector(),
                (Scientrace.Vector.y1vector()*canvasheight).tryToNonzeroVector());

            Scientrace.HorizontalGridSurfaceMarker hormarker = new Scientrace.HorizontalGridSurfaceMarker(legendSquare);
            hormarker.minval = min_wl*1E9;
            hormarker.maxval = max_wl*1E9;
            hormarker.xunits = "nm";
            double textheight = hormarker.textheight();
            double imagewidth = legendSquare.viewBoxWidth()+((fontSizeBasedMarginLeft+fontSizeBasedMarginRight)*textheight);
            double imageheight = legendSquare.viewBoxHeight()+((fontSizeBasedMarginTop+fontSizeBasedMarginBottom)*textheight);

            //Scientrace.Parallelogram surface = legendSquare.getDistributionSurface();
            //double spotsize = Math.Sqrt(Math.Pow(surface.u.length,2)+Math.Pow(surface.v.length,2))*(0.005);

            double[] vb = legendSquare.getViewBorders();
            //		Console.WriteLine("canvaswidth: "+canvaswidth+ " vb[2]: "+vb[3]);

            string strokewidth = (((vb[2]-vb[0])+(vb[3]-vb[1]))/800.0).ToString("#.##############"); //0.25% linewidth
            string fullfilename = path.FullName+System.IO.Path.DirectorySeparatorChar+"wl_legend.svg";
            //Console.WriteLine("Writing legend to "+fullfilename);
            using (StreamWriter retstr = new StreamWriter(fullfilename)) {
            retstr.WriteLine(this.getSVGHeader());
            retstr.WriteLine(this.getSVGTagOpen(imagewidth, imageheight,
                              legendSquare.getAbsMarginViewBox(fontSizeBasedMarginLeft,fontSizeBasedMarginTop,
                                                                  fontSizeBasedMarginRight, fontSizeBasedMarginBottom,textheight)
                              ));

            retstr.WriteLine(@"<desc>Drawing borders</desc>
            <rect x='"+vb[0]+"' y='"+vb[1]+"' width='"+vb[2]+"' height='"+vb[3]+@"'
            fill='none' stroke='black' stroke-width='"+strokewidth+"' />");

            retstr.WriteLine(hormarker.exportSVG());

            Scientrace.Location loc2d, tloc2d;
            int order = 5;
            string centerSpots = "<!-- END OF SPOTS CENTERS -->";
            double unitfraction = (Math.Pow(2,order)-1);
            double unitheight  = Convert.ToDouble(canvasheight)/unitfraction;

            //added "+(stepsize*0.001)" to condition to avoid float-boundary-problems
            for (double wavelength = min_wl; wavelength<=max_wl+(((max_wl-min_wl)/resolution)*0.001); wavelength=wavelength+((max_wl-min_wl)/resolution)) {
                Scientrace.Location loc =  this.relLocationVector(wavelength);
                Scientrace.Spot aSpot = new Scientrace.Spot(loc, legendSquare, 1, 1, null);
                loc2d = legendSquare.get2DLoc(aSpot.loc);

                if (loc2d==null) {throw new Exception("ERROR: loc2d created by "+legendSquare.tag+" == null");}

                double centerspotsize = (Convert.ToDouble(canvaswidth)/Convert.ToDouble(resolution))*0.5;
                loc2d.y = -centerspotsize+canvasheight;
                            //unitheight * (unitfraction-0.5);
            /*								(Math.Pow(2.0,order-1) * 0.5) +
                                (Math.Pow(2.0,order-1) - 1)
                                );*/

                centerSpots = this.spotSVGForWavelength(loc2d, centerspotsize, wavelength, 1)+centerSpots;

                for (int iorder = 1; iorder <= order; iorder++) {
                    tloc2d = loc2d;
                    tloc2d.y = unitheight * (
                                (Math.Pow(2.0,iorder-1) * 0.5) +
                                (Math.Pow(2.0,iorder-1) - 1)
                                );
                    retstr.WriteLine(this.spotSVGForWavelength(tloc2d, unitheight*(Math.Pow(2,(iorder-2))), wavelength, 0.25));
                    }
                }
            centerSpots = "<!-- START OF CENTERSPOTS-->"+centerSpots;
            retstr.WriteLine(centerSpots);
            retstr.WriteLine("</svg> ");

                //retstr.Close();
                }
        }
        public void writeSVGFile(System.IO.DirectoryInfo path)
        {
            double min_wl       = this.min_wavelength;
            double max_wl       = this.max_wavelength;
            int    resolution   = this.resolution;
            int    canvaswidth  = this.figure_size_width;
            int    canvasheight = this.figure_size_height;

            /* base square positioning on the direction. Since spots have to be placed in a line,
             * it makes sense to start the axis along which it lies at zero towards the length or height
             * of the axis. The spots will be placed along other axis, which is therefore centered about
             * that axis (-0.5*width/length; 0.5*width/length). */
            Scientrace.Location squareloc = (this.isHorizontal() ?
                                             (Scientrace.Vector.y1vector() * canvasheight * -0.5).toLocation() :
                                             (Scientrace.Vector.x1vector() * canvaswidth * -0.5).toLocation());

            Scientrace.Rectangle legendSquare = new Scientrace.Rectangle(null, null,
                                                                         squareloc,
                                                                         (Scientrace.Vector.x1vector() * canvaswidth).tryToNonzeroVector(),
                                                                         (Scientrace.Vector.y1vector() * canvasheight).tryToNonzeroVector());

            Scientrace.HorizontalGridSurfaceMarker hormarker = new Scientrace.HorizontalGridSurfaceMarker(legendSquare);
            hormarker.minval = min_wl * 1E9;
            hormarker.maxval = max_wl * 1E9;
            hormarker.xunits = "nm";
            double textheight  = hormarker.textheight();
            double imagewidth  = legendSquare.viewBoxWidth() + ((fontSizeBasedMarginLeft + fontSizeBasedMarginRight) * textheight);
            double imageheight = legendSquare.viewBoxHeight() + ((fontSizeBasedMarginTop + fontSizeBasedMarginBottom) * textheight);

            //Scientrace.Parallelogram surface = legendSquare.getDistributionSurface();
            //double spotsize = Math.Sqrt(Math.Pow(surface.u.length,2)+Math.Pow(surface.v.length,2))*(0.005);

            double[] vb = legendSquare.getViewBorders();
            //		Console.WriteLine("canvaswidth: "+canvaswidth+ " vb[2]: "+vb[3]);

            string strokewidth  = (((vb[2] - vb[0]) + (vb[3] - vb[1])) / 800.0).ToString("#.##############"); //0.25% linewidth
            string fullfilename = path.FullName + System.IO.Path.DirectorySeparatorChar + "wl_legend.svg";

            //Console.WriteLine("Writing legend to "+fullfilename);
            using (StreamWriter retstr = new StreamWriter(fullfilename)) {
                retstr.WriteLine(this.getSVGHeader());
                retstr.WriteLine(this.getSVGTagOpen(imagewidth, imageheight,
                                                    legendSquare.getAbsMarginViewBox(fontSizeBasedMarginLeft, fontSizeBasedMarginTop,
                                                                                     fontSizeBasedMarginRight, fontSizeBasedMarginBottom, textheight)
                                                    ));

                retstr.WriteLine(@"<desc>Drawing borders</desc>
<rect x='" + vb[0] + "' y='" + vb[1] + "' width='" + vb[2] + "' height='" + vb[3] + @"'
        fill='none' stroke='black' stroke-width='" + strokewidth + "' />");

                retstr.WriteLine(hormarker.exportSVG());

                Scientrace.Location loc2d, tloc2d;
                int    order        = 5;
                string centerSpots  = "<!-- END OF SPOTS CENTERS -->";
                double unitfraction = (Math.Pow(2, order) - 1);
                double unitheight   = Convert.ToDouble(canvasheight) / unitfraction;

                //added "+(stepsize*0.001)" to condition to avoid float-boundary-problems
                for (double wavelength = min_wl; wavelength <= max_wl + (((max_wl - min_wl) / resolution) * 0.001); wavelength = wavelength + ((max_wl - min_wl) / resolution))
                {
                    Scientrace.Location loc   = this.relLocationVector(wavelength);
                    Scientrace.Spot     aSpot = new Scientrace.Spot(loc, legendSquare, 1, 1, null);
                    loc2d = legendSquare.get2DLoc(aSpot.loc);

                    if (loc2d == null)
                    {
                        throw new Exception("ERROR: loc2d created by " + legendSquare.tag + " == null");
                    }

                    double centerspotsize = (Convert.ToDouble(canvaswidth) / Convert.ToDouble(resolution)) * 0.5;
                    loc2d.y = -centerspotsize + canvasheight;
                    //unitheight * (unitfraction-0.5);

/*								(Math.Pow(2.0,order-1) * 0.5) +
 *                                                              (Math.Pow(2.0,order-1) - 1)
 *                                                              );*/

                    centerSpots = this.spotSVGForWavelength(loc2d, centerspotsize, wavelength, 1) + centerSpots;

                    for (int iorder = 1; iorder <= order; iorder++)
                    {
                        tloc2d   = loc2d;
                        tloc2d.y = unitheight * (
                            (Math.Pow(2.0, iorder - 1) * 0.5) +
                            (Math.Pow(2.0, iorder - 1) - 1)
                            );
                        retstr.WriteLine(this.spotSVGForWavelength(tloc2d, unitheight * (Math.Pow(2, (iorder - 2))), wavelength, 0.25));
                    }
                }
                centerSpots = "<!-- START OF CENTERSPOTS-->" + centerSpots;
                retstr.WriteLine(centerSpots);
                retstr.WriteLine("</svg> ");

                //retstr.Close();
            }
        }