Saturday, September 19, 2015

Parsing and splitting openstreetmap file [ C ]


Its quite bizarre to me, more I'm trying to friendly with string / character processing with C programming, they are showing their envy to me.

I was/am need to split a / any big osm file to three parts, NODE, WAY and RELATION. You can do that by giving line number range to program. But I want to get the line number automatically.

This was seems very easy, just counting the new line till getting required string, i.e. <way id=

So I wrote,

 char way_compare[] = "<way id=";  
 FILE *fp = fopen("Kiel.osm", "r");  
 char ckchr[10];  
 int count_line=1;  
 char chr = getc(fp);  
 while(chr != EOF)  
   {  
   if(chr == '\n')  
     {  count_line++;  
       fgets(ckchr, 10, fp);  
       if(!strcmp(way_compare,ckchr))  
         { break; }  
     }  
     chr = getc(fp);  
   }  
   printf("Searched: %s found at %d\n",way_compare,count_line);  

Wednesday, September 2, 2015

Reading between two given line number of a File


 It is sometimes very important, to let program to read a big file only some specific part/s.

For example, I was and still trying with Openstreetmap with readosm library. Which really need such option.

As .OSM file is quite a large and readosm does read every single bit of the file, on other hand my projected implementation hardware is quite low in resources, badly needed to optimize readosm reading style.

I'd and still have a plan of doing indexing for .OSM file and apply program to read according it.

To do so, here comes the first part of virtually slicing the .OSM file and apply to program to read by given lines between.

My program is an extension of
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file

Wednesday, August 26, 2015

Simple thing but difficult to find [ALSA wav file]


I was in need of ALSA and honestly, I'd just few testing style programming of it long before.

It need to take wav file as input and do a playback of that file using ALSA. However, I need to learn it form scratch, though to find any suitable example according how I can handle wav file to send as ALSA PCM playback, was difficult.

So I wish to write some explanation of it here, and will try to exclude those what you can find and learn by a short googling.

Below part, I presume you already know, or if you don't, I found -

http://www.linuxjournal.com/article/6735?page=0,0

         is the best and most informative.

Wednesday, August 12, 2015

GEO-Search - Faster approch between two point


Previous post, I port the calculation and formula from Federico

My search bring me another solution, which is more faster than previous ->

Below it is, [This one calculate for Kilometre]
  
struct arg_max_min_lo_lt

{
    double min_long;

    double min_lat;

    double max_long;

    double max_lat;
}; 

struct arg_max_min_lo_lt get_lo_lt_values()

{

        int eRadius = 12742;

        float radius=5;

        struct arg_max_min_lo_lt m_lo_lt_ptr;

        //each degree of lon or lat is approximately 69 miles or 111 kilometres difference

        double denominator = cos(deg2rad(curr_lat)) * 111;

        m_lo_lt_ptr.min_long = curr_long - (radius / denominator );

        m_lo_lt_ptr.max_long = curr_long + (radius / denominator );

        m_lo_lt_ptr.min_lat = curr_lat - (double)radius / 111;

        m_lo_lt_ptr.max_lat = curr_lat + (double)radius / 111;

        return m_lo_lt_ptr;

}

Friday, August 7, 2015

GEO-Search: The Haversine Equation


To calculate longitude & latitude of an area easiest way is to calculate The "Haversine Equation".
Implementation of this equation in various programming language was done at here ->

http://blog.fedecarg.com/2009/02/08/geo-proximity-search-the-haversine-equation/

I port it in basic C programming ->


 #include <stdio.h>  
 #include <math.h>  
 double deg2rad(double lat);  
 int main()  
 {  
 double curr_long=-2.708077,curr_lat = 53.754842;  
 int radius=20;  
 double denominator = cos(deg2rad(curr_lat)) * 69;  // 69 as calculation in Mile
 double min_long = curr_long - (radius / denominator );  
 double max_long = curr_long + (radius / denominator );  
 double min_lat = curr_lat - (double)radius / 69;  
 double max_lat = curr_lat + (double)radius / 69;  
 printf("Minimum Longitude :%1.9f\nMaximum Longitude: %1.9f\n",min_long,max_long);  
 printf("Minimum Latitude :%1.9f\nMaximum Latitude: %1.9f\n",min_lat,max_lat);  
 return 0;  
 }  
 double deg2rad(double lat)  
 {  
 return 0.0174532925*lat;  
 }  

Wednesday, July 29, 2015

Eat insect - UN said.

So far I know and can guess there's million or could be billion of dollars are set on budget as expense for entertainment [food] for guest coming/working/visiting any / one UN office round the world. Current new advice came on board from UN to eat insect in order to have proper nutrition and to minimize food scarcity.

    http://www.un.org/apps/news/story.asp?NewsID=44886#.VbiQIrWQlTU

Lets have some hypothesis of such FOOD SCARCITY ->

1. In 2012 - 2013 total UN approved budget was $5.152 B.

    http://www.un.org/en/hq/dm/pdfs/oppba/Regular%20Budget.pdf

2. If 2% of total amount has been used for food & related stuff (UN offices, for employee and guests) - $103.04 Million is in total.

3. Average annual budget for UNESCO is $326 Million. However due to US suspension of funding UNESCO is in shortfall of $188 Million.

So, we can make a corollary as, if UN follows its report, its possible to cover 60% of US contribution to UNESCO, which ensure better living with education, science and diversity.

Tuesday, July 28, 2015

Schleswig-Holstein & North Sea Tour


Last Sunday, actually a lot to do, but I cought with lazy disease. I can't sit, I can't type, I can't read, even I can't concentrate to movie - so I made Schleswig Holstein tour. And honestly speaking, I'm cured from disease.

My first stop was in Friedrichstadt, a very little Town, about 400 years old. Friedrichstadt is established by Dutch settler, and made it a little Netherlands with Canals and Dutch style buildings.

Interesting thing about the city is, it started with population more / less 2500 inhabitant and for decades maintain it, however still total inhabitant is around 2500.