Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // 5m_lem_dem2binary_mac
- //
- // http://www1.gsi.go.jp/geowww/Laser_HP/f5m2.html
- //
- // sample data:
- // http://aitech.ac.jp/~y-yama/data/elv/07nd154.lem.zip
- //
- // Created by yamamoto on 2013/08/29.
- // Copyright (c) 2013年 yamamoto. All rights reserved.
- //
- #include <stdio.h>
- #include <stdlib.h> /*atoi*/
- #include <string.h>
- //main
- int main(int argc,char *argv[])
- {
- FILE *fpi,*fpo; /*File pointer*/
- int i,j,pos_line,data_m;
- char line[6]; /*for text data*/
- short data; //for binary data
- if(argc!=3)
- {
- fprintf(stderr,"Usage: %s 5m_mesh_data.lem,5m_mesh_data.raw\n",argv[0]);
- exit(1);
- }
- printf("OPEN FILE NAME:%s\n",argv[1]);
- if((fpi=fopen(argv[1],"r"))==NULL)
- {
- fprintf(stderr,"Can not open\n");
- exit(1);
- }
- if((fpo=fopen(argv[2],"wb"))==NULL)
- {
- fprintf(stderr,"Can not open\n");
- exit(1);
- }
- for(i=0;i<300;i++)
- {
- fseek(fpi,i*2012+10,SEEK_SET); // Offset
- pos_line=ftell(fpi); //return current position
- // printf("calc_pos=%2ld\n",pos_line); //print current position
- for (j=0;j<400;j++)
- {
- fseek(fpi,5*j+i*2012+10,SEEK_SET); //Offset
- //723 714 715 715 724 741 743 745 747
- fgets(line, 6, fpi); //Reads characters from stream
- data=atoi(line); //convert string to integer
- data_m=(short)data/10; //convert 10cm to m
- if(data_m==-999) //convert values on sea
- {
- data_m=0;
- }
- else
- {
- data_m=data_m;
- }
- // printf("%d\n",data_m);
- fwrite(&data_m,sizeof(short),1,fpo); //write block of data to stream
- }
- }
- fclose(fpi);
- fclose(fpo);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment