Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int main(int argc,char *argv[])
- {
- /*****************************************************
- 1.Definition of Variables
- ******************************************************/
- FILE *fpr,*fpw1,*fpw2; //file pointer for input&output file
- float dn1,dn2,dn3;
- unsigned char dn4,dn5;
- /*****************************************************
- 2.command line arguments processing
- ******************************************************/
- if(argc!=4)
- {
- fprintf(stderr,"Usage: %s (1)input_org.txt\n(2)write_xyz FILENAME\n",argv[0]);
- exit(1);
- }
- printf("OPEN FILE NAME:%s\n",argv[1]);
- /**********************************************************************************
- **********************************************************************************
- 4. FILE OPEN + Binary File Input
- **********************************************************************************
- *************************************************************************************/
- // open input file
- if((fpr=fopen(argv[1],"r"))==NULL)
- {
- printf("ファイルのオープンに失敗しました。プログラムを終了します。\n");
- exit(1);
- }
- //write file
- if((fpw1=fopen(argv[2],"wb"))==NULL)
- {
- fprintf(stderr,"DSM by GSI データファイル.raw\n");
- exit(1);
- }
- //write file
- if((fpw2=fopen(argv[3],"wb"))==NULL)
- {
- fprintf(stderr,"DSM by GSI データファイル.raw\n");
- exit(1);
- }
- /*****************************************************
- データの読み取り書き込み
- ******************************************************/
- /* データ処理 */
- while (fscanf(fpr,"%f %f %f %d %d", &dn1,&dn2,&dn3,&dn4,&dn5)!= EOF)
- {
- fwrite(&dn1,sizeof(float),4,fpw1);
- fwrite(&dn2,sizeof(float),4,fpw1);
- fwrite(&dn3,sizeof(float),4,fpw1);
- fwrite(&dn4,sizeof(char),1,fpw2);
- fwrite(&dn5,sizeof(char),1,fpw2);
- }
- /* ファイル・クローズ */
- fclose(fpr);
- fclose(fpw1);
- fclose(fpw2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement