[44] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
[106] | 5 | ; @file_comments read the f77 unformated files used in Oasis (version < 2.5) |
---|
[44] | 6 | ; |
---|
[106] | 7 | ; @categories reading |
---|
[44] | 8 | ; |
---|
[106] | 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 |
---|
[44] | 14 | ; |
---|
[107] | 15 | ; @keyword /I2 |
---|
[106] | 16 | ; @keyword /I4 |
---|
| 17 | ; @keyword /I8 |
---|
| 18 | ; @keyword /R4 |
---|
| 19 | ; to change the defaut format (R8) of the data to be read. |
---|
[44] | 20 | ; |
---|
[106] | 21 | ; @returns a 2d array |
---|
[44] | 22 | ; |
---|
[106] | 23 | ; @examples |
---|
[44] | 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 | ; |
---|
[106] | 29 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[44] | 30 | ; July 01, 2002 |
---|
| 31 | ;- |
---|
| 32 | ;------------------------------------------------------------ |
---|
| 33 | ;------------------------------------------------------------ |
---|
| 34 | ;------------------------------------------------------------ |
---|
| 35 | |
---|
| 36 | |
---|
[107] | 37 | FUNCTION read_oasis, filename, varname, jpi, jpj, I2 = I2, I4 = i4, I8 = i8, R4 = r4 |
---|
[114] | 38 | ; |
---|
| 39 | compile_opt idl2, strictarrsubs |
---|
| 40 | ; |
---|
[44] | 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 |
---|
| 77 | end |
---|