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

Last change on this file since 325 was 325, checked in by pinsard, 17 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

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