d10070dd

☆add_triangles

Jan 21st, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define VTX 3
  6. #define XYZ 3
  7.  
  8. int main(int argc,char *argv[])
  9. {
  10.     FILE *fpi1,*fpi2,*fpo;
  11.     int i,j;
  12.     int tri1,tri2,tri3; //number of triangles
  13.  
  14.     float dn1;
  15.     int x,y;
  16.     int re;
  17.     int ix,iy;
  18.     int iw,ih,iW,iH;
  19.     int to_tri1,to_tri2,to_tri3;
  20.     float *file1,*file2,*file3;
  21.    
  22.     if(argc!=6)
  23.     {
  24.         fprintf(stderr,"Usage: %s\n(2)Input_file1_filename\n(3)Input_file2_filename\n(4)Output_new_filename\n(5)triangles_1\n(6)triangles_2\n",argv[0]);
  25.         exit(1);
  26.     }
  27.    
  28.     printf("OPEN base FILE NAME:%s\n",argv[1]);
  29.     printf("OPEN add FILE NAME:%s\n",argv[2]);
  30.     printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]); //for output
  31.    
  32.     tri1 = atoi(argv[4]); printf("triangles1 = %d,", tri1);  //number of triangles1
  33.     tri2 = atoi(argv[5]); printf("triangles2 = %d\n", tri2); //number of triangles2
  34.     tri3=tri2+tri1;
  35.    
  36.     to_tri1=tri1*VTX*XYZ;
  37.     to_tri2=tri2*VTX*XYZ;
  38.     to_tri3=tri3*VTX*XYZ;
  39.     printf("total_triangles = %d\n", tri3);
  40.  
  41.     printf("check00\n");
  42.    
  43.     file1= (float *)malloc(to_tri1*sizeof(float)); //memory for triangles1
  44.     file2= (float *)malloc(to_tri2*sizeof(float)); //memory for triangles2
  45.     file3= (float *)malloc(to_tri3*sizeof(float)); //memory for triangles3
  46.    
  47.     //   printf("check0\n");
  48.    
  49.     //base
  50.     if((fpi1=fopen(argv[1],"rb"))==NULL)
  51.     {
  52.         fprintf(stderr,"input file open error\n");
  53.         exit(1);
  54.     }
  55.     printf("check0-1\n");
  56.  
  57.     fread((float *)file1,sizeof(float),to_tri1,fpi1);//large
  58.  
  59.     printf("check0-2\n");
  60.    
  61.     //add
  62.     if((fpi2=fopen(argv[2],"rb"))==NULL)
  63.     {
  64.         fprintf(stderr,"input file open error\n");
  65.         exit(1);
  66.     }
  67.     printf("check0-3\n");
  68.     fread((float *)file2,sizeof(float),to_tri2,fpi2);//small
  69.     printf("check0-4\n");
  70.  
  71.     if((fpo=fopen(argv[3],"wb"))==NULL)
  72.     {
  73.         fprintf(stderr,"input file open error\n");
  74.         exit(1);
  75.     }
  76.  
  77.     printf("check1\n");
  78.    
  79.     for(i=0;i<to_tri1;i++)
  80.     {
  81.     file3[i]=file1[i];
  82.     }
  83.  
  84.     printf("check2\n");
  85.     for(i=0;i<to_tri2;i++)
  86.     {
  87.     file3[i+to_tri1]=file2[i];
  88.     }  
  89.  
  90.     printf("check3\n");
  91.     for(i=0;i<to_tri3;i++)
  92.     {
  93.         dn1=file3[i];
  94.     fwrite(&dn1,sizeof(float),1,fpo);
  95.     }  
  96.    
  97.     printf("check4\n");
  98.    
  99.     free(file1);
  100.     free(file2);
  101.     free(file3);
  102.     fclose(fpi1);
  103.     fclose(fpi2);
  104.     fclose(fpo);
  105.    
  106. }
Advertisement
Add Comment
Please, Sign In to add comment