How to install g2ctl.pl and wgrib2 in linux

Dear All,

Now we are going to see how to install wgrib2 and g2ctl in our linux machine, for the Grib version 2 data.

step 1:

First of we need to install GRADS

http://grads.iges.org/grads/downloads.html

From the above link we can get the source.

In ubuntu we need to install some dependencies,

$ sudo apt-get install libgrib2c-dev libgrib2c0d (to install wgrib2 correctly)

$ sudo apt-get install grads  (for gribmap)

Note : grads version must be equal or higher than the 2.0.a8 (to work correctly for grib2).

If you are using ubuntu 10.04, then grads may be lower than the above version.

So download the source of grads version 2.0.a8 or higher.

$ sudo apt-get install libxmu-dev libxmu-headers x11-common x11-xserver-utils

Extract that downloaded grads source and change directory into that extracted folder.

$ ./configure

$ make && make install

Now it should be installed in that folder called ‘src’.

You can use this grads, gribmap (inside the src folder of the extracted folder of grads2.0.a8) to use the grib2 version.

$ sudo cp -r src /usr/local/grads2.0.a8

Edit your home .bashrc file, add the following lines.

alias grads=’/usr/local/grads2.0.a8/grads’

alias gribmap=/usr/local/grads2.0.a8/gribmap’

 

step 2:

From the below site we can download the g2ctl.pl perl source code
http://www.cpc.ncep.noaa.gov/products/wesley/g2ctl.html

Look in the bottom of the page.

Try to open all the above links in firefox not in chrome.

Download that g2ctl.pl source code from here ftp://ftp.cpc.ncep.noaa.gov/wd51we/g2ctl/g2ctl  save as g2ctl.pl . If that perl source code has viewed by web page itself means, copy that perl code into one text file, and save that as g2ctl.pl file in your home folder itself.

step 3:

Go to the below link to download the wgrib2 tar file
http://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/

From here you can download the wgrib2.tgz source file in the above link.

Go to this section in the above link “Source Code and Compling Hints” .

Download the “wgrib2.tgz” by http way.

After downloaded the wgrib2.tgz file, extract it either by GUI “Extract here” or

$ tar -zxvf wgrib.gz

It should create directory called “grib2″.

Now move this folder into /usr/bin by

$ sudo mv grib2 /usr/bin/

Now go to that directory by

$ cd /usr/bin/grib2

$ sudo make

It takes few minutes to install wgrib2 inside that folder itself.

Note : now our wgrib2 executable path is ” /usr/bin/grib2/wgrib2/wgrib2 “.

step 4:

Now open the g2ctl.pl file,

  1. Look for the line:
    $wgrib2=’wgrib2′;
    and change it to point to your wgrib2 path. In our case,
    $wgrib2=’/usr/bin/grib2/wgrib2/wgrib2′;
  2. Don’t forget to make the program  as executable (chmod 755 g2ctl.pl) and put it on your PATH. i.e $ sudo chmod 755 g2ctl.pl    and  $ sudo cp g2ctl.pl  /usr/bin/

Thats it … !

Now you can access the g2ctl.pl from the bash shell (terminal) itself.

Try the following usage of g2ctl with your analysis and forecasting binary grib files.

Usage

For analyses:

$ g2ctl.pl -0 grib2_file >grib2_file.ctl    [ here we passed zero option]
$ gribmap -0 -i grib2_file.ctl        [ here we passed zero option]
$ grads
Landscape mode? (no for portrait):
ga-> open grib2_file.ctl 

For forecasts:

$ g2ctl.pl  grib2_file >grib2_file.ctl
$ gribmap -i grib2_file.ctl
$ grads
Landscape mode? (no for portrait):
ga-> open grib2_file.ctl

The main differences between the syntax of grib2ctl.pl and g2ctl.pl are,

  • For grib version 2 files, we are using g2.ctl.pl script to create ctl files. The usage option -0 (zero) are passed for both g2ctl.pl and gribmap commands for analysis files and not for forecast files in the grib version 2.
  • For grib version 1 files, we are using grib2ctl.pl script to create ctl files. The usage option -0 (zero) is passed in gribmap command for analysis files and option -verf is passed in grib2ctl.pl command for forecast files. To know more about grib2ctl.pl script, how to install that and how to use that, click here .

To understand, what is grib and ctl file formate

grib is the one of binary file formate to store the analysis and forecast data in some kind of structured manner.
ctl means control file in ascii formate. we can read it. Both these formates are usually used in atmospheric and meteorological departments.

The generated ctl files can be read and visualized by GRADS , CDAT and other meteorological softwares.

Both Grads and CDAT are open source software.

More over many other foss applications are available for the same kind of stuff.

Thanks,
Arulalan.T

This entry was posted in CDAT and tagged , , , , . Bookmark the permalink.

