Ice Sheet System Model  4.18
Code documentation
Functions
DescriptorIndex.cpp File Reference
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "../Enum/Enum.h"
#include "../io/io.h"
#include "../Exceptions/exceptions.h"

Go to the source code of this file.

Functions

int DescriptorIndex (char *root, int *pindex, char *descriptor)
 

Function Documentation

◆ DescriptorIndex()

int DescriptorIndex ( char *  root,
int *  pindex,
char *  descriptor 
)

Definition at line 20 of file DescriptorIndex.cpp.

20  { //We assume root has already been allocated, and we just have to copy into it.
21 
22  char * pch=NULL;
23 
24  /*retrieve first token, separated by underscore: */
25  pch = strtok (descriptor,"_");
26  if(!pch)_error_("descriptor " << descriptor << " is not correctly formatted!");
27 
28  if (strncmp(pch,"scaled",6)==0){
29  /*we have a scaled variable. recover the root: */
30  pch = strtok (NULL, "_");
31  if(!pch)_error_("scaled descriptor " << descriptor << " is not correctly formatted!");
32  memcpy(root,pch,(strlen(pch)+1)*sizeof(char));
33 
34  /*now recover the index if it exists: */
35  pch = strtok (NULL, "_");
36  if(!pch){
37  *pindex=-1;
38  }
39  else{
40  sscanf(pch,"%i",pindex);
41  }
42  return ScaledEnum;
43  }
44  else if (strncmp(pch,"indexed",7)==0){
45  /*we have an indexed variable. recover the root: */
46  pch = strtok (NULL, "_");
47  if(!pch)_error_("indexed descriptor " << descriptor << " is not correctly formatted!");
48  memcpy(root,pch,(strlen(pch)+1)*sizeof(char));
49  /*now recover the index: */
50  pch = strtok (NULL, "_");
51  if(!pch)_error_("indexed descriptor " << descriptor << " is not correctly formatted!");
52  sscanf(pch,"%i",pindex);
53  return IndexedEnum;
54  }
55  else if (strncmp(pch,"nodal",5)==0){
56  /*we have an indexed variable. recover the root: */
57  pch = strtok (NULL, "_");
58  if(!pch)_error_("nodal descriptor " << descriptor << " is not correctly formatted!");
59  memcpy(root,pch,(strlen(pch)+1)*sizeof(char));
60  /*now recover the index: */
61  pch = strtok (NULL, "_");
62  if(!pch)_error_("nodal descriptor " << descriptor << " is not correctly formatted!");
63  sscanf(pch,"%i",pindex);
64  return NodalEnum;
65  }
66  else{
67  /*We don't have _ in the name, this is a regular variable: */
68  memcpy(root,pch,(strlen(pch)+1)*sizeof(char));
69  *pindex=-1;
70  return RegularEnum;
71  }
72 }
ScaledEnum
@ ScaledEnum
Definition: EnumDefinitions.h:1258
RegularEnum
@ RegularEnum
Definition: EnumDefinitions.h:1238
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
IndexedEnum
@ IndexedEnum
Definition: EnumDefinitions.h:1119
NodalEnum
@ NodalEnum
Definition: EnumDefinitions.h:1198