C2011mar17.cc

From TORI
Revision as of 14:24, 20 June 2013 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

// Generator of image

C2011mar17.jpg

shown at fight; see the description there.

// (in Tori, as in other wikis, the images are clickable).
// This file requires the data c2011mar16.txt and c2011mar17.txt
// Then this generator can be saved as c2011mar17.cc and
// compiled with command make c2011mar17 and
// executed with command ./c2011mar17.
// Unfortunately, the mediawiki supports neither the eps nor pdf format;
// for the uploading of an updated version, the image should be converted to the jpg format. // Copyleft 2011 by Dmitrii Kouznetsov. At the reuse, indicate the source: this helps to trace the errors, if any.

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define DB double
#define DO(x,y) for(x=0; x<y; x++)
void ado(FILE *O, int X, int Y)
{      fprintf(O,"%c!PS-Adobe-2.0 EPSF-2.0\n",'%');
       fprintf(O,"%c%cBoundingBox: 0 0 %d %d\n",'%','%',X,Y);
       fprintf(O,"/M {moveto} bind def\n");
       fprintf(O,"/L {lineto} bind def\n");
       fprintf(O,"/S {stroke} bind def\n");
       fprintf(O,"/s {show newpath} bind def\n");
       fprintf(O,"/C {closepath} bind def\n");
       fprintf(O,"/F {fill} bind def\n");
       fprintf(O,"/o {.01 0 360 arc C S} bind def\n");
       fprintf(O,"/O {.01 0 360 arc C F} bind def\n");
       fprintf(O,"/times-Roman findfont .25 scalefont setfont\n");
       fprintf(O,"/W {setlinewidth} bind def\n");
       fprintf(O,"/RGB {setrgbcolor} bind def\n");}
main(){ int m,n,k; DB x,y,z, X[49],Y[49], Z[49][17]; char c,d, namae[32];
       //char city[16];
       //char City[49][16];
       char CITY[49][16];
       char NAMAE[49][32];
       char HOURS[17][17];
       char hours[17];
       FILE *i,*o;
//i=fopen("04.txt","r");
i=fopen("c2011mar16.txt","r");
DO(m,900) { fscanf(i,"%c",&c); printf("%c",c); if(c==64) goto end1; }
end1: printf("m=%7d\n",m);
for(n=1; n<48; n++)
{ fscanf(i,"%d", &m);   printf("%2d ",n);
 fscanf(i,"%s", NAMAE[n]);
 fscanf(i,"%s", CITY[n]);
 printf("%12s ",CITY[n]);
 fscanf(i,"%lf%lf",&y,&x);     printf("% 5.2lf %6.2lf ",y,x);          X[n]=x; Y[n]=y;
 for(k=1;k<16;k++){ fscanf(i,"%lf",&z); if(z==0) z=1.; printf(" %5.3lf",z);    Z[n][k]=z;}
 printf("\n");
}
fclose(i);
printf("\n");
 i=fopen("c2011mar17.txt","r");
DO(m,1900) { fscanf(i,"%c",&c); printf("%c",c); if(c==64) goto end; }
end: printf("m=%7d\n",m);
for(k=1;k<10;k++)
{  fscanf(i,"%s", hours); printf("\nhours=%3s \n",hours);
   for(n=1;n<48;n++) { if(n==7 || (n==4 && k==9) ) z=1.; else fscanf(i,"%lf",&z);
                       Z[n][k]=z; printf(" %5.3lf",Z[n][k]);
                       }
}                                                          
fclose(i);
for(n=1;n<48;n++){ printf("\n"); printf("%3d %12s",n,CITY[n]);
for(k=1;k<10;k++){ printf(" %5.3lf",Z[n][k]);  } printf(" %12s",NAMAE[n]);}
printf("\n");
o=fopen("c2011mar17.eps", "w"); ado(o,114,140);
#define o(x,y) fprintf(o,"%4.3f %4.3f o\n",(x-130.)*.88,(y-30.)*1.15);
#define O(x,y) fprintf(o,"%4.3f %4.3f O\n",(x-130.)*.88,(y-30.)*1.15);
#define M(x,y) fprintf(o,"%4.3f %4.3f M\n",(x-130.)*.88,(y-30.)*1.15);
// The scaling is an attempt to fit the mercator projection of the map
//fprintf(o,"10 5 translate\n");
fprintf(o,"2 -15 translate\n");
fprintf(o,"10 10 scale\n");


fprintf(o,".4 W\n");
for(n=1;n<48;n++)
       {
       DB s=0; for(k=1;k<9;k++) s+=Z[n][k]; s/=8.;
       if(s<0.05){ fprintf(o,"0 1 0 RGB\n"); goto fin;}
       if(s<0.1) { fprintf(o,".5 .5 0 RGB\n"); goto fin;}
       if(s<0.2) { fprintf(o,"1 0 0 RGB\n"); goto fin;}
       if(s<0.4) {fprintf(o,".7 0 .8 RGB\n"); goto fin;}
                     fprintf(o,"0 0 .4 RGB\n");
fin:    M(X[n],Y[n])   fprintf(o,"(%2d %s) show newpath\n", n, CITY[n]);
o(X[n],Y[n]);
}
fprintf(o,"0 1 1 RGB\n");
//o(138.252924,36.204824)
//141.0125, 37.449167 futaba
o(141.032917, 37.422972)
fprintf(o,"/times-Roman findfont .4 scalefont setfont\n");
fprintf(o,"newpath 0  0  0 RGB 0 14.8 M (level, measured in  microZv/h :) show\n");
fprintf(o,"0  .8  0 RGB 0 14.4 M (less than 0.05    : rgb 0 1 0) show\n");
fprintf(o,".4 .4 0 RGB 0 14.0 M (from 0.05 to 0.1 : rgb .5 .5 0) show\n");
fprintf(o,".8  0  0 RGB 0 13.6 M (from 0.1 to 0.2  : rgb 1 0 0) show\n");
fprintf(o,".6 0 .7 RGB 0 13.2 M (from 0.2 to 0.4   : rgb .7 0 .8) show\n");
fprintf(o,"0  0  .4 RGB 0 12.8 M (more than 0.4    : rgb  0 0 .4) show\n");
fprintf(o,"/times-Roman findfont .25 scalefont setfont\n");
fprintf(o,"0 10.7 M 0 0 0 RGB (Interpretation of data from) show\n");
fprintf(o,"0 10.4 M (http://www.mext.go.jp/component/a_menu/other/detail/__icsFiles/afieldfile/2011/03/17/1303724_6_3.pdf) show\n");
fprintf(o,"/times-Roman findfont .3 scalefont setfont\n");
fprintf(o,"0 10 M 0 0 0 RGB (Map of contamination for 2010 March 17) show\n");
fprintf(o,"0 9.6 M 0 0 0 RGB (Copyleft 2011 by Dmitrii Kouznetsov) show\n");
fprintf(o,"showpage\n");
fprintf(o,"%cTrailer\n",'%');
fclose(o);
system("epstopdf c2011mar17.eps");
system(    "open c2011mar17.pdf");
//system("convert c2011mar17.eps c2011mar17.jpg");
}

// End of the C++ source // // //