/*[bt-pgm.c] -------------------------------------------------------------- */ /* File Converter to .pgm for Bathymetry files */ /* prog. by Y.Okamoto 1999.07/02 */ /* ------------------------------------------------------------------------ */ #include #include /* for atoi() */ #include #include /* define constant */ #define IMAX 240*2 /* grid max */ #define JMAX 240*2 #define T_END 10 #define TMF 300 #define BT_FILE "etp5_js2.sqf" /* Bathymetoric data file */ #define WH_FILE "okushiri3_" /* Wave Height File 1-column */ #define WHO_FILE "oku_bt" /* Wave Height File xy-grid */ /* grid val. init. */ double wf[IMAX+2][JMAX+2]; double h[IMAX+2][JMAX+2]; double hu[IMAX+2][JMAX+2]; double hv[IMAX+2][JMAX+2]; int lf[IMAX+2][JMAX+2]; /* land area flag */ int dep; int i,j,t=0; /* grid,time iteration counter */ double wh; int ww,ht,w[IMAX+2][JMAX+2]; char height[20]; char tm[20]; char f_name[20]; char f_name2[20]; char dmy[20]; FILE *fp; FILE *fp2; /*--main routine--------------------------------------------------------------*/ void main(void) { /* read Bathy. data file */ fp=fopen(BT_FILE,"r"); for (j=0;j<=JMAX/2;j++) { for (i=0;i<=IMAX/2;i++) { fscanf(fp,"%d\n",&dep); if (dep>0) dep=0; h[i*2][j*2]=-dep; /* twice grid */ /* printf("dep=%d\n",dep); */ } } fclose(fp); /*while (getchar() != 'x')*/ ; /* grid extend twice */ for (j=0;j<=JMAX;j++) { for (i=0;i<=IMAX;i++) { if (i==IMAX || j==JMAX) continue; if (i%2==0 && j%2==0) continue; if (i%2==1 && j%2==0) { h[i][j]=(h[i-1][j]+h[i+1][j])/2.0; /* printf("h=%f\n",h[i][j]); */ } if (i%2==0 && j%2==1) { h[i][j]=(h[i][j-1]+h[i][j+1])/2.0; /* printf("h=%f\n",h[i][j]); */ } if (i%2==1 && j%2==1) { h[i][j]=(h[i-1][j-1]+h[i+1][j+1])/2.0; /* printf("h=%f\n",h[i][j]); */ } } } j=JMAX; for (i=0;i<=IMAX;i++) { h[i][j]=h[i][j-1]; } i=IMAX; for (j=0;j<=JMAX;j++) { h[i][j]=h[i-1][j]; } /*while (getchar() != 'x') ;*/ for (j=0;j<=JMAX-1;j++) /* JMAX null data? */ { for (i=0;i<=IMAX-1;i++) { /*printf("%10d\n",h[i][j]);*/ /* cl=3; x=i*DS*MX; y=j*DS*MY; z=-h[i][j]*DZ*M*0.001; xx=x+y+x00; yy=-y+z+y00; if(i==0 || (h[i][j]+h[i-1][j])==0){ MoveTo(0,xx,yy);} else{*/ /* PutPixel(0,xx,yy,cl);}*/ /* setcolor(cl); LineTo(0,xx,yy);}*/ } } /* staggared grid depth */ for (j=0;j<=JMAX;j++) { for (i=0;i<=IMAX;i++) { hv[i][j]=(h[i][j]+h[i+1][j])/2.0; hu[i][j]=(h[i][j]+h[i][j+1])/2.0; /* printf("h=%f\n",hu[i][j]); printf("h=%f\n",hv[i][j]); */ } } j=JMAX+1; for (i=0;i<=IMAX;i++) { hu[i][j]=h[i][j]; hv[i][j]=h[i][j]; /* printf("h=%f\n",hv[i][j]); printf("h=%f\n",hu[i][j]); */ } i=IMAX+1; for (j=0;j<=JMAX;j++) { hu[i][j]=h[i][j]; hv[i][j]=h[i][j]; /* printf("h=%f\n",hv[i][j]); printf("h=%f\n",hu[i][j]); */ } /* land flag */ for (j=0;j<=JMAX;j++) { for (i=0;i<=IMAX;i++) { if (hu[i][j]<=0 && hv[i][j]<=0 && hu[i+1][j]<=0 && hv[i][j+1]<=0) /* closed land area */ lf[i][j]=1; else { lf[i][j]=0; } } /* input Wave Height data file */ /* input Wave Height data file */ sprintf(tm,"%d",t); strcpy(f_name2,WHO_FILE); strcpy(dmy,tm); strcat(f_name2,tm); strcat(f_name2,".pgm"); printf("%s\n",f_name2); fp2=fopen(f_name2,"w"); /*Header File*/ fprintf(fp2,"P2\n"); fprintf(fp2,"481 481\n"); fprintf(fp2,"65535\n"); for (j=0;j<=JMAX;j++) { for (i=0;i<=IMAX;i++) { if (lf[i][j]==1) ht=35000; else ht=35000-h[i][j]*4-100; if (ht<0) ht=0; sprintf(height,"%4d",ht); /* value to text */ if (i==IMAX) fprintf(fp2,"%s\n",height); else fprintf(fp2,"%s ",height); } } fclose(fp2); } }