NOTE: In this example, a code for the program will be developed in C. Nevertheless, any programming language may be used.
The code of the program that calculates the center of mass (cmas2d.c) is as follows:
See the file exec/cmas2d.c for the complete source code or the procedures input, calculate and output.The cmas2d.c file
Code Block | ||
---|---|---|
| ||
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <math.h> #define MAXMAT 1000 #define MAXCND 1000 char projname[1024]; int i, ielem, inod, icnd; double *x, *y; int *N, *imat; int nodc[MAXCND]; double rho[MAXMAT], wval[MAXCND]; int Nelem, Nnod, Nmat, Ncnd; double x_CG, y_CG; void input(void); void calculate(void); void output(void); void main( int argc, char *argv[] ) { strcpy( projname, argv[1] ); input(); calculate(); output(); } |
...