source: trunk/ReadWrite/read_oasis.pro @ 44

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

upgrade of LECTURE/ReadWrite according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/ : files

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:read_oasis
6;
7; PURPOSE:read the f77 unformated files used in Oasis (version < 2.5)
8;
9; CATEGORY:reading
10;
11; CALLING SEQUENCE: z2d=read_oasis(filename, varname, jpi, jpj)
12;
13; INPUTS:
14;        filename:the filename
15;        varname: the name of the variable to be read
16;        jpi and jpj the size of the 2d array to be read
17;
18; KEYWORD PARAMETERS:
19;        /I2, /I4, /I8, /R4: to change the defaut format (R8) of the data to
20;        be read.
21;
22; OUTPUTS:a 2d array
23;
24; COMMON BLOCKS:
25;
26; SIDE EFFECTS:
27;
28; RESTRICTIONS:
29;
30; EXAMPLE:
31; IDL> a=read_oasis('grids_orca_t106','a106.lon',320,160)
32; IDL> m=read_oasis('masks_orca_t106','or1t.msk',182,149,/i4)
33;
34; see also IDL> scanoasis,'grids_orca_t106'
35;
36; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
37;                      July 01, 2002
38;-
39;------------------------------------------------------------
40;------------------------------------------------------------
41;------------------------------------------------------------
42
43
44FUNCTION read_oasis, filename, varname, jpi, jpj, I2, I4 = i4, I8 = i8, R4 = r4
45
46   openr, unit, filename, /f77_unformatted, /get_lun, /swap_if_little_endian $
47    , error=err
48   if err ne 0 then begin
49      print,!err_string
50      return, -1
51   endif
52
53   char8 = '12345678'
54   readu, unit, char8
55;   print, char8
56   found = char8 EQ varname
57
58   WHILE NOT EOF(unit) AND found NE 1 DO BEGIN
59      readu, unit
60      if EOF(unit) then begin
61         print, varname+' not found in '+filename
62         return, -1
63      endif
64      readu, unit, char8
65;      print, char8
66      found = char8 EQ varname
67   ENDWHILE
68   case 1 of
69      keyword_set(i2):res = intarr(jpi, jpj)
70      keyword_set(i4):res = lonarr(jpi, jpj)
71      keyword_set(i8):res = lon64arr(jpi, jpj)
72      keyword_set(r4):res = fltarr(jpi, jpj)
73      ELSE:res = dblarr(jpi, jpj)
74   endcase
75   
76   readu, unit, res
77   
78   free_lun,unit
79
80   return, res
81end
Note: See TracBrowser for help on using the repository browser.