~ubuntu-branches/ubuntu/raring/voxbo/raring

« back to all changes in this revision

Viewing changes to stand_alone/permstart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-06-06 11:33:11 UTC
  • Revision ID: james.westby@ubuntu.com-20100606113311-v3c13imdkkd5n7ae
Tags: upstream-1.8.5~svn1172
ImportĀ upstreamĀ versionĀ 1.8.5~svn1172

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// permstart.cpp
 
3
// Copyright (c) 1998-2010 by The VoxBo Development Team
 
4
 
 
5
// This file is part of VoxBo
 
6
// 
 
7
// VoxBo is free software: you can redistribute it and/or modify it
 
8
// under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation, either version 3 of the License, or
 
10
// (at your option) any later version.
 
11
// 
 
12
// VoxBo is distributed in the hope that it will be useful, but
 
13
// WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
// General Public License for more details.
 
16
// 
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with VoxBo.  If not, see <http://www.gnu.org/licenses/>.
 
19
// 
 
20
// For general information on VoxBo, including the latest complete
 
21
// source code and binary distributions, manual, and associated files,
 
22
// see the VoxBo home page at: http://www.voxbo.org/
 
23
// 
 
24
// original version written by Kosh Banerjee
 
25
 
 
26
#include <iostream>
 
27
#include "perm.h"
 
28
 
 
29
using namespace std;
 
30
 
 
31
void usage(const unsigned short exitValue, char *progName);
 
32
 
 
33
gsl_rng *theRNG = NULL;
 
