source: trunk/SRC/ToBeReviewed/LECTURE/GRIB/read_grib_bds.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1;+
2; @file_comments
3;
4; @categories
5;
6; @param NUM
7;
8; @param RECSTART
9;
10; @param NI
11;
12; @param NJ
13;
14; @returns
15;
16; @restrictions
17;
18; @examples
19;
20; @history
21;
22; @version
23; $Id$
24;-
25FUNCTION read_grib_bds, num, recstart, ni, nj
26;
27  compile_opt idl2, strictarrsubs
28;
29  offset = recstart+8
30  a = assoc(num, bytarr(1, /nozero), offset-1)
31  sizepds = bit2int([binary(a[1]), binary(a[2]), binary(a[3])])
32  flag = binary(a[8])
33  gdsnotomitted = flag[0]
34  bmsnotomitted = flag[1]
35  ddd =  bit2int([binary(a[27]), binary(a[28])], /checkneg)
36;
37  offset = offset+sizepds
38;
39  IF gdsnotomitted THEN BEGIN
40    a = assoc(num, bytarr(1, /nozero), offset-1)
41    sizedds = bit2int([binary(a[1]), binary(a[2]), binary(a[3])])
42    offset = offset+sizedds
43  ENDIF
44;
45  IF bmsnotomitted THEN BEGIN
46    a = assoc(num, bytarr(1, /nozero), offset-1)
47    sizebms = bit2int([binary(a[1]), binary(a[2]), binary(a[3])])
48    offset = offset+sizebms
49  ENDIF
50;
51  a = assoc(num, bytarr(1, /nozero), offset-1)
52;
53  sizebds = bit2int([binary(a[1]), binary(a[2]), binary(a[3])])
54                                ;
55  flags = binary(a[4])
56; BIT VALUE MEANING
57; 1   0     Grid point data
58;     1     Spherical Harmonic Coefficients
59; 2   0     Simple packing
60;     1     Second order ("Complex") Packing
61; 3   0     Original data were floating point values
62;     1     Original data were integer values
63; 4   0     No additional flags at octet 14
64;     1     Octet 14 contains flag bits 5 - 12
65; 5         Reserved (set to 0)
66; 6   0     Single datum at each grid point
67;     1     Matrix of values at each grid point
68; 7   0     No secondary bit maps
69;     1     Secondary bit maps present
70; 8   0     Second order values have constant width
71;     1     Second order values have different widths
72; 9-12      Reserved (set to 0)
73;
74  eee = bit2int([binary(a[5]), binary(a[6])], /checkneg)
75;
76  aaa = bit2int(binary(a[7]), /checkneg)
77  bbb = bit2int([binary(a[8]), binary(a[9]), binary(a[10])])
78  IF aaa LT 0 THEN rrr = -2.^(-24) * bbb * 16.^(-aaa-64) $
79  ELSE rrr = 2.^(-24) * bbb * 16.^(aaa-64)
80;
81  nbits = (a[11])[0]
82  CASE 1 OF
83    flags[0] EQ 0 AND flags[1] EQ 0:BEGIN
84      CASE nbits OF
85        8 :a = assoc(num, bytarr(ni, nj, /nozero), offset-1+12)
86        16:a = assoc(num, uintarr(ni, nj, /nozero), offset-1+12)
87        32:a = assoc(num, ulonarr(ni, nj, /nozero), offset-1+12)
88        64:a = assoc(num, ulon64arr(ni, nj, /nozero), offset-1+12)
89        ELSE:
90      ENDCASE
91    END
92  ENDCASE
93
94  RETURN, (rrr+(a[0]*2.^(eee)))*10.^(-ddd)
95END
Note: See TracBrowser for help on using the repository browser.