<div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div><div><div><div>Hi Paolo,<br><br></div>I think that you will need a script. At least in my case, every file has the bands written in a different order, no using directly the band number is not possible. The only way I have found is to read the file metadata using a python script:<br>

<br>------<br><br>from osgeo import gdal<br>from osgeo.gdalconst import GA_ReadOnly<br><br>grib_file = "wrf-03.2013060200_32.grib"<br>variable = "UGRD"<br>level = "950-ISBL"<br><br>dataset = gdal.Open(grib_file, GA_ReadOnly )<br>

<br>for i in range(1,dataset.RasterCount + 1):<br>    band = dataset.GetRasterBand(i)<br>    metadata = band.GetMetadata()<br>    level_band = metadata['GRIB_SHORT_NAME']<br>    variable_band = metadata['GRIB_ELEMENT']<br>

<br>    if level_band == level and variable_band == variable:<br>        bandnum = i<br><br>print bandnum<br><br>------<br><br><br></div>Of course, you have to change the filename, variable and level, and you'll get the band number that fits the conditions. Then, just open this band and do whatever you need.<br>

</div><br></div>I hope that helps.<span class="HOEnZb"><font color="#888888"><br><br>Roger<br></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/6/18 Paolo Corti <span dir="ltr"><<a href="mailto:pcorti@gmail.com" target="_blank">pcorti@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Tue, Jun 18, 2013 at 12:46 AM, Even Rouault<br>
<<a href="mailto:even.rouault@mines-paris.org" target="_blank">even.rouault@mines-paris.org</a>> wrote:<br>
><br>
> From gdal_translate man page:<br>
><br>
>        -b band:<br>
>            Select an input band band for output. Bands are numbered from 1.<br>
> Multiple -b switches may be used to select a set of input bands to write to<br>
> the output file, or<br>
>            to reorder bands. Starting with GDAL 1.8.0, band can also be set to<br>
> 'mask,1' (or just 'mask') to mean the mask band of the first band of the input<br>
> dataset.<br>
<br>
</div>Hey Even<br>
<br>
thanks for the reply.<br>
<br>
I am well aware of the -b option, the problem here is that each raster<br>
has not the same bands order.<br>
Therefore, as I had to make some work on just one single band<br>
representing the same variable in all of the datasets, I ended up to<br>
write a script, iterate the datasets, then iterate the bands, read the<br>
metadata, and when found the correct band ran the process on it.<br>
<br>
thanks a lot in any case<br>
cheers<br>
<div>p<br>
<br>
--<br>
Paolo Corti<br>
Geospatial software developer<br>
web: <a href="http://www.paolocorti.net" target="_blank">http://www.paolocorti.net</a><br>
twitter: @capooti<br>
skype: capooti<br>
</div><div><div>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</div></div></blockquote></div><br></div>
</div></div></div><br></div>