mirror of https://github.com/ecmwf/eccodes.git
108 lines
8.6 KiB
HTML
108 lines
8.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
|
<title>grib_api: nearest.c</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
<link href="tabs.css" rel="stylesheet" type="text/css">
|
|
</head><body>
|
|
<!-- Generated by Doxygen 1.5.3 -->
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<h1>nearest.c</h1>nearest.c How to find the nearest grid points.<p>
|
|
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
|
|
<a name="l00010"></a>00010 <span class="comment">/*</span>
|
|
<a name="l00011"></a>00011 <span class="comment"> * C Implementation: fieldset</span>
|
|
<a name="l00012"></a>00012 <span class="comment"> *</span>
|
|
<a name="l00013"></a>00013 <span class="comment"> * Description: how to use a fieldset.</span>
|
|
<a name="l00014"></a>00014 <span class="comment"> *</span>
|
|
<a name="l00015"></a>00015 <span class="comment"> *</span>
|
|
<a name="l00016"></a>00016 <span class="comment"> * Author: Enrico Fucile</span>
|
|
<a name="l00017"></a>00017 <span class="comment"> *</span>
|
|
<a name="l00018"></a>00018 <span class="comment"> *</span>
|
|
<a name="l00019"></a>00019 <span class="comment"> */</span>
|
|
<a name="l00020"></a>00020
|
|
<a name="l00021"></a>00021 <span class="preprocessor">#include <stdio.h></span>
|
|
<a name="l00022"></a>00022 <span class="preprocessor">#include <stdlib.h></span>
|
|
<a name="l00023"></a>00023 <span class="preprocessor">#include <string.h></span>
|
|
<a name="l00024"></a>00024
|
|
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="grib__api_8h.html" title="Copyright 2005-2013 ECMWF.">grib_api.h</a>"</span>
|
|
<a name="l00026"></a>00026
|
|
<a name="l00027"></a>00027 <span class="keywordtype">void</span> usage(<span class="keywordtype">char</span>* prog) {
|
|
<a name="l00028"></a>00028 printf(<span class="stringliteral">"Usage: %s grib_file grib_file ...\n"</span>,prog);
|
|
<a name="l00029"></a>00029 exit(1);
|
|
<a name="l00030"></a>00030 }
|
|
<a name="l00031"></a>00031
|
|
<a name="l00032"></a>00032 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv) {
|
|
<a name="l00033"></a>00033 <span class="keywordtype">int</span> err = 0;
|
|
<a name="l00034"></a>00034 <span class="keywordtype">long</span> step=0;
|
|
<a name="l00035"></a>00035 <span class="keywordtype">size_t</span> nfiles;
|
|
<a name="l00036"></a>00036 <span class="keywordtype">int</span> i=0;
|
|
<a name="l00037"></a>00037 grib_fieldset* <span class="keyword">set</span>=NULL;
|
|
<a name="l00038"></a>00038 <a name="a0"></a><a class="code" href="group__grib__handle.html#g309a5ee24f4c730646d3f80ad0ef5f1b">grib_handle</a>* h=NULL;
|
|
<a name="l00039"></a>00039 <span class="keywordtype">char</span> param[20]={0,};
|
|
<a name="l00040"></a>00040 <span class="keywordtype">size_t</span> len=20;
|
|
<a name="l00041"></a>00041 <span class="keywordtype">double</span> lats[4]={0,};
|
|
<a name="l00042"></a>00042 <span class="keywordtype">double</span> lons[4]={0,};
|
|
<a name="l00043"></a>00043 <span class="keywordtype">double</span> values[4]={0,};
|
|
<a name="l00044"></a>00044 <span class="keywordtype">double</span> distances[4]={0,};
|
|
<a name="l00045"></a>00045 <span class="keywordtype">int</span> indexes[4]={0,};
|
|
<a name="l00046"></a>00046 <span class="keywordtype">char</span>* order_by=<span class="stringliteral">"param,step"</span>;
|
|
<a name="l00047"></a>00047
|
|
<a name="l00048"></a>00048 <span class="keywordtype">size_t</span> size=4;
|
|
<a name="l00049"></a>00049 <span class="keywordtype">double</span> lat=-40,lon=15;
|
|
<a name="l00050"></a>00050 <span class="keywordtype">int</span> mode=0;
|
|
<a name="l00051"></a>00051 <span class="keywordtype">int</span> count;
|
|
<a name="l00052"></a>00052 <span class="keywordtype">char</span>** filenames;
|
|
<a name="l00053"></a>00053 <a name="a1"></a><a class="code" href="grib__api_8h.html#1b47558cfe02835ba44213ee4d45fd9b">grib_nearest</a>* nearest=NULL;
|
|
<a name="l00054"></a>00054
|
|
<a name="l00055"></a>00055 <span class="keywordflow">if</span> (argc < 2) usage(argv[0]);
|
|
<a name="l00056"></a>00056
|
|
<a name="l00057"></a>00057 nfiles=argc-1;
|
|
<a name="l00058"></a>00058 filenames=(<span class="keywordtype">char</span>**)malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*)*nfiles);
|
|
<a name="l00059"></a>00059 <span class="keywordflow">for</span> (i=0;i<nfiles;i++)
|
|
<a name="l00060"></a>00060 filenames[i]=(<span class="keywordtype">char</span>*)strdup(argv[i+1]);
|
|
<a name="l00061"></a>00061
|
|
<a name="l00062"></a>00062 <span class="keyword">set</span>=grib_fieldset_new_from_files(0,filenames,nfiles,0,0,0,order_by,&err);
|
|
<a name="l00063"></a>00063 GRIB_CHECK(err,0);
|
|
<a name="l00064"></a>00064
|
|
<a name="l00065"></a>00065 printf(<span class="stringliteral">"\nordering by %s\n"</span>,order_by);
|
|
<a name="l00066"></a>00066 printf(<span class="stringliteral">"\n%d fields in the fieldset\n"</span>,grib_fieldset_count(<span class="keyword">set</span>));
|
|
<a name="l00067"></a>00067 printf(<span class="stringliteral">"n,step,param\n"</span>);
|
|
<a name="l00068"></a>00068
|
|
<a name="l00069"></a>00069 mode=GRIB_NEAREST_SAME_GRID | GRIB_NEAREST_SAME_POINT;
|
|
<a name="l00070"></a>00070 count=1;
|
|
<a name="l00071"></a>00071 <span class="keywordflow">while</span> ((h=grib_fieldset_next_handle(<span class="keyword">set</span>,&err))!=NULL) {
|
|
<a name="l00072"></a>00072 GRIB_CHECK(<a name="a2"></a><a class="code" href="group__get__set.html#g03cfa6762312face1a3cc3ef23e16526" title="Get a long value from a key, if several keys of the same name are present, the last...">grib_get_long</a>(h,<span class="stringliteral">"step"</span>,&step),0);
|
|
<a name="l00073"></a>00073 len=20;
|
|
<a name="l00074"></a>00074 GRIB_CHECK(<a name="a3"></a><a class="code" href="group__get__set.html#g8aeaf9f930eea1cc0f15e92f18a25053" title="Get a string value from a key, if several keys of the same name are present, the...">grib_get_string</a>(h,<span class="stringliteral">"param"</span>,param,&len),0);
|
|
<a name="l00075"></a>00075
|
|
<a name="l00076"></a>00076 printf(<span class="stringliteral">"%d %ld %s "</span>,count,step,param);
|
|
<a name="l00077"></a>00077 <span class="keywordflow">if</span> (!nearest) nearest=<a name="a4"></a><a class="code" href="group__iterators.html#g4bd616cf0d0c4f5f147f4a207ddc7687" title="Create a new nearest from a handle, using current geometry .">grib_nearest_new</a>(h,&err);
|
|
<a name="l00078"></a>00078 GRIB_CHECK(err,0);
|
|
<a name="l00079"></a>00079 GRIB_CHECK(<a name="a5"></a><a class="code" href="group__iterators.html#g15043a2482608fb93a0385f3c3e86926" title="Find the 4 nearest points of a latitude longitude point.">grib_nearest_find</a>(nearest,h,lat,lon,mode,lats,lons,values,distances,indexes,&size),0);
|
|
<a name="l00080"></a>00080 <span class="keywordflow">for</span> (i=0;i<4;i++) printf(<span class="stringliteral">"%d %.2f %.2f %g %g - "</span>,
|
|
<a name="l00081"></a>00081 (<span class="keywordtype">int</span>)indexes[i],lats[i],lons[i],distances[i],values[i]);
|
|
<a name="l00082"></a>00082 printf(<span class="stringliteral">"\n"</span>);
|
|
<a name="l00083"></a>00083
|
|
<a name="l00084"></a>00084 <a name="a6"></a><a class="code" href="group__grib__handle.html#g0e4b2585f22247c49b930c1579257677" title="Frees a handle, also frees the message if it is not a user message.">grib_handle_delete</a>(h);
|
|
<a name="l00085"></a>00085 count++;
|
|
<a name="l00086"></a>00086 }
|
|
<a name="l00087"></a>00087
|
|
<a name="l00088"></a>00088 <span class="keywordflow">if</span> (nearest) <a name="a7"></a><a class="code" href="group__iterators.html#g2b3c0069013e1ad7b3e34f30b4659c15" title="Frees an nearest from memory.">grib_nearest_delete</a>(nearest);
|
|
<a name="l00089"></a>00089
|
|
<a name="l00090"></a>00090 <span class="keywordflow">if</span> (<span class="keyword">set</span>) grib_fieldset_delete(<span class="keyword">set</span>);
|
|
<a name="l00091"></a>00091
|
|
<a name="l00092"></a>00092 <span class="keywordflow">return</span> 0;
|
|
<a name="l00093"></a>00093 }
|
|
</pre></div> <hr size="1"><address style="text-align: right;"><small>Generated on Tue Sep 22 15:18:21 2009 for grib_api by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
|
|
</body>
|
|
</html>
|