source: trunk/SRC/ReadWrite/read_oasis.pro @ 107

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

bugfix in ead/write_oasis

  • Property svn:executable set to *
File size: 2.0 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   openr, unit, filename, /f77_unformatted, /get_lun, /swap_if_little_endian $
40    , error=err
41   if err ne 0 then begin
42      print,!err_string
43      return, -1
44   endif
45
46   char8 = '12345678'
47   readu, unit, char8
48;   print, char8
49   found = char8 EQ varname
50
51   WHILE NOT EOF(unit) AND found NE 1 DO BEGIN
52      readu, unit
53      if EOF(unit) then begin
54         print, varname+' not found in '+filename
55         return, -1
56      endif
57      readu, unit, char8
58;      print, char8
59      found = char8 EQ varname
60   ENDWHILE
61   case 1 of
62      keyword_set(i2):res = intarr(jpi, jpj)
63      keyword_set(i4):res = lonarr(jpi, jpj)
64      keyword_set(i8):res = lon64arr(jpi, jpj)
65      keyword_set(r4):res = fltarr(jpi, jpj)
66      ELSE:res = dblarr(jpi, jpj)
67   endcase
68   
69   readu, unit, res
70   
71   free_lun,unit
72
73   return, res
74end
Note: See TracBrowser for help on using the repository browser.