34
 
 
35
int main(int argc, char *argv[]) {
 
36
  SEGV_HANDLER
 
37
  GSL_ERROR_HANDLER_OFF
 
38
 
 
39
  if (argc == 1)
 
40
    usage(1, argv[0]);
 
41
 
 
42
  string matrixStemName;
 
43
  string permDir;
 
44
  short method = -1;
 
45
 
 
46
/*********************************************************************
 
47
* Now processing the command line options.                           *
 
48
*                                                                    *
 
49
* -h ==> Display usage information.                                  *
 
50
* -m ==> Specifies the matrix stem name.                             *
 
51
* -d ==> Permutation directory.                                      *
 
52
* -t ==> Permutation type.                                           *
 
53
* -v ==> Print out the gobal VoxBo version number.                   *
 
54
*                                                                    *
 
55
* VARIABLES:                                                         *
 
56
* printHelp - a flag, used to determine if the "-h" command line     *
 
57
*             option was used or not.                                *
 
58
* printVersion - a flag, used to determine if the "-v" command line  *
 
59
*                option was used or not.                             *
 
60
*********************************************************************/
 
61
  GLMInfo glmi;
 
62
  arghandler a;
 
63
  a.setArgs("-h", "--help", 0);
 
64
  a.setArgs("-m", "--matrixstemname", 1);
 
65
  a.setArgs("-d", "--permdir", 1);
 
66
  a.setArgs("-t", "--method", 1);
 
67
  a.setArgs("-v", "--version", 0);
 
68
  a.parseArgs(argc, argv);
 
69
  string errstring = a.badArg();
 
70
  if (errstring.size()) {
 
71
     errstring = "[E] unknown flag: " + errstring;
 
72
     printErrorMsg(VB_ERROR, errstring.c_str());
 
73
     exit(-1);
 
74
  }
 
75
  if (a.flagPresent("-h"))
 
76
     usage(0, argv[0]);
 
77
  matrixStemName = a.getFlaggedArgs("-m")[0];
 
78
  permDir = a.getFlaggedArgs("-d")[0];
 
79
  method = atoi(a.getFlaggedArgs("-t")[0].c_str());
 
80
  if (a.flagPresent("-v"))
 
81
    printf("\nVoxBo v%s\n",vbversion.c_str());
 
82
  if (matrixStemName.size() == 0) {
 
83
    ostringstream errorMsg;
 
84
    errorMsg << "Must specify the matrix stem name, using the \"-m\" option.";
 
85
    printErrorMsgAndExit(VB_ERROR, errorMsg, 1);
 
86
  } 
 
87
  if (permDir.size() == 0) {
 
88
    ostringstream errorMsg;
 
89
    errorMsg << "Must specify the permutation directory name, using the \"-d\" option.";
 
90
    printErrorMsgAndExit(VB_ERROR, errorMsg, 1);
 
91
  } 
 
92
  if ((method < 0) || (method > 2)) {
 
93
    ostringstream errorMsg;
 
94
    errorMsg << "The \"-t\" argument must be 1 or 2, not [" << method << "].";
 
95
    printErrorMsgAndExit(VB_ERROR, errorMsg, 1);
 
96
  }
 
97
  permclass pc;
 
98
  glmi.setup(matrixStemName);
 
99
  pc.AddMatrixStemName(glmi.stemname);
 
100
  pc.AddPermDir(permDir);
 
101
  pc.AddMethod(method);
 
102
  int err = 0;
 
103
  err = permStart(pc);
 
104
  if (err)
 
105
     switch(err) {
 
106
         case 200:
 
107
          printErrorMsg(VB_ERROR, "permstart: no stem name specified.\n");
 
108
          break;
 
109
         case 201:
 
110
          printErrorMsg(VB_ERROR, "permstart: no perm directory specified.\n");
 
111
          return -1;
 
112
         case 202:
 
113
          printErrorMsg(VB_ERROR, "permstart: prm file not valid.\n");
 
114
          return -1;
 
115
         case 203:
 
116
          printErrorMsg(VB_ERROR, "permstart: g matrix file not readable.\n");
 
117
          return -1;
 
118
         case 204:
 
119
          printErrorMsg(VB_ERROR, "permstart: MAT1 header not valid.\n");
 
120
          break;
 
121
         case 205:
 
122
          printErrorMsg(VB_ERROR, "permstart: failed to allocate permutation.\n");
 
123
          return -1;
 
124
         case 206:
 
125
          printErrorMsg(VB_ERROR, "permstart: bad permuation type.\n");
 
126
          return -1;
 
127
         case 207:
 
128
          printErrorMsg(VB_ERROR, "permstart: failed to make subdirectory.\n");
 
129
          return -1;
 
130
         case 208:
 
131
          printErrorMsg(VB_ERROR, "permstart: failed to make permutation matrix.\n");
 
132
          break;
 
133
         case 209:
 
134
          printErrorMsg(VB_ERROR, "permstart: permutation matrix is not valid.\n");
 
135
          return -1;
 
136
         case 210:
 
137
          printErrorMsg(VB_ERROR, "permstart: failed to write permutation matrix file.\n");
 
138
          return -1;
 
139
         default:
 
140
          printErrorMsg(VB_ERROR, "permstart: unknown error.\n");
 
141
          return -1;
 
142
     }
 
143
  return 0;
 
144
 
145
 
 
146
void usage(const unsigned short exitValue, char *progName) {
 
147
  printf("\nVoxBo permstart (v%s)\n",vbversion.c_str());
 
148
  printf("summary: ");
 
149
  printf(" Permutation start.\n");
 
150
  printf("usage:\n");
 
151
  printf(" permstart -h -m[matrix stem name] -d[permutation directory] -t[permutation type] -v\n");
 
152
  printf("flags:\n");
 
153
  printf(" -h                        Print usage information. Optional.\n");
 
154
  printf(" -m <matrix stem name>                       Specify the matrix stem name. Required.\n");
 
155
  printf(" -d                        Permutation directory name. Required.\n");
 
156
  printf(" -t                        Permutation type. 1 means regular permutation.\n");
 
157
  printf("                           2 means sign permutation. Required.\n");
 
158
  printf(" -v                        Global VoxBo version number. Optional.\n\n");
 
159
  exit(-1);
 
160