#include <stdio.h>
#include <string.h>
#include "preprocess.h"
#include "common.h"
#include "init.h"
#include <windows.h>
#define MAX_NUM 50000
main(void)
{
FILE *fp,*fp_write,*fp_read;
int node_num,linear_element_num,i,j,k,element_num,pre_cout;
char buf[100];
char string[50];
char string1[50];
char s1[10],s2[10],s3[10],s4[10],s5[10],s6[10],s7[10],s8[10],s9[10];
int d1,d2,d3,d4,d5,d6;
double l1,l2,l3;
node_num=0;
linear_element_num=0;
element_num=0;
pre_cout=0;
// free_mem();
// struct NODE_INFO *node_info;
// struct ELEMENT_INFO *element_info;
if(node_info!=NULL)
free(node_info);
if(element_info!=NULL)
free(element_info);
printf("Please input the preprocessed file get from GiD: \n");
scanf("%s",&string);
fp=fopen(string,"r");
if(fp==NULL)
{
printf("open result file .msh from GiD failed\n");
return 0;
}
//try to find coordinates of nodes
for (i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to node type is %s \n",buf);
//node_num++;
pre_cout++;
if(strcmp(buf,"coordinates")==0)
{
//printf(" found 'coordinates',now begin to count the number of nodes\n");
break;
}
}
if(!(strcmp(buf,"coordinates")==0))
printf("can not find 'end',maybe MAX_NUM is too small\n");
//element_num=(element_num-2)/10;
// now find it and begin to count number of nodes
for (i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to node type is %s \n",buf);
node_num++;
if(strcmp(buf,"end")==0)
{
printf(" found 'end'for node coordinates!!\n");
break;
}
}
if(!(strcmp(buf,"end")==0))
printf("can not find 'end'of nodes list,maybe MAX_NUM is too small\n");
//element_num=(element_num-2)/10;
node_num=node_num/4;
//fscanf(fp,"%d",&node_num); //将fp所指的node数赋给node_num
printf("node_num is %d\n", node_num);
/*
//count number of linear element(with two nodes)
for (i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to linear elements type is %s \n",buf);
linear_element_num++;
if(strcmp(buf,"end")==0)
{
printf(" found 'end'for linear elements!!\n");
break;
}
}
linear_element_num/=13;
*/
//count number of triangular element
//try to find 'elements' first
//fscanf(fp,"%s",buf);
//fscanf(fp,"%s",buf);//in order to avoid the 'end elements' for linear elements, the fp move two times
for(i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to element type is %s \n",buf);
if(strcmp(buf,"elements")==0)
{
printf(" found 'elements'!! begin to count the number of triangular elements\n");
break;
}
}
//count now
for(i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to element type is %s \n",buf);
element_num++;
if(strcmp(buf,"end")==0)
{
printf(" found 'end' fo triangular elements!!\n");
break;
}
}
if(!(strcmp(buf,"end")==0))
printf("can not find 'end',maybe MAX_NUM is too small\n");
element_num=(element_num)/10; //10 columes
//count constrains
//try to find 'constraints' first
for (i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to constraints type is %s \n",buf);
//node_num++;
//pre_cout++;
if(strcmp(buf,"constraints")==0)
{
printf(" found 'coordinates',now begin to count the number of constraints\n");
break;
}
}
if(!(strcmp(buf,"constraints")==0))
printf("can not find 'constraints',maybe MAX_NUM is too small\n");
//now count number of constraints
for(i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to constrain type is %s \n",buf);
iDispRestNodeNum++;
if(strcmp(buf,"end")==0)
{
printf(" found 'end' for constraints!!\n");
break;
}
}
if(!(strcmp(buf,"end")==0))
printf("can not find 'end' for constraints,maybe MAX_NUM is too small\n");
iDispRestNodeNum=(iDispRestNodeNum)/9;
//count num of pressure elements
//try to find global_pressure_loads fist
for (i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to node type is %s \n",buf);
//node_num++;
//pre_cout++;
if(strcmp(buf,"global_pressure_loads")==0)
{
printf(" found 'global_pressure_loads',now begin to count the number of global_pressure_loads elements\n");
break;
}
}
if(!(strcmp(buf,"global_pressure_loads")==0))
printf("can not find 'global_pressure_loads',maybe MAX_NUM is too small\n");
//now begin to count global_pressure_loads
for(i=0;i<MAX_NUM;i++)
{
fscanf(fp,"%s",buf);
//printf(" string belong to global_pressure_loads type is %s \n",buf);
iPressElementNum++;
if(strcmp(buf,"end")==0)
{
printf(" found 'end'for global_pressure_loads!!\n\n\n");
break;
}
}
if(!(strcmp(buf,"end")==0))
printf("can not find 'end' for global_pressure_loads,maybe MAX_NUM is too small\n");
iPressElementNum=(iPressElementNum)/6;
printf("node_num is %d\n", node_num);
printf("linear_element_num is %d\n", linear_element_num);
printf("element_num is %d\n", element_num);
printf("DispRestNodeNum is %d\n", iDispRestNodeNum);
printf("PressElementNum is %d\n", iPressElementNum);
fclose (fp);
//FILE *fp_read;
fp_read=fopen(string,"r");
if(fp_read==NULL)
{
printf("reread result file .msh from GiD failed\n");
return 0;
}
for(i=0;i<pre_cout;i++)
{
fscanf(fp_read,"%s",buf);
}
if((node_info=(struct NODE_INFO *)malloc(sizeof(struct NODE_INFO)*node_num)))
{
for(i=0;i<node_num;i++)
{
fscanf(fp_read,"%d %lf %lf %lf",&j,&node_info[i].x[0],&node_info[i].x[1],&node_info[i].x[2]);
//for(j=0;j<3;j++)
//if(fabs(node_info[i].x[j])<1e-4)
//node_info[i].x[j]=0;
}
}
else
{
//MessageBox(wglobal,"alloc memory fail\n");
//MessageBox(NULL,"Attention:alloc memory for nodes failed!","MessageBox",MB_OK);
if(node_info!=NULL)
free(node_info);
if(element_info!=NULL)
free(element_info);
return 0;
}
/*
//begin to write linear elements
for(i=0;i<3;i++)
{
fscanf(fp_read,"%s",buf);
}
//move to linear element lists
if((linear_element_info=(struct LINEAR_ELEMENT_INFO *)malloc(sizeof(struct LINEAR_ELEMENT_INFO)*linear_element_num)))
{
for(i=0;i<linear_element_num;i++)
{
fscanf(fp,"%d %d %d %d %s %s %s %s %s %s %s %s %s",&j,
&linear_element_info[i].node[0],
&linear_element_info[i].node[1],
&k,&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9);
}
}
else
{
//MessageBox(wglobal,"alloc memory fail\n");
//MessageBox(NULL,"Attention: alloc memery for element failed!","MessageBox",MB_OK);
if(node_info!=NULL)
free(node_info);
if(element_info!=NULL)
free(element_info);
return 0;
} */
//write elements
//try to find triangular elements first
//in order to avoid 'elements' of linear elements,fp move forward two times
// fscanf(fp,"%s",buf);
// fscanf(fp,"%s",buf);
/*//////////////////////////////////
for (i=0;i<MAX_NUM;i++)
{
fscanf(fp_read,"%s",buf);
//printf(" string belong to node type is %s \n",buf);
//node_num++;
//pre_cout++;
if(strcmp(fp_read,"elements")==0)
{
//printf(" found 'elements',now begin to count the number of triangular elements\n");
break;
}
}
if(!(strcmp(fp_read,"elements")==0))
printf("can not find 'elements' for triangular elements,maybe MAX_NUM is too small\n");
*//////////////////////////////////
fscanf(fp_read,"%s",buf);
fscanf(fp_read,"%s",buf);
fscanf(fp_read,"%s",buf);
UGQM.rar_GID
版权申诉
63 浏览量
2022-09-23
01:44:50
上传
评论
收藏 3KB RAR 举报
小波思基
- 粉丝: 70
- 资源: 1万+