index page
0001: //////////////////////////////////////////////////
0002: //
0003: //                      ppa-r
0004: //  point process analysis system: pair correlation
0005: //
0006: //
0007: //      Copyright  November 2004 by TAKENAKA, A.
0008: 
0009: #include <iostream>
0010: #include <iomanip>
0011: 
0012: #include "plotarea.h"          // link to plotarea.cpp
0013: 
0014: void showUsage(void);  //  prototype declaration.
0015: 
0016: /////////////////////////////////////////////////
0017: //
0018: //
0019: 
0020: int main (int argc, char** argv)
0021: {
0022:     double r_unit, r_upto;
0023:     const char* file1;
0024:     const char* file2 = NULL;
0025:     bool rvl;
0026: 
0027:     if (argc < 3 || 5 < argc) {
0028:         showUsage();
0029:         return -1;
0030:     }
0031: 
0032:     r_unit = atof(argv[1]);
0033:     r_upto = atof(argv[2]);
0034:     file1 = argv[3];  //  if argc = 3, argv[3] is NULL.
0035:     if (argc > 3) {
0036:         file2 = argv[4];  //  if argc = 4, argv[4] is NULL.
0037:     }
0038: 
0039:     PlotArea plot;
0040: 
0041:     rvl = plot.loadPoints(file1, file2);
0042:     if (!rvl) {
0043:         return -1;  //  failed to load points.
0044:     }
0045: 
0046:     rvl = plot.calc_cor(r_unit, r_upto);
0047:     if (!rvl) {
0048:         return -1;  //  failed to calculate r.
0049:     }
0050: 
0051:     const r_X_Array& results = plot.getResults();
0052: 
0053:     std::cout << "r\tcor" << std::endl;
0054:     
0055:     //  The next line is to overcome the different interpretation
0056:     //  of setprecision() among compilers.
0057:     // cf http://home.earthlink.net/~ddruml/setpre.html
0058: 
0059:     std::cout.setf(std::ios::fixed);
0060: 
0061:     int oldPrec = std::cout.precision();
0062: 
0063:     for (int i = 0; i < (int) results.size(); ++i) {
0064:         std::cout << std::setprecision(2)
0065:                   << double (results[i].first)
0066:                   << "\t"
0067:                    << std::setprecision(3)
0068:                   << double (results[i].second)
0069:                   << std::endl;
0070:     }
0071: 
0072:     std::cout.precision(oldPrec);
0073: 
0074:     return 0;
0075: }
0076: 
0077: //////////////////////////////////////
0078: 
0079: void showUsage(void)
0080: {
0081:     std::cout << "ppa-r ver 0.1  2004 by TAKENAKA A." << std::endl;
0082:     std::cout << "USAGE: ppa-r r_unit r_upto file1 [file2]" << std::endl;
0083:     std::cout << "  r_unit is the increment of distance, r." << std::endl;
0084:     std::cout << "  r_upto is the max r." << std::endl;
0085:     std::cout << "  If file2 is not given, pair cor. within a set of points ";
0086:     std::cout << "is caluculated." << std::endl;
0087:     std::cout << "  If file2 is given, pair cor. between two sets of points ";
0088:     std::cout << "is caluculated." << std::endl;
0089:     std::cout << "For details, visit http://takenaka-akio.cool.ne.jp/etc/ppa-r/" << std::endl;
0090:     
0091: }

Back to Top of this Page