Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(int argc, char *argv[])
- {
- //Decralation of variables
- int i;
- int r,g,b;
- unsigned long newline_count_1=0,newline_count_2=0,lines;
- FILE *fpi1,*fpi2,*fpo;
- float x,y,z;
- if(argc!=4)
- {
- fprintf(stderr,"Usage: %s (1)CSV1File\n(2)CSV2File\n(3)VTKFile\n",argv[0]);
- return 0;
- }
- printf("Open CSV1 File\n");
- //Open CSV1 file
- if((fpi1=fopen(argv[1],"r"))==NULL)
- {
- printf("The file can't be opened. The program is exit.\n");
- return 0;
- }
- printf("Open CSV2 File\n");
- //Open CSV2 file
- if((fpi2=fopen(argv[2],"r"))==NULL)
- {
- printf("The file can't be opened. The program is exit.\n");
- return 0;
- }
- printf("Open VTK File\n");
- //Open VTK file for save
- if((fpo=fopen(argv[3],"w"))==NULL)
- {
- printf("The file can't be opened. The program is exit.\n");
- return 0;
- }
- //count how many lines
- /*
- while((c==fgetc(fpi))!=EOF
- {
- if(c=='\n')
- newline_count++;
- }
- */
- printf("CSV1 File\n");
- while (fscanf(fpi1,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!= EOF)
- {
- newline_count_1=newline_count_1+1;
- }
- printf("CSV1 total=%ld\n",newline_count_1);
- printf("CSV2 File\n");
- while (fscanf(fpi2,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!= EOF)
- {
- newline_count_2=newline_count_2+1;
- }
- printf("CSV2 total=%ld\n",newline_count_2);
- lines=newline_count_1+newline_count_2;
- printf("Total lines=%ld\n",lines);
- //writing VTK file
- fprintf(fpo,"# vtk DataFile Version 3.0\n");
- fprintf(fpo,"vtk output\n");
- fprintf(fpo,"ASCII\n");
- fprintf(fpo,"DATASET UNSTRUCTURED_GRID\n");
- fprintf(fpo,"POINTS %ld float\n",lines);
- fseek(fpi1,0,SEEK_SET);
- fseek(fpi2,0,SEEK_SET);
- printf("writing CSV1 x y z\n");
- while (fscanf(fpi1,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!= EOF)
- {
- printf("%f,%f,%f,%d,%d,%d\n", x, y, z, r, g, b);
- fprintf(fpo,"%f %f %f\n",x,y,z);
- }
- printf("writing CSV2 x y z\n");
- while (fscanf(fpi2,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!= EOF)
- {
- printf("%f,%f,%f,%d,%d,%d\n", x, y, z, r, g, b);
- fprintf(fpo,"%f %f %f\n",x,y,z);
- }
- fprintf(fpo,"CELLS %ld %ld\n",lines,lines*2);
- for(i=0;i<lines;i++)
- {
- fprintf(fpo,"1 %d\n",i);
- }
- fprintf(fpo,"CELL_TYPES %ld\n",lines);
- for(i=0;i<lines;i++)
- {
- fprintf(fpo,"1\n");
- }
- fprintf(fpo,"POINT_DATA %ld\n",lines);
- fprintf(fpo,"COLOR_SCALARS RGB 3\n");
- fseek(fpi1,0,SEEK_SET);
- fseek(fpi2,0,SEEK_SET);
- while (fscanf(fpi1,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!= EOF)
- {
- fprintf(fpo,"%f %f %f\n",(float)r/255,(float)g/255,(float)b/255);
- }
- while (fscanf(fpi2,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!= EOF)
- {
- fprintf(fpo,"%f %f %f\n",(float)r/255,(float)g/255,(float)b/255);
- }
- fclose(fpi1);
- fclose(fpi2);
- fclose(fpo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement