;+ ; @file_comments ; ; ; @categories ; ; ; @param NUM ; ; ; @param RECSTART ; ; ; @param NI ; ; ; @param NJ ; ; ; @returns ; ; ; @restrictions ; ; ; @examples ; ; ; @history ; ; ; @version ; $Id$ ;- FUNCTION read_grib_bds, num, recstart, ni, nj ; ; compile_opt idl2, strictarrsubs ; offset = recstart+8 a = assoc(num, bytarr(1, /nozero), offset-1) sizepds = bit2int([binary(a[1]), binary(a[2]), binary(a[3])]) flag = binary(a[8]) gdsnotomitted = flag[0] bmsnotomitted = flag[1] ddd = bit2int([binary(a[27]), binary(a[28])], /checkneg) ; offset = offset+sizepds ; IF gdsnotomitted THEN BEGIN a = assoc(num, bytarr(1, /nozero), offset-1) sizedds = bit2int([binary(a[1]), binary(a[2]), binary(a[3])]) offset = offset+sizedds ENDIF ; IF bmsnotomitted THEN BEGIN a = assoc(num, bytarr(1, /nozero), offset-1) sizebms = bit2int([binary(a[1]), binary(a[2]), binary(a[3])]) offset = offset+sizebms ENDIF ; a = assoc(num, bytarr(1, /nozero), offset-1) ; sizebds = bit2int([binary(a[1]), binary(a[2]), binary(a[3])]) ; flags = binary(a[4]) ; BIT VALUE MEANING ; 1 0 Grid point data ; 1 Spherical Harmonic Coefficients ; 2 0 Simple packing ; 1 Second order ("Complex") Packing ; 3 0 Original data were floating point values ; 1 Original data were integer values ; 4 0 No additional flags at octet 14 ; 1 Octet 14 contains flag bits 5 - 12 ; 5 Reserved (set to 0) ; 6 0 Single datum at each grid point ; 1 Matrix of values at each grid point ; 7 0 No secondary bit maps ; 1 Secondary bit maps present ; 8 0 Second order values have constant width ; 1 Second order values have different widths ; 9-12 Reserved (set to 0) ; eee = bit2int([binary(a[5]), binary(a[6])], /checkneg) ; aaa = bit2int(binary(a[7]), /checkneg) bbb = bit2int([binary(a[8]), binary(a[9]), binary(a[10])]) IF aaa LT 0 THEN rrr = -2.^(-24) * bbb * 16.^(-aaa-64) $ ELSE rrr = 2.^(-24) * bbb * 16.^(aaa-64) ; nbits = (a[11])[0] CASE 1 OF flags[0] EQ 0 AND flags[1] EQ 0:BEGIN CASE nbits OF 8 :a = assoc(num, bytarr(ni, nj, /nozero), offset-1+12) 16:a = assoc(num, uintarr(ni, nj, /nozero), offset-1+12) 32:a = assoc(num, ulonarr(ni, nj, /nozero), offset-1+12) 64:a = assoc(num, ulon64arr(ni, nj, /nozero), offset-1+12) ELSE: ENDCASE END ENDCASE RETURN, (rrr+(a[0]*2.^(eee)))*10.^(-ddd) END