void main(void) { /*Set up the I2C device*/ setup(); sleep(1); /*Initialize the control registers*/ init(); while(1) { /*Read the X,Y,Z axes of the I2C device*/ readXYZ(); sleep(1); } }
int main(int argc, char **argv) { struct part *part; int opt, n; int dump_part = 0; int printStructurePotentialEnergy = 0; int needVDW = 1; char *printPotential = NULL; double printPotentialInitial = -1; // pm double printPotentialIncrement = -1; // pm double printPotentialLimit = -1; // pm char *fileNameTemplate = NULL; char *outputFilename = NULL; reinit_globals(); if (signal(SIGTERM, &SIGTERMhandler) == SIG_ERR) { perror("signal(SIGTERM)"); exit(1); } CommandLine = assembleCommandLine(argc, argv); while ((opt = getopt_long(argc, argv, "hnmEi:f:s:t:xXONI:K:rD:o:q:B:", option_vec, NULL)) != -1) { switch(opt) { case 'h': usage(); case OPT_DUMP_PART: dump_part = 1; break; case OPT_WRITE_GROMACS_TOPOLOGY: GromacsOutputBaseName = optarg; break; case OPT_PATH_TO_CPP: PathToCpp = optarg; break; case OPT_SYSTEM_PARAMETERS: SystemParametersFileName = optarg; break; case OPT_PRINT_POTENTIAL: printPotential = optarg; break; case OPT_INITIAL: printPotentialInitial = atof(optarg); break; case OPT_INCREMENT: printPotentialIncrement = atof(optarg); break; case OPT_LIMIT: printPotentialLimit = atof(optarg); break; case OPT_DIRECT_EVALUATE: DirectEvaluate = 1; break; case OPT_INTERPOLATE: DirectEvaluate = 0; break; case OPT_SIMPLE_MOVIE_FORCE_SCALE: SimpleMovieForceScale = atof(optarg); break; case OPT_MIN_THRESH_CUT_RMS: MinimizeThresholdCutoverRMS = atof(optarg); break; case OPT_MIN_THRESH_CUT_MAX: MinimizeThresholdCutoverMax = atof(optarg); break; case OPT_MIN_THRESH_END_RMS: MinimizeThresholdEndRMS = atof(optarg); break; case OPT_MIN_THRESH_END_MAX: MinimizeThresholdEndMax = atof(optarg); break; case OPT_VDW_CUTOFF_RADIUS: VanDerWaalsCutoffRadius = atof(optarg); break; case OPT_VDW_CUTOFF_FACTOR: VanDerWaalsCutoffFactor = atof(optarg); break; case OPT_ENABLE_ELECTROSTATIC: EnableElectrostatic = atoi(optarg); break; case OPT_TIME_REVERSAL: TimeReversal = 1; break; case OPT_THERMOSTAT_GAMMA: ThermostatGamma = atof(optarg); break; case OPT_PRINT_ENERGIES: PrintPotentialEnergy = 1; break; case OPT_NEIGHBOR_SEARCHING: NeighborSearching = atoi(optarg); break; case 'n': // ignored break; case 'm': ToMinimize=1; break; case 'E': printStructurePotentialEnergy=1; break; case 'i': IterPerFrame = atoi(optarg); break; case 'f': NumFrames = atoi(optarg); break; case 's': Dt = atof(optarg); break; case 't': Temperature = atof(optarg); break; case 'x': DumpAsText = 1; break; case 'X': DumpIntermediateText = 1; break; case 'O': OutputFormat = 1; break; case 'N': OutputFormat = 2; break; case OPT_OUTPUT_FORMAT_3: OutputFormat = 3; break; case 'I': IDKey = optarg; break; case 'K': KeyRecordInterval = atoi(optarg); break; case 'r': PrintFrameNums = 1; break; case 'D': n = atoi(optarg); if (n < 32 && n >= 0) { debug_flags |= 1 << n; } break; case 'o': outputFilename = optarg; break; case 'q': TraceFileName = optarg; break; case 'B': BaseFileName = optarg; break; case ':': case '?': default: usage(); exit(1); } } if (optind + 1 == argc) { // (optind < argc) if not paranoid fileNameTemplate = argv[optind]; } if (DEBUG(D_PRINT_BEND_STRETCH)) { // -D8 initializeBondTable(); printBendStretch(); exit(0); } if (DumpAsText) { OutputFormat = 0; } if (!fileNameTemplate) { usage(); } InputFileName = replaceExtension(fileNameTemplate, "mmp"); if (BaseFileName != NULL) { int i1; int i2; struct xyz *basePositions; struct xyz *initialPositions; basePositions = readXYZ(BaseFileName, &i1); if (basePositions == NULL) { fprintf(stderr, "could not read base positions file from -B<filename>\n"); exit(1); } initialPositions = readXYZ(InputFileName, &i2); if (initialPositions == NULL) { fprintf(stderr, "could not read comparison positions file\n"); exit(1); } if (i1 != i2) { fprintf(stderr, "structures to compare must have same number of atoms\n"); exit(1); } exit(doStructureCompare(i1, basePositions, initialPositions, NumFrames, 1e-8, 1e-4, 1.0+1e-4)); } if (outputFilename) { OutputFileName = copy_string(outputFilename); } else { char *extension; switch (OutputFormat) { case 0: extension = "xyz"; break; case 1: case 2: default: extension = "dpb"; break; case 3: extension = "gro"; break; } OutputFileName = replaceExtension(fileNameTemplate, extension); } if (TraceFileName) { TraceFile = fopen(TraceFileName, "w"); if (TraceFile == NULL) { perror(TraceFileName); exit(1); } } else { TraceFile = fdopen(1, "w"); if (TraceFile == NULL) { perror("fdopen stdout as TraceFile"); exit(1); } } traceFileVersion(); // call this before any other writes to trace file. // tell where and how the simulator was built. We never build the // standalone simulator with distutils. fprintf(TraceFile, "%s", tracePrefix); initializeBondTable(); if (IterPerFrame <= 0) IterPerFrame = 1; if (printPotential) { printPotentialAndGradientFunctions(printPotential, printPotentialInitial, printPotentialIncrement, printPotentialLimit); exit(0); } part = readMMP(InputFileName); if (EXCEPTION) { exit(1); } if (GromacsOutputBaseName != NULL) { needVDW = 0; } initializePart(part, needVDW); createPatterns(); matchPartToAllPatterns(part); if (printStructurePotentialEnergy) { struct xyz *force = (struct xyz *)allocate(sizeof(struct xyz) * part->num_atoms); double potentialEnergy = calculatePotential(part, part->positions); calculateGradient(part, part->positions, force); printf("%e %e %e %e (Potential energy in aJ, gradient of atom 1)\n", potentialEnergy, force[1].x, force[1].y, force[1].z); exit(0); } if (dump_part) { // // this segment is convenient to run valgrind on to test the // part and bond table destructors. By the time we reach the // exit() there should be no malloc'd blocks remaining. // // valgrind -v --leak-check=full --leak-resolution=high --show-reachable=yes simulator --dump-part part.mmp // printPart(stdout, part); destroyPart(part); part = NULL; destroyBondTable(); fclose(TraceFile); destroyAccumulator(CommandLine); free(InputFileName); free(OutputFileName); exit(0); } if (GromacsOutputBaseName != NULL) { printGromacsToplogy(GromacsOutputBaseName, part); destroyPart(part); part = NULL; destroyBondTable(); fclose(TraceFile); destroyAccumulator(CommandLine); free(InputFileName); free(OutputFileName); done(""); exit(0); } constrainGlobals(); traceHeader(part); if (ToMinimize) { NumFrames = max(NumFrames,(int)sqrt((double)part->num_atoms)); Temperature = 0.0; } else { traceJigHeader(part); } OutputFile = fopen(OutputFileName, DumpAsText ? "w" : "wb"); if (OutputFile == NULL) { perror(OutputFileName); exit(1); } writeOutputHeader(OutputFile, part); if (ToMinimize) { minimizeStructure(part); exit(0); } else { dynamicsMovie(part); } done(""); return 0; }