IPCC  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CKNCommandFileParser Class Reference

This class for parsing input command file. More...

#include "KNCommandFileParser.h"

Collaboration diagram for CKNCommandFileParser:
Collaboration graph

Classes

struct  INPUT_CMD_PARAM
 Structure for save input command file parsing result. More...
 

Public Types

typedef struct
CKNCommandFileParser::INPUT_CMD_PARAM
LPINPUT_CMD_PARAM
 

Public Member Functions

 CKNCommandFileParser ()
 
 ~CKNCommandFileParser ()
 

Static Public Member Functions

static LPINPUT_CMD_PARAM ParsingInputCommand (char *pszInputCommnadFileName)
 Parsing Commaind file. More...
 

Static Private Member Functions

static void GetValueAfterEqualString (char *pszOption, char *pszValue)
 Extracting string after equal charater postion. More...
 
static void SetOptionParam (LPINPUT_CMD_PARAM lpParam, char *pszOption, int nHash, int nOptIndex)
 Setting option variable. More...
 
static void TrimString (char *pszBuffer)
 Trim string using white spapce including ' '. More...
 
static void TrimStringEx (char *pszBuffer)
 Trim string using white spapce not including ' '. More...
 
static void TrimSpaceEdge (char *pszBuffer)
 Trim space both side of string. More...
 
static void ExtractParam (char *pszBuffer, double *pParam, int nParamSize)
 Extracing paramter in string. More...
 
static void InitData (LPINPUT_CMD_PARAM lpParam)
 Initialize some default parameter. More...
 
static unsigned int ExtractOptionIndex (char *pszBuffer, int nHash, int nOptIndex)
 Get Number of Index. ex) Geometry_Origin(1)=[ 0 0 0 ], -> Get '1' from option string. More...
 

Detailed Description

This class for parsing input command file.

Date
2014/9/30
Author
Kyu Nam Cho(mysto.nosp@m.us@k.nosp@m.orea..nosp@m.ac.k.nosp@m.r), Hoon Ryu(elec1.nosp@m.020@.nosp@m.gmail.nosp@m..com)

Definition at line 16 of file KNCommandFileParser.h.

Member Typedef Documentation

Constructor & Destructor Documentation

CKNCommandFileParser::CKNCommandFileParser ( )

Definition at line 48 of file KNCommandFileParser.cpp.

49 {
50 }
CKNCommandFileParser::~CKNCommandFileParser ( )

Definition at line 52 of file KNCommandFileParser.cpp.

53 {
54 }

Member Function Documentation

unsigned int CKNCommandFileParser::ExtractOptionIndex ( char *  pszBuffer,
int  nHash,
int  nOptIndex 
)
staticprivate

Get Number of Index. ex) Geometry_Origin(1)=[ 0 0 0 ], -> Get '1' from option string.

Parameters
pszBufferTarget string
nHashHash value
nOptIndexOption index

Definition at line 520 of file KNCommandFileParser.cpp.

References g_inputOption.

Referenced by SetOptionParam().

521 {
522  int nStart = strlen(g_inputOption[nHash][nOptIndex]) + 1;
523  char szNumber[10];
524  unsigned int nLastIndex, i;
525 
526  nLastIndex = 99999;
527  for (i = nStart; i < strlen(pszBuffer); ++i)
528  {
529  if (')' == pszBuffer[i])
530  {
531  nLastIndex = i;
532  break;
533  }
534  }
535 
536  if (99999 == nLastIndex)
537  return 0;
538 
539  strncpy(szNumber, pszBuffer + nStart, nLastIndex - nStart);
540  szNumber[nLastIndex - nStart] = NULL;
541  if (0 == strlen(szNumber))
542  return 0;
543  else
544  return atoi(szNumber);
545 }
char * g_inputOption[27][MAX_INPUTOPTION_HASH_NUMBER]

Here is the caller graph for this function:

void CKNCommandFileParser::ExtractParam ( char *  pszBuffer,
double *  pParam,
int  nParamSize 
)
staticprivate

Extracing paramter in string.

Parameters
pszBufferString buffer that want to extract parameters
[out]pParamBuffer for saving parmeters
nParamSizeCount that want to extract

