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