[150] | 1 | ;+ |
---|
| 2 | ; |
---|
| 3 | ; @file_comments |
---|
[295] | 4 | ; Reading of a NetCdf file with widgets |
---|
[150] | 5 | ; |
---|
[231] | 6 | ; @categories |
---|
[157] | 7 | ; Widget |
---|
[150] | 8 | ; |
---|
[231] | 9 | ; @param NAME {in}{optional}{type=string} |
---|
| 10 | ; It give the name of the file to be opened. If NAME |
---|
| 11 | ; does not contain the separating character of directories ('/' under |
---|
[150] | 12 | ; unix for example), the file will be looked for in the current directory. |
---|
| 13 | ; |
---|
[163] | 14 | ; @keyword IODIR {type=string} |
---|
| 15 | ; It contains the directory where to go look for the file to be read. |
---|
[231] | 16 | ; If NAME does not contain the separating character of directories ('/' under |
---|
[150] | 17 | ; unix for example), the file will be called iodir+nom_fichier. |
---|
| 18 | ; |
---|
[163] | 19 | ; @keyword COUNT {type=vector} |
---|
[150] | 20 | ; An optional vector containing the counts to be used in |
---|
| 21 | ; reading Value. COUNT is a 1-based vector with an element for |
---|
| 22 | ; each dimension of the data to be written.The default matches |
---|
| 23 | ; the size of the variable so that all data is written out. |
---|
| 24 | ; |
---|
| 25 | ; @keyword GROUP |
---|
| 26 | ; The widget ID of the widget that calls XNCDF_LEC. When |
---|
| 27 | ; this ID is specified, a death of the caller results in a death |
---|
[231] | 28 | ; of XNCDF_LEC. |
---|
[150] | 29 | ; |
---|
[163] | 30 | ; @keyword OFFSET {type=vector}{default=[0, 0,...]} |
---|
[150] | 31 | ; An optional vector containing the starting position |
---|
| 32 | ; for the read. The default start position is [0, 0, ...]. |
---|
| 33 | ; |
---|
[163] | 34 | ; @keyword SHIFT {type=vector}{default=[0, 0,...]} |
---|
[231] | 35 | ; A vector of integers, specifying for each dimension how much we have to shift it. |
---|
[295] | 36 | ; By default, it is [0,0,...]. See the function <proidl>shift</proidl> for more explanations. BEWARE, |
---|
[231] | 37 | ; the shift is done on the biggest array before a possible reduction determined |
---|
| 38 | ; by OFFSET and COUNT. On the other hand, it is done after the possible extraction |
---|
[150] | 39 | ; created by the STRIDE. |
---|
| 40 | ; |
---|
[163] | 41 | ; @keyword STRIDE {type=vector}{default=[1, 1,...]} |
---|
[150] | 42 | ; An optional vector containing the strides, or sampling |
---|
| 43 | ; intervals, between accessed values of the netCDF variable. The |
---|
| 44 | ; default stride vector is that for a contiguous read, [1, 1,...]. |
---|
| 45 | ; |
---|
| 46 | ; @returns |
---|
| 47 | ; 2 different cases: |
---|
| 48 | ; 1) None attribute has been selected. In this case, res is the array we |
---|
| 49 | ; wanted to read. |
---|
[231] | 50 | ; 2) Some attributes has been selected. In this case, res is a structure |
---|
| 51 | ; whose the first element having the name of the variable is the values |
---|
[150] | 52 | ; array and the other arguments are the select arguments. |
---|
| 53 | ; |
---|
| 54 | ; @uses |
---|
| 55 | ; wididbase, infovariable, resultat, motcle |
---|
| 56 | ; |
---|
| 57 | ; @examples |
---|
[295] | 58 | ; IDL> help, xncdf_lec() |
---|
[150] | 59 | ; |
---|
| 60 | ; @history |
---|
[157] | 61 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[150] | 62 | ; 24/8/1999 |
---|
| 63 | ; |
---|
| 64 | ; @version |
---|
| 65 | ; $Id$ |
---|
| 66 | ;- |
---|
| 67 | FUNCTION xncdf_lec, name, ATT = att, COUNT = count, GROUP = group, OFFSET = offset, IODIR = iodir, SHIFT = shift, STRIDE = stride, VAR = var |
---|
| 68 | ; |
---|
| 69 | compile_opt idl2, strictarrsubs |
---|
| 70 | ; |
---|
| 71 | COMMON wididbase, base |
---|
| 72 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
| 73 | COMMON resultat, res |
---|
| 74 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
| 75 | ;------------------------------------------------------------ |
---|
[297] | 76 | ; Trick for using keywords (we pass by variables declared in a common) |
---|
[150] | 77 | ;------------------------------------------------------------ |
---|
| 78 | res = -1 |
---|
| 79 | if keyword_set(att) then mcatt = att ELSE mcatt = 0 |
---|
| 80 | if keyword_set(count) then mccount =count ELSE mccount = 0 |
---|
| 81 | if keyword_set(offset) then mcoffset = offset ELSE mcoffset = 0 |
---|
| 82 | if keyword_set(shift) then mcshift = shift ELSE mcshift = 0 |
---|
| 83 | if keyword_set(stride) then mcstride = stride ELSE mcstride = 0 |
---|
| 84 | if keyword_set(var) then mcvar = var ELSE mcvar = 0 |
---|
| 85 | ;------------------------------------------------------------ |
---|
| 86 | ; choice of the file's name |
---|
| 87 | ;------------------------------------------------------------ |
---|
| 88 | ; What type of machine is used |
---|
| 89 | thisOS = strupcase(strmid(!version.os_family, 0, 3)) |
---|
| 90 | CASE thisOS of |
---|
| 91 | 'MAC':sep = ':' |
---|
| 92 | 'WIN':sep = '\' |
---|
| 93 | ELSE: sep = '/' |
---|
| 94 | ENDCASE |
---|
| 95 | ; If IODIR is not defined, we initialize it at the current directory |
---|
| 96 | if NOT keyword_set(iodir) then cd, current = iodir |
---|
| 97 | mciodir = iodir |
---|
| 98 | ; We complete IODIR with a separating character if needed. |
---|
[231] | 99 | IF rstrpos(iodir, sep) NE strlen(iodir)-1 THEN iodir = iodir+sep |
---|
[150] | 100 | if n_elements(name) EQ 0 then BEGIN ; If NAME is not defined, we find one thanks to the program dialog_pickfile. |
---|
[231] | 101 | name = dialog_pickfile(filter = iodir+'*.nc') |
---|
[150] | 102 | if name[0] EQ '' then return, -1 ;If we do not have find anything, we go out. |
---|
| 103 | ;We complete NAME by IODIR if NAME does not contain any directory separating character. |
---|
| 104 | ENDIF ELSE if strpos(name, sep) EQ -1 then name = iodir+name |
---|
| 105 | test = findfile(name) ; Does the name looked for correspond to a file? |
---|
| 106 | while test[0] EQ '' OR n_elements(test) GT 1 do BEGIN ; We look for one as long as it correspond to nothing! |
---|
| 107 | test = test[0] |
---|
| 108 | name = dialog_pickfile(filter = iodir+'*.nc') |
---|
| 109 | if name EQ '' then return, -1 |
---|
| 110 | test = findfile(name) |
---|
| 111 | endwhile |
---|
| 112 | ;------------------------------------------------------------ |
---|
| 113 | ; Opening of the file name. |
---|
| 114 | ;------------------------------------------------------------ |
---|
| 115 | cdfid=ncdf_open(name) |
---|
| 116 | contient=ncdf_inquire(cdfid) |
---|
| 117 | ;------------------------------------------------------------ |
---|
| 118 | ; What does this file contain?? |
---|
| 119 | ;------------------------------------------------------------ |
---|
| 120 | ; Opening of the base window as columns |
---|
| 121 | if n_elements(group) EQ 0 then base = widget_base(/column, title='Fichier: '+name, /align_left) $ |
---|
| 122 | ELSE base = widget_base(/column, title='Fichier: '+name, /align_left, GROUP_LEADER = group) |
---|
| 123 | ; Opening of base sub-windows ; |
---|
| 124 | ;------------------------------------------------------------ |
---|
| 125 | ; base 1 title having the file's name |
---|
| 126 | ;------------------------------------------------------------ |
---|
| 127 | base1 = widget_base(base, /column, /align_center) |
---|
[295] | 128 | rien = widget_label(base1, value = 'NetCdf filename', /align_center) |
---|
[150] | 129 | rien = widget_text(base1, value = name, /align_center, uvalue=1, /editable) ;File's name we can change |
---|
| 130 | rien = widget_label(base1, value = ' ') ; We jump a line |
---|
| 131 | ;------------------------------------------------------------ |
---|
| 132 | ; base 2 General informations on the file |
---|
| 133 | ;------------------------------------------------------------ |
---|
| 134 | base2 = widget_base(base, /column) |
---|
| 135 | ;------------------------------------------------------------ |
---|
| 136 | ; Informations on global attributes |
---|
| 137 | ;------------------------------------------------------------ |
---|
| 138 | if contient.ngatts NE -1 then begin |
---|
| 139 | rien = widget_label(base2, value = 'Nombre de attributs globaux: '+ strtrim(contient.ngatts,1), /align_left) |
---|
| 140 | for attiq=0,contient.ngatts-1 do BEGIN ; Loop on the number of global attributes |
---|
| 141 | name=ncdf_attname(cdfid,attiq,/global) ;Attribute's name |
---|
| 142 | ncdf_attget,cdfid,name,value,/global ;Attribute's value |
---|
| 143 | rien = widget_text(base2, value = name+': '+strtrim(string(value),1), xsize = 60, /scroll, /wrap, /align_right) |
---|
| 144 | endfor |
---|
| 145 | rien = widget_label(base2, value = ' ') |
---|
| 146 | endif |
---|
| 147 | ;------------------------------------------------------------ |
---|
| 148 | ; Informations on dimensions |
---|
| 149 | ;------------------------------------------------------------ |
---|
| 150 | rien = widget_label(base2, value = 'Nombre de dimensions: '+strtrim(contient.ndims,1), /align_left) |
---|
| 151 | if contient.recdim NE -1 then begin ; Loop on the number of global attributes |
---|
| 152 | ncdf_diminq,cdfid,contient.recdim,name,value ; Name and value of the dimension |
---|
| 153 | rien = widget_label(base2, value = 'name de la dimension infinie: '+name, /align_left) |
---|
| 154 | endif |
---|
| 155 | ; |
---|
| 156 | nomdim =strarr(contient.ndims) ; Vector containing dimensions's name |
---|
| 157 | tailledim=lonarr(contient.ndims) ; Vector containing dimensions's value |
---|
| 158 | for dimiq=0,contient.ndims-1 do begin ; Loop on the number of dimensions |
---|
| 159 | ncdf_diminq,cdfid,dimiq,name,value ; Name and value of the dimension |
---|
| 160 | nomdim[dimiq]=name |
---|
| 161 | tailledim[dimiq]=value |
---|
| 162 | rien = widget_label(base2, value = name+' de taille: '+strtrim(value,1), /align_right) |
---|
| 163 | ENDFOR |
---|
| 164 | rien = widget_label(base2, value = ' ') ; We jump a line |
---|
| 165 | ;------------------------------------------------------------ |
---|
| 166 | ; base 3 choice of the variable |
---|
| 167 | ;------------------------------------------------------------ |
---|
| 168 | base3 = widget_base(base, /column) |
---|
| 169 | rien = widget_label(base3, value = 'Nombre de variables: '+strtrim(contient.nvars,1), /align_left) |
---|
| 170 | base31 = widget_base(base3, /row, /align_center) |
---|
| 171 | ;Creation of a listename containing the name of all file's variables |
---|
| 172 | listename = strarr(contient.nvars) |
---|
| 173 | for varid=0,contient.nvars-1 do begin |
---|
| 174 | varcontient=ncdf_varinq(cdfid,varid) ; that the variable contain |
---|
| 175 | listename[varid] = varcontient.name |
---|
| 176 | endfor |
---|
| 177 | rien= widget_label(base31, value = 'variable') |
---|
| 178 | ; Creation of a button with a pop-up menu. |
---|
| 179 | base311=widget_droplist(base31,value=listename, uvalue=2) |
---|
| 180 | rien = widget_label(base3, value = '') |
---|
| 181 | ;------------------------------------------------------------ |
---|
| 182 | ; base 4 button done |
---|
| 183 | ;------------------------------------------------------------ |
---|
| 184 | base4 = widget_base(base, /row) |
---|
| 185 | base42=widget_button(base4,value='done', uvalue=3, /align_right) |
---|
| 186 | ;Execution of the base window and of sub-windows |
---|
| 187 | widget_control,base,/realize |
---|
| 188 | ;------------------------------------------------------------ |
---|
| 189 | xmanager,'xncdf_lec',base |
---|
| 190 | ;------------------------------------------------------------ |
---|
| 191 | ;------------------------------------------------------------ |
---|
| 192 | ;------------------------------------------------------------ |
---|
| 193 | return, res |
---|
| 194 | end |
---|
| 195 | ; |
---|
[2] | 196 | ; La lecture de ce programme se fait de bas en haut: |
---|
| 197 | ; 1) xncdf_lec |
---|
| 198 | ; -->2) xncdf_lec_event |
---|
| 199 | ; |--> 3) wid_var |
---|
| 200 | ; --> wid_var_event |
---|
| 201 | ; |
---|
[150] | 202 | ;+ |
---|
[231] | 203 | ; |
---|
[150] | 204 | ; @file_comments |
---|
| 205 | ; Procedure called by xmanager when we press on a button of a second widget created by wid_var. |
---|
[231] | 206 | ; |
---|
[150] | 207 | ; @param EVENT {in}{required} |
---|
[297] | 208 | ; A structure characterizing the type of event which arrive to a widget number1 2 |
---|
[2] | 209 | ; |
---|
[150] | 210 | ; @uses |
---|
| 211 | ; wididbase,resultat,infovariable,indicewid,motcle |
---|
[231] | 212 | ; |
---|
[150] | 213 | ; @version |
---|
| 214 | ; $Id$ |
---|
| 215 | ;- |
---|
[231] | 216 | PRO wid_var_event, event |
---|
| 217 | ; |
---|
[114] | 218 | compile_opt idl2, strictarrsubs |
---|
| 219 | ; |
---|
[2] | 220 | COMMON wididbase, base |
---|
| 221 | COMMON resultat, res |
---|
| 222 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
| 223 | COMMON indicewid_var, widbase1, widbase2111, widbase212, widbase213, selectatt |
---|
| 224 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
| 225 | ; |
---|
[150] | 226 | ; What is the type of event? |
---|
[2] | 227 | widget_control, event.id, get_uvalue=uval |
---|
| 228 | tailledimvar = tailledim[varcontient.dim] |
---|
| 229 | if n_elements(uval) EQ 0 then return |
---|
[150] | 230 | ; case on the type of event. |
---|
[2] | 231 | case uval OF |
---|
[150] | 232 | 1:BEGIN ; We change values in the array |
---|
| 233 | ; We check that values put in the array are not totally false. |
---|
[2] | 234 | widget_control, widbase1, get_value = table |
---|
[150] | 235 | ; Is it the good type of argument? |
---|
| 236 | ; If the type is wrong, we automatically change it by default values. |
---|
[2] | 237 | if event.x GT (size(table))[1] then return |
---|
| 238 | if event.y GT (size(table))[2] then return |
---|
| 239 | if size(table[event.x, event.y], /type) GE 6 $ |
---|
[231] | 240 | OR size(table[event.x, event.y], /type) EQ 0 then BEGIN |
---|
[2] | 241 | if event.x EQ 1 then $ |
---|
| 242 | widget_control, widbase1, use_table_select = [1, event.y,1, event.y] $ |
---|
| 243 | , set_value = tailledimvar[event.y] $ |
---|
| 244 | ELSE widget_control, widbase1 $ |
---|
| 245 | , use_table_select = [event.x, event.y, event.x, event.y], set_value = 0 |
---|
| 246 | endif |
---|
[150] | 247 | ; Argument with a wrong name value? |
---|
[2] | 248 | table = fix(table) |
---|
| 249 | case event.x of |
---|
[150] | 250 | 0:BEGIN ; We touched the offset |
---|
[2] | 251 | if table[0, event.y] LT 0 then BEGIN |
---|
| 252 | table[0, event.y] = 0 |
---|
| 253 | widget_control, widbase1, use_table_select = [0, event.y, 0, event.y] $ |
---|
| 254 | , set_value = 0 |
---|
[150] | 255 | endif |
---|
| 256 | ; If it exceed the dimension of the array, we put it at the max and the cont at 1. |
---|
[2] | 257 | if table[0, event.y] GT tailledimvar[event.y]/table[3, event.y] then begin |
---|
| 258 | widget_control, widbase1, use_table_select = [0, event.y,1, event.y] $ |
---|
| 259 | , set_value = [tailledimvar[event.y]/table[3, event.y], 1] |
---|
[150] | 260 | ENDIF ELSE BEGIN |
---|
| 261 | ; If, with the new offset, the cont is too big, we reduce it until it goes well! |
---|
[2] | 262 | if table[1, event.y] GT $ |
---|
| 263 | (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then begin |
---|
| 264 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
| 265 | , set_value = (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] |
---|
| 266 | endif |
---|
| 267 | ENDELSE |
---|
| 268 | END |
---|
[150] | 269 | 1:BEGIN ;We touched the cont. |
---|
[2] | 270 | if table[1, event.y] LT 1 then BEGIN |
---|
| 271 | table[1, event.y] = 1 |
---|
| 272 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
| 273 | , set_value = 1 |
---|
| 274 | endif |
---|
[150] | 275 | ; If it is too big, we reduce it until it goes well! |
---|
[2] | 276 | if table[1, event.y] GT $ |
---|
| 277 | (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then BEGIN |
---|
| 278 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
| 279 | , set_value = (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] |
---|
| 280 | endif |
---|
| 281 | END |
---|
[150] | 282 | 2:BEGIN ;We touched the shift. |
---|
[2] | 283 | widget_control, widbase1, use_table_select = [2, event.y, 2, event.y] $ |
---|
| 284 | , set_value = table[2, event.y] MOD (tailledimvar[event.y]/table[3, event.y]) |
---|
| 285 | END |
---|
[150] | 286 | 3:BEGIN ;We touched the stride. |
---|
[2] | 287 | if table[3, event.y] LT 1 then BEGIN |
---|
| 288 | table[3, event.y] = 1 |
---|
| 289 | widget_control, widbase1, use_table_select = [3, event.y, 3, event.y] $ |
---|
| 290 | , set_value = 1 |
---|
| 291 | endif |
---|
[150] | 292 | if table[3, event.y] EQ 0 then $ ;It must not be null. |
---|
[2] | 293 | widget_control, widbase1, use_table_select = [3, event.y, 3, event.y] $ |
---|
| 294 | , set_value = 1 |
---|
[150] | 295 | ; It must not be too big. |
---|
[2] | 296 | if table[3, event.y] GT tailledimvar[event.y] then $ |
---|
| 297 | widget_control, widbase1, use_table_select = [0, event.y,3, event.y] $ |
---|
| 298 | , set_value = [0, 1, 0, tailledimvar[event.y]] $ |
---|
| 299 | ELSE BEGIN |
---|
| 300 | if table[1, event.y] GT $ |
---|
| 301 | (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then begin |
---|
| 302 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
| 303 | , set_value = (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] |
---|
| 304 | endif |
---|
| 305 | ENDELSE |
---|
| 306 | END |
---|
| 307 | ELSE: |
---|
| 308 | endcase |
---|
| 309 | END |
---|
[150] | 310 | 2111:BEGIN ;We touched buttons yes/no |
---|
| 311 | ; We update the vector selectatt at 0 or 1 for the concerned attribute (number event.id). |
---|
[2] | 312 | selectatt[where(widbase2111 EQ event.id)] = event.select |
---|
| 313 | end |
---|
[150] | 314 | 31:BEGIN ;We pressed on 'get' |
---|
[2] | 315 | widget_control, widbase1, get_value = table |
---|
| 316 | table = fix(table) |
---|
| 317 | mcshift = where(table[2, *] NE 0) |
---|
| 318 | mcoffset = table[0, *] |
---|
| 319 | mccount = table[1, *] |
---|
| 320 | mcstride = table[3, *] |
---|
[150] | 321 | if mcshift[0] NE -1 then BEGIN ; There are some shifts. |
---|
| 322 | ; We read the wholeness of dimensions for which ones there is a shift. |
---|
[2] | 323 | mcoffset[mcshift] = 0 |
---|
| 324 | mccount[mcshift] = tailledimvar[mcshift] |
---|
[150] | 325 | ; We do not activate stride when there is no need because it makes write something weird on the screen. |
---|
[2] | 326 | if total(mcstride) EQ n_elements(mcstride) then $ |
---|
| 327 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount $ |
---|
| 328 | ELSE $ |
---|
| 329 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount, STRIDE = mcstride |
---|
[150] | 330 | ; To do the shift |
---|
[2] | 331 | mcshift = table[2, *] |
---|
| 332 | mcoffset = table[0, *] |
---|
| 333 | mccount = table[1, *] |
---|
[150] | 334 | ; We define the command allowing to do a shift. |
---|
[2] | 335 | commande = 'res=shift(res' |
---|
| 336 | for dim = 0, varcontient.ndims-1 do commande = commande+','+string(table[2,dim]) |
---|
| 337 | commande = commande+')' |
---|
| 338 | rien = execute(commande) |
---|
[150] | 339 | ; We redefine the command allowing to cut dimensions which has not been cut yet (ones we shift). |
---|
| 340 | commande = 'res=res[' ; initialization of the command |
---|
[231] | 341 | for dim = 0, varcontient.ndims-1 do BEGIN |
---|
[2] | 342 | if mcshift[dim] EQ 0 then commande = commande+'*,' $ |
---|
| 343 | ELSE commande=commande+string(mcoffset[dim])+':'+string(mccount[dim]+mcoffset[dim]-1)+',' |
---|
| 344 | ENDFOR |
---|
| 345 | commande = strmid(commande, 0, strlen(commande)-1)+']' |
---|
| 346 | rien = execute(commande) |
---|
[150] | 347 | ; Case without shift, we read directly the good part of the array. |
---|
[2] | 348 | ENDIF ELSE BEGIN |
---|
| 349 | if total(mcstride) EQ n_elements(mcstride) then $ |
---|
| 350 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount $ |
---|
| 351 | ELSE $ |
---|
| 352 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount, STRIDE = mcstride |
---|
| 353 | ENDELSE |
---|
[150] | 354 | ; Do we have to constitute a structure with selected attributes. |
---|
| 355 | if total(selectatt) NE 0 then BEGIN ; There are selected attributes |
---|
| 356 | res = create_struct(varcontient.name, res) ; We create the structure |
---|
| 357 | selectatt = where(selectatt EQ 1) ; We find selected attributes |
---|
| 358 | for attid = 0, n_elements(selectatt)-1 do BEGIN ; for which we take |
---|
| 359 | widget_control, widbase212[selectatt[attid]], get_value = attname ; the name |
---|
| 360 | widget_control, widbase213[selectatt[attid]], get_value = attvalue ; the value |
---|
| 361 | res = create_struct(res, attname[0], attvalue[0]) ; We concatenate the structure |
---|
[2] | 362 | endfor |
---|
| 363 | endif |
---|
[150] | 364 | widget_control, event.top, /destroy ;We shut the second widget. |
---|
| 365 | widget_control, base, /destroy ;We shut the first widget. |
---|
[2] | 366 | ncdf_close,cdfid |
---|
| 367 | END |
---|
[150] | 368 | 32: ;Case of the display of a held (with xdisplayfile) |
---|
| 369 | 33:widget_control, event.top, /destroy ;We shut the second widget. |
---|
[2] | 370 | ELSE: |
---|
| 371 | endcase |
---|
| 372 | return |
---|
| 373 | end |
---|
[231] | 374 | ; |
---|
[150] | 375 | ;+ |
---|
[231] | 376 | ; |
---|
[150] | 377 | ; @file_comments |
---|
[297] | 378 | ; This procedure manage the second created widget when we call xncdf_lec. |
---|
[150] | 379 | ; This widget concern the reading of the variable. |
---|
[2] | 380 | ; |
---|
[163] | 381 | ; @param WIDID_PERE {type=scalar}{in}{required} |
---|
[231] | 382 | ; It contains the identity of the father widget which was |
---|
[150] | 383 | ; created by xncdf_lec and which has allowed to select the variable to be read. |
---|
[2] | 384 | ; |
---|
[297] | 385 | ; @results |
---|
| 386 | ; indirectement res (le tableau ou la structure resultat) |
---|
[2] | 387 | ; |
---|
[231] | 388 | ; @uses |
---|
[150] | 389 | ; resultat,infovariable,indicewid_var,motcle |
---|
[2] | 390 | ; |
---|
[150] | 391 | ; @version |
---|
| 392 | ; $Id$ |
---|
| 393 | ;- |
---|
| 394 | PRO wid_var, widid_pere |
---|
[114] | 395 | ; |
---|
| 396 | compile_opt idl2, strictarrsubs |
---|
| 397 | ; |
---|
[2] | 398 | COMMON resultat, res |
---|
| 399 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
| 400 | COMMON indicewid_var, widbase1, widbase2111, widbase212, widbase213, selectatt |
---|
| 401 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
| 402 | res = -1 |
---|
| 403 | ;------------------------------------------------------------ |
---|
[150] | 404 | ; Opening of the base window as columns. |
---|
[2] | 405 | widbase = widget_base(/column, title='variable: '+varcontient.name, /align_center, group_leader = widid_pere) |
---|
| 406 | ;------------------------------------------------------------ |
---|
[231] | 407 | ; Opening of the base subwindow |
---|
[2] | 408 | ;------------------------------------------------------------ |
---|
[150] | 409 | ; widbase1 array of offsets |
---|
[2] | 410 | ;------------------------------------------------------------ |
---|
[150] | 411 | rien = widget_label(widbase, value = ' ') ; We jump a line |
---|
| 412 | ; Definition of labels of lines of the array |
---|
[2] | 413 | rowlab = string(tailledim[varcontient.dim]) |
---|
| 414 | for i = 0, n_elements(rowlab)-1 do rowlab[i] = strtrim(rowlab[i], 1) |
---|
| 415 | rowlab = nomdim[varcontient.dim]+replicate(': ', n_elements(varcontient.dim))+rowlab |
---|
[150] | 416 | ; Definition of array's initial values |
---|
[2] | 417 | valinit = lonarr(4, n_elements(varcontient.dim)) |
---|
[150] | 418 | ; column 0 : offsets |
---|
[2] | 419 | if keyword_set(mcoffset) AND n_elements(mcoffset) EQ varcontient.ndims THEN $ |
---|
| 420 | valinit[0,*]=mcoffset ELSE valinit[0, *] = 0 |
---|
[150] | 421 | ; colomn 1 : counts |
---|
[2] | 422 | if keyword_set(mccount) AND n_elements(mccount) EQ varcontient.ndims THEN $ |
---|
| 423 | valinit[1,*]=mccount ELSE valinit[1, *] = tailledim[varcontient.dim] |
---|
[150] | 424 | ; column 2 : shifts |
---|
[2] | 425 | if keyword_set(mcshift) AND n_elements(mcshift) EQ varcontient.ndims THEN $ |
---|
| 426 | valinit[2,*]=mcshift ELSE valinit[2, *] = 0 |
---|
[150] | 427 | ; column 3 : strides |
---|
[2] | 428 | if keyword_set(mcstride) AND n_elements(mcstride) EQ varcontient.ndims THEN $ |
---|
| 429 | valinit[3,*]=mcstride ELSE valinit[3, *] = 1 |
---|
[150] | 430 | ; test of initial values of the array |
---|
[2] | 431 | valinit = fix(valinit) |
---|
[150] | 432 | valinit[3, *] = 1 > valinit[3, *] < tailledim[varcontient.dim] ; test of strides |
---|
| 433 | valinit[0, *] = 0 > valinit[0, *] < tailledim[varcontient.dim] ; test of offsets |
---|
| 434 | ; test of counts |
---|
[2] | 435 | valinit[1, *] = 1 > valinit[1, *] < ((tailledim[varcontient.dim]/valinit[3, *])-valinit[0, *]) |
---|
[150] | 436 | valinit[2, *] = valinit[2, *] MOD (tailledim[varcontient.dim]/valinit[3, *]) ; test of shifts |
---|
| 437 | ; declaration of the array |
---|
[2] | 438 | widbase1 = widget_table(widbase, row_labels = rowlab, value = valinit, /editable $ |
---|
| 439 | , column_labels = ['Offset', 'Count', 'Shift', 'Stride'], uvalue = 1) |
---|
| 440 | ; un petit blabla |
---|
| 441 | rien = widget_label(widbase, value = 'ATTENTION: Faire des ''return'' pour que les valeurs', /align_center) |
---|
| 442 | rien = widget_label(widbase, value = 'du tableau ou des textes soient bien prises en compte', /align_center) |
---|
| 443 | ;------------------------------------------------------------ |
---|
[150] | 444 | ; widbase2 choice of attributes |
---|
[2] | 445 | ;------------------------------------------------------------ |
---|
[150] | 446 | rien = widget_label(widbase, value = ' ') ; We jump a line |
---|
[2] | 447 | widbase2 = widget_base(widbase, /column) |
---|
[231] | 448 | ; To each attribute, we created a widget (widbase21) containing in line a button |
---|
[297] | 449 | ; yes/no (widbase211), and two widget text (widbase212, widbase213) comprising the |
---|
[150] | 450 | ; name and the value of the attribute. |
---|
[2] | 451 | widbase21 = lonarr(varcontient.natts) |
---|
| 452 | widbase211 = lonarr(varcontient.natts) |
---|
| 453 | widbase2111 = lonarr(varcontient.natts) |
---|
[150] | 454 | ; Vector which will serve to know which yes/no are selected. see. wid_var_event |
---|
[2] | 455 | selectatt = lonarr(varcontient.natts) |
---|
| 456 | selectatt[*] = 0 |
---|
| 457 | widbase212 = lonarr(varcontient.natts) |
---|
| 458 | widbase213 = lonarr(varcontient.natts) |
---|
[297] | 459 | for attid = 0, varcontient.natts-1 do BEGIN ;Loop on the number of attribute. |
---|
[2] | 460 | widbase21[attid] = widget_base(widbase2, /row) |
---|
| 461 | name=ncdf_attname(cdfid,varid,attid) |
---|
| 462 | ncdf_attget,cdfid,varid,name,value |
---|
| 463 | widbase211[attid] = widget_base(widbase21[attid], /nonexclusive) |
---|
| 464 | widbase2111[attid] = widget_button(widbase211[attid], value = ' ', uvalue = 2111) |
---|
| 465 | widbase212[attid] = widget_text(widbase21[attid], value = name, /editable) |
---|
| 466 | widbase213[attid] = widget_text(widbase21[attid], value=strtrim(string(value),1), /editable) |
---|
| 467 | endfor |
---|
| 468 | ;------------------------------------------------------------ |
---|
[150] | 469 | ; widbase3 buttons of the bottom. |
---|
[2] | 470 | ;------------------------------------------------------------ |
---|
| 471 | widbase3 = widget_base(widbase, /row,/align_center) |
---|
| 472 | widbase31=widget_button(widbase3,value='GET', uvalue=31) |
---|
| 473 | widbase32=widget_button(widbase3,value='Help', uvalue=32) |
---|
| 474 | widbase33=widget_button(widbase3,value='DONE', uvalue=33) |
---|
| 475 | ;------------------------------------------------------------ |
---|
[150] | 476 | ;execution of the base window and of sub-window. |
---|
[2] | 477 | ;------------------------------------------------------------ |
---|
| 478 | widget_control,widbase,/realize |
---|
| 479 | ;------------------------------------------------------------ |
---|
| 480 | xmanager,'wid_var',widbase |
---|
| 481 | return |
---|
| 482 | end |
---|
[231] | 483 | ; |
---|
[150] | 484 | ;+ |
---|
[231] | 485 | ; |
---|
[150] | 486 | ; @file_comments |
---|
[231] | 487 | ; Procedure called by xmanager when we press a button of the first widget |
---|
[150] | 488 | ; created by par xncdf_lec |
---|
[231] | 489 | ; |
---|
[150] | 490 | ; @param EVENT |
---|
[297] | 491 | ; A structure characterising the event type which arrive at the widget number 1. |
---|
[2] | 492 | ; |
---|
[150] | 493 | ; @uses |
---|
| 494 | ; resultat, infovariable, motcle |
---|
[2] | 495 | ; |
---|
[150] | 496 | ; @version |
---|
| 497 | ; $Id$ |
---|
| 498 | ;- |
---|
| 499 | PRO xncdf_lec_event, event |
---|
[114] | 500 | ; |
---|
| 501 | compile_opt idl2, strictarrsubs |
---|
| 502 | ; |
---|
[2] | 503 | COMMON resultat, res |
---|
| 504 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
| 505 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
[150] | 506 | ; What is the type of event? |
---|
[2] | 507 | widget_control, event.id, get_uvalue=uval |
---|
[150] | 508 | ; case on the type of event. |
---|
[2] | 509 | case uval of |
---|
[150] | 510 | 1:BEGIN ; We want to read an other file |
---|
| 511 | widget_control, event.id, get_value = nom ; We recuperate the name. |
---|
| 512 | widget_control, event.top, /destroy ;We shut the widget. |
---|
| 513 | ncdf_close,cdfid ;We shut the wrong file which has been opened. |
---|
| 514 | ;We call back xncdf_lec |
---|
[2] | 515 | res = xncdf_lec(nom[0], ATT = mcatt, COUNT = mccount, OFFSET = mcoffset, IODIR = mciodir $ |
---|
[231] | 516 | , SHIFT = mcshift, STRIDE = mcstride, VAR = mcvar) |
---|
[2] | 517 | return |
---|
| 518 | END |
---|
[150] | 519 | 2:BEGIN ; A variable is selected. |
---|
| 520 | varid = event.index ; We recuperat its number in the file Netcdf |
---|
[2] | 521 | varcontient = ncdf_varinq(cdfid,varid) |
---|
[150] | 522 | wid_var, event.top ; We call the program which launch the second widget. See sooner. |
---|
[2] | 523 | END |
---|
[150] | 524 | 3:BEGIN ; button done |
---|
| 525 | widget_control, event.top, /destroy ; We delete the widget |
---|
| 526 | ncdf_close,cdfid ; We shut the file. |
---|
[2] | 527 | END |
---|
| 528 | ELSE: |
---|
| 529 | endcase |
---|
| 530 | return |
---|
| 531 | end |
---|