source: trunk/ToBeReviewed/LECTURE/GRIB/scan_grib_recstart.pro @ 67

Last change on this file since 67 was 67, checked in by pinsard, 18 years ago

miscellaneous modifications according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/

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