23 Responses to How to install g2ctl.pl and wgrib2 in linux

  1. Ismoil says:

    Dear Arrulan T.
    I’m starting the command “make && make install” and i’m getting error below:

    gxX.c:20:19: fatal error: cairo.h: No such file or directory
    compilation terminated.

    How can I install this cairo.h? I’m using ubuntu 12.04

    Regards,
    Ismoil

    • arulalant says:

      Better you do, $ sudo apt-get install grads , instead of install it from source.
      It will take care of it. The thing is you need to install cairo package. That also you can install it from sudo apt-get .

  2. Elif YILMAZ says:

    Dear Arrulan T.

    How can I open the grb2. file that had sent from meteorology center in Linux? Is it as above that you explain? And do you know they can opened in windows 7?

    • arulalant says:

      Dear Eyilmaz,

      You can use the above steps to access grib2 files in linux. I documented here on how to install/setup to access grib2 files in Ubuntu distribution. Moreover you can follow the same steps in other linux distros also.

      I never tried / worked in windows. So I do not know how to setup the same in windows.

      Thanks.

  3. goitom says:

    Hello Dear Arulalan.T
    I am using you configuration steps grib2ctl.pl is working for grib1 but when I tray to use it in grib2 it doesn’t work but I install grads 2.0.a9.1 and wgrib2 but is display the following errors.
    bash-4.2$ gribmap -i newforecast.ctl
    grib2map: scanning GRIB2 file: gfs_4_20120601_0000_000.grb2
    grib2map: Writing out the index file

    I am looking your help thank very much for your help

    • arulalant says:

      Hai Goitom.,
      Are you using grib2ctl.pl or g2ctl.pl ? grib2ctl.pl for grib1 version. g2ctl.pl for grib2 version data.
      What error it throws ?

      • goitom says:

        Hello Dear Arulalan.T
        I am using g2ctl.pl and wgrib2 for grib2 , additional i am install wrfems 3.4.1.13.33 this is the shell script
        #! /bin/csh
        cd /home/model/wrfems/runs/ethiopia/emsprd/grib
        set yymmdd = `date +%y%m%d`
        cat *grb2*>gribdata_$yymmdd-2
        mv gribdata_$yymmdd-2 /home/model/ethiowrf/
        cd /home/model/ethiowrf/
        g2ctl.pl -verf gribdata_$yymmdd-2 >grib.ctl
        gribmap -i grib.ctl

        and the error is grib2map: Writing out the index file and the index files are not read by grads

        thanks for your help

        • arulalant says:

          Dear Goitom,
          I dont think this is an error “grib2map: Writing out the index file”. It seems like it info print statement. Is that created idx file correctly or not. Instead of writing csh script to create ctl, idx file for the model data, I suggest that you would have try it by your hand itself.
          Go to the data directory via terminal and give try to create ctl file and the idx file by there itself. So that will give us more way to find out the error. While you opening “ctl” file in Grads, what error it throws ?

          • Goitom says:

            Dear Arulalan.T
            the individual grib2 file are working properly but the cat file “gribdata_$yymmdd-2″ is not working.
            Best regards
            Goitom

            • arulalant says:

              So its not problem with g2ctl.pl. It is problem with “cat *grb2*>gribdata_$yymmdd-2″ command. You have to find the solution for this. I think you can not use cat command for the binary *grb2* files. Try to use cp [copy] instead of cat.
              ” cp *grb2*>gribdata_$yymmdd-2″.
              If this also fails means you have to find the solution.
              Thanks.

  4. tony says:

    Hi.
    I work with:
    step 3:
    Go to the below link to download the wgrib2 tar file……
    ….
    .. but help me with the data http://nomads.ncdc.noaa.gov/data/cfsr-rfl-mmts/oceansst/, but no file.idx.
    In GrADS:
    clima@lluvia:~/CFSv2$ perl g2ctl oceansst.ensm.jan.cfsv2.data.grb2 >oceansst.ensm.jan.cfsv2.ctl
    clima@lluvia:~/CFSv2$ gribmap -i oceansst.ensm.jan.cfsv2.ctl
    grib2map: scanning GRIB2 file: oceansst.ensm.jan.cfsv2.data.grb2
    grib2map: Writing out the index file
    Thanks

  5. quangtuan says:

    Dear Arulalan.T
    How to install wgrib2 in Windows XP?

    • arulalant says:

      Dear Quangtuan,

      I never tried to install grib2ctl in windows.

      First of all you need to install perl and perl dependencies packages in windows.

      Then you need to install wgrib package also in your windows.

      Finally grib2ctl.pl … But I dont know how to install all the above successfully in windows.

      Switch to Free Open Source OS / Linux / Ubuntu !

      • Adem says:

        Dear Arulalant,
        Do you have a similar step by step procedure for installation of wgrib2 in Windows 7?
        How can I install wgrib2 in Windows 7?
        Many thanks
        Adem

  6. jo says:

    hi, you have same step by step procedure for installation in Windows?

  7. leeladam says:

    Thanks for the great tutorial, you saved me a lot of googling!
    A note: I had to create a symbolic link after step 3 to make my system recognize the wgrib2 command:
    sudo ln -s /usr/bin/grib2/wgrib2/wgrib2 /usr/bin

  8. Andres Duque says:

    Thank you very much, saved my life
    Greetings from Colombia

  9. Naresh Krishna vissa says:

    Thank you very much
    for the useful information
    regards
    naresh

  10. miquel says:

    Many thanks, it worked allright!
    Miquel
    Spain

    • Adem says:

      Dear Arulalant,
      Do you have a similar step by step procedure for installation of wgrib2 in Windows 7?
      How can I install wgrib2 in Windows 7?
      Many thanks
      Adem

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s