[150] | 1 | ;+ |
---|
[231] | 2 | ; |
---|
[150] | 3 | ; @file_comments |
---|
[2] | 4 | ; |
---|
[150] | 5 | ; @categories |
---|
| 6 | ; |
---|
| 7 | ; @param NAMEFILE |
---|
| 8 | ; |
---|
[221] | 9 | ; @keyword GRID {default='T'}{type=scalar string} |
---|
| 10 | ; Used to specify on which grid type are located the data |
---|
[150] | 11 | ; |
---|
| 12 | ; @keyword _EXTRA |
---|
[271] | 13 | ; Used to pass keywords to <pro>isafile</pro>, |
---|
| 14 | ; <pro>ncdf_getaxis</pro> and <pro>ncdf_gettime</pro> |
---|
[226] | 15 | ; |
---|
[150] | 16 | ; @returns |
---|
[226] | 17 | ; |
---|
[150] | 18 | ; @uses |
---|
[226] | 19 | ; |
---|
[150] | 20 | ; @restrictions |
---|
[226] | 21 | ; |
---|
[150] | 22 | ; @examples |
---|
[226] | 23 | ; |
---|
[150] | 24 | ; @history |
---|
[226] | 25 | ; |
---|
| 26 | ; @version |
---|
[150] | 27 | ; $Id$ |
---|
| 28 | ; |
---|
| 29 | ; @todo |
---|
| 30 | ; seb : I don't know what to do with that... |
---|
[226] | 31 | ; |
---|
[150] | 32 | ;- |
---|
[325] | 33 | FUNCTION scanfile, namefile, GRID = GRID, _EXTRA = ex |
---|
[150] | 34 | ; |
---|
[2] | 35 | ; liste des presupposes: |
---|
| 36 | ; 1) le fichier a lire est un fichier netcdf |
---|
| 37 | ; 2) le nom de ce fichier finit |
---|
| 38 | ; par U.nc, V.nc, W.nc, T.nc ou F.nc, la lettre avant le |
---|
| 39 | ; nc designant la grille a laquelle se rapporte la champ. |
---|
| 40 | ; Si tel n''est pas la cas, le fichier est attribue a la grille |
---|
| 41 | ; T. |
---|
| 42 | ; 3) ce fichier contient une dimension infinie qui doit etre |
---|
| 43 | ; celle qui se rapporte au temps et au mois 2 autres dimensions |
---|
[69] | 44 | ; dont les noms sont 'x','lon...','xi_...' et 'y','lat...' ou |
---|
| 45 | ; 'eta_...' ou bien en majuscule. |
---|
[226] | 46 | ; 4) il doit exister ds ce fichier une unique variable n''ayant |
---|
[2] | 47 | ; qu''une dimension et etant la dimension temporelle. cette |
---|
| 48 | ; variable sera prise comme axe des temps. Rq: si plusieurs |
---|
| 49 | ; variables verifient ces criteres on considere la premiere |
---|
| 50 | ; variable |
---|
| 51 | ; 5) Cette variable axe des temps doit contenir l''attribut |
---|
[226] | 52 | ; 'units' qui doit etre ecrit suivant la syntaxe: |
---|
| 53 | ; "seconds since 0001-01-01 00:00:00" |
---|
| 54 | ; "hours since 0001-01-01 00:00:00" |
---|
| 55 | ; "days since 1979-01-01 00:59:59" |
---|
| 56 | ; "months since 1979-01-01 00:59:59" |
---|
| 57 | ; "years since 1979-01-01 00:59:59" |
---|
[2] | 58 | ; |
---|
| 59 | ; je crois que c''est tout! |
---|
| 60 | ; |
---|
[69] | 61 | ; GRID='[UTVWF]' to specify the type of grid. Defaut is (1) |
---|
| 62 | ; based on the name of the file if the file ends by |
---|
| 63 | ; GRID[._][TUVFW].NC (not case sensible) or (2) T if case (1) |
---|
| 64 | ; is not found. |
---|
[2] | 65 | ; |
---|
[231] | 66 | ; |
---|
[114] | 67 | compile_opt idl2, strictarrsubs |
---|
| 68 | ; |
---|
[2] | 69 | @common |
---|
| 70 | ;------------------------------------------------------------ |
---|
[69] | 71 | ; filename |
---|
[2] | 72 | ;------------------------------------------------------------ |
---|
[69] | 73 | fullname = isafile(filename = namefile, IODIRECTORY = iodir, _extra = ex) |
---|
[221] | 74 | IF size(fullname, /type) NE 7 THEN return, -1 |
---|
[2] | 75 | ;------------------------------------------------------------ |
---|
[69] | 76 | ; open file |
---|
[2] | 77 | ;------------------------------------------------------------ |
---|
[69] | 78 | cdfid = ncdf_open(fullname) |
---|
[2] | 79 | ;------------------------------------------------------------ |
---|
[69] | 80 | ; What contains the file? |
---|
[2] | 81 | ;------------------------------------------------------------ |
---|
[271] | 82 | inq = ncdf_inquire(cdfid) ; |
---|
[2] | 83 | ;------------------------------------------------------------ |
---|
[69] | 84 | ; name of all dimensions |
---|
[2] | 85 | ;------------------------------------------------------------ |
---|
[271] | 86 | namedim = strarr(inq.ndims) |
---|
| 87 | for dimiq = 0, inq.ndims-1 do begin |
---|
[226] | 88 | ncdf_diminq, cdfid, dimiq, tmpname, value |
---|
[69] | 89 | namedim[dimiq] = strlowcase(tmpname) |
---|
[49] | 90 | ENDFOR |
---|
[69] | 91 | ;------------------------------------------------------------ |
---|
[221] | 92 | ; x/y dimensions id |
---|
| 93 | ;------------------------------------------------------------ |
---|
| 94 | ncdf_getaxis, cdfid, dimidx, dimidy, _extra = ex |
---|
| 95 | ;------------------------------------------------------------ |
---|
[69] | 96 | ; name of all variables |
---|
| 97 | ;------------------------------------------------------------ |
---|
| 98 | ; we keep only the variables containing at least x, y and time dimension (if existing...) |
---|
[271] | 99 | namevar = strarr(inq.nvars) |
---|
| 100 | for varid = 0, inq.nvars-1 do begin |
---|
| 101 | varinq = ncdf_varinq(cdfid, varid) ; what contains the variable? |
---|
| 102 | if (inter(varinq.dim, dimidx))[0] NE -1 AND $ |
---|
| 103 | (inter(varinq.dim, dimidy))[0] NE -1 AND $ |
---|
| 104 | ((where(varinq.dim EQ inq.recdim))[0] NE -1 OR inq.recdim EQ -1) $ |
---|
| 105 | THEN namevar[varid] = varinq.name |
---|
[49] | 106 | ENDFOR |
---|
| 107 | namevar = namevar[where(namevar NE '')] |
---|
[2] | 108 | ;------------------------------------------------------------ |
---|
[172] | 109 | ; find vargrid for each selected variable... |
---|
| 110 | ;------------------------------------------------------------ |
---|
| 111 | listgrid = strarr(n_elements(namevar)) |
---|
| 112 | ; default definitions |
---|
| 113 | IF keyword_set(grid) THEN vargrid = strupcase(grid) ELSE vargrid = 'T' |
---|
| 114 | ; look for values of vargrid for each variable |
---|
| 115 | IF finite(glamu[0]) EQ 1 AND NOT keyword_set(grid) THEN BEGIN |
---|
| 116 | ; for each variable, look if we in one of the case corresponding to ROMS conventions? |
---|
| 117 | FOR i = 0, n_elements(namevar)-1 do begin |
---|
[271] | 118 | varinq = ncdf_varinq(cdfid, namevar[i]) |
---|
| 119 | tmpnm = namedim[varinq.dim] |
---|
[172] | 120 | ; are we in one of the case corresponding to ROMS conventions? |
---|
| 121 | CASE 1 OF |
---|
[271] | 122 | tmpnm[2 < (varinq.ndims-1)] EQ 's_w':vargrid = 'W' |
---|
[172] | 123 | tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'T' |
---|
| 124 | tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_u' :listgrid[i] = 'U' |
---|
| 125 | tmpnm[0] EQ 'xi_v' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'V' |
---|
| 126 | tmpnm[0] EQ 'xi_psi' AND tmpnm[1] EQ 'eta_psi':listgrid[i] = 'F' |
---|
| 127 | tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'V' |
---|
| 128 | tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'U' |
---|
| 129 | tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'F' |
---|
[226] | 130 | ELSE: |
---|
| 131 | ENDCASE |
---|
[172] | 132 | ENDFOR |
---|
| 133 | empty = where(listgrid EQ '') |
---|
[226] | 134 | IF empty[0] NE -1 THEN BEGIN |
---|
[172] | 135 | ; could we define the grid type from the file name?? |
---|
| 136 | pattern = ['GRID.', 'GRID_', 'GRID', 'UPID_', '30ID_'] |
---|
| 137 | gdtype = ['T', 'U', 'V', 'W', 'F'] |
---|
| 138 | fnametest = strupcase(fullname) |
---|
| 139 | FOR i = 0, n_elements(pattern)-1 DO BEGIN |
---|
| 140 | FOR j = 0, n_elements(gdtype)-1 DO BEGIN |
---|
| 141 | substr = pattern[i]+gdtype[j] |
---|
| 142 | pos = strpos(fnametest, substr) |
---|
| 143 | IF pos NE -1 THEN $ |
---|
| 144 | vargrid = strmid(fnametest, pos+strlen(substr)-1, 1) |
---|
| 145 | ENDFOR |
---|
| 146 | ENDFOR |
---|
| 147 | listgrid[empty] = vargrid |
---|
[226] | 148 | ENDIF |
---|
[172] | 149 | ENDIF ELSE listgrid[*] = vargrid |
---|
| 150 | ;------------------------------------------------------------ |
---|
[69] | 151 | ; time axis |
---|
[2] | 152 | ;------------------------------------------------------------ |
---|
[271] | 153 | time = ncdf_gettime(fullname, cdfid, caller = 'scanfile', err = err, _extra = ex) |
---|
| 154 | IF n_elements(err) NE 0 THEN BEGIN |
---|
| 155 | dummy = report(err) |
---|
| 156 | jpt = abs(time) |
---|
[69] | 157 | fakecal = 1 |
---|
[271] | 158 | ENDIF ELSE jpt = n_elements(time) |
---|
[69] | 159 | ; high frequency calendar: more than one element per day |
---|
[271] | 160 | IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0 |
---|
| 161 | date0fk = date2jul(19000101) |
---|
| 162 | IF keyword_set(fakecal) THEN time = date0fk+lindgen(1 > jpt) |
---|
[2] | 163 | ;------------------------------------------------------------ |
---|
[69] | 164 | ncdf_close, cdfid |
---|
| 165 | ;------------------------------------------------------------ |
---|
| 166 | return, {filename:fullname, time_counter:time, listvar:namevar $ |
---|
| 167 | , listgrid:strupcase(listgrid), caltype:key_caltype $ |
---|
| 168 | , fakecal:date0fk*fakecal} |
---|
[2] | 169 | end |
---|