The Matsu Wheel: A Cloud-based Framework \protect\\ for the Efficient Analysis and Reanalysis \protect\\ of Earth Satellite Imagery
\IEEEauthorblockN{Maria T. Patterson\IEEEauthorrefmark{1
% Project Matsu is a collaboration between the Open Commons Consortium and NASA focused on developing open source technology for the cloud-based processing of Earth satellite imagery. A particular focus is the development of applications for detecting fires and floods to help support natural disaster detection and relief. Project Matsu has developed an open source cloud-based infrastructure to process, analyze, and reanalyze large collections of hyperspectral satellite image data using OpenStack, Hadoop, MapReduce, Storm and related technologies. We describe a framework for efficient analysis of large amounts of data called the Matsu ``Wheel." The Matsu Wheel is currently used to process incoming hyperspectral satellite data produced daily by NASA's Earth Observing-1 (EO-1) satellite. The framework is designed to be able to support scanning queries using cloud computing applications, such as Hadoop and Accumulo. A scanning query processes all, or most of the data, in a database or data repository. % % We also describe our preliminary Wheel analytics, including an anomaly detector for rare spectral signatures or thermal anomalies in hyperspectral data and a land cover classifier that can be used for water and flood detection. Each of these analytics can generate visual reports accessible via the web for the public and interested decision makers. The resultant products of the analytics are also made accessible through an Open Geospatial Compliant (OGC)-compliant Web Map Service (WMS) for further distribution. The Matsu Wheel allows many shared data services to be performed together to efficiently use resources for processing hyperspectral satellite image data and other, e.g., large environmental datasets that may be analyzed for many purposes. %
arxiv.tex
\documentclass[conference,letterpaper]{IEEEtran}
\IEEEoverridecommandlockouts

% *** IEEE Copyright notice with TikZ ***
%
\usepackage{tikz}
\usepackage{textcomp}
\usepackage{hyperref}
\usepackage{lipsum}

\newcommand\copyrighttext{%
  \footnotesize \textcopyright 2016 IEEE. Personal use of this material is permitted.
  Permission from IEEE must be obtained for all other uses, in any current or future
  media, including reprinting/republishing this material for advertising or promotional
  purposes, creating new collective works, for resale or redistribution to servers or
  lists, or reuse of any copyrighted component of this work in other works.
  DOI: \href{<http://tex.stackexchange.com>}{<DOI No.>}}
\newcommand\copyrightnotice{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=south,yshift=10pt] at (current page.south) {\fbox{\parbox{\dimexpr\textwidth-\fboxsep-\fboxrule\relax}{\copyrighttext}}};
\end{tikzpicture}%
}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{fixltx2e}
\usepackage{gensymb}
\usepackage{todonotes}
\usepackage{url}
%
\hyphenation{op-tical net-works semi-conduc-tor top-ology}


\begin{document}
%
%
%
\title{The Matsu Wheel: A Cloud-based Framework 
\protect\\ for the Efficient Analysis and Reanalysis
\protect\\ of Earth Satellite Imagery}


%
%
%
%
%
%
%
%

%

%
%
%

%
%
%
%
%
%

%
%
%
\author{\IEEEauthorblockN{Maria T. Patterson\IEEEauthorrefmark{1},
Nikolas Anderson\IEEEauthorrefmark{1}, 
Collin Bennett\IEEEauthorrefmark{2},
Jacob Bruggemann\IEEEauthorrefmark{1}, 
Robert L. Grossman\IEEEauthorrefmark{1}\IEEEauthorrefmark{2},\\
Matthew Handy\IEEEauthorrefmark{3},
Vuong Ly\IEEEauthorrefmark{3},
Daniel J. Mandl\IEEEauthorrefmark{3},
Shane Pederson\IEEEauthorrefmark{2},
James Pivarski\IEEEauthorrefmark{2},\\
Ray Powell\IEEEauthorrefmark{1}, 
Jonathan Spring\IEEEauthorrefmark{1},
Walt Wells\IEEEauthorrefmark{4}, and
John Xia\IEEEauthorrefmark{1}}
\IEEEauthorblockA{\IEEEauthorrefmark{1}Center for Data Intensive Science\\
University of Chicago,
Chicago, IL 60637\\ mtpatter@uchicago.edu}
\IEEEauthorblockA{\IEEEauthorrefmark{2}Open Data Group\\
River Forest, IL 60305}
\IEEEauthorblockA{\IEEEauthorrefmark{3}NASA Goddard Space Flight Center\\
Greenbelt, MD 20771}
\IEEEauthorblockA{\IEEEauthorrefmark{4}Open Commons Consortium}
}



%
\maketitle
\thispagestyle{plain}
\pagestyle{plain}
\copyrightnotice

\begin{abstract}
%
Project Matsu is a collaboration between the Open Commons Consortium and NASA focused on developing open source technology for the cloud-based processing of Earth satellite imagery.  A particular focus is the development of applications for detecting fires and floods to help support natural disaster detection and relief. Project Matsu has developed an open source cloud-based infrastructure to process, analyze, and reanalyze large collections of hyperspectral satellite image data using OpenStack, Hadoop, MapReduce, Storm and related technologies. 

We describe a framework for efficient analysis of large amounts of data called the Matsu ``Wheel."  The Matsu Wheel is currently used to process incoming hyperspectral satellite data produced daily by NASA's Earth Observing-1 (EO-1) satellite. The framework is designed to be able to support scanning queries using cloud computing applications, such as Hadoop and Accumulo.  A scanning query processes all, or most of the data, in a database or data repository.  %

%

We also describe our preliminary Wheel analytics, including an anomaly detector for rare spectral signatures or thermal anomalies in hyperspectral data and a land cover classifier that can be used for water and flood detection. Each of these analytics can generate visual reports accessible via the web for the public and interested decision makers. The resultant products of the analytics are also made accessible through an Open Geospatial Compliant (OGC)-compliant Web Map Service (WMS) for further distribution.  The Matsu Wheel allows many shared data services to be performed together to efficiently use resources for processing hyperspectral satellite image data and other, e.g., large environmental datasets that may be analyzed for many purposes.

%


\end{abstract}
%
%
%
%
%
%

%




%
%
%
%
%
%
%
%
\IEEEpeerreviewmaketitle


%
%
%
\section{Introduction}
The increasing availability of large volumes of scientific data due to the
decreasing cost of storage and processing power has led to new challenges in
scientific research.  Scientists are finding that the bottleneck to 
discovery is no longer a lack of data but an inability to manage and 
analyze their large datasets. 

A common class of problems require applying an analytic computation over an 
entire dataset.  Sometimes these are called {\em scanning queries} since they involve a
scan of the entire dataset. For example, analyzing each image in a large collection
of images is an example of a scanning query.  In contrast, standard queries typically process a relatively small percentage of the data in a database or data repository.

With multiple scanning queries that are run within a time that is comparable to 
the length of time required for a single scan, it can be much more efficient to 
scan the entire dataset once and apply each analytic in turn versus scanning the
entire dataset for each scanning query as the query arrives. This is the case unless the data management infrastructure has specific technology for recognizing and processing scanning queries.  In this paper, we introduce a software application called the Matsu Wheel that is designed to support multiple scanning queries over satellite imagery data.

Project Matsu is a collaborative effort between the 
Open Science Data Cloud (OSDC), managed by the Open Commons Consortium (OCC), 
and NASA, working to develop open source
tools for processing and analyzing Earth satellite imagery in the cloud.
The Project Matsu ``Wheel" is a framework for simplifying Earth satellite image
analysis on large volumes of data by providing an efficient system that performs all 
the common data services and then passes the prepared chunks of data in a common format to the analytics, which processes each new chunk of data in turn.

%
\subsection{Motivation for an analytic wheel}
The idea behind the wheel is to have all of the data processing services 
performed together on chunks of data to efficiently use resources, including 
available network bandwidth, access to secondary storage, and available computing resources.  This is especially important with reanalysis, in which the entire dataset is processed using an updated algorithm, a recalibration of the data, a new normalization of the data, a new workflow, etc.   
The motivation behind the analytic wheel is 
to streamline and share these services so that they are only performed 
once on each chunk of data in a scanning query, regardless of the number or type of scanning analytics run over the data.

\subsection{Comparison to existing frameworks}
The Matsu Wheel approach differs from other common data management or data processing systems.  Real-time distributed data processing frameworks (for example, Storm, S4, or Akka) are designed to process data in real time as it flows through a distributed system (see also, e.g., \cite{Backman2012,Zeng2013,Kienzler2012}).  In contrast, the Wheel is designed for the reanalysis of an entire static dataset that is stored in distributed storage system (for example, the Hadoop Distributed File System) or distributed database (for example, HBase or Accumulo).

It is important to note, that any distributed scale-out data processing system based upon virtual machines has certain performance issues due to the shared workload across multiple virtual machines associated with a single physical node. In particular, these types of applications may have significant variability in performance for real scientific workloads \cite{Jackson2010}.  This is true, when multiple scanning queries hit a distributed file system, a NoSQL database, or a wheel based system on top of one these infrastructures.
When a NoSQL database is used for multiple scanning queries with a framework like the wheel, the NoSQL database can quickly become overloaded.  


%
%
%
%
%
%
%
%
%


%
\subsection{Application to Earth satellite data}

Analyses of Earth satellite data and hyperspectral imagery data in particular
benefit from the Matsu Wheel system as a use case in which the data may be large,
have high-volume throughput, and are used for many types of applications.
The Project Matsu Wheel currently processes the data produced each day by NASA's 
Earth Observing- 1 (EO-1) satellite and makes a variety of data products available 
to the community.  In addition to the Atmospheric Corrector, the EO-1 satellite has 
two primary scientific instruments for land
observations, the Advanced Land Imager (ALI) and a hyperspectral 
imager called Hyperion \cite{Hearn2001,Pearlman2001}.  
EO-1 was launched in November 2000 as
part of NASA's New Millennium Program (NMP) initiative for advancing new technologies
in space and is currently in an extended mission.  

The ALI instrument acquires
data in 9 different bands from 0.48$-$2.35 $\mu$m with 30-meter resolution plus
a panchromatic band with higher 10-meter spatial resolution.  The standard scene
size projected on the Earth surface equates to 37 km x 42 km (width x length).
Hyperion has similar spatial resolution but higher spectral resolution, observing in 
242 band channels from 0.357$-$2.576 $\mu$m with 10-nm bandwidth. Hyperion scenes
have a smaller standard footprint width of 7.7 km.  The Matsu Wheel runs 
analytics over Level 1G data in Geographic Tagged 
Image File Format (GeoTiff) format, which have been radiometrically
corrected, resampled for geometric correction, and registered to a geographic
map projection.  The GeoTiff data and metadata for all bands in a single Hyperion
scene can amount to 1.5$-$2.5 GB of data for only the Level 1G data.  
A cloud environment for shared storage and computing capabilities is ideal for
scientific analysis of many scenes, which can quickly add to a large amount of data.


%
%
%
\section{Workflow}

\subsection{Cloud environment}

Project Matsu uses both an OpenStack-based computing platform and a 
Hadoop-based computing platform, both of which are managed by the OCC (www.occ-data.org)
in conjunction with the University of Chicago. The OpenStack platform 
(the Open Science Data Cloud \cite{Grossman2012}) currently contains 60 nodes,
1208 compute cores, 4832 GB of compute RAM, and 1096 TB of raw storage. 
The Hadoop \cite{White2012} platform currently contains 28 nodes, 896 compute cores, 
261 TB of storage, and 3584 GB of compute RAM. 

\subsection{Pre-processing of data on the OSDC}

The Open Science Data Cloud provides a number of data center services for 
Project Matsu.   
The data are received daily from NASA, stored on a distributed, fault-tolerant
file system (GlusterFS), and pre-processed prior to the application of the Wheel 
analytics on Skidmore.  The images are converted into SequenceFile format,
a file format more suited for MapReduce, and uploaded into HDFS \cite{MapReduce}.
%
%
Metadata and compute summary statistics are extracted for each scene and stored in 
Accumulo, a distributed NoSQL database \cite{Accumulo}.  The metadata are
used to display the geospatial location of scenes via a mapping service
so that users can easily visualize which areas of the Earth are covered in the
data processed by the Matsu Wheel.

Here is an overview of the Matsu data flow for processing EO-1 images and 
producing data and analytic products:
\begin{enumerate} 
\item Performed by NASA/GSFC as part of their daily operations: \\
a) Transmit data from NASA's EO-1 Satellite to NASA ground stations and then to
NASA/GSFC.\\
 b) Align data and generate Level 0 images.\\
 c) Transmit Level 0 data from NASA/GSFC to the OSDC.
\item Run by NASA on the OSDC OpenStack cloud for Matsu and other projects:\\
 a) Store Level 0 images in the OSDC Public Data Commons for long-term, active
storage.\\
 b) Within the OSDC, launch Virtual Machines (VMs) specifically built to 
 render Level 1 images from Level 0. Each Level 1 band is saved as a distinct 
 image file (GeoTIFF).\\
 c) Store Level 1 band images in the OSDC Public Data Commons for long-term storage.  \item Run specifically for Project Matsu on the Hadoop cloud:\\
 a) Read Level 1 images, combine bands, and serialize image bands into a single file.\\
 b) Store serialized files on HDFS.\\
 c) Run Wheel analytics on the serialized Level 1 images stored in HDFS.\\
 d) Store the results of the analysis in Accumulo for further analysis, generate reports, and load into a Web Map Service. 
\end{enumerate}

\subsection{Analytic `wheel' architecture}

The analytic Wheel is so named because multiple analytics are applied to data 
as it flows underneath.  While a bicycle or water wheel does not fit exactly, the
image is clear: do the work as the data flows through once, like the pavement under
the bicycle wheel.  With big data, retrieving or processing data multiple times
is an inefficient use of resources and should be avoided.  

When new data become available in HDFS as part of the pre-processing described
above, the MapReduce scanning analytics kick off.  
Intermediate output is written to HDFS, and all analytic results are stored in
Accumulo as JSON.  Secondary analysis that can run from the results of other
analytics can be done ``off the wheel" by using the Accumulo-stored JSON as
input.

As many analytics can be included in the Wheel as can run in the allowed time.
If new data are obtained each day, then the limit is 24 hours to avoid back-ups
in processing.  For other use cases, there may be a different time window in which
the results are needed.  This can be seconds, minutes, or hours.  Our MapReduce 
analytic environment is not designed to yield immediate results, but the 
analytics can be run on individual images at a per minute speed.  Analytics 
with results that  need to be made available as soon as possible can be 
configured to run first in the Wheel.  We show a diagram of the flow of EO-1 
data from acquisition and ingest into HDFS through the analytic Wheel framework 
in Figure \ref{fig:wheel}. 

%
%
%
\begin{figure*}[h ] 
\centering
\includegraphics[scale = .55]{WheelFlow.pdf}
\caption{A diagram of the flow of EO-1 ALI and Hyperion data
from data acquisition and ingest through the Wheel framework.  Orange denotes
the processes performed on the OSDC Skidmore cloud.  With the Wheel architecture,
the data need to be read in only once regardless of the number of analytics
applied to the data.  The Matsu Wheel system is unique in that, essentially,
the \emph{data} are flowing through the framework while the analytic queries
sit in place and scan for new data.  Additional analytics plug in easily, with the 
requirement that an analytic takes as input a batch of data to be processed.
An analytic query may be written such that it can be run on its own in the Wheel
or written to take as input the output of an upstream analytic.  The report generators
are an example of the latter case, generating summary information from upstream analytics.}
\label{fig:wheel}
\end{figure*}

The Wheel architecture is an efficient framework not restricted only to 
image processing, but is applicable to any workflow where an assortment 
of analytics needs to be run on data that require heavy pre-processing or 
have high-volume throughput.

%
%
%
\section{Analytics}
We are currently running five scanning analytics on daily images from 
NASA's EO-1 satellite with the Project Matsu Wheel, including several spectral
anomaly detection algorithms and a land cover classification analytic.  
Here we describe each of these and the resulting analytic reports generated.

\subsection{Contours and Clusters}
This analytic looks for contours in geographic space around clusters in spectral 
space.  
The input data consist of Level 1G EO-1 GeoTiff images from Hyperion, essentially
a set of radiances for all spectral bands for each pixel in an image.  The
radiance in each band is divided by its underlying solar irradiance to convert to 
units of reflectivity or at-sensor reflectance.  This is done
by scaling each band individually by the irradiance and then applying a
geometric correction for the solar elevation and Earth-Sun distance, as shown in
eqn.~\ref{eq:correction}, 

\begin{equation} \label{eq:correction}
\rho_i = \left(\frac{\pi}{\mu_0 F_{0,i} / d_{earth-sun}^2} \right) L_i
\end{equation}
where $\rho_i$ is the at-sensor reflectance at channel $i$, $\mu_0 =
\cos{\textrm{(solar zenith angle)}}$, $F_{0,i}$ is the incident solar flux at
channel $i$, $d_{Earth-Sun}$ is the Earth-Sun distance, and $L_i$ is the
irradiance recorded at channel $i$ \cite{Griffin2005}.  
This correction accounts for differences in the data due to time of day or year. 

We then apply a principal component analysis (PCA) to the set
of reflectivities, and the top N (we choose N=5) 
PCA components are extracted for further analysis.
There are two passes for the Contours and Clusters analytic to generate a 
contour result: spectral and spatial.
\begin{itemize}
  \item Spectral clusters are found in the transformed N-dimensional spectral space 
  for each image using a k-means clustering algorithm and are then
  ranked from most to least extreme using the 
  Mahalanobis distance of the cluster from the spectral center of the image.
  
  \item Pixels are spatially analyzed and are grouped together into contiguous 
  regions with a certain minimum purity or fraction of pixels that belong to that
  cluster and are then ranked again based on their distance from the spectral 
  cluster center.
  %
\end{itemize}

%
%
%
%
%
%
%
%
Each cluster then has a score indicating 1) how anomalous the spectral signature is 
in comparison with the rest of the image
and 2) how close the pixels within the contour are to the cluster signature.  
The top ten most anomalous clusters over a given timeframe are singled out for manual 
review and highlighted in a daily overview summary report.

The analytic returns the clusters as contours of geographic regions of spectral
"anomalies" which can then be
viewed as polygonal overlays on a map.  The Matsu Wheel produces image reports 
for each image, which contain an interactive map with options for an 
OpenStreetMap, Google Physical, or Google Satellite base layer and an RGB image 
created from the hyperspectral data and identified polygon contours as options
for overlays. Researchers or anyone interested in the results can view the image
reports online through a web browser.  %
%
%
%

By implementing this analytic in the Matsu Wheel, we have been able to automatically
identify regions
of interesting activity on the Earth's surface, including several volcanic events.
For example, in February 2014,
this Matsu Wheel analytic automatically identified anomalous activity 
in EO-1 Hyperion data of the Barren Island volcano, which was also confirmed to 
be active by other sources.  We show an example analytic image report for this
event in Figure \ref{fig:Matsu image report}.

%
%
%
\begin{figure*}[!h ] 
\centering
\includegraphics[scale = .45]{MatsuReport.pdf}
\caption{A screenshot of a Matsu analytic image report for 
a Contours and Clusters spectral anomaly analytic that automatically identified 
regions of interest
around the Barren Island volcano, confirmed as active by other sources
in February 2014.  The reports contain basic information about the data analyzed
and the analytic products and
a zoomable map with the data and analytic products 
shown as an overlay on an OpenStreetMap, Google Physical,
or Google Satellite base layer.  In this analytic, interesting regions are
given a cluster score from 0 - 1000 based on how anomalous they are compared to the
average detection and appear as colored contours over the image.}
\label{fig:Matsu image report}
\end{figure*}


\subsection{Rare Pixel Finder}
The Rare Pixel Finder (RPF) is an analytic designed to find small clusters of 
unusual pixels in a hyperspectral image. 
This algorithm is applied directly to the EO-1 data in radiances, but the data can 
also be transformed to reflectances or other metrics or can have logs applied.

Using the subset of k hyperspectral bands that are determined to be most 
informative, it computes k-dimensional Mahalanobis distances and finds the pixels 
most distant.
From this subset, pixels that are both spectrally similar and geographically
proximate are retained. Spectrally similar pixels that can be further grouped into 
small compact sets are reported as potential outlying clusters.
Details of the different steps of the algorithm are given below. 

In the pre-processing step, we remove areas of the image that are obvious anomalies
not related to the image (e.g., zero radiances on the edges of images), as well as spectral
bands that correspond to water absorption or other phenomena that result in near-zero 
observed radiances. Any transformations are applied to the data at this point, such as 
transforming radiance to reflectance or logs.

Once the data are pre-processed, the Mahalanobis distance ($D_i$) is calculated for each pixel.
Then, only the subset $S_1$ of pixels that satisfy $D_i > k_1$ are selected, where $k_1$ is chosen 
such that $S_1$ only contains 0.1--0.5\% of pixels. In practice $k_1$ was based on the upper 
6$\sigma$ of the distribution of sample distances, assuming a log-normal distribution for the
distances. 

For the subset of $S_1$ pixels chosen in the previous step, we next compute a 
similarity matrix $T$ with elements $T_{ij}$ measuring the spectral similarity 
between each pair of pixels. The similarity metric is based on the dot product 
between each pair of points and measures the multi-dimensional angle between points.
The matrix is only formed for the subset $S_1$ and contains a few hundred rows. The pixels
are then further subsetted. Pixel $i$ is selected for set $S_2$ if $T_{ij} > k_2$ for 
$j \neq i$. The parameter $k_2$ is chosen to be very close to 1; in this way we select
objects that are both spectrally extreme but still have similar spectral profiles to one
another.

In order to cluster the pixels geographically, we assume they lie on a rectangular grid. 
An $L_1$ norm metric is applied to the subset $S_2$ in order to further whittle down 
the candidate set to pixels that are spectrally extreme, spectrally similar, and geographically 
proximate. The metric is set so that traversing from one pixel to an immediately adjacent one would 
give a distance 
of $1$, as if only vertical and horizontal movements were allowed. Pixel $i$ is selected for set 
$S_3$ if $M_{ij} < k_3$ for $j \neq i$ and for some
small value of $k_3$. We used $k_3 = 3$, so that pixels either needed to be touching on a face or 
diagonally adjacent.

In the final step a simple heuristic designed to find the connected components of an 
undirected graph is applied. We further restrict to a set $S_4$ that are geographically
proximate to at least $k_4$ other pixels (including itself). We used $k_4=5$, with the
goal of finding compact clusters of between 5 and 20 pixels in size. The clumping
heuristic then returns the pixels that were mapped into a cluster, the corresponding
cluster ID's, and the associated distances for the elements of the cluster.

The flagged pixels are reported as "objects". These groups of objects are further filtered in order
to make sure that they actually represent regions of interest. The following criteria must be 
satisfied in order to qualify:

\begin{enumerate}
  \item {\it Spectral Extremeness}.  The mean Mahalanobis Distance must be greater 
  than or equal to some parameter $p_1$.  This selects clusters that are 
  sufficiently extreme in spectral space.   
  \item {\it Spectral Closeness}.  The Signal-to-Noise ratio must be greater than 
  or equal to some parameter $p_2$.  This selects clusters that have similar 
  values of Mahalanobis Distance. 
  \item {\it Cluster Size}.  All clusters must be between a minimum value 
  parameter $p_3$ and a maximum parameter $p_4$ pixels in size (the goal of this 
  classifier is to find small clusters).  
  \item {\it Cluster Dimension}.  All clusters must have at least some
  parameter  $p_5$ rows and columns (but are not restricted to be rectangles).
\end{enumerate}

Parameters $p_1$ - $p_5$ are all tuning parameters that can be set in the algorithm
%
%
%
to achieve the desired results.

%
%

%
%
%
%
%
%
%

%

%
%
%
%
%

%

%
%

%
%
%
%
%
%

%
%
%
%
%
%
%



\subsection{Gaussian Mixture Model and K-Nearest Neighbors (GMM-KNN) Algorithm}
The Gaussian Mixture Model and  K-Nearest Neighbors (GMM-KNN) algorithm is also
designed to find small clusters of unusual pixels in a multispectral image.
Using 10--30 spectral bands, it fits the most common spectral shapes to a 
Gaussian Mixture Model (smoothly varying, but makes strong assumptions about 
tails of the distribution) and also a K-Nearest Neighbor model (more detailed 
description of tails, but granular), then searches for pixels that are far from 
common.  Once a set of candidate pixels have been found, they are expanded and 
merged into ``clumps'' using a flood-fill algorithm.  Six characteristics of 
these clumps are used to further reduce the number of candidates.

In short, the GMM-KNN algorithm consists of the following steps.

\begin{enumerate}
  \item Preprocessing: Take the logarithm of the radiance value of each band and 
    project the result onto a color-only basis to remove variations in intensity,
    which tend to be transient while variations in color are more indicative of
    ground objects.
  \item Gaussian Mixture Model: Fit $k$ = 20 Gaussian components to the spectra of all 
    pixels, sufficiently large to cover the major structures in a typical image.
  \item Flood-fill: Expand GMM outliers to enclose any surrounding region that is 
    also anomalous, and merge GMM outliers if they are in the same clump.
  \item Characterizing clumps: Derive a detailed suite of features to quantify 
    each clump, including KNN, edge detection, and the distribution of pixel 
    spectra in the clump.
  \item Optimizing selection: Choose the most unusual candidates based on their 
    features.
\end{enumerate}


\subsection{Spectral Blobs}
This algorithm uses a ``windowing'' technique to create a boundary mask from the
standard deviation of neighboring pixels.  A catalog of spectrally similar blobs,
that contain varying numbers of pixels, is created.
This analytic consists of the following steps:
\begin{itemize}
  \item Label spatially connected components of the mask using an undirected graph
  search algorithm.
  \item  Apply statistical significance tests (t-test, chi-squared) to the
  spectral features of the connected component (the ``blobs'').
  \item Merge spectrally similar regions.
\end{itemize}

The anomalous regions are the small spatial blobs that are not a member of any
larger spatial cluster.

\subsection{Supervised Spectral Classifier}
The Supervised Spectral Classifier is a land coverage classification algorithm
for the Matsu Wheel.  We are particularly interested in developing these analytics
for the detection of water and constructing flood maps to complement the onboard
EO-1 flood detection system \cite{Ip2006}.
This analytic is written to take ALI or Hyperion Level 1G
data and classify each pixel in an image as a member of a given class
in a provided training set.  We currently implement this analytic with a 
simple land coverage classification training set with four possible classes:
\begin{itemize}
\item{Clouds}
\item{Water}
\item{Desert / dry land}
\item{Vegetation}
\end{itemize}

The classifier relies on a support vector machine (SVM) algorithm, using the 
reflectance values of each pixel as the characterizing vector. 
In this implementation of the classifier, we bin Hyperion data to
resemble ALI spectra for ease of use and computation speed in training the 
classifier.  The result of this analytic is a GeoTiff showing the classification
at each pixel.

\subsubsection{Building a training data set}
We constructed a training data set of classified spectra from sections of EO-1 
Hyperion images over areas 
with known land coverage and cloud coverage and confirmed our selections by visual 
inspection of three-color (RGB) images created of the training images.
We used a combinination of Hyperion bands B16 (508.22 nm), B23 (579.45 nm), and 
B29 (640.5 nm) to construct the RGB images.
For each image contributing to the training data set, we only included spectra for
collections of pixels that were visually confirmed as exclusively desert, water, 
clouds, or vegetation. 

The training data set consists of approximately 6,000 to
9,000 objects for each class.
%
We include spectra for a variety of different regions on the
Earth observed during different times of the year and a range of solar elevation 
angles.  Because absolute values are necessary to directly compare the training 
data to all test images, the raw
irradiance values from the Level 1G data must first be converted to at-sensor 
reflectance using eqn.~\ref{eq:correction}. 
Table \ref{tab:trainingset} lists general properties of the Hyperion scenes 
used in constructing the training set, where the class column indicates which
class(es) (C = cloud, W = water, V = vegetation, and D = desert) 
that scene contributed to.

%
%
%
\begin{table}[!h]
\caption{Scenes included in training set}
\label{tab:trainingset}
\centering
\begin{tabular}{|l|c|r|r|r|}
\hline

Region name& Class & Obs Date & Sun Azim. (\degree) & Sun Elev. (\degree)\\ \hline
Aira & W & 4/18/14 & 119.12 & 49.1 \\ 
San Rossore & C/W & 1/29/14 & 145.5 & 20.9 \\ 
San Rossore & C/V & 8/10/12 & 135.8 & 54.5 \\ 
Barton Bendish & C & 8/22/13 & 142.7 & 43.5 \\ 
Jasper Ridge & V/D & 9/17/13 & 140.7 & 46.9 \\ 
Jasper Ridge & V/C & 9/14/13 & 132.9 & 45.2 \\ %
Jasper Ridge & V/C & 9/27/12 & 147.6 & 45.4 \\ %
Arabian Desert & D & 12/30/12 & 147.0 & 29.9 \\
Jornada & D & 12/10/12 & 28.7 & 151.4 \\
Jornada & D & 7/24/12 & 59.6 & 107.5 \\
Negev & D & 9/15/12 & 130.7 & 52.1 \\
White Sands & C & 7/29/12 & 58.3 & 108.4 \\
Besetsutzuyu & V & 7/14/12 & 56.8 & 135.5 \\
Kenatedo & W & 6/22/12 & 50.5 & 46.5 \\ 
Santarem & W & 6/17/12 & 57.1 & 118.15 \\
Bibubemuku & W & 5/20/12 & 57.5 & 127.7 \\
\hline
\end{tabular}
\end{table}

We show a plot of the average training set object's reflectance spectra for each
of the four classes (clouds, desert, vegetation, water) in Figure 
\ref{fig:trainingSpec}, which are in agreement with the expected results.
These spectra are consistent with the spectral signatures of cloud, vegetation,
and desert sand presented in other examples of EO-1 Hyperion data analysis,
specifically Figures 3 and 4 in Griffin, et. al. (2005)
\cite{Griffin2005} \cite{Burke2004}.
%
%

%
%
%
\begin{figure*}[!h ]
\centering
\includegraphics[scale=0.5]{trainingSpectra}
\caption{The average reflectance spectra for each of the four classifications in
the training data used by our implementation of the Supervised Spectral Classifier
analytic. The four classes are clouds (salmon), desert (lime green), vegetation
(cyan), and water (purple). Shaded grey areas show the wavelength coverage of
ALI bands, which are the wavelength regions used by the classifier described.}
\label{fig:trainingSpec}
\end{figure*}


%
%
%
%
%
%
%

%
%
%

%
%
%
%


\subsubsection{Classifying new data}
The classifier uses the SVM method provided by the Python
scikit-learn machine learning package \cite{scikit-learn}. 
We construct a vector space from all ALI bands and two additional ALI band ratios,
the ratios between ALI bands 3:7 and 4:8.  These ratios were chosen because
they provided the best individual results in correctly distinguishing between 
classes when used as the sole dimension for the SVM.

For Hyperion images, bands that
correspond to the coverages of the ALI bands are combined. 
The same corrections to reflectance values that are applied to the training data 
are applied to the input image data. For ALI data, an additional scale and offset
need to be applied before the irradiance values are converted to reflectance.

\subsubsection{Validating results}
To confirm that the classifier analytic is generating reasonable results,
we compare the fractional amount of land coverage types calculated by 
the classifier with known fractional amounts from other sources.
We compare our results for classified cloud coverage with the cloud coverage
amounts stated for individual scenes available through the
EarthExplorer tool from the U.S. Geological Survey (USGS) \cite{EarthExplorer}.
We show a visual comparison of cloud coverage determined by our classifier with cloud 
coverage amounts stated by EarthExplorer for three Hyperion scenes of the big island 
of Hawaii with varying amounts of clouds and a randomly chosen scene of a section of 
the coast of Valencia in Figure \ref{fig:cloudtests}. 
%
%
For each pair of scenes, the left image shows an RGB image
of the Hyperion data with the
USGS calculated cloud coverage, and the right column has the classified image results,
with the amount of cloud coverage classified indicated. 

\begin{figure*}
\centering
	
	\begin{subfigure}[b]{.2\linewidth}
		\includegraphics[scale=0.65]{10testbright}
		\caption{EarthExplorer: \\10-19\% cloud coverage}
		\label{fig:10rgb}
	\end{subfigure}
	\begin{subfigure}[b]{.2\linewidth}
		\includegraphics[scale=0.65]{10test}
		\caption{This work: \\0.5\% cloud coverage}
		\label{fig:10class}
	\end{subfigure}
    \hspace{.65in}
    \begin{subfigure}[b]{.2\linewidth}
		\includegraphics[scale=0.65]{40testbright}
		\caption{EarthExplorer: \\40-49\% cloud coverage}
		\label{fig:40rgb}
	\end{subfigure}
	\begin{subfigure}[b]{.2\linewidth}
		\includegraphics[scale=0.65]{40test}
		\caption{This work: \\23\% cloud coverage}
		\label{fig:40class}
	\end{subfigure}
	
	\begin{subfigure}[b]{.2\linewidth}
		\includegraphics[scale=0.675]{90testbright}
		\caption{EarthExplorer: \\90-99\% cloud coverage}
		\label{fig:90rgb}
	\end{subfigure}
    \begin{subfigure}[b]{.2\linewidth}
		\includegraphics[scale=0.675]{90test.png}
		\caption{This work: \\95\% cloud coverage}
		\label{fig:90class}
	\end{subfigure}
    \hspace{.65in}
    \begin{subfigure}[b]{.2\linewidth}
    	%
        \includegraphics[scale=0.675]{valenciargb.png}
        \caption{EarthExplorer: \\10-19\% cloud coverage}
        \label{fig:valencrgb}
     \end{subfigure}
     \begin{subfigure}[b]{.2\linewidth}
    	\includegraphics[scale=0.675]{valenciaclassified.png}
        \caption{This work: \\28\% cloud coverage}
        \label{fig:valencclass}
    \end{subfigure}
	
	\caption{A visual comparison of RGB images  (left) 
    for several Hyperion test data scenes
    against the results from our Supervised Spectral Classifier  (right) with a 
    training set of 4 classes. For the classified images, white = clouds, 
    green = vegetation, blue = water, brown = desert/ dry land.
    Subfigures a) to f) are scenes over the big island of Hawaii showing a range
    of cloud coverage amounts.  Subfigures g) and h) show the coastal region of
    Valencia, Spain with a good mix of all four classes.
    The classifier results generally appear to be visually consistent with RGB 
    images, though the calculations for classified cloud coverage are not in 
    complete agreement with USGS. This may be because of a different treatment of
    very thin cloud "haze" in cloud coverage calculations.	}
    \label{fig:cloudtests}
\end{figure*}

The classified images appear to be visually consistent with RGB images, though the
calculations for classified cloud coverage are not in complete agreement
with USGS particularly for lower amounts of cloud coverage. 
This may be because the USGS EarthExplorer images include very thin cloud "haze" 
in cloud coverage calculations.
%
%
%
%
%

In the image of Valencia, Spain, shown in Figures \ref{fig:valencrgb} and
\ref{fig:valencclass} the classifier can clearly distinguish the 
coastline in the picture, correctly classifying the water and land features
and shows good agreement with regions that appear to be cloud.
It has some difficulty in shadowed areas like those regions covered by cloud shadow.
In Figure \ref{fig:expected}, we show a plot comparing expected cloud and water 
coverage to the coverages determined by our classifier for 20 random test scenes. 
For each scene, the expected cloud coverage is taken as the center of the range 
provided by the USGS EarthExplorer summary for that image. The expected water coverage 
is calculated from scenes of islands that are completely contained within the image. 
We can then calculate expected water coverage by removing the known fractional
land area of the islands and the USGS reported cloud coverage.
We fit a regression line to the data, which shows an overall consistent 
relationship between the classified results and expected estimates.

%
%
%
%
%
%
%
%
%

\begin{figure}
	\includegraphics[scale=0.5]{classExpect.png}
    \caption{Comparison of expected cloud and water coverages from USGS vs. 
    coverages calculated from our classifier. Expected water points (triangles) are 
    calculated from island scenes as described in the text. 
 	Expected cloud coverage estimates (circles) are taken from USGS EarthExplorer 
    quoted cloud coverage for each image. 
    The linear regression is the solid black line, and the grey 
    shaded area is the 95\% confidence interval. 
    A 1-1 relationship is shown as a dashed black line for comparison.}
    \label{fig:expected}
\end{figure}

\subsection{Viewing analytic results}
For convenience, each analytic produces a report after each run of the Wheel.  
These reports are built from the JSON results stored in Accumulo 
and are accessible to the public via a web page.  The generated reports
contain spectral and geospatial information about the scene analyzed
as well as analytic results.  An overview summary report is created for 
all daily data processed by an analytic in one run of the Wheel in addition to
reports for individual scenes.  These reports are generated and viewable
immediately upon completion of the scan of new data available each day
at the following address: \url{http://matsu-analytics.opensciencedatacloud.org/}.
Analytic products are also made programmatically accessible through a Web Map
Service.

%
%
%
\section{Future work}
The Matsu Wheel allows for additional analytics to be easily
slotted in with no change to the existing framework so that we
can continue to develop a variety of scanning analytics over these data.
We are extending our existing Supervised Spectral Classifier to use 
specifically over floodplain regions to aid in flood detection for disaster relief.
We are also planning to develop a similar analytic to aid in the detection of fires.

The analytics we described here are all detection algorithms, but we can
also apply this framework and the results of our current analytics to implement
algorithms for prediction. For example, our future work includes developing 
Wheel analytics for the prediction of floods.  This could be done using the following
approach:
\begin{enumerate}
\item Develop a dataset of features describing the observed topology of the Earth.
\item Use the topological data to identify "flood basins," or regions that may
		accumulate water around a local minimum.
\item Determine the relationship between detected water coverage in flood basins and 
		the volume of water present.
\item Use observed water coverage on specific dates to relate the water volume
		in flood basins with time.
\item Use geospatial climate data to relate recent rainfall amounts with water
		volume, which then provides a simple model relating rainfall to expected
        water coverage at any pixel.
\end{enumerate}

%
%
%
%
This proposed scanning analytic would provide important information 
particularly if implemented
over satellite data with global and frequent coverage, such as data from the 
Global Precipitation Measurement (GPM) mission \cite{GPM} \cite{Neeck2013}.
Our future work involves continuing to develop the Matsu Wheel analytics 
and apply this framework to additional Earth satellite datasets.


%
%
%
\section{Summary}
We have described here the Project Matsu Wheel, which is what we believe to be
the first working application of a Hadoop-based framework for creating analysis
products from a daily scan of available satellite imagery data.  This system is
unique in that it allows for new analytics to be dropped into a daily process
that scans all available data and produces new data analysis products.
With an analytic Wheel scanning framework, the data
need to be read in only once, regardless of the number or types of analytics
applied, which is particularly advantageous when large volumes of data,
such as those produced by Earth satellite observations, need to be 
processed by an assortment of analytics.

We currently use the Matsu Wheel to process daily spectral data from
NASA's EO-1 satellite and make the data and Wheel analytic products available 
to the public through the Open Science Data Cloud and via analytic 
reports on the web. 

A driving goal of Project Matsu is to develop open source technology
for satellite imagery analysis and data mining analytics to provide
data products in support of human assisted disaster relief. The open 
nature of this project and its implementation over commodity hardware
encourages the development and growth of a community of contributors
to develop new scanning analytics for these and other Earth satellite data.

%


%
\section*{Acknowledgment}

Project Matsu is an Open Commons Consortium (OCC)-sponsored project
supported by the Open Science Data Cloud.
The source code and documentation is made available on GitHub at
(\url{https://github.com/LabAdvComp/matsu-project}).
This work was supported in part by grants from Gordon and Betty Moore 
Foundation and the National Science Foundation (Grant OISE- 1129076
and CISE 1127316).

The Earth Observing-1 satellite image is courtesy of 
%
%
the Earth Observing-1 project team at NASA Goddard Space Flight Center.
The EarthExplorer cloud coverage 
calculations are available from the U.S. Geological Survey on earthexplorer.usgs.gov.
 


%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%

%
%


%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%


%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%


%
%
%
%
%
%



%
%
%
%
%
%
%

%

%
%
%
%
%
%
\bibliography{biblio}
\bibliographystyle{IEEEtran}


\end{document}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%

%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
pgfcore.code.tex
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcore.code.tex,v 1.7 2010/04/11 07:09:19 ludewich Exp $

\newif\ifpgf@draftmode

\input pgfmath.code.tex

\input pgfcorepoints.code.tex
\input pgfcorepathconstruct.code.tex
\input pgfcorepathusage.code.tex
\input pgfcorescopes.code.tex
\input pgfcoregraphicstate.code.tex
\input pgfcoretransformations.code.tex
\input pgfcorequick.code.tex
\input pgfcoreobjects.code.tex
\input pgfcorepathprocessing.code.tex
\input pgfcorearrows.code.tex
\input pgfcoreshade.code.tex
\input pgfcoreimage.code.tex
\input pgfcorelayers.code.tex
\input pgfcoretransparency.code.tex
\input pgfcorepatterns.code.tex

\pgfutil@ifundefined{pgf@texdist@protect}{%
	\def\pgf@texdist@protect{}%
}{}
\endinput

pgffor.code.tex
% Copyright 2008 by Till Tantau and Mark Wibrow
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/utilities/pgffor.code.tex,v 1.18 2010/03/23 14:47:45 vibrovski Exp $


\newdimen\pgffor@iter
\newdimen\pgffor@skip
\newif\ifpgffor@continue


\let\pgffor@beginhook=\pgfutil@empty
\let\pgffor@endhook=\pgfutil@empty
\let\pgffor@afterhook=\pgfutil@empty

% Stack emulation
%
\newtoks\pgffor@stack
\pgffor@stack={{}{}{}}

\def\pgffor@stackpush#1{%
	\def\pgffor@stacktemp{#1}%
	\expandafter\expandafter\expandafter\pgffor@stack\expandafter\expandafter\expandafter=%
	\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter%
		{\expandafter\pgffor@stacktemp\expandafter}\the\pgffor@stack}%
}

\def\pgffor@stackpop{\expandafter\pgffor@@stackpop\the\pgffor@stack\pgffor@stackstop}
\def\pgffor@@stackpop#1#2\pgffor@stackstop{\pgffor@stack{#2}#1}

\def\pgffor@emptyvalues{, \pgffor@stop,}%

\def\pgffor@foreach{%
	\pgffor@atbeginforeach%
	\let\pgffor@assign@before@code=\pgfutil@empty%
	\let\pgffor@assign@after@code=\pgfutil@empty%
	\let\pgffor@assign@once@code=\pgfutil@empty%
	\let\pgffor@remember@code=\pgfutil@empty%
	\let\pgffor@remember@once@code=\pgfutil@empty%
	\pgffor@alphabeticsequencefalse%
	\pgffor@contextfalse%	
	%	
	\let\pgffor@var=\pgfutil@empty
	%
	\pgffor@vars%
}
	
\let\foreach=\pgffor@foreach

\def\pgffor@vars{%
	\pgfutil@ifnextchar i{\pgffor@@vars@end}{%
		\pgfutil@ifnextchar[{\pgffor@@vars@opt}{%]
			\pgfutil@ifnextchar/{\pgffor@@vars@slash@gobble}{%	
				\pgffor@@vars}}}}%
				
\def\pgffor@@vars@end in{\pgfutil@ifnextchar\bgroup{\pgffor@normal@list}{\pgffor@macro@list}}
\def\pgffor@@vars@opt[#1]{\pgfkeys{/pgf/foreach/.cd,#1}\pgffor@vars}
\def\pgffor@@vars#1{\pgffor@var@add#1\pgffor@stop\pgffor@vars}
\def\pgffor@@vars@slash@gobble/{\pgffor@@vars}

\def\pgffor@var@add#1#2\pgffor@stop{%
	\ifx\pgffor@var\pgfutil@empty%
		\def\pgffor@var{#1}%
		\def\pgffor@mainvar{#1}%
	\else%
		\expandafter\def\expandafter\pgffor@var\expandafter{\pgffor@var/#1}%
	\fi%
}

\def\pgffor@macro@list#1{%
  \expandafter\pgffor@normal@list\expandafter{#1}}
\def\pgffor@normal@list#1{%
  \def\pgffor@values{#1, \pgffor@stop,}%
  \ifx\pgffor@values\pgffor@emptyvalues
    \def\pgffor@values{\pgffor@stop,}%
  \fi%
  \let\pgffor@body=\pgfutil@empty%
  \global\pgffor@continuetrue%
  \pgffor@collectbody}
\def\pgffor@collectbody{%
  \pgfutil@ifnextchar\foreach{\pgffor@collectforeach}{%
    \pgfutil@ifnextchar\bgroup{\pgffor@collectargument}{\pgffor@collectsemicolon}}%
}

\def\pgffor@collectforeach\foreach#1in{%
  \pgfutil@ifnextchar\bgroup{\pgffor@collectforeach@normal{#1}}{\pgffor@collectforeach@macro{#1}}}
\def\pgffor@collectforeach@macro#1#2{%
  \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body\foreach#1in#2}%
  \pgffor@collectbody%
}
\def\pgffor@collectforeach@normal#1#2{%
  \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body\foreach#1in{#2}}%
  \pgffor@collectbody%
}
\long\def\pgffor@collectargument#1{%
	\expandafter\pgfutil@in@\expandafter\foreach\expandafter{\pgffor@body}%
	\ifpgfutil@in@%
		\expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter%
  	{\pgffor@body{#1}}%
	\else%
		\expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter%
  	{\pgffor@body#1}%
	\fi%
  \pgffor@iterate%
}

\def\pgffor@collectsemicolon{%
  \let\pgffor@next=\pgffor@collectnormalsemicolon%
  \ifnum\the\catcode`\;=\active\relax%
    \let\pgffor@next=\pgffor@collectactivesemicolon%
  \fi%
  \pgffor@next%
}

\def\pgffor@collectnormalsemicolon#1;{%
  \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body#1;}%
  \pgffor@iterate%
}

{
  \catcode`\;=\active
  
  \gdef\pgffor@collectactivesemicolon#1;{%
    \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body#1;}%
    \pgffor@iterate%
  }
}  

\def\pgffor@iterate{%
	% Must do all of these in case the internal stack is used.
	\let\pgffor@last=\pgfutil@empty%
  \let\pgffor@prevlast=\pgfutil@empty%
  \let\pgffor@dotsend=\pgfutil@empty%
	\let\pgffor@dots@pre=\pgfutil@empty%
	\let\pgffor@dots@post=\pgfutil@empty%
	%
	\expandafter\pgffor@scan\pgffor@values}

\def\pgffor@stop{\pgffor@stop}%
\def\pgffor@dots{...}%

\def\pgffor@scan{\pgfutil@ifnextchar({\pgffor@scanround}{\pgffor@scanone}}
\def\pgffor@scanround(#1)#2,{\def\pgffor@value{(#1)}\pgffor@scanned}
\def\pgffor@scanone#1,{\def\pgffor@value{#1}\pgffor@scanned}


% Check for dots.
\newif\ifpgffor@dots@in@
\def\pgffor@dots@in@#1...#2#3\pgffor@stop{%
	\ifx\pgffor@dots@@#2%
		\pgffor@dots@in@false%
	\else%
		\pgffor@dots@in@true%
	\fi%
}

\def\pgffor@dots@@{\pgffor@dots@@}

\def\pgffor@scanned{%
  \ifx\pgffor@value\pgffor@stop%
    \let\pgffor@next=\pgffor@after% Done!
  \else%
  	% Check for dots. Quicker than \pgfutil@in@ and not suceptable 
		% to false-positives when a token sequence ends in a single full-stop.
  	\expandafter\pgffor@dots@in@\pgffor@value\pgffor@dots@...\pgffor@dots@@\pgffor@stop%
    \ifpgffor@dots@in@%
      \let\pgffor@next=\pgffor@handledots%
    \else%
      \let\pgffor@next=\pgffor@handlevalue%
    \fi%
    \ifpgffor@continue%
    \else%
      \let\pgffor@next=\pgffor@scan% Done!
    \fi%
  \fi%
  \pgffor@next}


\def\pgffor@after{%
  \global\pgffor@continuetrue%
  \pgffor@atendforeach%
  \pgffor@afterhook}
  
\def\pgffor@handlevalue{%
	\let\pgffor@prevlast=\pgffor@last%
  \let\pgffor@last=\pgffor@value%
  \pgffor@invokebody%
  \pgffor@scan%
}

	
\def\pgffor@invokebody{%
	\pgffor@begingroup%
    \expandafter\pgfutil@in@\expandafter/\expandafter{\pgffor@var}%
    \ifpgfutil@in@%
      \expandafter\def\expandafter\pgffor@valuerest\expandafter{\pgffor@value//\relax}%
      \expandafter\pgffor@multiassign\pgffor@var/\pgffor@stop/\pgffor@stop/\relax%
    \else%
      \expandafter\expandafter\expandafter\def\expandafter\pgffor@var\expandafter{\pgffor@value}%
    \fi%
    % Execute assign once code.
    \ifx\pgffor@assign@once@code\pgfutil@empty%
  	\else%
  		\pgffor@assign@once@code%
  	\fi%
    % Execute assign before code.
    \ifx\pgffor@assign@before@code\pgfutil@empty%
    \else%
    	\pgffor@assign@before@code%
    \fi%  
    %  
    \expandafter\pgffor@beginhook\pgffor@body\pgffor@endhook%
    % Execute assign after code.
    \ifx\pgffor@assign@after@code\pgfutil@empty%
    \else%
    	\pgffor@assign@after@code%
    \fi%  
    %
  \pgffor@endgroup%
}


\def\pgffor@multiassign#1/#2/\relax{%
  \def\pgffor@currentvar{#1}%
  \def\pgffor@rest{#2}%
  \ifx\pgffor@currentvar\pgffor@stop%
    \let\pgffor@next=\relax%
  \else%
    \let\pgffor@next=\pgffor@multiassignrest%
  \fi%
  \pgffor@next%
}

\def\pgffor@multiassignrest{\expandafter\pgffor@multiassignfinal\pgffor@valuerest}
\def\pgffor@multiassignfinal#1/#2/\relax{%
	\def\pgffor@temp{#1}%
	\ifx\pgffor@currentvar\pgffor@mainvar%
		\ifpgffor@alphabeticsequence%
  		\pgffor@makealphabetic\pgffor@temp%
  	\fi%
  \fi%
  \def\pgffor@test{#2}%
  \ifx\pgffor@test\pgfutil@empty%
  	\expandafter\def\expandafter\pgffor@valuerest\expandafter{\pgffor@temp//\relax}% repeat
  \else%
    \def\pgffor@valuerest{#2/\relax}%
  \fi%
  \expandafter\expandafter\expandafter\def\expandafter\pgffor@currentvar\expandafter{\pgffor@temp}%
	%
  \expandafter\pgffor@multiassign\pgffor@rest/\relax%
}    		

\def\pgffor@gobblespaces#1{\pgfutil@ifnextchar x{#1}{#1}}

\def\pgffor@handledots{%
	\pgffor@gobblespaces{\expandafter\pgffor@@handledots\pgffor@value\pgffor@@stop}%
}

\newif\ifpgffor@context

\def\pgffor@@handledots#1...#2\pgffor@@stop{%
	% Define the context if any.
	\def\pgffor@dots@pre{#1}%
	\def\pgffor@dots@post{#2}%
	\def\pgffor@dots@stripcontext#1##1#2\pgffor@@stop{\def\pgffor@dotsvalue{##1}}%
	\pgffor@contexttrue%
	\ifx\pgffor@dots@pre\pgfutil@empty%
		\ifx\pgffor@dots@post\pgfutil@empty%
			\pgffor@contextfalse%
			\def\pgffor@dots@stripcontext##1\pgffor@@stop{\def\pgffor@dotsvalue{##1}}%
		\fi%
	\fi%
	\pgffor@gobblespaces{\pgffor@dotsscanend}%
}

\def\pgffor@dots@value@process#1{%
	\expandafter\pgffor@dots@stripcontext#1\pgffor@@stop%
	\expandafter\pgffor@dots@charcheck\pgffor@dotsvalue\pgffor@@stop%
  \let#1=\pgffor@dotsvalue% 
}

\def\pgffor@dotsscanend#1,{%
	\pgffor@alphabeticsequencefalse%
	% Strip context and check for a character sequence.
	\def\pgffor@dotsend{#1}%
	\pgffor@dots@value@process{\pgffor@dotsend}% 
  %
  \pgffor@dots@value@process{\pgffor@last}%
  %
  % calculate skip%
  \ifx\pgffor@prevlast\pgfutil@empty%
    \ifdim\pgffor@dotsend pt>\pgffor@last pt%
      \pgffor@skip=1pt%
    \else%
      \pgffor@skip=-1pt%
    \fi%
  \else%
  	\pgffor@dots@value@process{\pgffor@prevlast}%
    \pgffor@skip=\pgffor@last pt%
    \pgffor@iter=\pgffor@prevlast pt%
    \advance\pgffor@skip by-\pgffor@iter%
  \fi%
  \pgffor@iter=\pgffor@last pt%
  % do loop
  \pgffor@loop%
}

\def\pgffor@loop{%
  \advance\pgffor@iter by\pgffor@skip%
  \let\pgffor@next=\pgffor@doloop%
  \ifdim\pgffor@skip<0pt%
    \ifdim\pgffor@iter<\pgffor@dotsend pt%
      \let\pgffor@next=\pgffor@endloop%
    \fi%
  \else%
    \ifdim\pgffor@iter>\pgffor@dotsend pt%
      \let\pgffor@next=\pgffor@endloop%
    \fi%
  \fi%
  \ifpgffor@continue%
  \else%
    \let\pgffor@next=\pgffor@endloop% Done!
  \fi%
  \pgffor@next%
}

\def\pgffor@endloop{%
	\pgffor@alphabeticsequencefalse%
	\pgffor@scan%
}

{\catcode`\p=12\catcode`\t=12\gdef\Pgffor@geT#1pt{#1}}

\def\pgffor@doloop{%
  \pgffor@begingroup
    \edef\pgffor@temp{\expandafter\Pgffor@geT\the\pgffor@iter}%
    \edef\pgffor@incheck{{.0/}{\pgffor@temp/}}%
    \expandafter\pgfutil@in@\pgffor@incheck%
    \ifpgfutil@in@%
      \expandafter\pgffor@strip\pgffor@temp%
    \fi%
    \expandafter\pgfutil@in@\expandafter/\expandafter{\pgffor@var}%
    \ifpgfutil@in@%
      \expandafter\def\expandafter\pgffor@valuerest\expandafter{\pgffor@temp//\relax}%
      \expandafter\pgffor@multiassign\pgffor@var/\pgffor@stop/\pgffor@stop/\relax%
    \else%
    	% Convert to alphabetic sequence, if necessary.
    	\ifpgffor@alphabeticsequence%
    		\pgffor@makealphabetic\pgffor@temp%
    		\expandafter\let\pgffor@var=\pgffor@temp%    						
    	\else%
    		\expandafter\expandafter\expandafter\def\expandafter\pgffor@var\expandafter{\pgffor@temp}%
      \fi%
    \fi%
    % Insert any context, if any.
    \ifpgffor@context%
      \let\pgffor@temp=\pgffor@dots@pre%
	    \expandafter\pgfutil@append@macrotomacro\expandafter%
	    	{\expandafter\pgffor@temp\expandafter}\expandafter{\pgffor@var}%
	    \expandafter\pgfutil@append@macrotomacro\expandafter%
	    	{\expandafter\pgffor@temp\expandafter}\expandafter{\pgffor@dots@post}%
	    \expandafter\let\pgffor@var=\pgffor@temp%
	  \fi%
	  % Perform assignments before loop body.
	  \ifx\pgffor@assign@before@code\pgfutil@empty%
    \else%
    	\pgffor@assign@before@code%
    \fi% 
    %  
    \expandafter\pgffor@beginhook\pgffor@body\pgffor@endhook%
    %
    % Perform assignments after loop body.
	  \ifx\pgffor@assign@after@code\pgfutil@empty%
    \else%
    	\pgffor@assign@after@code%
    \fi% 
  \pgffor@endgroup%
  \pgffor@loop%  
}

\def\pgffor@strip#1.0{\def\pgffor@temp{#1}}

\def\breakforeach{\global\pgffor@continuefalse}
  
\def\pgffor@gobbletil@pgffor@@stop#1\pgffor@@stop{}


\newif\ifpgffor@registeriscount

\def\pgffor@ifcsregister#1{%
	\expandafter\pgffor@@ifcsregister\meaning#1\pgffor@stop}

\def\pgffor@@ifcsregister#1#2#3#4#5\pgffor@stop{%
	\if#1m% It is an ordinary (m)acro.
		\pgffor@registeriscountfalse%
		\let\pgffor@csnext=\pgfutil@secondoftwo%
	\else%
		\if#1u% It is (u)ndefined.
			\let\pgffor@csnext=\pgfutil@secondoftwo%
			\pgffor@registeriscountfalse%
		\else%
			\let\pgffor@csnext=\pgfutil@firstoftwo%
			\if#4u% It is a co(u)nt
				\pgffor@registeriscounttrue%
			\else% Assume it is a dimen or skip (bad assumption in the general case).
				\pgffor@registeriscountfalse%
				\let\pgffor@csnext=\pgfutil@firstoftwo%
			\fi%
		\fi%
	\fi%
	\pgffor@csnext}
	
\newif\ifpgffor@alphabeticsequence

% 
\def\pgffor@dots@charcheck#1\pgffor@@stop{%
  \edef\pgffor@dots@charcheck@temp{#1}%
  \expandafter\expandafter\expandafter\pgffor@@dotscharcheck\expandafter\meaning\pgffor@dots@charcheck@temp\pgffor@@stop%
}
\def\pgffor@@dotscharcheck#1#2\pgffor@@stop{%
	\if#1t%
  	\afterassignment\pgffor@gobbletil@pgffor@@stop%	
	  \expandafter\chardef\expandafter\pgffor@char\expandafter=\expandafter`\pgffor@dots@charcheck@temp\relax\pgffor@@stop%
	  \edef\pgffor@char{\the\pgffor@char}%
	  \ifnum\pgffor@char>64\relax% From A-Z?
	    \ifnum\pgffor@char<91\relax%
	      \let\pgffor@dotsvalue=\pgffor@char%
	      \pgffor@alphabeticsequencetrue%		
	    \else%
	      \ifnum\pgffor@char>96\relax% From a-z?
	        \ifnum\pgffor@char<123\relax%
	          \let\pgffor@dotsvalue=\pgffor@char%
	          \pgffor@alphabeticsequencetrue%	
	        \fi%
	      \fi%
	    \fi%
	  \fi%
	\fi%
}

\def\pgffor@makealphabetic#1{%
	% Convert the number in the macro passed as #1 to a-z or A-Z.
	\pgfutil@tempcnta=#1\relax%
	\ifnum\pgfutil@tempcnta>95\relax%
		\advance\pgfutil@tempcnta by-96%
		\expandafter\def\expandafter#1\expandafter%
			{\pgffor@alpha\pgfutil@tempcnta}%   		
	\else%
		\advance\pgfutil@tempcnta by-64%
		\expandafter\def\expandafter#1\expandafter%
			{\pgffor@Alpha\pgfutil@tempcnta}%    						
	\fi%
}

\def\pgffor@Alpha#1{%
	\ifcase#1\or A\or B\or C\or D\or E\or F\or G\or H\or I\or J\or K\or L\or M%
	\or N\or O\or P\or Q\or R\or S\or T\or U\or V\or W\or X\or Y\or Z\else?\fi%
}

\def\pgffor@alpha#1{%
	\ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or l\or m%
	\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z\else?\fi%
}

\newtoks\pgffor@toks

\def\pgffor@addcstotoks#1{%
	\expandafter\def\expandafter\pgffor@tokstemp\expandafter{\expandafter\def\expandafter#1\expandafter{#1}}%
	\pgffor@@addcstotoks}

\def\pgffor@addregtotoks#1{%
	\expandafter\def\expandafter\pgffor@tokstemp\expandafter{\expandafter#1\expandafter=\the#1}%
	\pgffor@@addcstotoks}

\def\pgffor@addiftotoks#1{%
	\begingroup%
		\escapechar=-1\relax%
			\expandafter\pgffor@@addiftotoks\string#1\pgffor@stop}
\def\pgffor@@addiftotoks#1#2#3#4#5\pgffor@stop{%
	\endgroup
	\csname if#4#5\endcsname%
		\expandafter\def\expandafter\pgffor@tokstemp\expandafter{\csname#4#5true\endcsname}%
	\else%
		\expandafter\def\expandafter\pgffor@tokstemp\expandafter{\csname#4#5false\endcsname}%
	\fi%
	\pgffor@@addcstotoks%
}

\def\pgffor@@addcstotoks{%
	\expandafter\expandafter\expandafter\pgffor@toks\expandafter\expandafter\expandafter=%
	\expandafter\expandafter\expandafter{\expandafter\pgffor@tokstemp\the\pgffor@toks}%
}

% Set up the pgffor scopes.

\def\pgffor@atbeginforeach{%
	\begingroup%
}

\def\pgffor@atendforeach{%
		\global\edef\pgffor@remember@expanded{\pgffor@remember@code}%
  \endgroup%
  \ifx\pgffor@remember@expanded\pgfutil@empty%
  \else%
  	\pgffor@remember@expanded%
  	\global\let\pgffor@remember@expanded=\pgfutil@empty%
  \fi%
}
\def\pgffor@default@begingroup{%
	\begingroup%
}

\let\pgffor@remember@once@expanded=\pgfutil@empty
\let\pgffor@remember@expanded=\pgfutil@empty

\def\pgffor@default@endgroup{%
		\ifx\pgffor@assign@once@code\pgfutil@empty%
		\else%
			\global\edef\pgffor@remember@once@expanded{\pgffor@remember@once@code}%
  	\fi%
		\ifx\pgffor@remember@code\pgfutil@empty%
    \else%
			\global\edef\pgffor@remember@expanded{\pgffor@remember@code}%
		\fi%
	\endgroup%
	%
	\ifx\pgffor@remember@once@expanded\pgfutil@empty%
  \else%
  	\pgffor@remember@once@expanded%
  	\let\pgffor@assign@once@code=\pgfutil@empty%
  	\global\let\pgffor@remember@once@expanded=\pgfutil@empty%
  \fi%
  %
	\ifx\pgffor@remember@expanded\pgfutil@empty%
  \else%
  	\pgffor@remember@expanded%
  	\global\let\pgffor@remember@expanded=\pgfutil@empty%
  \fi%
}

\let\pgffor@begingroup=\pgffor@default@begingroup
\let\pgffor@endgroup=\pgffor@default@endgroup

	
\def\pgffor@stack@begingroup{%
	\pgffor@toks={}%
	\pgffor@addcstotoks{\pgffor@mainvar}%
	\pgffor@addcstotoks{\pgffor@var}%
	\pgffor@addcstotoks{\pgffor@body}%
	%
	\pgffor@addcstotoks{\pgffor@last}%
	\pgffor@addcstotoks{\pgffor@prevlast}%
	\pgffor@addcstotoks{\pgffor@dotsend}%
	%
	\pgffor@addcstotoks{\pgffor@assign@before@code}%
	\pgffor@addcstotoks{\pgffor@assign@after@code}%
	\pgffor@addcstotoks{\pgffor@remember@code}%
	\pgffor@addcstotoks{\pgffor@remember@once@code}%
	\pgffor@addcstotoks{\pgffor@dots@pre}%
	\pgffor@addcstotoks{\pgffor@dots@post}%
	%
	\pgffor@addregtotoks{\pgffor@iter}%
	\pgffor@addregtotoks{\pgffor@skip}%
	%
	\pgffor@addiftotoks{\ifpgffor@alphabeticsequence}%
	\pgffor@addiftotoks{\ifpgffor@context}%
	\expandafter\pgffor@stackpush\expandafter{\the\pgffor@toks}%
}

\def\pgffor@stack@endgroup{\pgffor@stackpop}

% Keys stuff.

\newif\ifpgffor@assign@evaluate
\newif\ifpgffor@assign@once

\pgfkeys{/pgf/foreach/.cd,
	var/.code=\pgffor@var@add#1\pgffor@stop,
	scope iterations/.code={
		\csname if#1\endcsname%
			\let\pgffor@begingroup=\pgffor@default@begingroup%
			\let\pgffor@endgroup=\pgffor@default@endgroup%
		\else%
			\let\pgffor@begingroup=\pgffor@stack@begingroup%
			\let\pgffor@endgroup=\pgffor@stack@endgroup%	
		\fi%
	},
	evaluate/.code=\pgffor@assign@evaluatetrue\pgffor@assign@oncefalse\pgffor@assign@parse{#1},%
	assign/.code=\pgffor@assign@evaluatefalse\pgffor@assign@oncefalse\pgffor@assign@parse{#1},%
	evaluate once/.code=\pgffor@assign@evaluatetrue\pgffor@assign@oncetrue\pgffor@assign@parse{#1},%
	assign once/.code=\pgffor@assign@evaluatefalse\pgffor@assign@oncetrue\pgffor@assign@parse{#1},%
	remember/.code=\pgffor@remember@parse{#1},%
	count/.code=\pgffor@count@parse#1\pgffor@stop
}

\def\pgffor@assign@parse#1{%
	\pgfutil@in@;{#1}%
	\ifpgfutil@in@%
	\else%
		\pgfutil@in@={#1}%
	\fi%
	\ifpgfutil@in@%
		\pgffor@assign@@parse#1;\pgffor@stop;%
	\else%
		\pgffor@assign@parse@old#1\pgffor@stop%%
	\fi%
}

\def\pgffor@stop{\pgffor@stop}
\def\pgffor@assign@@parse#1;{%
	\def\pgffor@test{#1}%
	\ifx\pgffor@test\pgffor@stop%
		\let\pgffor@next=\relax%
	\else%
		\let\pgffor@next=\pgffor@assign@@parse%
		\ifx\pgffor@test\pgfutil@empty%
		\else%
			\pgfutil@in@={#1}%
			\ifpgfutil@in@%
				\pgffor@assign@@@parse#1\pgffor@stop%
			\else%
				\pgffor@assign@@@parse#1=#1\pgffor@stop%
			\fi%
		\fi%
	\fi%
	\pgffor@next}
	
\def\pgffor@assign@@@parse#1=#2\pgffor@stop{%
	\ifpgffor@assign@evaluate%
		\ifpgffor@assign@once%
			\pgfutil@append@tomacro{\pgffor@assign@once@code}{\pgfmathparse{#2}\let#1=\pgfmathresult}%
			\pgfutil@append@tomacro{\pgffor@remember@once@code}{\noexpand\def\noexpand#1{#2}}%
		\else
			\pgfutil@append@tomacro{\pgffor@assign@before@code}{\pgfmathparse{#2}\let#1=\pgfmathresult}%
		\fi%
	\else%
		\ifpgffor@assign@once%
			\pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#1{#2}}%
			\pgfutil@append@tomacro{\pgffor@remember@once@code}{\noexpand\def\noexpand#1{#2}}%
		\else
			\pgfutil@append@tomacro{\pgffor@assign@before@code}{\def#1{#2}}%
		\fi%
	\fi%
}

\def\pgffor@assign@parse@old#1#2\pgffor@stop{%
	\pgffor@assign@@parse@old#2\pgffor@stop as#1using #1\pgffor@@stop}

\def\pgffor@assign@@parse@old#1as#2#3\pgffor@@stop{%
	\pgffor@assign@@@parse@old{#2}#1#3\pgffor@stop\pgffor@@stop}

\def\pgffor@assign@@@parse@old#1#2using #3\pgffor@stop#4\pgffor@@stop{%
	\pgffor@assign@@@parse#1=#3\pgffor@stop}
	


\def\pgffor@remember@parse#1{%
	\pgfutil@in@ a{#1}% This matches the 'a' in 'as' or 'intially'.
	\ifpgfutil@in@%
		\pgffor@remember@parse@old#1\pgffor@stop%
	\else%
		\pgffor@remember@@parse#1;\pgffor@stop;%
	\fi%
}

\def\pgffor@remember@@parse#1;{%
	\def\pgffor@test{#1}%
	\ifx\pgffor@test\pgffor@stop%
		\let\pgffor@next=\relax%
	\else%
		\let\pgffor@next=\pgffor@remember@@parse%
		\ifx\pgffor@test\pgfutil@empty%
		\else%
			\pgfutil@in@={#1}%
			\ifpgfutil@in@%
				\pgffor@remember@@@parse#1\pgffor@stop%
			\else%
				\pgffor@ifcsregister{#1}{%
					\pgfutil@append@tomacro{\pgffor@remember@code}{\noexpand#1=\the#1\noexpand\relax}%			
				}%
				{%
					\pgfutil@append@tomacro{\pgffor@remember@code}{\noexpand\def\noexpand#1{#1}}%
				}%
			\fi%
		\fi%
	\fi%
	\pgffor@next%
}

\def\pgffor@remember@@@parse#1=#2\pgffor@stop{%
	\pgffor@ifcsregister{#2}{%
		\pgfutil@append@tomacro{\pgffor@assign@after@code}{\expandafter\def\expandafter#1\expandafter{\the#2}}%
		\pgfutil@append@tomacro{\pgffor@remember@code}{\noexpand\def\noexpand#1{#1}}%			
	}%
	{%
		\pgfutil@append@tomacro{\pgffor@assign@after@code}{\expandafter\def\expandafter#1\expandafter{#2}}%
		\pgfutil@append@tomacro{\pgffor@remember@code}{\noexpand\def\noexpand#1{#1}}%
	}%
}

\def\pgffor@remember@parse@old#1#2\pgffor@stop{%
	\pgffor@remember@@parse@old#1#2\pgffor@stop as#1(initially )\pgffor@@stop}

\def\pgffor@remember@@parse@old#1#2as#3#4\pgffor@@stop{%
	\pgffor@remember@@@parse@old{#1}{#3}#2#4\pgffor@stop\pgffor@@stop}

\def\pgffor@remember@@@parse@old#1#2#3(initially #4)#5\pgffor@stop#6\pgffor@@stop{%
	\pgfutil@append@tomacro{\pgffor@assign@after@code}{\edef#2{#1}}%
	\pgfutil@append@tomacro{\pgffor@remember@code}{\noexpand\def\noexpand#2{#2}}%
	\def\pgffor@test{#4}%
	\ifx\pgffor@test\pgfutil@empty%
	\else%
		\pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#2{#4}}%
	\fi%
}

\def\pgffor@count@parse#1#2\pgffor@stop{%
	\pgffor@count@@parse#1#2\pgffor@stop from 1\pgffor@stop\pgffor@@stop}

\def\pgffor@count@@parse#1#2from#3\pgffor@stop#4\pgffor@@stop{%
	\pgfutil@append@tomacro\pgffor@remember@code{\noexpand\def\noexpand#1{#1}}%
	\pgfutil@append@tomacro\pgffor@assign@before@code{\pgfmathparse{int(#1+1)}\let#1=\pgfmathresult}%
	\pgfmathparse{int(#3-1)}\let#1=\pgfmathresult%
}


\def\pgfutil@append@macrotomacro#1#2{%
	\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
		#1\expandafter\expandafter\expandafter{\expandafter#1#2}}

\def\pgfutil@append@tomacro#1#2{%
	\expandafter\def\expandafter#1\expandafter{#1#2}}
	

\endinput

pgfkeys.code.tex
% Copyright 2007 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.


% The files pgfkeys.code.tex and pgfkeysfiltered.code.tex are
% perfectly self-contained, except that the catcode of @ 
% should be made a letter. 


% Guard against reading twice
\ifx\pgfkeysloaded\undefined
  \let\pgfkeysloaded=\relax
\else
  \expandafter\endinput
\fi
  
% The purpose of this file is to provide a general settings engine that 
% works with all TeX formats and has no save-stack impact


% This is useful:

\def\pgfkeys@ifcsname#1\endcsname#2\else#3\fi{\expandafter\ifx\csname#1\endcsname\relax#3\else#2\fi}%
\ifx\eTeXrevision\undefined%
\else%
  \expandafter\let\expandafter\pgfkeys@ifcsname\csname ifcsname\endcsname%
\fi

\def\pgfkeys@empty{}

% This also:

\ifx\PackageError\undefined
  \def\pgfkeys@error#1{\immediate\write-1{Package pgfkeys: Error! #1.}}%
\else
  \def\pgfkeys@error#1{\PackageError{pgfkeys}{#1}{}}%
\fi

% Set a key to a value
%
% #1 = key
% #2 = tokens
%
% Description:
%
% This command sets the key to the given tokens. The tokens are stored as
% is and can even contain things like #9. 
%
% Keys are organized hierarchically using something similar to Unix
% paths. Thus, a typically key might be called "/tikz/length" or
% "/tikz/length dimension/.@cmd". Some keys starting with a dot are
% special, so they should not be used as normal key names (they are
% similar to Unix files starting with a dot -- you can use them, but
% be careful).
%
% Keys are always local to the current TeX group.
%
% Example:
%
% \pgfkeyssetvalue{/tikz/length}{2cm-3cm}
% \pgfkeyssetvalue{/algo/swap}{{#2}{#1}}

\long\def\pgfkeyssetvalue#1#2{%
  \pgfkeys@temptoks{#2}\expandafter\edef\csname pgfk@#1\endcsname{\the\pgfkeys@temptoks}%
}



% Add text to a key at the end
%
% #1 = key
% #2 = a value to be added at the beginning
% #3 = a value to be added at the end
%
% Description:
%
% This command adds #2 to the definition of the key. The key should
% have been set previously using \pgfkeyssetvalue.
%
% Example:
%
% \pgfkeysaddvalue{/tikz/length}{}{-3cm}

\long\def\pgfkeysaddvalue#1#2#3{%
  {%
    \toks0{#2}%
    \pgfkeysifdefined{#1}
    {\pgfkeys@temptoks\expandafter\expandafter\expandafter{\csname pgfk@#1\endcsname}}%
    {\pgfkeys@temptoks{}}%
    \toks1{#3}%
    \xdef\pgfkeys@global@temp{\the\toks0 \the\pgfkeys@temptoks \the\toks1}% believe or don't: the spaces are important
  }%
  \pgfkeyslet{#1}\pgfkeys@global@temp%
}



% Makes a key equal a given code
%
% #1 = key
% #2 = a code name
%
% Description:
%
% This command executes a \let command so that a key gets the same
% value as the parameter #2.
%
% Keys are always local to the current TeX group.
%
% Example:
%
% \pgfkeyslet{/algo/swap}{\myswap}

\def\pgfkeyslet#1#2{%
  \expandafter\let\csname pgfk@#1\endcsname#2%
}


% Retrieve the code stored in a key into a code
%
% #1 = key
% #2 = code
%
% Description:
%
% This command will set #2 to "point" to the value stored in the key.
%
% Example:
%
% \pgfkeysgetvalue{/tikz/swap}{\myswap}

\def\pgfkeysgetvalue#1#2{\expandafter\let\expandafter#2\csname pgfk@#1\endcsname}



% Retrieve the value stored in a key
%
% #1 = key
%
% Description:
%
% This command will expand to the value stored in the key. The key
% should previously have been set using \pgfkeyasetkey or \pgfkeyslet. 
%
% Example:
%
% The length is \pgfkeysvalue{/tikz/length}.

\def\pgfkeysvalueof#1{\csname pgfk@#1\endcsname}



% If for testing whether a key exists
%
% #1 = key
% #2 = if-case
% #3 = else-case
%
% Description:
%
% This if will be executed if the key exists. In eTeX mode this works
% like a normal if, in normal TeX mode you need to provide an \else.
%
% Example:
%
% \pgfkeysifdefined{/tikz/length}{key exists}{does not exist}

\long\def\pgfkeysifdefined#1#2#3{\pgfkeys@ifcsname pgfk@#1\endcsname#2\else#3\fi}

% Tests whether a key is assignable. For standard keys which just
% store their value, this is identical to \pgfkeysifdefined.
%
% But \pgfkeysifassignable is true for command keys as well (but not
% for handled keys).
\long\def\pgfkeysifassignable#1#2#3{%
  \pgfkeysifdefined{#1}%
  	{#2}
	{\pgfkeysifdefined{#1/.@cmd}%
	  {#2}%
	  {#3}}%
}%



% Execute settings
%
% #1 = list of settings
%
% Description:
%
% The list of settings should contain comma-separated settings. Each
% setting has the following form:
%
% /path/key=value
%
% The parts "/path/" and "=value" are optional. When the path is not
% specified, the value of the token register "\pgfkeypath" is used. If
% "=value" is missing, the value of the setting "/path/key/.@def" is used
% instead. If this key is set to "\pgfvaluerequired", the key
% "/errors/value required/.@cmd" is executed. Theis error handler,
% like all other error handlers, will get the current key as its first
% parameter (unexpanded) and the current value as its second value
% (also unexpanded).
%
% Any spaces at the beginning and at the end and around the
% equals-sign are removed. The key with the complete path is set to
% the code \pgfcurrentkey.
%
% The setting is then processed according to the following rules:
%
% 1) If the key /path/key/.@cmd" is present, its code is executed
%    with the value computed above, followed by \pgfeov (end of
%    value). So, to handle
%
%    "/stuff/height=  1.5 ,"
%
%    /stuff/height/.@cmd should be set to some code, that can
%    handle the parameter
%
%    "1.5\pgfeov"
%
%    For instance, saying
%
%    \pgfkeys{/stuff/height/.@cmd}{#1\pgfeov}{\def\myheight{#1}}
%
%    will do nicely.
%
% 2) Otherwise, if the key /path/key is present, this key is
%    set to the value computed above.
%
% 3) Otherwise, if the key /handlers/key/.@cmd is present, it is executed
%    with the same parameters as in 1). Additionally, the
%    token register \pgfcurrentkeypath will be set to "/path/" and the
%    macor \pgfcurrentkeywithoutpath to "key". So, in the above
%    example if neither "/stuff/height/.@cmd" nor
%    "/stuff/height" is present, but "/handlers/height" is,
%    then "/handlers/height" is executed with the parameters:
%
%    "1.5\pgfeov"
%
%    and \pgfcurrentkey is set to "/stuff/height" and \pgfcurrentkeypath
%    is set to "/stuff/" and \pgfcurrentkeywithoutpath to "height".
%
% 4) Otherwise, if the key "/path/.unknown/.@cmd" is present, its code is
%    executed with the same parameters as in 3).
%
% 5) Otherwise, the key "/handlers/.unknown/.@cmd" is executed with the same
%    parameters as in 1).
%
% After all settings have been processed, the value of the token
% register \pgfdefaultkeypath is set to its original value. Thus, any local
% change of this token register has no effect outside the call.
%
% Example:
%
% \pgfkeys{/tikz/.is family}
% \pgfkeys{/tikz/line width/.cd,
%         .def=\pgfsetlinewidth{##1},
%         .set default=.4pt}
% \pgfkeys{tikz,line width=1pt}

\newtoks\pgfkeys@pathtoks
\def\pgfkeyscurrentpath{\the\pgfkeys@pathtoks}
\newtoks\pgfkeys@temptoks

\def\pgfkeys@root{/}
\let\pgfkeysdefaultpath\pgfkeys@root

\def\pgfkeys{\expandafter\pgfkeys@@set\expandafter{\pgfkeysdefaultpath}}%
\long\def\pgfkeys@@set#1#2{%
  \let\pgfkeysdefaultpath\pgfkeys@root%
  \pgfkeys@parse#2,\pgfkeys@mainstop%
  \def\pgfkeysdefaultpath{#1}}

\def\pgfkeys@parse{\futurelet\pgfkeys@possiblerelax\pgfkeys@parse@main}
\def\pgfkeys@parse@main{%
  \ifx\pgfkeys@possiblerelax\pgfkeys@mainstop%
    \expandafter\pgfkeys@cleanup%
  \else%
    \expandafter\pgfkeys@normal%
  \fi%
}
\long\def\pgfkeys@normal#1,{%
  \pgfkeys@unpack#1=\pgfkeysnovalue=\pgfkeys@stop%
  \pgfkeys@parse%
}
\def\pgfkeys@cleanup\pgfkeys@mainstop{}

\def\pgfkeys@mainstop{\pgfkeys@mainstop} % equals only itself
\def\pgfkeys@novalue{} % equals only itself
\def\pgfkeysnovalue{\pgfkeys@novalue} % equals only itself
\def\pgfkeysnovalue@text{\pgfkeysnovalue}
\def\pgfkeysvaluerequired{\pgfkeysvaluerequired} % equals only itself

\long\def\pgfkeys@unpack#1=#2=#3\pgfkeys@stop{%
  \pgfkeys@spdef\pgfkeyscurrentkey{#1}%
  \edef\pgfkeyscurrentkey{\pgfkeyscurrentkey}%
  \ifx\pgfkeyscurrentkey\pgfkeys@empty%
    % Skip
  \else%
    \pgfkeys@add@path@as@needed%
    \pgfkeys@spdef\pgfkeyscurrentvalue{#2}%
    \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text% Hmm... no value
      \pgfkeysifdefined{\pgfkeyscurrentkey/.@def}%
      {\pgfkeysgetvalue{\pgfkeyscurrentkey/.@def}{\pgfkeyscurrentvalue}}
      {}% no default, so leave it
    \fi%
    \ifx\pgfkeyscurrentvalue\pgfkeysvaluerequired%
      \pgfkeysvalueof{/errors/value required/.@cmd}\pgfkeyscurrentkey\pgfkeyscurrentvalue\pgfeov%
    \else%
      \pgfkeys@case@one%
    \fi%
  \fi}

\def\pgfkeys@case@one{%
  \pgfkeysifdefined{\pgfkeyscurrentkey/.@cmd}%
  {\pgfkeysgetvalue{\pgfkeyscurrentkey/.@cmd}{\pgfkeys@code}%
   \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov}
  {\pgfkeys@case@two}%
}

\def\pgfkeys@case@two{%
  \pgfkeysifdefined{\pgfkeyscurrentkey}%
  {\pgfkeys@case@two@extern}%
  {\pgfkeys@case@three}%
}

\def\pgfkeys@case@two@extern{%
  \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text%
    \pgfkeysvalueof{\pgfkeyscurrentkey}%
  \else%
    \pgfkeyslet{\pgfkeyscurrentkey}\pgfkeyscurrentvalue%
  \fi%
}


% either handled key or unknown.
%
% This macro will be replaced by the /handler config/handle only existing
% configuration, see below.
\def\pgfkeys@case@three{%
  \pgfkeys@split@path%
  \pgfkeysifdefined{/handlers/\pgfkeyscurrentname/.@cmd}%
  {\pgfkeysgetvalue{/handlers/\pgfkeyscurrentname/.@cmd}{\pgfkeys@code}%
    \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov}
  {\pgfkeys@unknown}%
}
\let\pgfkeys@case@three@handleall=\pgfkeys@case@three
\def\pgfkeys@case@three@handle@restricted{%
  \pgfkeys@split@path%
  \pgfkeysifdefined{/handlers/\pgfkeyscurrentname/.@cmd}{%
    \pgfkeys@ifexecutehandler{%
	  \pgfkeysgetvalue{/handlers/\pgfkeyscurrentname/.@cmd}{\pgfkeys@code}%
      \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov
	}{%
      % this here is necessary:  /my search path/key/.code
      % won't be called, so \pgfkeyscurrentpath == '/my search path/key'
      % -> it should be one directory higher! We want to invoke the
	  %  .unknown handler in
	  % '/my search path'
	  %
	  % Idea:
	  % set 
	  % - path := '/my search path'
	  % - name := 'key/.code'
	  % - key = '/my search path/key/.code'
	  \let\pgfkeys@temp=\pgfkeyscurrentkey
	  \let\pgfkeys@tempb=\pgfkeyscurrentname
      \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}%
      \pgfkeys@split@path%
	  \let\pgfkeyscurrentkey=\pgfkeys@temp
	  \edef\pgfkeyscurrentname{\pgfkeyscurrentname/\pgfkeys@tempb}%
  	  \pgfkeys@unknown
	}%
  }{%
  	\pgfkeys@unknown
  }%
}

% this macro is to implement the |handly only existing| key in key filtering:
% #1: the code to invoke IF the key handler shall be executed
% #2: the code to invoke if it shall not run.
\def\pgfkeys@ifexecutehandler#1#2{#1}%
\let\pgfkeys@ifexecutehandler@handleall=\pgfkeys@ifexecutehandler
\def\pgfkeys@ifexecutehandler@handleonlyexisting#1#2{%
  \pgfkeys@ifcsname pgfk@excpt@\pgfkeyscurrentname\endcsname%
     #1% ok, this particular key handler is known and should be processed in any case (for example .try)
  \else
     % implement the 'only existing' feature here:
     \pgfkeysifdefined{\pgfkeyscurrentpath}{#1}{%
		\pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}{#1}{#2}%
     }{}%
  \fi%
}%
\def\pgfkeys@ifexecutehandler@handlefullorexisting#1#2{%
  \ifpgfkeysaddeddefaultpath
    \pgfkeys@ifcsname pgfk@excpt@\pgfkeyscurrentname\endcsname%
%\message{ifexecutehandler(\pgfkeyscurrentkeyRAW, path \pgfkeysdefaultpath): '\pgfkeyscurrentname' is an exception; processing it (on \pgfkeyscurrentpath).}%
       #1% ok, this particular key handler is known and be processed in any case (for example .try)
    \else
       % implement the 'only existing' feature here:
       \pgfkeysifdefined{\pgfkeyscurrentpath}{%
%\message{ifexecutehandler(\pgfkeyscurrentkeyRAW, path \pgfkeysdefaultpath): '\pgfkeyscurrentpath' does exist. Executing '\pgfkeyscurrentname'.}%
          #1%
		}{%
			\pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}{%
%\message{ifexecutehandler(\pgfkeyscurrentkeyRAW, path \pgfkeysdefaultpath): '\pgfkeyscurrentpath/.@cmd' does exist. Executing '\pgfkeyscurrentname'.}%
               #1%
            }{%
%\message{ifexecutehandler(\pgfkeyscurrentkeyRAW, path \pgfkeysdefaultpath): '\pgfkeyscurrentpath' does NOT exist. Skipping '\pgfkeyscurrentname'.}%
               #2%
            }%
        }%
    \fi%
  \else
%\message{ifexecutehandler(\pgfkeyscurrentkeyRAW, path \pgfkeysdefaultpath): Fully qualified key provided. Executing '\pgfkeyscurrentname'.}%
    #1% ok, always true if the USER explicitly provided the full key path.
  \fi
}%
\def\pgfkeysaddhandlyonlyexistingexception#1{\expandafter\def\csname pgfk@excpt@#1\endcsname{1}}%


\def\pgfkeys@unknown{%
  \pgfkeysifdefined{\pgfkeyscurrentpath/.unknown/.@cmd}%
  {%
    \pgfkeysgetvalue{\pgfkeyscurrentpath/.unknown/.@cmd}{\pgfkeys@code}%
    \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov}
  {%
    \pgfkeysgetvalue{/handlers/.unknown/.@cmd}{\pgfkeys@code}%
    \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov%
  }%
}


\long\def\pgfkey@argumentisspace#1{%
  \long\def\pgfkeys@spdef##1##2{%
    \futurelet\pgfkeys@possiblespace\pgfkeys@sp@a##2\pgfkeys@stop\pgfkeys@stop#1\pgfkeys@stop\relax##1}%
  \def\pgfkeys@sp@a{%
    \ifx\pgfkeys@possiblespace\pgfkeys@sptoken%
      \expandafter\pgfkeys@sp@b%
    \else%
      \expandafter\pgfkeys@sp@b\expandafter#1%
    \fi}%
  \long\def\pgfkeys@sp@b#1##1 \pgfkeys@stop{\pgfkeys@sp@c##1}%
}
\pgfkey@argumentisspace{ }
\long\def\pgfkeys@sp@c#1\pgfkeys@stop#2\relax#3{\pgfkeys@temptoks{#1}\edef#3{\the\pgfkeys@temptoks}}
{\def\:{\global\let\pgfkeys@sptoken= } \: }



\def\pgfkeys@add@path@as@needed{% Should add the path if the
  % \pgfkeyscurrentkey does not start with /
  \expandafter\futurelet\expandafter\pgfkeys@possibleslash\expandafter\pgfkeys@check@slash\pgfkeyscurrentkey\relax%
}
\newif\ifpgfkeysaddeddefaultpath
\def\pgfkeys@check@slash{%
  \ifx\pgfkeys@possibleslash/%
    \expandafter\pgfkeys@nevermind%
  \else%
    \expandafter\pgfkeys@addpath%
  \fi%
}

\def\pgfkeys@nevermind#1\relax{%
  \pgfkeysaddeddefaultpathfalse
  \let\pgfkeyscurrentkeyRAW\pgfkeyscurrentkey
}
\def\pgfkeys@addpath#1\relax{%
  \pgfkeysaddeddefaultpathtrue
  \def\pgfkeyscurrentkeyRAW{#1}%
  \edef\pgfkeyscurrentkey{\pgfkeysdefaultpath#1}%
}


\def\pgfkeys@split@path{% Should assign the two codes
                       % \pgfkeyscurrentname and \pgfcurrentlkeypath
  \pgfkeys@pathtoks{}%
  \expandafter\pgfkeys@splitter\pgfkeyscurrentkey//%
}
\def\pgfkeys@splitter#1/#2/{%
  \def\pgfkeys@temp{#2}%
  \ifx\pgfkeys@temp\pgfkeys@empty%
    % Ah. done
    \def\pgfkeyscurrentname{#1}%
    \expandafter\pgfkeys@gobbletoslash%
  \else%
    \expandafter\pgfkeys@pathtoks\expandafter{\the\pgfkeys@pathtoks#1/}%
  \fi%
  \pgfkeys@splitter#2/%
}
\def\pgfkeys@gobbletoslash\pgfkeys@splitter/{\expandafter\pgfkeys@remove@slash\the\pgfkeys@pathtoks\relax}%
\def\pgfkeys@remove@slash#1/\relax{\pgfkeys@pathtoks{#1}}



% Quickly set keys
%
% #1 = default path
% #2 = key-value pairs
%
% Desscription:
%
% This command starts the execution with the default path set to
% #1. This command should only be used when speed is important (like
% in a heavily used macro like \tikzset). Normally, keys should be
% used to set the path. Note that if #1 equals /, then \pgfkeys will
% actually be quicker!
%
% Example:
%
% \pgfqkeys{/tikz}{myother length/.code=\def\myotherlength{#1}\pgfkeysalso{length=#1}}

\def\pgfqkeys{\expandafter\pgfkeys@@qset\expandafter{\pgfkeysdefaultpath}}%
\long\def\pgfkeys@@qset#1#2#3{\def\pgfkeysdefaultpath{#2/}\pgfkeys@parse#3,\pgfkeys@mainstop\def\pgfkeysdefaultpath{#1}}


% Sets keys while setting keys
%
% #1 = key-value pairs
%
% Desscription:
%
% This code may only be called inside the code that is executed for a
% key. The #1 should be a list of settings pairs. They will be executed
% as if they had been given as the argument to the \pgfkeys command.
%
% Example:
%
% \pgfkeys{tikz,myother length/.code=\def\myotherlength{#1}\pgfkeysalso{length=#1}}

\long\def\pgfkeysalso#1{\pgfkeys@parse#1,\pgfkeys@mainstop}



% Quickly sets keys while setting keys
%
% #1 = default path
% #2 = key-value pairs
%
% Desscription:
%
% This command executes #2 with the default path set to #1. This
% command will cause chaos if used incorrectly. The only safe
% place to use it instead of \pgfkeys is at the beginning of a TeX group.
%
% Example:
%
% \begingroup
%   \pgfqkeysalso{/tikz}{myother length/.code=\def\myotherlength{#1}\pgfkeysalso{length=#1}}

\long\def\pgfqkeysalso#1#2{\def\pgfkeysdefaultpath{#1/}\pgfkeys@parse#2,\pgfkeys@mainstop}




% Now setup the default handelers and keys:

% Define a key macro with one argument (\def or \edef)
%
% #1 = key
% #2 = code
%
% Description:
%
% This command will setup things so the key/.@cmd contains a macro
% that takes one parameter and has #2 as its code.
%
% Example:
%
% \pgfkeysdef{/my key}{\show#1}

\long\def\pgfkeysdef#1#2{%
  \long\def\pgfkeys@temp##1\pgfeov{#2}%
  \pgfkeyslet{#1/.@cmd}{\pgfkeys@temp}%
}
\long\def\pgfkeysedef#1#2{%
  \long\edef\pgfkeys@temp##1\pgfeov{#2}%
  \pgfkeyslet{#1/.@cmd}{\pgfkeys@temp}%
}


% Define a key macro with mutliple arguments (\def or \edef)
%
% #1 = key
% #2 = argument pattern
% #2 = code
%
% Description:
%
% This command will setup things so the key/.@cmd contains a macro
% that takes #2 as its parameter pattern and has #3 as its code.
%
% Example:
%
% \pgfkeysdefargs{/swap}{#1#2}{#2#1}

\long\def\pgfkeysdefargs#1#2#3{%
  \long\def\pgfkeys@temp#2\pgfeov{#3}%
  \pgfkeyslet{#1/.@cmd}{\pgfkeys@temp}%
  \pgfkeyssetvalue{#1/.@args}{#2\pgfeov}%
  \pgfkeyssetvalue{#1/.@body}{#3}%
}
\long\def\pgfkeysedefargs#1#2#3{%
  \long\edef\pgfkeys@temp#2\pgfeov{#3}%
  \pgfkeyslet{#1/.@cmd}{\pgfkeys@temp}%
  \pgfkeyssetvalue{#1/.@args}{#2\pgfeov}%
  \pgfkeyssetvalue{#1/.@body}{#3}%
}

% Like \pgfkeysdefargs, but `#2' is an integer denoting the expected
% *number* of arguments.
%
% There is a subtle difference between the 'args' command, when it
% comes to spaces:
%  a key defined with defargs{#1#2} must not have spaces between the
%  arguments when it is used.
%
% See this:
%
%--------------------------------------------------
% % defnargs:
% \pgfkeysdefnargs{/a}{2}{1=`#1', 2=`#2'}
% \pgfkeys{
% 	/a=
% 		{1}
% 		{2}
% }
% ->defnargs: 1=`1', 2=`2'
% 
% defargs:
% \pgfkeysdefargs{/b}{#1#2}{1=`#1', 2=`#2'}
% \pgfkeys{
% 	/b=
% 		{1}
% 		{2}
% }
% ->defargs: 1=`1', 2=` 2'  (note the space!)
%
% defargs:
% \pgfkeysdefargs{/b}{#1#2}{1=`#1', 2=`#2'}
% \pgfkeys{
% 	/b=
% 		{1}% 
% 		{2}
% }
% ->defargs: 1=`1', 2=`2'
%-------------------------------------------------- 
\long\def\pgfkeysdefnargs#1#2#3{\pgfkeysdefnargs@{#1}{#2}{#3}{\def}}%
\long\def\pgfkeysedefnargs#1#2#3{\pgfkeysdefnargs@{#1}{#2}{#3}{\edef}}%
\long\def\pgfkeysdefnargs@#1#2#3#4{%
  \ifcase#2\relax
	  \pgfkeyssetvalue{#1/.@args}{}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8##9}%
  \else
	  \pgfkeys@error{\string\pgfkeysdefnargs: expected  <= 9 arguments, got #2}%
  \fi
  \pgfkeysgetvalue{#1/.@args}\pgfkeys@tempargs
  \def\pgfkeys@temp{\expandafter#4\csname pgfk@#1/.@@body\endcsname}%
  \expandafter\pgfkeys@temp\pgfkeys@tempargs{#3}%
  % eliminate the \pgfeov at the end such that TeX gobbles spaces
  % by using
  % \pgfkeysdef{#1}{\pgfkeysvalueof{#1/.@@body}##1}
  % (with expansion of '#1'):
  \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
  \def\pgfkeys@temp{\pgfkeysdef{#1}}%
  \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
  \pgfkeyssetvalue{#1/.@body}{#3}%
}



% Defining a key command

\pgfkeysdef{/handlers/.code}{\pgfkeysdef{\pgfkeyscurrentpath}{#1}}
\pgfkeysdef{/handlers/.code 2 args}{\pgfkeysdefargs{\pgfkeyscurrentpath}{##1##2}{#1}}
\pgfkeysdef{/handlers/.ecode}{\pgfkeysedef{\pgfkeyscurrentpath}{#1}}
\pgfkeysdef{/handlers/.ecode 2 args}{\pgfkeysedefargs{\pgfkeyscurrentpath}{##1##2}{#1}}
\pgfkeysdefnargs{/handlers/.code args}{2}{\pgfkeysdefargs{\pgfkeyscurrentpath}{#1}{#2}}
\pgfkeysdefnargs{/handlers/.ecode args}{2}{\pgfkeysedefargs{\pgfkeyscurrentpath}{#1}{#2}}
\pgfkeysdefnargs{/handlers/.code n args}{2}{\pgfkeysdefnargs{\pgfkeyscurrentpath}{#1}{#2}}
\pgfkeysdefnargs{/handlers/.ecode n args}{2}{\pgfkeysedefnargs{\pgfkeyscurrentpath}{#1}{#2}}

% Adding to a key command

\pgfkeys{/handlers/.add code/.code 2 args=%
  % Find out, whether with args or not.
  \pgfkeysifdefined{\pgfkeyscurrentpath/.@args}%
  {% Yes, so add to body and reuse args
	\pgfkeysaddvalue{\pgfkeyscurrentpath/.@body}{#1}{#2}%
	% Redefine code
	{%
	  \pgfkeysgetvalue{\pgfkeyscurrentpath/.@args}{\pgfkeys@tempargs}%
	  \pgfkeysgetvalue{\pgfkeyscurrentpath/.@body}{\pgfkeys@tempbody}%
	  \def\pgfkeys@marshal{\expandafter\gdef\expandafter\pgfkeys@global@temp\pgfkeys@tempargs}%
	  \expandafter\pgfkeys@marshal\expandafter{\pgfkeys@tempbody}%
	}%
    \pgfkeysifdefined{\pgfkeyscurrentpath/.@@body}{%
	  % support for \pgfkeysndefargs:
	  \pgfkeyslet{\pgfkeyscurrentpath/.@@body}{\pgfkeys@global@temp}%
	}{%
	  % support for \pgfkeysdefargs:
      \pgfkeyslet{\pgfkeyscurrentpath/.@cmd}{\pgfkeys@global@temp}%
	}%
  }%
  {%
    % No, so single argument (simple \pgfkeysdef). Redefine accordingly.
    {%
      \toks0{#1}%
      \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}%
      {\pgfkeys@temptoks\expandafter\expandafter\expandafter{\csname pgfk@\pgfkeyscurrentpath/.@cmd\endcsname##1\pgfeov}}%
      {\pgfkeys@temptoks{}}%
      \toks1{#2}%
      \xdef\pgfkeys@global@temp{\the\toks0 \the\pgfkeys@temptoks \the\toks1 }%
    }%
    \expandafter\def\expandafter\pgfkeys@temp\expandafter##\expandafter1\expandafter\pgfeov\expandafter{\pgfkeys@global@temp}%
    \pgfkeyslet{\pgfkeyscurrentpath/.@cmd}\pgfkeys@temp%
  }%
}
\pgfkeys{/handlers/.prefix code/.code=\pgfkeys{\pgfkeyscurrentpath/.add code={#1}{}}}%
\pgfkeys{/handlers/.append code/.code=\pgfkeys{\pgfkeyscurrentpath/.add code={}{#1}}}%


% Defining a style

\pgfkeys{/handlers/.style/.code=\pgfkeys{\pgfkeyscurrentpath/.code=\pgfkeysalso{#1}}}
\pgfkeys{/handlers/.estyle/.code=\pgfkeys{\pgfkeyscurrentpath/.ecode=\noexpand\pgfkeysalso{#1}}}
\pgfkeys{/handlers/.style args/.code 2 args=\pgfkeys{\pgfkeyscurrentpath/.code args={#1}{\pgfkeysalso{#2}}}}
\pgfkeys{/handlers/.estyle args/.code 2 args=\pgfkeys{\pgfkeyscurrentpath/.ecode args={#1}{\noexpand\pgfkeysalso{#2}}}}
\pgfkeys{/handlers/.style 2 args/.code=\pgfkeys{\pgfkeyscurrentpath/.code 2 args=\pgfkeysalso{#1}}}
\pgfkeys{/handlers/.style n args/.code 2 args=\pgfkeys{\pgfkeyscurrentpath/.code n args={#1}{\pgfkeysalso{#2}}}}

% Adding to a style

\pgfkeys{/handlers/.add style/.code 2 args=\pgfkeys{\pgfkeyscurrentpath/.add code={\pgfkeysalso{#1}}{\pgfkeysalso{#2}}}}%
\pgfkeys{/handlers/.prefix style/.code=\pgfkeys{\pgfkeyscurrentpath/.add code={\pgfkeysalso{#1}}{}}}%
\pgfkeys{/handlers/.append style/.code=\pgfkeys{\pgfkeyscurrentpath/.add code={}{\pgfkeysalso{#1}}}}%


% Defining a value

\pgfkeys{/handlers/.initial/.code=\pgfkeyssetvalue{\pgfkeyscurrentpath}{#1}}
\pgfkeys{/handlers/.add/.code 2 args=\pgfkeysaddvalue{\pgfkeyscurrentpath}{#1}{#2}}
\pgfkeys{/handlers/.prefix/.code=\pgfkeysaddvalue{\pgfkeyscurrentpath}{#1}{}}
\pgfkeys{/handlers/.append/.code=\pgfkeysaddvalue{\pgfkeyscurrentpath}{}{#1}}
\pgfkeys{/handlers/.get/.code=\pgfkeysgetvalue{\pgfkeyscurrentpath}{#1}}
\pgfkeys{/handlers/.link/.code=\pgfkeyssetvalue{\pgfkeyscurrentpath}{\pgfkeysvalueof{#1}}}


% Defining a default

\pgfkeys{/handlers/.default/.code=\pgfkeyssetvalue{\pgfkeyscurrentpath/.@def}{#1}}
\pgfkeys{/handlers/.value required/.code=\pgfkeyssetvalue{\pgfkeyscurrentpath/.@def}{\pgfkeysvaluerequired}}
\pgfkeys{/handlers/.value forbidden/.code=\pgfkeys{\pgfkeyscurrentpath/.add code=%
{%
  \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text%
  \else%
    \pgfkeysvalueof{/errors/value forbidden/.@cmd}\pgfkeyscurrentkey\pgfkeyscurrentvalue\pgfeov%
  \fi%
}{}}}


% High-level cmds

\pgfkeys{/handlers/.store in/.code=\pgfkeysalso{\pgfkeyscurrentpath/.code=\def#1{##1}}}
\pgfkeys{/handlers/.estore in/.code=\pgfkeysalso{\pgfkeyscurrentpath/.code=\edef#1{##1}}}

\pgfkeys{/handlers/.is if/.code=\pgfkeysalso{%
    \pgfkeyscurrentpath/.code=\pgfkeys@handle@boolean{#1}{##1},
    \pgfkeyscurrentpath/.default=true%
  }%
}
\def\pgfkeys@handle@boolean#1#2{%
  \pgfkeys@ifcsname#1#2\endcsname%
    \csname#1#2\endcsname%
  \else%
    \pgfkeysvalueof{/errors/boolean expected/.@cmd}\pgfkeyscurrentkey{#2}\pgfeov%
  \fi
}

\pgfkeys{/handlers/.is choice/.code=%
  \pgfkeys{%
    \pgfkeyscurrentpath/.cd,%
    .code=\expandafter\pgfkeysalso\expandafter{\pgfkeyscurrentkey/##1},
    .unknown/.style={/errors/unknown choice value=\pgfkeyscurrentkey\pgfkeyscurrentvalue}}}


% Repeatedly setting a key

\pgfkeys{/handlers/.list/.code=%
  {%
    % Use foreach to unfold the list
    \let\pgf@keys@temp=\pgfutil@empty%
    \foreach \pgf@keys@key in{#1}%
    {\expandafter\expandafter\expandafter\gdef%
      \expandafter\expandafter\expandafter\pgf@keys@temp%
      \expandafter\expandafter\expandafter{\expandafter\pgf@keys@temp\expandafter{\pgf@keys@key}}}%
    \edef\pgf@keys@list@path{\pgfkeyscurrentpath}%
    \expandafter\expandafter\expandafter\pgf@keys@do@list%
    \expandafter\expandafter\expandafter{\expandafter\pgf@keys@list@path\expandafter}\pgf@keys@temp\pgf@stop%
  }% 
}
\def\pgf@keys@do@list#1{\pgfutil@ifnextchar\bgroup{\pgf@keys@do@list@item{#1}}\pgfutil@gobble}
\def\pgf@keys@do@list@item#1#2{\pgfkeysalso{#1={#2}}\pgf@keys@do@list{#1}}



% Inspection handlers

\pgfkeys{/handlers/.show value/.code=\pgfkeysgetvalue{\pgfkeyscurrentpath}{\pgfkeysshower}\show\pgfkeysshower} % inspect the value 
\pgfkeys{/handlers/.show code/.code=\pgfkeysgetvalue{\pgfkeyscurrentpath/.@cmd}{\pgfkeysshower}\show\pgfkeysshower} % inspect the body of the command


% Path handling

% Prepares the .unknown handler used by '.search also'.
% It will be stored into \pgfkeys@global@temp.
\def\pgfkeys@searchalso@prepare@unknown@handler#1{%
  \global\def\pgfkeys@global@temp##1\pgfeov{}%
  \pgfkeys@searchalso@parse#1,\pgfkeys@mainstop
  {%
  	\toks0=\expandafter{\pgfkeys@global@temp##1\pgfeov}%
	\toks1={\def\pgfutilnext{\pgfkeysvalueof{/handlers/.unknown/.@cmd}##1\pgfeov}\pgfutilnext}%
	\xdef\pgfkeys@global@temp{%
		\noexpand\ifpgfkeysaddeddefaultpath
			\noexpand\pgfkeyssuccessfalse
			\noexpand\let\noexpand\pgfkeys@searchalso@name=\noexpand\pgfkeyscurrentkeyRAW
			\the\toks0 % one or more /.try things; one for each path. The last element won't have a /.try
			%\noexpand\ifpgfkeyssuccess
			%\noexpand\else
			%	\the\toks1 % invoke /handlers/.unknown handler
			%\noexpand\fi
		\noexpand\else
			\the\toks1 % invoke /handlers/.unknown handler
		\noexpand\fi
	}%
	\expandafter\gdef\expandafter\pgfkeys@global@temp\expandafter##\expandafter1\expandafter\pgfeov\expandafter{\pgfkeys@global@temp}%
  }%
}%

\def\pgfkeys@searchalso@parse{\futurelet\pgfkeys@possiblerelax\pgfkeys@searchalso@parse@main}
\def\pgfkeys@searchalso@parse@main{%
  \ifx\pgfkeys@possiblerelax\pgfkeys@mainstop%
    \expandafter\pgfkeys@cleanup%
  \else%
    \expandafter\pgfkeys@searchalso@appendentry%
  \fi%
}
\def\pgfkeys@searchalso@appendentry#1,#2{%
  \def\pgfkeys@searchalso@nexttok{#2}%
  \pgfkeys@spdef\pgfkeys@temp{#1}%
  {%
    \toks0=\expandafter{\pgfkeys@global@temp##1\pgfeov}%
	\toks1=\expandafter{\pgfkeys@temp}%
	\toks2={##1}%
	\xdef\pgfkeys@global@temp{%
		\the\toks0 % the space is important!
		\noexpand\ifpgfkeyssuccess\noexpand\else
			\noexpand\pgfqkeys{\the\toks1 }{\noexpand\pgfkeys@searchalso@name
               \ifx\pgfkeys@searchalso@nexttok\pgfkeys@mainstop\else/.try\fi={\the\toks2 }}%
		\noexpand\fi}%
	\expandafter\gdef\expandafter\pgfkeys@global@temp\expandafter##\expandafter1\expandafter\pgfeov\expandafter{\pgfkeys@global@temp}%
  }%
  \pgfkeys@searchalso@parse#2%
}
\pgfkeys{%
	/handlers/.is family/.code=\pgfkeys{\pgfkeyscurrentpath/.ecode=\edef\noexpand\pgfkeysdefaultpath{\pgfkeyscurrentpath/}},%
	/handlers/.cd/.code=\edef\pgfkeysdefaultpath{\pgfkeyscurrentpath/},%
	/handlers/.search also/.code={%
		\pgfkeys@searchalso@prepare@unknown@handler{#1}%
%\message{I prepared the '\pgfkeyscurrentpath/.unknown' handler \meaning\pgfkeys@global@temp\space for '#1'.}%
		\pgfkeyslet{\pgfkeyscurrentpath/.unknown/.@cmd}{\pgfkeys@global@temp}%
	}
}%


% Value expansion

\pgfkeys{/handlers/.expand once/.code=\expandafter\pgfkeys@exp@call\expandafter{#1}}
\pgfkeys{/handlers/.expand twice/.code=\expandafter\expandafter\expandafter\pgfkeys@exp@call\expandafter\expandafter\expandafter{#1}}
\pgfkeys{/handlers/.expanded/.code=\edef\pgfkeys@temp{#1}\expandafter\pgfkeys@exp@call\expandafter{\pgfkeys@temp}}

\def\pgfkeys@exp@call#1{\pgfkeysalso{\pgfkeyscurrentpath={#1}}}

% Try to set a key and do nothing if not define

\newif\ifpgfkeyssuccess
\pgfkeys{/handlers/.try/.code=\pgfkeys@try}
\pgfkeys{/handlers/.retry/.code=\ifpgfkeyssuccess\else\pgfkeys@try\fi}
\def\pgfkeys@try{%
  \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}% make sure that \pgfkeys@code doesn't know about 'try'. Important for .is choice
  \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text% Hmm... no value
    \pgfkeysifdefined{\pgfkeyscurrentpath/.@def}%
    {\pgfkeysgetvalue{\pgfkeyscurrentpath/.@def}{\pgfkeyscurrentvalue}}
    {}% no default, so leave it
  \fi%
  \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}%
  {%
    \pgfkeysgetvalue{\pgfkeyscurrentpath/.@cmd}{\pgfkeys@code}%
    \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov%
    \pgfkeyssuccesstrue%
  }%
  {%
    \pgfkeysifdefined{\pgfkeyscurrentpath}%
    {%
      \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text%
        \pgfkeysvalueof{\pgfkeyscurrentpath}%
      \else%
        \pgfkeyslet{\pgfkeyscurrentpath}\pgfkeyscurrentvalue%
      \fi%
      \pgfkeyssuccesstrue%
    }%
    {%
      \pgfkeys@split@path%
      \pgfkeysifdefined{/handlers/\pgfkeyscurrentname/.@cmd}{%
	    % in the standard configuration, this check here is redundand
	    % because pgfkeys@ifexecutehandler === true.
		% It is only interesting for 'handle only existing'.
        \pgfkeys@ifexecutehandler{%
	      \pgfkeysgetvalue{/handlers/\pgfkeyscurrentname/.@cmd}{\pgfkeys@code}%
          \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov
          \pgfkeyssuccesstrue%
    	}{%
	      \pgfkeyssuccessfalse
    	}%
      }{%
	    \pgfkeyssuccessfalse
      }%
	}%
  }%
}

% Utilities

\pgfkeys{/utils/exec/.code=#1} % simply execute the given code directly.


% Errors

\pgfkeys{/errors/boolean expected/.code 2 args=\pgfkeys@error{%
    Boolean parameter of key '#1' must be 'true' or 'false', not
    '#2'. I am going to ignore it}}  
\pgfkeys{/errors/value required/.code 2 args=\pgfkeys@error{%
    The key '#1' requires a value. I am going to ignore this key}{}}  
\pgfkeys{/errors/value forbidden/.code 2 args=\pgfkeys@error{%
    You may not specify a value for the key '#1'. I am going to ignore
    the value '#2' that you provided}}
\pgfkeys{/errors/unknown choice value/.code 2 args=\pgfkeys@error{%
    Choice '\pgfkeyscurrentname' unknown in key
    '\pgfkeyscurrentpath'. I am going to ignore this key}}
\pgfkeys{/errors/unknown key/.code 2 args=\pgfkeys@error{%
    I do not know the key '#1' and I am going to ignore it. Perhaps
    you misspelled it}}

\pgfkeys{/handlers/.unknown/.code=%
  {%
    \let\pgfkeys@orig@key=\pgfkeyscurrentkey%
    \pgfkeysalso{/errors/unknown key=\pgfkeys@orig@key{}}%
  }
}

\pgfkeys{
	/handler config/.is choice,
	/handler config/all/.code={%
		\let\pgfkeys@case@three=\pgfkeys@case@three@handleall
		\let\pgfkeys@ifexecutehandler=\pgfkeys@ifexecutehandler@handleall
	},
	/handler config/only existing/.code={%
		\let\pgfkeys@case@three=\pgfkeys@case@three@handle@restricted
		\let\pgfkeys@ifexecutehandler=\pgfkeys@ifexecutehandler@handleonlyexisting
	},
	/handler config/full or existing/.code={%
		\let\pgfkeys@case@three=\pgfkeys@case@three@handle@restricted
		\let\pgfkeys@ifexecutehandler=\pgfkeys@ifexecutehandler@handlefullorexisting
	},
	/handler config/only existing/add exception/.code={\pgfkeysaddhandlyonlyexistingexception{#1}},
}%
\pgfkeysaddhandlyonlyexistingexception{.cd}%
\pgfkeysaddhandlyonlyexistingexception{.try}%
\pgfkeysaddhandlyonlyexistingexception{.retry}%
\pgfkeysaddhandlyonlyexistingexception{.lastretry}%
\pgfkeysaddhandlyonlyexistingexception{.unknown}%


\input pgfkeysfiltered.code.tex

\endinput

pgfmathcalc.code.tex
% Copyright 2007 by Mark Wibrow
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

% This file loads all the parsing, functions and operator stuff
%
% Version 1.414213 29/9/2007

\input pgfmathutil.code.tex
\input pgfmathparser.code.tex
\input pgfmathfunctions.code.tex
%\input pgfmathbase.code.tex

% \pgfmathsetlength, \pgfmathaddtolength
%
% #1 = dimension register
% #2 = expression
%
% Description:
%
% These functions work similar to \setlength and \addtolength. Only,
% they allow #2 to contain an expression, which is evaluated before
% assignment. Furthermore, the font is setup before the assignment is
% done, so that dimensions like 1em are evaluated correctly.
%
% If #2 starts with "+", then a simple assignment is done (but the
% font is still setup). This is orders of magnitude faster than a
% parsed assignment.

\def\pgfmathsetlength#1#2{%
	\expandafter\pgfmath@onquick#2\pgfmath@%
	{%
		% Ok, quick version:
		\begingroup%
			\pgfmath@selectfont%
			\pgfmath@x#2\unskip%
			\pgfmath@returnone\pgfmath@x%
		\endgroup%
		#1\pgfmathresult pt\relax%
	}%
	{%
		\pgfmathparse{#2}%
		#1\pgfmathresult pt\relax%
	}%
	\ignorespaces%
}

% \pgfmathaddtolength
%
% Add to #1 the result of evaluating #2.
%
% #1 - a dimension register
% #2 - an expression
%
\def\pgfmathaddtolength#1#2{%
	\expandafter\pgfmath@onquick#2\pgfmath@%
  {%
  	\begingroup%
  		\pgfmath@selectfont%
  		\pgfmath@x#1\relax%
  		\advance\pgfmath@x#2\unskip%
  		\pgfmath@returnone\pgfmath@x%
    \endgroup%
    #1\pgfmathresult pt\relax%
  }%
  {%
  	\pgfmathparse{#2}%
  	\advance#1\pgfmathresult pt\relax%
  }%
  \ignorespaces%
}

% \pgfmathsetcount
%
% Assign #1 the truncated evaluation of #2.
%
% #1 - a count register
% #2 - an expression
%
\def\pgfmathsetcount#1#2{%
  \expandafter\pgfmath@onquick#2\pgfmath@%
  {%
    \afterassignment\pgfmath@gobbletilpgfmath@%
    #1#2\relax\pgfmath@%
  }%
  {%
    \pgfmathparse{#2}%
    \afterassignment\pgfmath@gobbletilpgfmath@%
    #1\pgfmathresult\relax\pgfmath@%
  }%
  \ignorespaces%
}

% \pgfmathaddtocount
%
% Add to #1 the truncated evaluation of #2.
%
% #1 - a count register
% #2 - an expression
%
\def\pgfmathaddtocount#1#2{%
  \expandafter\pgfmath@onquick#2\pgfmath@%
  {%
    \edef\pgfmath@addtocounttemp{\the#1}%
    \afterassignment\pgfmath@gobbletilpgfmath@%
    #1#2\relax\pgfmath@%
    \advance#1\pgfmath@addtocounttemp\relax%
  }%
  {%
    \edef\pgfmath@addtocounttemp{\the#1}%
    \pgfmathparse{#2}%
    \afterassignment\pgfmath@gobbletilpgfmath@%
    #1\pgfmathresult\relax\pgfmath@%
    \advance#1\pgfmath@addtocounttemp\relax%
  }%
  \ignorespaces%
}

% \pgfmathnewcounter
%
% LaTeX style counter which also works in plain TeX. Defines
% \c@<name> as a count register and also defines \the<name>.
%
% #1 the name of the counter.
%
% Example:
%
% \pgfmathnewcounter{counter}
% \pgfmathsetcounter{counter}{12}
% \thecounter  (same as \the\c@counter)
%
\def\pgfmathnewcounter#1{%
	\expandafter\ifx\csname c@#1\endcsname\relax%
		\def\pgfmath@marshal{\csname newcount\endcsname}% Ha! Who cares about \outer?
		\expandafter\pgfmath@marshal\csname c@#1\endcsname%
		\expandafter\def\csname the#1\endcsname{\expandafter\the\csname c@#1\endcsname}%
	\fi%
}

% \pgfmathsetcounter
%
% Set the counter #1 to the evaluation of #2.
%
% #1 - a counter name
% #2 - an expression
%
\def\pgfmathsetcounter#1#2{%
 	\expandafter\pgfmathsetcount\csname c@#1\endcsname{#2}%
}

% \pgfmathaddtocounter
%
% Add the counter #1 to the evaluation of #2.
%
% #1 - a counter name
% #2 - an expression
%
\def\pgfmathaddtocounter#1#2{%
  \expandafter\pgfmathaddtocount\csname c@#1\endcsname{#2}%
}

% \pgfmathmakecounterglobal
%
% Make the current value of a counter globally defined.
%
% #1 - a (valid) counter name.
%
\def\pgfmath@pgftext{pgf}
\def\pgfmath@tikztext{tikz}
\def\pgfmathmakecounterglobal#1{%
	\pgfmath@ifundefined{c@#1}{}{%
		\expandafter\pgfmath@in@\expandafter{\pgfmath@pgftext}{#1}%
		\ifpgfmath@in@%
		\else%
			\expandafter\pgfmath@in@\expandafter{\pgfmath@tikztext}{#1}%
			\ifpgfmath@in@%
			\else%
				\expandafter\global\csname c@#1\endcsname\csname c@#1\endcsname\relax%
			\fi%
		\fi%
	}%
}

% \pgfmathsetmacro
%
% \edef#1 as the result of evaluating #2.
%
% #1 - a macro
% #2 - an expression
%
\def\pgfmathsetmacro#1#2{%
	\begingroup%
		\pgfmathsetlength\pgfmath@x{#2}%
		\edef#1{\pgfmath@tonumber{\pgfmath@x}}%
		\pgfmath@smuggleone{#1}%
	\endgroup%
}

% \pgfmathsetlengthmacro
%
% \edef#1 as the result of evaluating #2 with pt.
%
% #1 - a macro
% #2 - an expression
%
\def\pgfmathsetlengthmacro#1#2{%
	\begingroup%
		\pgfmathsetlength\pgfmath@x{#2}%
		\edef#1{\the\pgfmath@x}%
		\pgfmath@smuggleone{#1}%
	\endgroup%
}

% \pgfmathtruncatemacro
%
% \edef#1 as the truncated result of evaluating #2.
%
% #1 - a macro
% #2 - an expression
%
\def\pgfmathtruncatemacro#1#2{%
	\begingroup%
		\pgfmathsetcount\c@pgfmath@counta{#2}%
		\edef#1{\the\c@pgfmath@counta}%
		\pgfmath@smuggleone{#1}%
	\endgroup%
}

% Check whether a given parameter starts with quick.
%
% The command should be followed by nonempty text, ending with
% \pgfmath@ as a stop-token. Then should follow
%
% #1 - code to execute if text starts with +
% #2 - code to execute if text does not
%
% Example:
%
% \pgfmath@onquick+0pt\pgfmath@{is quick}{is slow}

\def\pgfmath@onquick{%
  \futurelet\pgfmath@next%
  \pgfmath@@onquick}
\def\pgfmath@@onquick#1\pgfmath@{%
	\ifx\pgfmath@next+%
	  \let\pgfmath@next=\pgfmath@firstoftwo%
	\else%
	  \let\pgfmath@next=\pgfmath@secondoftwo%
	\fi%
	\pgfmath@next%
}

% *** The following commands DO NOT WORK without the rest of PGF ***
%
% (a dumping ground for stuff that doesn't really belong anywhere else)
	
% \pgfmathanglebetweenpoints
%
% Define \pgfmathresult as the angle between points #1 and #2
% Should get the quadrants right as well.
%
\def\pgfmathanglebetweenpoints#1#2{%
	\begingroup%
		\pgf@process{\pgfpointdiff{#1}{#2}}%
		%
		% First approximate the angle of the external point...
		%
		\pgf@xa\pgf@x%
		\pgf@ya\pgf@y%
		\pgf@xb\pgf@x%
		\pgf@yb\pgf@y%
		\ifdim\pgf@xa<0pt\relax%
			\pgf@xa-\pgf@xa%
		\fi%
		\ifdim\pgf@ya<0pt\relax%
			\pgf@ya-\pgf@ya%
		\fi%
		\ifdim\pgf@ya>\pgf@xa%
			\pgf@x\pgf@xa%
			\pgf@y\pgf@ya%
		\else%
			\pgf@x\pgf@ya%
			\pgf@y\pgf@xa%
		\fi%
		\ifdim\pgf@y=0pt\relax%
			\pgf@x0pt%
		\else%
			\pgfmathreciprocal@{\pgfmath@tonumber{\pgf@y}}%
			\pgf@x\pgfmathresult\pgf@x%
		\fi%
		\multiply\pgf@x1000\relax%
		\afterassignment\pgfmath@gobbletilpgfmath@%
		\expandafter\c@pgf@counta\the\pgf@x\relax\pgfmath@%
		\expandafter\pgf@x\csname pgfmath@atan@\the\c@pgf@counta\endcsname pt\relax%
		\ifdim\pgfmath@ya>\pgfmath@xa\relax%
			\pgf@x-\pgf@x%
			\advance\pgf@x90pt%
		\fi%
		\ifdim\pgf@xb<0pt%
			\ifdim\pgf@yb>0pt%
				\pgf@x-\pgf@x%
			\fi%
			\advance\pgf@x180pt\relax%
		\else%
			\ifdim\pgf@yb<0pt%
			\pgf@x-\pgf@x%
			\advance\pgf@x360pt\relax%
		\fi\fi%
		\pgfmath@returnone\pgf@x%
	\endgroup%
}

%
% \pgfmathrotatepointaround
%
% Rotate point #1 about point #2 by #3 degrees.
%
\def\pgfmathrotatepointaround#1#2#3{%
	\pgf@process{%
		\pgf@process{#1}%
		\pgf@xc=\pgf@x%
		\pgf@yc=\pgf@y%
		\pgf@process{#2}%
		\pgf@xa\pgf@x%
		\pgf@ya\pgf@y%
		\pgf@xb\pgf@x%
		\pgf@yb\pgf@y%
		\pgf@x=\pgf@xc%
		\pgf@y=\pgf@yc%
		\advance\pgf@x-\pgf@xa%
		\advance\pgf@y-\pgf@ya%
		\pgfmathsetmacro\angle{#3}%
		\pgfmathsin@{\angle}%
		\let\sineangle\pgfmathresult%
		\pgfmathcos@{\angle}%
		\let\cosineangle\pgfmathresult%
		\pgf@xa\cosineangle\pgf@x%
		\advance\pgf@xa-\sineangle\pgf@y%
		\pgf@ya\sineangle\pgf@x%
		\advance\pgf@ya\cosineangle\pgf@y%
		\pgf@x\pgf@xb%
		\pgf@y\pgf@yb%
		\advance\pgf@x\pgf@xa%
		\advance\pgf@y\pgf@ya%
	}%
}

% \pgfmathanglebetweenlines
%
% Calculate the clockwise angle between a line from point #1
% to point #2 and a line from #3 to point #4.
%
\def\pgfmathanglebetweenlines#1#2#3#4{%
	\begingroup%
		\pgfmathanglebetweenpoints{#1}{#2}%
		\let\firstangle\pgfmathresult%
		\pgfmathanglebetweenpoints{#3}{#4}%
		\let\secondangle\pgfmathresult%
		\ifdim\firstangle pt>\secondangle pt\relax%
			\pgfmathadd@{\secondangle}{360}%
			\let\secondangle\pgfmathresult%
		\fi%
		\pgfmathsubtract@{\secondangle}{\firstangle}%
		\pgfmath@smuggleone\pgfmathresult%
	\endgroup%
}

% \pgfmathpointreflectalongaxis
%
% Reflects point #2 around an axis centered on #2 at an angle #3.
%
\def\pgfmathreflectpointalongaxis#1#2#3{%
	\pgf@process{%
		\pgfmathanglebetweenpoints{#2}{#1}%
		\pgfmath@tempdima\pgfmathresult pt\relax%
		\pgfmathparse{#3}%
		\advance\pgfmath@tempdima-\pgfmathresult pt\relax%
		\pgfmath@tempdima-2.0\pgfmath@tempdima%
		\pgfmathrotatepointaround{#1}{#2}{\pgfmath@tonumber{\pgfmath@tempdima}}%
	}%
}



% \pgfmathpointintersectionoflineandarc 
%
% A bit experimental at the moment:
%
% Locates the point where a line crosses an eliptical arc. If the line
% does not cross the arc, a meaningless point will result.
%
% #1 the point of the line on the "convex" side of the arc.
% #2 the point of the line on the "concave" side of the arc.
% #3 the center of the eliptical arc.
% #4 start angle of the arc.
% #5 end angle of the arc.
% #6 radii of the arc.
%
\def\pgfmathpointintersectionoflineandarc#1#2#3#4#5#6{%
	\pgf@process{%
		%
		% Get the required angle.
		%
		\pgfmathanglebetweenpoints{#2}{#1}%
		\let\x\pgfmathresult%
		%
		% Get the radii of the arc.
		%
		\pgfmath@in@{and }{#6}%
	  \ifpgfmath@in@%
	    \pgf@polar@#6\@@%
	  \else%
	    \pgf@polar@#6 and #6\@@%
	  \fi%
	  \edef\xarcradius{\the\pgf@x}%
	  \edef\yarcradius{\the\pgf@y}% 
	   %
	  % Get the start and end angles of the arc...
	  % 
	  \pgfmathsetmacro\s{#4}%
	  \pgfmathsetmacro\e{#5}%
	  %
	  % ...and also with rounding.
	  %
	  \pgfmathmod@{\s}{360}%
	  \ifdim\pgfmathresult pt<0pt\relax%
	  	\pgfmathadd@{\pgfmathresult}{360}%
	  \fi%
	  \let\ss\pgfmathresult%
	  \pgfmathmod@{\e}{360}%
	  \ifdim\pgfmathresult pt<0pt\relax%
	  	\pgfmathadd@{\pgfmathresult}{360}%
	  \fi%
	  \let\ee\pgfmathresult%
	  %
	  % Hackery for when arc straddles zero.
	  %
	  \ifdim\ee pt<\ss pt\relax%
	  	\pgfmathadd@{\x}{180}%
	  	\pgfmathmod@{\pgfmathresult}{360}%
	  	\let\x\pgfmathresult%
	  \fi%
	  \def\m{360}% Measure of nearness.
		\pgfmathadd@{\s}{\e}%
		\pgfmathdivide@{\pgfmathresult}{2}%
		\let\n\pgfmathresult% The best estimate (default to middle of arc).
		\pgfmathloop%
			\pgfmathadd@{\s}{\e}%
			\pgfmathdivide@{\pgfmathresult}{2}%
			\let\p\pgfmathresult%
			\ifdim\p pt=\s pt\relax% 
			\else%
				\pgfmathanglebetweenpoints{#2}{%
					\pgfpointadd{#3}{%
						\pgf@x\xarcradius\relax%
						\pgfmathcos@{\p}%
						\pgf@x\pgfmathresult\pgf@x%
						\pgf@y\yarcradius\relax%
						\pgfmathsin@{\p}%
						\pgf@y\pgfmathresult\pgf@y%
					}%
				}%
				%
			  % Hackery for when arc straddles zero.
			  %
				\ifdim\ee pt<\ss pt\relax%
			  	\pgfmathadd@{\pgfmathresult}{180}%
			  	\pgfmathmod@{\pgfmathresult}{360}%
			  \fi%
				\let\q\pgfmathresult%
				%
				% More hackery...
				%
				\ifdim\x pt>335pt\relax%
					\ifdim\q pt<45pt\relax%
						\pgfmathadd@{\q}{360}%
						\let\q\pgfmathresult%
					\fi%
				\fi%
				\ifdim\x pt=\q pt% Found it!
						\pgfmathbreakloop% Breaks after current iteration is complete.
					\else
						\ifdim\x pt<\q pt\relax%
							\let\e\p%
						\else%
							\let\s\p%
						\fi%
					\fi%
					\pgfmathsubtract@{\x}{\q}%
					\pgfmathabs@{\pgfmathresult}%
					%
					% Save the estimate if it is better than any previous estimate.
					%
					\ifdim\pgfmathresult pt<\m pt\relax%
						\let\m\pgfmathresult%
						\let\n\p%
					\fi%				
		\repeatpgfmathloop%
		\pgfpointadd{#3}{\pgfpointpolar{\n}{\xarcradius and \yarcradius}}%
	}%
}

% \pgfmathangleonellipse
% 
% Find the angle corresponding to a point on the border of an ellispe.
%
% #1 - the point on the border.
% #2 - the radii of the ellipse.
%
\def\pgfmathangleonellipse#1#2{%
	\begingroup%
		\pgfmath@in@{and }{#2}%
	  \ifpgfmath@in@%
	    \pgf@polar@#2\@@%
	  \else%
	    \pgf@polar@#2 and #2\@@%
	  \fi%
	  \pgf@xa\pgf@x%
	  \pgf@ya\pgf@y%
	  \pgf@process{#1}% 
	  \ifdim\pgf@x=0pt\relax%
			\pgfutil@tempdima1pt\relax%
		\else%
			\pgfutil@tempdima\pgf@x%
			\pgfmathdivide@{\pgfmath@tonumber{\pgf@xa}}{\pgfmath@tonumber{\pgfutil@tempdima}}%
			\pgfutil@tempdima\pgfmathresult pt\relax%
		\fi%
		\ifdim\pgf@y=0pt\relax%
			\pgfutil@tempdima1pt\relax%
		\else%
			\pgfmathdivide@{\pgfmath@tonumber{\pgf@y}}{\pgfmath@tonumber{\pgf@ya}}%
			\pgfutil@tempdima\pgfmathresult\pgfutil@tempdima%
			\pgfmathatan@{\pgfmath@tonumber{\pgfutil@tempdima}}%
		\fi%
		%
		\pgfutil@tempdima\pgfmathresult pt\relax%
		\ifdim\pgfutil@tempdima<0pt\relax%
  		\advance\pgfutil@tempdima360pt\relax%
  	\fi%
		\ifdim\pgf@x<0pt\relax%
			\ifdim\pgf@y=0pt\relax%
				\pgfutil@tempdima180pt\relax%
			\else%
				\ifdim\pgf@y<0pt\relax%
					\advance\pgfutil@tempdima180pt\relax%
				\else%
					\advance\pgfutil@tempdima-180pt\relax%
				\fi%
			\fi%
		\else%
			\ifdim\pgf@x=0pt\relax%
				\ifdim\pgf@y<0pt\relax%
					\pgfutil@tempdima270pt\relax%
				\else%
					\pgfutil@tempdima90pt\relax%
				\fi%
			\else%
				\ifdim\pgf@y=0pt\relax%
					\pgfutil@tempdima0pt\relax%
				\fi%
			\fi%				
		\fi%
		\pgfmath@returnone\pgfutil@tempdima%
	\endgroup%
}

pgfmath.code.tex
% Copyright 2007 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\input pgfmathcalc.code.tex

\ifx\pgfkeysloaded\undefined
  \let\pgfkeysloaded=\relax
\else
  \expandafter\input pgfmathfloat.code.tex
\fi


pgfmathfloat.code.tex
% Copyright 2008 by Christian Feuersaenger
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
%
% This file contains methods for basic floating point arithmetics, rounding
% to arbitrary precision and number pretty printing.
%
% Version 1.0 2008/09/17

\global\newif\ifpgfmathfloatcomparison
\newif\ifpgfmathfloatroundhasperiod
\newif\ifpgfmathprintnumberskipzeroperiod


% used internally in grouped macros:
\toksdef\pgfmathfloat@tmptoks=1
\newif\ifpgfmathfloat@fixed@digits@after@period
\newif\ifpgfmathfloatroundmayneedrenormalize
\toksdef\pgfmathfloat@a@Mtok=0

%% WARNING: avoid conflicting register names!
\let\pgfmathfloat@a@S=\c@pgf@counta
\let\pgfmathfloat@a@M=\pgf@xa
\let\pgfmathfloat@a@E=\c@pgf@countb
\let\pgfmathfloat@b@S=\c@pgf@countc
\let\pgfmathfloat@b@M=\pgf@xb
\let\pgfmathfloat@b@E=\c@pgf@countd

% can be changed with options.
\def\pgfmathfloat@round@precision{2}

\gdef\pgfmathfloat@glob@TMP{}


% Computes a normalised floating point representation for #1 of the
% form
%   [FLAGS] MANTISSE EXPONENT
% meaning
%   [+-]X.XXXXXXX*10^C
% where 
%   X.XXXXXX is a mantissa with first number != 0, C is an integer and
% FLAGS contains the sign and some other special cases.
%
% This method does NOT use TeX Registers to represent the numbers! The
% computation is COMPLETELY STRING BASED.
% This allows numbers such at 10000000 or 5.23e-10 to be represented
% properly, although TeX-registers would produce overflow/underflow
% errors in these cases. 
%
% It is to be used to compute logs, because log(X*10^Y) = log(X) + log(10)*Y
%
% Arguments:
% #1:  an arbitrary number which shall be parsed. Maybe a macro.
%     Examples:
%     [+-]XXXXX.XXXXXX
%     [+-]XXXXX.XXXXXXeXXXX
%     [+-]0.0000XXXXXX
%     [+-]0.0000XXXXXXeXXXX
%     [+-]inf
%     nan
%    Maybe a macro containing such a number.
%
% Return value:
% \pgfmathresult will be \def'ed to
%  FLAGS MANTISSE 'e' EXPONENT
% where
% FLAGS is a number in [0-5] where
% 		0 == '0' (the number is +- 0.0),
% 		1 == '+', 
% 		2 == '-',
% 		3 == 'not a number'
% 		4 == '+ infinity'
% 		5 == '- infinity'
%
% MANTISSE is a normalised number 1 <= M < 10. It always contains a
% period and at least one digit after the period.
%
% EXPONENT is an integer value.
%
% Example:
% \pgfmathfloatparsenumber{1}
% -> \pgfmathresult = 11.0e0
% \pgfmathfloatparsenumber{141.212}
% -> \pgfmathresult = 11.41212e2
\def\pgfmathfloatparsenumber#1{%
	\begingroup
	\edef\pgfmathresult{#1}%
	\expandafter\pgfflt@impl\pgfmathresult\pgfflt@EOI
	\ifpgfmathfloatparsenumberpendingperiod
		\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.0}%
	\fi
	\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

% The same as \pgfmathfloatparsenumber, but does not perform sanity checking.
% FIXME: there is no longer any difference here.
\let\pgfmathfloatqparsenumber=\pgfmathfloatparsenumber

% Takes a floating point number #1 as input and writes flags to count
% register #2, mantissa to dimen register #3 and exponent to count
% register #4.
\def\pgfmathfloattoregisters#1#2#3#4{%
	\expandafter\pgfmathfloat@decompose#1\relax{#2}{#3}{#4}%
}

% the same, but writes the mantissa into a token register.
\def\pgfmathfloattoregisterstok#1#2#3#4{%
	\expandafter\pgfmathfloat@decompose@tok#1\relax{#2}{#3}{#4}%
}

% Extracts the flags of #1 into the count register #2.
\def\pgfmathfloatgetflags#1#2{%
	\expandafter\pgfmathfloat@decompose@F#1\relax{#2}%
}
% Extracts the flags of #1 into the macro #2.
\def\pgfmathfloatgetflagstomacro#1#2{%
	\expandafter\pgfmathfloat@decompose@Fmacro#1\relax{#2}%
}%

% Extracts the mantissa of #1 into the dimen register #2.
\def\pgfmathfloatgetmantissa#1#2{%
	\expandafter\pgfmathfloat@decompose@M#1\relax{#2}%
}
\let\pgfmathfloatgetmantisse=\pgfmathfloatgetmantissa
% Extracts the mantissa of #1 into the token register #2.
\def\pgfmathfloatgetmantissatok#1#2{%
	\expandafter\pgfmathfloat@decompose@Mtok#1\relax{#2}%
}
\let\pgfmathfloatgetmantissetok=\pgfmathfloatgetmantissatok
% Extracts the exponent of #1 into the count register #2.
\def\pgfmathfloatgetexponent#1#2{%
	\expandafter\pgfmathfloat@decompose@E#1\relax{#2}%
}


% Assigns \pgfmathresult to be a float encoded as
% <FLAGS><MANTISSE>e<EXPONENT>
%
% example:
% \pgfmathfloatcreate{1}{2.0}{10}
% \pgfmathfloat@to@FMeE@style\pgfmathresult
% ->
% \pgfmathresult is now '12.0e10' regardless of the internal float
% format.
\def\pgfmathfloat@to@FMeE@style#1{\expandafter\pgfmathfloat@to@FMeE@style@#1\relax\relax}%
\def\pgfmathfloat@to@FMeE@style@#1#2{%
	\ifx#2Y%
		\expandafter\pgfmathfloat@to@FMeE@style@@%
	\else
		\expandafter\pgfmathfloat@to@FMeE@style@error%
	\fi
	#1#2%
}%
\def\pgfmathfloat@to@FMeE@style@@#1Y#2e#3]\relax\relax{\def\pgfmathresult{#1#2e#3}}%
\def\pgfmathfloat@to@FMeE@style@error#1\relax\relax{%
	\begingroup
	\pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
	\xdef\pgfmathfloat@decompose@TMP{%
		\noexpand\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
	}%
	\endgroup
	\pgfmathfloat@decompose@TMP
}%


% decomposes a lowlevel floating point representation into flags,
% mantissa and exponent.
%
% #4: integer register for the flags.
% #5: dimen registers for the mantissa.
% #6: integer register for the exponent.
%
% \expandafter\pgfmathfloat@decompose\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@M\pgfmathfloat@a@E
% -> the three temp registers contain flags, mantissa and exponent
\def\pgfmathfloat@decompose#1#2{% sanitize!
	\ifx#2Y%
		\expandafter\pgfmathfloat@decompose@%
	\else
		\expandafter\pgfmathfloat@decompose@error%
	\fi
	#1#2%
}
\def\pgfmathfloat@decompose@#1Y#2e#3]\relax#4#5#6{%
   #4=#1\relax
   #5=#2pt % keep space here.
   #6=#3\relax%
}

% overloaded, #5 needs to be a token register for the mantissa.
% @see also \pgfmathfloatvalueof  which does also employ the load
% level repr.
% \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
% -> the three temp registers contain flags, mantissa and exponent
\def\pgfmathfloat@decompose@tok#1#2{%
	\ifx#2Y%
		\expandafter\pgfmathfloat@decompose@tok@%
	\else
		\expandafter\pgfmathfloat@decompose@tok@error%
	\fi
	#1#2%
}%
\def\pgfmathfloat@decompose@tok@#1Y#2e#3]\relax#4#5#6{%
   #4=#1\relax
   #5={#2}%
   #6=#3\relax%
}
% overloaded, returns only ONE of the three components into #4:
% \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S
% -> \pgfmathfloat@a@S contains the flags field.
\def\pgfmathfloat@decompose@F#1#2{%
	\ifx#2Y%
		\expandafter\pgfmathfloat@decompose@F@%
	\else
		\expandafter\pgfmathfloat@decompose@F@error%
	\fi
	#1#2%
}%
\def\pgfmathfloat@decompose@Fmacro#1#2{%
	\ifx#2Y%
		\expandafter\pgfmathfloat@decompose@Fmacro@%
	\else
		\expandafter\pgfmathfloat@decompose@F@error%
	\fi
	#1#2%
}%
\def\pgfmathfloat@decompose@M#1#2{%
	\ifx#2Y%
		\expandafter\pgfmathfloat@decompose@M@%
	\else
		\expandafter\pgfmathfloat@decompose@M@error%
	\fi
	#1#2%
}%
\def\pgfmathfloat@decompose@E#1#2{%
	\ifx#2Y%
		\expandafter\pgfmathfloat@decompose@E@%
	\else
		\expandafter\pgfmathfloat@decompose@E@error%
	\fi
	#1#2%
}%
\def\pgfmathfloat@decompose@Mtok#1#2{%
	\ifx#2Y%
		\expandafter\pgfmathfloat@decompose@Mtok@%
	\else
		\expandafter\pgfmathfloat@decompose@Mtok@error%
	\fi
	#1#2%
}%
\def\pgfmathfloat@decompose@F@#1Y#2e#3]\relax#4{#4=#1\relax}%
\def\pgfmathfloat@decompose@Fmacro@#1Y#2e#3]\relax#4{\def#4{#1}}%
\def\pgfmathfloat@decompose@M@#1Y#2e#3]\relax#4{#4=#2pt}%
\def\pgfmathfloat@decompose@Mtok@#1Y#2e#3]\relax#4{#4={#2}}%
\def\pgfmathfloat@decompose@E@#1Y#2e#3]\relax#4{#4=#3\relax}%

\def\pgfmathfloat@decompose@error#1\relax#2#3#4{%
	\begingroup
	\pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
	\xdef\pgfmathfloat@decompose@TMP{%
		\noexpand#2=\the\pgfmathfloat@a@S\space
		\noexpand#3=\the\pgfmathfloat@a@Mtok pt
		\noexpand#4=\the\pgfmathfloat@a@E\space
	}%
	\endgroup
	\pgfmathfloat@decompose@TMP
}%
\def\pgfmathfloat@decompose@tok@error#1\relax#2#3#4{%
	\begingroup
	\pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
	\xdef\pgfmathfloat@decompose@TMP{%
		\noexpand#2=\the\pgfmathfloat@a@S\space
		\noexpand#3={\the\pgfmathfloat@a@Mtok}%
		\noexpand#4=\the\pgfmathfloat@a@E\space
	}%
	\endgroup
	\pgfmathfloat@decompose@TMP
}%
\def\pgfmathfloat@decompose@F@error#1\relax#2{%
	\begingroup
	\pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
	\xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@S\space}%
	\endgroup
	\pgfmathfloat@decompose@TMP
}%
\def\pgfmathfloat@decompose@M@error#1\relax#2{%
	\begingroup
	\pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
	\xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@Mtok pt }%
	\endgroup
	\pgfmathfloat@decompose@TMP
}%
\def\pgfmathfloat@decompose@Mtok@error#1\relax#2{%
	\begingroup
	\pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
	\xdef\pgfmathfloat@decompose@TMP{\noexpand#2={\the\pgfmathfloat@a@Mtok}}%
	\endgroup
	\pgfmathfloat@decompose@TMP
}%
\def\pgfmathfloat@decompose@E@error#1\relax#2{%
	\begingroup
	\pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
	\xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@E\space}%
	\endgroup
	\pgfmathfloat@decompose@TMP
}%
% Takes a floating point number #1 as input and writes flags to macro
% #2, mantissa to macro #3 and exponent to macro #4.
\def\pgfmathfloattomacro#1#2#3#4{%
	\begingroup
	\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
	\xdef\pgfmathfloat@glob@TMP{%
		\noexpand\def\noexpand#2{\the\pgfmathfloat@a@S}%
		\noexpand\def\noexpand#3{\the\pgfmathfloat@a@Mtok}%
		\noexpand\def\noexpand#4{\the\pgfmathfloat@a@E}%
	}%
	\endgroup
	\pgfmathfloat@glob@TMP
}


% Defines \pgfmathresult as the floating point number encoded by
% the flags #1, mantissa #2 and exponent #3.
%
% All arguments are characters and will be expanded using '\edef'.
\def\pgfmathfloatcreate#1#2#3{%
	\edef\pgfmathresult{#1Y#2e#3]}%
}%
% This is the character present in any low-level floating point
% number. It is assumed to be the SECOND character of a float (after
% the flags integer).
\def\pgfmathfloat@POSTFLAGSCHAR{Y}



% Converts a composed floating point representation to fixed point.
%
% Example:
% \pgfmathfloattofixed{142e1}
% -> \pgfmathresult = 42.0
\def\pgfmathfloattofixed@#1{%
	\begingroup
	\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
	\ifcase\pgfmathfloat@a@S
		\def\pgfmathresult{0.0}%
	\or
		\expandafter\pgfmathfloattofixed@impl\the\pgfmathfloat@a@Mtok\relax
	\or
		\expandafter\pgfmathfloattofixed@impl\the\pgfmathfloat@a@Mtok\relax
		\pgfmathfloat@a@Mtok=\expandafter{\pgfmathresult}%
		\edef\pgfmathresult{-\the\pgfmathfloat@a@Mtok}%
	\or\def\pgfmathresult{nan}%
	\or\def\pgfmathresult{inf}%
	\or\def\pgfmathresult{-inf}%
	\fi
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}
\let\pgfmathfloattofixed=\pgfmathfloattofixed@

% Converts a float to an integer (in integer format).
%
% @see \pgfmathfloatint 
\def\pgfmathfloattoint#1{%
	\pgfmathfloattofixed{#1}%
	\expandafter\pgfmathfloattoint@@\pgfmathresult\relax
}%
\def\pgfmathfloattoint@@#1.#2\relax{%
	\def\pgfmathresult{#1}%
}%

% Converts a floating point number to scientific format 1.234e5.
%
% This operation is very fast.
\def\pgfmathfloattosci@#1{%
	\begingroup
	\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
	\ifcase\pgfmathfloat@a@S
		\def\pgfmathresult{0.0e0}%
	\or
		\edef\pgfmathresult{\the\pgfmathfloat@a@Mtok e\the\pgfmathfloat@a@E}%
	\or
		\edef\pgfmathresult{-\the\pgfmathfloat@a@Mtok e\the\pgfmathfloat@a@E}%
	\or\def\pgfmathresult{nan}%
	\or\def\pgfmathresult{inf}%
	\or\def\pgfmathresult{-inf}%
	\fi
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}%
\let\pgfmathfloattosci=\pgfmathfloattosci@

% Expands a floating point number to scientific format 1.234e5.
%
% This operation is very fast.
\def\pgfmathfloatvalueof#1{\expandafter\pgfmathfloatvalueof@@#1\relax}%
\def\pgfmathfloatvalueof@@#1Y#2e#3]\relax{%
	\ifcase#1 %
		0.0e0%
	\or
		#2e#3%
	\or
		-#2e#3%
	\or nan%
	\or inf%
	\or -inf%
	\fi
}%


% Rounds a fixed point number #1 to \pgfmathfloat@round@precision digits precision and returns
% the result into \pgfmathresult.
%
% Any trailing zeros after the period are discarded.
% See \pgfmathroundtozerofill if you want trailing zeros and fixed
% width.
%
% This method is PURELY text based and can work with arbirtrary
% precision (well, limited to TeX's stack size and integer size).
%
% Examples:
% \pgfmathroundto{1}
% -> \pgfmathresult = '1'
%
% \pgfmathroundto{19999.9996}
% -> \pgfmathresult = '20000'
%
% Arguments:
% #1 may be either a number or a macro (\pgfmathresult is allowed) expanding to a number.
%
% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set.
\def\pgfmathroundto#1{%
	\pgfmathfloatroundhasperiodtrue
	\begingroup
	\pgfmathfloat@fixed@digits@after@periodfalse
	\pgfmathroundto@impl{#1}%
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}


% Overloaded method. 
%
% This variant always uses a FIXED number behind the period and fills
% in zeros if necessary.
% Examples:
% \pgfmathroundtozerofill{1}
% -> \pgfmathresult = '1.00'
%
% \pgfmathroundtozerofill{19999.9996}
% -> \pgfmathresult = '20000.00'
%
% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set.
\def\pgfmathroundtozerofill#1{%
	\pgfmathfloatroundhasperiodtrue
	\begingroup
	\pgfmathfloat@fixed@digits@after@periodtrue
	\pgfmathroundto@impl{#1}%
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

% see \pgfmathprintnumber@fixed@style for docs
\def\pgfmathprintnumber@fixed@styleDEFAULT#1#2#3e#4\relax{%
	\begingroup
	\pgfkeysgetvalue{/pgf/number format/set decimal separator}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP
	\pgfkeysgetvalue{/pgf/number format/@dec sep mark}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK
	\pgfkeysgetvalue{/pgf/number format/set thousands separator}\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP
	\c@pgf@counta=#4\relax
	\ifnum#2=0
		\c@pgf@counta=0
	\fi
	\def\pgfmathresult{}%
	\ifpgfmathfloatroundhasperiod
		\expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@period#1\pgfmathfloat@EOI
	\else
		\expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI%
		\begingroup
		\toks0=\expandafter{\pgfmathresult}%
		\toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}%
		\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
		\endgroup
		\let\pgfmathresult=\pgfmathfloat@glob@TMP
	\fi
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@period#1.#2\pgfmathfloat@EOI{%
	\ifpgfmathprintnumberskipzeroperiod
		\def\pgfmathfloat@loc@TMPb{#1}%
		\ifx\pgfmathfloatparsenumber@tok@ZERO\pgfmathfloat@loc@TMPb
		\else
			\def\pgfmathfloat@loc@TMPc{-0}%
			\ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb
				\def\pgfmathresult{-}%
			\else
				\def\pgfmathfloat@loc@TMPc{+0}%
				\ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb
					\def\pgfmathresult{+}%
				\else
					\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI
				\fi
			\fi
		\fi
	\else
		\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI
	\fi
	\begingroup
	\toks0=\expandafter{\pgfmathresult}%
	\toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}%
	\toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP #2}%
	\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }%
	\endgroup
	\let\pgfmathresult=\pgfmathfloat@glob@TMP
}%
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod{%
	\ifx\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP\pgfutil@empty
		\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
			\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}%
	\else
		\ifnum\c@pgf@counta<0\relax
			\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
				\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}%
		\else
			\ifnum\c@pgf@counta<\pgfkeysvalueof{/pgf/number format/min exponent for 1000 sep}\relax
				\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
					\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}%
			\else
				\advance\c@pgf@counta by1 % counta:= total number of digits, N.
				\c@pgf@countb=\c@pgf@counta
				\divide\c@pgf@countb by3 %  countb := N DIV 3
				\c@pgf@countc=\c@pgf@countb
				\multiply\c@pgf@countc by3
				\advance\c@pgf@counta by-\c@pgf@countc% now counta := N MOD 3
				\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
					\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printsign
				}%
			\fi
		\fi
	\fi
	\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
}
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printsign#1{%
	\def\pgfmathfloat@loc@TMPb{#1}%
	\ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@MINUS
		\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
		\let\pgfmathfloat@loc@TMPb=\pgfutil@empty
	\else
		\ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@PLUS
			\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
			\let\pgfmathfloat@loc@TMPb=\pgfutil@empty
		\else
			\ifpgfmathprintnumber@showpositive
				\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult +}%
			\fi
		\fi
	\fi
	\ifnum\c@pgf@counta>0
		\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
			\expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits\pgfmathfloat@loc@TMPb
		}%
	\else
		\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
			\expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird\pgfmathfloat@loc@TMPb
		}%
	\fi
	\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
}
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits#1#2{%
	\ifcase\c@pgf@counta
	\or
		\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
		\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
			\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird#2%
		}%
	\or
		\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1#2}%
		\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
			\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird%
		}%
	\fi
	\ifnum\c@pgf@countb>0\relax
		\begingroup
		\toks0=\expandafter{\pgfmathresult}%
		\toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}%
		\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
		\endgroup
		\let\pgfmathresult=\pgfmathfloat@glob@TMP
	\fi
	\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
}
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird#1#2#3{%
	\ifnum\c@pgf@countb>0\relax
		\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1#2#3}%
		\advance\c@pgf@countb by-1
		\ifnum\c@pgf@countb>0\relax
			\begingroup
			\toks0=\expandafter{\pgfmathresult}%
			\toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}%
			\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
			\endgroup
			\let\pgfmathresult=\pgfmathfloat@glob@TMP
		\fi
		\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
			\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird%
		}%
	\else
		% in thise case, #1#2#3 are expected to be
		% \pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI
		%--------------------------------------------------
		% \def\pgfmathfloat@loc@TMPb{\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI}%
		% \def\pgfmathfloat@loc@TMPc{#1#2#3}%
		% \ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb
		% \else
		% 	\pgfmath@error{INTERNAL ERROR in fixed style - The input sequence did not terminate as expected; which indicates a wrong exponent argument provided to \string\pgfmathprintnumber@fixed@style}{}%
		% \fi
		%-------------------------------------------------- 
		\let\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT=\relax
	\fi
	\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
}
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall#1{%
	\def\pgfmathfloat@loc@TMPb{#1}%
	\let\pgfmathfloat@loc@TMPc=\pgfutil@empty
	\ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@MINUS
	\else
		\ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@PLUS
		\else
			\ifpgfmathprintnumber@showpositive
				\def\pgfmathfloat@loc@TMPc{+}%
			\fi
		\fi
	\fi
	\expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall@\pgfmathfloat@loc@TMPc#1%
}
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall@#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI{%
	\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
}%

% @deprecated. It has been replaced by \pgfmathprintnumber@fixed@styleDEFAULT
% #1 maybe a macro
\def\pgfmathprintnumber@fixed@stylePERIOD#1#2#3e#4\relax{%
	\def\pgfmathresult{#1}%
}

% @deprecated. It has been replaced by \pgfmathprintnumber@fixed@styleDEFAULT
% #1 maybe a macro
\def\pgfmathprintnumber@fixed@styleCOMMA#1#2#3e#4\relax{%
	\ifpgfmathfloatroundhasperiod
		\expandafter\pgfmathprintnumber@fixed@styleCOMMA@impl#1\pgfmathfloat@EOI
	\else
		\def\pgfmathresult{#1}%
	\fi
}
\def\pgfmathprintnumber@fixed@styleCOMMA@impl#1.#2\pgfmathfloat@EOI{\def\pgfmathresult{#1{,}#2}}

% The default style to display fixed point numbers.
%
% It does not apply numerics, but it is responsable to typeset the
% rounded number.
% It can access the \ifpgfmathfloatroundhasperiod boolean.
%
% Arguments:
% #1#2#3e#4\relax

% Input: 
% #1  the fixed point number to be displayed (maybe a macro).
% #2#3e#4:  the (possibly unformatted) floating point representation
%     which belongs to #1. This format is returned (only!) by
%     \pgfmathfloat@to@FMeE@style.
%     It is used to determine sign and exponent.
\let\pgfmathprintnumber@fixed@style=\pgfmathprintnumber@fixed@styleDEFAULT


% Rounds a normalized floating point number to \pgfmathfloat@round@precision 
% digits precision and writes the result to \pgfmathresult.
%
% This method uses \pgfmathroundto for the mantissa.
%
% @see pgfmathfloatroundzerofill
%
% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set to
% whether the final mantissa #5 has a period or not.
\def\pgfmathfloatround#1{%
	\pgfmathfloatroundhasperiodtrue
	\begingroup
	\pgfmathfloat@fixed@digits@after@periodfalse
	\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
	\pgfmathfloatround@impl
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

% Overload.
%
% This method uses a fixed width for the mantissa and fills in zeros
% if necessary.
%
% This method uses \pgfmathroundtozerofill for the mantissa.
%
% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set to
% whether the final mantissa #5 has a period or not.
\def\pgfmathfloatroundzerofill#1{%
	\pgfmathfloatroundhasperiodtrue
	\begingroup
	\pgfmathfloat@fixed@digits@after@periodtrue
	\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
	\pgfmathfloatround@impl
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

\newif\ifpgfmathfloatround@allow@empty@mantissa
\def\pgfmathfloatround@mantissa@ONE{1.0}%

% #1: sign
% #2: mantissa
% #3: exponent
% #4: CODE to display if the mantissa is drawn.
% 	This code will be shown just before the exponent. 
% 	Example: #4=\cdot
% #5: CODE to display if the mantissa is NOT draw. (unused currently)
% 	Might be used to display '10^1' instead of '1*10^1'.
% #6: CODE to display the exponent.
\def\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax#4#5#6{%
	\pgfkeysgetvalue{/pgf/number format/@sci exponent mark}\pgfmathfloatrounddisplaystyle@e@mark
	\ifcase#1\relax
		\pgfmathprintnumber@fixed@style{#2}#1#2e0\relax%
		\expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}%
	\or\pgfmathprintnumber@fixed@style{#2}#1#2e0\relax%
		\expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}%
	\or\pgfmathprintnumber@fixed@style{-#2}#1#2e0\relax%
		\expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}%
	\or
		\pgfmathfloatrounddisplaystyle@shared@impl@@{\hbox{NaN}}{}%
	\or
		\ifpgfmathprintnumber@showpositive
			\pgfmathfloatrounddisplaystyle@shared@impl@@{+\infty}{}%
		\else
			\pgfmathfloatrounddisplaystyle@shared@impl@@{\infty}{}%
		\fi
	\or
		\pgfmathfloatrounddisplaystyle@shared@impl@@{-\infty}{}%
	\fi
}

% #1: the part before the exponent code
% #2: the part for the exponent code.
\def\pgfmathfloatrounddisplaystyle@shared@impl@#1#2{%
	{\toks0={#1}%
	\toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
	\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
	}%
	\let\pgfmathresult=\pgfmathfloat@glob@TMP
}%
% Same as \pgfmathfloatrounddisplaystyle@shared@impl@, but it also
% inserts the '@dec sep mark' at the end.
\def\pgfmathfloatrounddisplaystyle@shared@impl@@#1#2{%
	{\toks0={#1}%
	\toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
	\pgfkeysgetvalue{/pgf/number format/@dec sep mark}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK
	\toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}%
	\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }%
	}%
	\let\pgfmathresult=\pgfmathfloat@glob@TMP
}

\def\pgfmathfloatrounddisplaystyle@std#1#2e#3\relax{%
	\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{\cdot}{}{10^{#3}}%
}
\def\pgfmathfloatrounddisplaystyle@subscript#1#2e#3\relax{%
	\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}{_{#3}}%
}
\def\pgfmathfloatrounddisplaystyle@superscript#1#2e#3\relax{%
	\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}{^{#3}}%
}
\def\pgfmathfloatrounddisplaystyle@e#1#2e#3\relax{%
	\ifnum#3<0\relax
		{\count0=#3\relax
		\multiply\count0 by-1
		\xdef\pgfmathfloat@glob@TMP{e{-}\the\count0}%
		}%
		\let\pgfmathresult=\pgfmathfloat@glob@TMP
	\else
		\def\pgfmathresult{e{+}#3}%
	\fi
	\def\pgfmathfloat@loc@TMPb{\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}}%
	\expandafter\pgfmathfloat@loc@TMPb\expandafter{\pgfmathresult}%
}
\def\pgfmathfloatrounddisplaystyle@E#1#2e#3\relax{%
	\ifnum#3<0\relax
		{\count0=#3\relax
		\multiply\count0 by-1
		\xdef\pgfmathfloat@glob@TMP{E{-}\the\count0}%
		}%
		\let\pgfmathresult=\pgfmathfloat@glob@TMP
	\else
		\def\pgfmathresult{E{+}#3}%
	\fi
	\def\pgfmathfloat@loc@TMPb{\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}}%
	\expandafter\pgfmathfloat@loc@TMPb\expandafter{\pgfmathresult}%
}

\def\pgfmathfloatrounddisplaystyle@generic#1#2e#3\relax{%
	\begingroup
	\pgfkeysvalueof {/pgf/number format/sci generic/@/.@cmd}{#3}{#1}{#2}\pgfeov
	\pgfkeysgetvalue{/pgf/number format/sci generic/mantissa sep}\pgfmathdisplay@aftermantissa
	\pgfkeysgetvalue{/pgf/number format/sci generic/empty mantissa sep}\pgfmathdisplay@nomantissa
	\pgfkeysgetvalue{/pgf/number format/sci generic/exponent}\pgfmathdisplay@e
	\toks0=\expandafter{\pgfmathdisplay@aftermantissa}%
	\toks1=\expandafter{\pgfmathdisplay@nomantissa}%
	\toks2=\expandafter{\pgfmathdisplay@e}%
	\xdef\pgfmathfloat@glob@TMP{\noexpand\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\noexpand\relax{\the\toks0}{\the\toks1}{\the\toks2}}%
	\endgroup
	\pgfmathfloat@glob@TMP
}

% A macro which takes the argument '<SIGN><MANTISSE>e<EXPONENT>' and
% expands to the final TeX-representation for that floating point
% number.
%
% PRECONDITION:
%   the floating point number has already been rounded properly and
%   the mantissa has been rounded correcty.
%
% The argument needs to be in the format returned by
% \pgfmathfloat@to@FMeE@style and terminated by '\relax'.
\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std
\newif\ifpgfmathfloat@usezerofill@sci
\newif\ifpgfmathfloat@usezerofill@fixed
\newif\ifpgfmathprintnumber@assumemathmode
\newif\ifpgfmathprintnumber@showpositive
\newif\ifpgfmathprintnumber@frac@warn
\newif\ifpgfmathprintnumber@frac@whole

\long\def\pgfmathfloatfrac@verbatim#1#2{#1/#2}%

\pgfkeys{%
	/pgf/number format/.is family,
	/pgf/number format,
	fixed/.code=			\pgfmath@set@number@printer{pgfmathprintnumber@FIXED},
	sci/.code=				\pgfmath@set@number@printer{pgfmathprintnumber@SCI},
	std/.code=				{\pgfmath@set@number@printer{pgfmathprintnumber@STD}\pgfmathprintnumber@STD@setparam{#1}},
	std/.default=,%
	int detect/.code=		\pgfmath@set@number@printer{pgfmathprintnumber@INT@DETECT},
	int trunc/.code=		\pgfmath@set@number@printer{pgfmathprintnumber@INT@TRUNC},
	frac/.code=				\pgfmath@set@number@printer{pgfmathprintnumber@frac},%
	frac TeX/.initial=\frac,
	frac whole format/.code={\def\pgfmathresult{#1}},
	frac denom/.initial=,
	frac whole/.is if=pgfmathprintnumber@frac@whole,
	frac whole=true,
	frac shift/.initial=4,
	frac warning/.is if=pgfmathprintnumber@frac@warn,
	frac warning=true,
	assume math mode/.is if=pgfmathprintnumber@assumemathmode,
	assume math mode/.default=true,
	fixed zerofill/.is if=	pgfmathfloat@usezerofill@fixed,
	fixed zerofill/.default=true,
	sci zerofill/.is if=	pgfmathfloat@usezerofill@sci,
	sci zerofill/.default=true,
	zerofill/.style=		{/pgf/number format/fixed zerofill=#1,/pgf/number format/sci zerofill=#1},
	zerofill/.default=		true,
	precision/.store in=	\pgfmathfloat@round@precision,
	sci precision/.code={%
		\edef\pgfmathfloat@loc@TMPa{#1}%
		\ifx\pgfmathfloat@loc@TMPa\pgfutil@empty
			\def\pgfmathprintnumber@sci@precision{\pgfmathfloat@round@precision}%
		\else
			\let\pgfmathprintnumber@sci@precision=\pgfmathfloat@loc@TMPa
		\fi
	},%
	sci precision/.default=,
	sci precision=,
	fixed default/.code=		{\let\pgfmathprintnumber@fixed@style=\pgfmathprintnumber@fixed@styleDEFAULT},
	set decimal separator/.initial=,
	dec sep/.style={/pgf/number format/set decimal separator=#1},
	@dec sep mark/.initial=,
	@sci exponent mark/.initial=,
	set thousands separator/.initial=,
	1000 sep/.style={/pgf/number format/set thousands separator=#1},
	min exponent for 1000 sep/.initial=0,
	use period/.style=		{/pgf/number format/set decimal separator={.},/pgf/number format/set thousands separator={{{,}}}},
	use comma/.style=		{/pgf/number format/set decimal separator={{{,}}},/pgf/number format/set thousands separator={.}},
	showpos/.is if=pgfmathprintnumber@showpositive,
	showpos/.default=true,
	print sign/.is if=pgfmathprintnumber@showpositive,
	print sign/.default=true,
	skip 0./.is if=pgfmathprintnumberskipzeroperiod,
	skip 0./.default=true,
	skip 0.= false,
	use period,
	sci 10^e/.code=			{\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std},
	sci 10e/.code=			{\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std},
	sci e/.code=			{\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@e},
	sci E/.code=			{\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@E},
	sci subscript/.code=	{\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@subscript},
	sci superscript/.code=	{\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@superscript},
	sci generic/.code=		{%
		\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@generic
		\pgfkeysdefargs{/pgf/number format/sci generic/@}%
			{##1##2##3}%
			{\pgfqkeys{/pgf/number format/sci generic}{#1}}%
	},
	sci generic/mantissa sep/.initial=,%
	sci generic/empty mantissa sep/.initial=,%
	sci generic/mantisse sep/.style={/pgf/number format/sci generic/mantissa sep={#1}},%
	sci generic/empty mantisse sep/.style={/pgf/number format/sci generic/empty mantissa sep={#1}},%
	sci generic/exponent/.initial=,%
	sci generic/.value required,
	verbatim/.code={%
		\pgfqkeys{/pgf/number format}{%
			sci generic={mantissa sep=,exponent={e##1}},
			1000 sep=,
			skip 0.=false,
			print sign=false,
			dec sep=.,
			assume math mode,
			frac TeX=\pgfmathfloatfrac@verbatim,
			frac whole format/.code={\def\pgfmathresult{##1 }},
			@dec sep mark=,
			@sci exponent mark=,
		}%
	},
%	sci may skip mantissa/.is if=pgfmathfloatround@allow@empty@mantissa,
%	sci may skip mantissa/.default=true,
}



\def\pgfmathprintnumber@STD#1{%
	% parse the input:
	\pgfmathfloatparsenumber{#1}%
	\pgfmathfloat@to@FMeE@style\pgfmathresult
	\expandafter\pgfmathprintnumber@STD@issci\pgfmathresult\relax
}

\def\pgfmathprintnumber@STD@setparam#1{%
	\edef\pgfmathfloat@loc@TMPb{#1}%
	\ifx\pgfmathfloat@loc@TMPb\pgfutil@empty
		% DEFAULT for lower and upper bound.
		\def\pgfmathprintnumber@STD@getlowerbound{%
			\c@pgf@counta=\pgfmathfloat@round@precision\relax
			\divide\c@pgf@counta by-2\relax
		}%
		\def\pgfmathprintnumber@STD@upperbound{4}%
	\else
		\expandafter\pgfutil@in@\expandafter:\expandafter{\pgfmathfloat@loc@TMPb}%
		\ifpgfutil@in@
			% we have -4:5 or something like that.
			% parse both values:
			\def\pgfmathfloat@loc@TMPa##1:##2\relax{%
				\edef\pgfmathprintnumber@STD@getlowerbound{%
					\noexpand\c@pgf@counta=##1\space
				}%
				\edef\pgfmathprintnumber@STD@upperbound{##2}%
			}%
			\expandafter\pgfmathfloat@loc@TMPa\pgfmathfloat@loc@TMPb\relax
		\else
			% we have just the lower bound:
			\def\pgfmathprintnumber@STD@upperbound{4}%
			\edef\pgfmathprintnumber@STD@getlowerbound{%
				\noexpand\c@pgf@counta=\pgfmathfloat@loc@TMPb\space
			}%
		\fi
	\fi
}%

\def\pgfmathprintnumber@STD@issci#1#2e#3\relax{%
	\expandafter\ifnum#1<3
		\expandafter\ifnum#3>\pgfmathprintnumber@STD@upperbound\relax
			\pgfmathprintnumber@SCI@issci#1#2e#3\relax%
		\else
			\begingroup
			\pgfmathprintnumber@STD@getlowerbound
			\ifnum#3<\c@pgf@counta
				\pgfmathprintnumber@SCI@issci#1#2e#3\relax%
			\else
				\pgfmathprintnumber@FIXED@issci#1#2e#3\relax%
			\fi
			\pgfmath@smuggleone\pgfmathresult
			\endgroup
		\fi
	\else% nan or inf:
		\pgfmathfloatrounddisplaystyle#1#2e#3\relax%
	\fi
}

\def\pgfmathprintnumber@frac#1{%
	% parse the input:
	\pgfmathfloatparsenumber{#1}%
	\pgfmathfloatgetfrac{\pgfmathresult}%
	\expandafter\pgfmathprintnumber@frac@formatresult\pgfmathresult
}
\def\pgfmathprintnumber@frac@issci#1#2e#3\relax{%
	\pgfmathfloatcreate{#1}{#2}{#3}%
	\pgfmathfloatgetfrac{\pgfmathresult}%
	\expandafter\pgfmathprintnumber@frac@formatresult\pgfmathresult
}
\def\pgfmathprintnumber@frac@formatresult#1#2#3{%
	\begingroup
	\pgfkeysgetvalue{/pgf/number format/frac TeX}\pgfmathresult
	\toks0=\expandafter{\pgfmathresult}%
	\def\pgfmathfloat@loc@TMPa{#1}%
	\ifx\pgfmathfloat@loc@TMPa\pgfutil@empty
		\ifpgfmathprintnumber@showpositive
			\def\pgfmathfloat@loc@TMPa{+}%
		\fi
	\else
		\ifx\pgfmathfloat@loc@TMPa-%
		\else
			\ifx\pgfmathfloat@loc@TMPa+%
			\else
				\ifpgfmathprintnumber@showpositive
					\edef\pgfmathfloat@loc@TMPa{+\pgfmathfloat@loc@TMPa}%
				\fi
				\def\pgfmathfloat@loc@TMPb{\pgfkeysvalueof{/pgf/number format/frac whole format/.@cmd}}%
				\expandafter\pgfmathfloat@loc@TMPb\pgfmathfloat@loc@TMPa\pgfeov
				\let\pgfmathfloat@loc@TMPa=\pgfmathresult
			\fi
		\fi
	\fi
	\toks1=\expandafter{\pgfmathfloat@loc@TMPa}%
	\edef\pgfmathresult{%
		\the\toks1 \ifnum#2=0 \else\the\toks0 {#2}{#3}\fi%
	}%
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}%

% Defines \pgfmathresult to contain three sets of braces containing
% the sign (optionally containing any components >1), the numerator and the denominator for #1.
%
% \pgfmathfloatgetfrac{0.5}  -> \pgfmathresult contains {}{1}{2}
% \pgfmathfloatgetfrac{-0.5} -> \pgfmathresult contains {-}{1}{2}
% \pgfmathfloatgetfrac{1.5} ->  \pgfmathresult contains {1}{1}{2}
%
% special cases:
% \pgfmathfloatgetfrac{0}   ->  \pgfmathresult contains {0}{0}{1}
% \pgfmathfloatgetfrac{1}   ->  \pgfmathresult contains {1}{0}{1}
%
% The numerator and denominator is always a number (not empty)
\def\pgfmathfloatgetfrac#1{%
	\pgfutil@ifundefined{pgfmathfloatmultiply@}{%
		\PackageError{tikz}{Sorry, the number format 'frac' requires '\string\usetikzlibrary{fpu}' (and, optionally, \string\usepackage{fp}) in order to work correctly}{}%
		\edef\pgfmathresult{{#1}{0}{1}}%
	}{%
		\pgfmathfloatgetfrac@{#1}%
	}%
}%
\def\pgfmathfloatgetfrac@#1{%
	\begingroup
		\edef\pgfmathfloat@arg{#1}%
		\expandafter\pgfmathfloat@decompose@tok\pgfmathfloat@arg\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
		\def\pgfmathfloat@loc@TMPa{0}%
		\ifcase\pgfmathfloat@a@S
		% #1 = 0:
			\def\pgfmathresult{{0}{0}{1}}%
		\or% #1 > 0
			\pgfmathfloat@a@S=1
			\def\pgfmathfloat@loc@TMPa{1}%
		\or% #1 < 0
			\pgfmathfloat@a@S=-1
			\def\pgfmathfloat@loc@TMPa{1}%
		\or
			\edef\pgfmathresult{{}{NaN}{1}}%
		\or
			\edef\pgfmathresult{{}{\infty}{1}}%
		\or
			\edef\pgfmathresult{{-}{\infty}{1}}%
		\fi
		\if1\pgfmathfloat@loc@TMPa
			\ifnum\pgfmathfloat@a@E<0
				\def\pgfmathfloat@wholenumber{}%
			\else
				\pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
				\pgfmathfloattofixed\pgfmathresult%
				\def\pgfmathfloat@loc@TMPa##1.##2\relax{%
					\def\pgfmathfloat@wholenumber{##1}%
					\pgfmathfloatparsenumber{0.##2}%
				}%
				\expandafter\pgfmathfloat@loc@TMPa\pgfmathresult\relax
				\expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@b@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
			\fi
			%
			\def\pgfmathfloat@loc@TMPa##1.##2\relax{%
				\def\pgfmathfloat@mantissa@first{##1}%
				\def\pgfmathfloat@mantissa@ltone{0.##2}%
			}%
			\expandafter\pgfmathfloat@loc@TMPa\the\pgfmathfloat@a@Mtok\relax
			%
			\def\pgfmathfloat@loc@@to@int##1.##2\relax##3{%
				##3=##1
				\ifdim0.##2pt>0.5pt
					\advance##3 by1
				\fi
			}%
			%
			% alias registers names:
			\let\pgfmathresultnumerator=\pgfmathfloat@b@S
			\let\pgfmathresultdenom=\pgfmathfloat@b@E
			%
			\pgfkeysgetvalue{/pgf/number format/frac denom}\pgfmath@target@denominator
			\ifx\pgfmath@target@denominator\pgfutil@empty
			%
				\pgfmathfloat@a@E=-\pgfmathfloat@a@E
				\ifdim\pgfmathfloat@mantissa@ltone pt=0pt
					\def\pgfmathfloat@factor{1}%
					\edef\pgfmathfloat@scaled@numerator{\the\pgfmathfloat@a@Mtok}%
				\else
					% FIXME : this here is numerically instable.
					%
					% The errors of 1/r are magnified by 10^k which
					% doesn't work.
					\pgfutil@ifundefined{FPdiv}{%
						\pgfmathfloatparsenumber{\pgfmathfloat@mantissa@ltone}%
						\pgfmathfloatreciprocal@{\pgfmathresult}%
					}{%
						% \usepackage{fp}.
						% yields higher absolute precision.
						\FPmessagesfalse%
						\FPdebugfalse%
						\FPdiv\pgfmathresult{1}{\pgfmathfloat@mantissa@ltone}%
						\pgfmathfloatparsenumber{\pgfmathresult}%
					}%
					\let\pgfmathfloat@inv=\pgfmathresult
					\pgfmathfloatcreate{1}{1.0}{\pgfkeysvalueof{/pgf/number format/frac shift}}%
					\let\pgfmathfloat@scalebaseten=\pgfmathresult
					\pgfmathfloatmultiply@{\pgfmathfloat@inv}{\pgfmathfloat@scalebaseten}%
					\let\pgfmathfloat@factor=\pgfmathresult
					%
					\expandafter\pgfmathfloatparsenumber\expandafter{\the\pgfmathfloat@a@Mtok}%
					\let\pgfmathfloat@loc@TMPa=\pgfmathresult
					\pgfmathfloatmultiply@{\pgfmathfloat@factor}{\pgfmathfloat@loc@TMPa}%
					\pgfmathfloattofixed\pgfmathresult
					\let\pgfmathfloat@scaled@numerator=\pgfmathresult
					%
					\pgfmathfloattofixed\pgfmathfloat@factor
					\expandafter\pgfmathfloat@loc@@to@int\pgfmathresult\relax{\pgfmathfloat@b@S}%
					\edef\pgfmathfloat@factor{\the\pgfmathfloat@b@S}%
				\fi
				%
				%
				\pgfmathresultdenom=\pgfmathfloat@factor\relax
				\pgfmathfloat@multiply@ten@to@the@E\pgfmathresultdenom
				%
				\expandafter\pgfmathfloat@loc@@to@int\pgfmathfloat@scaled@numerator\relax{\pgfmathresultnumerator}%
	%\message{scale = \pgfmathfloat@factor;  Z = \the\pgfmathresultnumerator\space ( von \pgfmathfloat@scaled@numerator), N = \the\pgfmathresultdenom.}%
				%
				\pgfmathgreatestcommondivisor{\pgfmathresultnumerator}{\pgfmathresultdenom}%
				\divide\pgfmathresultnumerator by\pgfmathresult\relax
				\divide\pgfmathresultdenom by\pgfmathresult\relax
				\ifpgfmathprintnumber@frac@warn
					\ifnum\pgfmathresultdenom>1000
						\pgfutil@ifundefined{FPdiv}{%
							\pgfmathfloattosci@\pgfmathfloat@arg
							\immediate\write16{! Package pgf /pgf/number format/frac warning=true: /pgf/number format/frac of `\pgfmathresult' = \the\pgfmathresultnumerator\space / \the\pgfmathresultdenom\space might be large due to instabilities. Try \string\usepackage{fp} to improve accuracy.}%
						}{}%
					\fi
				\fi
			\else
				% use target denominator:
				\pgfmathresultdenom=\pgfmath@target@denominator\relax
				\pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
				\pgfmathfloattofixed\pgfmathresult
				\pgf@xa=\pgfmathresult pt
				\multiply\pgf@xa by\pgfmathresultdenom
				\edef\pgfmathfloat@scaled@numerator{\pgf@sys@tonumber\pgf@xa}%
				\expandafter\pgfmathfloat@loc@@to@int\pgfmathfloat@scaled@numerator\relax{\pgfmathresultnumerator}%
			\fi
			\ifpgfmathprintnumber@frac@whole
			\else
				\ifx\pgfmathfloat@wholenumber\pgfutil@empty
				\else
					\count0=\pgfmathfloat@wholenumber\relax
					\multiply\count0 by\pgfmathresultdenom
					\advance\pgfmathresultnumerator by\count0
					\def\pgfmathfloat@wholenumber{}%
				\fi
			\fi
			\ifnum\pgfmathfloat@a@S<0
				\edef\pgfmathresult{{-\pgfmathfloat@wholenumber}{\the\pgfmathresultnumerator}{\the\pgfmathresultdenom}}%
			\else
				\edef\pgfmathresult{{\pgfmathfloat@wholenumber}{\the\pgfmathresultnumerator}{\the\pgfmathresultdenom}}%
			\fi
		\fi
		\pgfmath@smuggleone\pgfmathresult
	\endgroup
}%
\def\pgfmathfloat@gobble@until@relax#1\relax{}

% computes the greatest common divisor of two integer numbers (in
% integer arithmetics).
\def\pgfmathgreatestcommondivisor#1#2{%
	\begingroup
		\count0=#1\relax
		\count1=#2\relax
		\ifnum\count0=0
			\edef\pgfmathresult{\the\count1}%
		\else
			\pgfmathgreatestcommondivisor@loop
			\edef\pgfmathresult{\the\count0}%
		\fi
		\pgfmath@smuggleone\pgfmathresult
	\endgroup
}
\def\pgfmathgreatestcommondivisor@loop{%
	\ifnum\count1=0
	\else
		\ifnum\count0>\count1
			\advance\count0 by-\count1
		\else
			\advance\count1 by-\count0
		\fi
		\expandafter\pgfmathgreatestcommondivisor@loop
	\fi
}%

% multiplies a TeX register by 10^E where E is stored in the register
% \pgfmathfloat@a@E (and it should be positive!)%
%
% #1 a TeX register
\def\pgfmathfloat@multiply@ten@to@the@E#1{%
	\ifnum\pgfmathfloat@a@E>0
		\multiply#1 by10
		\advance\pgfmathfloat@a@E by-1
		\def\pgfmathfloat@multiply@ten@to@the@E@next{\pgfmathfloat@multiply@ten@to@the@E{#1}}%
	\else
		\let\pgfmathfloat@multiply@ten@to@the@E@next=\relax%
	\fi
	\pgfmathfloat@multiply@ten@to@the@E@next
}%

\def\pgfmathprintnumber@INT@TRUNC#1{%
	\pgfmathfloatparsenumber{#1}%
	\pgfmathfloat@to@FMeE@style\pgfmathresult
	\expandafter\pgfmathprintnumber@INT@TRUNC@issci\pgfmathresult\relax
}

\def\pgfmathprintnumber@INT@TRUNC@impl#1.#2\relax#3#4e#5\relax{%
	\pgfmathfloatroundhasperiodfalse
	\pgfmathprintnumber@fixed@style{#1}#3#4e#5\relax%
}
\def\pgfmathprintnumber@INT@TRUNC@issci#1#2e#3\relax{%
	\ifnum#1<3\relax
		\pgfmathfloatcreate{#1}{#2}{#3}%
		\pgfmathfloattofixed{\pgfmathresult}%
		\expandafter\pgfmathprintnumber@INT@TRUNC@impl\pgfmathresult\relax#1#2e#3\relax
	\else
		\pgfmathfloatrounddisplaystyle#1#2e#3\relax%
	\fi
}

% Invokes '#2' if '#1' is actually an integer or '#3' if not.
%
% As a side--effect, \pgfretval will be set to the integer value if it
% actually *is* an integer. Otherwise, \pgfretval will contain the
% parsed floating point number.
%
% #1 a number constant (not necessarily a parsed float).
\def\pgfmathifisint#1#2#3{%
	\gdef\pgfmathfloatisint@@{0}%
	\begingroup
	\pgfmathfloatparsenumber{#1}%
	\let\pgfretval\pgfmathresult
	\pgfmathfloat@to@FMeE@style\pgfmathresult
	\expandafter\pgfmathfloatisint@\pgfmathresult\relax
	\pgfmath@smuggleone\pgfretval
	\endgroup
	\if1\pgfmathfloatisint@@ #2\else #3\fi
}%
\def\pgfmathfloatisint@#1#2e#3\relax{%
	\ifnum#1<3\relax
		\pgfmathfloatcreate{#1}{#2}{#3}%
		\pgfmathfloattofixed{\pgfmathresult}%
		\def\pgfmathfloat@round@precision{6}%
		\expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
		\ifpgfmathfloatroundhasperiod
		\else
			\let\pgfretval\pgfmathresult%
			\gdef\pgfmathfloatisint@@{1}%
		\fi
	\fi
}

\def\pgfmathprintnumber@INT@DETECT#1{%
	\pgfmathfloatparsenumber{#1}%
	\pgfmathfloat@to@FMeE@style\pgfmathresult
	\expandafter\pgfmathprintnumber@INT@DETECT@issci\pgfmathresult\relax
}

\def\pgfmathprintnumber@INT@DETECT@issci#1#2e#3\relax{%
	\begingroup
	\ifnum#1<3\relax
		\pgfmathfloatcreate{#1}{#2}{#3}%
		\pgfmathfloattofixed{\pgfmathresult}%
		\let\pgfmathfloat@round@precision@=\pgfmathfloat@round@precision
		\def\pgfmathfloat@round@precision{6}%
		\expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
		\let\pgfmathfloat@round@precision=\pgfmathfloat@round@precision@
		\ifpgfmathfloatroundhasperiod
			\pgfmathprintnumber@SCI@issci#1#2e#3\relax
		\else
			\expandafter\pgfmathprintnumber@fixed@style\expandafter{\pgfmathresult}#1#2e#3\relax
		\fi
	\else
		\pgfmathfloatrounddisplaystyle#1#2e#3\relax%
	\fi
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

\def\pgfmathprintnumber@FIXED#1{%
	\pgfmathfloatparsenumber{#1}%
	\pgfmathfloat@to@FMeE@style\pgfmathresult
	\expandafter\pgfmathprintnumber@FIXED@issci\pgfmathresult\relax
}

\def\pgfmathprintnumber@FIXED@issci#1#2e#3\relax{%
	\begingroup
	\ifnum#1<3
		\pgfmathfloatcreate{#1}{#2}{#3}%
		\pgfmathfloattofixed{\pgfmathresult}%
		\ifpgfmathfloat@usezerofill@fixed
			\expandafter\pgfmathroundtozerofill\expandafter{\pgfmathresult}%
		\else
			\expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
		\fi
		\ifpgfmathfloatroundmayneedrenormalize
			\pgfmathfloat@a@E=#3\relax
			\advance\pgfmathfloat@a@E by1
			\edef\pgfmathfloat@loc@TMPb{\noexpand\pgfmathprintnumber@fixed@style{\pgfmathresult}#1#2e\the\pgfmathfloat@a@E}%
			\pgfmathfloat@loc@TMPb\relax%
		\else
			\expandafter\pgfmathprintnumber@fixed@style\expandafter{\pgfmathresult}#1#2e#3\relax%
		\fi
	\else% nan or inf:
		\pgfmathfloatrounddisplaystyle#1#2e#3\relax%
	\fi
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}


\def\pgfmathprintnumber@SCI#1{%
	\pgfmathfloatparsenumber{#1}%
	\pgfmathfloat@to@FMeE@style\pgfmathresult
	\expandafter\pgfmathprintnumber@SCI@issci\pgfmathresult\relax
}

\def\pgfmathprintnumber@SCI@issci#1#2e#3\relax{%
	\begingroup
	\pgfmathfloatcreate{#1}{#2}{#3}%
	\edef\pgfmathfloat@round@precision{\pgfmathprintnumber@sci@precision}%
	\ifpgfmathfloat@usezerofill@sci
		\pgfmathfloatroundzerofill{\pgfmathresult}%
	\else
		\pgfmathfloatround{\pgfmathresult}%
	\fi
	\pgfmathfloat@to@FMeE@style\pgfmathresult
	\expandafter\pgfmathfloatrounddisplaystyle\pgfmathresult\relax
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

% Prints argument #1 using the current pretty printer environment (all
% variables in /pgf/number format).
%
% You may specify optional arguments with \pgfmathprintnumber[...].
\def\pgfmathprintnumber{%
	% \protect allows to supply \pgfmathprintnumber inside of latex
	% captions. The \csname yields \relax in case protect is undefined.
	\pgf@texdist@protect\pgfmathprintnumber@protected
}%
\def\pgfmathprintnumber@protected{%
	\pgfutil@ifnextchar[%
		{\pgfmathprintnumber@OPT}%
		{\pgfmathprintnumber@noopt}%
}

\def\pgfmathprintnumber@noopt#1{%
	\pgfmathprintnumber@{#1}%
	\ifpgfmathprintnumber@assumemathmode
		\pgfmathresult
	\else
		\pgfutilensuremath{\pgfmathresult}%
	\fi
}%
\def\pgfmathprintnumber@OPT[#1]#2{%
	\begingroup
	\pgfqkeys{/pgf/number format}{#1}%
	\pgfmathprintnumber@{#2}%
	\ifpgfmathprintnumber@assumemathmode
		\pgfmathresult
	\else
		\pgfutilensuremath{\pgfmathresult}%
	\fi
	\endgroup
}%

% As \pgfmathprintnumber, but it produces its output into the second
% argument.
\def\pgfmathprintnumberto{%
	\pgfutil@ifnextchar[%
		{\pgfmathprintnumberto@OPT}%
		{\pgfmathprintnumberto@noopt}%
}

\def\pgfmathprintnumberto@noopt#1#2{%
	\begingroup
	\pgfmathprintnumber@{#1}%
	\ifpgfmathprintnumber@assumemathmode
		\global\let\pgfmathfloat@glob@TMP=\pgfmathresult
	\else
		\toks0=\expandafter{\pgfmathresult}%
		\xdef\pgfmathfloat@glob@TMP{\noexpand\pgfutilensuremath{\the\toks0 }}%
	\fi
	\endgroup
	\let#2=\pgfmathfloat@glob@TMP
}%
\def\pgfmathprintnumberto@OPT[#1]#2#3{%
	\begingroup
	\pgfqkeys{/pgf/number format}{#1}%
	\pgfmathprintnumber@{#2}%
	\ifpgfmathprintnumber@assumemathmode
		\global\let\pgfmathfloat@glob@TMP=\pgfmathresult
	\else
		\toks0=\expandafter{\pgfmathresult}%
		\xdef\pgfmathfloat@glob@TMP{\noexpand\pgfutilensuremath{\the\toks0 }}%
	\fi
	\endgroup
	\let#3=\pgfmathfloat@glob@TMP
}%
	

% Changes the current number pretty printer to #1.
%
% #1 is the macro base name for the pretty print routine, without the
% leading '\'.
\def\pgfmath@set@number@printer#1{%
	\expandafter\let\expandafter\pgfmathprintnumber@\csname #1\endcsname
	\expandafter\let\expandafter\pgfmathprintnumber@issci\csname #1@issci\endcsname
}

\pgfkeys{/pgf/number format/std}

%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% IMPL
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

% equals only itsself when compared with \ifx:
\def\pgfmathfloat@EOI{\pgfmathfloat@EOI}%

% Re-use counters internally.
%
% They are always grouped and only used inside of the rounding
% routines.
\let\c@pgfmathroundto@prec=\pgfmathfloat@b@S% ATTENTION: DOUBLE-USED REGISTERS!
\let\c@pgfmathroundto@offsetbehindperiod=\pgfmathfloat@b@E
\newcount\c@pgfmathroundto@lastzeros

\newif\ifpgfmathround@impl@PREPERIOD@is@negative@zero

% PRECONDITION:
%  	\ifpgfmathfloatroundhasperiod=\iftrue  holds outside of the
%  	current TeX group.
%
% POSTCONDITION:
%   \ifpgfmathfloatroundhasperiod will be set correctly AFTER the
%   current TeX group.
%   \ifpgfmathfloatroundmayneedrenormalize will be set globally
\def\pgfmathroundto@impl#1{%
	\edef\pgfmathround@input{#1}%
	\global\pgfmathfloatroundmayneedrenormalizefalse
	\pgfmathfloat@tmptoks={}%
	\let\pgfmathround@next=\pgfutil@empty
	\let\pgfmathround@cur=\pgfutil@empty
	\let\pgfmathresult=\pgfutil@empty
	\expandafter\c@pgfmathroundto@prec\pgfmathfloat@round@precision\relax
	\c@pgfmathroundto@lastzeros=0
	\c@pgfmathroundto@offsetbehindperiod=-1 % means: no period found so far
	\pgfmathround@impl@PREPERIOD@is@negative@zerotrue
	\expandafter\pgfmathroundto@impl@ITERATE@NODOT@firstcall\pgfmathround@input\pgfmathfloat@EOI
}

% \pgfmathroundto implementation in WORDS:
%
% coarse idea: 
%    1. collect all digits/sign BEFORE the first period in REVERSE order
%    2. then, collect UP TO \prec digits after the period in REVERSE order
% Steps 1. and 2. lead to the digit [sign] sequence
%    "x_{-p} x_{-p+1} ... x_{-2} x_{-1} '.' x_0 ... x_r"
% where 'r' is the total number of digits. The integer 'p' denotes the
% ACTUALLY collected number of digits behind the period.
%
% Let 'k' be the desired precision.
%
% Please note that pgfmathroundto rounds the mantissa, that means |abs(x)|.
%
% There are exactly TWO cases:
% 1. The case with p<=k and x_{-p-1} = end of input.
% 2. The case with p=k and x_{-p-1} is a further, next character.
%
% Then, for case 1.):
% 	discard any unused zeros at the tail of our number (possibly
% 	including the period)
%
% and in case 2.)
%   if NEXT DIGIT < 5:
%       do exactly the same as in case 1.) above and discard any
%       following digits.
%   else
%   	let q := -p
%   	while(x_q = 9 and q<=r )
%   		if q>=0
%   			set x_q = '0'
%   		else
%   			discard digit x_q='9'
%   		fi
%   		++q
%   		if q=0
%   			discard the period 
%   		fi
%   	end while
%   	if q = r+1
%   		insert a '1'
%   	else
%   		set x_q = x_q + 1
%   	fi
%   fi
%
% All these loops have been implemented in spaghetti-code below.
% Sorry, I fear its hard to understand. In principle, everything is
% realised using more or less finite state machines (with some number
% counting logic).
%
% Some comments:
%   - The token register \pgfmathfloat@tmptoks is used to accumulate the REVERSED input number.
%	- \pgfmathfloat@EOI always denotes 'END OF INPUT'.
%	- in the second stage, we need to reverse \pgfmathfloat@tmptoks.
%	  This is -again- done with \pgfmathfloat@tmptoks.

\def\pgfmathroundto@impl@discard@period#1.#2\pgfmathfloat@EOI{%
	\pgfmathfloatroundhasperiodfalse
	\aftergroup\pgfmathfloatroundhasperiodfalse
	\def\pgfmathresult{#1}%
}

\def\pgfmathroundto@impl@gobble@rest@and@start#1\pgfmathfloat@EOI{%
	\pgfmathroundto@impl@start
}
\def\pgfmathroundto@impl@gobble@and@start\pgfmathfloat@EOI{%
	\pgfmathroundto@impl@start
}
\def\pgfmathroundto@impl@gobble\pgfmathfloat@EOI{}%
\def\pgfmathroundto@impl@gobble@rest#1\pgfmathfloat@EOI{}%

% This method will be invoked as soon as the first step, the reverse
% collection of up to PREC digits after the period, has finished.
\def\pgfmathroundto@impl@start{%
	\ifx\pgfmathround@next\pgfutil@empty
		\ifnum\c@pgfmathroundto@offsetbehindperiod<0
			% no period found.
			\ifpgfmathfloat@fixed@digits@after@period
				\ifnum\c@pgfmathroundto@prec=0\relax
					\pgfmathfloatroundhasperiodfalse
					\aftergroup\pgfmathfloatroundhasperiodfalse
					\edef\pgfmathresult{\pgfmathround@input}%
				\else
					\pgfmathfloat@tmptoks=\expandafter{\pgfmathround@input.}%
					\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
					\pgfmathroundto@impl@append@zeros
					\edef\pgfmathresult{\the\pgfmathfloat@tmptoks}%
				\fi
			\else
				\pgfmathfloatroundhasperiodfalse
				\aftergroup\pgfmathfloatroundhasperiodfalse
				\edef\pgfmathresult{\pgfmathround@input}%
			\fi
		\else
			%\ifnum\c@pgfmathroundto@offsetbehindperiod>\c@pgfmathroundto@prec
			%	\pgfmath@error{Internal logic error in pgfmathroundto at [I] - should not have happened!?}{}%
			%\fi
			\pgfmathroundto@impl@finish@with@truncation
		\fi
	\else
		%\ifnum\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
		%\else
		%	\pgfmath@error{Internal logic error in pgfmathroundto at [II] - should not have happened!? I have offsetbehindperiod=\the\c@pgfmathroundto@offsetbehindperiod and prec = \the\c@pgfmathroundto@prec}{}%
		%\fi
		\expandafter\ifnum\pgfmathround@next<5\relax
			\pgfmathroundto@impl@finish@with@truncation
		\else
			\multiply\c@pgfmathroundto@offsetbehindperiod by-1
			\expandafter\pgfmathroundto@impl@ADD@ONE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
		\fi
	\fi
}
			
% takes the current input and decides whether trailing zeros shall be
% discarded or more zeros need to be filled in.
\def\pgfmathroundto@impl@finish@with@truncation{%
	\ifpgfmathfloat@fixed@digits@after@period
		\expandafter\pgfmathroundto@impl@REVERSE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
		\ifnum\c@pgfmathroundto@lastzeros=\c@pgfmathroundto@offsetbehindperiod
			\ifpgfmathround@impl@PREPERIOD@is@negative@zero
				% write '0.0000' instead of '-0.0000':
				\expandafter\pgfmathroundto@impl@discard@minus\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
			\fi
		\fi
		\ifnum\c@pgfmathroundto@prec=0\relax
			\expandafter\pgfmathroundto@impl@discard@period\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
		\else
			\advance\c@pgfmathroundto@prec by-\c@pgfmathroundto@offsetbehindperiod
			\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
			\pgfmathroundto@impl@append@zeros
			\edef\pgfmathresult{\the\pgfmathfloat@tmptoks}%
		\fi
	\else
		\pgfmathroundto@impl@discard@suffix@zeros
	\fi
}

\def\pgfmathroundto@impl@discard@minus-#1\pgfmathfloat@EOI{\pgfmathfloat@tmptoks={#1}}%

% appends \c@pgfmathroundto@offsetbehindperiod zeros at the end of \pgfmathfloat@tmptoks.
\def\pgfmathroundto@impl@append@zeros{%
	\ifnum\c@pgfmathroundto@offsetbehindperiod>0
		\pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
		\advance\c@pgfmathroundto@offsetbehindperiod by-1
		\pgfmathroundto@impl@append@zeros
	\fi
}

\def\pgfmathroundto@impl@ADD@ONE{%
	\pgfmathfloat@tmptoks={}% no longer needed because its old value will be read from input
	\pgfmathroundto@impl@ADD@ONE@ITERATE
}
\def\pgfmathroundto@impl@ADD@ONE@ITERATE{%
	\pgfutil@ifnextchar\pgfmathfloat@EOI{%
		\global\pgfmathfloatroundmayneedrenormalizetrue
		\edef\pgfmathresult{1\the\pgfmathfloat@tmptoks}%
		\pgfmathroundto@impl@gobble
	}{%
		\pgfutil@ifnextchar.{%
			\ifnum\c@pgfmathroundto@prec=0
				% silently discard period in special case precision=0
				\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot}%
			\else
				\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@NEXT@COLLECT}%
			\fi
			\pgfmathround@nextcmd
		}{%
			\pgfutil@ifnextchar+{%
				\global\pgfmathfloatroundmayneedrenormalizetrue
				\edef\pgfmathresult{1\the\pgfmathfloat@tmptoks}%
				\pgfmathroundto@impl@gobble@rest
			}{%
				\pgfutil@ifnextchar-{%
					\global\pgfmathfloatroundmayneedrenormalizetrue
					\edef\pgfmathresult{-1\the\pgfmathfloat@tmptoks}%
					\pgfmathroundto@impl@gobble@rest
				}{%
					\pgfmathroundto@impl@ADD@ONE@NEXT
				}%
			}%
		}%
	}%
}

\def\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot.{%
	\pgfmathfloatroundhasperiodfalse
	\aftergroup\pgfmathfloatroundhasperiodfalse
	\pgfmathroundto@impl@ADD@ONE@ITERATE
}

\def\pgfmathroundto@impl@ADD@ONE@NEXT@COLLECT#1{%
	\pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
	\pgfmathroundto@impl@ADD@ONE@ITERATE
}
\def\pgfmathroundto@impl@ADD@ONE@NEXT#1{%
	\ifnum#1=9
		\ifnum\c@pgfmathroundto@offsetbehindperiod<0
			\ifpgfmathfloat@fixed@digits@after@period
				\pgfmathfloat@tmptoks=\expandafter{\expandafter0\the\pgfmathfloat@tmptoks}%
			\else
				% silently DROP digit
			\fi
		\else
			\pgfmathfloat@tmptoks=\expandafter{\expandafter0\the\pgfmathfloat@tmptoks}%
		\fi
		\advance\c@pgfmathroundto@offsetbehindperiod by1
		\ifnum\c@pgfmathroundto@offsetbehindperiod=0
			\ifpgfmathfloat@fixed@digits@after@period
				\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE}%
			\else
				\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot}%
			\fi
		\else
			\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE}%
		\fi
	\else
		% re-use this counter:
		\c@pgfmathroundto@lastzeros=#1
		\advance\c@pgfmathroundto@lastzeros by1
		\edef\pgfmathresult{\the\c@pgfmathroundto@lastzeros\the\pgfmathfloat@tmptoks}%
		\pgfmathfloat@tmptoks=\expandafter{\pgfmathresult}%
		\def\pgfmathround@nextcmd{\pgfmathroundto@impl@REVERSE@ITERATE}%
	\fi
	\pgfmathround@nextcmd
}


\def\pgfmathroundto@impl@discard@suffix@zeros{%
	\ifnum\c@pgfmathroundto@lastzeros=\c@pgfmathroundto@offsetbehindperiod
		\ifpgfmathround@impl@PREPERIOD@is@negative@zero
			\pgfmathfloatroundhasperiodfalse
			\aftergroup\pgfmathfloatroundhasperiodfalse
			\def\pgfmathresult{0}% write '0' instead of '-0'
		\else
			\expandafter\pgfmathroundto@impl@discard@period\pgfmathround@input\pgfmathfloat@EOI
		\fi
	\else
		\ifnum\c@pgfmathroundto@lastzeros=0
			\expandafter\pgfmathroundto@impl@REVERSE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
		\else
			\expandafter\pgfmathroundto@impl@discard@suffix@zeros@ITERATE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
		\fi
	\fi
}

% PRECONDITION: 
%    \c@pgfmathroundto@lastzeros > 0
\def\pgfmathroundto@impl@discard@suffix@zeros@ITERATE#1{%
	\advance\c@pgfmathroundto@lastzeros by-1
	\ifnum\c@pgfmathroundto@lastzeros=0
		\def\pgfmathround@nextcmd{\pgfmathroundto@impl@REVERSE}%
	\else
		\def\pgfmathround@nextcmd{\pgfmathroundto@impl@discard@suffix@zeros@ITERATE}%
	\fi
	\pgfmathround@nextcmd
}

% Usage:
% \pgfmathroundto@impl@REVERSE#1\pgfmathfloat@EOI
% -> writes #1 reversed into \pgfmathfloat@tmptoks
\def\pgfmathroundto@impl@REVERSE{%
	\pgfmathfloat@tmptoks={}%
	\pgfmathroundto@impl@REVERSE@ITERATE
}

\def\pgfmathroundto@impl@REVERSE@ITERATE{%
	\pgfutil@ifnextchar\pgfmathfloat@EOI{%
		\edef\pgfmathresult{\the\pgfmathfloat@tmptoks}%
		\pgfmathroundto@impl@gobble
	}{%
		\pgfmathroundto@impl@REVERSE@NEXT
	}%
}

\def\pgfmathroundto@impl@REVERSE@NEXT#1{%
	\pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
	\pgfmathroundto@impl@REVERSE@ITERATE
}

\def\pgfmathroundto@impl@BEGIN@DOT.{%
	\pgfmathfloat@tmptoks=\expandafter{\expandafter.\the\pgfmathfloat@tmptoks}%
	\c@pgfmathroundto@offsetbehindperiod=0
	\pgfmathroundto@impl@ITERATE@DOT
}
\def\pgfmathroundto@impl@ITERATE@DOT{%
	\pgfutil@ifnextchar\pgfmathfloat@EOI{%
		% finished.
		\pgfmathroundto@impl@gobble@and@start
	}{%
		\pgfmathroundto@impl@NEXT@DOT
	}%
}
\def\pgfmathroundto@impl@NEXT@DOT#1{%
	\ifnum\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
		\def\pgfmathround@next{#1}%
		\def\pgfmathround@nextcmd{\pgfmathroundto@impl@gobble@rest@and@start}%
	\else
		\advance\c@pgfmathroundto@offsetbehindperiod by1
		\ifnum#1=0
			\advance\c@pgfmathroundto@lastzeros by1
		\else
			\c@pgfmathroundto@lastzeros=0
		\fi
		\pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
		\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@DOT}%
	\fi
	\pgfmathround@nextcmd
}%

% in contrast to pgfmathroundto@impl@ITERATE@NODOT, this method here
% checks also for signs
\def\pgfmathroundto@impl@ITERATE@NODOT@firstcall#1{%
	\def\pgfmathround@cur{#1}%
	\ifx\pgfmathround@cur\pgfmathfloat@EOI
		\pgfmathround@impl@PREPERIOD@is@negative@zerofalse
		\def\pgfmathround@nextcmd{\pgfmathroundto@impl@start}%
	\else
		\ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@PERIOD
			\pgfmathround@impl@PREPERIOD@is@negative@zerofalse
			\def\pgfmathround@nextcmd{\pgfmathroundto@impl@BEGIN@DOT.}%
		\else
			\ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@MINUS
			\else
				\pgfmathround@impl@PREPERIOD@is@negative@zerofalse
			\fi
			\pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
			\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@NODOT}%
		\fi
	\fi
	\pgfmathround@nextcmd
}

\def\pgfmathroundto@impl@ITERATE@NODOT#1{%
	\def\pgfmathround@cur{#1}%
	\ifx\pgfmathround@cur\pgfmathfloat@EOI
		\def\pgfmathround@nextcmd{\pgfmathroundto@impl@start}%
	\else
		\ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@PERIOD
			\def\pgfmathround@nextcmd{\pgfmathroundto@impl@BEGIN@DOT.}%
		\else
			\ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@ZERO
			\else
				\pgfmathround@impl@PREPERIOD@is@negative@zerofalse
			\fi
			\pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
			\def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@NODOT}%
		\fi
	\fi
	\pgfmathround@nextcmd
}

%--------------------------------------------
% END of pgfmathroundto implementation.
%--------------------------------------------


% flags, mantissa and exponent has already been stored into
% \pgfmathfloat@a@* [using ...@Mtok]
%
% PRECONDITION:
%   \ifpgfmathfloatroundhasperiod = \iftrue outside of the current
%   group
%
% POSTCONDITION:
%   \ifpgfmathfloatroundhasperiod will be set after the current TeX
%   group.
\def\pgfmathfloatround@impl{%
	\expandafter\pgfmathroundto@impl\expandafter{\the\pgfmathfloat@a@Mtok}%
	\ifpgfmathfloatroundmayneedrenormalize
		\ifpgfmathfloatroundhasperiod
			\expandafter\pgfmathfloatround@impl@renormalize\pgfmathresult\pgfmathfloat@EOI%
		\else
			\expandafter\pgfmathfloatround@impl@renormalize\pgfmathresult.\pgfmathfloat@EOI%
		\fi
		\advance\pgfmathfloat@a@E by1
	\fi
	\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\pgfmathresult}{\the\pgfmathfloat@a@E}%
}

\def\pgfmathfloatround@impl@renormalize#1#2.#3\pgfmathfloat@EOI{%
	\pgfmathroundto@impl{#1.#2#3}%
}





% ATTENTION: this thing REQUIRES a period in the mantissa!
% collects everything into \pgfmathresult
\def\pgfmathfloattofixed@impl#1.#2\relax{%
	\ifnum\pgfmathfloat@a@E<0
		\ifcase-\pgfmathfloat@a@E
		\or%e-1
			\pgfmathfloat@a@Mtok={0.}%
		\or%e-2
			\pgfmathfloat@a@Mtok={0.0}%
		\or%e-3
			\pgfmathfloat@a@Mtok={0.00}%
		\or%e-4
			\pgfmathfloat@a@Mtok={0.000}%
		\or%e-5
			\pgfmathfloat@a@Mtok={0.0000}%
		\or%e-6
			\pgfmathfloat@a@Mtok={0.00000}%
		\or%e-7
			\pgfmathfloat@a@Mtok={0.000000}%
		\or%e-8
			\pgfmathfloat@a@Mtok={0.0000000}%
		\or%e-9
			\pgfmathfloat@a@Mtok={0.00000000}%
		\or%e-10
			\pgfmathfloat@a@Mtok={0.000000000}%
		\else%<= -11
			\pgfmathfloat@a@Mtok={0.0000000000}%
			\advance\pgfmathfloat@a@E by10
			\pgfutil@loop
			\ifnum\pgfmathfloat@a@E<-1
				\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok 0}%
				\advance\pgfmathfloat@a@E by1
			\pgfutil@repeat
		\fi
		\def\pgfmathfloat@loc@TMPb{#2}%
		\def\pgfmathfloat@loc@TMPc{0}%
		\ifx\pgfmathfloat@loc@TMPb\pgfmathfloat@loc@TMPc
			\edef\pgfmathresult{\the\pgfmathfloat@a@Mtok #1}%
		\else
			\edef\pgfmathresult{\the\pgfmathfloat@a@Mtok #1#2}%
		\fi
	\else
		%--------------------------------------------------
		% \ifnum\pgfmathfloat@a@E=0%
		% 	\edef\pgfmathresult{#1.#2}%
		% \else
		% 	\pgfmathfloat@a@Mtok={#1}%
		% 	\pgfmathfloattofixed@impl@collectmantissa#2\count\pgfmathfloat@a@E
		% 	\edef\pgfmathresult{\the\pgfmathfloat@a@Mtok}%
		% \fi
		%-------------------------------------------------- 
		\pgfmathfloat@a@Mtok{#1}%
		\pgfmathfloattofixed@impl@pos#2000000000\pgfmathfloat@EOI
		\edef\pgfmathresult{\the\pgfmathfloat@a@Mtok}%
	\fi
}

% FIXME: this implementation here is very fast, but it introduces trailing zeros. Is that acceptable?
\def\pgfmathfloattofixed@impl@pos#1#2#3#4#5#6#7#8#9\pgfmathfloat@EOI{%
	\ifcase\pgfmathfloat@a@E
	% e+0
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok .#1#2#3#4#5#6#7#8#9}%
	\or%e+1
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1.#2#3#4#5#6#7#8#9}%
	\or%e+2
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2.#3#4#5#6#7#8#9}%
	\or%e+3
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3.#4#5#6#7#8#9}%
	\or%e+4
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4.#5#6#7#8#9}%
	\or%e+5
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5.#6#7#8#9}%
	\or%e+6
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6.#7#8#9}%
	\or%e+7
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7.#8#9}%
	\or%e+8
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7#8.#9}%
	\else%>=9
		\pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7#8}%
		\advance\pgfmathfloat@a@E by-8
		\pgfmathfloattofixed@impl@collectmantissa#9\count\pgfmathfloat@a@E
	\fi
}%

\def\pgfmathfloattofixed@impl@collectmantissa#1#2\count#3{%
	\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok #1}%
	\advance\pgfmathfloat@a@E by-1%
	\def\pgfmathfloat@loc@TMPb{#2}%
	\ifx\pgfmathfloat@loc@TMPb\pgfutil@empty
		\pgfutil@loop
		\ifnum\pgfmathfloat@a@E>0%
			\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok 0}%
			\advance\pgfmathfloat@a@E by-1%
		\pgfutil@repeat
		\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok .0}%
	\else
		\ifnum\pgfmathfloat@a@E=0
			\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok .#2}%
		\else
			\pgfmathfloattofixed@impl@collectmantissa#2\count#3%
		\fi
	\fi
}


% ============================================
%
%
% \pgfmathfloatparsenumber implementation
%
%
% ============================================

% accepted parser tokens:
\def\pgfmathfloatparsenumber@tok@ZERO{0}
\def\pgfmathfloatparsenumber@tok@PLUS{+}
\def\pgfmathfloatparsenumber@tok@MINUS{-}
\def\pgfmathfloatparsenumber@tok@PERIOD{.}

\newif\ifpgfmathfloatparsenumberpendingperiod

\def\pgfflt@EOI{p@EOI}%
\def\pgfflt@EOI@unexpanded{\pgfflt@EOI}%

% Starts a finite-start-machine parser to read a number.
%
% The machine's state is represented by the macro which is currently
% processed; state transitions are realised using \csname...#1\endcsname
% constructions.
%
% It assigns \pgfmathfloat@a@S, \pgfmathfloat@a@Mtok, \pgfmathfloat@a@E.
\def\pgfflt@impl#1{%
	\pgfmathfloatparsenumberpendingperiodfalse
	\pgfmathfloat@tmptoks={}% this register is used to collect PENDING ZEROS
	\pgfmathfloat@a@E=0
	% start parsing: check for sign:
	\expandafter\ifx\csname pgfflt@#1\endcsname\relax
		\pgfmathfloat@a@S=1
		\expandafter\pgfflt@init\expandafter#1%
	\else
		\expandafter\expandafter\csname pgfflt@#1\endcsname
	\fi
}
% State transitions:
\expandafter\def\csname pgfflt@+\endcsname{%
	\pgfmathfloat@a@S=1 %
	\pgfflt@init}%
\expandafter\def\csname pgfflt@-\endcsname{%
	\pgfmathfloat@a@S=2 %
	\pgfflt@init}%
\expandafter\def\csname pgfflt@\pgfflt@EOI\endcsname{%
	\pgfmathfloatparsenumber@handleerror{empty number}{}{}}%

\pgfkeys{
	/pgf/fpu/handlers/empty number/.style 2 args={%
		/pgf/fpu/handlers/invalid number={#1}{#2}%
	},
	/pgf/fpu/empty number is zero/.style={%
		/pgf/fpu/handlers/empty number/.code 2 args={%
			\pgfmathfloatcreate{0}{0.0}{0}%
		}%
	},%
	/pgf/fpu/handlers/invalid number/.code 2 args={%
		\pgfmath@error{Could not parse input '#1' as a floating point number, sorry. The unreadable part was near '#2'.}{}%
	},
	/pgf/fpu/handlers/wrong lowlevel format/.code 2 args={%
		\pgfmath@error{Sorry, an internal routine of the floating point unit got an ill-formatted floating point number `#1'. The unreadable part was near '#2'.}{}%
		\let\pgfmathresult=\pgfutil@empty
	},
}

% #1 the error handler
% #2 the number which was invalid.
% #3 the part which produced the error
%
% POSTCONDITION: the three registers
% 	\pgfmathfloat@a@S
% 	\pgfmathfloat@a@Mtok
% 	\pgfmathfloat@a@E
% will contain the number which results from the error handler.
\def\pgfmathfloatparsenumber@handleerror#1#2#3{%
	\let\pgfmathresult=\pgfutil@empty
	\pgfmathfloatparsenumberpendingperiodfalse
	\pgfkeys{/pgf/fpu/handlers/#1={#2}{#3}}%
	\ifx\pgfmathresult\pgfutil@empty
		\pgfmathfloat@a@S=3
		\pgfmathfloat@a@Mtok={0.0}%
		\pgfmathfloat@a@E=0
	\else
		\expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
	\fi
}
\def\pgfflt@error#1\pgfflt@EOI{%
	\begingroup
	\pgfmathfloat@a@Mtok={#1}%
	\xdef\pgfmathfloat@glob@TMP{%
		\noexpand\pgfmathfloatparsenumber@handleerror
			{invalid number}{\pgfmathresult}{\the\pgfmathfloat@a@Mtok}}%
	\endgroup
	\pgfmathfloat@glob@TMP
}%



% FROM: checksign.
%
\def\pgfflt@init#1{%
	\expandafter\ifx\csname pgffltA@#1\endcsname\relax
		\expandafter\pgfflt@error\expandafter#1%
	\else
		\expandafter\expandafter\csname pgffltA@#1\endcsname
	\fi}
% state transitions:
\expandafter\def\csname pgffltA@0\endcsname{\pgfflt@leadingzero}% FIXME: inline optimization!
\expandafter\def\csname pgffltA@1\endcsname{\pgfflt@nonzerodigit1}%
\expandafter\def\csname pgffltA@2\endcsname{\pgfflt@nonzerodigit2}%
\expandafter\def\csname pgffltA@3\endcsname{\pgfflt@nonzerodigit3}%
\expandafter\def\csname pgffltA@4\endcsname{\pgfflt@nonzerodigit4}%
\expandafter\def\csname pgffltA@5\endcsname{\pgfflt@nonzerodigit5}%
\expandafter\def\csname pgffltA@6\endcsname{\pgfflt@nonzerodigit6}%
\expandafter\def\csname pgffltA@7\endcsname{\pgfflt@nonzerodigit7}%
\expandafter\def\csname pgffltA@8\endcsname{\pgfflt@nonzerodigit8}%
\expandafter\def\csname pgffltA@9\endcsname{\pgfflt@nonzerodigit9}%
\def\pgfflt@nonzerodigit#1{%
	\pgfmathfloat@a@Mtok={#1}%
	\pgfmathfloatparsenumberpendingperiodtrue
	\pgfflt@positiveexp}%
\expandafter\def\csname pgffltA@n\endcsname{\pgfflt@readnan}% FIXME: inlining?
\expandafter\def\csname pgffltA@N\endcsname{\pgfflt@readnan}% FIXME: inlining?
\expandafter\def\csname pgffltA@i\endcsname{\pgfflt@readinf}% FIXME: inlining?
\expandafter\def\csname pgffltA@I\endcsname{\pgfflt@readinf}% FIXME: inlining?
\expandafter\def\csname pgffltA@.\endcsname{% read '.9' like '0.9'
	\pgfmathfloat@a@E=-1
	\pgfflt@leadingzero@foundperiod}%

\def\pgfflt@finish#1\pgfflt@EOI{}

\def\pgfflt@readnan #1#2{%
	\def\pgfflt@readnan@ok{1}%
	\if#1a\else\if#1A\else\def\pgfflt@readnan@ok{0}\fi\fi
	\if#2n\else\if#2N\else\def\pgfflt@readnan@ok{0}\fi\fi
	\if\pgfflt@readnan@ok1%
		\pgfmathfloat@a@S=3\relax%
		\pgfmathfloat@a@Mtok={0.0}%
		\pgfmathfloat@a@E=0%
		\expandafter\pgfflt@finish
	\else
		\def\pgfflt@readnan@{\pgfflt@error #1#2}%
		\expandafter\pgfflt@readnan@
	\fi
}
\def\pgfflt@readinf #1#2{%
	\def\pgfflt@readinf@ok{1}%
	\if#1n\else\if#1N\else\def\pgfflt@readinf@ok{0}\fi\fi
	\if#2f\else\if#2F\else\def\pgfflt@readinf@ok{0}\fi\fi
	\if\pgfflt@readinf@ok1%
		\ifnum\pgfmathfloat@a@S=1 %
			\pgfmathfloat@a@S=4 %
			\pgfmathfloat@a@Mtok={0.0}%
		\else
			\pgfmathfloat@a@S=5 %
			\pgfmathfloat@a@Mtok={0.0}%
		\fi
		\pgfmathfloat@a@E=0 %
		\expandafter\pgfflt@finish
	\else
		\def\pgfflt@readinf@{\pgfflt@error #1#2}%
		\expandafter\pgfflt@readinf@
	\fi
}
\def\pgfflt@leadingzero#1{%
	\expandafter\ifx\csname pgffltB@#1\endcsname\relax
		\expandafter\pgfflt@error\expandafter#1%
	\else
		\expandafter\expandafter\csname pgffltB@#1\endcsname
	\fi}
% State transitions:
\expandafter\def\csname pgffltB@0\endcsname{\pgfflt@leadingzero}%
\expandafter\def\csname pgffltB@1\endcsname{\pgfmathfloat@a@Mtok={1}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@2\endcsname{\pgfmathfloat@a@Mtok={2}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@3\endcsname{\pgfmathfloat@a@Mtok={3}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@4\endcsname{\pgfmathfloat@a@Mtok={4}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@5\endcsname{\pgfmathfloat@a@Mtok={5}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@6\endcsname{\pgfmathfloat@a@Mtok={6}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@7\endcsname{\pgfmathfloat@a@Mtok={7}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@8\endcsname{\pgfmathfloat@a@Mtok={8}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@9\endcsname{\pgfmathfloat@a@Mtok={9}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
\expandafter\def\csname pgffltB@\pgfmathfloat@POSTFLAGSCHAR\endcsname{\pgfmathfloat@a@Mtok={0}\pgfflt@readlowlevelfloat}%
\expandafter\def\csname pgffltB@.\endcsname{%
	\pgfmathfloat@a@E=-1
	\pgfflt@leadingzero@foundperiod}%
\expandafter\def\csname pgffltB@e\endcsname{%
	\pgfmathfloat@a@S=0\relax%
	\pgfmathfloat@a@Mtok={0.0}%
	\pgfmathfloat@a@E=0%
	\pgfflt@readexponent}%
\let\pgffltB@E=\pgffltB@e
\expandafter\def\csname pgffltB@\pgfflt@EOI\endcsname{%
	\pgfmathfloat@a@S=0\relax%
	\pgfmathfloat@a@Mtok={0.0}%
	\pgfmathfloat@a@E=0}%

\def\pgfflt@leadingzero@foundperiod#1{%
	\expandafter\ifx\csname pgffltC@#1\endcsname\relax
		\expandafter\pgfflt@error\expandafter#1%
	\else
		\expandafter\expandafter\csname pgffltC@#1\endcsname
	\fi}
% State transitions:
\expandafter\def\csname pgffltC@0\endcsname{%
	\advance\pgfmathfloat@a@E by-1
	\pgfflt@leadingzero@foundperiod}%
\expandafter\def\csname pgffltC@1\endcsname{\pgfmathfloat@a@Mtok={1}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@2\endcsname{\pgfmathfloat@a@Mtok={2}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@3\endcsname{\pgfmathfloat@a@Mtok={3}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@4\endcsname{\pgfmathfloat@a@Mtok={4}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@5\endcsname{\pgfmathfloat@a@Mtok={5}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@6\endcsname{\pgfmathfloat@a@Mtok={6}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@7\endcsname{\pgfmathfloat@a@Mtok={7}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@8\endcsname{\pgfmathfloat@a@Mtok={8}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@9\endcsname{\pgfmathfloat@a@Mtok={9}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
\expandafter\def\csname pgffltC@e\endcsname{%
	\pgfmathfloat@a@S=0\relax%
	\pgfmathfloat@a@Mtok={0.0}%
	\pgfmathfloat@a@E=0%
	\pgfflt@readexponent}%
\let\pgffltC@E=\pgffltC@e
\expandafter\def\csname pgffltC@\pgfflt@EOI\endcsname{%
	\pgfmathfloat@a@S=0\relax%
	\pgfmathfloat@a@Mtok={0.0}%
	\pgfmathfloat@a@E=0}%


\def\pgfflt@positiveexp#1{%
	\expandafter\ifx\csname pgffltD@#1\endcsname\relax
		\expandafter\pgfflt@error\expandafter#1%
	\else
		\expandafter\expandafter\csname pgffltD@#1\endcsname
	\fi}
% State transitions:
\expandafter\def\csname pgffltD@0\endcsname{%
	\advance\pgfmathfloat@a@E by1
	\pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
	\pgfflt@pendingzeros@positiveexp}%
\expandafter\def\csname pgffltD@1\endcsname{\pgffltD@nonzerodigit1}%
\expandafter\def\csname pgffltD@2\endcsname{\pgffltD@nonzerodigit2}%
\expandafter\def\csname pgffltD@3\endcsname{\pgffltD@nonzerodigit3}%
\expandafter\def\csname pgffltD@4\endcsname{\pgffltD@nonzerodigit4}%
\expandafter\def\csname pgffltD@5\endcsname{\pgffltD@nonzerodigit5}%
\expandafter\def\csname pgffltD@6\endcsname{\pgffltD@nonzerodigit6}%
\expandafter\def\csname pgffltD@7\endcsname{\pgffltD@nonzerodigit7}%
\expandafter\def\csname pgffltD@8\endcsname{\pgffltD@nonzerodigit8}%
\expandafter\def\csname pgffltD@9\endcsname{\pgffltD@nonzerodigit9}%
\expandafter\def\csname pgffltD@\pgfmathfloat@POSTFLAGSCHAR\endcsname{\pgfflt@readlowlevelfloat}%
\expandafter\def\csname pgffltD@.\endcsname{\pgfflt@finish@number@after@period}% FIXME : inlining?
\expandafter\def\csname pgffltD@e\endcsname{\pgfflt@readexponent}% FIXME : inlining?
\let\pgffltD@E=\pgffltD@e
\expandafter\def\csname pgffltD@\pgfflt@EOI\endcsname{}% NOP
\def\pgffltD@nonzerodigit#1{%
	\advance\pgfmathfloat@a@E by1
	\ifpgfmathfloatparsenumberpendingperiod
		\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
		\pgfmathfloatparsenumberpendingperiodfalse
	\fi
	\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
	\pgfflt@positiveexp}%

% Read a low-level floating point.
% Since we are in the second state, \pgfmathfloat@a@Mtok contains the
% FLAGS. The post-flags-char has also been read.
\def\pgfflt@readlowlevelfloat#1e#2]\pgfflt@EOI{%
	\pgfmathfloatparsenumberpendingperiodfalse
	\pgfmathfloat@a@S=\the\pgfmathfloat@a@Mtok\relax
	\pgfmathfloat@a@Mtok={#1}%
	\pgfmathfloat@a@E=#2
}%

\def\pgfflt@readexponent#1\pgfflt@EOI{%
	\afterassignment\pgfflt@readexponent@
	\pgfmathfloat@b@E=#1 \pgfflt@EOI% the white space is important, otherwise \pgfflt@EOI will be expanded.
}
\def\pgfflt@readexponent@#1{%
	\advance\pgfmathfloat@a@E by\pgfmathfloat@b@E\relax
	%
	% sanity checking:
	\def\pgfmathfloat@loc@TMPb{#1}%
	\ifx\pgfmathfloat@loc@TMPb\pgfflt@EOI@unexpanded
	\else
		\def\pgfmathfloat@loc@TMPb{\pgfflt@error#1}%
		\expandafter\pgfmathfloat@loc@TMPb
	\fi
}

\def\pgfflt@pendingzeros@positiveexp#1{%
	\expandafter\ifx\csname pgffltE@#1\endcsname\relax
		\expandafter\pgfflt@error\expandafter#1%
	\else
		\expandafter\expandafter\csname pgffltE@#1\endcsname
	\fi}
% State transitions:
\expandafter\def\csname pgffltE@0\endcsname{%
	\pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
	\advance\pgfmathfloat@a@E by1
	\pgfflt@pendingzeros@positiveexp}%
\expandafter\def\csname pgffltE@1\endcsname{\pgffltE@nonzerodigit1}%
\expandafter\def\csname pgffltE@2\endcsname{\pgffltE@nonzerodigit2}%
\expandafter\def\csname pgffltE@3\endcsname{\pgffltE@nonzerodigit3}%
\expandafter\def\csname pgffltE@4\endcsname{\pgffltE@nonzerodigit4}%
\expandafter\def\csname pgffltE@5\endcsname{\pgffltE@nonzerodigit5}%
\expandafter\def\csname pgffltE@6\endcsname{\pgffltE@nonzerodigit6}%
\expandafter\def\csname pgffltE@7\endcsname{\pgffltE@nonzerodigit7}%
\expandafter\def\csname pgffltE@8\endcsname{\pgffltE@nonzerodigit8}%
\expandafter\def\csname pgffltE@9\endcsname{\pgffltE@nonzerodigit9}%
\expandafter\def\csname pgffltE@.\endcsname{\pgfflt@finish@number@after@period}% FIXME : inlining?
\def\pgffltE@e{\pgfflt@readexponent}% FIXME : inlining?
\let\pgffltE@E=\pgffltE@e
\expandafter\def\csname pgffltE@\pgfflt@EOI\endcsname{}% NOP
\def\pgffltE@nonzerodigit#1{%
	\advance\pgfmathfloat@a@E by1
	\ifpgfmathfloatparsenumberpendingperiod
		\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
		\pgfmathfloatparsenumberpendingperiodfalse
	\fi
	\pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}%
	\pgfmathfloat@tmptoks={}%
	\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
	\pgfflt@positiveexp}%

\def\pgfflt@finish@number@after@period#1{%
	\expandafter\ifx\csname pgffltF@#1\endcsname\relax
		\expandafter\pgfflt@error\expandafter#1%
	\else
		\expandafter\expandafter\csname pgffltF@#1\endcsname
	\fi}
% State transitions:
\expandafter\def\csname pgffltF@0\endcsname{%
	\pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
	\pgfflt@pendingzeros}%
\expandafter\def\csname pgffltF@1\endcsname{\pgffltF@nonzerodigit1}%
\expandafter\def\csname pgffltF@2\endcsname{\pgffltF@nonzerodigit2}%
\expandafter\def\csname pgffltF@3\endcsname{\pgffltF@nonzerodigit3}%
\expandafter\def\csname pgffltF@4\endcsname{\pgffltF@nonzerodigit4}%
\expandafter\def\csname pgffltF@5\endcsname{\pgffltF@nonzerodigit5}%
\expandafter\def\csname pgffltF@6\endcsname{\pgffltF@nonzerodigit6}%
\expandafter\def\csname pgffltF@7\endcsname{\pgffltF@nonzerodigit7}%
\expandafter\def\csname pgffltF@8\endcsname{\pgffltF@nonzerodigit8}%
\expandafter\def\csname pgffltF@9\endcsname{\pgffltF@nonzerodigit9}%
\def\pgffltF@e{\pgfflt@readexponent}%
\let\pgffltF@E=\pgffltF@e
\expandafter\def\csname pgffltF@\pgfflt@EOI\endcsname{}% NOP
\def\pgffltF@nonzerodigit#1{%
	\ifpgfmathfloatparsenumberpendingperiod
		\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
		\pgfmathfloatparsenumberpendingperiodfalse
	\fi
	\pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}%
	\pgfmathfloat@tmptoks={}%
	\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
	\pgfflt@finish@number@after@period}%


\def\pgfflt@pendingzeros#1{%
	\expandafter\ifx\csname pgffltG@#1\endcsname\relax
		\expandafter\pgfflt@error\expandafter#1%
	\else
		\expandafter\expandafter\csname pgffltG@#1\endcsname
	\fi}
% State transitions:
\expandafter\def\csname pgffltG@0\endcsname{%
	\pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
	\pgfflt@pendingzeros}%
\expandafter\def\csname pgffltG@1\endcsname{\pgffltG@nonzerodigit1}%
\expandafter\def\csname pgffltG@2\endcsname{\pgffltG@nonzerodigit2}%
\expandafter\def\csname pgffltG@3\endcsname{\pgffltG@nonzerodigit3}%
\expandafter\def\csname pgffltG@4\endcsname{\pgffltG@nonzerodigit4}%
\expandafter\def\csname pgffltG@5\endcsname{\pgffltG@nonzerodigit5}%
\expandafter\def\csname pgffltG@6\endcsname{\pgffltG@nonzerodigit6}%
\expandafter\def\csname pgffltG@7\endcsname{\pgffltG@nonzerodigit7}%
\expandafter\def\csname pgffltG@8\endcsname{\pgffltG@nonzerodigit8}%
\expandafter\def\csname pgffltG@9\endcsname{\pgffltG@nonzerodigit9}%
\def\pgffltG@e{\pgfflt@readexponent}% FIXME: inlining?
\let\pgffltG@E=\pgffltG@e
\expandafter\def\csname pgffltG@\pgfflt@EOI\endcsname{}% NOP
\def\pgffltG@nonzerodigit#1{%
	\ifpgfmathfloatparsenumberpendingperiod
		\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
		\pgfmathfloatparsenumberpendingperiodfalse
	\fi
	\pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}%
	\pgfmathfloat@tmptoks={}%
	\pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
	\pgfflt@finish@number@after@period}%

\endinput

pgfmathparser.code.tex

\newdimen\pgfmath@dimen
\newcount\pgfmath@count
\newbox\pgfmath@box
\newtoks\pgfmath@toks

\newif\ifpgfmath@quickparse
\newif\ifpgfmathfloat
\newif\ifpgfmathunitsdeclared
\newif\ifpgfmathignoreunitscale

\def\pgfmathprint#1{\pgfmathparse{#1}\pgfmathresult}

\def\pgfmathparse{%
	\begingroup%
		\pgfmath@catcodes%
		\pgfmath@quickparsefalse%
		\ifpgfmathfloat%
			\let\pgfmath@parse@next=\pgfmathfloatparsenumber%
		\else%
			\let\pgfmath@parse@next=\pgfmathparse@%
		\fi%
		\pgfmath@parse@next}

\def\pgfmath@catcodes{% Maybe unecessary.
	\catcode`\==12%
	\catcode`\,=12%
	\catcode`\|=12%
	\catcode`\&=12%
}

\def\pgfmathqparse{%
	\begingroup%
		\pgfmath@catcodes%
		\pgfmath@quickparsetrue%
		\pgfmathparse@}
	
\def\pgfmathparse@#1{%
		% Stuff for calc compatiability.
		\let\real=\pgfmath@calc@real%
    \let\minof=\pgfmath@calc@minof%
    \let\maxof=\pgfmath@calc@maxof%
    \let\ratio=\pgfmath@calc@ratio%
    \let\widthof=\pgfmath@calc@widthof%
    \let\heightof=\pgfmath@calc@heightof%
    \let\depthof=\pgfmath@calc@depthof%
    % Restore font.
    \pgfmath@selectfont%
    % Expand expression so any reamining CSs are registers
    % or box dimensions (i.e., \wd, \ht, \dp).
    \edef\pgfmath@expression{#1}%
    % No units yet. 
    \global\pgfmathunitsdeclaredfalse%
    % Set up stack.
    \pgfmath@stack@operation={{}{}{}}%
		\pgfmath@stack@operand={{}{}{}}%
		\let\pgfmath@stack@operation@top=\pgfmath@stack@empty%
		\let\pgfmath@stack@operand@top=\pgfmath@stack@empty%
		% An expression always begins with an operand.
		\expandafter\pgfmath@bgroup@strip\expandafter{\pgfmath@expression}%
		\expandafter\pgfmath@parse@@operand\pgfmath@bgroup@stripped @@@@\pgfmath@parse@stop%
}%

\def\pgfmath@parse@end#1\pgfmath@parse@stop{%
		\pgfmathpostparse%
		\pgfmath@smuggleone\pgfmathresult%
	\endgroup%
	\ignorespaces}%	

\let\pgfmathpostparse=\relax%

% For compatiability with older version.
%
\def\pgfmathscaleresult{%
	\ifpgfmathunitsdeclared%
  \else%
  	\ifpgfmathignoreunitscale%
  	\else%
   	  \afterassignment\pgfmath@gobbletilpgfmath@%
      \pgfmath@x\pgfmathresultunitscale pt\relax\pgfmath@%
      \expandafter\pgfmath@x\pgfmathresult\pgfmath@x%
      \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}%
    \fi%
  \fi%
}
\def\pgfmathsetresultunitscale#1{\def\pgfmathresultunitscale{#1}}
\def\pgfmathresultunitscale{1}

% Stuff for compatability with the calc package.
%
\def\pgfmath@calc@real#1{#1}
\def\pgfmath@calc@minof#1#2{min(#1,#2)}
\def\pgfmath@calc@maxof#1#2{max(#1,#2)}
\def\pgfmath@calc@ratio#1#2{#1/#2}
\def\pgfmath@calc@widthof#1{width("#1")}
\def\pgfmath@calc@heightof#1{height("#1")}
\def\pgfmath@calc@depthof#1{depth("#1")}

\def\pgfmath@bgroup{\string\pgfmath@bgroup}
\def\pgfmath@egroup{\string\pgfmath@egroup}
\def\pgfmath@egroup@token{\pgfmath@egroup}

\def\pgfmath@text@@{@}
\def\pgfmath@text@operator{operator}
\def\pgfmath@text@function{function}
\def\pgfmath@dots{...}
\def\pgfmath@char@zero{0}
\def\pgfmath@char@quote{"}
\def\pgfmath@char@exclamation{!}
\def\pgfmath@char@plus{+}
\def\pgfmath@char@minus{-}
\def\pgfmath@char@period{.}
\def\pgfmath@char@leftangle{<}
\def\pgfmath@char@leftbracket{[}
\pgfmath@toks={#}
\edef\pgfmath@char@hash{\the\pgfmath@toks}

\def\pgfmath@tokens@make#1#2{%
	\def\pgfmath@prefix{#1}%
	\expandafter\pgfmath@tokens@@make#2{}}
	
\def\pgfmath@tokens@@make#1{%
	\def\pgfmath@token{#1}%
	\ifx\pgfmath@token\pgfmath@empty%
	\else%
		\pgfmath@namedef{pgfmath@token@\pgfmath@prefix @\string#1}{#1}%
		\expandafter\pgfmath@tokens@@make%
	\fi}

\pgfmath@tokens@make{box}{\wd\ht\dp}
\pgfmath@tokens@make{unit}{{bp}{cc}{cm}{dd}{em}{ex}{in}{mm}{pc}{pt}{sp}}
\pgfmath@tokens@make{numeric}{.0123456789}
\pgfmath@tokens@make{number}{0123456789}
\pgfmath@tokens@make{functional}{_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ}
\pgfmath@tokens@make{exponent}{eE}
\pgfmath@tokens@make{group}{{()}{[]}{\pgfmath@bgroup\pgfmath@egroup}}
\pgfmath@tokens@make{specials}{@)]\pgfmath@egroup}
\pgfmath@tokens@make{hexadecimal}{0123456789ABCDEFabcdef}
\pgfmath@tokens@make{octal}{01234567}
\pgfmath@tokens@make{binary}{01}

\pgfmath@namedef{pgfmath@base@0x}{16}
\pgfmath@namedef{pgfmath@base@0X}{16}
\pgfmath@namedef{pgfmath@base@0b}{2}
\pgfmath@namedef{pgfmath@base@0B}{2}

% Determine if a register is a count or a dimension/skip register.
%
\newif\ifpgfmath@dimen@
\def\pgfmath@dimen@#1{%
	\begingroup%
		\afterassignment\pgfmath@dimen@@%
		#1=0.0pt\relax\pgfmath@}
\def\pgfmath@dimen@@#1#2\pgfmath@{%
	\endgroup%
	\ifx#1.%
		\pgfmath@dimen@false%
	\else%
		\pgfmath@dimen@true%
	\fi}

\def\pgfmath@parse@ifbgroup#1#2{%
	\let\pgfmath@parse@bgroup@after=#1%
	\let\pgfmath@parse@nobgroup@after=#2%
	\futurelet\pgfmath@token@let%
	\pgfmath@parse@@ifbgroup}
	
\def\pgfmath@parse@@ifbgroup{%
	\ifx\pgfmath@token@let\bgroup%
		\let\pgfmath@parse@next=\pgfmath@parse@@@ifbgroup%
	\else%
		\ifx\pgfmath@token@let\pgfmath@sptoken%
			\let\pgfmath@parse@next=\pgfmath@parse@@@@ifbgroup%
		\else%
			\let\pgfmath@parse@next=\pgfmath@parse@nobgroup@after%
		\fi%
	\fi%
	\pgfmath@parse@next}

\def\pgfmath@parse@@@ifbgroup#1{\pgfmath@parse@bgroup@after\pgfmath@bgroup#1\pgfmath@egroup}

{
\def\:{\pgfmath@parse@@@@ifbgroup}
\expandafter\gdef\: {\futurelet\pgfmath@token@let\pgfmath@parse@@ifbgroup}
}

% Parse an operand.
%	
\def\pgfmath@parse@operand{\expandafter\pgfmath@parse@@operand\pgfmath@token@next}%

\def\pgfmath@parse@@operand{\pgfmath@parse@ifbgroup{\pgfmath@parse@@operand}{\pgfmath@parse@@operand@}}

\def\pgfmath@parse@@operand@#1{%
	\def\pgfmath@token{#1}%
	\ifx\pgfmath@token\pgfmath@char@plus% Ignore.
		\let\pgfmath@parse@next=\pgfmath@parse@@operand%
	\else%
		\ifx\pgfmath@token\pgfmath@char@minus%
			\pgfmath@stack@push@operation{neg}% Unary minus.
			\let\pgfmath@parse@next=\pgfmath@parse@@operand%
		\else%
			\expandafter\ifx\csname pgfmath@operation@\expandafter\string\pgfmath@token @prefix\endcsname\pgfmath@token%
				\let\pgfmath@parse@next=\pgfmath@parse@prefix@operator%
			\else%
				\ifpgfmath@quickparse%
					\let\pgfmath@parse@next=\pgfmath@qparse@operand%
				\else%
					\let\pgfmath@number=\pgfmath@empty%
					\expandafter\ifx\csname pgfmath@token@functional@\string#1\endcsname\relax%
						\let\pgfmath@base=\pgfmath@empty%
						\let\pgfmath@token@next=\pgfmath@token%
						\if#10% Check for octal prefix.
							\def\pgfmath@base{8}%
						\fi%
						\let\pgfmath@parse@next=\pgfmath@parse@number%
					\else%
						\let\pgfmath@function=\pgfmath@token%
						\let\pgfmath@parse@next=\pgfmath@parse@function%
					\fi%
				\fi%
			\fi%
		\fi%
	\fi%
	\pgfmath@parse@next%
}

% Parse prefix operators.
%
\def\pgfmath@parse@prefix@operator{%
	\ifx\pgfmath@token\pgfmath@char@quote% Quote character.
		\let\pgfmath@parse@next=\pgfmath@parse@operand@quote%
	\else%
		\ifx\pgfmath@token\pgfmath@char@exclamation% Prefix !.
			\pgfmath@stack@push@operation{not}%
			\let\pgfmath@parse@next=\pgfmath@parse@@operand%
		\else% Anything else, just push and hope.
			\expandafter\pgfmath@stack@push@operation\expandafter{\pgfmath@token}%
			\let\pgfmath@parse@next=\pgfmath@parse@@operand%
		\fi%
	\fi%
	\pgfmath@parse@next%
}%


% Quote part of an expression.
%
\def\pgfmath@parse@operand@quote#1"{%
	\def\pgfmathresult{#1}%
	\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
	\pgfmath@parse@@operator%
}

% Quick operand parsing. Should always have units.
% No functions, base conversion, quoting or scientific notation
% are permitted.
\def\pgfmath@qparse@operand{%
	\afterassignment\pgfmath@qparse@@operand%
	\pgfmath@dimen\pgfmath@token}
\def\pgfmath@qparse@@operand{%
	\edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
	\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
	\pgfmath@parse@@operator%
}

% Parse a number, which can take the form:
%
% 1. An integer, or a decimal, with or without units.
% 2. A dimension/skip or a count register.
% 3. A dimension register preceded by a number or count register.
% 4. A box dimension (e.g., \wd\mybox).
% 5. A box dimension preceded by a number or a count register.
% 6. Scientific notation (e.g., 1.234567e-10).
% 7. A binary, hexadeciaml, or octal number.
%  
\def\pgfmath@parse@number{\pgfmath@parse@ifbgroup{\pgfmath@parse@number}{\pgfmath@parse@number@}}
\def\pgfmath@parse@number@#1{%
	\let\pgfmath@token=\pgfmath@token@next%
	\def\pgfmath@token@next{#1}%
	\pgfmath@parse@@number}

\def\pgfmath@parse@@number{%
	\ifx\pgfmath@token\pgfmath@egroup@token%
		\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmath@number}%
		\let\pgfmath@parse@next=\pgfmath@parse@@@operator%
	\else%
		\expandafter\ifcat\pgfmath@token\relax% A CS?
			\expandafter\ifx\csname pgfmath@token@box@\expandafter\string\pgfmath@token\endcsname\relax%
			  % So, is the CS is a dimension or a count register?
				\expandafter\pgfmath@dimen@\pgfmath@token%
				\ifpgfmath@dimen@% A dimension register.
					\global\pgfmathunitsdeclaredtrue%
					\pgfmath@dimen=\pgfmath@number\pgfmath@token%
					\edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
					\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
					\let\pgfmath@parse@next=\pgfmath@parse@operator%
				\else% A count register.
					\pgfmath@count=\pgfmath@token%
					\expandafter\def\expandafter\pgfmath@number\expandafter{\the\pgfmath@count}%
					\expandafter\ifcat\pgfmath@token@next\relax%
						% A CS following a count register should be \wd, \ht or \dp. 
						\let\pgfmath@parse@next=\pgfmath@parse@number%
					\else%
						\let\pgfmathresult=\pgfmath@number%
						\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
						\let\pgfmath@parse@next=\pgfmath@parse@operator%
					\fi%
				\fi%
			\else%
				% This should be a box specification, for example, 0.5\wd\mybox.
				\global\pgfmathunitsdeclaredtrue%
				\pgfmath@dimen=\pgfmath@number\pgfmath@token\pgfmath@token@next%
				\edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
				\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
				\let\pgfmath@parse@next=\pgfmath@parse@@operator%
			\fi%
		\else%
			\expandafter\ifx\csname pgfmath@token@numeric@\expandafter\string\pgfmath@token\endcsname\relax%
				% It isn't numeric (i.e., 012345679.), so it might be units...
				\expandafter\ifx\csname pgfmath@token@unit@\pgfmath@token\expandafter\string\pgfmath@token@next\endcsname\relax%
					% ...or the exponent characters...
					\expandafter\ifx\csname pgfmath@token@exponent@\pgfmath@token\endcsname\relax%
						% ...or a base prefix...
						\expandafter\ifx\csname pgfmath@base@\pgfmath@number\pgfmath@token\endcsname\relax%
							% ...none of the above...
							\ifx\pgfmath@base\pgfmath@empty%
								\let\pgfmathresult=\pgfmath@number% 
							\else%
								\ifx\pgfmath@number\pgfmath@char@zero%
									\let\pgfmathresult=\pgfmath@number%
								\else%
									% Convert from octal.
									\expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{8}{10}%
								\fi%
							\fi%
							\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
							\let\pgfmath@parse@next=\pgfmath@parse@@@operator%
						\else%
						  % ...here, it is a base prefix 0x, 0X, 0b or 0B
						  \expandafter\let\expandafter\pgfmath@base\expandafter=%
						  	\csname pgfmath@base@\pgfmath@number\pgfmath@token\endcsname%
						  \let\pgfmath@parse@next=\pgfmath@parse@base%
						\fi%
					\else% ... and here, it is the exponent characters.
						\let\pgfmath@parse@next=\pgfmath@parse@exponent%					
					\fi%
				\else% ...but here it is units.
					\global\pgfmathunitsdeclaredtrue%
					\pgfmath@dimen=\pgfmath@number\pgfmath@token\pgfmath@token@next\relax%
					\edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
					\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
					\let\pgfmath@parse@next=\pgfmath@parse@@operator%
				\fi%
			\else% It is numeric.
				\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgfmath@number%
					\expandafter\expandafter\expandafter{\expandafter\pgfmath@number\pgfmath@token}%
				\ifx\pgfmath@token\pgfmath@char@period%
					\let\pgfmath@base=\pgfmath@empty%
				\fi%
				\let\pgfmath@parse@next=\pgfmath@parse@number%
			\fi%
		\fi%
	\fi%
	\pgfmath@parse@next%
}

% Parse the exponent of a number.
%
% REMARK: this method will be overwritten by the FPU library. Please
% keep changes consistent...
\def\pgfmath@parse@exponent{%
	\afterassignment\pgfmath@parse@@exponent%
	\pgfmath@count\pgfmath@token@next}
\def\pgfmath@parse@@exponent{%
	\pgfmathscientific{\pgfmath@number}{\the\pgfmath@count}%
	\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
	\pgfmath@parse@@operator%
}

% Parse binary or hexadecimal numbers (octal numbers done elsehwere).
%
\def\pgfmath@parse@base{%
	\ifnum\pgfmath@base=2\relax%
		\let\pgfmath@parse@next=\pgfmath@parse@binary%
	\else%
		\ifnum\pgfmath@base=16\relax%
			\let\pgfmath@parse@next=\pgfmath@parse@hexadecimal%
		\else%
			\pgfmath@error{Unexpected numerical base `\pgfmath@base'}{}%
			\def\pgfmathresult{0}%
			\let\pgfmath@parse@next=\pgfmath@parse@end%
		\fi%
	\fi%
	\let\pgfmath@number=\pgfmath@empty%
	\expandafter\pgfmath@parse@next\pgfmath@token@next%
}
	
\def\pgfmath@parse@binary#1{%
	\expandafter\ifx\csname pgfmath@token@binary@#1\endcsname\relax%
		\expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{2}{10}%
		\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
		\def\pgfmath@token@next{#1}%
		\let\pgfmath@parse@next=\pgfmath@parse@operator%
	\else%
		\expandafter\def\expandafter\pgfmath@number\expandafter{\pgfmath@number#1}%
		\let\pgfmath@parse@next=\pgfmath@parse@binary%
	\fi%
	\pgfmath@parse@next%
}

\def\pgfmath@parse@hexadecimal#1{%
	\expandafter\ifx\csname pgfmath@token@hexadecimal@#1\endcsname\relax%
		\expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{16}{10}%
		\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
		\def\pgfmath@token@next{#1}%
		\let\pgfmath@parse@next=\pgfmath@parse@operator%
	\else%
		\expandafter\def\expandafter\pgfmath@number\expandafter{\pgfmath@number#1}%
		\let\pgfmath@parse@next=\pgfmath@parse@hexadecimal%
	\fi%
	\pgfmath@parse@next%
}
	
% Parse a function.
%
\def\pgfmath@parse@function{\pgfmath@parse@ifbgroup{\pgfmath@parse@function}{\pgfmath@parse@@function}}
\def\pgfmath@parse@function@{\futurelet\pgfmath@token@let\pgfmath@parse@@function}
\def\pgfmath@parse@@function{%
	\ifx\pgfmath@token@let\pgfmath@sptoken%
		\let\pgfmath@token=\pgfmath@empty%
		\let\pgfmath@parse@next=\pgfmath@parse@@@@function%
	\else%
		\let\pgfmath@parse@next=\pgfmath@parse@@@function%
	\fi%
	\pgfmath@parse@next}

\def\pgfmath@parse@@@function#1{%
	\expandafter\ifx\csname pgfmath@token@functional@\expandafter\string#1\endcsname\relax%
		\expandafter\ifx\csname pgfmath@token@number@\expandafter\string#1\endcsname\relax%
			\def\pgfmath@token{#1}% Not from A-Z, a-z, 0-9, or _.
			\let\pgfmath@parse@next=\pgfmath@parse@@@@function%
		\else% It is from 0-9.
			\expandafter\def\expandafter\pgfmath@function\expandafter{\pgfmath@function#1}%
			\let\pgfmath@parse@next=\pgfmath@parse@function@%
		\fi%
	\else% It is from from A-Z, a-z, or _.
		\edef\pgfmath@function{\pgfmath@function#1}%
		\let\pgfmath@parse@next=\pgfmath@parse@function@%
	\fi%
	\pgfmath@parse@next}

\def\pgfmath@parse@@@@function{%
	\expandafter\ifx\csname pgfmath@function@\pgfmath@function\endcsname\relax%
		\pgfmath@error{Unknown function `\pgfmath@function'}{}%
		\def\pgfmathresult{0}%
		\let\pgfmath@parse@next=\pgfmath@parse@end%
	\else%
		\expandafter\ifnum\csname pgfmath@operation@\pgfmath@function @arity\endcsname=0\relax%
		 % Functions with zero arity are called directly.
			\csname pgfmath\pgfmath@function @\endcsname%
			\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
			\let\pgfmath@parse@next=\pgfmath@parse@@operator%
		\else% Otherwise, they are pushed onto the operator stack
			\expandafter\pgfmath@stack@push@operation\expandafter{\pgfmath@function}%
			\let\pgfmath@parse@next=\pgfmath@parse@@operand%
		\fi%
	\fi%
	\expandafter\pgfmath@parse@next\pgfmath@token}

% Parse an operator.
%
\def\pgfmath@parse@operator{\pgfmath@parse@ifbgroup{\pgfmath@parse@operator}{\pgfmath@parse@operator@}}%
\def\pgfmath@parse@operator@#1{% Get one token.
	\let\pgfmath@token=\pgfmath@token@next%
	\def\pgfmath@token@next{#1}%
	\pgfmath@parse@@@operator}

\def\pgfmath@parse@@operator{\pgfmath@parse@ifbgroup{\pgfmath@parse@@operator}{\pgfmath@parse@@operator@}}%
\def\pgfmath@parse@@operator@#1{% Get first token...
	\def\pgfmath@token{#1}%
	\pgfmath@parse@ifbgroup{\pgfmath@parse@@operator@@}{\pgfmath@parse@@operator@@}}%
\def\pgfmath@parse@@operator@@#1{% ...and second token.
	\def\pgfmath@token@next{#1}%
	\pgfmath@parse@@@operator}	

\def\pgfmath@parse@@@operator{%
	\expandafter\ifx\csname pgfmath@operator@\pgfmath@token\expandafter\string\pgfmath@token@next\endcsname\relax%
		% Not a double character operator.
		\expandafter\ifx\csname pgfmath@operator@\pgfmath@token\endcsname\relax%
			% Not a single character operator.
			\pgfmath@error{Unknown operator `\pgfmath@token' or `\pgfmath@token\pgfmath@token@next'}{}%
			\def\pgfmathresult{0}%
		\let\pgfmath@parse@next=\pgfmath@parse@end%
		\else%
			\expandafter\pgfmath@operation@process\expandafter{\pgfmath@token}%
			\ifx\pgfmath@token\pgfmath@text@@%
				\let\pgfmath@parse@next=\pgfmath@parse@end%
			\else%
				\expandafter\ifx\csname pgfmath@operation@\pgfmath@token @postfix\endcsname\pgfmath@token%
					% Postfix operators are followed by an operator.
					\ifx\pgfmath@token@next\pgfmath@char@leftbracket% Except [.
						\let\pgfmath@parse@next=\pgfmath@parse@operand%
					\else%
						\let\pgfmath@parse@next=\pgfmath@parse@operator%
					\fi%
				\else%
					% Any other operator is followed by an operand.
					\let\pgfmath@parse@next=\pgfmath@parse@operand%
				\fi%
			\fi%
		\fi%
	\else%
		% A double character operator...
		\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
			\pgfmath@token\expandafter\expandafter\expandafter%
				{\expandafter\pgfmath@token\pgfmath@token@next}%
		\expandafter\pgfmath@operation@process\expandafter{\pgfmath@token}%
		% ...is always followed by an operand.
		\let\pgfmath@parse@next=\pgfmath@parse@@operand%
	\fi%
	\pgfmath@parse@next%
}


% Process an operation.
%
\def\pgfmath@operation@process#1{%
	\def\pgfmath@operator{#1}%
	\ifx\pgfmath@stack@operation@top\pgfmath@stack@empty%
	\else%
		\pgfmath@operation@@process%
	\fi%
	\expandafter\ifx\csname pgfmath@token@specials@#1\endcsname\relax%
		\pgfmath@stack@push@operation{#1}%
	\fi%
}

% Process the operation stack.
%
\def\pgfmath@operation@@process{%
	\ifx\pgfmath@stack@operation@top\pgfmath@stack@empty%
		\let\pgfmath@parse@next=\relax%
	\else%
		\ifnum\csname pgfmath@operation@\pgfmath@operator @precedence\endcsname>%
			\csname pgfmath@operation@\pgfmath@stack@operation@top @precedence\endcsname\relax%
			% If the precedence of the scanned operator is greater than the
			% precedence of the operator at the top of the stack, do nothing.
			\let\pgfmath@parse@next=\relax%
		\else%
			\let\pgfmath@stack@operation@last=\pgfmath@stack@operation@top%
			\expandafter\ifx\csname pgfmath@operator@\pgfmath@stack@operation@top\endcsname\relax%
				\pgfmath@function@@@process%
			\else%
				\pgfmath@operator@@@process%
			\fi%
			\expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
			\expandafter\ifx\csname pgfmath@token@group@\pgfmath@stack@operation@last\pgfmath@operator\endcsname\relax%
				\let\pgfmath@parse@next=\pgfmath@operation@@process%
			\else%
				\let\pgfmath@parse@next=\relax%
			\fi%
		\fi%
	\fi%
	\pgfmath@parse@next%
}

% Process an operator.
%
\def\pgfmath@operator@@@process{% Process an operator.
	\pgfmath@stack@pop@operation\pgfmath@@operator%
	\pgfmath@stack@pop@operand\pgfmath@operand@a%	
	\ifcase\csname pgfmath@operation@\pgfmath@@operator @arity\endcsname\relax%
		% Zero arity operators (!).
	\or%		
		\pgfmath@operator@@@@process{\pgfmath@operand@a}%
	\or%
		\pgfmath@stack@pop@operand\pgfmath@operand@b%
		\pgfmath@operator@@@@process{\pgfmath@operand@b}{\pgfmath@operand@a}%
	\or%
		\pgfmath@stack@pop@operand\pgfmath@operand@b%
		\expandafter\pgfmath@operator@@@@process\expandafter%
			{\expandafter\pgfmath@operand@b\expandafter}\pgfmath@operand@a%		
	\else%
		% No operators with more than tenary arity.
	\fi%
}

\def\pgfmath@operator@@@@process{%
	\csname pgfmath%
		\csname pgfmath@operation@\pgfmath@@operator @name\endcsname%
	@\endcsname}

% Process a function.
%
\def\pgfmath@function@@@process{% Process a function.
	\ifnum\csname pgfmath@operation@\pgfmath@stack@operation@top @arity\endcsname>0\relax%
		\pgfmath@stack@pop@operation\pgfmath@@function%
		\pgfmath@stack@pop@operand\pgfmath@@operand%
		\ifnum\csname pgfmath@operation@\pgfmath@@function @arity\endcsname>1\relax%
			\ifnum\csname pgfmath@operation@\pgfmath@@function @arity\endcsname>9\relax%
				\csname pgfmath\pgfmath@@function @\endcsname{\pgfmath@@operand}%
			\else%
				\expandafter\pgfmath@function@@@@process\pgfmath@@operand%
			\fi
		\else%
			\expandafter\pgfmath@function@@@@process\expandafter{\pgfmath@@operand}%
		\fi%
	\fi%		
}

\def\pgfmath@function@@@@process{\csname pgfmath\pgfmath@@function @\endcsname}

% Stack.
%
\newtoks\pgfmath@stack@operand
\newtoks\pgfmath@stack@operation
\let\pgfmath@stack@empty=\pgfmath@empty

\def\pgfmath@stack@push#1#2{%
	\def\pgfmath@stack@top{#2}%
	\expandafter\expandafter\expandafter#1%
		\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter%
			{\expandafter\pgfmath@stack@top\expandafter}\the#1}}%

\def\pgfmath@stack@pop#1#2{\expandafter\pgfmath@stack@@pop\the#1\pgfmath@stack@stop{#1}{#2}}
\def\pgfmath@stack@@pop#1#2#3\pgfmath@stack@stop#4#5{\def#5{#1}#4={{#2}#3}\def\pgfmath@stack@top{#2}}

\def\pgfmath@stack@push@operation#1{%
	\pgfmath@stack@push\pgfmath@stack@operation{#1}%
	\let\pgfmath@stack@operation@top=\pgfmath@stack@top}

\def\pgfmath@stack@pop@operation#1{%
	\pgfmath@stack@pop\pgfmath@stack@operation{#1}%
	\let\pgfmath@stack@operation@top=\pgfmath@stack@top}
	
% REMARK: This method will be overwritten by the FPU library. Please
% keep any changes consistent.
\def\pgfmath@stack@push@operand#1{%
	\pgfmath@stack@push\pgfmath@stack@operand{#1}%
	\let\pgfmath@stack@operand@top=\pgfmath@stack@top}

\def\pgfmath@stack@pop@operand#1{%
	\pgfmath@stack@pop\pgfmath@stack@operand{#1}%
	\let\pgfmath@stack@operand@top=\pgfmath@stack@top}
	

% Declare an operator for the parser.
%
% It is not recommended that new operators be created as 
% the parser is not fully robust for arbitrary operators.
%
\def\pgfmathdeclareoperator#1#2#3#4#5{%
	\pgfmath@namedef{pgfmath@operator@\string#1}{#1}%
	\pgfmath@namedef{pgfmath@operation@\string#1@name}{#2}%
	\pgfmath@namedef{pgfmath@operation@\string#1@arity}{#3}%
	\pgfmath@namedef{pgfmath@operation@\string#1@#4}{#1}%
	\pgfmath@namedef{pgfmath@operation@\string#1@precedence}{#5}%
}

\pgfmathdeclareoperator{+}{add}     {2}{infix}{500}
\pgfmathdeclareoperator{-}{subtract}{2}{infix}{500}
\pgfmathdeclareoperator{*}{multiply}{2}{infix}{700}
\pgfmathdeclareoperator{/}{divide}  {2}{infix}{700}
\pgfmathdeclareoperator{^}{pow}     {2}{infix}{900}

\pgfmathdeclareoperator{<} {}       {1}{prefix} {1}

\pgfmathdeclareoperator{>} {greater}   {2}{infix} {250}
\pgfmathdeclareoperator{<} {less}      {2}{infix} {250}
\pgfmathdeclareoperator{==}{equal}     {2}{infix} {250}
\pgfmathdeclareoperator{>=}{notless}   {2}{infix} {250}
\pgfmathdeclareoperator{<=}{notgreater}{2}{infix} {250}
\pgfmathdeclareoperator{&&}{and}       {2}{infix} {200}
\pgfmathdeclareoperator{||}{or}        {2}{infix} {200}
\pgfmathdeclareoperator{!=}{notequalto}{2}{infix} {250}
\pgfmathdeclareoperator{!} {not}       {1}{prefix}{975}
\pgfmathdeclareoperator{?} {ifthenelse}{3}{infix} {100}
\pgfmathdeclareoperator{:} {@@collect}  {2}{infix}{101}

\pgfmathdeclareoperator{!}{factorial}{1}{postfix}{800}% Must be defined after prefix ! operator.
\pgfmathdeclareoperator{r}{deg}      {1}{postfix}{600}

\pgfmathdeclareoperator{,}{@collect}   {2}{infix}  {10}
\pgfmathdeclareoperator{[}{@startindex}{2}{prefix} {7}
\pgfmathdeclareoperator{]}{@endindex}  {0}{postfix}{6}
\pgfmathdeclareoperator{(}{@startgroup}{1}{prefix} {5}
\pgfmathdeclareoperator{)}{@endgroup}  {0}{postfix}{4}

\pgfmathdeclareoperator{\pgfmath@bgroup}{@startarray}{1}{prefix} {3}
\pgfmathdeclareoperator{\pgfmath@egroup}{@endarray}  {1}{postfix}{2}% 

% Special operators.
\pgfmathdeclareoperator{"}{}{1}{prefix}{1}
\pgfmathdeclareoperator{@}{}{0}{postfix}{0}

% Internal functions.

% Begin and end parenthesis ().
%
\def\pgfmath@startgroup@#1{\edef\pgfmathresult{#1}}
\def\pgfmath@endgroup@{}% Never actually called.

% Begin and end array access [].
%
\def\pgfmath@startindex@#1#2{%
	\expandafter\pgfmatharray@#1{#2}%
	\expandafter\pgfmath@bgroup@strip\expandafter{\pgfmathresult}%
	\ifx\pgfmath@token@let\bgroup%
		\expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmathresult}}%
	\fi}
\def\pgfmath@endindex@{}% Never actually called.

% Begin and end array {}.
%
\def\pgfmath@startarray@#1{\expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{#1}}}
\def\pgfmath@endarray@#1{\expandafter\def\expandafter\pgfmathresult\expandafter{#1}}% Never actually called.


\def\pgfmath@@collect@#1#2{%
	\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
		\pgfmathresult\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter%
			{\expandafter#1\expandafter}\expandafter{#2}}%
}
% Collect items separated by ,.
%
\def\pgfmath@collect@#1#2{%
	\expandafter\def\expandafter\pgfmath@collect@original\expandafter{#1}%
	\expandafter\pgfmath@bgroup@strip\expandafter{#1}%
	\ifx\pgfmath@token@let\bgroup%
		\ifx\pgfmath@collect@original\pgfmath@bgroup@stripped%
			\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmath@bgroup@stripped}%
		\else%
			\expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmath@bgroup@stripped}}%
		\fi%
	\else%
		\expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmath@bgroup@stripped}}%
	\fi%
	\expandafter\pgfmath@bgroup@strip\expandafter{#2}%
	\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
		\pgfmathresult\expandafter\expandafter\expandafter%
			{\expandafter\pgfmathresult\expandafter{\pgfmath@bgroup@stripped}}%
}

% Strip braces from a token sequence.
%
\def\pgfmath@bgroup@strip#1{%
	\def\pgfmath@bgroup@strip@last{#1}%
	\pgfmath@bgroup@@strip{#1}\pgfmath@\pgfmath@@\pgfmath@@@}

\def\pgfmath@bgroup@strip@#1{%
	\def\pgfmath@bgroup@strip@last{#1}%
	\pgfmath@bgroup@@strip#1\pgfmath@\pgfmath@@\pgfmath@@@}

\def\pgfmath@bgroup@pgfmath@{\pgfmath@}

\def\pgfmath@bgroup@@strip{\futurelet\pgfmath@token@let\pgfmath@bgroup@@@strip}
\def\pgfmath@bgroup@@@strip#1#2#3\pgfmath@@@{%
	\ifx\pgfmath@token@let\bgroup%
		\def\pgfmath@bgroup@test{#2}%
		\ifx\pgfmath@bgroup@test\pgfmath@bgroup@pgfmath@%
			\def\pgfmath@next{\pgfmath@bgroup@strip@{#1}}%
		\else%
			\let\pgfmath@bgroup@stripped=\pgfmath@bgroup@strip@last%
			\let\pgfmath@next=\relax%
		\fi%
	\else%
		\pgfmath@bgroup@@@@strip#1#2#3%
		\let\pgfmath@next=\relax%
	\fi%
	\pgfmath@next%
}

\def\pgfmath@bgroup@@@@strip#1\pgfmath@\pgfmath@@{\def\pgfmath@bgroup@stripped{#1}}%

pgfmathutil.code.tex
% Copyright 2007 Mark Wibrow
%
% but subject to the LaTeX Project Public License 
% (http://www.latex-project.org/lppl.txt)
%
% and the GNU Public License 
% (http://www.gnu.org/licenses/gpl.txt)
%

% This file defines utilities common to the \pgfmath files.
%
% Version 1.414213 29/9/2007

\def\pgfmathincluded{}

% \pgfmath@ensureregister
%
% Ensure a control sequence exists as a TeX count/dimen register.
%
% #1 - count or dimen.
% #2 - a control sequence.
%
\def\pgfmath@ensureregister#1#2{%
	\begingroup%
	\setbox0=\hbox\bgroup\begingroup% In case #2 is a defined macro. Unlikely, but you never know...
		\afterassignment\pgfmath@@ensureregister%
		\noexpand#20.0pt\let\pgfmath@temp\relax\relax\pgfmath@#2#1\pgfmath@}

\def\pgfmath@@ensureregister#1#2\pgfmath@#3#4#5\pgfmath@{%
		\endgroup\egroup%
	\endgroup%
	\ifx#4c% 
		\ifx#1.% Already a count register.
		\else%
			\csname newcount\endcsname#3% This gets round \outer in plain TeX.
		\fi%
	\else%
		\ifx#4d% 
			\ifx\let#1% Already a dimen register.
			\else%
				\csname newdimen\endcsname#3%
			\fi%
		\fi%
	\fi%
}

% Check registers exist. If not, create them. 
%
\pgfmath@ensureregister{dimen}{\pgf@x}
\pgfmath@ensureregister{dimen}{\pgf@xa}
\pgfmath@ensureregister{dimen}{\pgf@xb}
\pgfmath@ensureregister{dimen}{\pgf@xc}

\pgfmath@ensureregister{dimen}{\pgf@y}
\pgfmath@ensureregister{dimen}{\pgf@ya}
\pgfmath@ensureregister{dimen}{\pgf@yb}
\pgfmath@ensureregister{dimen}{\pgf@yc}

\pgfmath@ensureregister{dimen}{\pgfutil@tempdima}
\pgfmath@ensureregister{dimen}{\pgfutil@tempdimb}

\pgfmath@ensureregister{count}{\c@pgf@counta}
\pgfmath@ensureregister{count}{\c@pgf@countb}
\pgfmath@ensureregister{count}{\c@pgf@countc}
\pgfmath@ensureregister{count}{\c@pgf@countd}

\pgfmath@ensureregister{count}{\pgfutil@tempcnta}
\pgfmath@ensureregister{count}{\pgfutil@tempcntb}

% Alias for \pgfmath.
%
\let\pgfmath@x\pgf@x
\let\pgfmath@xa\pgf@xa
\let\pgfmath@xb\pgf@xb
\let\pgfmath@xc\pgf@xc

\let\pgfmath@y\pgf@y
\let\pgfmath@ya\pgf@ya
\let\pgfmath@yb\pgf@yb
\let\pgfmath@yc\pgf@yc

\let\pgfmath@tempdima\pgfutil@tempdima
\let\pgfmath@tempdima\pgfutil@tempdima

\let\c@pgfmath@counta\c@pgf@counta
\let\c@pgfmath@countb\c@pgf@countb
\let\c@pgfmath@countc\c@pgf@countc
\let\c@pgfmath@countd\c@pgf@countd

\let\pgfmath@tempcnta\pgfutil@tempcnta
\let\pgfmath@tempcntb\pgfutil@tempcntb

% Now check if pgfutil and pgf@sys stuff exists. If it does, fine.
% Just \let pgfmath versions. If not, define pgfmath versions (Arghhh). 
%

% \...ifnextchar
%
\ifx\pgfutil@ifnextchar\pgfmath@undefined%
	\long\def\pgfmath@ifnextchar#1#2#3{%
  \let\pgfmath@reserved@d#1%
  \def\pgfmath@reserved@a{#2}%
  \def\pgfmath@reserved@b{#3}%
  \futurelet\pgfmath@let@token\pgfmath@ifnch}
	\def\pgfmath@ifnch{%
	  \ifx\pgfmath@let@token\pgfmath@sptoken%
	    \let\pgfmath@reserved@c\pgfmath@xifnch%
	  \else%
	    \ifx\pgfmath@let@token\pgfmath@reserved@d%
	      \let\pgfmath@reserved@c\pgfmath@reserved@a%
	    \else%
	      \let\pgfmath@reserved@c\pgfmath@reserved@b%
	    \fi%
	  \fi%
	  \pgfmath@reserved@c}
	{%
	  \def\:{\global\let\pgfmath@sptoken= } \:
	  \def\:{\pgfmath@xifnch} \expandafter\gdef\: {\futurelet\pgfmath@let@token\pgfmath@ifnch}
	}%
\else%
	\let\pgfmath@ifnextchar\pgfutil@ifnextchar%
	% Still need to define \pgfmath@sptoken (cannot \let).
	{%
		\def\:{\global\let\pgfmath@sptoken= } \:
	}%
\fi%

% \...ifundefined
%
\ifx\pgfutil@ifundefined\pgfmath@undefined%
	\long\def\pgfmath@ifundefined#1{%
	  \expandafter\ifx\csname#1\endcsname\relax%
	    \expandafter\pgfmath@firstoftwo%
	  \else%
	    \expandafter\pgfmath@secondoftwo%
	  \fi}%
\else%
	\let\pgfmath@ifundefined\pgfutil@ifundefined%
\fi%

% \...selectfont
%
\ifx\pgfutil@selectfont\pgfmath@undefined%
	\ifx\selectfont\pgfmath@undefined%
		\let\pgfmath@selectfont\rm% Plain TeX and ConTeXt.
	\else%
		\let\pgfmath@selectfont\selectfont% LaTeX.
	\fi%
\else%
	\let\pgfmath@selectfont\pgfutil@selectfont%
\fi%

% New definition easier than fussing around with let.
%
\newif\ifpgfmath@in@
\def\pgfmath@in@#1#2{%
 \def\pgfmath@in@@##1#1##2##3\pgfmath@in@@{%
  \ifx\pgfmath@in@##2\pgfmath@in@false\else\pgfmath@in@true\fi}%
 \pgfmath@in@@#2#1\pgfmath@in@\pgfmath@in@@}


% \...tonumber
%
\ifx\pgf@sys@tonumber\pgfmath@undefined%
  {\catcode`\p=12\catcode`\t=12\gdef\Pgf@geT#1pt{#1}}
	\def\pgfmath@tonumber#1{\expandafter\Pgf@geT\the#1}
\else%
	\let\pgfmath@tonumber\pgf@sys@tonumber%
\fi%


% \PackageWarning and \PackageError
%
\ifx\PackageWarning\pgfmath@undefined
	\def\pgfmath@PackageWarning#1#2{\immediate\write-1{Package #1: Warning! #2.}}%
\else%
	\let\pgfmath@PackageWarning\PackageWarning%
\fi%
\ifx\PackageError\pgfmath@undefined
	\def\pgfmath@PackageError#1#2#3{\immediate\write-1{Package #1: Error! #2.}}%
\else%
	\let\pgfmath@PackageError\PackageError%
\fi%

\def\pgfmath@error#1#2{%
	\pgfmath@PackageError{PGF Math}{%
		#1%
		\pgfutil@ifundefined{pgfmath@expression}{}{ (in '\pgfmath@expression')}%
	}{#2}%
}
\def\pgfmath@warning#1{%
	\pgfmath@PackageWarning{PGF Math}{%
		#1%
		\pgfutil@ifundefined{pgfmath@expression}{}{ (in '\pgfmath@expression')}%
	}%
}

% \pgfmath@pt
%
% Needed to test for 'pt' resulting from expansion using \the.
%
{\catcode`\p=12\catcode`\t=12\gdef\PgfmaTh@PT{pt}}		
\edef\pgfmath@pt{\PgfmaTh@PT}%

% \pgfmath@empty
%
% A handy macro.
%
\def\pgfmath@empty{}

\def\pgfmath@firstoftwo#1#2{#1}
\def\pgfmath@secondoftwo#1#2{#2}

% \pgfmath@gobbletilpgfmath@
%
% Gobble stream until \pgfmath@ {which is undefined}.
% 
\def\pgfmath@gobbletilpgfmath@#1\pgfmath@{}
\def\pgfmath@gobbleone#1{}%


\def\pgfmath@namedef#1{\expandafter\def\csname#1\endcsname}
\def\pgfmath@nameedef#1{\expandafter\edef\csname#1\endcsname}

% \pgfmathloop
%
% A version of the standard TeX and LaTeX
% \loop, with an additional macro \pgfmathcounter
% (which is *not* a TeX counter) which keeps
% track of the iterations.
%
\newif\ifpgfmathcontinueloop
\def\pgfmathloop#1\repeatpgfmathloop{%
	\def\pgfmathcounter{1}%
	\def\pgfmath@iterate{%
		#1\relax%
		{% Do this inside a group, just in case...
			\c@pgfmath@counta\pgfmathcounter%
			\advance\c@pgfmath@counta1\relax%
			\xdef\pgfmathloop@temp{\the\c@pgfmath@counta}%
		}%	
		\edef\pgfmathcounter{\pgfmathloop@temp}%
		\expandafter\pgfmath@iterate\fi}%
	\pgfmath@iterate\let\pgfmath@iterate\relax}
\let\repeatpgfmathloop\fi
\def\pgfmathbreakloop{\let\pgfmath@iterate\relax}%

% \pgfmath@returnone
%
% #1 - a dimension representing a number or dimension.
%
% Changed by TT: made faster and simpler since it is used
% *heavily*. #1 must be something that can be assigned to a
% dimension. 
%
\def\pgfmath@returnone#1\endgroup{%
  \pgfmath@x#1%
  \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@x}}%
  \expandafter\endgroup\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmath@temp}%
}

\let\pgfmathreturn=\pgfmath@returnone

% \pgfmath@smuggleone
%
% Smuggle a macro outside a group.
%
% Changed by TT: Speedup by insisting, that smuggleone is directly
% followed by \endgroup
%
\def\pgfmath@smuggleone#1\endgroup{%
  \expandafter\endgroup\expandafter\def\expandafter#1\expandafter{#1}}  

\let\pgfmathsmuggle=\pgfmath@smuggleone

pgfrcs.code.tex
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.



% The purpose of this file is to define the command
% \ProvidesPackageRCS, which should be followed by an RCS id
% string. This command will also be available in plain TeX, where it
% prints out a message to the log.


%\def\pgfversion{2.00-cvs}
%\def\pgftypesetversion{\oldstylenums{2}.\oldstylenums{00}--\textsc{cvs}}
\def\pgfversion{2.10}
\def\pgftypesetversion{\oldstylenums{2}.\oldstylenums{10}}


\ifx\pgfrcsloaded\undefined
\def\pgfrcsloaded{}

\edef\pgfrcsatcode{\the\catcode`\@}
\catcode`\@=11

% Get date and version from RCS Ids
\def\pgf@parseid $#1: #2.#3,v #4 #5/#6/#7 #8${%
  \pgf@parsercsfile$#2/$
  \def\pgf@rcssuffix{#3}
  \def\pgf@rcsrevision{#4}
  \def\pgf@rcsdate{#5/#6/#7}
}
\def\pgf@parsercsfile$#1/#2${
  \def\pgf@temp{#2}
  \ifx\pgf@temp\pgfutil@empty
    \def\pgf@rcsfile{#1}
  \else
    \pgf@parsercsfile$#2$
  \fi}

\def\ProvidesFileRCS{%
  \def\pgfrcs@marshal{\ProvidesFile{\pgf@rcsfile.\pgf@rcssuffix}}%
  \pgfrcs@parserest%
}

\def\ProvidesPackageRCS{%
  \def\pgfrcs@marshal{\ProvidesPackage{\pgf@rcsfile}}%
  \pgfrcs@parserest%
}

\def\pgfrcs@parserest{%
  \def\pgf@rcsadditional{}%
  \afterassignment\pgfrcs@checkforoptional\let\next=}

\def\pgfrcs@checkforoptional{%
  \ifx\next[%
    \let\next=\pgfrcs@getoptional%
  \else
    \let\next=\pgfrcs@package%
  \fi%
  \next}%}

\def\pgfrcs@getoptional#1] ${%
  \def\pgf@rcsadditional{#1}%
  \pgfrcs@package%
}

\def\pgfrcs@package#1${
  \pgf@parseid $#1$
  \pgfrcs@marshal[\pgf@rcsdate\space\pgf@rcsadditional\space(rcs-revision \pgf@rcsrevision)]
}

\def\ProvidesClassRCS $#1$ [#2]{%
  \pgf@parseid $#1$
  \ProvidesClass{\pgf@rcsfile}[\pgf@rcsdate\space#2\space (rcs-revision \pgf@rcsrevision)]
}

\ifx\ProvidesPackage\@undefined
  % plain tex
  \def\ProvidesPackage#1[#2]{\wlog{Loading package #1 version #2.}}
\fi

\ifx\ProvidesFile\@undefined
  % plain tex
  \def\ProvidesFile#1[#2]{\wlog{Loading file #1 version #2.}}
\fi

\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/utilities/pgfrcs.code.tex,v 1.24 2010/10/25 20:57:06 ludewich Exp $

\catcode`\@=\pgfrcsatcode

\fi


pgfsys.code.tex
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsys.code.tex,v 1.37 2010/06/30 13:06:37 ludewich Exp $


% Load key mechanism
\input pgfkeys.code.tex

% "pgf" is a family
\pgfkeys{/pgf/.is family}
\def\pgfset{\pgfqkeys{/pgf}}

%
% The following conversion functions are used to convert from TeX
% dimensions to postscript/pdf points.
% 
{\catcode`\p=12\catcode`\t=12\gdef\Pgf@geT#1pt{#1}}

\def\pgf@sys@tonumber#1{\expandafter\Pgf@geT\the#1}

\def\pgf@sys@bp@correct#1{#1=0.99627#1}

\def\pgf@sys@bp#1{%
  {%
    \pgf@x=#1\relax%
    \pgf@x=0.99627\pgf@x%
    \edef\temp{\expandafter\Pgf@geT\the\pgf@x\space}%
    \pgfutil@toks@\expandafter\expandafter\expandafter{\expandafter\pgfsysprotocol@currentprotocol\temp}%
    \xdef\pgfsysprotocol@currentprotocol{\the\pgfutil@toks@}%
  }%
}
\def\pgf@sys@pt#1{%
  {%
    \pgf@x=#1\relax%
    \edef\temp{\expandafter\Pgf@geT\the\pgf@x\space}%
    \pgfutil@toks@\expandafter\expandafter\expandafter{\expandafter\pgfsysprotocol@currentprotocol\temp}%
    \xdef\pgfsysprotocol@currentprotocol{\the\pgfutil@toks@}%
  }%
}


% internal dimensions that are always present when pgsys is loaded.
\newdimen\pgf@x
\newdimen\pgf@y
\newdimen\pgf@xa
\newdimen\pgf@ya
\newdimen\pgf@xb
\newdimen\pgf@yb
\newdimen\pgf@xc
\newdimen\pgf@yc

\newwrite\w@pgf@writea
\newread\r@pgf@reada
\let\pgfutil@inputcheck=\r@pgf@reada

% internal counters that are alwyas present when pgfsys is loaded
\newcount\c@pgf@counta
\newcount\c@pgf@countb
\newcount\c@pgf@countc
\newcount\c@pgf@countd


% The following \if decides, whether even-odd filling and clipping is
% to be used or normal the non-zero winding number rule. See the
% pdf-documentation for details on what these rules are.

\newif\ifpgfsys@eorule



% In the following dummy definitions of the pgf system commands are
% given. The individual drivers must overwrite these definitions,
% preferably all of them. If some system command is used that has not
% been overwritten, the command fails with a warning.
%
% In some cases, some pgf system commands are just shorthands for a
% series of more complicated commands. In this case, a default
% implementation is given in this file, but a driver may choose to
% overwrite this default implementation with a more effecient
% version. For example, a closestroke is the same as a closepath
% followed by a stroking, but in pdf there is a special shorthand for
% this. So, the pdf driver overwrites \pgfsys@closestroke, while the
% postscript driver does not.
%
% The commands for which default implementations are available are
% given at the end.

\def\pgf@sys@fail#1{%
  \expandafter\ifx\csname pgf@sys@fail@#1\endcsname\pgfutil@empty%
  \else%
    \expandafter\global\expandafter\let\csname pgf@sys@fail@#1\endcsname=\pgfutil@empty%
    \PackageWarning{pgf}{%
      Your graphic driver \pgfsysdriver\space does not support #1. This warning is given only once}%
  \fi%
}



\def\pgfsys@invoke{\pgf@sys@fail{invoking specials}}
% This command is used whenever some literal text needs to be inserted
% into the resulting .pdf, .ps, or .dvi file. Note that most
% \pgfsys@xxxx commands will not directly call this command, but,
% rather, use the protocolling mechanism to record their literal
% text. It is then left to the discretion of the protocolling
% mechansim to insert the literal text at some appropriate, later
% time. 
%
% This command should only be called when \pgfsys@beginpicture has
% been called previously and when the picture has not been suspended
% using \pgfsys@beginhbox.


\def\pgfsys@outerinvoke{\pgfsys@invoke}
% This command can be used to insert protocolled graphic commands
% outside any picture. This is extremely dangerous, but sometimes
% useful. By default, this command does the same as inside pictures. 



%
%
% Path construction commands
%
%

\def\pgfsys@moveto#1#2{\pgf@sys@fail{path constructions}}
% This command is used to start a path at a specific point (#1bp,#2bp)
% or to move the current point of the current path to (#1bp,#2bp)
% without drawing anything upon stroking (the current path is
% `interrupted'). 
%
% Here (and in the following) the coordinates are in TeX's big points
% (bp), unless the coordinate system has been scaled. A big point is
% 1/72 inches. Note that TeX's point pt is 1/72.27 inches.
%
% Example:
%
% \pgfsys@moveto{10}{10}
% \pgfsys@lineto{0}{0}
% \pgfsys@stroke
%
% This will draw a line from (10bp,10bp) to the origin of the picture.

\def\pgfsys@lineto#1#2{\pgf@sys@fail{path constructions}}
% Continue the current path to (#1bp,#2bp) with a line.

\def\pgfsys@curveto#1#2#3#4#5#6{\pgf@sys@fail{path constructions}}
% Continue the current path with a bezier curver to (#5bp,#6bp). The
% control points of the curve are at (#1bp,#2bp) and (#3bp,#4bp).

\def\pgfsys@rect#1#2#3#4{\pgf@sys@fail{path constructions}}
% Append a rectangle to the current path whose lower left corner is at
% (#1bp,#2bp) and whose width/height is given by (#3bp,#4bp).
%
% This command can be `mapped back' to moveto and lineto commands, but
% it is included since pdf has a special, quick version of this command.

\def\pgfsys@closepath{\pgf@sys@fail{path constructions}}
% Close the current path. This results in joining the current point of
% the path with the point specified by the last moveto
% operation. Typically, this is preferable over using lineto to the
% last point specified by a moveto, since the line starting at this
% point and the line ending at this point will be smoothly joined by
% closepath. 
%
% Example:
%
% \pgfsys@moveto{0}{0}
% \pgfsys@lineto{10}{10}
% \pgfsys@lineto{0}{10}
% \pgfsys@closepath
% \pgfsys@stroke
%
% versus
%
% \pgfsys@moveto{0}{0}
% \pgfsys@lineto{10}{10}
% \pgfsys@lineto{0}{10}
% \pgfsys@lineto{0}{0}
% \pgfsys@stroke
% 
% The difference between the above will be that in the second triangle
% the corner at the origin will be wrong; it will just be the overlay
% of two lines going in different directions, not a sharp pointed
% corner.






%
%
% Stroking and filling commands
%
%

\def\pgfsys@stroke{\pgf@sys@fail{path usage}}
% Stroke the current path (as if it were drawn with a pen). A number
% of so-called graphic state parameters influence this, which can be
% set in different ways:
%
% - linewidth
%   The `thickness' of the line. A width of 0 is the thinnest width
%   renderable on the device. On a high-resolution printer this may
%   become invisible and should be avoided. A good choice is 0.4pt,
%   which is the default.
%
% - stroke color
%   This special color is used for stroking. If it is not set, the
%   current color is used.
%
% - cap
%   The cap describes how the endings of lines a drawn. A round cap
%   adds a little half circle to these endings. A butt cap ends the
%   lines exactly at the end (or start) point without anything
%   added. A rectangular cap ends the lines like the butt cap, but the
%   lines protrude over the endpoint by the line thickness. (See also
%   the pdf or postscript manual). If the path has been closed, no cap
%   is drawn.
%
% - join
%   This describes how a bend (a join) in a path is rendered. A round
%   join draws bends using small arcs. A bevel join just draws the two
%   lines and then fills the join minimally so that it becomes
%   convex. A miter join extends the lines so that they form a single
%   sharp corner, but only up to a certain miter limit. (See the pdf
%   or postscript manual once more).
%
% - dash
%   The line may be dashed according to a dashing pattern.
%
% - clipping area
%   If a clipping area is established, only those parts of the path
%   that are inside the clipping area will be drawn.
%
% In addition to stroking a path, the path may also be used for
% clipping after it has been stroked. This will happen if the
% \pgfsys@clipnext is used prior to this command, see there for
% details.

\def\pgfsys@fill{\pgf@sys@fail{path usage}}
% This command fills the area surrounded by the current path. If the
% path has not yet been closed, it is closed prior to filling. The
% path itself is not stroked. For self-intersecting paths or paths
% consisting of multiple parts, the nonzero winding number rule is
% used to determine whether a point is inside or outside the
% path, except if \ifpgfsys@eorule holds -- in which case the even-odd
% rule should be used. (See the pdf or postscript manual for details.) 
%
% The following graphic state parameters influence the filling:
%
% - fill color
%   If the fill color is not especially set, the current color is
%   used. 
%
% - clipping area
%   If a clipping area is established, only those parts of the filling
%   area that are inside the clipping area will be drawn.
%
% In addition to filling the path, the path will also be used for
% clipping if \pgfsys@clipnext is used prior to this command.

\def\pgfsys@fillstroke{\pgf@sys@fail{path usage}}
% First, the path is filled, then the path is stroked. If the fill and
% stroke colors are the same (or if they are not specified and the
% current color is used), this yields almost the same as a
% \pgfsys@fill. However, due to the line thickness of the stroked
% path, the fillstroked area will be slightly larger.
%
% In addition to stroking and filling the path, the path will also be
% used for clipping if \pgfsys@clipnext is used prior to this command.

\def\pgfsys@clipnext{\pgf@sys@fail{path usage}}
% This command should be issued after a path has been constructed, but
% before it has been stroked and/or filled or discarded. When the
% command is used, the next stroking/filling/discarding command will
% first be executed normally. Then, afterwards, the just-used path
% will be used for subsequent clipping. If there has already been a
% clipping region, this region is intersected with the new clipping
% path (the clipping cannot get bigger). The nonzero winding number
% rule is used to determine whether a point is inside or outside the
% clipping area or the even-odd rule, depending on whether
% \ifpgfsys@eorule holds.

\def\pgfsys@discardpath{\pgf@sys@fail{path usage}}
% Normally, this command should `throw away' the current path.
% However, after \pgfsys@clipnext has been called, the current path
% should subsequently be used for clipping. See \pgfsys@clipnext for
% details. 





%
%
% Stroking options
%
%
\def\pgfsys@setlinewidth#1{\pgf@sys@fail{setting the line width}}
% Sets the width of lines, when stroked, to #1bp.

\def\pgfsys@buttcap{\pgf@sys@fail{setting the line cap}}
% Sets the cap to a butt cap. See \pgfsys@stroke.

\def\pgfsys@roundcap{\pgf@sys@fail{setting the line cap}}
% Sets the cap to a round cap. See \pgfsys@stroke.

\def\pgfsys@rectcap{\pgf@sys@fail{setting the line cap}}
% Sets the cap to a rectangular cap. See \pgfsys@stroke.

\def\pgfsys@miterjoin{\pgf@sys@fail{setting the line join}}
% Sets the join to a miter join. See \pgfsys@stroke.

\def\pgfsys@setmiterlimit#1{\pgf@sys@fail{setting the line cap}}
% Sets the miter limit of lines to #1. See the pdf or postscript
% documentation.

\def\pgfsys@roundjoin{\pgf@sys@fail{setting the line cap}}
% Sets the join to a round join. See \pgfsys@stroke.

\def\pgfsys@beveljoin{\pgf@sys@fail{setting the line cap}}
% Sets the join to a bevel join. See \pgfsys@stroke.

\def\pgfsys@setdash#1#2{\pgf@sys@fail{setting the dashing pattern}}
% Sets the dashing patter. #1 should be a list of lengths given in big
% points (bp) separated by spaces. #2 should be a single value given
% in bp.
%
% The list of values in #1 is used to determine the lengths of the
% `on' phases of the dashing and of the `off' phases. For example, if
% #1 is `3 4', then the dashing pattern is `3bp on followed by 4bp
% off, followed by 3bp on, followed by 4bp off, and so on'. A pattern
% of `.5 4 3 1.5' means `.5bp on, 4bp off, 3bp on, 1.5bp off, .5bp on,
% ...'. If the number of entries is odd, the last one is used twice,
% so `3' means `3bp on, 3bp off, 3bp on, 3bp off,...'. An empty list
% means `always on'.
%
% The second argument determines the `phase' of the pattern. For
% example, for a pattern of `3 4' and a phase of `1', the pattern
% would start: `2bp on, 4bp off, 3bp on, 4bp off, 3bp on, 4bp off...'.





%
%
% Color stuff
%
%

\def\pgfsys@color@rgb@stroke#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given rgb tuple
% (numbers between 0 and 1). 
%
% Example: Make stroked text dark red: \pgfsys@color@rgb@stroke{0.5}{0}{0}
%
% The special stroking color is only used if the stroking color has
% been set since the last \pgfutil@color command. Thus, each \pgfutil@color command
% should reset both the stroking and filling colors.

\def\pgfsys@color@rgb@fill#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given rgb tuple
% (numbers between 0 and 1). This color may be different from the
% stroking color.

\def\pgfsys@color@rgb#1#2#3{\pgfsys@color@rgb@stroke{#1}{#2}{#3}\pgfsys@color@rgb@fill{#1}{#2}{#3}}
% Sets the color used for filling and stroking operations. This is a
% ``low-level'' version of the \pgfutil@color command. It is currently only
% used by the plain tex version to support colors.

\def\pgfsys@color@cmyk@stroke#1#2#3#4{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given cymk tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmyk@fill#1#2#3#4{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given cymk tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmyk#1#2#3#4{\pgfsys@color@cmyk@stroke{#1}{#2}{#3}{#4}\pgfsys@color@cmyk@fill{#1}{#2}{#3}{#4}}
% Sets the color used for filling and stroking operations.

\def\pgfsys@color@cmy@stroke#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given cym tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmy@fill#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given cym tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmy#1#2#3{\pgfsys@color@cmy@stroke{#1}{#2}{#3}\pgfsys@color@cmy@fill{#1}{#2}{#3}}
% Sets the color used for filling and stroking operations.

\def\pgfsys@color@gray@stroke#1{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given gray level 
% (number between 0 and 1). 

\def\pgfsys@color@gray@fill#1{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given gray level 
% (number between 0 and 1). 

\def\pgfsys@color@gray#1{\pgfsys@color@gray@stroke{#1}\pgfsys@color@gray@fill{#1}}
% Sets the color used for filling and stroking operations.

\newif\ifpgfsys@color@reset@inorder
% This if decides whether the color resetting of the
% \pgfsys@color@reset command may assume that all color commands are
% given ``in order.'' This means that this command will not be called,
% say, at the beginning of a box that is later inserted at a point
% where a fill color was actively set. This may allow the command to
% produce more compact code when it ``knows'' that no special fill or
% stroke color has been set.
\pgfsys@color@reset@inordertrue


\def\pgfsys@color@reset{}
% This command will be called when the \pgfutil@color command is used. It
% should purge any internal settings of stroking and filling
% color. After this call, till the next use of a command like
% \pgfsys@color@rgb@fill, the current color installed by the \pgfutil@color
% command should be used.

\def\pgfsys@color@unstacked#1{}
% This slightly obscure command causes the color stack to be
% tricked. When called, this command should set the current color to
% #1 without causing any change in the color stack. 



%
%
% Coordinate system transformations
%
%

\def\pgfsys@transformcm#1#2#3#4#5#6{\pgf@sys@fail{transformations}}
% Perform a concatenation of the low-level current transformation
% matrix with the matrix given by the values #1 to #6. The
% transformation matrix is a transformation on a homogeneous
% 2D-coordinate system. See the pdf or postscript manual for details. 




%
%
% Graphic state saving and restoring.
%
%

\def\pgfsys@beginscope{\pgf@sys@fail{scoping}}
% Saves the current graphic state on a graphic state stack. All
% changes to the graphic state parameters mentioned for \pgfsys@stroke
% and \pgfsys@fill will be local to the current graphic state and will
% the old values will be restored after endscope is used.
%
% WARNING: pdf and postscript differ with respect to the question of
% whether the current path is part of the graphic state or not. For
% this reason, you should never use this command unless the path is
% currently empty. For example, it might be a good idea to use
% discardpath prior to calling this command. 

\def\pgfsys@endscope{\pgf@sys@fail{scoping}}
% Restores the last saved graphic state.




%
%
% Special commands
%
%

\def\pgfsys@imagesuffixlist{}
% A list of suffixes, separated by `:', that will be tried when
% searching for an image.



%
%
% Transparency
%
%

\def\pgfsys@stroke@opacity#1{\pgf@sys@fail{opacity}}
% Sets the opacity of stroking operations. 1 means fully opaque, 0
% means fully transparent.

\def\pgfsys@fill@opacity#1{\pgf@sys@fail{opacity}}
% Sets the opacity of filling operations. 1 means fully opaque, 0
% means fully transparent.

\def\pgfsys@transparencygroupfrombox#1{\pgf@sys@fail{transparency groups}}
% This takes a TeX box and converts it into a transparency
% group. This means that any transparency settings apply to the box as
% a whole. For instance, if a box contains two overlapping black
% circles and you draw them normally with 50% transparency, then the
% overlap will be darker than the rest. By comparison, if the circles
% are part of a transparency group, the overlap will get the same
% color as the rest.

\def\pgfsys@definemask{\pgf@sys@fail{image masks}}
% This command declares a mask for usage with images. It works similar
% to \pgfsys@defineimage: Certain macros are set when the command is
% called. The result should be to set the macro \pgf@mask to a pdf
% object count that can subsequently be used as a soft mask. The
% following macros will be set when this command is invoked:
%
% - \pgf@filename
%   File name of the mask to be defined.
%
% - \pgf@maskmatte
%   The so-called matte of the mask (see the pdf documentation for
%   details). The matte is a color specification consisting of 1, 3 or
%   4 numbers between 0 and 1. The number of numbers depends on the
%   number of color channels in the image (not in the mask!). It will
%   be assumed that the image has been preblended with this color.

\def\pgfsys@fadingfrombox#1#2{\pgf@sys@fail{fadings}}
% Declares an fading named #1. The parameter #2 must be a
% box. Its contents luminosity determines the opacity of the resulting
% mask. 

\def\pgfsys@usefading#1#2#3#4#5#6#7{\pgf@sys@fail{fadings}}
% Installs a previously declared fading #1 in the current graphics
% state. Parameters #2 to #7 specify a transformation cm that should
% be applied to the mask before it is used.



%
%
% Shading commands
%
%

\def\pgfsys@horishading#1#2#3{\pgf@sys@fail{shadings}\pgf@sys@noshading{#1}}
% Declares a horizontal shading for later use. The effect of this
% command should be the definition of a macro called `@pgfshading#1!'
% (or \csname @pdfshading#1!\endcsname, to be precise). When invoked,
% this new macro should insert a shading at the current position.
%
% #1 is the name of the shading, which is also used in the output
% macro name. #2 is the height of the shading and must be given as a
% TeX dimension like `2cm' or `10pt'. #3 is a shading color
% specification as specified in the pgfuserguide. The shading
% specification implicitly fixes the width of the shading. 
%
% When `@pgfshading#1!' is invoked, it should insert a box of height
% #2 and the width implicit in the shading declaration.

\def\pgfsys@vertshading#1#2#3{\pgf@sys@fail{shadings}\pgf@sys@noshading{#1}}
% Like horishading, only for vertical shadings. This time, the height
% of the shading is implicit in #3 and the width is given as #2.

\def\pgfsys@radialshading#1#2#3{\pgf@sys@fail{shadings}\pgf@sys@noshading{#1}}
% Declares a radial shading. Like the previous macros, this command
% should setup the macro `@pgfshading#1!', which upon invocation
% should insert a radial shading whose size is implicit in #3. 
%
% The parameter #2 is a pgf point specification if the starting point
% of the shading. See the pgfuserguide for details.

\def\pgfsys@functionalshading#1#2#3#4{\pgf@sys@fail{shadings (functional)}\pgf@sys@noshading{#1}}
% Declares a shading using a PostScript-like function that provides a
% color for each point. Like the previous macros, this command
% should setup the macro `@pgfshading#1!' so that it will produce a
% box containing the desired shading.
%
% Parameter #1 is the name of the shading. Parameter #4 is a
% Postscript-like function (type 4 function of the PDF specification)
% as described in Section 3.9.4 of the PDF Specification version 1.7.
% Parameter #2 and #3 are pgf point specifications that specifies the
% lower left and upper right coordinate.
%
% When function #4 is evaluated, the coordinate of the current
% point will be on the (virtual) PostScript stack in bp units. After
% the function has been evaluated, the stack should consist of three
% numbers (not integers! - the Apple PDF renderer is broken in this
% regard, so add cvr's at the end if needed) that represent the red,
% green, and blue components of the color.
%
% A buggy #4 will result is *totally unpredictable chaos* during
% rendering. 

\def\pgf@sys@noshading#1{\expandafter\global\expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@empty}




%
%
% Pattern stuff
%
%

\def\pgfsys@declarepattern#1#2#3#4#5#6#7#8#9{\pgf@sys@fail{patterns}}
% This command declares a new colored or uncolored pattern. Uncolored
% patterns have no inherent color, the color is provided when they are
% set. Colored patters have an inherent color.
% #1       = name of the pattern (must be a plain suffix for use in
%            postscript/pdf/etc.) 
% #2 to #5 = four coordinates describing the corners of a bounding box
%            of pattern cells
% #6       = x-step
% #7       = y-step
% #8       = pattern code
% #9       = 0 if uncolored patter, 1 if colored pattern.

\def\pgfsys@setpatternuncolored#1#2#3#4{\pgf@sys@fail{patterns}}
% Sets an uncolored pattern #1 as filling color. The numbers #2, #3,
% #4 must be an rgb-value to be used as the color of the pattern.

\def\pgfsys@setpatterncolored#1{\pgf@sys@fail{patterns}}
% Sets an colored pattern #1 as filling color.


%
%
% Page size stuff
%
%
\def\pgfsys@papersize#1#2{\pgf@sys@fail{papersize}}
% This command sets the paper size in a portable way.
% #1 = width
% #2 = height



%
%
% Position tracking commands
%
%

% Marks the current position on the page. This position can later be
% referenced using \pgfsys@getposition
\def\pgfsys@markposition#1{\pgf@sys@fail{marking the current position}}

% Sets #2 to a pgfpoint macro that returns the position #1 is
% returned in a coordinate system where the x-axis goes right and the
% y-axis goes up. The origin of this coordinate system may or may not
% lie in the lower left corner; you should shift the coordinate system
% to the position "pgfpageorigin" to make sure that the origin is at
% the lower left corner. Typically, getting this position
% requires two runs of TeX. On the first run, the macro will be set to
% \relax, indicating that the position is not available. 
%
% If #1 is set to the special position "pgfpageorigin", the position
% of the the lower left page corner is returned. 

\def\pgfsys@getposition#1#2{\let#2=\relax}



%
%
% Commands having a default implementation. These commands only need
% not be implemented by drivers if this results in a better
% preformance. 
%
%


\def\pgfsys@shadingoutsidepgfpicture#1{%
  #1%
}
% This command gets the definition of a shading (@pgfshadingxxxx!) as
% an argument and should insert this shading into the normal text.
%
% This command has a default implementation.


\def\pgfsys@shadinginsidepgfpicture#1{%
  \pgf@makehbox{#1}%
  \setbox\pgf@hbox=\hbox{\hskip-.5\wd\pgf@hbox\lower.5\ht\pgf@hbox\hbox{\box\pgf@hbox}}%
  \pgfqbox{\pgf@hbox}%
}
% This command works like \pgfsys@shadingoutsidepgfpicture, only it is
% called when a shading should be inserted inside a picture. This
% command should insert the shading centered on the origin (which will
% typically have been low-level translated somewhere else.)
%
% This command has a default implementation.





\def\pgfsys@closestroke{\pgfsys@closepath\pgfsys@stroke}
% This command should have the same effect as first closing the path
% and then stroking it.


\def\pgfsys@transformshift#1#2{\pgfsys@transformcm{1}{0}{0}{1}{#1}{#2}}
% This command will change the origin of the low-level coordinate
% system to (#1bp,#2bp).

\def\pgfsys@transformxyscale#1#2{\pgfsys@transformcm{#1}{0}{0}{#2}{0bp}{0bp}}
% This command will scale the low-level coordinate system (and
% everything that is drawn) by a factor of #1 in x-directed and #2 in
% y-direction. Note that this applies to everything, including
% lines. So a scaled line will have a different width and may even
% have a different width when going along the x-axis and when going
% along the y-axis, if the scaling is different in these directions.

\def\pgfsys@hbox#1{%
  \pgfsys@beginscope%
    \setbox#1=\hbox{\box#1}%
    \wd#1=0pt%
    \ht#1=0pt%
    \dp#1=0pt%
    \box#1%
  \pgfsys@endscope%
}
% Called to insert a TeX hbox into a pgfpicture. 

\def\pgfsys@hboxsynced#1{%
  {\pgfsys@beginscope\pgflowlevelsynccm\pgfsys@hbox#1\pgfsys@endscope}%
}
% Called to insert a TeX hbox into a pgfpicture, but with the current
% coordinate transformation matrix synced with the canvas
% transformation matrix. 
%
% In essence, this command does the same as if you first said
% \pgflowlevelsynccm and then \pgfsys@hbox. However, a driver may
% choose to use a ``TeX-translation'' for the translation part of the
% transformation cm. This will ensure that hyperlinks ``survive'' at
% least translations. 

\def\pgfsys@beginpicture{}
% Called at the beginning of a pgfpicture. Used to setup things.

\def\pgfsys@endpicture{}
% Called at the end of a pgfpicture. 

\def\pgfsys@typesetpicturebox#1{%
  \pgf@ya=\pgf@shift@baseline\relax%
  \advance\pgf@ya by-\pgf@picminy\relax%
  %
  %
  \advance\pgf@picmaxy by-\pgf@picminy\relax% maxy is now the height
  \advance\pgf@picmaxx by-\pgf@picminx\relax% maxx is now the width
  \setbox#1=\hbox{\hskip-\pgf@picminx\lower\pgf@picminy\box#1}%
  \ht#1=\pgf@picmaxy%
  \wd#1=\pgf@picmaxx%
  \dp#1=0pt%
  \leavevmode%
  \pgf@xa=\pgf@trimleft@final\relax  \ifdim\pgf@xa=0pt \else\kern\pgf@xa\fi
  \raise-\pgf@ya\box#1%
  \pgf@xa=\pgf@trimright@final\relax \ifdim\pgf@xa=0pt \else\kern\pgf@xa\fi
}
% Called after a picture has been typeset in box #1. This
% command should insert the box into the normal TeX code. The box #1
% will still be a ``raw'' box that contains only the \special's. The
% job of this command is to resize and shift this box according to the
% baseline shift and the size of the box.
%
% This command has a default implementation.

\def\pgfsys@beginpurepicture{\pgfsys@beginpicture}
% This version of the beginpicture command can be used for pictures
% that are guaranteed not to contain any hboxes. In this case, a
% driver might provide a more compact version of the command.

\def\pgfsys@endpurepicture{\pgfsys@endpicture}
% Called at the end of a ``pure'' pgfpicture.

\def\pgfsys@defineimage{%
  \ifx\pgf@imagewidth\pgfutil@empty\else\edef\pgf@imagewidth{width=\pgf@imagewidth,}\fi%
  \ifx\pgf@imageheight\pgfutil@empty\else\edef\pgf@imageheight{height=\pgf@imageheight,}\fi%
  \ifx\pgf@imagepage\pgfutil@empty\else\edef\pgf@imagepage{page=\pgf@imagepage,}\fi%
  \edef\pgf@image{\noexpand\includegraphics[\pgf@imageheight\pgf@imagewidth]{\pgf@filename}}%
}
% Called, when an image should be defined. 
%
% This command does not take any parameters. Instead, certain macros
% will be preinstalled with appropriate values when this command is
% invoked. These are:
%
% - \pgf@filename
%   File name of the image to be defined.
%
% - \pgf@imagewidth
%   Will be set to the desired (scaled) width of the image.
%
% - \pgf@imageheight
%   Will be set to the desired (scaled) height of the image.
%
%   If this macro and also the height macro are empty, the image
%   should have its `natural' size.
%
%   If exactly only of them is specified, the undefined value the
%   image is scaled so that the aspect ratio is kept.
%
%   If both are set, the image is scaled in both directions
%   independently, possibly changing the aspect ratio.
%
%
% The following macros presumable mostly make sense for drivers that
% can handle pdf: 
%
% - \pgf@imagepage
%   The desired page number to be extracted from a multi-page
%   `image'. 
%
% - \pgf@imagemask
%   If set, it will be set to `/SMask x 0 R', where x is the pdf
%   object number of a soft mask to be applied to the image.
%
% - \pgf@imageinterpolate
%   If set, it will be set to `/Interpolate true' or  `/Interpolate
%   false', indicating whether the image should be interpolated in
%   pdf. 
%
%
% The command should now setup the macro \pgf@image such that calling
% this macro will result in typesetting the image. Thus, \pgf@image is
% the `return value' of the command.


\def\pgfsys@defobject#1#2#3#4{%
  \pgfsysprotocol@getcurrentprotocol\pgfsys@temp%
  {%
    \pgfsysprotocol@setcurrentprotocol\pgfutil@empty%
    \pgfsysprotocol@bufferedtrue%
    #4%
    \pgfsysprotocol@getcurrentprotocol\pgfsys@@temp%
    \expandafter\global\expandafter\let\csname #1\endcsname=\pgfsys@@temp%
  }%
  \pgfsysprotocol@setcurrentprotocol\pgfsys@temp%
}
% Declares an object for later use. The idea is that the object can be
% precached in some way and then be rendered more quickly when used
% several times. For example, an arrow head might be defined and
% prerendered in this way.
%
% The parameter #1 is the name for later use. #2 and #3 are pgf points
% specifying a bounding box for the object. #4 is the code for the
% object. The code may only contain protocollable code.


\def\pgfsys@useobject#1#2{%
  \pgfsysprotocol@getcurrentprotocol\pgfsys@temp%
  {%
    \pgfsysprotocol@setcurrentprotocol\pgfutil@empty%
    \pgfsysprotocol@bufferedfalse%
    #2%
    \expandafter\pgfsysprotocol@setcurrentprotocol\csname #1\endcsname%
    \pgfsysprotocol@invokecurrentprotocol%
  }%
  \pgfsysprotocol@setcurrentprotocol\pgfsys@temp%
}
% Renders a previously declared object. The first parameter is the
% name of the the object. The second parameter is extra code that
% should be executed right *before* the object is rendered. Typically,
% this will be some transformation code. 


\def\pgfsys@begininvisible{\pgfsys@transformcm{1}{0}{0}{1}{2000bp}{2000bp}}
% Between this command and the closing endinvisible, all output should
% be suppressed. Nothing should be drawn at all, which includes all
% paths, images and shadings.

\def\pgfsys@endinvisible{\pgfsys@transformcm{1}{0}{0}{1}{-2000bp}{-2000bp}}
% Ends the invisibilty section, unless invisibility blocks have been
% nested. In this case, only the `last' one restores visibility.


\def\pgfsys@atbegindocument{}
% This command will be executed at the begin of the document. If for
% whatever reason this is not done, you may wish to execute this
% command yourself. It will setup certain specials that need to be
% inserted into the resulting .pdf/.ps/.xxx file.





% Discern the driver:

% Default driver:
\ifx\pgfsysdriver\@undefined
  \pgfutil@guessdriver
\fi

\input pgf.cfg

\PackageInfo{pgfsys}{Driver file for pgf: \pgfsysdriver}
\pgfutil@InputIfFileExists{\pgfsysdriver}{}{%
  \PackageError{pgfsys}{Driver file ``\pgfsysdriver'' not found.}{}}



% This will insert always-present-specials at the beginning of the
% code. 
\AtBeginDocument{
  \pgfsys@atbegindocument
  \let\pgfsys@atbegindocument=\pgfutil@empty
}



% Read aux file in plain and context mode:

\pgfutil@aux@read@hook


\endinput

arxiv.bbl
% Generated by IEEEtran.bst, version: 1.13 (2008/09/30)
\begin{thebibliography}{10}
\providecommand{\url}[1]{#1}
\csname url@samestyle\endcsname
\providecommand{\newblock}{\relax}
\providecommand{\bibinfo}[2]{#2}
\providecommand{\BIBentrySTDinterwordspacing}{\spaceskip=0pt\relax}
\providecommand{\BIBentryALTinterwordstretchfactor}{4}
\providecommand{\BIBentryALTinterwordspacing}{\spaceskip=\fontdimen2\font plus
\BIBentryALTinterwordstretchfactor\fontdimen3\font minus
  \fontdimen4\font\relax}
\providecommand{\BIBforeignlanguage}[2]{{%
\expandafter\ifx\csname l@#1\endcsname\relax
\typeout{** WARNING: IEEEtran.bst: No hyphenation pattern has been}%
\typeout{** loaded for the language `#1'. Using the pattern for}%
\typeout{** the default language instead.}%
\else
\language=\csname l@#1\endcsname
\fi
#2}}
\providecommand{\BIBdecl}{\relax}
\BIBdecl

\bibitem{Backman2012}
N.~Backman, K.~Pattabiraman, R.~Fonseca, and U.~Cetintemel, ``C-mr:
  Continuously executing mapreduce workflows on multi-core processors,'' in
  \emph{Proceedings of third international workshop on MapReduce and its
  Applications Date}.\hskip 1em plus 0.5em minus 0.4em\relax ACM, 2012, pp.
  1--8.

\bibitem{Zeng2013}
J.~Zeng and B.~Plale, ``Data pipeline in mapreduce,'' in \emph{eScience
  (eScience), 2013 IEEE 9th International Conference on}.\hskip 1em plus 0.5em
  minus 0.4em\relax IEEE, 2013, pp. 164--171.

\bibitem{Kienzler2012}
R.~Kienzler, R.~Bruggmann, A.~Ranganathan, and N.~Tatbul, ``Stream as you go:
  The case for incremental data access and processing in the cloud,'' in
  \emph{Data Engineering Workshops (ICDEW), 2012 IEEE 28th International
  Conference on}.\hskip 1em plus 0.5em minus 0.4em\relax IEEE, 2012, pp.
  159--166.

\bibitem{Jackson2010}
K.~R. Jackson, L.~Ramakrishnan, K.~Muriki, S.~Canon, S.~Cholia, J.~Shalf, H.~J.
  Wasserman, and N.~J. Wright, ``Performance analysis of high performance
  computing applications on the amazon web services cloud,'' in
  \emph{CloudCom}, 2010, pp. 159--168.

\bibitem{Hearn2001}
D.~Hearn, C.~Digenis, D.~Lencioni, J.~Mendenhall, J.~B. Evans, and R.~D. Welsh,
  ``Eo-1 advanced land imager overview and spatial performance,'' in
  \emph{Geoscience and Remote Sensing Symposium, 2001. IGARSS '01. IEEE 2001
  International}, vol.~2, 2001, pp. 897--900 vol.2.

\bibitem{Pearlman2001}
J.~Pearlman, S.~Carman, C.~Segal, P.~Jarecke, P.~Clancy, and W.~Browne,
  ``Overview of the hyperion imaging spectrometer for the nasa eo-1 mission,''
  in \emph{Geoscience and Remote Sensing Symposium, 2001. IGARSS '01. IEEE 2001
  International}, vol.~7, 2001, pp. 3036--3038 vol.7.

\bibitem{Grossman2012}
R.~L. Grossman, M.~Greenway, A.~P. Heath, R.~Powell, R.~D. Suarez, W.~Wells,
  K.~P. White, M.~P. Atkinson, I.~A. Klampanos, H.~L. Alvarez, C.~Harvey, and
  J.~Mambretti, ``The design of a community science cloud: The open science
  data cloud perspective,'' in \emph{SC Companion}, 2012, pp. 1051--1057.

\bibitem{White2012}
T.~White, \emph{Hadoop - The Definitive Guide: Storage and Analysis at Internet
  Scale (3. ed., revised and updated)}.\hskip 1em plus 0.5em minus 0.4em\relax
  O'Reilly, 2012.

\bibitem{MapReduce}
J.~Dean and S.~Ghemawat, ``Mapreduce: Simplified data processing on large
  clusters,'' in \emph{OSDI}, 2004, pp. 137--150.

\bibitem{Accumulo}
\url{https://accumulo.apache.org/}.

\bibitem{Griffin2005}
M.~K. Griffin, S.~M. Hsu, H.-H. Burke, S.~M. Orloff, and C.~A. Upham,
  ``Examples of eo-1 hyperion data analysis,'' \emph{Lincoln Laboratory
  Journal}, vol.~15, no.~2, pp. 271--298, 2005.

\bibitem{Ip2006}
\BIBentryALTinterwordspacing
F.~Ip, J.~Dohm, V.~Baker, T.~Doggett, A.~Davies, R.~CastaÃ±o, S.~Chien,
  B.~Cichy, R.~Greeley, R.~Sherwood, D.~Tran, and G.~Rabideau, ``Flood
  detection and monitoring with the autonomous sciencecraft experiment onboard
  eo-1,'' \emph{Remote Sensing of Environment}, vol. 101, no.~4, pp. 463 --
  481, 2006. [Online]. Available:
  \url{http://www.sciencedirect.com/science/article/pii/S0034425706000228}
\BIBentrySTDinterwordspacing

\bibitem{Burke2004}
H.~hua K.~Burke, S.~Hsu, M.~K. Griffin, C.~A. Upham, and K.~Farrar, ``Eo-1
  hyperion data analysis applicable to cloud detection, coastal
  characterization and terrain classification,'' in \emph{IGARSS}, 2004, pp.
  1483--1486.

\bibitem{scikit-learn}
F.~Pedregosa, G.~Varoquaux, A.~Gramfort, V.~Michel, B.~Thirion, O.~Grisel,
  M.~Blondel, P.~Prettenhofer, R.~Weiss, V.~Dubourg, J.~Vanderplas, A.~Passos,
  D.~Cournapeau, M.~Brucher, M.~Perrot, and E.~Duchesnay, ``Scikit-learn:
  Machine learning in {P}ython,'' \emph{Journal of Machine Learning Research},
  vol.~12, pp. 2825--2830, 2011.

\bibitem{EarthExplorer}
\url{http://earthexplorer.usgs.gov/}.

\bibitem{GPM}
\url{http://www.nasa.gov/mission_pages/GPM/main/index.html}.

\bibitem{Neeck2013}
S.~P. {Neeck}, R.~K. {Kakar}, A.~A. {Azarbarzin}, and A.~Y. {Hou}, ``{Global
  Precipitation Measurement (GPM) L-6},'' in \emph{Society of Photo-Optical
  Instrumentation Engineers (SPIE) Conference Series}, ser. Society of
  Photo-Optical Instrumentation Engineers (SPIE) Conference Series, vol. 8889,
  Oct. 2013.

\end{thebibliography}

bibio.bbl
% Generated by IEEEtran.bst, version: 1.13 (2008/09/30)
\begin{thebibliography}{10}
\providecommand{\url}[1]{#1}
\csname url@samestyle\endcsname
\providecommand{\newblock}{\relax}
\providecommand{\bibinfo}[2]{#2}
\providecommand{\BIBentrySTDinterwordspacing}{\spaceskip=0pt\relax}
\providecommand{\BIBentryALTinterwordstretchfactor}{4}
\providecommand{\BIBentryALTinterwordspacing}{\spaceskip=\fontdimen2\font plus
\BIBentryALTinterwordstretchfactor\fontdimen3\font minus
  \fontdimen4\font\relax}
\providecommand{\BIBforeignlanguage}[2]{{%
\expandafter\ifx\csname l@#1\endcsname\relax
\typeout{** WARNING: IEEEtran.bst: No hyphenation pattern has been}%
\typeout{** loaded for the language `#1'. Using the pattern for}%
\typeout{** the default language instead.}%
\else
\language=\csname l@#1\endcsname
\fi
#2}}
\providecommand{\BIBdecl}{\relax}
\BIBdecl

\bibitem{Backman2012}
N.~Backman, K.~Pattabiraman, R.~Fonseca, and U.~Cetintemel, ``C-mr:
  Continuously executing mapreduce workflows on multi-core processors,'' in
  \emph{Proceedings of third international workshop on MapReduce and its
  Applications Date}.\hskip 1em plus 0.5em minus 0.4em\relax ACM, 2012, pp.
  1--8.

\bibitem{Zeng2013}
J.~Zeng and B.~Plale, ``Data pipeline in mapreduce,'' in \emph{eScience
  (eScience), 2013 IEEE 9th International Conference on}.\hskip 1em plus 0.5em
  minus 0.4em\relax IEEE, 2013, pp. 164--171.

\bibitem{Kienzler2012}
R.~Kienzler, R.~Bruggmann, A.~Ranganathan, and N.~Tatbul, ``Stream as you go:
  The case for incremental data access and processing in the cloud,'' in
  \emph{Data Engineering Workshops (ICDEW), 2012 IEEE 28th International
  Conference on}.\hskip 1em plus 0.5em minus 0.4em\relax IEEE, 2012, pp.
  159--166.

\bibitem{Jackson2010}
K.~R. Jackson, L.~Ramakrishnan, K.~Muriki, S.~Canon, S.~Cholia, J.~Shalf, H.~J.
  Wasserman, and N.~J. Wright, ``Performance analysis of high performance
  computing applications on the amazon web services cloud,'' in
  \emph{CloudCom}, 2010, pp. 159--168.

\bibitem{Hearn2001}
D.~Hearn, C.~Digenis, D.~Lencioni, J.~Mendenhall, J.~B. Evans, and R.~D. Welsh,
  ``Eo-1 advanced land imager overview and spatial performance,'' in
  \emph{Geoscience and Remote Sensing Symposium, 2001. IGARSS '01. IEEE 2001
  International}, vol.~2, 2001, pp. 897--900 vol.2.

\bibitem{Pearlman2001}
J.~Pearlman, S.~Carman, C.~Segal, P.~Jarecke, P.~Clancy, and W.~Browne,
  ``Overview of the hyperion imaging spectrometer for the nasa eo-1 mission,''
  in \emph{Geoscience and Remote Sensing Symposium, 2001. IGARSS '01. IEEE 2001
  International}, vol.~7, 2001, pp. 3036--3038 vol.7.

\bibitem{Grossman2012}
R.~L. Grossman, M.~Greenway, A.~P. Heath, R.~Powell, R.~D. Suarez, W.~Wells,
  K.~P. White, M.~P. Atkinson, I.~A. Klampanos, H.~L. Alvarez, C.~Harvey, and
  J.~Mambretti, ``The design of a community science cloud: The open science
  data cloud perspective,'' in \emph{SC Companion}, 2012, pp. 1051--1057.

\bibitem{White2012}
T.~White, \emph{Hadoop - The Definitive Guide: Storage and Analysis at Internet
  Scale (3. ed., revised and updated)}.\hskip 1em plus 0.5em minus 0.4em\relax
  O'Reilly, 2012.

\bibitem{MapReduce}
J.~Dean and S.~Ghemawat, ``Mapreduce: Simplified data processing on large
  clusters,'' in \emph{OSDI}, 2004, pp. 137--150.

\bibitem{Accumulo}
\url{https://accumulo.apache.org/}.

\bibitem{Griffin2005}
M.~K. Griffin, S.~M. Hsu, H.-H. Burke, S.~M. Orloff, and C.~A. Upham,
  ``Examples of eo-1 hyperion data analysis,'' \emph{Lincoln Laboratory
  Journal}, vol.~15, no.~2, pp. 271--298, 2005.

\bibitem{Ip2006}
\BIBentryALTinterwordspacing
F.~Ip, J.~Dohm, V.~Baker, T.~Doggett, A.~Davies, R.~CastaÃ±o, S.~Chien,
  B.~Cichy, R.~Greeley, R.~Sherwood, D.~Tran, and G.~Rabideau, ``Flood
  detection and monitoring with the autonomous sciencecraft experiment onboard
  eo-1,'' \emph{Remote Sensing of Environment}, vol. 101, no.~4, pp. 463 --
  481, 2006. [Online]. Available:
  \url{http://www.sciencedirect.com/science/article/pii/S0034425706000228}
\BIBentrySTDinterwordspacing

\bibitem{Burke2004}
H.~hua K.~Burke, S.~Hsu, M.~K. Griffin, C.~A. Upham, and K.~Farrar, ``Eo-1
  hyperion data analysis applicable to cloud detection, coastal
  characterization and terrain classification,'' in \emph{IGARSS}, 2004, pp.
  1483--1486.

\bibitem{scikit-learn}
F.~Pedregosa, G.~Varoquaux, A.~Gramfort, V.~Michel, B.~Thirion, O.~Grisel,
  M.~Blondel, P.~Prettenhofer, R.~Weiss, V.~Dubourg, J.~Vanderplas, A.~Passos,
  D.~Cournapeau, M.~Brucher, M.~Perrot, and E.~Duchesnay, ``Scikit-learn:
  Machine learning in {P}ython,'' \emph{Journal of Machine Learning Research},
  vol.~12, pp. 2825--2830, 2011.

\bibitem{EarthExplorer}
\url{http://earthexplorer.usgs.gov/}.

\bibitem{GPM}
\url{http://www.nasa.gov/mission_pages/GPM/main/index.html}.

\bibitem{Neeck2013}
S.~P. {Neeck}, R.~K. {Kakar}, A.~A. {Azarbarzin}, and A.~Y. {Hou}, ``{Global
  Precipitation Measurement (GPM) L-6},'' in \emph{Society of Photo-Optical
  Instrumentation Engineers (SPIE) Conference Series}, ser. Society of
  Photo-Optical Instrumentation Engineers (SPIE) Conference Series, vol. 8889,
  Oct. 2013.

\end{thebibliography}
