<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://thechange.wiki/index.php?action=history&amp;feed=atom&amp;title=Code%3Anumber-pairs-to-array-file.c</id>
	<title>Code:number-pairs-to-array-file.c - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://thechange.wiki/index.php?action=history&amp;feed=atom&amp;title=Code%3Anumber-pairs-to-array-file.c"/>
	<link rel="alternate" type="text/html" href="https://thechange.wiki/index.php?title=Code:number-pairs-to-array-file.c&amp;action=history"/>
	<updated>2026-08-06T19:44:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://thechange.wiki/index.php?title=Code:number-pairs-to-array-file.c&amp;diff=355&amp;oldid=prev</id>
		<title>Elie: Created page with &quot;The main use-case of this code, is to take certain SQL results and convert them to array files that can be used in the image generator.  Example of how this was used: The results of a query in Code:food1.sql were used to generate :File:yields.data-float64-895x1 which was used in generating :File:food-crop-production1.png.  ==Code== &lt;syntaxhighlight lang=&quot;c&quot;&gt; // takes pairs of numbers from stdin // reads them as &quot;index&quot; and &quot;value&quot; // put...&quot;</title>
		<link rel="alternate" type="text/html" href="https://thechange.wiki/index.php?title=Code:number-pairs-to-array-file.c&amp;diff=355&amp;oldid=prev"/>
		<updated>2022-09-01T06:53:35Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;The main use-case of this code, is to take certain SQL results and convert them to array files that can be used in the &lt;a href=&quot;/Code:isochromic.c&quot; title=&quot;Code:isochromic.c&quot;&gt;image generator&lt;/a&gt;.  Example of how this was used: The results of a query in &lt;a href=&quot;/Code:food1.sql&quot; title=&quot;Code:food1.sql&quot;&gt;Code:food1.sql&lt;/a&gt; were used to generate &lt;a href=&quot;/File:yields.data-float64-895x1&quot; title=&quot;File:yields.data-float64-895x1&quot;&gt;File:yields.data-float64-895x1&lt;/a&gt; which was used in generating &lt;a href=&quot;/File:food-crop-production1.png&quot; title=&quot;File:food-crop-production1.png&quot;&gt;File:food-crop-production1.png&lt;/a&gt;.  ==Code== &amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt; // takes pairs of numbers from stdin // reads them as &amp;quot;index&amp;quot; and &amp;quot;value&amp;quot; // put...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The main use-case of this code, is to take certain SQL results and convert them to array files that can be used in the [[Code:isochromic.c|image generator]].&lt;br /&gt;
&lt;br /&gt;
Example of how this was used: The results of a query in [[Code:food1.sql]] were used to generate [[:File:yields.data-float64-895x1]] which was used in generating [[:File:food-crop-production1.png]].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// takes pairs of numbers from stdin&lt;br /&gt;
// reads them as &amp;quot;index&amp;quot; and &amp;quot;value&amp;quot;&lt;br /&gt;
// puts them into an array&lt;br /&gt;
// saves the array to an output file&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define MAXSIZE 1048576&lt;br /&gt;
int size=0;&lt;br /&gt;
char *name=&amp;quot;out&amp;quot;;&lt;br /&gt;
double default_value=NAN;&lt;br /&gt;
double a[MAXSIZE];&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char **argv) {&lt;br /&gt;
 if (argc &amp;gt;= 2) { char *p=argv[1]; while (*p &amp;amp;&amp;amp; (*p=='-'||*p=='_'||isalnum(*p))) p++; if (!*p) name = argv[1]; }&lt;br /&gt;
 if (argc &amp;gt;= 3) default_value = atof(argv[2]);&lt;br /&gt;
 for (int i=0; i&amp;lt;MAXSIZE; i++) a[i] = default_value;&lt;br /&gt;
 while (1) {&lt;br /&gt;
  double index, value;&lt;br /&gt;
  if (scanf(&amp;quot;%lf %lf&amp;quot;, &amp;amp;index, &amp;amp;value) != 2) break;&lt;br /&gt;
  int i = index;&lt;br /&gt;
  if (i &amp;lt; 0)        { printf(&amp;quot;Index can't be negative\n&amp;quot;); continue; }&lt;br /&gt;
  if (i &amp;gt;= MAXSIZE) { printf(&amp;quot;Index too big, can't add it\n&amp;quot;); continue; }&lt;br /&gt;
  if (i &amp;gt;= size) size = i+1;&lt;br /&gt;
  a[i] = value;&lt;br /&gt;
 }&lt;br /&gt;
 char filename[256];&lt;br /&gt;
 sprintf(filename, &amp;quot;data/%s.data-float64-%dx1&amp;quot;, name, size);&lt;br /&gt;
 FILE *f = fopen(filename, &amp;quot;w&amp;quot;);&lt;br /&gt;
 if (!f) { perror(filename); return 1; }&lt;br /&gt;
 printf(&amp;quot;Writing file: %s\n&amp;quot;, filename);&lt;br /&gt;
 fwrite(a, sizeof(double), size, f);&lt;br /&gt;
 fclose(f);&lt;br /&gt;
 return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Elie</name></author>
	</entry>
</feed>