yamaji14

polygon_analysis

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