[Gdal-dev] IPCC raster format

Frank Warmerdam warmerdam at pobox.com
Fri Jun 16 11:57:47 EDT 2006


Ivan Lucena wrote:
> Hi there,
> 
>  
> 
> I would rather been watching the World Cup, but I have to get this data 
> in a usable format and there is no better place to get it than from 
> GDAL’s experts.
> 
>  
> 
> The “Intergovernmental Panel on Climate Change” (IPCC) offers data on 
> the web in a format described by this Fortran source code: (The file 
> extension is just a generic “.dat”)
> 
>  
> 
> http://ipcc-ddc.cru.uea.ac.uk/obs/observed_fileformat.html
> 
>  
> 
>>  more cpre0130.dat
> 
>     grd_sz      xmin      ymin      xmax      ymax    n_cols    n_rows  
> n_months
> 
>       0.50      0.25    -89.75    359.75     89.75       720       
> 360        12
> 
>> 
> -9999-9999-9999-9999-9999-9999-9999-9999-9999   52   88  103   91   65   
> 45   27   32 …
> 
> -9999-9999-9999-9999-9999   11   20   22   25   27   26   27   28   31 
>   29   28   30 …
> 
>> 
>  
> 
> It’s not hard to analyze the pattern on the data or the code, so I 
> figured that:
> 
>  
> 
> - It’s an ASCII format;
> 
> - There are two lines of reader (easy to read)
> 
> - Each cell is 5 characters wide;
> 
> - The no-data is “-9999”;
> 
> - There is no separator between cells (what makes my task difficult);
> 
> - It’s a multi-band raster dataset with 12 bands; (720x360x12 cells)
> 
> - I am not sure if positive values can go beyond 9999 (that reminds me 
> COBOL)
> 
>  
> 
> I am heading in the direction of writing a Python+GDAL script to do the 
> task, but I am stuck in how to separate the cells. The Fortran code is 
> doing it in just one command as you can see in the code. I am thing that 
> maybe by using the NumPY stuff embedded in GDAL I could do the same.
> 
>  
> 
> Any Idea? Any experience with this data format?

Ivan,

I think a Python script would be the right approach since there is no
generic ascii driver that could be used for this format.  Since there is
no field separator, I guess you will need to loop through the strings you
read cutting out 5 character chunks of data as substrings.

eg.
   for item_i in range(12):
     item = line[item_i:item_i+5]
     ...

I imagine it would make sense to assemble the data in a Numeric array,
and then push that back with band.WriteArray() or something simmilar.
I was going to point at the gdal2grd.py script as an example, but it
goes the other way ... from gdal format to ascii file.  Perhaps it will
help a bit.  (gdal/pymod/samples/gdal2grd.py)

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list