/* This program computes the possible circumferences of bucky tubes. */
#include <math.h>
#include <stdio.h>
/* given carbon atoms C1, C2, and C3, with C1 bonded to
   C2 and C2 bonded to C3 in a sheet of graphite, CCC
   is the distance between C1 and C3 in nanometers.
   This is approximately 0.2465
#define CCC 0.2451
#define PI  3.141592653589793
main (argc,argv)
int     argc;
char    *argv [];
   double circumference, x, y, xycircumference;
   int i,j,limit;

   printf("1 This program enumerates all possible circumferences of bucky tubes\n");
   printf("2 that are shorter than the circumference entered on the command line.\n");
   printf("3 It is often convenient to sort the output of this program by,\n");
   printf("4 for example, piping the output to the unix 'sort' command.\n");
   printf("5 This lists the possible circumferences in ascending order.\n");
   if(argc !=2) { printf(
     "One argument required: the maximum circumference in nanometers\n");
   if (  (sscanf(argv[1],"%lf",&circumference)!=1) || (circumference<=0.0) ){
      printf("Bad argument: %s\n",argv[1]);
     "One argument required: the maximum circumference in nanometers\n");
   printf("6 The circumference entered on the command line was %7.3lf.\n",circumference);
   printf("7 \n");
"8 Computed circumference (nanometers), radius (nanometers) and (i,j) indices:\n");
     /* scan over the unit cells with indices i and j, and
        compute the distance of each unit cell from the origin.
        Because of symmetry, only consider unit cells which have
        angular position phi such that 0 <= phi <= 30 degrees.
        "limit" is too large too insure we don't miss a tube
        with a circumference in the desired range.  This means
        we have to throw out a lot of tubes that we find that
        have a circumference larger than desired.

        One interpretation of the indices i and j is that i
        scans along the x axis, while j scans along a line 60
        degrees above the x axis.  The unit cell indicated by
        (i,j) is found by first moving along the x axis in a
        positive direction for i cells, and then moving along
        a line inclined upwards from the x axis by 60 degrees
        for j cells.
      x=i*CCC + j*CCC/2.0;   /* x offset of unit cell */
      y=j*CCC*sqrt(3.0)/2.0; /* y offset of unit cell */
      xycircumference= sqrt(x*x+y*y); /* distance from origin to (x,y) */
      if (xycircumference <= circumference)
"Circumference =%8.4lf, radius =%8.4lf,   index = (%d,%d)\n",