source: trunk/SRC/ReadWrite/read_oasis.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 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; @file_comments read the f77 unformated files used in Oasis (version < 2.5)
6;
7; @categories reading
8;
9;        @param filename {in}{required} the filename
10;        @param varname {in}{required} the name of the variable to be read
11;        @param jpi {in}{required}
12;        @param jpj {in}{required}
13;        the size of the 2d array to be read
14;
15; @keyword /I2
16; @keyword /I4
17; @keyword /I8
18; @keyword /R4
19; to change the defaut format (R8) of the data to be read.
20;
21; @returns a 2d array
22;
23; @examples
24; IDL> a=read_oasis('grids_orca_t106','a106.lon',320,160)
25; IDL> m=read_oasis('masks_orca_t106','or1t.msk',182,149,/i4)
26;
27; see also IDL> scanoasis,'grids_orca_t106'
28;
29; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
30;                      July 01, 2002
31;-
32;------------------------------------------------------------
33;------------------------------------------------------------
34;------------------------------------------------------------
35
36
37FUNCTION read_oasis, filename, varname, jpi, jpj, I2 = I2, I4 = i4, I8 = i8, R4 = r4
38;
39  compile_opt idl2, strictarrsubs
40;
41
42   openr, unit, filename, /f77_unformatted, /get_lun, /swap_if_little_endian $
43    , error=err
44   if err ne 0 then begin
45      print,!err_string
46      return, -1
47   endif
48
49   char8 = '12345678'
50   readu, unit, char8
51;   print, char8
52   found = char8 EQ varname
53
54   WHILE NOT EOF(unit) AND found NE 1 DO BEGIN
55      readu, unit
56      if EOF(unit) then begin
57         print, varname+' not found in '+filename
58         return, -1
59      endif
60      readu, unit, char8
61;      print, char8
62      found = char8 EQ varname
63   ENDWHILE
64   case 1 of
65      keyword_set(i2):res = intarr(jpi, jpj)
66      keyword_set(i4):res = lonarr(jpi, jpj)
67      keyword_set(i8):res = lon64arr(jpi, jpj)
68      keyword_set(r4):res = fltarr(jpi, jpj)
69      ELSE:res = dblarr(jpi, jpj)
70   endcase
71   
72   readu, unit, res
73   
74   free_lun,unit
75
76   return, res
77end
Note: See TracBrowser for help on using the repository browser.