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