|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #include "BlockAlignerParameters.hpp" 00023 00024 #include <stdio.h> 00025 #include <unistd.h> 00026 00027 #include <sstream> 00028 using namespace std; 00029 00030 00031 #include "../aligners/AbstractBlockAligner.hpp" 00032 00033 #define AUTO_GRID_SIZE (-1) 00034 00035 #define DEFAULT_BLOCK_SIZE 0 00036 #define DEFAULT_BLOCK_SIZE_STR "0" 00037 00038 #define DEFAULT_GRID_SIZE AUTO_GRID_SIZE 00039 #define DEFAULT_GRID_SIZE_STR "Auto" 00040 00041 /** 00042 * Usage Strings 00043 */ 00044 #define USAGE_HEADER "Specific Parameters" 00045 #define USAGE "\ 00046 --block-width=W Defines that each Block has H cells vertically. Default: "DEFAULT_BLOCK_SIZE_STR".\n\ 00047 --block-height=H Defines that each Block has W cells horizontally. Default: "DEFAULT_BLOCK_SIZE_STR".\n\ 00048 --block-size=H,W Defines the dimensions of each block.\n\ 00049 --grid-width=W Divides the Grid in H rows of blocks. Default: "DEFAULT_GRID_SIZE_STR".\n\ 00050 --grid-height=H Divides the Grid in W columns of blocks. Default: "DEFAULT_GRID_SIZE_STR".\n\ 00051 --grid-size=H,W Defines the dimensions of the grid.\n\ 00052 " 00053 00054 /** 00055 * getopt arguments 00056 */ 00057 #define ARG_GRID_WIDTH 0x1001 00058 #define ARG_GRID_HEIGHT 0x1002 00059 #define ARG_BLOCK_HEIGHT 0x1003 00060 #define ARG_BLOCK_WIDTH 0x1004 00061 #define ARG_GRID_SIZE 0x1005 00062 #define ARG_BLOCK_SIZE 0x1006 00063 00064 static struct option long_options[] = { 00065 {"block-height", required_argument, 0, ARG_BLOCK_HEIGHT}, 00066 {"block-width", required_argument, 0, ARG_BLOCK_WIDTH}, 00067 {"grid-height", required_argument, 0, ARG_GRID_HEIGHT}, 00068 {"grid-width", required_argument, 0, ARG_GRID_WIDTH}, 00069 {"grid-size", required_argument, 0, ARG_GRID_SIZE}, 00070 {"block-size", required_argument, 0, ARG_BLOCK_SIZE}, 00071 {0, 0, 0, 0} 00072 }; 00073 00074 /* 00075 * Constructor. Initializates the inner structures. 00076 */ 00077 BlockAlignerParameters::BlockAlignerParameters() { 00078 gridWidth = DEFAULT_GRID_SIZE; 00079 gridHeight = DEFAULT_GRID_SIZE; 00080 blockWidth = DEFAULT_BLOCK_SIZE; 00081 blockHeight = DEFAULT_BLOCK_SIZE; 00082 } 00083 00084 void BlockAlignerParameters::printUsage() const { 00085 AbstractAlignerParameters::printFormattedUsage(USAGE_HEADER, USAGE); 00086 } 00087 00088 /* 00089 * Destructor 00090 */ 00091 BlockAlignerParameters::~BlockAlignerParameters() { 00092 } 00093 00094 int BlockAlignerParameters::processArgument(int argc, char** argv) { 00095 00096 int ret = AbstractAlignerParameters::callGetOpt(argc, argv, long_options); 00097 switch ( ret ) { 00098 case ARG_GRID_SIZE: 00099 sscanf ( optarg, "%d,%d", &gridHeight,&gridWidth); 00100 break; 00101 case ARG_GRID_WIDTH: 00102 sscanf ( optarg, "%d", &gridWidth ); 00103 break; 00104 case ARG_GRID_HEIGHT: 00105 sscanf ( optarg, "%d", &gridHeight ); 00106 break; 00107 case ARG_BLOCK_SIZE: 00108 sscanf ( optarg, "%d,%d", &blockHeight,&blockWidth); 00109 break; 00110 case ARG_BLOCK_WIDTH: 00111 sscanf ( optarg, "%d", &blockWidth); 00112 break; 00113 case ARG_BLOCK_HEIGHT: 00114 sscanf ( optarg, "%d", &blockHeight); 00115 break; 00116 default: 00117 return ret; 00118 } 00119 00120 if ( gridHeight > MAX_GRID_SIZE || gridWidth > MAX_GRID_SIZE 00121 || (gridHeight < MIN_GRID_SIZE && gridHeight != AUTO_GRID_SIZE) 00122 || (gridWidth < MIN_GRID_SIZE && gridWidth != AUTO_GRID_SIZE)) { 00123 stringstream out; 00124 out << "Grid dimensions must be in range [" << MIN_GRID_SIZE << ".." << MAX_GRID_SIZE << "]."; 00125 setLastError(out.str().c_str()); 00126 return ARGUMENT_ERROR; 00127 } 00128 if ( blockHeight > MAX_BLOCK_SIZE || blockWidth > MAX_BLOCK_SIZE 00129 || (blockHeight < MIN_BLOCK_SIZE && blockHeight != 0) 00130 || (blockWidth < MIN_BLOCK_SIZE && blockWidth != 0)) { 00131 stringstream out; 00132 out << "Block dimensions must be in range [" << MIN_BLOCK_SIZE << ".." << MAX_BLOCK_SIZE << "]."; 00133 setLastError(out.str().c_str()); 00134 return ARGUMENT_ERROR; 00135 } 00136 00137 return ARGUMENT_OK; 00138 } 00139 00140 int BlockAlignerParameters::getBlockWidth() const { 00141 return blockWidth; 00142 } 00143 00144 int BlockAlignerParameters::getGridWidth() const { 00145 return gridWidth; 00146 } 00147 00148 int BlockAlignerParameters::getBlockHeight() const { 00149 return blockHeight; 00150 } 00151 00152 int BlockAlignerParameters::getGridHeight() const { 00153 return gridHeight; 00154 }
1.7.6.1