Use of the C gadget

Source: Internet
Author: User

1. This is a GPS data filtering gadget, the purpose is to filter the GPS data in the non-compliant data, and then converted to JSON data

Requires two gadgets

BERMUDA.C------> Filter certain range of data

GEO2JSON.C------> Convert GPS data to JSON format

Note that you need to establish a connection pipeline between the two files in the executable file

First look at the BERMUDA.C code.

#include <stdio.h>intMain () {floatlatitude; floatlongitude; Charinfo[ the];  while(SCANF ("%f,%f,%79[^\n]", &latitude,&longitude,info) = =3) {                if(Latitude > -&& Latitude < the) {                        if(Longitude >- the&& Longitude <- -) {printf ("%f,%f,%s\n", Latitude,longitude,info); }        }    }        return 0;}

And look at the GEO2JSON.C code.

#include <stdio.h>int  main () {        float  latitude;     float longitude;     Char info[];     int 0 ;    

Puts("data=[");
 while(SCANF ("%f,%f,%79[^\n]", &latitude,&longitude,info) = =3) {                if(started) printf (", \ n"); Elsestarted =1; if(Latitude <-90.0|| Latitude >90.0) {
STDERR is the standard error output, and when an error occurs, the error is not entered in the standard output file, but is output to the foreground fprintf (stderr,"Invalid Latitude:%f\n", latitude); return 2; } if(Longitude <-180.0|| Longitude >180.0) {fprintf (stderr,"Invalid Longitude:%f\n", longitude); return 2; } printf ("Latitude:%f, Longitude:%f, Info: '%s '", Latitude,longitude,info); } puts ("\ n]"); return 0;}

Use the terminal to enter the directory of these two files, execute the command compiled into an executable file

GCC bermuda.c-o Geo2json

Then set up the pipeline incoming data input file everywhere to the file Outpu.json

(./bermuda |./geo2json) <spooky.csv> Output.json

The file content of the input file Spooky.csv is

30.685163,-68.137207, type=Yeti28.304380,-74.575195, type=UFO29.132971,-71.136475, type= Ship28.343065,-62.753906, type=Elvis27.868217,-68.005371, type=Goatsucker30.496017,-73.333740, type=Disappearance26.224447,-71.477051, type=UFO29.401320,-66.027832, type= Ship37.879536,-69.477539, type=Elvis22.705256,-68.192139, type=Elvis27.166695,-87.484131, Type=elvis

The final output file Outpu.json content is

data =[Latitude:30.685163, Longitude:-68.137207, Info:'Type=yeti', Latitude:28.304380, Longitude:-74.575195, Info:'Type=ufo', Latitude:29.132971, Longitude:-71.136475, Info:'type=ship', Latitude:27.868217, Longitude:-68.005371, Info:'Type=goatsucker', Latitude:30.496017, Longitude:-73.333740, Info:'type=disappearance', Latitude:26.224447, Longitude:-71.477051, Info:'Type=ufo', Latitude:29.401320, Longitude:-66.027832, Info:'type=ship']

Use of the C gadget

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.