Definition at line 125 of file KNCommandFileParser.cpp.

Referenced by SetOptionParam().

126 {
127  char *token = NULL;
128  char strSperate[] = " ";
129  int nCount = 0;
130 
131  token = strtok(pszBuffer, strSperate);
132 
133  while (token != NULL)
134  {
135  pParam[nCount++] = atof(token);
136 
137  if (nParamSize == nCount)
138  break;
139 
140  token = strtok(NULL, strSperate);
141  }
142 }

Here is the caller graph for this function:

void CKNCommandFileParser::GetValueAfterEqualString ( char *  pszOption,
char *  pszValue 
)
staticprivate

Extracting string after equal charater postion.

Parameters
pszOptionString that include parameter
[out]pszValueData buffer for saving option value

Definition at line 438 of file KNCommandFileParser.cpp.

Referenced by SetOptionParam().

439 {
440  strcpy(pszValue, strrchr(pszOption, '=') + 1);;
441 }

Here is the caller graph for this function:

void CKNCommandFileParser::InitData ( LPINPUT_CMD_PARAM  lpParam)
staticprivate

Initialize some default parameter.

Parameters
lpParamparameter structure for initialization

Definition at line 508 of file KNCommandFileParser.cpp.

References CKNCommandFileParser::INPUT_CMD_PARAM::load_in_MIC, CKNCommandFileParser::INPUT_CMD_PARAM::nFindingDegeneratedEVCount, and CKNCommandFileParser::INPUT_CMD_PARAM::nMPILevel.

Referenced by ParsingInputCommand().

509 {
510  lpParam->nMPILevel = 1;
511  lpParam->nFindingDegeneratedEVCount = 1;
512  lpParam->load_in_MIC = 0;
513 }

Here is the caller graph for this function:

CKNCommandFileParser::LPINPUT_CMD_PARAM CKNCommandFileParser::ParsingInputCommand ( char *  pszInputCommnadFileName)
static

Parsing Commaind file.

Parameters
pszInputCommnadFileNameCommand file name

Definition at line 446 of file KNCommandFileParser.cpp.

References g_inputOption, HASH_SARP, InitData(), MAX_INPUTOPTION_HASH_NUMBER, SetOptionParam(), and CKNCommandFileParser::INPUT_CMD_PARAM::szDataFileName.

Referenced by CKNTBMS_Solver::Launching_TBMS_Solver(), CKNGeometricConstructionLaunch::LaunchingGeometricConstruction(), and CKNGeometricConstructionLaunch::LaunchingGeometricConstructionMPI().

447 {
448  LPINPUT_CMD_PARAM lpRtn = NULL;
449  FILE *opt = NULL;
450  char szBuffer[1024];
451  int nHash;
452  int i;
453 
454  int k = 0;
455 
456  opt = fopen(pszInputCommnadFileName, "rt");
457  if (NULL == opt)
458  return lpRtn;
459 
460 
461  lpRtn = (LPINPUT_CMD_PARAM)malloc(sizeof(INPUT_CMD_PARAM));
462  memset(lpRtn, NULL, sizeof(INPUT_CMD_PARAM));
463  strcpy(lpRtn->szDataFileName, pszInputCommnadFileName);
464  InitData(lpRtn);
465 
466  while (fgets(szBuffer, 1024, opt))
467  {
468  nHash = (int)szBuffer[0];
469 
470  if (HASH_SARP == nHash)
471  continue;
472 
473  if (nHash >= 48 && nHash <= 57)
474  {
475  nHash = 26;
476  }
477  else
478  {
479  nHash -= 65;
480  if (nHash > 26)
481  nHash -= 32;
482  }
483 
484  if (nHash < 0 || nHash > 26)
485  continue;
486 
487  for (i = 0; i < MAX_INPUTOPTION_HASH_NUMBER; i++)
488  {
489  if (0 == strlen(g_inputOption[nHash][i]))
490  continue;
491 
492  if (!strncmp(g_inputOption[nHash][i], szBuffer, strlen(g_inputOption[nHash][i])))
493  {
494  SetOptionParam(lpRtn, szBuffer, nHash, i);
495  break;
496  }
497  }
498  }
499 
500  fclose(opt);
501 
502  return lpRtn;
503 }
#define HASH_SARP
Command file parameter names.
#define MAX_INPUTOPTION_HASH_NUMBER
static void InitData(LPINPUT_CMD_PARAM lpParam)
Initialize some default parameter.
static void SetOptionParam(LPINPUT_CMD_PARAM lpParam, char *pszOption, int nHash, int nOptIndex)
Setting option variable.
char * g_inputOption[27][MAX_INPUTOPTION_HASH_NUMBER]
struct CKNCommandFileParser::INPUT_CMD_PARAM * LPINPUT_CMD_PARAM

Here is the call graph for this function:

Here is the caller graph for this function:

void CKNCommandFileParser::SetOptionParam ( LPINPUT_CMD_PARAM  lpParam,
char *  pszOption,
int  nHash,
int  nOptIndex 
)
staticprivate

Setting option variable.

Parameters
[out]lpParamResult of parsing
pszOptionString that including options
nHashHash index A to #
nOptIndexSub index in save Hash

< A

< B

< C

< D

< E

< F

< G

< K

< L

< M

< N

< P

< R

< S

< U

< W

Definition at line 150 of file KNCommandFileParser.cpp.

References _X, _Y, _Z, CKNCommandFileParser::INPUT_CMD_PARAM::bCalculateEigenVectors, CKNCommandFileParser::INPUT_CMD_PARAM::bCalculateWaveFunction, CKNCommandFileParser::INPUT_CMD_PARAM::bConsiderBoundaryCondition, CKNCommandFileParser::INPUT_CMD_PARAM::bDoSelectiveReorthogonalization, CKNCommandFileParser::INPUT_CMD_PARAM::bNeedRotate, BOX_SHAPE, CKNCommandFileParser::INPUT_CMD_PARAM::bSaveHamiltonian, CKNCommandFileParser::INPUT_CMD_PARAM::bSaveMapFile, CKNCommandFileParser::INPUT_CMD_PARAM::bSortBeforeCSRBuilding, CKNCommandFileParser::INPUT_CMD_PARAM::bUsingCubeModel, CYLINDER_SHAPE, ExtractOptionIndex(), ExtractParam(), CKNCommandFileParser::INPUT_CMD_PARAM::fConvergeceCriteria, CKNCommandFileParser::INPUT_CMD_PARAM::fDirection, CKNCommandFileParser::INPUT_CMD_PARAM::fevMax, CKNCommandFileParser::INPUT_CMD_PARAM::fevMin, CKNCommandFileParser::INPUT_CMD_PARAM::fKPoints, CKNCommandFileParser::INPUT_CMD_PARAM::fKValueFinal, CKNCommandFileParser::INPUT_CMD_PARAM::fKValueInit, CKNCommandFileParser::INPUT_CMD_PARAM::fOrigin, CKNCommandFileParser::INPUT_CMD_PARAM::fShapeLength, CKNCommandFileParser::INPUT_CMD_PARAM::fUnitcellLength, GetValueAfterEqualString(), CKNCommandFileParser::INPUT_CMD_PARAM::load_in_MIC, CKNCommandFileParser::INPUT_CMD_PARAM::nBandSize, CKNCommandFileParser::INPUT_CMD_PARAM::nCheckEigenvalueInterval, CKNCommandFileParser::INPUT_CMD_PARAM::nDirectionSingle, CKNCommandFileParser::INPUT_CMD_PARAM::nFindingDegeneratedEVCount, CKNCommandFileParser::INPUT_CMD_PARAM::nFindingEigenValueCount, CKNCommandFileParser::INPUT_CMD_PARAM::nLanczosIterationCount, CKNCommandFileParser::INPUT_CMD_PARAM::nMatrixDemension, CKNCommandFileParser::INPUT_CMD_PARAM::nMatrixNonzeroElementCount, CKNCommandFileParser::INPUT_CMD_PARAM::nMPILevel, CKNCommandFileParser::INPUT_CMD_PARAM::nShape, CKNCommandFileParser::INPUT_CMD_PARAM::nSubDomainNumber, CKNCommandFileParser::INPUT_CMD_PARAM::szDataFileName, CKNCommandFileParser::INPUT_CMD_PARAM::szDomainMat, CKNCommandFileParser::INPUT_CMD_PARAM::szShape, CKNCommandFileParser::INPUT_CMD_PARAM::szStructureType, TrimSpaceEdge(), TrimString(), and TrimStringEx().

