<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>boyfarrell.com</title>
	<atom:link href="http://www.boyfarrell.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.boyfarrell.com</link>
	<description>I'd better think of something smart to put up here...</description>
	<pubDate>Tue, 10 Jun 2008 07:22:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>NSOperation meets the graphics card?</title>
		<link>http://www.boyfarrell.com/learning-curve/nsoperation-meets-the-graphics-card</link>
		<comments>http://www.boyfarrell.com/learning-curve/nsoperation-meets-the-graphics-card#comments</comments>
		<pubDate>Tue, 10 Jun 2008 07:22:38 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/nsoperation-meets-the-graphics-card</guid>
		<description><![CDATA[Details released from the WWDC yesterday mention  OpenCL (Open Compute Library) as a technology in Leopard:
Another powerful Snow Leopard technology, OpenCL (Open Compute Library), makes it possible for developers to efficiently tap the vast gigaflops of computing power currently locked up in the graphics processing unit (GPU). With GPUs approaching processing speeds of a [...]]]></description>
			<content:encoded><![CDATA[<p>Details released from the WWDC yesterday mention <a href="http://www.apple.com/macosx/snowleopard/"> OpenCL (Open Compute Library)</a> as a technology in Leopard:</p>
<p><quote><i>Another powerful Snow Leopard technology, OpenCL (Open Compute Library), makes it possible for developers to efficiently tap the vast gigaflops of computing power currently locked up in the graphics processing unit (GPU). With GPUs approaching processing speeds of a trillion operations per second, they’re capable of considerably more than just drawing pictures. OpenCL takes that power and redirects it for general-purpose computing.</i></quote></p>
<p>As a matter of interest the <a hef="http://opencl.sourceforge.net/">Open Source Cryptographic Library</a> &#8212; previous holder of the OpenCL name &#8212; has recently changed to <a hef="http://botan.randombit.net/">Botan</a>. Is this possibly at the request of Apple?</p>
<p>Also, an interesting link from <a href="http://www.macresearch.org/cuda-every-mac">MacResearch.org</a> references <a href="a quote from the http://news.cnet.com/8301-13579_3-9962117-37.html?part=rss&#038;subj=news&#038;tag=2547-1040_3-0-5">Nvidia CEO, Jen-Hsun Huang</a> stating <quote>Apple knows alot about CUDA</quote> are we going to see Apple writing a higher level API on top of CUDA? NSOperation meets the graphics card.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/nsoperation-meets-the-graphics-card/feed</wfw:commentRss>
		</item>
		<item>
		<title>GNU Scientific Library and XCode 3.1</title>
		<link>http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31</link>
		<comments>http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31#comments</comments>
		<pubDate>Fri, 04 Apr 2008 15:30:22 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Learning Curve]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/uncategorised/gnu-scientific-library-and-xcode-31</guid>
		<description><![CDATA[Assuming you have a working installation of GNU Scientific Library either from source, Fink or MacPorts, this tutorial will show you how to getting a working XCode project. I am currently using XCode 3.1 but this process hasn&#8217;t changed much over the last few years, so will work on older systems.
Download a GSL Example project [...]]]></description>
			<content:encoded><![CDATA[<p>Assuming you have a working installation of GNU Scientific Library either from source, Fink or MacPorts, this tutorial will show you how to getting a working XCode project. I am currently using XCode 3.1 but this process hasn&#8217;t changed much over the last few years, so will work on older systems.</p>
<p>Download a GSL Example project ready for your own code:<br />
<a href="http://www.boyfarrell.com/files/GSL-Project-Xcode-3.0.zip"> XCode 3.0+ GSL Example Project</a><br />
<a href="http://www.boyfarrell.com/files/GSL-Project-Xcode-2.4.zip"> XCode 2.4+ GSL Example Project</a></p>
<ol>
<li>
Create a new project, I called mine, &#8216;GSL Project&#8217;.<br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-1.png" title="Create project"><img id="image86" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-1.thumbnail.png" alt="Create project" /></a></p>
</li>
<li> Choose a default template, New Cocoa application will do nicely.<br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-2.png" title="Template"><img id="image87" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-2.thumbnail.png" alt="Template" /></a></p>
</li>
<li>
Select get info on the project icon. As we need to tell xcode where GSL is.<br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-4.png" title="Get info"><img id="image88" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-4.thumbnail.png" alt="Get info" /></a></p>
</li>
<li> Select the native option in the architectures list. Xcode can build dual binaries (DB), however, GSL is only compiled for the native machine, so it it tried to make a DB is will FAIL!<br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-5.png" title="native"><img id="image89" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-5.thumbnail.png" alt="native" /></a></p>
</li>
<li> Type header search paths into the search box. Editing the &#8216;Header Search Paths&#8217; field, add the following paths.
<p><a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-6.png" title="hsp"><img id="image90" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-6.thumbnail.png" alt="hsp" /></a><br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-7.png" title="hsp fields"><img id="image91" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-7.thumbnail.png" alt="hsp fields" /></a></p>
</li>
<li> Next we will do the same process as but for the &#8216;Library search paths&#8217;,
<p><a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-8.png" title="lsp"><img id="image92" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-8.thumbnail.png" alt="lsp" /></a><a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-9.png" title="lsp fields"><img id="image93" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-9.thumbnail.png" alt="lsp fields" /></a></p>
</li>
<li> Now search for &#8216;other linker flags&#8217; and set the following values,<br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-11.png" title="olf"><img id="image94" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-11.thumbnail.png" alt="olf" /></a><br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-12.png" title="olf field"><img id="image95" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-12.thumbnail.png" alt="olf field" /></a></p>
</li>
<li> We are done, but let&#8217;s do a test program. Select the main.m file in the File &#038; Groups list. You may need to press the &#8216;Editor&#8217; button in the button menu to see the contents of the file,<br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-13.png" title="main.m cocoa"><img id="image96" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-13.thumbnail.png" alt="main.m cocoa" /></a> </p>
</li>
<li>
Select all and replace with some <a href="http://www.network-theory.co.uk/docs/gslref/Exampleprogramsforvectors.html">GSL test code</a>, build and run.<br />
<a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-15.png" title="main.m gsl"><img id="image97" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/04/picture-15.thumbnail.png" alt="main.m gsl" /></a></p>
</li>
</ol>
<p>Make sure that you have the DEBUG build settings active. Have your project in RELEASE mode  won&#8217;t work (thanks for point that out Paul).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31/feed</wfw:commentRss>
		</item>
		<item>
		<title>Gnuplot Blue-Green-Red PM3D Colourmap</title>
		<link>http://www.boyfarrell.com/learning-curve/gnuplot-blue-green-red-pm3d-colourmap</link>
		<comments>http://www.boyfarrell.com/learning-curve/gnuplot-blue-green-red-pm3d-colourmap#comments</comments>
		<pubDate>Sun, 17 Feb 2008 23:49:33 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/gnuplot-blue-green-red-pm3d-colourmap</guid>
		<description><![CDATA[
set palette model RGB
set palette rgbformulae 30,-13,-23

This code will produce a MATLAB like colormap with the default &#8216;jet&#8217; setting.

]]></description>
			<content:encoded><![CDATA[<p><code><br />
set palette model RGB<br />
set palette rgbformulae 30,-13,-23<br />
</code><br />
This code will produce a MATLAB like colormap with the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/colormap.html&#038;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/colormap.html#f19-356665">default &#8216;jet&#8217; </a>setting.</p>
<p><a class="imagelink" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/02/jet-colourmap.png" title="gnuplot with pm3d jet settings (30, -13, -23)"><img id="image83" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/02/jet-colourmap.png" alt="gnuplot with pm3d jet settings (30, -13, -23)" width="500"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/gnuplot-blue-green-red-pm3d-colourmap/feed</wfw:commentRss>
		</item>
		<item>
		<title>ChocPlot: First Results</title>
		<link>http://www.boyfarrell.com/learning-curve/chocplot-first-results</link>
		<comments>http://www.boyfarrell.com/learning-curve/chocplot-first-results#comments</comments>
		<pubDate>Mon, 14 Jan 2008 22:01:39 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/code/chocplot-first-results</guid>
		<description><![CDATA[
It has been quite slow going with the plotting framework as of late; the trouble with being in the fourth year of a three year PhD! I have decided to rely on Cocoa for as much as possible for the plot above (under the advice of Wil Shipley). I am using NSBezierPath to draw the [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image79" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/01/cocoa-plot-view.jpg" alt="Cocoa Plot View" /></p>
<p>It has been quite slow going with the plotting framework as of late; the trouble with being in the fourth year of a three year PhD! I have decided to rely on Cocoa for as much as possible for the plot above (<a href="http://www.wilshipley.com/blog/2007/05/pimp-my-code-part-14-be-inflexible.html">under the advice of Wil Shipley</a>). I am using NSBezierPath to draw the red dashed line and the filled the circles. NSAffineTransform is used to convert data points from data to screen/view coordinates.</p>
<h2>A lot for free</h2>
<p>Using NSAffineTransform makes it very easy to position and also alter the points (which themselves are drawn with NSBezierPath) in the view, e.g. rotation of the data points by 23 degrees in the example below. One just needs to specify a &#8216;data&#8217; coordinate rectangle which is made from the min, max and range of the experimental data set in x and y. A NSAffineTransform is made such that the &#8216;data&#8217; rectangle is first translated and then scaled to fit into the view bounds. Hmmm I lke &#8216;tiny code&#8217; &#8230;</p>
<p><img id="image81" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/01/cocoa-plot-view-crosses.jpg" alt="Cocoa Plot View with crosses" /></p>
<p>Drawing lines is made very easy, using NSBezierPath&#8217;s <code>setLineDash:count:phase:</code> method. Also, drawing oval/circles comes for free with <code>bezierPathWithOvalInRect:</code> method. So the only really work I have actually done is added <code>bezierPathWithCrossInRect:</code> extension to aid drawing of crosses (shown above)!</p>
<h2>Next step&#8230;</h2>
<p>Next I will add a points-lines plotting style. This will be similar to drawing a dashed lines but will have ovals or crosses, and regular points along it&#8217;s length. A nice touch would be to have the rotation of the points follow the gradient of the line; think of the way loops in chain would rotate as of a chain changes direction. </p>
<p>Also, we will implement the code from the <a href="http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model">first few chocplot plots</a> and have nicley spaced axis labels on the plot.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/chocplot-first-results/feed</wfw:commentRss>
		</item>
		<item>
		<title>Garbage collected buffers</title>
		<link>http://www.boyfarrell.com/micro-post/cocoas-version-of-malloc</link>
		<comments>http://www.boyfarrell.com/micro-post/cocoas-version-of-malloc#comments</comments>
		<pubDate>Wed, 07 Nov 2007 18:17:16 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Micro Post]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/micro-post/cocoas-version-of-malloc</guid>
		<description><![CDATA[Since the original post I realised there is a problem with the approach (thanks to Rick Hog). The garbage collector only collects objects! As such you must not dereference the pointer to the NSMutableData, you must assign it, and, on another line, make the method call to mutableBytes.
Now that Cocoa as garbage collection there if [...]]]></description>
			<content:encoded><![CDATA[<div class="notice">Since the original post I realised there is a problem with the approach (thanks to <a href="http://lists.apple.com/archives/cocoa-dev/2007/Nov/msg00755.html">Rick Hog</a>). The garbage collector only collects objects! As such you must not dereference the pointer to the NSMutableData, you must assign it, and, on another line, make the method call to mutableBytes.</div>
<p>Now that Cocoa as garbage collection there if a real advantage to using it to allocate buffer. Where before I would have just made a quick malloc statement to get some dynamic memory:<br />
<code>// buffer/dynamic array that holds with 10 doubles<br />
double *x;<br />
x = (double*) malloc(sizeof(double) * 10);<br />
//... sometime later ...<br />
free(x);</code></p>
<p>Now I find myself doing,<br />
<del>double *x = [[NSMutableData dataWithCapacity:sizeof(double) * 10] mutableBytes];</del><br />
NSMutableData *buffer = [NSMutableData dataWithCapacity:sizeof(double) * 10];<br />
double *x = [buffer mutableBytes];</p>
<p>Garbage collected buffers; for the lazy at heart.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/micro-post/cocoas-version-of-malloc/feed</wfw:commentRss>
		</item>
		<item>
		<title>syntax error before &#8216;AT_NAME&#8217; token</title>
		<link>http://www.boyfarrell.com/code/syntax-error-before-at_name-token</link>
		<comments>http://www.boyfarrell.com/code/syntax-error-before-at_name-token#comments</comments>
		<pubDate>Mon, 29 Oct 2007 11:10:27 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Micro Post]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/code/syntax-error-before-at_name-token</guid>
		<description><![CDATA[This means you have some junk in one of your header file that should be there.
Tip of the hat to Infurious Blog for pointing out one possible meaning of this error; a missing @end in  an Objective-C class header file.
Another possibility for this (this took me an hour to find!) is that you have [...]]]></description>
			<content:encoded><![CDATA[<p>This means you have some junk in one of your header file that should be there.</p>
<p>Tip of the hat to <a href="http://blog.infurious.com/2007/10/22/syntax-error-before-‘at_name’-token/">Infurious Blog</a> for pointing out one possible meaning of this error; a missing @end in  an Objective-C class header file.</p>
<p>Another possibility for this (<bold>this took me an hour to find!</bold>) is that you have a curly bracket somewhere in you header file. For example, from cut and pasting your method definition from the implementation file into your header file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/code/syntax-error-before-at_name-token/feed</wfw:commentRss>
		</item>
		<item>
		<title>gracebat: quickly print a graph from Terminal</title>
		<link>http://www.boyfarrell.com/micro-post/gracebat-quickly-print-a-graph-from-terminal</link>
		<comments>http://www.boyfarrell.com/micro-post/gracebat-quickly-print-a-graph-from-terminal#comments</comments>
		<pubDate>Fri, 19 Oct 2007 15:10:00 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Micro Post]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/micro-post/gracebat-quickly-print-a-graph-from-terminal</guid>
		<description><![CDATA[Later for that meeting with your supervisor, bashing the computer to hurry up and finished number crunching&#8230; the last thing you want to do it open Excel for Mac and make a crap looking graph of your results&#8230; enter gracebat&#8230;
Print a graph from an X Y1 Y2 formatted data file straight from the command line [...]]]></description>
			<content:encoded><![CDATA[<p>Later for that meeting with your supervisor, bashing the computer to hurry up and finished number crunching&#8230; the last thing you want to do it open Excel for Mac and make a crap looking graph of your results&#8230; enter gracebat&#8230;</p>
<p>Print a graph from an X Y1 Y2 formatted data file straight from the command line using:</p>
<p><quote><code>gracebat -nxy datafile.dat</code><quote></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/micro-post/gracebat-quickly-print-a-graph-from-terminal/feed</wfw:commentRss>
		</item>
		<item>
		<title>ChocPlot: Mutable Axis Model</title>
		<link>http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model</link>
		<comments>http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model#comments</comments>
		<pubDate>Tue, 04 Sep 2007 21:33:17 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model</guid>
		<description><![CDATA[The original AxisModel was quite limited in it&#8217;s abilities; it just did everything automatically. Here I introduce the mutable subclass of AxisModel; MutableAxisModel
As this is a subclass it still responds to the same methods defined in AxisModel; -interval, -spacing, -start, -stop, -representation, -description
MutableAxisModel adds additional methods designed to give the user some control over the [...]]]></description>
			<content:encoded><![CDATA[<p>The original <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a> was quite limited in it&#8217;s abilities; it just did everything automatically. Here I introduce the mutable subclass of <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a>; <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_mutable_axis_model.html">MutableAxisModel</a></p>
<p>As this is a subclass it still responds to the same methods defined in <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a>; <code>-interval, -spacing, -start, -stop, -representation, -description</code></p>
<p><a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_mutable_axis_model.html">MutableAxisModel</a> adds additional methods designed to give the user some control over the axis properties. These new methods are: <code>-setStart:, -setStop:, -moreIntervals, -fewerIntervals</code></p>
<p>As one might expect these allow the start and stop to be set exactly; these values will not be rounded like the -initWithStart:stop: values are with <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a>. The interval positions are still placed at nice rounded intervals but <b>inside</b> these end-points. Using the last two methods in the list allows the number of axis interval (tic marks) can be increased or decreased. </p>
<p>The actual number of intervals afterwards is determined by <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_mutable_axis_model.html">MutableAxisModel</a>, if it thinks that you have too many (such that adding more would just looked cluttered), it won&#8217;t add anymore! The same is true for the opposite case; having to fewer intervals.</p>
<p>There are a few more model classes left before moving on to the Graphical objects. The next post will be about <b>LinkedAxisModel</b>; a subclass of mutable axis model that uses a transform to display the same data but it different units.</p>
<p><a href="http://www.boyfarrell.com/code/chocplot/src/AxisModel-1.1.tar.gz">Source Code with Documentation (104kB)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model/feed</wfw:commentRss>
		</item>
		<item>
		<title>Overview of axis rounding</title>
		<link>http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding</link>
		<comments>http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding#comments</comments>
		<pubDate>Mon, 03 Sep 2007 20:00:41 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding</guid>
		<description><![CDATA[(A pdf version of this discussion with equations, and  source code with documentation are available. Alternatively, just the documentation is available on-line.)
Update There were some problems with the original code, but they are all solved now. There were just silly bugs: one variable was a unsigned and should have been an int etc.
I have [...]]]></description>
			<content:encoded><![CDATA[<p>(A <a id="p69" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/rounding-algorithms.pdf" title="Rounding Algorithm Discussion">pdf version of this discussion</a> with equations, and <a id="p70" href="http://www.boyfarrell.com/wordpress/download-manager.php?id=9"> source code with documentation</a> are available. Alternatively, just the <a href="http://www.boyfarrell.com/code/axis-rounding/Documentation/html/_axis_rounding_8c.html">documentation is available on-line</a>.)</p>
<p><b>Update</b> There were some problems with the original code, but they are all solved now. There were just silly bugs: one variable was a unsigned and should have been an int etc.</p>
<p>I have been quite bored recently so in a search for something to do that was potential useful I &#8216;wrote up&#8217; some of my recent experiments with rounding axis values. The main problem to solve is how to place tic marks at nice interval along the axis, if your axis doesn&#8217;t start with nice rounded numbers. The solution, I hear you say, is to round the the axis start and top values. However this can only be done once the axis spacing is known! Moreover, we cannot find out how to round the axis start and stop values with out knowledge of how we have rounded them!</p>
<h2>Axis Definitions</h2>
<p>Before we continue let&#8217;s make some definitions:</p>
<p><img id="image64" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/axis-defintions-3.jpg" alt="Axis Definitions" /></p>
<p>The range is clearly the end minus the start value, <b>NB</b> this is assumed to always be positive, so start must always be less than stop. The spacing is the separation, in axis units, between tic marks. The interval is the number of tic marks placed along the axis.</p>
<p>We can then generate equations which describe; the axis spacing as a function of the range and interval number; and the number of intervals as a function of range and spacing. This is the interdependency that I refereed to previously.</p>
<h2>Rounding</h2>
<p>The example axis above is fortunate because we started with rounded values. However, what happens if the start value was 0.2 and the stop value was 3.7? We would still want exactly the same spacing. That is, we would want 0.2 to rounded down to 0 and 3.7 to be rounded up to 4.</p>
<p>This can be achieved using ceil() and floor() functions from math.h, along with a guess value for the axis spacing.</p>
<h2>Algorithm to find spacing</h2>
<p>The number of axis intervals should be some manageable mount, a number less than 4 is too few, while more than 11 is overkill. The basis for finding the rounded axis spacing is to try a few guess spacing and see which one produce intervals in the desired range. There are also a few clues that we can use to quickly find the spacing, and when this is done it takes no more than 6 iteration to acquire the result.</p>
<h2>AxisRounding Source Code</h2>
<p>The above algorithm is used below in the function <a href="http://www.boyfarrell.com/code/axis-rounding/Documentation/html/_axis_rounding_8c.html">MakeSpacing()</a>. Here we get clues for the guess value from looking at the decade of the axis range,</p>
<p><img id="image66" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/picture-1.png" alt="MakeSpacing Function" /></p>
<p>Now we set the guess values. The trick is to scale the guess values to the same range as the axis. The axis decade has been rounded down using floor() and as such we start our search in the lower decade and then more through to the higher one. This range will cover all possible solutions that fall into our tic mark range.</p>
<p><img id="image67" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/picture-2.png" alt="MakeSpacing Functions" /></p>
<p>Finally, calculate the number of intervals for the current guess spacing. If this falls into the our desired range for the number of intervals, we return the value.</p>
<p><img id="image68" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/picture-3.png" alt="MakeSpacing Function" /></p>
<p>Please find the source code and documentation of how to use the axis spacing functions in the links above.</p>
<h3>Example Use</h3>
<p><code>double start = 400;<br />
  double stop = 800;<br />
  double spacing  = MakeSpacing(start, stop);<br />
  unsigned interval = MakeInterval(start, stop);<br />
  PrintDescription(start, stop, spacing, interval);</p>
<p>  /*<br />
  Axis Description:<br />
  start = 400<br />
  stop  = 800<br />
  spacing   = 50<br />
  interval = 9<br />
  (400, 450, 500, 550, 600, 650, 700, 750, 800)<br />
 */<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding/feed</wfw:commentRss>
		</item>
		<item>
		<title>ChocPlot 1: Axis Model</title>
		<link>http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model</link>
		<comments>http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model#comments</comments>
		<pubDate>Thu, 16 Aug 2007 17:45:33 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model</guid>
		<description><![CDATA[ChocPlot is my very poorly named framework/application for plotting using Cocoa. It is still very much a work in progress, so far I have written a class called AxisModel. It can be used to generate nicely spacing axis tic marks from just two variables; the start and stop values of the axis.
Please read the on-line [...]]]></description>
			<content:encoded><![CDATA[<p>ChocPlot is my very poorly named framework/application for plotting using Cocoa. It is still very much a work in progress, so far I have written a class called AxisModel. It can be used to generate nicely spacing axis tic marks from just two variables; the start and stop values of the axis.</p>
<p>Please read the <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/index.html">on-line documentation</a> and get the <a href="http://www.boyfarrell.com/code/chocplot/src/AxisModel.1.0.tar.gz">source </a>. Alternatively, download the whole <a href="http://www.boyfarrell.com/code/chocplot/src/ChocPlot-1.0.zip">XCode Project</a>.</p>
<h2>Example</h2>
<p><code lang="objc"><br />
/*<br />
axis with automatically positioned tic marks but with the number supplied by the user<br />
*/<br />
CPAxisModel *axis = [CPAxisModel axisWithStart:1 stop:10];<br />
NSLog([axis description]);<br />
// (0, 2, 4, 6, 8, 10)<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
