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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1FUNCTION scan_grib_recstart, num
2;
3  compile_opt idl2, strictarrsubs
4;
5
6  infofile = fstat(num)
7; minimum size of one record
8  minisize = 8L+28L+4L+4L
9  maxoffset = infofile.size-minisize
10;
11  start = 0L
12  offset = 0L
13  previousrecsize = 0L
14
15  WHILE offset LT maxoffset DO BEGIN
16; Every record must begin with 'GRIB'.
17; However, their is no rule to define the space between 2 records.
18; (1) we try space = previousrecsize MOD 8, because for echam outputs,
19; the total size of the records is rounded to modulo 8
20    addoff = 8 - (previousrecsize MOD 8)
21    offset = offset+addoff
22    IF offset GE maxoffset THEN GOTO, out
23    a = assoc(num, bytarr(4, /nozero), offset)
24    typefile = string(a[0])
25    IF typefile NE 'GRIB' THEN offset = offset-addoff
26; (2) we try space = previousrecsize MOD 120, because for ecmwf
27; outputs, the total size of the records is rounded to modulo 120
28    addoff = 120 - (previousrecsize MOD 120)
29    IF typefile NE 'GRIB' THEN BEGIN
30      offset = offset+addoff
31      IF offset GE maxoffset THEN GOTO, out
32      a = assoc(num, bytarr(4, /nozero), offset)
33      typefile = string(a[0])
34      IF typefile NE 'GRIB' THEN offset = offset-addoff
35    ENDIF
36; (3) we try space = 0
37    IF typefile NE 'GRIB' THEN BEGIN
38      a = assoc(num, bytarr(4, /nozero), offset)
39      typefile = string(a[0])
40    ENDIF
41; (4) we try any value for space
42    IF typefile NE 'GRIB' THEN BEGIN
43      REPEAT BEGIN
44        CASE 1 OF
45          array_equal((a[0])[3  ], byte('G'  )):offset = offset+3
46          array_equal((a[0])[2:3], byte('GR' )):offset = offset+2
47          array_equal((a[0])[1:3], byte('GRI')):offset = offset+1
48          else:offset = offset+4
49        ENDCASE
50        IF offset GE maxoffset THEN GOTO, out
51        a = assoc(num, bytarr(4, /nozero), offset)
52        typefile = string(a[0])
53      ENDREP UNTIL typefile EQ 'GRIB'
54    ENDIF
55;
56    start = [start, offset]
57;   
58    a = assoc(num, bytarr(1, /nozero), offset+4)
59    recsize = bit2int([binary(a[0]), binary(a[1]), binary(a[2])])
60    offset = offset+recsize
61    previousrecsize = recsize
62;
63  ENDWHILE
64;
65out:
66;
67  RETURN, start[1:n_elements(start)-1]
68END
Note: See TracBrowser for help on using the repository browser.