Referenced by ParsingInputCommand().

151 {
152  char szValue[1024] = "";
153 
154  GetValueAfterEqualString(pszOption, szValue);
155 
156  switch (nHash)
157  {
158  case 0:
159  switch (nOptIndex)
160  {
161  case 0:
162  lpParam->fUnitcellLength[_X] = atof(szValue);
163  break;
164  case 1:
165  lpParam->fUnitcellLength[_Y] = atof(szValue);
166  break;
167  case 2:
168  lpParam->fUnitcellLength[_Z] = atof(szValue);
169  break;
170  }
171  break;
172  case 1:
173  switch(nOptIndex)
174  {
175  case 0:
176  lpParam->nBandSize = atoi(szValue);
177  break;
178  }
179  case 2:
180  switch (nOptIndex)
181  {
182  case 0:
183  lpParam->fConvergeceCriteria = atof(szValue);
184  break;
185  case 1:
186  lpParam->nCheckEigenvalueInterval = atoi(szValue);
187  break;
188  }
189  break;
190  case 3:
191  switch (nOptIndex)
192  {
193  case 0:
194  {
195  double param[3];
196 
197  TrimStringEx(szValue);
198  TrimSpaceEdge(szValue);
199  ExtractParam(szValue, param, 3);
200  lpParam->fDirection[_X] = param[0];
201  lpParam->fDirection[_Y] = param[1];
202  lpParam->fDirection[_Z] = param[2];
203  lpParam->nDirectionSingle = 100 * (int)param[0];
204  lpParam->nDirectionSingle += (10 * (int)param[1]);
205  lpParam->nDirectionSingle += (int)param[2];
206  if (100 != lpParam->nDirectionSingle)
207  lpParam->bNeedRotate = true;
208  else
209  lpParam->bNeedRotate = false;
210  }
211  break;
212  case 1:
213  /*TrimString(szValue);
214  strcpy(lpParam->szDomainMat, szValue);*/
215  break;
216  case 2:
217  break;
218  case 3:
219  break;
220  }
221  case 4:
222  switch (nOptIndex)
223  {
224  case 0:
225  lpParam->fevMin = atof(szValue);
226  break;
227  case 1:
228  lpParam->fevMax = atof(szValue);
229  break;
230  case 2:
231  lpParam->bCalculateEigenVectors = atoi(szValue) == 1 ? true : false;
232  break;
233  }
234  break;
235  case 5:
236  switch (nOptIndex)
237  {
238  case 0:
239  lpParam->nFindingEigenValueCount = atoi(szValue);
240  break;
241  case 1:
242  lpParam->nFindingDegeneratedEVCount = atoi(szValue);
243  break;
244  }
245  break;
246  case 6:
247  switch (nOptIndex)
248  {
249  case 0:
250  {
251  double param[3];
252  unsigned int nSubIndex = ExtractOptionIndex(pszOption, nHash, nOptIndex);
253 
254  TrimStringEx(szValue);
255  TrimSpaceEdge(szValue);
256  ExtractParam(szValue, param, 3);
257  lpParam->fOrigin[nSubIndex - 1][_X] = param[0];
258  lpParam->fOrigin[nSubIndex - 1][_Y] = param[1];
259  lpParam->fOrigin[nSubIndex - 1][_Z] = param[2];
260  }
261  break;
262  case 1:
263  {
264  double param[3];
265  unsigned int nSubIndex = ExtractOptionIndex(pszOption, nHash, nOptIndex);
266 
267  TrimStringEx(szValue);
268  TrimSpaceEdge(szValue);
269  ExtractParam(szValue, param, 3);
270  lpParam->fShapeLength[nSubIndex - 1][_X] = param[0];
271  lpParam->fShapeLength[nSubIndex - 1][_Y] = param[1];
272  lpParam->fShapeLength[nSubIndex - 1][_Z] = param[2];
273  lpParam->nSubDomainNumber = nSubIndex - 1;
274  }
275  break;
276  case 2:
277  {
278  unsigned int nSubIndex = ExtractOptionIndex(pszOption, nHash, nOptIndex);
279 
280  TrimString(szValue);
281  strcpy(lpParam->szShape[nSubIndex - 1], szValue);
282  if (!strcmp(lpParam->szShape[nSubIndex - 1], "Box"))
283  lpParam->nShape[nSubIndex - 1] = BOX_SHAPE;
284  else if (!strcmp(lpParam->szShape[nSubIndex - 1], "Cylinder"))
285  lpParam->nShape[nSubIndex - 1] = CYLINDER_SHAPE;
286  break;
287  }
288  case 3:
289  {
290  unsigned int nSubIndex = ExtractOptionIndex(pszOption, nHash, nOptIndex);
291 
292  TrimString(szValue);
293  strcpy(lpParam->szDomainMat[nSubIndex - 1], szValue);
294  break;
295  }
296  }
297  break;
298  case 10:
299  switch (nOptIndex)
300  {
301  case 0:
302  lpParam->fKPoints = atoi(szValue);
303  break;
304  case 1:
305  {
306  double param[2];
307  TrimStringEx(szValue);
308  TrimSpaceEdge(szValue);
309  ExtractParam(szValue, param, 2);
310  lpParam->fKValueInit[0] = param[0];
311  lpParam->fKValueFinal[0] = param[1];
312  }
313  break;
314  case 2:
315  {
316  double param[2];
317  TrimStringEx(szValue);
318  TrimSpaceEdge(szValue);
319  ExtractParam(szValue, param, 2);
320  lpParam->fKValueInit[1] = param[0];
321  lpParam->fKValueFinal[1] = param[1];
322  }
323  break;
324  case 3:
325  {
326  double param[2];
327  TrimStringEx(szValue);
328  TrimSpaceEdge(szValue);
329  ExtractParam(szValue, param, 2);
330  lpParam->fKValueInit[2] = param[0];
331  lpParam->fKValueFinal[2] = param[1];
332  }
333  break;
334  }
335  break;
336  case 11:
337  switch (nOptIndex)
338  {
339  case 0:
340  lpParam->load_in_MIC = atof(szValue);
341  break;
342  }
343  break;
344  case 12:
345  switch (nOptIndex)
346  {
347  case 0:
348  TrimString(szValue);
349  strcpy(lpParam->szDataFileName, szValue);
350  break;
351  case 1:
352  lpParam->nMatrixDemension = atoi(szValue);
353  break;
354  case 2:
355  lpParam->nLanczosIterationCount = atoi(szValue);
356  break;
357  case 3:
358  lpParam->nMPILevel = atoi(szValue);
359  break;
360  }
361  break;
362  case 13:
363  switch (nOptIndex)
364  {
365  case 0:
366  lpParam->nMatrixNonzeroElementCount = atoi(szValue);
367  break;
368  }
369  break;
370  case 15:
371  switch (nOptIndex)
372  {
373  case 0:
374  {
375  double param[3];
376 
377  TrimStringEx(szValue);
378  TrimSpaceEdge(szValue);
379  ExtractParam(szValue, param, 3);
380  lpParam->bConsiderBoundaryCondition[_X] = param[0] == 1. ? true : false;
381  lpParam->bConsiderBoundaryCondition[_Y] = param[1] == 1. ? true : false;
382  lpParam->bConsiderBoundaryCondition[_Z] = param[2] == 1. ? true : false;
383  }
384  break;
385  }
386  break;
387  case 17:
388  switch (nOptIndex)
389  {
390  case 0:
391  lpParam->bDoSelectiveReorthogonalization = atoi(szValue) == 1 ? true : false;
392  break;
393  }
394  break;
395  case 18:
396  switch (nOptIndex)
397  {
398  case 0:
399  lpParam->bSortBeforeCSRBuilding = atoi(szValue) == 1 ? true : false;
400  break;
401  case 1:
402  lpParam->bSaveMapFile = atoi(szValue) == 1 ? true : false;
403  break;
404  case 2:
405  lpParam->bSaveHamiltonian = atoi(szValue) == 1 ? true : false;
406  break;
407  case 3:
408  TrimString(szValue);
409  strcpy(lpParam->szStructureType, szValue);
410  break;
411  }
412  break;
413  case 20:
414  switch (nOptIndex)
415  {
416  case 0:
417  lpParam->bUsingCubeModel = atoi(szValue) == 1 ? true : false;
418  if ( lpParam->bUsingCubeModel )
419  lpParam->bNeedRotate = false;
420  break;
421  }
422  case 22:
423  switch (nOptIndex)
424  {
425  case 0:
426  lpParam->bCalculateWaveFunction = atoi(szValue) == 1 ? true : false;
427  break;
428  }
429  break;
430  }
431 
432 }
#define CYLINDER_SHAPE
Definition: CKNGlobal.h:89
static void TrimStringEx(char *pszBuffer)
Trim string using white spapce not including ' '.
static void GetValueAfterEqualString(char *pszOption, char *pszValue)
Extracting string after equal charater postion.
static unsigned int ExtractOptionIndex(char *pszBuffer, int nHash, int nOptIndex)
Get Number of Index. ex) Geometry_Origin(1)=[ 0 0 0 ], -> Get '1' from option string.
Definition: CKNGlobal.h:105
static void ExtractParam(char *pszBuffer, double *pParam, int nParamSize)
Extracing paramter in string.
Definition: CKNGlobal.h:105
Definition: CKNGlobal.h:105
#define BOX_SHAPE
Definition: CKNGlobal.h:88
static void TrimSpaceEdge(char *pszBuffer)
Trim space both side of string.
static void TrimString(char *pszBuffer)
Trim string using white spapce including ' '.

