Main Program: Argument Parsing

Here, we parse the command line arguments. The user running the program can specify the magnet side-length $ L$, the temperature (in units of $ J/k_B$), the number of cycles, the sampling interval, and the seed value for the pseudorandom number generator. The array argv[] and its count of elements argc appear as parameters in the definition of main, as is customary in C. The built-in function strcmp() returns 0 if the two arguments match, so the logical expression strcmp(a,b)! evaluates to TRUE if strings a and b match. The built-in functions atoi() and atof() convert their string arguments to integers and floating-points, respectively. The notation argv[++i] means that first the current value of i is incremented by 1 and then it is used to access the value in argv[]. So, for example, if the string "-L" is detected at the ith position in the array of command-line arguments, the code immediately jumps to the next position in the array and tries to intepret that argument as an integer to assign to L.
  for (i=1;i<argc;i++) {
    if (!strcmp(argv[i],"-L")) L=atoi(argv[++i]);
    else if (!strcmp(argv[i],"-T")) T=atof(argv[++i]);
    else if (!strcmp(argv[i],"-nc")) nCycles = atoi(argv[++i]);
    else if (!strcmp(argv[i],"-fs")) fSamp = atoi(argv[++i]);
    else if (!strcmp(argv[i],"-s")) {
      Seed = (unsigned long)atoi(argv[++i]);
    }
  }



cfa22@drexel.edu