numRemainingArgs

For developers writing C++, Fortran, Java, code who have questions or comments to make.

Moderators: silvia, selimgunay, Moderators

Post Reply
tangzhen
Posts: 30
Joined: Thu May 30, 2013 4:58 am
Location: HIT

numRemainingArgs

Post by tangzhen »

i have some problems understanding the SRC below, could someone give a detailed explaination.thanks.
OPS_Export void *
OPS_NewTrussElement()
{
Element *theElement = 0;

int numRemainingArgs = OPS_GetNumRemainingInputArgs();

if (numRemainingArgs < 4) {
opserr << "Invalid Args want: element Truss $tag $iNode $jNode $sectTag <-rho $rho> <-rayleigh $flag>\n";
opserr << " or: element Truss $tag $iNode $jNode $A $matTag <-rho $rho> <-rayleig $flagh>\n";
return 0;
}

if (numRemainingArgs == 4 || numRemainingArgs == 6 || numRemainingArgs ==8)
return 0; // it's a TrussSection

int iData[3];
double A = 0.0;
double rho = 0.0;
int matTag = 0;
int doRayleigh = 0;
int ndm = OPS_GetNDM();

int numData = 3;
if (OPS_GetInt(&numData, iData) != 0) {
opserr << "WARNING invalid integer (tag, iNode, jNode) in element Truss " << endln;
return 0;
}

numData = 1;
if (OPS_GetDouble(&numData, &A) != 0) {
opserr << "WARNING: Invalid A: element Truss " << iData[0] <<
" $iNode $jNode $A $matTag <-rho $rho> <-rayleig $flagh>\n";
return 0;
}

numData = 1;
if (OPS_GetInt(&numData, &matTag) != 0) {
opserr << "WARNING: Invalid matTag: element Truss " << iData[0] <<
" $iNode $jNode $A $matTag <-rho $rho> <-rayleig $flagh>\n";
return 0;
}

UniaxialMaterial *theUniaxialMaterial = OPS_GetUniaxialMaterial(matTag);

if (theUniaxialMaterial == 0) {
opserr << "WARNING: Invalid material not found element Truss " << iData[0] << " $iNode $jNode $A " <<
matTag << " <-rho $rho> <-rayleig $flagh>\n";
return 0;
}

numRemainingArgs -= 5;
while (numRemainingArgs > 1) {
char argvS[15];
if (OPS_GetString(argvS, 15) != 0) {
opserr << "WARNING: Invalid optional string element Truss " << iData[0] <<
" $iNode $jNode $A $matTag <-rho $rho> <-doRayleigh $flagh>\n";
return 0;
}

if (strcmp(argvS,"-rho") == 0) {
numData = 1;
if (OPS_GetDouble(&numData, &rho) != 0) {
opserr << "WARNING Invalid rho in element Truss " << iData[0] <<
" $iNode $jNode $A $matTag <-rho $rho> <-doRayleigh $flagh>\n";
return 0;
}
} else if (strcmp(argvS,"-doRayleigh") == 0) {
numData = 1;
if (OPS_GetInt(&numData, &doRayleigh) != 0) {
opserr << "WARNING: Invalid doRayleigh in element Truss " << iData[0] <<
" $iNode $jNode $A $matTag <-rho $rho> <-doRayleigh $flagh>\n";
return 0;
}
} else {
opserr << "WARNING: Invalid option " << argvS << " in: element Truss " << iData[0] <<
" $iNode $jNode $A $matTag <-rho $rho> <-doRayleigh $flagh>\n";
return 0;
}
numRemainingArgs -= 2;
}

//now create the ReinforcedConcretePlaneStress
theElement = new Truss(iData[0], ndm, iData[1], iData[2], *theUniaxialMaterial, A, rho, doRayleigh);

if (theElement == 0) {
opserr << "WARNING: out of memory: element Truss " << iData[0] <<
" $iNode $jNode $A $matTag <-rho $rho> <-doRayleigh $flagh>\n";
}

return theElement;
}
fmk
Site Admin
Posts: 5884
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: numRemainingArgs

Post by fmk »

the function parses the input line for the args and returns either a new elemenet or 0.

it uses a number of functions to parse the input line:
OPS_GetNumRemaingArgs - returns the number of args on the command line that have not been parsed
OPS_GetInt(&numData, iData) - will obtain the next numData integer args from the line and place them i nan integer array iData
OPS_GetDouble() - does the same thing just with doubles.
OPS_GetString() - returns a string.
OPS_GetUniaxialMaterial(matTag) - returns a pointer to a UnixaialMaterial that has been defines, if not defined returns 0.

knowing these, and if you understand C++, the code is painfully obvious in what it does.
Post Reply