MNQM.C
上传用户:qq5388545
上传日期:2022-07-04
资源大小:29849k
文件大小:7k
- #include "string.h"
- #include "alloc.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "io.h"
- int nelement,nnode,nsum_node;
- struct elems
- {
- int nedge;
- float x[4],y[4];
- float s11[4],s22[4],s12[4];
- }*elem_stress;
- void main(argc,argv)
- int argc; char *argv[];
- {
- FILE *fs,*fc,*fj;
- int i,j,nelement,nnode,l,have=0,num,numk,numl,fast=0,ielement,nmat,gap=0;
- char str[100],coname[80],cname[80],sname[80],str1[20];
- float y1,z1;
- float *coora[2];
- int *element[4];
- struct coors{
- int numj;
- float y,z;
- /* float s11,s22,s12;*/
- }*coor_stress;
- if(argc<4)
- {
- for(i=0;i<3;i++)
- {
- switch(i)
- {
- case 0:strcpy(str1,"control");break;
- case 1:strcpy(str1,"element");break;
- case 2:strcpy(str1,"stress");break;
- }
- for(;;)
- {
- /*/gotoxy(wherex()-15,wherey()-1);*/
- printf("input %s data filename (<CR> TO QUIT):",str1);
- gets(str);
- if(str[0]==' ')
- /*/exit(0);*/
- return;
- else if(access(str,0)==0)
- {
- if(i!=2) break;
- else
- {
- /*/gotoxy(wherex()-15,wherey());*/
- printf(" ");
- break;
- }
- }
- else printf("afile not found!");
- }
- switch(i)
- {
- case 0:strcpy(coname,str);break;
- case 1:strcpy(cname,str);break;
- case 2:strcpy(sname,str);break;
- }
- }
- }
- else
- {
- strcpy(coname,argv[1]);
- strcpy(cname,argv[2]);
- strcpy(sname,argv[3]);
- }
- /*/ clrscr();*/
- /*read nnodem,nelement*/
- if((fj=fopen(coname,"r"))==NULL)
- {
- printf("aopen failed");
- exit(0);
- }
- fscanf(fj,"%d%d",&nnode,&nelement);
- fclose(fj);
- if((fj=fopen(cname,"r"))==NULL) /*cooresponding node and element file*/
- {
- printf("aopen failed");
- exit(0);
- }
- if((fc=fopen(cname,"r"))==NULL) /*corradate file*/
- {
- printf("aopen failed");
- exit(0);
- }
- if((fs=fopen(sname,"r"))==NULL) /*stress file*/
- {
- printf("aopen failed");
- exit(0);
- }
- /*allocate memory*/
- fgets(str,100,fj);
- fscanf(fj,"%d",&nsum_node);
- fgets(str,100,fj);
- for(i=0;i<2;i++)
- {
- if((coora[i]=(float *)malloc(sizeof(float)*nsum_node))!=NULL)
- fast=1;
- else
- {
- printf("antoo many node; Do you want to continue(y/n)");
- if((getchar())=='y')
- fast=0;
- else
- exit(0);
- }
- }
- if(fast)
- {
- printf("nreading cooradation information......");
- for(i=0;i<nsum_node;i++)
- {
- float y1,z1;
- if(fscanf(fj,"%d",&num)==EOF)
- {
- break;
- }
- fgets(str,30,fj);
- fscanf(fj,"%f%f",&y1,&z1);
- coora[0][i]=y1;coora[1][i]=z1;
- /* printf(" %d, %.5f, %.5fn",i,coora[0][i],coora[1][i]);*/
- fgets(str,100,fj);
- }
- }
- if(!fast)
- {
- if((coor_stress=(struct coors *)malloc(sizeof(struct coors)*nnode))==NULL)
- {printf("anot enough memory (coor_stress)");
- exit(0);
- }
- }
- for(i=0;i<4;i++)
- if((element[i]=(int *)malloc(sizeof(int)*nelement))==NULL)
- {printf("anot enough memory (element %d)",i);
- exit(0);
- }
- nnode=0;
- if(fast)
- {
- fscanf(fj,"%d",&ielement);
- fscanf(fj,"%d",&ielement);
- fscanf(fj,"%d",&nmat);
- fgets(str,100,fj);
- for(i=0;i<nmat;i++) /*nmat number of material class*/
- {
- printf("nreading material %d information of group 1",i+1);
- for(j=0;j<3;j++)
- fgets(str,100,fj);
- }
- printf("nreading element information of group 1");
- for(i=0;i<ielement+4;i++)
- {
- fgets(str,100,fj);
- }
- fscanf(fj,"%d",&ielement);
- if(ielement==14) /*exist gap element*/
- {
- gap=1;
- printf("nreading gap data......");
- fscanf(fj,"%d",&ielement);
- fgets(str,100,fj);
- for(i=0;i<ielement+6;i++)
- fgets(str,100,fj);
- }
- if(gap)
- fscanf(fj,"%d",&ielement);
- fscanf(fj,"%d",&ielement);
- for(i=0;i<8;i++)
- fgets(str,100,fj);
- }
- else
- {
- rewind(fj);
- fgets(str,100,fj);
- fscanf(fj,"%d",&ielement);
- fgets(str,100,fj);
- for(i=0;i<ielement+1;i++)
- fgets(str,100,fj);
- fscanf(fj,"%d",&ielement);
- fscanf(fj,"%d",&ielement);
- fscanf(fj,"%d",&nmat);
- fgets(str,100,fj);
- for(i=0;i<nmat;i++) /*nmat number of material class*/
- for(j=0;j<3;j++)
- fgets(str,100,fj);
- for(i=0;i<ielement+4;i++)
- fgets(str,100,fj);
- fscanf(fj,"%d",&ielement);
- fscanf(fj,"%d",&ielement);
- fgets(str,100,fj);
- for(i=0;i<ielement+6;i++)
- fgets(str,100,fj);
- fscanf(fj,"%d",&ielement);
- fscanf(fj,"%d",&ielement);
- for(i=0;i<8;i++)
- fgets(str,100,fj);
- }
- if(ielement!=nelement)
- {
- printf("anlining element number error!");
- exit(0);
- }
- printf("nreading element information of group 2");
- for(ielement=0;ielement<nelement;ielement++)
- {
- if(fscanf(fj,"%d",&i)==EOF) break;
- for(i=0;i<4;i++)
- {
- fscanf(fj,"%d",&element[i][ielement]);
- if(!fast)
- {
- coor_stress[nnode].numj=element[i][ielement];
- have=0;
- /*decide the existance this nodes cooradates:YES:have=1;NO: have=0*/
- for(l=0;l<nnode;l++)
- {
- numk=(coor_stress[nnode].numj);
- numl=(coor_stress[l].numj);
- if(numk==numl)
- {
- have=1;
- break;
- }
- }
- /*if no this node's cooradates,then search and record it*/
- if(!have)
- {
- for(;;)
- {
- /*read node */
- fgets(str,100,fc);
- fgets(str,100,fc);
- if(fscanf(fc,"%d",&num)==EOF)
- {
- rewind(fc);
- fgets(str,100,fc);
- fgets(str,100,fc);
- fscanf(fc,"%d",&num);
- }
- /*decide if needed*/
- if(num==coor_stress[nnode].numj)
- {
- fgets(str,30,fc);
- fscanf(fc,"%f%f",&y1,&z1);
- /* printf(" %d, %.5f, %.5fn",coor_stress[nnode].numj,y1,z1);*/
- (coor_stress[nnode].y)=y1;(coor_stress[nnode].z)=z1;
- fgets(str,100,fc);
- nnode++;
- break;
- }
- /*skip the rest string*/
- else fgets(str,100,fc);
- }/*end search*/
- }/*end record*/
- }
- }/*end of the current element*/
- fgets(str,100,fj);
- }/*end of all element*/
- /*printf("%d %d",nnode,ielement);
- getch(); */
- fclose(fj);
- fclose(fc);
- if((elem_stress=(struct elems *)malloc(sizeof(struct elems)*nelement))==NULL)
- {printf("annot enough memory");
- exit(0);
- }
- rewind(fs);
- numk=0;
- printf("nsearching stress data.....");
- for(;;)
- {
- fgets(str,100,fs);
- if(stricmp(str," Sigma-Intn")==0)
- numk++;
- if(numk==2) break;
- }
- fgets(str,100,fs);
- printf("nreading stress data......");
- for(numk=0;numk<nelement;numk++)
- {
- if(element[2][numk]==element[3][numk]) have=3;
- else have=4;
- elem_stress[numk].nedge=have;
- for(i=0;i<have;i++)
- {
- int inode,in;
- inode=element[i][numk];
- if(!fast)
- {
- for(in=0;in<nnode;in++)
- {
- if(inode==coor_stress[in].numj)
- {
- elem_stress[numk].x[i]=coor_stress[in].y;
- elem_stress[numk].y[i]=coor_stress[in].z;
- break;
- }
- }
- }
- else
- {
- elem_stress[numk].x[i]=coora[0][inode-1];
- elem_stress[numk].y[i]=coora[1][inode-1];
- }
- {
- printf(" %d %d",numk,elem_stress[numk].nedge);
- printf(" %.2f %.2f",elem_stress[numk].x[i],elem_stress[numk].y[i]);
- }
- fscanf(fs,"%d",&numl);
- if(numl!=numk+1)
- {
- printf("anstress data file read error!");
- exit(0);
- }
- fgets(str,9,fs);
- fscanf(fs,"%f%f",&y1,&z1);
- elem_stress[numk].s11[i]=y1;
- elem_stress[numk].s22[i]=z1;
- printf(" %f %f",elem_stress[numk].s11[i],elem_stress[numk].s22[i]);
- fscanf(fs,"%f%f",&y1,&z1);
- elem_stress[numk].s12[i]=z1;
- printf(" %f",elem_stress[numk].s12[i]);
- fgets(str,100,fs);
- fgets(str,100,fs);
- printf("n");
- }
- }
- fclose(fs);
- if((fj=fopen("test.dat","wb"))==NULL)
- {
- printf("aopen failed");
- exit(0);
- }
- fwrite(&nelement,sizeof(int),1,fj);
- fwrite(elem_stress,sizeof(struct elems)*nelement,1,fj);
- fclose(fj);
- if(!fast)
- free((void *)elem_stress);
- else
- {
- for(i=0;i<2;i++)
- free((void *)coora[i]);
- }
- for(i=0;i<4;i++)
- free((void *)element[i]);
- free((void *)coor_stress);
- }