Commit 76956c7e authored by saeed's avatar saeed
Browse files

a bit modification

parent ed971b4c
#!/bin/bash
issh=1
issh=0
iobs=0
isvg=0
isvg=1
......
......@@ -49,7 +49,7 @@ int Strcmp(char *sa, char *sb){
}
}
int Readsshcsv(char *filename, char *station, int idbeg, int idend, Data *sshdata){
static int Readsshcsv(char *filename, char *station, int idbeg, int idend, Data *sshdata){
FILE *FS = NULL;
FS = fopen(filename,"r");
......
......@@ -8,7 +8,6 @@ float sfmin(float *y, int N){
}
return zm;
}
float sfmax(float *y, int N){
float zm = y[0];
for (int i=1; i < N; ++i){
......@@ -17,12 +16,67 @@ float sfmax(float *y, int N){
return zm;
}
void create_svg(int, float*, float*);
void create_svg_line_chart_line_chart(int, float*, float*);
void create_svg_contour_init(FILE **);
void create_svg_contour_add(FILE *, float *, float *, int *);
void create_svg_contour_close(FILE *);
int main(void){
float height= 600.0;
float width = 900.0;
//we create topography contour like a circular seamount
// x * x + y * y
int npoint = 40001;
float *ax = (float*)malloc(npoint *sizeof(float));
float *ay = (float*)malloc(npoint *sizeof(float));
float **az = NULL;
float delta = (4.0) / (npoint -1);
for (int i=0; i < npoint;++i){
ax[i] = i*delta;
ay[i] = i*delta;
}
az = (float **)malloc(sizeof(float*)*npoint);
for (int i=0; i < npoint;++i){
az[i] = (float*)malloc(sizeof(float)*npoint);
}
for (int i=0; i < npoint; ++i){
for (int j=0; j < npoint; ++j){
az[i][j] = ax[i] * ax[i] + ay[j] * ay[j];
}
}
for (int i=0; i < npoint; ++i){
for (int j=0; j < npoint; ++j){
if ( az[i][j] == 4.0f){
printf("%f\t%f\t%f\n",ax[i],ay[j],az[i][j]);
}
}
}
for (int i=0; i < npoint; ++i){
ax[i] = (width /(ax[npoint-1] -ax[0]))*ax[i] - ((width *ax[0]) / (ax[npoint-1] - ax[0]));
ay[i] = (height/(ay[npoint-1]-ay[0]))* ay[i] - ((height *ay[0])/ (ay[npoint-1] - ay[0]));
}
int begin = 0;
FILE *fin = NULL;
create_svg_contour_init(&fin);
create_svg_contour_add(fin,ax,ay,&begin);
for (int i=0; i < npoint; ++i){
for (int j=0; j < npoint; ++j){
if ( az[i][j] == 4.0f){
create_svg_contour_add(fin,(ax+i),(ay+j),&begin);
}
}
}
create_svg_contour_close(fin);
for (int i=0; i < npoint; i++){
free(az[i]);
}
free(ax);
free(ay);
free(az);
#if 0
FILE *fin = fopen("barseback_ssh.dat","r");
char c = 0;
......@@ -44,7 +98,7 @@ int main(void){
xa[ni] = (float)(ni+1);
ni++;
}
fclose(fin);
float vmin = sfmin(ssh, nl), vmax = sfmax(ssh, nl);
height -= 50.0;
......@@ -58,15 +112,15 @@ int main(void){
xa[i] = (width / (xa[nl-1] - xa[0]) )* xa[i] - ((width *xa[0]) / (xa[nl-1] - xa[0]));
}
create_svg(nl,xa,ssh);
create_svg_line_chart(nl,xa,ssh);
#endif
#if 0
for (int i=0; i < nl; ++i){
printf("ssh[%d] %f\n",i,ssh[i]);
}
float PI = 4.0*atan(1.0);
int nx = 100001;
int nx = 1001;
float dx = (2.0*PI)/(nx -1);
float *xx = (float*)malloc(nx *sizeof(float));
float *yy = (float*)malloc(nx *sizeof(float));
......@@ -84,7 +138,7 @@ int main(void){
xx[i] = (width / (xx[nx-1] - xx[0]) )* xx[i] - ((width *xx[0]) / (xx[nx-1] - xx[0]));
}
create_svg(nx,xx,yy);
create_svg_line_chart(nx,xx,yy);
free(ssh);
free(xa);
......@@ -92,13 +146,13 @@ int main(void){
free(yy);
#endif
fclose(fin);
return 0;
}
void create_svg(int N, float *x, float *y){
void create_svg_line_chart(int N, float *x, float *y){
FILE *fin = fopen("obs.svg","w");
fprintf(fin,"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n");
......@@ -123,3 +177,34 @@ void create_svg(int N, float *x, float *y){
fclose(fin);
}
void create_svg_contour_init(FILE **fin){
*fin = fopen("circle.svg","w");
fprintf(*fin,"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n");
fprintf(*fin,"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
fprintf(*fin,"<svg height=\"600px\" version=\"1.1\" viewBox=\"0 0 900 600\" width=\"900px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n");
fprintf(*fin,"<defs><style type=\"text/css\">*{stroke-linecap:square;stroke-linejoin:round;}</style></defs>");
fprintf(*fin,"<g id=\"line2d_1\"> <path d=\"\n");
}
void create_svg_contour_add(FILE *fin , float *x, float *y, int *beg){
if (*beg == 0){
fprintf(fin,"M%f %f\n",*x,*y);
}
else{
fprintf(fin,"L%f %f\n",*x,*y);
}
*beg = 1;
}
void create_svg_contour_close(FILE *fin){
fprintf(fin,"Z\" style=\"fill:none;stroke:#ff0000;\"");
fprintf(fin,"/>\n");
fprintf(fin,"</g>\n");
fprintf(fin,"</svg>");
fclose(fin);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment