⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jiaodian.c

📁 地震资料处理时计算二维测线交点的程序,有弯线也能用
💻 C
字号:

#include "stdio.h"
#include "math.h"
#include "string.h"
#define NUM 30
#define MAX 10000
#define TOTAL 300000

int n,sum;
int count[NUM];

struct cmp_coordinate
{ 
  int cmp;
  float cmp_x;
  float cmp_y;
} cmp[MAX];

struct all_line
{ 
  char line[10];
  int point;
  float point_x;
  float point_y;
}  all[TOTAL];

struct jiaodian
{
  char a_line[10];
  int  a_cmp;
  char b_line[10];
  int  b_cmp;
} intersection[MAX];

double dist( float x1, float x2, float y1,float y2)
{
	return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}


int merg()
{
	int i,j,m=0,num,sum=0,k=0;
	int each_line[NUM];
	char path[100];
   	FILE *in[NUM];
	

	printf("-------How many 2D lines? Please input the number-----------\n");
	scanf("%d", &n);

   
 for (i=0;i <n;i++) {

		printf("Please input the files\n把文件名改成线号,不带后缀,输入一个文件后回车,再输入下一个:\n");
        scanf("%s",path);
		if((in[i]=fopen(path,"r"))==NULL) {
  
           printf("can't open the file\n");
           exit(0);
		}

		num=0;
	   
     for(j=0;j<MAX;j++) {

		 cmp[j].cmp = 0;
	    
		 fscanf(in[i],"%d%f%f",&cmp[j].cmp,&cmp[j].cmp_x,&cmp[j].cmp_y);
		 
		 if ( cmp[j].cmp != 0 ) {
            
		     num +=1;
		 	 strcpy ( all[m].line , path );
			 all[m].point = cmp[j].cmp;
			 all[m].point_x = cmp[j].cmp_x;
			 all[m].point_y = cmp[j].cmp_y;
			// printf("%s%6d%16.4f%16.4f\n",all[m].line,all[m].point,all[m].point_x,all[m].point_y);
             m += 1;
		 } 	 
	
   	   }
	   count[0]=0;
       count[i+1]=m;
       each_line[i]=num;
	   sum += each_line[i];
	   fclose(in[i]);
	   printf("%6d%8d\n", each_line[i],count[i+1]);
 }
   printf("There are %6d cmp points in all.\n", sum);

   return sum;

}

void main()
{ 
	int i,j,k,u,v,r,total,w=0;
	int c[NUM];
    double d;
	char path[100];
    FILE *out[NUM];

    total = merg();
	for ( i=0;i<n;i++ ) {
		u=0;
		for ( j=count[i];j<count[i+1];j++ ) {
			
            for ( k=0;k<total;k++ ) {
               
               d = dist( all[j].point_x,all[k].point_x,all[j].point_y,all[k].point_y );
			   if ( (strcmp( all[j].line,all[k].line )) != 0 && d < 20.0 ) {
		
		       printf ("%s%6d   %s%6d   %12.4f\n",all[j].line,all[j].point,all[k].line,all[k].point,d);
			   strcpy ( intersection[w].a_line , all[j].line );
			   intersection[w].a_cmp  = all[j].point;
			   strcpy ( intersection[w].b_line , all[k].line );
			   intersection[w].b_cmp  = all[k].point;
			   w += 1;
			   u += 1;
               }
			}
		}
		c[0]=0;
		c[i+1]=w;
		printf("%6d\n",c[i+1]);
	}
	//printf("%6d\n",w);

	for ( v=0; v < n; v++ ) {
		printf("Please input the name of result files\n输入想要保存的交点文件名,和上面的输入对应\n");
		scanf("%s",path);

		if((out[v]=fopen(path,"a"))==NULL) {
   
           printf("can't open the file\n");
           exit(0);
		}
		fprintf(out[v], "----+----1----+----2----+----3----+----4----+----5----+----6----+----7\n");
		fprintf(out[v], "INTSLINE                 %s\n",intersection[c[v]].a_line);

		for ( r=c[v];r<c[v+1]; r++ ) {
		
		fprintf(out[v], "INTSINTR      %4d                %s      CMP    %4d\n", intersection[r].a_cmp,intersection[r].b_line,intersection[r].b_cmp);               
		//printf("INTSINTR      %4d                %s      CMP    %4d\n", intersection[r].a_cmp,intersection[r].b_line,intersection[r].b_cmp);
		//printf("%6d%6d\n",r,v);
		}
		
        fclose(out[v]);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -