ait-survey

5m_lem_dem2binary

Sep 4th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  5m_lem_dem2binary_mac
  4. //
  5. //  http://www1.gsi.go.jp/geowww/Laser_HP/f5m2.html
  6. //
  7. //  sample data:
  8. //  http://aitech.ac.jp/~y-yama/data/elv/07nd154.lem.zip
  9. //
  10. //  Created by yamamoto on 2013/08/29.
  11. //  Copyright (c) 2013年 yamamoto. All rights reserved.
  12. //
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>               /*atoi*/
  16. #include <string.h>
  17.  
  18.  
  19. //main
  20. int main(int argc,char *argv[])
  21. {
  22.     FILE *fpi,*fpo;            /*File pointer*/
  23.     int i,j,pos_line,data_m;  
  24.     char line[6];              /*for text data*/
  25.     short data;     //for binary data
  26.    
  27.     if(argc!=3)
  28.     {
  29.         fprintf(stderr,"Usage: %s 5m_mesh_data.lem,5m_mesh_data.raw\n",argv[0]);
  30.         exit(1);
  31.     }
  32.      printf("OPEN FILE NAME:%s\n",argv[1]);
  33.    
  34.         if((fpi=fopen(argv[1],"r"))==NULL)
  35.     {
  36.             fprintf(stderr,"Can not open\n");
  37.             exit(1);
  38.         }
  39.    
  40.     if((fpo=fopen(argv[2],"wb"))==NULL)
  41.     {
  42.              fprintf(stderr,"Can not open\n");
  43.             exit(1);
  44.      }
  45.    
  46.         for(i=0;i<300;i++)
  47.     {
  48.         fseek(fpi,i*2012+10,SEEK_SET);     // Offset
  49.         pos_line=ftell(fpi);                 //return current position
  50.         //  printf("calc_pos=%2ld\n",pos_line);  //print current position
  51.         for (j=0;j<400;j++)
  52.         {
  53.             fseek(fpi,5*j+i*2012+10,SEEK_SET); //Offset
  54.  
  55.             //723  714  715  715  724  741  743  745  747
  56.             fgets(line, 6, fpi);       //Reads characters from stream
  57.             data=atoi(line);           //convert string to integer
  58.             data_m=(short)data/10;     //convert 10cm to m
  59.             if(data_m==-999)           //convert values on sea
  60.             {
  61.                 data_m=0;
  62.             }
  63.            
  64.             else
  65.             {
  66.                 data_m=data_m;
  67.             }
  68.             //  printf("%d\n",data_m);
  69.             fwrite(&data_m,sizeof(short),1,fpo); //write block of data to stream
  70.         }
  71.     }
  72.    
  73.     fclose(fpi);
  74.     fclose(fpo);
  75.    
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment