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

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

corrections of some headers and parameters and keywords case. change of pro2href to replace proidl

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