ait-survey

3colors_to_1_color.c

Feb 21st, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. /***************************************************************************:::
  2. 3colors_to_1
  3.  
  4.  convert csv to raw
  5.  read
  6.  2015/11/07
  7.  made by Yoshiyuki Yamamoto
  8.  ver1.1 2009/3/7
  9.  *******************************************************************************/
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <math.h>
  14.  
  15. int main(int argc,char *argv[])
  16. {
  17.        
  18.     /*****************************************************
  19.          1.Definition of Variables
  20.          ******************************************************/
  21.     FILE *fpr,*fpw;  //file pointer for input&output file
  22.  
  23.     int color;//
  24.     int dn1,dn2,dn3,dn4,dn5;
  25.     unsigned char r,g,b;
  26.     float x,y,z;
  27.  
  28.  
  29.  
  30.        
  31.        
  32.     /*****************************************************
  33.          2.command line arguments processing
  34.          ******************************************************/
  35.     if(argc!=3)
  36.     {
  37.         fprintf(stderr,"Usage: %s (1)input_org.txt\n(2)write_xyz FILENAME\n",argv[0]);
  38.             exit(1);
  39.     }
  40.         printf("OPEN FILE NAME:%s\n",argv[1]);
  41.        
  42.         /**********************************************************************************
  43.          **********************************************************************************
  44.          4.  FILE OPEN + Binary File Input
  45.          **********************************************************************************
  46.          *************************************************************************************/
  47.        
  48.         // open input file
  49.     if((fpr=fopen(argv[1],"r"))==NULL)
  50.   {
  51.             printf("ファイルのオープンに失敗しました。プログラムを終了します。\n");
  52.             exit(1);
  53.   }
  54.        
  55.         //write file
  56.     if((fpw=fopen(argv[2],"wb"))==NULL)
  57.    {
  58.                 fprintf(stderr,"DSM by GSI データファイル.raw\n");
  59.                 exit(1);
  60.         }
  61.        
  62.     /*****************************************************
  63.          データの読み取り書き込み
  64.          ******************************************************/
  65.     /* データ処理 */
  66.     while (fscanf(fpr,"%f %f %f %d %d %d", &x,&y,&z,&r,&g,&b)!= EOF)
  67.         {
  68.                 color=1000000*r+1000*g+b;
  69.                 fprintf(fpw,"%f %f %f %d\n",x,y,z,color);
  70.     }
  71.     /* ファイル・クローズ */
  72.         fclose(fpr);
  73.       fclose(fpw);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment