wgrib讀grib數據


該文章來自博客:http://windforestwing.blog.163.c ... 412007103084743804/如有錯誤 ,大家及時指出啊!ps:meteoinfo可以直接處理grib數據
===========================

grib格式轉換心得

1、wgrib的使用

在cmd命令行下鍵入wgrib后即可察看wgrib相關命令參數,簡要介紹如下:

l        Inventory/diagnostic–output selections 詳細目錄或診斷的輸出選擇

-s                 short inventory 簡短目錄

-v                 verbose inventory 詳細目錄

-V                 diagnostic output <not inventory> 診斷輸出

<none>        regular inventory 一般目錄

例如:wgrib E:\GrADS\Data\grib2005071500 –v>a.txt

       Options 相關選項

       -PDS/-PDS10                    print PDS in hex/decimal

十六進制或二進制繪制PDS圖

       -GDS/-GDS10                  print GDS in hex/decimal

十六進制或二進制繪制GDS圖

       -verf                                  print forecast verification time

       -ncep_opn/-ncep_rean       default T62 NCEP grib table

       -4yr                                    print year using 4 digits

l        Decoding GRIB selection      GRIB格式解碼選項

-d [record number|all]       decode record number

按編號輸出數據

-p [byte position]               decode record at byte position

按二進制位置輸出數據

-i                                        decode controlled by stdin <inventory list>

                                                 按輸入流控制編碼,一般轉化Grib文件都要加

<none>                              no decoding

Options 相關選項

       -text/-ieee/-grib/-bin          conver to text/ieee/grib/bin

                                                        轉化格式控制

-nh/-h                        output will have no headers/headers

                                                 是否包含標題頭

-H                                     output will include PDS and GDS <-bin/-ieee only>

                                                 輸出否否包含PDS和GDS

-append                             append to output file

                                                 在輸出文件上添加而不是替換

-o [file]                              output file name, ‘dump’ is default

                                                 輸出文件名

綜合使用實例:

DOS命令行下:

>wgrib grib_file_name | find “:GAP:” | wgrib grib_file_name –i –nh –text –o temp

linux shell命令行下:

% wgrib grib_file_name | grep “:GAP:” | wgrib grib_file_name –i –nh –text –o temp

從Grib格式文件中選擇GAP參數相關的數據生成名為temp的文本文件

2、 Grib文件目錄說明

l      wgrib –s生成目錄:

1:0:d=05071500:HGT:1000 mb:anl:NAve=0

1)        記錄號

2)        二進制位置

3)        時間

4)        參數名稱

5)        層次值

6)        analysis分析數據,也可能是fcst(forecast 預報數據)

7)        用於求平均的格點數

l      wgrib –v 生成目錄:

1:0:D=2005071500:HGT:1000 mb:kpds=7,100,1000:anl:"Geopotential height [gpm]

1)        記錄號

2)        二進制位置

3)        時間

4)        參數名稱

5)        層次值

6)        kpds,第一個數字是Grib參數編號,比如PRES是1,TMP是11;第二個數字是層次類型(高度層或等壓面層);第三個數字是層次值;

7)        analysis分析數據,也可能是fcst(forecast 預報數據)

8)        該參數的解釋及單位

l      wgrib –V 生成目錄:

rec 1:0:date 2005071500 HGT kpds5=7 kpds6=100 kpds7=1000 levels=(3,232) grid=3 1000 mb anl:

   HGT=Geopotential height [gpm]

   timerange 10 P1 0 P2 0 TimeU 1  nx 360 ny 181 GDS grid 0 num_in_ave 0 missing 0

   center 7 subcenter 0 process 82 Table 2

   latlon: lat  90.000000 to -90.000000 by 1.000000  nxny 65160

          long 0.000000 to -1.000000 by 1.000000, (360 x 181) scan 0 mode 128 bdsgrid 1

   min/max data -631 334  num bits 14  BDS_Ref -6310  DecScale 1 BinScale 0

這個綜合幾種兩種目錄顯示目前只能看明白其中一部分……

l        wgrib <none> 生成目錄:

1:0:d=05071500:HGT:kpds5=7:kpds6=100:kpds7=1000:TR=10:P1=0:P2=0:TimeU=1:1000 mb:anl:NAve=0

1)        記錄號

2)        二進制位置

3)        時間

4)        參數名稱

5)        Grib參數編號,比如PRES是1,TMP是11

6)        層次類型(高度層或等壓面層)

7)        層次值

8)        時間范圍

9)        時間1的時段

10)    時間2的時段

11)    預報時間單位

12)    層次值

13)    analysis分析數據,也可能是fcst(forecast 預報數據)

14)    用於求平均的格點數

3、 利用C程序轉化Grib格式文件與讀取Grib文件

C# 實例(Web平台上)

    /*調用Dos命令實現Grib文件到Text文件的轉換*/

    private void GribToText()

    {

        Process process = new Process();

        process.StartInfo.FileName = "cmd.exe";

        process.StartInfo.UseShellExecute = false;

        process.StartInfo.RedirectStandardInput = true;

        process.StartInfo.RedirectStandardOutput = true;

        process.StartInfo.CreateNoWindow = true;    //不創建窗口

        process.Start();

        string command = "wgrib E:\\Projects\\AtmosData\\grib2005071500 | find \":5WAVA:\" | wgrib E:\\Projects\\AtmosData\\grib2005071500 -i -nh -text -o E:\\Projects\\AtmosData\\temp";

        process.StandardInput.WriteLine(command);   //調用Dos命令

        process.StandardInput.WriteLine("exit");

        process.WaitForExit();

        string output = process.StandardOutput.ReadToEnd();

        Response.Write(output); //將執行結果輸出

}

/*將Text文件中的Grib數據讀入臨時數組*/

    private void ReadTextData()

    {

        StreamReader GribText = new StreamReader("E:\\Projects\\AtmosData\\temp");

 

        string[] aryReadResult = new string[65160];     //360*181個格點數據

        float[] aryData = new float[65160];

 

        for (int i = 0; i < 1000; i++)

        {

            aryReadResult = GribText.ReadLine();

            aryData = Convert.ToSingle(aryReadResult);

        }

 

        GribText.Close();

    }

C++實例(控制台下)

/*調用DOS命令將Grib文件轉化為臨時文本文件*/

     system("wgrib E:\\Projects\\AtmosData\\grib2005071500 | find \":5WAVA:\" | wgrib E:\\Projects\\AtmosData\\grib2005071500 -i -nh -text -o E:\\Projects\\AtmosData\\temp");

 

/*使用文件輸入輸出流將text文件讀入數組中*/

     FILE *fp;

     long int i;

    float wava[65160] ={0};

    char *path ="E:\\Projects\\AtmosData\\temp";

    if((fp=fopen(path,"r")) == NULL)

     {

         printf("Can not open file!");

         exit(1);

     }

     for( i=0; i<GRIBNUMBER; i++)

     {

         fscanf_s(fp,"%f",&wava);

     }

     for( i=0; i<GRIBNUMBER; i++)printf("%f ",wava);

     fclose(fp);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM