[2] | 1 | ;+ |
---|
| 2 | ; |
---|
[142] | 3 | ; @file_comments |
---|
[295] | 4 | ; Give informations on a file netcdf and allows to recuperate |
---|
| 5 | ; variables which are written in it. |
---|
[2] | 6 | ; |
---|
[142] | 7 | ; @categories |
---|
| 8 | ; Reading |
---|
[2] | 9 | ; |
---|
[142] | 10 | ; @param NOM {in}{required} |
---|
[295] | 11 | ; Name of a file netcdf located in the directory stipulated by iodir. |
---|
[2] | 12 | ; |
---|
[142] | 13 | ; @keyword ATT |
---|
[295] | 14 | ; 'global' or the name of a variable. Allows to see all attributes |
---|
| 15 | ; associated to variable |
---|
[2] | 16 | ; |
---|
[142] | 17 | ; @keyword DIM |
---|
| 18 | ; Give the list of dimensions. |
---|
[2] | 19 | ; |
---|
[142] | 20 | ; @keyword VAR |
---|
[295] | 21 | ; 1) /var: Give the list of dimensions. |
---|
| 22 | ; 2) var='name_of_a_variable': in this case the function send back the variable. |
---|
[2] | 23 | ; |
---|
[142] | 24 | ; @keyword IODIR |
---|
| 25 | ; String containing the directory containing the file to be read |
---|
[2] | 26 | ; |
---|
[142] | 27 | ; @keyword _EXTRA |
---|
[231] | 28 | ; Used to pass keywords defined by IDL to functions NETCDF (especially OFFSET |
---|
[260] | 29 | ; and COUNT in <proidl>NCDF_VARGET</proidl>) |
---|
[2] | 30 | ; |
---|
[142] | 31 | ; @returns |
---|
[163] | 32 | ; -1 (except if var='nom de variable', then the function send back the variable). |
---|
[2] | 33 | ; |
---|
[142] | 34 | ; @restrictions |
---|
[231] | 35 | ; Variables's names of the program are similar to these used by the IDL manual |
---|
[142] | 36 | ; 'scientific data formats' |
---|
[2] | 37 | ; |
---|
[142] | 38 | ; @history |
---|
[157] | 39 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[142] | 40 | ; 4/1/98 |
---|
[2] | 41 | ; |
---|
[142] | 42 | ; @version |
---|
| 43 | ; $Id$ |
---|
[2] | 44 | ; |
---|
| 45 | ;- |
---|
[232] | 46 | FUNCTION ncdf_lec,nom,ATT=att,DIM=dim,VAR=var, IODIR = iodir, _EXTRA = ex |
---|
[231] | 47 | ; |
---|
[114] | 48 | compile_opt idl2, strictarrsubs |
---|
| 49 | ; |
---|
[2] | 50 | res = -1 |
---|
| 51 | ;------------------------------------------------------------ |
---|
| 52 | if NOT keyword_set(IODIR) then iodir = '' |
---|
| 53 | if not(keyword_set(att) or keyword_set(dim) or keyword_set(var)) then BEGIN |
---|
| 54 | att = 1 |
---|
| 55 | dim = 1 |
---|
| 56 | var = 1 |
---|
| 57 | ; commande='ncdump -c '+iodir+nom |
---|
| 58 | ; spawn,commande |
---|
| 59 | ; goto,fini |
---|
| 60 | endif |
---|
| 61 | ;------------------------------------------------------------ |
---|
[142] | 62 | ; opening of the file name. |
---|
[2] | 63 | ;------------------------------------------------------------ |
---|
| 64 | cdfid=ncdf_open(iodir+nom) |
---|
| 65 | ;------------------------------------------------------------ |
---|
[240] | 66 | ; What does the file contain?? |
---|
[2] | 67 | ;------------------------------------------------------------ |
---|
| 68 | wathinside=ncdf_inquire(cdfid) |
---|
[142] | 69 | ; print,'in the file, ',iodir+nom,', there are:' |
---|
[231] | 70 | if keyword_set(dim) then begin |
---|
[240] | 71 | ras = report(['number of dimensions: ' + strtrim(wathinside.ndims,1), $ |
---|
| 72 | 'number of the dimension which value is infinite : ',strtrim(wathinside.recdim,1)]) |
---|
[2] | 73 | endif |
---|
| 74 | if keyword_set(var) then $ |
---|
[240] | 75 | if size(var, /type) NE 7 then ras = report('number of variables :'+strtrim(wathinside.nvars,1)) |
---|
[2] | 76 | if keyword_set(att) then begin |
---|
| 77 | if strlowcase(att) ne 'global' then goto,nonglobal |
---|
[240] | 78 | ras = report('number of global attributes :' + strtrim(wathinside.ngatts,1)) |
---|
[2] | 79 | endif |
---|
| 80 | ;------------------------------------------------------------ |
---|
[142] | 81 | ; Global attributes |
---|
[2] | 82 | ;------------------------------------------------------------ |
---|
| 83 | if keyword_set(att) then begin |
---|
| 84 | print, '----------------------------' |
---|
| 85 | print,'ATTRIBUTS GLOBAUX' |
---|
| 86 | for attiq=0,wathinside.ngatts-1 do begin |
---|
[142] | 87 | name=ncdf_attname(cdfid,attiq,/global) ;attribute's name |
---|
| 88 | ncdf_attget,cdfid,name,value,/global ;attribute's value |
---|
[240] | 89 | ras = report(name + ': ' + string(value)) |
---|
[2] | 90 | endfor |
---|
| 91 | endif |
---|
| 92 | nonglobal: |
---|
| 93 | ;------------------------------------------------------------ |
---|
[142] | 94 | ; Display of different dimensions. |
---|
[2] | 95 | ;------------------------------------------------------------ |
---|
[231] | 96 | if keyword_set(dim) then begin |
---|
[2] | 97 | print, '----------------------------' |
---|
| 98 | print,'DIMENSIONS' |
---|
| 99 | endif |
---|
| 100 | nomdim =strarr(wathinside.ndims) |
---|
| 101 | tailledim=lonarr(wathinside.ndims) |
---|
| 102 | for dimiq=0,wathinside.ndims-1 do begin |
---|
[142] | 103 | ncdf_diminq,cdfid,dimiq,name,value ; dimension's name and value |
---|
[2] | 104 | nomdim[dimiq]=name |
---|
| 105 | tailledim[dimiq]=value |
---|
[231] | 106 | if keyword_set(dim) then begin |
---|
[240] | 107 | ras = report('dimension number ' + strtrim(dimiq,1) + ', name: ' + $ |
---|
| 108 | nomdim[dimiq] + ' value: ' + strtrim(tailledim[dimiq],1)) |
---|
[2] | 109 | endif |
---|
| 110 | endfor |
---|
| 111 | ;------------------------------------------------------------ |
---|
[142] | 112 | ; Display of different variables. |
---|
[2] | 113 | ;------------------------------------------------------------ |
---|
| 114 | ; |
---|
[231] | 115 | if keyword_set(att) or keyword_set(var) then begin |
---|
[142] | 116 | ; var's value? string or 1 |
---|
[2] | 117 | help, var, output = nature |
---|
| 118 | if (strpos(nature, 'STRING'))[0] NE -1 then nature = 'string' ELSE nature = '1' |
---|
[142] | 119 | ; If we just have to read the variable. |
---|
[2] | 120 | if nature EQ 'string' then begin |
---|
| 121 | ncdf_varget, cdfid, var, res, _extra = ex |
---|
| 122 | GOTO, sortie |
---|
[231] | 123 | ENDIF |
---|
[142] | 124 | ; If it is to have pieces of information. |
---|
[2] | 125 | if not keyword_set(att) then att='rien' |
---|
| 126 | print, '----------------------------' |
---|
| 127 | for varid=0,wathinside.nvars-1 do begin |
---|
[142] | 128 | varcontent=ncdf_varinq(cdfid,varid) ; What does variable contain?? |
---|
[2] | 129 | if strlowcase(att) eq strlowcase(varcontent.name) or keyword_set(var) $ |
---|
| 130 | then begin |
---|
[240] | 131 | ras = report('variable number: ' + strtrim(varid,1) + $ |
---|
| 132 | ', name:' + varcontent.name + $ |
---|
| 133 | ', type:' + varcontent.datatype + $ |
---|
| 134 | ', dimensions:' + nomdim[varcontent.dim]) |
---|
[2] | 135 | if strlowcase(att) eq strlowcase(varcontent.name) then begin |
---|
| 136 | for attiq=0,varcontent.natts-1 do begin |
---|
| 137 | name=ncdf_attname(cdfid,varid,attiq) |
---|
| 138 | ncdf_attget,cdfid,varid,name,value |
---|
[240] | 139 | ras = report(' ' + strtrim(attiq) + ' ' + $ |
---|
| 140 | ' name : ' + strtrim(string(value),1)) |
---|
[2] | 141 | endfor |
---|
| 142 | goto, sortie |
---|
| 143 | endif |
---|
| 144 | endif |
---|
| 145 | endfor |
---|
| 146 | endif |
---|
| 147 | ;------------------------------------------------------------ |
---|
| 148 | sortie: |
---|
| 149 | ncdf_close,cdfid |
---|
| 150 | ;------------------------------------------------------------ |
---|
| 151 | ;------------------------------------------------------------ |
---|
| 152 | fini: |
---|
| 153 | |
---|
| 154 | return, res |
---|
| 155 | end |
---|