SlideShare a Scribd company logo
>> IN THE NAME OF GOD <<
Elastic Pseudo Response Spectrum in C programming
C program is written by Salar Delavar Ghashghaei – Publication Date: 21/March/2019
E-mail: salar.d.ghashghaei@gmail.com
C code :/* Elastic Response Spectra
This is a function to generate elastic response specra including Displacement
Spectrum, Pseudo Acceleration Spectrum and Pseudo Velocity Spectrum which
are needed in "Response Spectrum Analysis" of Structures. In this function
to solve "Equation of Motions" for different periods, Newmark Linear Method
has been used.
SPEC Function Help:
INPUTS:
dt: Time Interval (Sampling Time) of Record
Ag: Ground Motion Acceleration in g
zet: Damping Ratio in percent (%); e.g. 5
g: Gravitational Constant; e.g. 9.81 m/s/s
endp: End Period of Spectra; e.g. 4 sec
OUTPUTS:
T: Period of Structures (sec)
Spa: Elastic Pseudo Acceleration Spectrum
Spv: Elastic Pseudo Velocity Spectrum
Sd: Elastic Displacement Spectrum
*/
#include <graphics.h>
#include <windows.h> // text color
#define N 10000 // number of increment
#define NN 1 // number of degree of freedom
#define Ne 1 // number of element
#define PI 3.1415926535898
#define ShowText01 "ElasticResponseSpectrum-input.csv"
#define ShowText02 "ElasticResponseSpectrum-inputACCELERATION.csv"
#define ShowText03 "ElasticResponseSpectrum-outputEXCEL.csv"
#define ShowText04 "ElasticResponseSpectrum-outputHTML.html"
#define ShowText05 "Graph-outputHTML.html"
void MessageErrorReportTEXT();
void MessageAnalysisReportTEXT();
void MessageCheckInput(int M);
void MessageInitialData(double GRAVITY,double zet,double endp);
void MessageCheck_IMPORT_DATA01(double GRAVITY,double zet,double endp);
void ANALYSIS(double t[],double Ag[],double T[],double Sd[],double Spa[],double GRAVITY,double zet,double endp,int &kn,int &STEP);
void IMPORT_GRAPH(double data[8],double DATA1[],double DATA2[],double NORMAL_DATA1[],double NORMAL_DATA2[],int n);
void GRAPHICS(double data[8],double NORMAL_DATA1[],double NORMAL_DATA2[],int n,int kind);
double ABS(double);
double MAX(double A[],int n);
double MIN(double A[],int n);
double MAX_ABS(double A[],int n);
void OUTPUT_EXCEL(double time[],double Sd[],double Spa[],int n);
void OUTPUT_html(double GRAVITY,double zet,double endp,double time[],double Sd[],double Spa[],int n);
void IMPORT_DATA01(double &GRAVITY,double &zet,double &endp);
void IMPORT_DATA02(double t[],double Ag[],double GRAVITY,int &kn);
void textcolor(int ForgC);
double MAX_ABS(double A[],int n);
void OUTPUT_HTML_GRAPH(double X[],double Y[],int n,const char text1[],const char text2[],const char text3[]);
int main(){
int i,kn,STEP;
double GRAVITY,zet,endp;
double *t = new double [N];
double *Ag = new double [N];
double *time = new double [N];
double *Sd = new double [N];
double *Spa = new double [N];
double *NORMAL_DATA1 = new double [N];
double *NORMAL_DATA2 = new double [N];
double data[8];
IMPORT_DATA01(GRAVITY,zet,endp);
IMPORT_DATA02(t,Ag,GRAVITY,kn);
MessageCheck_IMPORT_DATA01(GRAVITY,zet,endp);
textcolor(11);
MessageInitialData(GRAVITY,zet,endp);
ANALYSIS(t,Ag,time,Sd,Spa,GRAVITY,zet,endp,kn,STEP);
MessageCheckInput(kn);
OUTPUT_EXCEL(time,Sd,Spa,STEP);
OUTPUT_html(GRAVITY,zet,endp,time,Sd,Spa,STEP);
IMPORT_GRAPH(data,time,Sd,NORMAL_DATA1,NORMAL_DATA2,STEP);
GRAPHICS(data,NORMAL_DATA1,NORMAL_DATA2,STEP,0);
IMPORT_GRAPH(data,time,Spa,NORMAL_DATA1,NORMAL_DATA2,STEP);
GRAPHICS(data,NORMAL_DATA1,NORMAL_DATA2,STEP,1);
char text1[40]="Elastic Pseudo Acceleration Spectrum",text2[20]="Peroid (sec)",text3[20]="Spa (g)";
OUTPUT_HTML_GRAPH(time,Spa,STEP,text1,text2,text3);
textcolor(15);
printf("na - Output data is written in Text, Excel and Html file -");
system("start /w Graph-outputHTML.html");
free(t);free(Ag);free(time);free(Sd);free(Spa);
free(NORMAL_DATA1);free(NORMAL_DATA2);
getch();
return 0;
}
void ANALYSIS(double t[],double Ag[],double T[],double Sd[],double Spa[],double GRAVITY,double zet,double endp,int &kn,int &STEP){
double dt,m,k,c,K,a,b,df,dv,du,dac;
double *u = new double [N];
double *v = new double [N];
double *ac = new double [N];
double *omega = new double [N];
double *Sv = new double [N];
double *Sa = new double [N];
double *Spv = new double [N];
int i,j;
dt = t[2] - t[1];
STEP = endp/dt;
//Ag[end+1]=0;
T[0]=0.00;
for (j=0;j<= STEP;j++){// equation of motion(Newmark linear method)
omega[j]=2*PI/T[j]; // Natural Frequency
m=1;
k=omega[j]*omega[j]*m;
c=2*m*omega[j]*zet/100;
K=k+3*c/dt+6*m/(dt*dt);
a=6*m/dt+3*c;
b=3*m+dt*c/2;
for (i=0;i<= kn-1;i++){
u[0]=0; //initial conditions
v[0]=0;
ac[0]=0;
df=-(Ag[i+1]-Ag[i])+a*v[i]+b*ac[i]; // delta Force
du=df/K;
dv=3*du/dt-3*v[i]-dt*ac[i]/2;
dac=6*(du-dt*v[i])/(dt*dt)-3*ac[i];
u[i+1]=u[i]+du;
v[i+1]=v[i]+dv;
ac[i+1]=ac[i]+dac;
}
Sd[j] = MAX_ABS(u,kn);
//Sv[j] = MAX_ABS(v,kn);
//Sa[j] = MAX_ABS(ac,kn);
Spv[j] =Sd[j]*omega[j];
Spa[j] = Sd[j]*(omega[j]*omega[j])/GRAVITY;
T[j+1]=T[j]+dt;
//cout<<T[j]<<" "<< Spa[j]<<endl;
}
Sd[1]=0; Spv[0]=0;Spv[1]=0;Spa[0]=MAX_ABS(Ag,kn)/GRAVITY;Spa[1]=MAX_ABS(Ag,kn)/GRAVITY;
free(u);free(v);free(ac);free(omega);
free(Sv);free(Sa);free(Spv);
}
void MessageInitialData(double GRAVITY,double zet,double endp){
char Qa,Qb,Qc,Qd,Qe,Qf,Qg,Qk;
int i;Qa=201;Qb=205;Qc=187;Qd=200;Qe=188,Qf=186,Qg=204,Qk=185;
printf("tttt%c",Qa);
for (i=1;i<61;i++)
printf("%c",Qb);
printf("%cn",Qc);
printf("tttt%c >> IN THE NAME OF GOD << %cn",Qf,Qf);
printf("tttt%c Elastic Response Spectrum %cn",Qf,Qf);
printf("tttt%c",Qg);
for (i=1;i<61;i++)
printf("%c",Qb);
printf("%cn",Qk);
printf("tttt%c Unit: Free unit %cn",Qf,Qf);
printf("tttt%c Notice: All input values must be positive %cn",Qf,Qf);
printf("tttt%c",Qg);
for (i=1;i<61;i++)
printf("%c",Qb);
printf("%cn",Qk);
printf("tttt%c Program is written by Salar Delavar Ghashghaei %cn",Qf,Qf);
printf("tttt%c E-mail: salar.d.ghashghaei@gmail.com %cn",Qf,Qf);
printf("tttt%c",Qd);
for (i=1;i<61;i++)
printf("%c",Qb);
printf("%cn",Qe);
MessageAnalysisReportTEXT();
printf(" Gravitational Constant: %fn",GRAVITY);
printf(" Damping Ratio in percent (%): %fn",zet);
printf(" End Period of Spectrum (sec): %fn",endp);
}
void IMPORT_GRAPH(double data[8],double DATA1[],double DATA2[],double NORMAL_DATA1[],double NORMAL_DATA2[],int n){
double DATA1NorMin,DATA1NorMax,DATA2NorMin,DATA2NorMax,DATA1_min,DATA1_max,DATA2_min,DATA2_max;
DATA1_min=MIN(DATA1,n);
DATA1_max=MAX(DATA1,n);
DATA2_min=MIN(DATA2,n);
DATA2_max=MAX(DATA2,n);
for (int i=1;i<n;i++){
NORMAL_DATA1[i]=DATA1[i]/(DATA1_max-DATA1_min); // Normalize DATA1
NORMAL_DATA2[i]=DATA2[i]/(DATA2_max-DATA2_min); // Normalize DATA2
}
DATA1NorMin=MIN(NORMAL_DATA1,n);//Minimum Normalize DATA1
DATA2NorMin=MIN(NORMAL_DATA2,n);//Minimum Normalize DATA2
DATA1NorMax=MAX(NORMAL_DATA1,n);//Maximum Normalize DATA1
DATA2NorMax=MAX(NORMAL_DATA2,n);//Maximum Normalize DATA2
data[0]=DATA1NorMin;
data[1]=DATA1NorMax;
data[2]=DATA2NorMin;
data[3]=DATA2NorMax;
data[4]=DATA1_min;
data[5]=DATA1_max;
data[6]=DATA2_min;
data[7]=DATA2_max;
}
void GRAPHICS(double data[8],double NORMAL_DATA1[],double NORMAL_DATA2[],int n,int kind){
double DATA1NorMin,DATA1NorMax,DATA2NorMin,DATA2NorMax,DATA1_min,DATA1_max,DATA2_min,DATA2_max;
DATA1NorMin=data[0];
DATA1NorMax=data[1];
DATA2NorMin=data[2];
DATA2NorMax=data[3];
DATA1_min=data[4];
DATA1_max=data[5];
DATA2_min=data[6];
DATA2_max=data[7];
int gd = DETECT, gm, color;
DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN);
DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN);
initwindow(screenWidth,screenHeight,"",-3,-3);// init window graphics
//initwindow(getmaxx( ),getmaxy( )); // initial window graphics
//initgraph(&gd, &gm, "C:TCBGI");
int i,j,a,x1,y1,x2,y2,Lx,Ly;
//initwindow(300, 300);
x1=95;
y1=85;
x2=x1+1250;
y2=y1+500;
Lx=x2-x1;
Ly=y2-y1;
setbkcolor(0);// set background
//setcolor(9); // color rectangle line
//setlinestyle(0,0,2);// (style,pattern,thickness)
//rectangle( x1, y1, x2,y2);
//setcolor(10);
//bar( x1, y1, x2, y2);
setlinestyle(0,0,1);// (style,pattern,thickness)
setcolor(9); // color dash line
if (DATA1NorMin < 0 && DATA1NorMax > 0){
a=y1*1/20;// Y - Coordinate Axis - 10 steps
for (i=1;i<=19;i++)
for (j=0;j<=124;j=j+2)
line(Lx*i/20 +x1,y1+j*a,Lx*i/20 +x1,y1+(j+1)*a);
a=x1*1/20; // X - Coordinate Axis - 10 steps
for (i=1;i<=19;i++)
for (j=0;j<=310;j=j+2)
line( x1+j*a,Ly*i/20 +y1,x1+(j+1)*a,Ly*i/20 +y1);
a=y1*1/5;// Y - Coordinate Axis - 5 steps
for (i=1;i<=10;i++)
line(Lx*i/10 +x1,y2,Lx*i/10 +x1,y2-a);
a=x1*1/5; // X - Coordinate Axis - 5 steps
for (i=1;i<=10;i++)
line( x1,y2-Ly*i/10,x1+a,y2-Ly*i/10);
}
else if (DATA2NorMin < 0 && DATA2NorMax > 0){
a=y1*1/20;// Y - Coordinate Axis - 10 steps
for (i=1;i<=19;i++)
for (j=0;j<=124;j=j+2)
line(Lx*i/20 +x1,y1+j*a,Lx*i/20 +x1,y1+(j+1)*a);
a=x1*1/20; // X - Coordinate Axis - 10 steps
for (i=1;i<=19;i++)
for (j=0;j<=310;j=j+2)
line( x1+j*a,Ly*i/20 +y1,x1+(j+1)*a,Ly*i/20 +y1);
a=y1*1/5;// Y - Coordinate Axis - 5 steps
for (i=1;i<=10;i++)
line(Lx*i/10 +x1,y2,Lx*i/10 +x1,y2-a);
a=x1*1/5; // X - Coordinate Axis - 5 steps
for (i=1;i<=10;i++)
line( x1,y2-Ly*i/10,x1+a,y2-Ly*i/10);
}
else{
a=y1*1/20;// Y - Coordinate Axis - 10 steps
for (i=1;i<=9;i++)
for (j=0;j<=120;j=j+2)
line(Lx*i/10 +x1,y1+j*a,Lx*i/10 +x1,y1+(j+1)*a);
a=x1*1/20; // X - Coordinate Axis - 10 steps
for (i=1;i<=9;i++)
for (j=0;j<=310;j=j+2)
line( x1+j*a,Ly*i/10 +y1,x1+(j+1)*a,Ly*i/10 +y1);
a=y1*1/5;// Y - Middle Coordinate Axis - 5 steps
for (i=1;i<=19;i++)
line(Lx*i/20 +x1,y2,Lx*i/20 +x1,y2-a);
a=x1*1/5; // X - Middle Coordinate Axis - 5 steps
for (i=1;i<=19;i++)
line( x1,y2-Ly*i/20,x1+a,y2-Ly*i/20);
a=y1*1/10;// Y - Middle Coordinate Axis - 100 steps
for (i=1;i<=99;i++)
line(Lx*i/100 +x1,y2,Lx*i/100 +x1,y2-a);
a=x1*1/7; // X - Middle Coordinate Axis - 100 steps
for (i=1;i<=99;i++)
line( x1,y2-Ly*i/100,x1+a,y2-Ly*i/100);
}
//cleardevice();
setcolor(WHITE);// set text color
if (kind == 0){
settextstyle(1, 0, 5);settextjustify(10, 5);
outtextxy(x2/2 -400,25,"Elastic Displacement Spectrum");// print text in window subtitle
settextstyle(1, 1, 1);settextjustify(10, 5);
outtextxy(x1/10 -10,.5*Ly+y1,"Sd");// print text in window graphics y
}
else if(kind == 1){
settextstyle(1, 0, 5);settextjustify(10, 5);
outtextxy(x2/2 -500,25,"Elastic Pseudo Acceleration Spectrum");// print text in window subtitle
settextstyle(1, 1, 1);settextjustify(10, 5);
outtextxy(x1/10 -10,.6*Ly+y1,"Spa (g)");// print text in window graphics y
}
settextjustify(50, 5);settextstyle(1, 0, 1);
outtextxy(x2/2 -10,y2 +50,"Peroid (sec)");// print text in window graphics x
char bufferX[10][100],bufferY[10][100];
double dXdata,dYdata;
settextstyle(-1, 0,-3);settextjustify(10, 5);
sprintf(bufferX[1], "%.3e" , DATA1_min);
outtextxy(x1-45,y2+10,bufferX[1]);// print text in window graphic x axis point
sprintf(bufferX[1], "%.3e" , DATA2_min);
outtextxy(x1-69,y2 -5,bufferX[1]);// print text in window graphic y axis point
for (i=1;i<=10;i++){
dXdata = DATA1_min + 0.1*i*(DATA1_max - DATA1_min);
if (ABS(dXdata) <= 1e-20) dXdata = 0.0; // if number is very low, got it zero
sprintf(bufferX[i], "%.3e" ,dXdata);
outtextxy(x1+Lx*i*.1-45,y2+10,bufferX[i]);// print text in window graphic x axis point -> max
}
for (i=1;i<=10;i++){
dYdata = DATA2_min + 0.1*i*(DATA2_max - DATA2_min);
if (ABS(dYdata) <= 1e-20) dYdata = 0.0; // if number is very low, got it zero
sprintf(bufferY[i], "%.3e" , dYdata);
outtextxy(x1-69,y2-Ly*i*.1 -5,bufferY[i]);// print text in window graphic y axis point -> max
}
double *X = new double [N];
double *Y = new double [N];
//Absolute data
double DATA1NorMin_Abs,DATA2NorMin_Abs;
DATA1NorMin_Abs=ABS(DATA1NorMin);DATA2NorMin_Abs=ABS(DATA2NorMin);
/*
setcolor(9);
setlinestyle(0,0,2);// (style,pattern,thickness)
line(Lx*(DATA1NorMin_Abs/(DATA1NorMax-DATA1NorMin)) +x1,y1,Lx*(DATA1NorMin_Abs/(DATA1NorMax-DATA1NorMin)) +x1,y2); //Middle axis -X
line(x1,y2-Ly*(DATA2NorMin_Abs/(DATA2NorMax-DATA2NorMin)),x2,y2-Ly*(DATA2NorMin_Abs/(DATA2NorMax-DATA2NorMin))); // Middle axis -Y
*/
if (DATA2NorMin < 0 && DATA2NorMax > 0 && DATA1NorMin >= 0)
X[0]=x2,Y[0]=y2;//First point
else if (DATA2NorMin <= 0 && DATA2NorMax <= 0)
X[0]=x2,Y[0]=y2;//First point
else
X[0]=x1,Y[0]= y2-Ly*(NORMAL_DATA2[1]/(DATA2NorMax-DATA2NorMin));//First point
// Draw line
setcolor(YELLOW);
setlinestyle(0,0,2);// (style,pattern,thickness)
for (i=1;i<=n-1;i++){
NORMAL_DATA1[i] = NORMAL_DATA1[i] + DATA1NorMin_Abs;//Absolute DATA1
NORMAL_DATA2[i] = NORMAL_DATA2[i] + DATA2NorMin_Abs;//Absolute DATA2
X[i] = x1+Lx*(NORMAL_DATA1[i]/(DATA1NorMax-DATA1NorMin));
Y[i] = y2-Ly*(NORMAL_DATA2[i]/(DATA2NorMax-DATA2NorMin));
line(X[i-1],Y[i-1],X[i],Y[i]);
}
// Covering error ;-)
setcolor(9);
settextstyle(1, 0,1);
rectangle( x1, y1, x2,y2);
/*
// Middle axis
double dXdata_abs,dYdata_abs;
int Ix,Iy;
if (DATA1NorMin < 0 && DATA1NorMax > 0)
for (i=1;i<=10;i++)
{
dXdata = DATA1_min + 0.1*i*(DATA1_max - DATA1_min);//cout<<dXdata<<endl;
if (dXdata > 0 && dXdata < .00001)
Ix=i;//cout<<"Ix: "<<Ix<<endl;
}
line(Lx*Ix/10 +x1,y1,Lx*Ix/10 +x1,y2);
if (DATA2NorMin < 0 && DATA2NorMax > 0)
for (i=1;i<=10;i++)
{
dYdata = DATA2_min + 0.1*i*(DATA2_max - DATA2_min);//cout<<dYdata<<endl;
if (dYdata > 0 && dYdata < .00001)
Iy=i;//cout<<"Iy: "<<Iy<<endl;
}
line(x1,Ly*Iy/10 +y1,x2,Ly*Iy/10 +y1);
*/
/* Box text */
/*
setcolor(9);
settextstyle(1, 0,1);
rectangle( x1+350, y2+50, x1+900,y2+80);
setlinestyle(1,0,3);settextjustify(10, 5);// (style,pattern,thickness)
outtextxy(x1+355,y2+55,"Analysis");// print text in box
setlinestyle(1,0,3);settextjustify(10, 5);// (style,pattern,thickness)
outtextxy(x1+620,y2+55,"Bilinear");// print text in box
setcolor(YELLOW);line(x1+500,y2+65,x1+600,y2+65);
setcolor(10);line(x1+765,y2+65,x1+850,y2+65);
*/
getch();
closegraph();
}
double ABS(double B){
double B_abs;
if (B < 0)
B_abs = -B;//Absolute number
else
B_abs = B;
return B_abs;
}
double MIN(double A[],int n){
int i;
double Amin;
Amin = A[0];
for (i=1;i<n;i++){
if (Amin > A[i])
Amin=A[i];
}
return Amin;//Minimum DATA
}
double MAX(double A[],int n){
int i;
double Amax;
Amax = A[0];
for (i=1;i<n;i++){
if (Amax < A[i])
Amax=A[i];
}
return Amax;//Maximum DATA
}
void MessageErrorReportTEXT(){
int i;
char Ql;
Ql=176;
textcolor(12);
printf("an ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf(" Error Report ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf("n");
}
void OUTPUT_EXCEL(double time[],double Sd[],double Spa[],int n){
// EXCEL OUTPUT
int i;
FILE *OutputFile;
OutputFile = fopen(ShowText03, "w");
fprintf(OutputFile," ### Output Elastic Response Spectrum ###n");
fprintf(OutputFile,"Step,Time,Spectral Displacement,Pseudo Acceleration Spectrumn");
for(i=0;i<n;i++)
fprintf(OutputFile,"%d,%f,%f,%fn",i+1,time[i],Sd[i],Spa[i]);
fclose(OutputFile);
}
void OUTPUT_html(double GRAVITY,double zet,double endp,double time[],double Sd[],double Spa[],int n){
// HTML OUTPUT
int i;
FILE *OutputFile;
OutputFile = fopen(ShowText04, "w");
fprintf(OutputFile,"<html> <body bgcolor="green">n");
// TOP TITLE oF HTML FILE
fprintf(OutputFile,"<table style=”width:100%” border="2px" width="1000px" height="120px" bgcolor="yellow">n");
fprintf(OutputFile,"<th bgcolor="cyan"> Elastic Response Spectrum - Output Report </th> n");
// TABLE 1
fprintf(OutputFile,"<table style=”width:100%” border="1px" width="1000px" height="120px" bgcolor="yellow">n");
fprintf(OutputFile,"<th colspan="2" bgcolor="orange"> Input Data </th> n");
fprintf(OutputFile,"<tr> <th bgcolor="orange"> Gravitational Constant: </th><th> %.3e </th></tr>n",GRAVITY);
fprintf(OutputFile,"<tr> <th bgcolor="orange"> Damping Ratio in percent (%): </th><th> %.3e </th></tr>n",zet);
fprintf(OutputFile,"<tr> <th bgcolor="orange"> End Period of Spectrum (sec): </th><th> %.3e </th></tr>n",endp);
// TABLE 2
fprintf(OutputFile,"<table style=”width:100%” border="1px" width="1000px" height="120px" bgcolor="yellow">n");
fprintf(OutputFile,"<th colspan="4" bgcolor="orange"> Displacement and Pseudo Acceleration Spectrum</th> n");
fprintf(OutputFile,"<tr> <th bgcolor="orange"> Step </th><th bgcolor="orange"> Time(Period) </th> <th bgcolor="orange"> Spectral Displacement </th> <th bgcolor="orange"> Pseudo Acceleration Spectrum </th></tr>n");
for(i=0;i<n;i++){
fprintf(OutputFile,"<tr> <td align ="center"> %d </td> <td align ="center"> %.3e </td> <td align ="center"> %.3e </td> <td align ="center"> %.3e </td></tr>n",i+1,time[i],Sd[i],Spa[i]);
}
fprintf(OutputFile,"</table></body></html>n");
fclose(OutputFile);
}
void MessageCheckInput(int M){
if (M>N || M<2){
MessageErrorReportTEXT();
printf(" Please check this file! -> [ ElasticResponseSpectrum-inputACCELERATION.csv ]n");
printf(" Number of data : %d - Minimum : 3 - Maximum : 20000",M);
Sleep(40000);
exit(1);
}
}
void MessageAnalysisReportTEXT(){
int i;
char Ql=176;
printf("n ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf(" Input Data ");
for (i=1;i<50;i++)
printf("%c",Ql);
printf("n");
}
void MessageCheck_IMPORT_DATA01(double GRAVITY,double zet,double endp){
if ( GRAVITY < 0 || zet < 0 || endp< 0 ){
MessageErrorReportTEXT();
printf(" Please check this file! -> [%s]n",ShowText01);
printf(" *** Negative data input value is not acceptable ***n");
printf(" Gravitational Constant: %f",GRAVITY);
printf(" Damping Ratio in percent (%): %f",zet);
printf(" End Period of Spectrum (sec): %f",endp);
Sleep(40000);
exit(1);
}
}
/*
void IMPORT_DATA01(double &GRAVITY,double &zet,double &endp){
ifstream IN1;IN1.open("ElasticResponseSpectrum-input.csv");
IN1>>GRAVITY>>zet>>endp;
IN1.close();
}
void IMPORT_DATA02(double t[],double Ag[],double GRAVITY,int &kn){
double Time,Acceleration,dt;char CHAR;
int i=0;
ifstream IN2;IN2.open("ElasticResponseSpectrum-inputACCELERATION.csv");//import strain-stress of elements
while(IN2 >> Time >> CHAR >> Acceleration){
t[i]=Time;Ag[i]=Acceleration*GRAVITY;
//cout<<"t["<<i<<"]:"<<t[i]<<" - Ag["<<i<<"]:"<<Ag[i]<<endl;
i++;
}
kn=i;
IN2.close();
}
*/
void IMPORT_DATA01(double &GRAVITY,double &zet,double &endp){
int i=0;
double AA[3];
FILE *InputFile;
InputFile = fopen(ShowText01, "r");
if (!InputFile){
MessageErrorReportTEXT();
printf(" File is not available! -> [%s] n",ShowText01);
}
char line[100],a[100];
while(i < N && fgets(line,sizeof(line),InputFile) != NULL){
sscanf(line,"%s",a);
//printf("a[%d]: %sn",i,a);
AA[i]= atof(a);
i++;
}
GRAVITY=AA[0];zet=AA[1];endp=AA[2];
}
void IMPORT_DATA02(double t[],double Ag[],double GRAVITY,int &kn){
int i = 0;
FILE *InputFile;
InputFile = fopen(ShowText02, "r");
if (!InputFile){
MessageErrorReportTEXT();
printf(" File is not available! -> [%s] n",ShowText02);
exit(1);
}
char line[1000];
double Time,Acceleration;
do{
fscanf(InputFile,"%lf,%lf",&Time,&Acceleration);
t[i]=Time;Ag[i]=Acceleration*GRAVITY;
//printf("%d - t[%d]: %lf - Ag[%d]: %lfn",i,i,t[i],i,Ag[i]);
i++;
}
while(i < N && fgets(line,sizeof(line),InputFile) != NULL);
kn = i;
}
void textcolor(int ForgC){
WORD wColor;
//This handle is needed to get the current background attribute
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
//csbi is used for wAttributes word
if(GetConsoleScreenBufferInfo(hStdOut, &csbi)){
//To mask out all but the background attribute, and to add the color
wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
SetConsoleTextAttribute(hStdOut, wColor);
}
return;
}
double MAX_ABS(double A[],int n){
int i;
double B[N];
double Amax;
// abs value
for (i=0;i<n;i++){
B[i] = A[i];
if(B[i] < 0)
B[i] = -B[i];
}
// Max of abs
Amax = B[0];
for (i=1;i<n;i++){
if(Amax < B[i])
Amax = B[i];
}
return Amax;
}
void OUTPUT_HTML_GRAPH(double X[],double Y[],int n,const char text1[],const char text2[],const char text3[]){
// HTML GRAPH OUTPUT
int i;
double x,y,NorX[N],NorY[N],Xmax,Ymax;
Xmax=MAX_ABS(X,n);
Ymax=MAX_ABS(Y,n);
for (i=0;i<n;i++){
NorX[i] = X[i]/Xmax;
NorY[i] = Y[i]/Ymax;
//printf("t %f %f n",NorX[i],NorY[i]);
}
FILE *OutputFile;
OutputFile = fopen(ShowText05, "w");
fprintf(OutputFile,"<!DOCTYPE HTML><html><body style="background-color:black;"><font color="white"><head><script> n");
fprintf(OutputFile,"window.onload = function(){ n");
fprintf(OutputFile,"var canvas = document.getElementById("myCanvas");var s1 = canvas.getContext("2d");var s2 = canvas.getContext('2d'); n");
fprintf(OutputFile,"var s3 = canvas.getContext("2d");var s4 = canvas.getContext("2d");var s5 = canvas.getContext("2d"); n");
fprintf(OutputFile,"var x=120,y=80,X,Y,Lx=1100,Ly=500,i; n");
fprintf(OutputFile,"s3.beginPath();s3.lineWidth = 3;s3.strokeStyle = "cyan";s3.rect(x,y,Lx,Ly); n");
fprintf(OutputFile,"for(i=0;i<9;i++){s3.moveTo(x+Lx*(i+1)*.1,y+Ly);s3.lineTo(x+Lx*(i+1)*.1,y+Ly-10);}; n");
fprintf(OutputFile,"for(i=0;i<9;i++){s3.moveTo(x,y+Ly*(i+1)*.1);s3.lineTo(x+10,y+Ly*(i+1)*.1);};s3.stroke();n");
fprintf(OutputFile,"s1.beginPath();s1.lineWidth = 3;s1.strokeStyle = "yellow"; n");
for (i=0;i<n-1;i++){
fprintf(OutputFile,"s1.moveTo(%f,%f);",120+NorX[i]*1100,80+500-NorY[i]*500);
fprintf(OutputFile,"s1.lineTo(%f,%f); n",120+NorX[i+1]*1100,80+500-NorY[i+1]*500);
}
fprintf(OutputFile,"s1.stroke(); n");
fprintf(OutputFile,"s2.beginPath();s2.lineWidth = 1;s2.strokeStyle = "cyan";s2.setLineDash([5, 5]); n");
fprintf(OutputFile,"for(i=0;i<19;i++){s2.moveTo(x+Lx*(i+1)*.05,y);s2.lineTo(x+Lx*(i+1)*.05,y+Ly);} n");
fprintf(OutputFile,"s2.lineWidth = 1;s2.strokeStyle = "cyan";for(i=0;i<19;i++){s2.moveTo(x,y+Ly*(i+1)*.05);s2.lineTo(x+Lx,y+Ly*(i+1)*.05);} s2.stroke();n");
fprintf(OutputFile,"X=x+.25*Lx;Y=.7*y;s4.translate(X,Y);s4.font="50px serif";s4.fillStyle = "#7fff00";s4.fillText("%s",0,0); n",text1);
fprintf(OutputFile,"s4.save();X=-X+.2*x;Y=-Y+y+.6*Ly;s4.translate(X,Y);s4.rotate(3*Math.PI/2);s4.font="15px serif"; n");
fprintf(OutputFile,"s4.fillStyle = "#7fff00";s4.textAlign = "left";s4.fillText("%s",0,0);s4.restore(); n",text3);
fprintf(OutputFile,"s4.save();X=.2*Lx;Y=y+Ly-20;s4.translate(X,Y);s4.rotate(2*Math.PI);s4.font="15px serif";s4.fillStyle = "#7fff00"; n");
fprintf(OutputFile,"s4.textAlign = "left";s4.fillText("%s",0,0);s4.restore(); n",text2);
for(i=0;i<10;i++){
x=.1*(i+1)*Xmax;
fprintf(OutputFile,"s5.save();X=-.29*Lx+Lx*(%d+1)*.1;Y=.3*y+Ly+20;s5.rotate(2*Math.PI);s5.font="16px serif"; n",i);
fprintf(OutputFile,"s5.fillStyle = "#7fff00";s5.textAlign = "left";s5.fillText("%.3e",X,Y);s5.restore(); n",x);
}
for(i=0;i<10;i++){
y=.1*(i+1)*Ymax;
fprintf(OutputFile,"s5.save();X=-.28*Lx-50;Y=Ly+.3*y-Ly*(%d+1)*.1;s5.rotate(2*Math.PI);s5.font="16px serif"; n",i);
fprintf(OutputFile,"s5.fillStyle = "#7fff00";s5.textAlign = "left";s5.fillText("%.3e",X,Y);s5.restore(); n",y);
}
fprintf(OutputFile,"s5.save();X=-.25*Lx;Y=.3*y+Ly+20;s5.rotate(2*Math.PI);s5.font="16px serif";s5.fillStyle = "#7fff00";s5.fillText(0,X,Y);s5.restore(); n");
fprintf(OutputFile,"s5.save();X=-.25*Lx-50;Y=Ly+.3*y;s5.rotate(2*Math.PI);s5.font="16px serif";s5.fillStyle = "#7fff00";s5.textAlign = "left";s5.fillText(0,X,Y);s5.restore();}; n");
fprintf(OutputFile,"</script></head><body><canvas id="myCanvas" width="1300" height="1300" style="border:1px solid black;"></canvas></body></html> n");
fclose(OutputFile);
}
Figure(1) Input csv file
Figure(2) Input time acceleration
Figure(3) Analysis file
Figure(4) Elastic displacement spectrum
Figure(5) Elastic pseudo acceleration spectrum
Figure(6) HTML output
Figure(7) EXCEL output

More Related Content

What's hot (19)

PDF
Mining Geo-referenced Data: Location-based Services and the Sharing Economy
tnoulas
 
PPTX
Partial Homomorphic Encryption
securityxploded
 
PDF
Forward secure asynchronous messaging from puncturable encryption
National Chengchi University
 
PPTX
Dun ddd
Lyuben Todorov
 
PDF
The Ring programming language version 1.9 book - Part 78 of 210
Mahmoud Samir Fayed
 
PPTX
Apache Flink Training: DataSet API Basics
Flink Forward
 
PDF
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)
Egor Petrov
 
PDF
05 - Qt External Interaction and Graphics
Andreas Jakl
 
PDF
Time Series Analysis by JavaScript LL matsuri 2013
Daichi Morifuji
 
PDF
GeoMesa on Apache Spark SQL with Anthony Fox
Databricks
 
PPT
C++ programming
Pranav Ghildiyal
 
TXT
Procesos
PublioScipion
 
PDF
Data Analysis
Assignmentpedia
 
PDF
The Ring programming language version 1.5.4 book - Part 59 of 185
Mahmoud Samir Fayed
 
PPTX
Class 31: Deanonymizing
David Evans
 
PDF
Embracing the-power-of-refactor
Xiaojun REN
 
PDF
OpenGL L05-Texturing
Mohammad Shaker
 
Mining Geo-referenced Data: Location-based Services and the Sharing Economy
tnoulas
 
Partial Homomorphic Encryption
securityxploded
 
Forward secure asynchronous messaging from puncturable encryption
National Chengchi University
 
The Ring programming language version 1.9 book - Part 78 of 210
Mahmoud Samir Fayed
 
Apache Flink Training: DataSet API Basics
Flink Forward
 
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)
Egor Petrov
 
05 - Qt External Interaction and Graphics
Andreas Jakl
 
Time Series Analysis by JavaScript LL matsuri 2013
Daichi Morifuji
 
GeoMesa on Apache Spark SQL with Anthony Fox
Databricks
 
C++ programming
Pranav Ghildiyal
 
Procesos
PublioScipion
 
Data Analysis
Assignmentpedia
 
The Ring programming language version 1.5.4 book - Part 59 of 185
Mahmoud Samir Fayed
 
Class 31: Deanonymizing
David Evans
 
Embracing the-power-of-refactor
Xiaojun REN
 
OpenGL L05-Texturing
Mohammad Shaker
 

Similar to Elastic response pseudo spectrum in c programming (20)

DOCX
Write a Matlab code (a computerized program) for calculating plane st.docx
ajoy21
 
PDF
Pushover analysis force analogy method with force control based on timoshenko...
Salar Delavar Qashqai
 
PDF
Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Salar Delavar Qashqai
 
PDF
Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Salar Delavar Qashqai
 
PDF
Nonlinear 2nd order analysis of 2 d fixed support beam with plastic hinge con...
Salar Delavar Qashqai
 
PDF
Matlab 3
asguna
 
PDF
Pushover analysis force analogy method with force control based on euler bern...
Salar Delavar Qashqai
 
DOCX
Graphics programs
NAVYA RAO
 
DOC
Graphical representation of Stack
Sanjay Kumar Chakravarti
 
DOC
Digital Signal Processing Lab Manual
Amairullah Khan Lodhi
 
DOCX
Computer graphics
snelkoli
 
PPTX
Graphics Programming in C
Kasun Ranga Wijeweera
 
PDF
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Salar Delavar Qashqai
 
DOCX
Graphics practical lab manual
Vivek Kumar Sinha
 
PDF
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
DOCX
Polymer Brush Data Processor
Cory Bethrant
 
TXT
Senior design project code for PPG
FrankDin1
 
PPTX
Presentation
Abhinand K.V
 
PDF
Cg lab cse-v (1) (1)
Surya Sukumaran
 
PDF
Project2
?? ?
 
Write a Matlab code (a computerized program) for calculating plane st.docx
ajoy21
 
Pushover analysis force analogy method with force control based on timoshenko...
Salar Delavar Qashqai
 
Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Salar Delavar Qashqai
 
Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Salar Delavar Qashqai
 
Nonlinear 2nd order analysis of 2 d fixed support beam with plastic hinge con...
Salar Delavar Qashqai
 
Matlab 3
asguna
 
Pushover analysis force analogy method with force control based on euler bern...
Salar Delavar Qashqai
 
Graphics programs
NAVYA RAO
 
Graphical representation of Stack
Sanjay Kumar Chakravarti
 
Digital Signal Processing Lab Manual
Amairullah Khan Lodhi
 
Computer graphics
snelkoli
 
Graphics Programming in C
Kasun Ranga Wijeweera
 
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Salar Delavar Qashqai
 
Graphics practical lab manual
Vivek Kumar Sinha
 
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
Polymer Brush Data Processor
Cory Bethrant
 
Senior design project code for PPG
FrankDin1
 
Presentation
Abhinand K.V
 
Cg lab cse-v (1) (1)
Surya Sukumaran
 
Project2
?? ?
 
Ad

More from Salar Delavar Qashqai (20)

PDF
Pushover 2order (p delta effect) analysis force analogy method with force con...
Salar Delavar Qashqai
 
PDF
Pushover analysis of frame by force analogy method with force control based o...
Salar Delavar Qashqai
 
PDF
Geometric nonlinearity analysis of springs with rigid element displacement co...
Salar Delavar Qashqai
 
PDF
Nonlinear analysis of braced frame with hinge by hinge method in c programming
Salar Delavar Qashqai
 
PDF
Truss optimization with excel solver
Salar Delavar Qashqai
 
PDF
Pushover analysis of triangular steel membrane element subjected to lateral d...
Salar Delavar Qashqai
 
PDF
Pushover analysis of simply support steel section beam based on plastic hinge...
Salar Delavar Qashqai
 
PDF
Pushover analysis of steel section beam subjected to incremental vertical loa...
Salar Delavar Qashqai
 
PDF
Moment curvature analysis of unconfined concrete section with matlab and sap2000
Salar Delavar Qashqai
 
PDF
Large deformation analysis of cantilever beam subjected to concentrated const...
Salar Delavar Qashqai
 
PDF
Moment curvature analysis unconfined concrete section with different tension...
Salar Delavar Qashqai
 
PDF
Optimization of steel section based on moment and section ductility
Salar Delavar Qashqai
 
PDF
Nonlinear analysis of 2 d cantilever nonprismatic beam with plastic hinge con...
Salar Delavar Qashqai
 
PDF
Import data from csv excel file and export to xml excel file in c programming
Salar Delavar Qashqai
 
PDF
Structural eigen value analysis in c programming
Salar Delavar Qashqai
 
PDF
Analysis of 1st order and 2nd order nonlinear semi rigid connection braced fr...
Salar Delavar Qashqai
 
PDF
Analysis of 1st order and 2nd order nonlinear semi rigid connection frame sub...
Salar Delavar Qashqai
 
PDF
Moment curvature analysis confined concrete section in matlab
Salar Delavar Qashqai
 
PDF
Moment curvature analysis of unconfined circular concrete pipe section with m...
Salar Delavar Qashqai
 
PDF
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Salar Delavar Qashqai
 
Pushover 2order (p delta effect) analysis force analogy method with force con...
Salar Delavar Qashqai
 
Pushover analysis of frame by force analogy method with force control based o...
Salar Delavar Qashqai
 
Geometric nonlinearity analysis of springs with rigid element displacement co...
Salar Delavar Qashqai
 
Nonlinear analysis of braced frame with hinge by hinge method in c programming
Salar Delavar Qashqai
 
Truss optimization with excel solver
Salar Delavar Qashqai
 
Pushover analysis of triangular steel membrane element subjected to lateral d...
Salar Delavar Qashqai
 
Pushover analysis of simply support steel section beam based on plastic hinge...
Salar Delavar Qashqai
 
Pushover analysis of steel section beam subjected to incremental vertical loa...
Salar Delavar Qashqai
 
Moment curvature analysis of unconfined concrete section with matlab and sap2000
Salar Delavar Qashqai
 
Large deformation analysis of cantilever beam subjected to concentrated const...
Salar Delavar Qashqai
 
Moment curvature analysis unconfined concrete section with different tension...
Salar Delavar Qashqai
 
Optimization of steel section based on moment and section ductility
Salar Delavar Qashqai
 
Nonlinear analysis of 2 d cantilever nonprismatic beam with plastic hinge con...
Salar Delavar Qashqai
 
Import data from csv excel file and export to xml excel file in c programming
Salar Delavar Qashqai
 
Structural eigen value analysis in c programming
Salar Delavar Qashqai
 
Analysis of 1st order and 2nd order nonlinear semi rigid connection braced fr...
Salar Delavar Qashqai
 
Analysis of 1st order and 2nd order nonlinear semi rigid connection frame sub...
Salar Delavar Qashqai
 
Moment curvature analysis confined concrete section in matlab
Salar Delavar Qashqai
 
Moment curvature analysis of unconfined circular concrete pipe section with m...
Salar Delavar Qashqai
 
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Salar Delavar Qashqai
 
Ad

Recently uploaded (20)

PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PDF
smart lot access control system with eye
rasabzahra
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
MRRS Strength and Durability of Concrete
CivilMythili
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
smart lot access control system with eye
rasabzahra
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 

Elastic response pseudo spectrum in c programming

  • 1. >> IN THE NAME OF GOD << Elastic Pseudo Response Spectrum in C programming C program is written by Salar Delavar Ghashghaei – Publication Date: 21/March/2019 E-mail: [email protected]
  • 2. C code :/* Elastic Response Spectra This is a function to generate elastic response specra including Displacement Spectrum, Pseudo Acceleration Spectrum and Pseudo Velocity Spectrum which are needed in "Response Spectrum Analysis" of Structures. In this function to solve "Equation of Motions" for different periods, Newmark Linear Method has been used. SPEC Function Help: INPUTS: dt: Time Interval (Sampling Time) of Record Ag: Ground Motion Acceleration in g zet: Damping Ratio in percent (%); e.g. 5 g: Gravitational Constant; e.g. 9.81 m/s/s endp: End Period of Spectra; e.g. 4 sec OUTPUTS: T: Period of Structures (sec) Spa: Elastic Pseudo Acceleration Spectrum Spv: Elastic Pseudo Velocity Spectrum Sd: Elastic Displacement Spectrum */ #include <graphics.h> #include <windows.h> // text color #define N 10000 // number of increment #define NN 1 // number of degree of freedom #define Ne 1 // number of element #define PI 3.1415926535898 #define ShowText01 "ElasticResponseSpectrum-input.csv" #define ShowText02 "ElasticResponseSpectrum-inputACCELERATION.csv" #define ShowText03 "ElasticResponseSpectrum-outputEXCEL.csv" #define ShowText04 "ElasticResponseSpectrum-outputHTML.html" #define ShowText05 "Graph-outputHTML.html" void MessageErrorReportTEXT(); void MessageAnalysisReportTEXT(); void MessageCheckInput(int M); void MessageInitialData(double GRAVITY,double zet,double endp); void MessageCheck_IMPORT_DATA01(double GRAVITY,double zet,double endp); void ANALYSIS(double t[],double Ag[],double T[],double Sd[],double Spa[],double GRAVITY,double zet,double endp,int &kn,int &STEP); void IMPORT_GRAPH(double data[8],double DATA1[],double DATA2[],double NORMAL_DATA1[],double NORMAL_DATA2[],int n); void GRAPHICS(double data[8],double NORMAL_DATA1[],double NORMAL_DATA2[],int n,int kind); double ABS(double); double MAX(double A[],int n); double MIN(double A[],int n); double MAX_ABS(double A[],int n); void OUTPUT_EXCEL(double time[],double Sd[],double Spa[],int n); void OUTPUT_html(double GRAVITY,double zet,double endp,double time[],double Sd[],double Spa[],int n); void IMPORT_DATA01(double &GRAVITY,double &zet,double &endp); void IMPORT_DATA02(double t[],double Ag[],double GRAVITY,int &kn); void textcolor(int ForgC); double MAX_ABS(double A[],int n); void OUTPUT_HTML_GRAPH(double X[],double Y[],int n,const char text1[],const char text2[],const char text3[]); int main(){ int i,kn,STEP; double GRAVITY,zet,endp; double *t = new double [N]; double *Ag = new double [N]; double *time = new double [N]; double *Sd = new double [N]; double *Spa = new double [N]; double *NORMAL_DATA1 = new double [N]; double *NORMAL_DATA2 = new double [N]; double data[8]; IMPORT_DATA01(GRAVITY,zet,endp); IMPORT_DATA02(t,Ag,GRAVITY,kn); MessageCheck_IMPORT_DATA01(GRAVITY,zet,endp); textcolor(11); MessageInitialData(GRAVITY,zet,endp); ANALYSIS(t,Ag,time,Sd,Spa,GRAVITY,zet,endp,kn,STEP); MessageCheckInput(kn); OUTPUT_EXCEL(time,Sd,Spa,STEP); OUTPUT_html(GRAVITY,zet,endp,time,Sd,Spa,STEP); IMPORT_GRAPH(data,time,Sd,NORMAL_DATA1,NORMAL_DATA2,STEP); GRAPHICS(data,NORMAL_DATA1,NORMAL_DATA2,STEP,0); IMPORT_GRAPH(data,time,Spa,NORMAL_DATA1,NORMAL_DATA2,STEP); GRAPHICS(data,NORMAL_DATA1,NORMAL_DATA2,STEP,1); char text1[40]="Elastic Pseudo Acceleration Spectrum",text2[20]="Peroid (sec)",text3[20]="Spa (g)"; OUTPUT_HTML_GRAPH(time,Spa,STEP,text1,text2,text3); textcolor(15); printf("na - Output data is written in Text, Excel and Html file -"); system("start /w Graph-outputHTML.html"); free(t);free(Ag);free(time);free(Sd);free(Spa); free(NORMAL_DATA1);free(NORMAL_DATA2); getch(); return 0; } void ANALYSIS(double t[],double Ag[],double T[],double Sd[],double Spa[],double GRAVITY,double zet,double endp,int &kn,int &STEP){ double dt,m,k,c,K,a,b,df,dv,du,dac; double *u = new double [N]; double *v = new double [N]; double *ac = new double [N]; double *omega = new double [N]; double *Sv = new double [N]; double *Sa = new double [N]; double *Spv = new double [N]; int i,j; dt = t[2] - t[1]; STEP = endp/dt; //Ag[end+1]=0; T[0]=0.00; for (j=0;j<= STEP;j++){// equation of motion(Newmark linear method) omega[j]=2*PI/T[j]; // Natural Frequency m=1; k=omega[j]*omega[j]*m; c=2*m*omega[j]*zet/100; K=k+3*c/dt+6*m/(dt*dt); a=6*m/dt+3*c; b=3*m+dt*c/2; for (i=0;i<= kn-1;i++){ u[0]=0; //initial conditions v[0]=0; ac[0]=0; df=-(Ag[i+1]-Ag[i])+a*v[i]+b*ac[i]; // delta Force du=df/K; dv=3*du/dt-3*v[i]-dt*ac[i]/2; dac=6*(du-dt*v[i])/(dt*dt)-3*ac[i]; u[i+1]=u[i]+du; v[i+1]=v[i]+dv; ac[i+1]=ac[i]+dac; } Sd[j] = MAX_ABS(u,kn); //Sv[j] = MAX_ABS(v,kn); //Sa[j] = MAX_ABS(ac,kn); Spv[j] =Sd[j]*omega[j]; Spa[j] = Sd[j]*(omega[j]*omega[j])/GRAVITY; T[j+1]=T[j]+dt; //cout<<T[j]<<" "<< Spa[j]<<endl; } Sd[1]=0; Spv[0]=0;Spv[1]=0;Spa[0]=MAX_ABS(Ag,kn)/GRAVITY;Spa[1]=MAX_ABS(Ag,kn)/GRAVITY; free(u);free(v);free(ac);free(omega); free(Sv);free(Sa);free(Spv); } void MessageInitialData(double GRAVITY,double zet,double endp){ char Qa,Qb,Qc,Qd,Qe,Qf,Qg,Qk; int i;Qa=201;Qb=205;Qc=187;Qd=200;Qe=188,Qf=186,Qg=204,Qk=185; printf("tttt%c",Qa); for (i=1;i<61;i++) printf("%c",Qb); printf("%cn",Qc); printf("tttt%c >> IN THE NAME OF GOD << %cn",Qf,Qf); printf("tttt%c Elastic Response Spectrum %cn",Qf,Qf); printf("tttt%c",Qg); for (i=1;i<61;i++) printf("%c",Qb); printf("%cn",Qk); printf("tttt%c Unit: Free unit %cn",Qf,Qf); printf("tttt%c Notice: All input values must be positive %cn",Qf,Qf); printf("tttt%c",Qg); for (i=1;i<61;i++) printf("%c",Qb); printf("%cn",Qk); printf("tttt%c Program is written by Salar Delavar Ghashghaei %cn",Qf,Qf); printf("tttt%c E-mail: [email protected] %cn",Qf,Qf); printf("tttt%c",Qd); for (i=1;i<61;i++) printf("%c",Qb); printf("%cn",Qe); MessageAnalysisReportTEXT(); printf(" Gravitational Constant: %fn",GRAVITY); printf(" Damping Ratio in percent (%): %fn",zet); printf(" End Period of Spectrum (sec): %fn",endp); } void IMPORT_GRAPH(double data[8],double DATA1[],double DATA2[],double NORMAL_DATA1[],double NORMAL_DATA2[],int n){ double DATA1NorMin,DATA1NorMax,DATA2NorMin,DATA2NorMax,DATA1_min,DATA1_max,DATA2_min,DATA2_max; DATA1_min=MIN(DATA1,n); DATA1_max=MAX(DATA1,n); DATA2_min=MIN(DATA2,n); DATA2_max=MAX(DATA2,n); for (int i=1;i<n;i++){ NORMAL_DATA1[i]=DATA1[i]/(DATA1_max-DATA1_min); // Normalize DATA1 NORMAL_DATA2[i]=DATA2[i]/(DATA2_max-DATA2_min); // Normalize DATA2
  • 3. } DATA1NorMin=MIN(NORMAL_DATA1,n);//Minimum Normalize DATA1 DATA2NorMin=MIN(NORMAL_DATA2,n);//Minimum Normalize DATA2 DATA1NorMax=MAX(NORMAL_DATA1,n);//Maximum Normalize DATA1 DATA2NorMax=MAX(NORMAL_DATA2,n);//Maximum Normalize DATA2 data[0]=DATA1NorMin; data[1]=DATA1NorMax; data[2]=DATA2NorMin; data[3]=DATA2NorMax; data[4]=DATA1_min; data[5]=DATA1_max; data[6]=DATA2_min; data[7]=DATA2_max; } void GRAPHICS(double data[8],double NORMAL_DATA1[],double NORMAL_DATA2[],int n,int kind){ double DATA1NorMin,DATA1NorMax,DATA2NorMin,DATA2NorMax,DATA1_min,DATA1_max,DATA2_min,DATA2_max; DATA1NorMin=data[0]; DATA1NorMax=data[1]; DATA2NorMin=data[2]; DATA2NorMax=data[3]; DATA1_min=data[4]; DATA1_max=data[5]; DATA2_min=data[6]; DATA2_max=data[7]; int gd = DETECT, gm, color; DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN); DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN); initwindow(screenWidth,screenHeight,"",-3,-3);// init window graphics //initwindow(getmaxx( ),getmaxy( )); // initial window graphics //initgraph(&gd, &gm, "C:TCBGI"); int i,j,a,x1,y1,x2,y2,Lx,Ly; //initwindow(300, 300); x1=95; y1=85; x2=x1+1250; y2=y1+500; Lx=x2-x1; Ly=y2-y1; setbkcolor(0);// set background //setcolor(9); // color rectangle line //setlinestyle(0,0,2);// (style,pattern,thickness) //rectangle( x1, y1, x2,y2); //setcolor(10); //bar( x1, y1, x2, y2); setlinestyle(0,0,1);// (style,pattern,thickness) setcolor(9); // color dash line if (DATA1NorMin < 0 && DATA1NorMax > 0){ a=y1*1/20;// Y - Coordinate Axis - 10 steps for (i=1;i<=19;i++) for (j=0;j<=124;j=j+2) line(Lx*i/20 +x1,y1+j*a,Lx*i/20 +x1,y1+(j+1)*a); a=x1*1/20; // X - Coordinate Axis - 10 steps for (i=1;i<=19;i++) for (j=0;j<=310;j=j+2) line( x1+j*a,Ly*i/20 +y1,x1+(j+1)*a,Ly*i/20 +y1); a=y1*1/5;// Y - Coordinate Axis - 5 steps for (i=1;i<=10;i++) line(Lx*i/10 +x1,y2,Lx*i/10 +x1,y2-a); a=x1*1/5; // X - Coordinate Axis - 5 steps for (i=1;i<=10;i++) line( x1,y2-Ly*i/10,x1+a,y2-Ly*i/10); } else if (DATA2NorMin < 0 && DATA2NorMax > 0){ a=y1*1/20;// Y - Coordinate Axis - 10 steps for (i=1;i<=19;i++) for (j=0;j<=124;j=j+2) line(Lx*i/20 +x1,y1+j*a,Lx*i/20 +x1,y1+(j+1)*a); a=x1*1/20; // X - Coordinate Axis - 10 steps for (i=1;i<=19;i++) for (j=0;j<=310;j=j+2) line( x1+j*a,Ly*i/20 +y1,x1+(j+1)*a,Ly*i/20 +y1); a=y1*1/5;// Y - Coordinate Axis - 5 steps for (i=1;i<=10;i++) line(Lx*i/10 +x1,y2,Lx*i/10 +x1,y2-a); a=x1*1/5; // X - Coordinate Axis - 5 steps for (i=1;i<=10;i++) line( x1,y2-Ly*i/10,x1+a,y2-Ly*i/10); } else{ a=y1*1/20;// Y - Coordinate Axis - 10 steps for (i=1;i<=9;i++) for (j=0;j<=120;j=j+2) line(Lx*i/10 +x1,y1+j*a,Lx*i/10 +x1,y1+(j+1)*a); a=x1*1/20; // X - Coordinate Axis - 10 steps for (i=1;i<=9;i++) for (j=0;j<=310;j=j+2) line( x1+j*a,Ly*i/10 +y1,x1+(j+1)*a,Ly*i/10 +y1); a=y1*1/5;// Y - Middle Coordinate Axis - 5 steps for (i=1;i<=19;i++) line(Lx*i/20 +x1,y2,Lx*i/20 +x1,y2-a); a=x1*1/5; // X - Middle Coordinate Axis - 5 steps for (i=1;i<=19;i++) line( x1,y2-Ly*i/20,x1+a,y2-Ly*i/20); a=y1*1/10;// Y - Middle Coordinate Axis - 100 steps for (i=1;i<=99;i++) line(Lx*i/100 +x1,y2,Lx*i/100 +x1,y2-a); a=x1*1/7; // X - Middle Coordinate Axis - 100 steps for (i=1;i<=99;i++) line( x1,y2-Ly*i/100,x1+a,y2-Ly*i/100); } //cleardevice(); setcolor(WHITE);// set text color if (kind == 0){ settextstyle(1, 0, 5);settextjustify(10, 5); outtextxy(x2/2 -400,25,"Elastic Displacement Spectrum");// print text in window subtitle settextstyle(1, 1, 1);settextjustify(10, 5); outtextxy(x1/10 -10,.5*Ly+y1,"Sd");// print text in window graphics y } else if(kind == 1){ settextstyle(1, 0, 5);settextjustify(10, 5); outtextxy(x2/2 -500,25,"Elastic Pseudo Acceleration Spectrum");// print text in window subtitle settextstyle(1, 1, 1);settextjustify(10, 5); outtextxy(x1/10 -10,.6*Ly+y1,"Spa (g)");// print text in window graphics y } settextjustify(50, 5);settextstyle(1, 0, 1); outtextxy(x2/2 -10,y2 +50,"Peroid (sec)");// print text in window graphics x char bufferX[10][100],bufferY[10][100]; double dXdata,dYdata; settextstyle(-1, 0,-3);settextjustify(10, 5); sprintf(bufferX[1], "%.3e" , DATA1_min); outtextxy(x1-45,y2+10,bufferX[1]);// print text in window graphic x axis point sprintf(bufferX[1], "%.3e" , DATA2_min); outtextxy(x1-69,y2 -5,bufferX[1]);// print text in window graphic y axis point for (i=1;i<=10;i++){ dXdata = DATA1_min + 0.1*i*(DATA1_max - DATA1_min); if (ABS(dXdata) <= 1e-20) dXdata = 0.0; // if number is very low, got it zero sprintf(bufferX[i], "%.3e" ,dXdata); outtextxy(x1+Lx*i*.1-45,y2+10,bufferX[i]);// print text in window graphic x axis point -> max } for (i=1;i<=10;i++){ dYdata = DATA2_min + 0.1*i*(DATA2_max - DATA2_min); if (ABS(dYdata) <= 1e-20) dYdata = 0.0; // if number is very low, got it zero sprintf(bufferY[i], "%.3e" , dYdata); outtextxy(x1-69,y2-Ly*i*.1 -5,bufferY[i]);// print text in window graphic y axis point -> max } double *X = new double [N]; double *Y = new double [N]; //Absolute data double DATA1NorMin_Abs,DATA2NorMin_Abs; DATA1NorMin_Abs=ABS(DATA1NorMin);DATA2NorMin_Abs=ABS(DATA2NorMin); /* setcolor(9); setlinestyle(0,0,2);// (style,pattern,thickness) line(Lx*(DATA1NorMin_Abs/(DATA1NorMax-DATA1NorMin)) +x1,y1,Lx*(DATA1NorMin_Abs/(DATA1NorMax-DATA1NorMin)) +x1,y2); //Middle axis -X line(x1,y2-Ly*(DATA2NorMin_Abs/(DATA2NorMax-DATA2NorMin)),x2,y2-Ly*(DATA2NorMin_Abs/(DATA2NorMax-DATA2NorMin))); // Middle axis -Y */ if (DATA2NorMin < 0 && DATA2NorMax > 0 && DATA1NorMin >= 0) X[0]=x2,Y[0]=y2;//First point else if (DATA2NorMin <= 0 && DATA2NorMax <= 0) X[0]=x2,Y[0]=y2;//First point else X[0]=x1,Y[0]= y2-Ly*(NORMAL_DATA2[1]/(DATA2NorMax-DATA2NorMin));//First point // Draw line setcolor(YELLOW); setlinestyle(0,0,2);// (style,pattern,thickness) for (i=1;i<=n-1;i++){ NORMAL_DATA1[i] = NORMAL_DATA1[i] + DATA1NorMin_Abs;//Absolute DATA1 NORMAL_DATA2[i] = NORMAL_DATA2[i] + DATA2NorMin_Abs;//Absolute DATA2
  • 4. X[i] = x1+Lx*(NORMAL_DATA1[i]/(DATA1NorMax-DATA1NorMin)); Y[i] = y2-Ly*(NORMAL_DATA2[i]/(DATA2NorMax-DATA2NorMin)); line(X[i-1],Y[i-1],X[i],Y[i]); } // Covering error ;-) setcolor(9); settextstyle(1, 0,1); rectangle( x1, y1, x2,y2); /* // Middle axis double dXdata_abs,dYdata_abs; int Ix,Iy; if (DATA1NorMin < 0 && DATA1NorMax > 0) for (i=1;i<=10;i++) { dXdata = DATA1_min + 0.1*i*(DATA1_max - DATA1_min);//cout<<dXdata<<endl; if (dXdata > 0 && dXdata < .00001) Ix=i;//cout<<"Ix: "<<Ix<<endl; } line(Lx*Ix/10 +x1,y1,Lx*Ix/10 +x1,y2); if (DATA2NorMin < 0 && DATA2NorMax > 0) for (i=1;i<=10;i++) { dYdata = DATA2_min + 0.1*i*(DATA2_max - DATA2_min);//cout<<dYdata<<endl; if (dYdata > 0 && dYdata < .00001) Iy=i;//cout<<"Iy: "<<Iy<<endl; } line(x1,Ly*Iy/10 +y1,x2,Ly*Iy/10 +y1); */ /* Box text */ /* setcolor(9); settextstyle(1, 0,1); rectangle( x1+350, y2+50, x1+900,y2+80); setlinestyle(1,0,3);settextjustify(10, 5);// (style,pattern,thickness) outtextxy(x1+355,y2+55,"Analysis");// print text in box setlinestyle(1,0,3);settextjustify(10, 5);// (style,pattern,thickness) outtextxy(x1+620,y2+55,"Bilinear");// print text in box setcolor(YELLOW);line(x1+500,y2+65,x1+600,y2+65); setcolor(10);line(x1+765,y2+65,x1+850,y2+65); */ getch(); closegraph(); } double ABS(double B){ double B_abs; if (B < 0) B_abs = -B;//Absolute number else B_abs = B; return B_abs; } double MIN(double A[],int n){ int i; double Amin; Amin = A[0]; for (i=1;i<n;i++){ if (Amin > A[i]) Amin=A[i]; } return Amin;//Minimum DATA } double MAX(double A[],int n){ int i; double Amax; Amax = A[0]; for (i=1;i<n;i++){ if (Amax < A[i]) Amax=A[i]; } return Amax;//Maximum DATA } void MessageErrorReportTEXT(){ int i; char Ql; Ql=176; textcolor(12); printf("an "); for (i=1;i<50;i++) printf("%c",Ql); printf(" Error Report "); for (i=1;i<50;i++) printf("%c",Ql); printf("n"); } void OUTPUT_EXCEL(double time[],double Sd[],double Spa[],int n){ // EXCEL OUTPUT int i; FILE *OutputFile; OutputFile = fopen(ShowText03, "w"); fprintf(OutputFile," ### Output Elastic Response Spectrum ###n"); fprintf(OutputFile,"Step,Time,Spectral Displacement,Pseudo Acceleration Spectrumn"); for(i=0;i<n;i++) fprintf(OutputFile,"%d,%f,%f,%fn",i+1,time[i],Sd[i],Spa[i]); fclose(OutputFile); } void OUTPUT_html(double GRAVITY,double zet,double endp,double time[],double Sd[],double Spa[],int n){ // HTML OUTPUT int i; FILE *OutputFile; OutputFile = fopen(ShowText04, "w"); fprintf(OutputFile,"<html> <body bgcolor="green">n"); // TOP TITLE oF HTML FILE fprintf(OutputFile,"<table style=”width:100%” border="2px" width="1000px" height="120px" bgcolor="yellow">n"); fprintf(OutputFile,"<th bgcolor="cyan"> Elastic Response Spectrum - Output Report </th> n"); // TABLE 1 fprintf(OutputFile,"<table style=”width:100%” border="1px" width="1000px" height="120px" bgcolor="yellow">n"); fprintf(OutputFile,"<th colspan="2" bgcolor="orange"> Input Data </th> n"); fprintf(OutputFile,"<tr> <th bgcolor="orange"> Gravitational Constant: </th><th> %.3e </th></tr>n",GRAVITY); fprintf(OutputFile,"<tr> <th bgcolor="orange"> Damping Ratio in percent (%): </th><th> %.3e </th></tr>n",zet); fprintf(OutputFile,"<tr> <th bgcolor="orange"> End Period of Spectrum (sec): </th><th> %.3e </th></tr>n",endp); // TABLE 2 fprintf(OutputFile,"<table style=”width:100%” border="1px" width="1000px" height="120px" bgcolor="yellow">n"); fprintf(OutputFile,"<th colspan="4" bgcolor="orange"> Displacement and Pseudo Acceleration Spectrum</th> n"); fprintf(OutputFile,"<tr> <th bgcolor="orange"> Step </th><th bgcolor="orange"> Time(Period) </th> <th bgcolor="orange"> Spectral Displacement </th> <th bgcolor="orange"> Pseudo Acceleration Spectrum </th></tr>n"); for(i=0;i<n;i++){ fprintf(OutputFile,"<tr> <td align ="center"> %d </td> <td align ="center"> %.3e </td> <td align ="center"> %.3e </td> <td align ="center"> %.3e </td></tr>n",i+1,time[i],Sd[i],Spa[i]); } fprintf(OutputFile,"</table></body></html>n"); fclose(OutputFile); } void MessageCheckInput(int M){ if (M>N || M<2){ MessageErrorReportTEXT(); printf(" Please check this file! -> [ ElasticResponseSpectrum-inputACCELERATION.csv ]n"); printf(" Number of data : %d - Minimum : 3 - Maximum : 20000",M); Sleep(40000); exit(1); } } void MessageAnalysisReportTEXT(){ int i; char Ql=176; printf("n "); for (i=1;i<50;i++) printf("%c",Ql); printf(" Input Data "); for (i=1;i<50;i++) printf("%c",Ql); printf("n"); } void MessageCheck_IMPORT_DATA01(double GRAVITY,double zet,double endp){ if ( GRAVITY < 0 || zet < 0 || endp< 0 ){ MessageErrorReportTEXT(); printf(" Please check this file! -> [%s]n",ShowText01); printf(" *** Negative data input value is not acceptable ***n"); printf(" Gravitational Constant: %f",GRAVITY); printf(" Damping Ratio in percent (%): %f",zet); printf(" End Period of Spectrum (sec): %f",endp); Sleep(40000); exit(1); } } /* void IMPORT_DATA01(double &GRAVITY,double &zet,double &endp){ ifstream IN1;IN1.open("ElasticResponseSpectrum-input.csv"); IN1>>GRAVITY>>zet>>endp; IN1.close(); } void IMPORT_DATA02(double t[],double Ag[],double GRAVITY,int &kn){ double Time,Acceleration,dt;char CHAR; int i=0; ifstream IN2;IN2.open("ElasticResponseSpectrum-inputACCELERATION.csv");//import strain-stress of elements while(IN2 >> Time >> CHAR >> Acceleration){ t[i]=Time;Ag[i]=Acceleration*GRAVITY; //cout<<"t["<<i<<"]:"<<t[i]<<" - Ag["<<i<<"]:"<<Ag[i]<<endl; i++; } kn=i; IN2.close(); } */
  • 5. void IMPORT_DATA01(double &GRAVITY,double &zet,double &endp){ int i=0; double AA[3]; FILE *InputFile; InputFile = fopen(ShowText01, "r"); if (!InputFile){ MessageErrorReportTEXT(); printf(" File is not available! -> [%s] n",ShowText01); } char line[100],a[100]; while(i < N && fgets(line,sizeof(line),InputFile) != NULL){ sscanf(line,"%s",a); //printf("a[%d]: %sn",i,a); AA[i]= atof(a); i++; } GRAVITY=AA[0];zet=AA[1];endp=AA[2]; } void IMPORT_DATA02(double t[],double Ag[],double GRAVITY,int &kn){ int i = 0; FILE *InputFile; InputFile = fopen(ShowText02, "r"); if (!InputFile){ MessageErrorReportTEXT(); printf(" File is not available! -> [%s] n",ShowText02); exit(1); } char line[1000]; double Time,Acceleration; do{ fscanf(InputFile,"%lf,%lf",&Time,&Acceleration); t[i]=Time;Ag[i]=Acceleration*GRAVITY; //printf("%d - t[%d]: %lf - Ag[%d]: %lfn",i,i,t[i],i,Ag[i]); i++; } while(i < N && fgets(line,sizeof(line),InputFile) != NULL); kn = i; } void textcolor(int ForgC){ WORD wColor; //This handle is needed to get the current background attribute HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; //csbi is used for wAttributes word if(GetConsoleScreenBufferInfo(hStdOut, &csbi)){ //To mask out all but the background attribute, and to add the color wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F); SetConsoleTextAttribute(hStdOut, wColor); } return; } double MAX_ABS(double A[],int n){ int i; double B[N]; double Amax; // abs value for (i=0;i<n;i++){ B[i] = A[i]; if(B[i] < 0) B[i] = -B[i]; } // Max of abs Amax = B[0]; for (i=1;i<n;i++){ if(Amax < B[i]) Amax = B[i]; } return Amax; } void OUTPUT_HTML_GRAPH(double X[],double Y[],int n,const char text1[],const char text2[],const char text3[]){ // HTML GRAPH OUTPUT int i; double x,y,NorX[N],NorY[N],Xmax,Ymax; Xmax=MAX_ABS(X,n); Ymax=MAX_ABS(Y,n); for (i=0;i<n;i++){ NorX[i] = X[i]/Xmax; NorY[i] = Y[i]/Ymax; //printf("t %f %f n",NorX[i],NorY[i]); } FILE *OutputFile; OutputFile = fopen(ShowText05, "w"); fprintf(OutputFile,"<!DOCTYPE HTML><html><body style="background-color:black;"><font color="white"><head><script> n"); fprintf(OutputFile,"window.onload = function(){ n"); fprintf(OutputFile,"var canvas = document.getElementById("myCanvas");var s1 = canvas.getContext("2d");var s2 = canvas.getContext('2d'); n"); fprintf(OutputFile,"var s3 = canvas.getContext("2d");var s4 = canvas.getContext("2d");var s5 = canvas.getContext("2d"); n"); fprintf(OutputFile,"var x=120,y=80,X,Y,Lx=1100,Ly=500,i; n"); fprintf(OutputFile,"s3.beginPath();s3.lineWidth = 3;s3.strokeStyle = "cyan";s3.rect(x,y,Lx,Ly); n"); fprintf(OutputFile,"for(i=0;i<9;i++){s3.moveTo(x+Lx*(i+1)*.1,y+Ly);s3.lineTo(x+Lx*(i+1)*.1,y+Ly-10);}; n"); fprintf(OutputFile,"for(i=0;i<9;i++){s3.moveTo(x,y+Ly*(i+1)*.1);s3.lineTo(x+10,y+Ly*(i+1)*.1);};s3.stroke();n"); fprintf(OutputFile,"s1.beginPath();s1.lineWidth = 3;s1.strokeStyle = "yellow"; n"); for (i=0;i<n-1;i++){ fprintf(OutputFile,"s1.moveTo(%f,%f);",120+NorX[i]*1100,80+500-NorY[i]*500); fprintf(OutputFile,"s1.lineTo(%f,%f); n",120+NorX[i+1]*1100,80+500-NorY[i+1]*500); } fprintf(OutputFile,"s1.stroke(); n"); fprintf(OutputFile,"s2.beginPath();s2.lineWidth = 1;s2.strokeStyle = "cyan";s2.setLineDash([5, 5]); n"); fprintf(OutputFile,"for(i=0;i<19;i++){s2.moveTo(x+Lx*(i+1)*.05,y);s2.lineTo(x+Lx*(i+1)*.05,y+Ly);} n"); fprintf(OutputFile,"s2.lineWidth = 1;s2.strokeStyle = "cyan";for(i=0;i<19;i++){s2.moveTo(x,y+Ly*(i+1)*.05);s2.lineTo(x+Lx,y+Ly*(i+1)*.05);} s2.stroke();n"); fprintf(OutputFile,"X=x+.25*Lx;Y=.7*y;s4.translate(X,Y);s4.font="50px serif";s4.fillStyle = "#7fff00";s4.fillText("%s",0,0); n",text1); fprintf(OutputFile,"s4.save();X=-X+.2*x;Y=-Y+y+.6*Ly;s4.translate(X,Y);s4.rotate(3*Math.PI/2);s4.font="15px serif"; n"); fprintf(OutputFile,"s4.fillStyle = "#7fff00";s4.textAlign = "left";s4.fillText("%s",0,0);s4.restore(); n",text3); fprintf(OutputFile,"s4.save();X=.2*Lx;Y=y+Ly-20;s4.translate(X,Y);s4.rotate(2*Math.PI);s4.font="15px serif";s4.fillStyle = "#7fff00"; n"); fprintf(OutputFile,"s4.textAlign = "left";s4.fillText("%s",0,0);s4.restore(); n",text2); for(i=0;i<10;i++){ x=.1*(i+1)*Xmax; fprintf(OutputFile,"s5.save();X=-.29*Lx+Lx*(%d+1)*.1;Y=.3*y+Ly+20;s5.rotate(2*Math.PI);s5.font="16px serif"; n",i); fprintf(OutputFile,"s5.fillStyle = "#7fff00";s5.textAlign = "left";s5.fillText("%.3e",X,Y);s5.restore(); n",x); } for(i=0;i<10;i++){ y=.1*(i+1)*Ymax; fprintf(OutputFile,"s5.save();X=-.28*Lx-50;Y=Ly+.3*y-Ly*(%d+1)*.1;s5.rotate(2*Math.PI);s5.font="16px serif"; n",i); fprintf(OutputFile,"s5.fillStyle = "#7fff00";s5.textAlign = "left";s5.fillText("%.3e",X,Y);s5.restore(); n",y); } fprintf(OutputFile,"s5.save();X=-.25*Lx;Y=.3*y+Ly+20;s5.rotate(2*Math.PI);s5.font="16px serif";s5.fillStyle = "#7fff00";s5.fillText(0,X,Y);s5.restore(); n"); fprintf(OutputFile,"s5.save();X=-.25*Lx-50;Y=Ly+.3*y;s5.rotate(2*Math.PI);s5.font="16px serif";s5.fillStyle = "#7fff00";s5.textAlign = "left";s5.fillText(0,X,Y);s5.restore();}; n"); fprintf(OutputFile,"</script></head><body><canvas id="myCanvas" width="1300" height="1300" style="border:1px solid black;"></canvas></body></html> n"); fclose(OutputFile); }
  • 7. Figure(2) Input time acceleration
  • 10. Figure(5) Elastic pseudo acceleration spectrum