URI: 
       tporosity.cpp - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
  HTML git clone git://src.adamsgaard.dk/sphere
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       tporosity.cpp (2980B)
       ---
            1 // Including library files
            2 #include <iostream>
            3 #include <string>
            4 #include <cstdlib>
            5 
            6 // Including user files
            7 #include "constants.h"
            8 #include "datatypes.h"
            9 #include "sphere.h"
           10 
           11 //////////////////
           12 // MAIN ROUTINE //
           13 //////////////////
           14 // The main loop returns the value 0 to the shell, if the program terminated
           15 // successfully, and 1 if an error occured which caused the program to crash.
           16 int main(const int argc, const char *argv[]) 
           17 {
           18     // Default values
           19     int verbose = 0;
           20     int nfiles = 0; // number of input files
           21     int slices = 10; // number of vertical slices
           22 
           23     // Process input parameters
           24     int i;
           25     for (i=1; i<argc; ++i) {        // skip argv[0]
           26 
           27         std::string argvi = std::string(argv[i]);
           28 
           29         // Display help if requested
           30         if (argvi == "-h" || argvi == "--help") {
           31             std::cout << argv[0] << ": sphere porosity calculator\n"
           32                 "Usage: " << argv[0] << " [OPTION[S]]... [FILE1 ...]\n"
           33                 "Options:\n"
           34                 "-h, --help\t\tprint help\n"
           35                 "-V, --version\t\tprint version information and exit\n"
           36                 "-v, --verbose\t\tdisplay in-/output file names\n"
           37                 "-s. --slices\t\tnumber of vertical slices to find porosity "
           38                 "within\n"
           39                 "The porosity values are stored in the output/ folder"
           40                 << std::endl;
           41             return 0; // Exit with success
           42         }
           43 
           44         // Display version with fancy ASCII art
           45         else if (argvi == "-V" || argvi == "--version") {
           46             std::cout << "Porosity calculator, sphere version " << VERSION
           47                 << std::endl;
           48             return 0;
           49         }
           50 
           51         else if (argvi == "-v" || argvi == "--verbose")
           52             verbose = 1;
           53 
           54         else if (argvi == "-s" || argvi == "--slices") {
           55             slices = atoi(argv[++i]); 
           56             if (slices < 1) {
           57                 std::cerr << "Error: The number of slices must be a positive, "
           58                     "real number (was " << slices << ")" << std::endl;
           59                 return 1;
           60             }
           61         }
           62 
           63         // The rest of the values must be input binary files
           64         else {
           65             nfiles++;
           66 
           67             if (verbose == 1)
           68                 std::cout << argv[0] << ": processing input file: " << argvi <<
           69                     std::endl;
           70 
           71             // Create DEM class, read data from input binary, check values
           72             DEM dem(argvi, verbose, 0, 0, 0, 0);
           73 
           74             // Calculate porosity and save as file
           75             dem.porosity(slices);
           76 
           77         }
           78     }
           79 
           80     // Check whether there are input files specified
           81     if (!argv[0] || argc == 1 || nfiles == 0) {
           82         std::cerr << argv[0] << ": missing input binary file\n"
           83             << "See `" << argv[0] << " --help` for more information"
           84             << std::endl;
           85         return 1; // Return unsuccessful exit status
           86     }
           87 
           88     return 0; // Return successfull exit status
           89 } 
           90 // END OF FILE
           91 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4