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