Here is the call graph for this function:

Here is the caller graph for this function:

void CKNCommandFileParser::TrimSpaceEdge ( char *  pszBuffer)
staticprivate

Trim space both side of string.

Parameters
pszBufferString buffer that want to trim

Definition at line 97 of file KNCommandFileParser.cpp.

Referenced by SetOptionParam().

98 {
99  char szTemp[1024], ch;
100  int i, nIndex, nLength = strlen(pszBuffer);
101 
102  nIndex = 0;
103  for (i = 0; i < nLength; ++i)
104  {
105  ch = pszBuffer[i];
106  if (' ' != ch)
107  break;
108  }
109 
110  for (; i < nLength; ++i)
111  {
112  ch = pszBuffer[i];
113  szTemp[nIndex++] = pszBuffer[i];
114  }
115 
116  szTemp[nIndex] = NULL;
117  strcpy(pszBuffer, szTemp);
118 }

Here is the caller graph for this function:

void CKNCommandFileParser::TrimString ( char *  pszBuffer)
staticprivate

Trim string using white spapce including ' '.

Parameters
pszBufferString buffer that want to trim

Definition at line 59 of file KNCommandFileParser.cpp.

Referenced by SetOptionParam().

60 {
61  char szTemp[1024], ch;
62  int i, nIndex, nLength = strlen(pszBuffer);
63 
64  nIndex = 0;
65  for (i = 0; i < nLength; ++i)
66  {
67  ch = pszBuffer[i];
68  if (' ' != ch && '\r' != ch && '\n' != ch && '\t' != ch && '[' != ch && ']' != ch)
69  szTemp[nIndex++] = pszBuffer[i];
70  }
71  szTemp[nIndex] = NULL;
72  strcpy(pszBuffer, szTemp);
73 }

Here is the caller graph for this function:

void CKNCommandFileParser::TrimStringEx ( char *  pszBuffer)
staticprivate

Trim string using white spapce not including ' '.

Parameters
pszBufferString buffer that want to trim

Definition at line 78 of file KNCommandFileParser.cpp.

Referenced by SetOptionParam().

79 {
80  char szTemp[1024], ch;
81  int i, nIndex, nLength = strlen(pszBuffer);
82 
83  nIndex = 0;
84  for (i = 0; i < nLength; ++i)
85  {
86  ch = pszBuffer[i];
87  if ('\r' != ch && '\n' != ch && '\t' != ch && '[' != ch && ']' != ch)
88  szTemp[nIndex++] = pszBuffer[i];
89  }
90  szTemp[nIndex] = NULL;
91  strcpy(pszBuffer, szTemp);
92 }

Here is the caller graph for this function:


The documentation for this class was generated from the following files: