source: trunk/SRC/ToBeReviewed/LECTURE/GRIB/scan_grib_recstart.pro @ 495

Last change on this file since 495 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.2 KB
Line 
1;+
2; @file_comments
3;
4; @categories
5;
6; @param NUM
7;
8; @returns
9;
10; @restrictions
11;
12; @examples
13;
14; @history
15;
16; @version
17; $Id$
18;-
19FUNCTION scan_grib_recstart, num
20;
21  compile_opt idl2, strictarrsubs
22;
23
24  infofile = fstat(num)
25; minimum size of one record
26  minisize = 8L+28L+4L+4L
27  maxoffset = infofile.size-minisize
28;
29  start = 0L
30  offset = 0L
31  previousrecsize = 0L
32
33  WHILE offset LT maxoffset DO BEGIN
34; Every record must begin with 'GRIB'.
35; However, their is no rule to define the space between 2 records.
36; (1) we try space = previousrecsize MOD 8, because for echam outputs,
37; the total size of the records is rounded to modulo 8
38    addoff = 8 - (previousrecsize MOD 8)
39    offset = offset+addoff
40    IF offset GE maxoffset THEN GOTO, out
41    a = assoc(num, bytarr(4, /nozero), offset)
42    typefile = string(a[0])
43    IF typefile NE 'GRIB' THEN offset = offset-addoff
44; (2) we try space = previousrecsize MOD 120, because for ecmwf
45; outputs, the total size of the records is rounded to modulo 120
46    addoff = 120 - (previousrecsize MOD 120)
47    IF typefile NE 'GRIB' THEN BEGIN
48      offset = offset+addoff
49      IF offset GE maxoffset THEN GOTO, out
50      a = assoc(num, bytarr(4, /nozero), offset)
51      typefile = string(a[0])
52      IF typefile NE 'GRIB' THEN offset = offset-addoff
53    ENDIF
54; (3) we try space = 0
55    IF typefile NE 'GRIB' THEN BEGIN
56      a = assoc(num, bytarr(4, /nozero), offset)
57      typefile = string(a[0])
58    ENDIF
59; (4) we try any value for space
60    IF typefile NE 'GRIB' THEN BEGIN
61      REPEAT BEGIN
62        CASE 1 OF
63          array_equal((a[0])[3  ], byte('G'  )):offset = offset+3
64          array_equal((a[0])[2:3], byte('GR' )):offset = offset+2
65          array_equal((a[0])[1:3], byte('GRI')):offset = offset+1
66          else:offset = offset+4
67        ENDCASE
68        IF offset GE maxoffset THEN GOTO, out
69        a = assoc(num, bytarr(4, /nozero), offset)
70        typefile = string(a[0])
71      ENDREP UNTIL typefile EQ 'GRIB'
72    ENDIF
73;
74    start = [start, offset]
75;
76    a = assoc(num, bytarr(1, /nozero), offset+4)
77    recsize = bit2int([binary(a[0]), binary(a[1]), binary(a[2])])
78    offset = offset+recsize
79    previousrecsize = recsize
80;
81  ENDWHILE
82;
83out:
84;
85  RETURN, start[1:n_elements(start)-1]
86END
Note: See TracBrowser for help on using the repository browser.