/*-----------------------------autobond.c------------------------------
  This finds the chemical bonds in hydrocarbon molecules. The input and
  output files are in .abc format. This software was written by
  Stephen Jordan.
  ---------------------------------------------------------------------*/

#include "cell.h"                //for Cell  
#include "abcio.h"               //for loadabc, saveabc, and find_neighb_i
#include "handy.h"               //for strip_path
#include <stdio.h>               //for printf, fopen, FILE
#include <stdlib.h>              //for EXIT_SUCCESS and EXIT_FAILURE
#include <string.h>              //for strlen


int main(int argc, char *argv[]) {
  FILE *infile;
  FILE *outfile;
  char filename[256];
  int digits = 6;
  int i;
  cell C;
  if(argc < 2) {
    printf("Usage: autobond molecule.abc\n");
    return EXIT_FAILURE;
  }
  for(i = 1; i < argc; i++) {
     infile = fopen(argv[i],"r");
    if(infile == NULL) {
      printf("Unable to open %s\n", argv[i]);
      return EXIT_FAILURE;
    }
    strip_path(argv[i]);
    sprintf(filename, "A_%s", argv[i]);
    outfile = fopen(filename, "w");
    if(outfile == NULL) {
      printf("Unable to create %s\n", filename);
      return EXIT_FAILURE;
    }
    loadabc(infile, &C, 1);          //load structure + allocate RAM
    find_neighb_i(&C);
    saveabc(outfile, &C, "Created by autobond\n", digits, 0);
    fclose(infile);   
    fclose(outfile);         
    destroy_cell(&C);                //de-allocate memory
  }
  return EXIT_SUCCESS;
}






