Advertisement
yamaji14

vector-txt2bin

Jan 23rd, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 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,*fpw1,*fpw2;  //file pointer for input&output file
  13.         float dn1,dn2,dn3;
  14.         unsigned char dn4,dn5;
  15.  
  16.        
  17.        
  18.     /*****************************************************
  19.          2.command line arguments processing
  20.          ******************************************************/
  21.         if(argc!=4)
  22.         {
  23.                 fprintf(stderr,"Usage: %s (1)input_org.txt\n(2)write_xyz FILENAME\n",argv[0]);
  24.                 exit(1);
  25.         }
  26.         printf("OPEN FILE NAME:%s\n",argv[1]);
  27.        
  28.         /**********************************************************************************
  29.          **********************************************************************************
  30.          4.  FILE OPEN + Binary File Input
  31.          **********************************************************************************
  32.          *************************************************************************************/
  33.        
  34.         // open input file
  35.         if((fpr=fopen(argv[1],"r"))==NULL)
  36.         {
  37.                 printf("ファイルのオープンに失敗しました。プログラムを終了します。\n");
  38.                 exit(1);
  39.         }
  40.        
  41.         //write file
  42.         if((fpw1=fopen(argv[2],"wb"))==NULL)
  43.         {
  44.                 fprintf(stderr,"DSM by GSI データファイル.raw\n");
  45.                 exit(1);
  46.         }
  47.        
  48.         //write file
  49.         if((fpw2=fopen(argv[3],"wb"))==NULL)
  50.         {
  51.                 fprintf(stderr,"DSM by GSI データファイル.raw\n");
  52.                 exit(1);
  53.         }
  54.        
  55.     /*****************************************************
  56.          データの読み取り書き込み
  57.          ******************************************************/
  58.     /* データ処理 */
  59.         while (fscanf(fpr,"%f %f %f %d %d", &dn1,&dn2,&dn3,&dn4,&dn5)!= EOF)
  60.         {      
  61.                
  62.                 fwrite(&dn1,sizeof(float),4,fpw1);
  63.                 fwrite(&dn2,sizeof(float),4,fpw1);
  64.                 fwrite(&dn3,sizeof(float),4,fpw1);
  65.                 fwrite(&dn4,sizeof(char),1,fpw2);
  66.                 fwrite(&dn5,sizeof(char),1,fpw2);
  67.     }
  68.     /* ファイル・クローズ */
  69.         fclose(fpr);
  70.         fclose(fpw1);
  71.         fclose(fpw2);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement