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)csvfile\n(2)csvfile\n(3)vtkfile\n",argv[0]);
- return 0;
- }
- printf("Open CSV File\n");
- //Open CSV1 file
- if((fpi1=fopen (argv[1],"r"))==NULL)
- {
- printf("The file can't opened. The program is exit.\n ");
- return 0;
- }
- printf("Open CSV File\n");
- //Open CSV2 file
- if((fpi2=fopen (argv[2],"r"))==NULL)
- {
- printf("The file can't 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 opened. The program is exit.\n ");
- return 0;
- }
- //count how many lines
- /*
- while((c==fgetc(fpi))!=EOF)
- {
- if(c=='\n')
- newline_count++;
- }
- */
- printf("CSVFile1 Count Lines\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("CSVFile2 Count Lines\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("total_1=%ld\n",newline_count_1);
- printf("total_2=%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