Changeset 150 for trunk/SRC/ToBeReviewed/LECTURE
- Timestamp:
- 08/09/06 12:12:54 (18 years ago)
- Location:
- trunk/SRC/ToBeReviewed/LECTURE
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/LECTURE/GRIB/bit2int.pro
r134 r150 1 ;+ 2 ; 3 ; @todo 4 ; seb 5 ; 6 ;- 1 7 FUNCTION bit2int, bitin, checkneg = checkneg 2 8 ; -
trunk/SRC/ToBeReviewed/LECTURE/read_ftp.pro
r142 r150 38 38 ;+ 39 39 ; 40 ; Syntax:40 ; @file_comments 41 41 ; READ_FTP, remote_host [, files] [, directory] [,/FILE] [,DATA=variable] 42 42 ; [,USER=string] [,PASS=string] [,/PTR] … … 118 118 ; $Id$ 119 119 ; 120 ; @todo seb: que fait-on de "syntax" au debut du header? 120 ; @todo 121 ; seb: que fait-on de "syntax" au debut du header? 122 ; give examples with date in year 0 (should not exists but may happen) 121 123 ; 122 124 ;- -
trunk/SRC/ToBeReviewed/LECTURE/read_ncdf.pro
r142 r150 1 ;------------------------------------------------------------2 ;------------------------------------------------------------3 ;------------------------------------------------------------4 1 ;+ 5 ; 6 ; PURPOSE:fonction de lecture pour fichier net_cdf. 7 ; Ce programme, est moins universel que ncdf_lec (il fait appelle au 8 ; variables declarees dans common.pro) mais il est du cop bcp plus 9 ; facile d''utilisation. Il prend en compte la declaration des 10 ; differents zoom qui ont ete definis (ixminmesh...premierx...) la 11 ; declaration de la variable key_shift... bref le resultat de 12 ; read_ncdf peut dorectement etre utilise dans plt... 13 ; C''est aussi ce programme qui est utilise par defaut dans mes 14 ; widgets pour la partie lecture. 15 ; 16 ; CATEGORY:lecture de fichiers NetCdf 17 ; 18 ; CALLING SEQUENCE:res = read_ncdf(name,debut[,fin]) 19 ; 20 ; INPUTS: name: un string definissant le champ a lire. 21 ; debut et fin: sont relatifs a l''axe des temps. Ce peut etre 22 ; - 2 dates du type yyyymmdd et ds ce cas on selectionne les 23 ; dates qui sont comprisent entre ces 2 dates. 24 ; - 2 indices qui definissent entre quel et quel pas de temps 25 ; on doit extraire la dimension temporelle. 26 ; exp: ne sert a rien! 27 ; 28 ; KEYWORD PARAMETERS: utilisables hors du contexte des widgets 29 ; 30 ; BOXZOOM: contient la boxzoom sur laquelle on doit faire la 31 ; lecture 32 ; FILENAME: string contennant le nom du fichier 33 ; /INIT; to call automatically initncdf, filename and thus 34 ; redefine all the grid parameters 35 ; GRID='[UTVWF]' to specify the type of grid. Defaut is (1) 36 ; based on the name of the file if the file ends by 37 ; GRID[._][TUVFW].NC (not case sensible) or (2) T if case (1) 38 ; is not found. 39 ; IODIRECTORY;a string giving the name of iodirectory (see 40 ; isafile.pro for all possibilities). default value is common 41 ; variable iodir 42 ; TIMESTEP:activer pour specifier que debut et fin font 43 ; reference a des indices de l''axe du temps et non pas a des 44 ; dates. 45 ; TOUT: activer si on veut lire le ficher sur l''ensemble du 46 ; domaine sans tenir compte du sous domaine definit par boxzoom 47 ; ou lon1,lon2,lat1,lat2,vert1,vert2. 48 ; NOSTRUCT: activer si on ne veut pas que read_ncdf reourne 49 ; une structure mais uniquement le tableau se rapportant au 50 ; champ. 51 ; TIMEVAR: a string to define the name of the variable that 52 ; contains the time axis. This keyword can be usefull if there 53 ; is no unlimited dimension or if the time axis selected by defaut 54 ; (the first 1D array with unlimited dimension) is not the good one 55 ; 56 ; 57 ; OUTPUTS:une stucture lisible par litchamp.pro ou un simple tableau 58 ; si /NOSTRUCT est active 59 ; 60 ; COMMON BLOCKS:common.pro 61 ; 62 ; SIDE EFFECTS: 63 ; 64 ; RESTRICTIONS:le champ doit avoir une dimension temporelle 65 ; 66 ; EXAMPLE: 67 ; 68 ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) 69 ; 15/10/1999 2 ; @file_comments 3 ; Reading function for the file net_cdf. 4 ; This program is less universal than ncdf_lec (it appeal to declarated 5 ; variables in common.pro) but it is very easier to be used. It considerate 6 ; the declaration of the different zooms which have been defined 7 ; (ixminmesh...premierx...), the declaration of the variable key_shift... 8 ; To put it in a nutshell, the result of read_ncdf can be directly used in plt... 9 ; This is also this program which is used by default inour reading widgets. 10 ; 11 ; @categories 12 ; reading 13 ; 14 ; 15 ; @param NAME {in}{required} 16 ; It is a string defining the field to be read. 17 ; 18 ; @param BEGINNING {in}{required} 19 ; Relative with the time axis. 20 ; These can be 21 ; - 2 date of the type yyyymmdd and in this case, we select dates 22 ; which are included between these two dates. 23 ; - 2 indexes which define between which and which time step we have 24 ; to extract the telporal dimension. 25 ; 26 ; @param ENDING {in}{required} 27 ; Relative with the time axis. 28 ; See BEGINNING. 29 ; 30 ; @param COMPATIBILITY {in}{required} 31 ; Useless 32 ; 33 ; @keyword BOXZOOM 34 ; Contain the boxzoom on which we have to do the reading 35 ; 36 ; @keyword FILENAME 37 ; It is a string containing the file's name. 38 ; 39 ; @keyword INIT 40 ; To call automatically initncdf, filename and thus 41 ; redefine all the grid parameters 42 ; 43 ; @keyword GRID 44 ; ='[UTVWF]' to specify the type of grid. Defaut is (1) 45 ; based on the name of the file if the file ends by 46 ; GRID[._][TUVFW].NC (not case sensible) or (2) T if case (1) 47 ; is not found. 48 ; 49 ; @keyword IODIRECTORY 50 ; It isa string giving the name of iodirectory (see isafile.pro 51 ; for all possibilities). default value is common variable iodir. 52 ; 53 ; @keyword TIMESTEP 54 ; We activate to specify that BEGINNING and ENDING refer to indexes 55 ; of the time axis and not to dates 56 ; 57 ; @keyword TOUT 58 ; We activate it if we want to read the file on the whole domain without 59 ; considerate the sub-domain defined by the boxzoom or 60 ; lon1,lon2,lat1,lat2,vert1,vert2. 61 ; 62 ; @keyword NOSTRUCT 63 ; We activate it if we do not want that read_ncdf send back a structure 64 ; but only the array refering to the field. 65 ; 66 ; @keyword TIMEVAR 67 ; It is a string which define the name of the variable that 68 ; contains the time axis. This keyword can be usefull if there 69 ; is no unlimited dimension or if the time axis selected by defaut 70 ; (the first 1D array with unlimited dimension) is not the good one. 71 ; 72 ; @keyword _EXTRA 73 ; Used to pass your keywords 74 ; 75 ; @returns 76 ; Structure readable by litchamp.pro or an array if NOSRUCT is activated. 77 ; 78 ; @uses 79 ; common.pro 80 ; 81 ; @restrictions 82 ; The field must have a temporal dimension. 83 ; 84 ; @history 85 ; Sebastien Masson (smasson@lodyc.jussieu.fr) 86 ; 15/10/1999 87 ; 88 ; @version 89 ; $Id$ 70 90 ;- 71 ;------------------------------------------------------------ 72 ;------------------------------------------------------------ 73 ;------------------------------------------------------------ 74 FUNCTION read_ncdf, name, debut, fin, pour_etre_compatible, BOXZOOM = boxzoom, FILENAME = filename $ 91 ;--------------------------------------------------------- 92 ;--------------------------------------------------------- 93 ;--------------------------------------------------------- 94 95 FUNCTION read_ncdf, name, beginning, ending, compatibility, BOXZOOM = boxzoom, FILENAME = filename $ 75 96 , PARENTIN = parentin, TIMESTEP = timestep, TIMEVAR = timevar $ 76 97 , TOUT = tout, NOSTRUCT = nostruct, CONT_NOFILL = CONT_NOFILL, INIT = init $ … … 98 119 filename = isafile(filename = filename, IODIRECTORY = iodir, _EXTRA = ex) 99 120 ;------------------------------------------------------------ 100 ; ouverture du fichier nom121 ; Opening of the name file 101 122 ;------------------------------------------------------------ 102 123 if size(filename, /type) NE 7 then $ … … 118 139 if keyword_set(init) THEN initncdf, filename, _extra = ex 119 140 ;------------------------------------------------------------ 120 ; check the time axis and the debut and findates121 ;------------------------------------------------------------ 122 if n_elements( debut) EQ 0 then begin123 debut= 0141 ; check the time axis and the debut and ending dates 142 ;------------------------------------------------------------ 143 if n_elements(beginning) EQ 0 then begin 144 beginning = 0 124 145 timestep = 1 125 146 endif 126 147 if keyword_set(timestep) then begin 127 firsttps = debut[0]128 if n_elements( fin) NE 0 then lasttps = fin[0] ELSE lasttps = firsttps148 firsttps = beginning[0] 149 if n_elements(ending) NE 0 then lasttps = ending[0] ELSE lasttps = firsttps 129 150 jpt = lasttps-firsttps+1 130 151 time = julday(1, 1, 1) + lindgen(jpt) … … 136 157 currentfile = (where(filelist EQ filename))[0] 137 158 time = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).time_counter 138 date1 = date2jul( debut[0])139 if n_elements( fin) NE 0 then date2 = date2jul(fin[0]) ELSE date2 = date1159 date1 = date2jul(beginning[0]) 160 if n_elements(ending) NE 0 then date2 = date2jul(ending[0]) ELSE date2 = date1 140 161 firsttps = where(time EQ date1) & firsttps = firsttps[0] 141 162 lasttps = where(time EQ date2) & lasttps = lasttps[0] … … 159 180 ; we find the FIRST time axis 160 181 timeid = 0 161 repeat BEGIN ; tant que l''on a pas trouve une variable qui n''a qu'' 162 ; une dimension: la dimension infinie 163 timecontient = ncdf_varinq(cdfid, timeid) ; que contient la variable 182 repeat BEGIN ; As long as we have not find a variable having only one dimension: the infinite one 183 timecontient = ncdf_varinq(cdfid, timeid) ; that the variable contain. 164 184 timeid = timeid+1 165 185 endrep until (n_elements(timecontient.dim) EQ 1 $ … … 188 208 ; 189 209 ; now we try to find the attribut called calendar... 190 ; the theattribute "calendar" exists?210 ; the attribute "calendar" exists? 191 211 ; If no, we suppose that the calendar is gregorian calendar 192 212 ; … … 248 268 end 249 269 ENDCASE 250 date1 = date2jul( debut[0])251 if n_elements( fin) NE 0 then date2 = date2jul(fin[0]) ELSE date2 = date1270 date1 = date2jul(beginning[0]) 271 if n_elements(ending) NE 0 then date2 = date2jul(ending[0]) ELSE date2 = date1 252 272 time = double(time) 253 273 firsttps = where(time GE date1) & firsttps = firsttps[0] … … 271 291 ENDELSE 272 292 ;------------------------------------------------------------ 273 ; nom de la grille a laquelle se rapporte le champ293 ; Name of the grid on which the field refer to. 274 294 ;------------------------------------------------------------ 275 295 IF keyword_set(grid) THEN vargrid = strupcase(grid) ELSE BEGIN … … 294 314 295 315 ;--------------------------------------------------------------- 296 ; redefinition du domaine316 ; redefinition of the domain 297 317 ;--------------------------------------------------------------- 298 318 if keyword_set(tout) then begin … … 331 351 ENDIF 332 352 grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz 333 undefine, glam & undefine, gphi & ; on libere un peu de memoire!353 undefine, glam & undefine, gphi & ; We liberate some memoty! 334 354 ENDELSE 335 355 ;--------------------------------------------------------------------- 336 ; on initialise les ixmindta, iymindta au besoin356 ; We initializate ixmindta, iymindta if needed 337 357 ;--------------------------------------------------------------------- 338 358 if n_elements(jpidta) EQ 0 THEN jpidta = jpiglo … … 352 372 IF izmaxdta EQ -1 then izmaxdta = jpkdta-1 353 373 ;---------------------------------------------------------------- 354 ; on va lire le fichier374 ; We will read the file 355 375 ;--------------------------------------------------------------- 356 376 if n_elements(key_stride) LE 2 then key_stride = [1, 1, 1] … … 401 421 AND (strupcase(vargrid) EQ 'U' OR strupcase(vargrid) EQ 'F') THEN key_shift = key_shift+1 402 422 ;--------------------------------------------------------------------- 403 ; on definit les variables globales rattachees a la variable423 ; We define global variable joined with the variable. 404 424 ;--------------------------------------------------------------------- 405 425 ; varname … … 434 454 ENDELSE 435 455 ; vardate 436 ; on construit une belle date lisible en fonction du langage specifie !!!437 year = long( debut[0])/10000438 month = (long( debut[0])/100) MOD 100439 day = (long( debut[0]) MOD 100)456 ; We make a legible date in function of the specified language. 457 year = long(beginning[0])/10000 458 month = (long(beginning[0])/100) MOD 100 459 day = (long(beginning[0]) MOD 100) 440 460 vardate = string(format = '(C(CMoA))', 31*(month-1))+' '+strtrim(day, 1)+', '+strtrim(year, 1) 441 461 varexp = file_basename(filename) … … 446 466 if keyword_set(key_zreverse) AND (size(res))[0] EQ 4 THEN res = reverse(temporary(res), 3) 447 467 448 ; on applique la valeur valmask sur les points terre468 ; We apply the value valmask on land points. 449 469 if NOT keyword_set(cont_nofill) then begin 450 470 valmask = 1e20 … … 482 502 ; ENDIF ELSE missing = -1 483 503 ENDIF ELSE missing = -1 484 ; on applique les add_offset, scale_factor et missing_value504 ; we apply add_offset, scale_factor and missing_value 485 505 if scale_factor NE 1 then res = temporary(res)*scale_factor 486 506 if add_offset NE 0 then res = temporary(res)+add_offset -
trunk/SRC/ToBeReviewed/LECTURE/xncdf_lec.pro
r134 r150 1 ;------------------------------------------------------------ 2 ;------------------------------------------------------------ 3 ;------------------------------------------------------------ 4 ;+ 5 ; 6 ; @file_comments 7 ; Reading of a Net Cdf file with widgets ! 8 ; 9 ; @categories 10 ; widget 11 ; 12 ; @param NAME {in}{optional} 13 ; It is a string giving the name of the file to be opened. If NAME 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 ; 17 ; @keyword IODIR 18 ; It is a string containing the directory where to go look for the file to be read. 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 ; 22 ; @keyword COUNT 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 ; 33 ; @keyword OFFSET 34 ; An optional vector containing the starting position 35 ; for the read. The default start position is [0, 0, ...]. 36 ; 37 ; @keyword SHIFT 38 ; A vector of integers, specifing for each dimension how much we have to shift it. 39 ; By default, it is [0,0,...]. See the function shift for more explanations. BEWARE, 40 ; the shift is done on the biggest array before a possible reduction determinated 41 ; by OFFSET and COUNT. On the other hand, it is done after the possible extraction 42 ; created by the STRIDE. 43 ; 44 ; @keyword STRIDE 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 64 ; Sebastien Masson (smasson@lodyc.jussieu.fr) 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 ; 1 202 ; La lecture de ce programme se fait de bas en haut: 2 203 ; 1) xncdf_lec … … 5 206 ; --> wid_var_event 6 207 ; 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 214 ; 215 ; @uses 216 ; wididbase,resultat,infovariable,indicewid,motcle 217 ; 218 ; @version 219 ; $Id$ 220 ;- 221 ;------------------------------------------------------------ 222 ;------------------------------------------------------------ 223 ;------------------------------------------------------------ 7 224 pro wid_var_event, event 8 ; NAME:wid_var_event9 ;10 ; PURPOSE:procedure appele par xmanager qd on appuie sur un bouton du11 ; 2eme widget cree par wid_var12 ;13 ; INPUTS: event, une structure caracterisant le type d''evenement qui14 ; arrive au widget numero1 215 ;16 ; COMMON BLOCKS:wididbase,resultat,infovariable,indicewid,motcle17 ;------------------------------------------------------------18 ;------------------------------------------------------------19 ;------------------------------------------------------------20 225 ; 21 226 compile_opt idl2, strictarrsubs … … 27 232 COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar 28 233 ; 29 ; quel est le type d''evenement?234 ; What is the type of event? 30 235 widget_control, event.id, get_uvalue=uval 31 236 tailledimvar = tailledim[varcontient.dim] 32 237 if n_elements(uval) EQ 0 then return 33 ; case sur le type d''evenement238 ; case on the type of event. 34 239 case uval OF 35 1:BEGIN ; on change des valeurs dans le tableau 36 ; on controle que les valeurs mises dans le tableau ne sont pas 37 ; completement fausses 240 1:BEGIN ; We change values in the array 241 ; We check that values put in the array are not totally false. 38 242 widget_control, widbase1, get_value = table 39 ; agument du bon type ? 40 ; si le type est mauvais on change automatiquement par des valeurs par 41 ; defaut 243 ; Is it the good type of argument? 244 ; If the type is wrong, we automatically change it by default values. 42 245 if event.x GT (size(table))[1] then return 43 246 if event.y GT (size(table))[2] then return … … 50 253 , use_table_select = [event.x, event.y, event.x, event.y], set_value = 0 51 254 endif 52 ; agument avec une valeur nom debile?255 ; Argument with a wrong name value? 53 256 table = fix(table) 54 257 case event.x of 55 0:BEGIN ; on a touche a l''offset:258 0:BEGIN ; We touched the offset 56 259 if table[0, event.y] LT 0 then BEGIN 57 260 table[0, event.y] = 0 58 261 widget_control, widbase1, use_table_select = [0, event.y, 0, event.y] $ 59 262 , set_value = 0 60 61 ; si il depasse la dim du tableau on le met au max et le cont a 1263 endif 264 ; If it exceed the dimension of the array, we put it at the max and the cont at 1. 62 265 if table[0, event.y] GT tailledimvar[event.y]/table[3, event.y] then begin 63 266 widget_control, widbase1, use_table_select = [0, event.y,1, event.y] $ 64 267 , set_value = [tailledimvar[event.y]/table[3, event.y], 1] 65 ENDIF ELSE BEGIN 66 ; si avec le nouvel offset le count est trop grand, on le diminue juste 67 ; de ce qu''il faut! 268 ENDIF ELSE BEGIN 269 ; If, with the new offset, the cont is too big, we reduce it until it goes well! 68 270 if table[1, event.y] GT $ 69 271 (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then begin … … 73 275 ENDELSE 74 276 END 75 1:BEGIN ; on a touche au count277 1:BEGIN ;We touched the cont. 76 278 if table[1, event.y] LT 1 then BEGIN 77 279 table[1, event.y] = 1 … … 79 281 , set_value = 1 80 282 endif 81 ; si il est trop grand, on le diminue juste de ce qu''il faut!283 ; If it is too big, we reduce it until it goes well! 82 284 if table[1, event.y] GT $ 83 285 (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then BEGIN … … 86 288 endif 87 289 END 88 2:BEGIN ; on a touche au shift290 2:BEGIN ;We touched the shift. 89 291 widget_control, widbase1, use_table_select = [2, event.y, 2, event.y] $ 90 292 , set_value = table[2, event.y] MOD (tailledimvar[event.y]/table[3, event.y]) 91 293 END 92 3:BEGIN ; on touche au stride294 3:BEGIN ;We touched the stride. 93 295 if table[3, event.y] LT 1 then BEGIN 94 296 table[3, event.y] = 1 … … 96 298 , set_value = 1 97 299 endif 98 if table[3, event.y] EQ 0 then $ ; il ne doit pas etre nul300 if table[3, event.y] EQ 0 then $ ;It must not be null. 99 301 widget_control, widbase1, use_table_select = [3, event.y, 3, event.y] $ 100 302 , set_value = 1 101 ; il ne doit pas etre trop grand303 ; It must not be too big. 102 304 if table[3, event.y] GT tailledimvar[event.y] then $ 103 305 widget_control, widbase1, use_table_select = [0, event.y,3, event.y] $ … … 114 316 endcase 115 317 END 116 2111:BEGIN ;on a touche aux boutons oui/non 117 ; on actualise le vecteur selectatt a 0 ou 1 pour l''attribut concerne 118 ; (numero event.id) 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). 119 320 selectatt[where(widbase2111 EQ event.id)] = event.select 120 321 end 121 31:BEGIN ; on a appuye sur'get'322 31:BEGIN ;We pressed on 'get' 122 323 widget_control, widbase1, get_value = table 123 324 table = fix(table) … … 126 327 mccount = table[1, *] 127 328 mcstride = table[3, *] 128 if mcshift[0] NE -1 then BEGIN ; il y a des shifts129 ; on lit l''integralite des dimensions pour lesquelles il y a un shift329 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. 130 331 mcoffset[mcshift] = 0 131 332 mccount[mcshift] = tailledimvar[mcshift] 132 ; on active pas stride qd il n''y en a pas besoin car ca fait ecrire a 133 ; l''ecran qqch de louche... 333 ; We do not activate stride when there is no need because it makes write something weird on the screen. 134 334 if total(mcstride) EQ n_elements(mcstride) then $ 135 335 ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount $ 136 336 ELSE $ 137 337 ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount, STRIDE = mcstride 138 ; pour faire le shift338 ; To do the shift 139 339 mcshift = table[2, *] 140 340 mcoffset = table[0, *] 141 341 mccount = table[1, *] 142 ; on definit commende qui permet de faire un shift342 ; We define the command allowing to do a shift. 143 343 commande = 'res=shift(res' 144 344 for dim = 0, varcontient.ndims-1 do commande = commande+','+string(table[2,dim]) 145 345 commande = commande+')' 146 346 rien = execute(commande) 147 ; on redefinit commnade qui permet de couper les dimensions qui n''ont 148 ; pas ete encore coupees (c''est celles que l''on shift) 149 commande = 'res=res[' ; initialisation de la commende 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 150 349 for dim = 0, varcontient.ndims-1 do BEGIN 151 350 if mcshift[dim] EQ 0 then commande = commande+'*,' $ … … 154 353 commande = strmid(commande, 0, strlen(commande)-1)+']' 155 354 rien = execute(commande) 156 ; cas sans shift, on lit directement le bon bout de tableau355 ; Case without shift, we read directly the good part of the array. 157 356 ENDIF ELSE BEGIN 158 357 if total(mcstride) EQ n_elements(mcstride) then $ … … 161 360 ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount, STRIDE = mcstride 162 361 ENDELSE 163 ; faut-il constituer une structure avec les attributs qui on ete selectionnes164 if total(selectatt) NE 0 then BEGIN ; il y a des attributs selectionnes165 res = create_struct(varcontient.name, res) ; on cree lastructure166 selectatt = where(selectatt EQ 1) ; on trouve les attributs selectiones167 for attid = 0, n_elements(selectatt)-1 do BEGIN ; pour lesquels on prend168 widget_control, widbase212[selectatt[attid]], get_value = attname ; le nom169 widget_control, widbase213[selectatt[attid]], get_value = attvalue ; la valeur170 res = create_struct(res, attname[0], attvalue[0]) ; on concatene la structe362 ; 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 171 370 endfor 172 371 endif 173 widget_control, event.top, /destroy ; on ferme le 2eme widget174 widget_control, base, /destroy ; on ferme le 1eme widget372 widget_control, event.top, /destroy ;We shut the second widget. 373 widget_control, base, /destroy ;We shut the first widget. 175 374 ncdf_close,cdfid 176 375 END 177 32: ; cas de l''affichage d''un held (avecxdisplayfile)178 33:widget_control, event.top, /destroy ; on ferme le 2eme widget376 32: ;Case of the display of a held (with xdisplayfile) 377 33:widget_control, event.top, /destroy ;We shut the second widget. 179 378 ELSE: 180 379 endcase … … 183 382 ;------------------------------------------------------------ 184 383 ;------------------------------------------------------------ 384 ;------------------------------------------------------------ 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. 389 ; 390 ; @param WIDID_PERE {in}{required} 391 ; It is a scalar containing the identity of the father widget which was 392 ; created by xncdf_lec and which has allowed to select the variable to be read. 393 ; 394 ; OUTPUTS: indirectement res (le tableau ou la structure resultat) 395 ; 396 ; @uses 397 ; resultat,infovariable,indicewid_var,motcle 398 ; 399 ; @version 400 ; $Id$ 401 ;- 402 ;------------------------------------------------------------ 403 ;------------------------------------------------------------ 404 ;------------------------------------------------------------ 185 405 PRO wid_var, widid_pere 186 ;------------------------------------------------------------187 ;------------------------------------------------------------188 ;------------------------------------------------------------189 ; NAME: wid_var190 ;191 ; PURPOSE: cette procedure gere le 2eme widget cree qd on appelle192 ; xncdf_lec. ce widget concerne la lecture de la variable193 ;194 ; INPUTS: widid_pere: un scalere contenant l'identite du widget pere195 ; qui a etait cree par xncdf_lec et qui a permis de selectionner la196 ; variable a lire.197 ;198 ; OUTPUTS: indirectement res (le tableau ou la structure resultat)199 ;200 ; COMMON BLOCKS:resultat,infovariable,indicewid_var,motcle201 ;202 ;------------------------------------------------------------203 ;------------------------------------------------------------204 ;------------------------------------------------------------205 406 ; 206 407 compile_opt idl2, strictarrsubs … … 212 413 res = -1 213 414 ;------------------------------------------------------------ 214 ; ouverture de la fenetre de base sous forme de colonnes 215 ;------------------------------------------------------------ 415 ; Opening of the base window as columns. 216 416 widbase = widget_base(/column, title='variable: '+varcontient.name, /align_center, group_leader = widid_pere) 217 417 ;------------------------------------------------------------ 218 ; ouverture de sous-fenetres de base ;219 ;------------------------------------------------------------ 220 ; widbase1 tableau desoffsets221 ;------------------------------------------------------------ 222 rien = widget_label(widbase, value = ' ') ; on saute une ligne223 ; defintion des lables des lignes du tableau418 ; Opening of the base subwindow 419 ;------------------------------------------------------------ 420 ; widbase1 array of offsets 421 ;------------------------------------------------------------ 422 rien = widget_label(widbase, value = ' ') ; We jump a line 423 ; Definition of labels of lines of the array 224 424 rowlab = string(tailledim[varcontient.dim]) 225 425 for i = 0, n_elements(rowlab)-1 do rowlab[i] = strtrim(rowlab[i], 1) 226 426 rowlab = nomdim[varcontient.dim]+replicate(': ', n_elements(varcontient.dim))+rowlab 227 ; definition des valeurs initiales du tableau427 ; Definition of array's initial values 228 428 valinit = lonarr(4, n_elements(varcontient.dim)) 229 ; col onne 0 : les offset429 ; column 0 : offsets 230 430 if keyword_set(mcoffset) AND n_elements(mcoffset) EQ varcontient.ndims THEN $ 231 431 valinit[0,*]=mcoffset ELSE valinit[0, *] = 0 232 ; colo nne 1 : lescounts432 ; colomn 1 : counts 233 433 if keyword_set(mccount) AND n_elements(mccount) EQ varcontient.ndims THEN $ 234 434 valinit[1,*]=mccount ELSE valinit[1, *] = tailledim[varcontient.dim] 235 ; col onne 2 : lesshifts435 ; column 2 : shifts 236 436 if keyword_set(mcshift) AND n_elements(mcshift) EQ varcontient.ndims THEN $ 237 437 valinit[2,*]=mcshift ELSE valinit[2, *] = 0 238 ; col onne 3 : lesstrides438 ; column 3 : strides 239 439 if keyword_set(mcstride) AND n_elements(mcstride) EQ varcontient.ndims THEN $ 240 440 valinit[3,*]=mcstride ELSE valinit[3, *] = 1 241 ; test des valeurs initiales du tableau441 ; test of initial values of the array 242 442 valinit = fix(valinit) 243 valinit[3, *] = 1 > valinit[3, *] < tailledim[varcontient.dim] ; test desstrides244 valinit[0, *] = 0 > valinit[0, *] < tailledim[varcontient.dim] ; test desoffsets245 ; test descounts443 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 246 446 valinit[1, *] = 1 > valinit[1, *] < ((tailledim[varcontient.dim]/valinit[3, *])-valinit[0, *]) 247 valinit[2, *] = valinit[2, *] MOD (tailledim[varcontient.dim]/valinit[3, *]) ; test desshifts248 ; declaration du tableau447 valinit[2, *] = valinit[2, *] MOD (tailledim[varcontient.dim]/valinit[3, *]) ; test of shifts 448 ; declaration of the array 249 449 widbase1 = widget_table(widbase, row_labels = rowlab, value = valinit, /editable $ 250 450 , column_labels = ['Offset', 'Count', 'Shift', 'Stride'], uvalue = 1) … … 253 453 rien = widget_label(widbase, value = 'du tableau ou des textes soient bien prises en compte', /align_center) 254 454 ;------------------------------------------------------------ 255 ; widbase2 choi x des attributs256 ;------------------------------------------------------------ 257 rien = widget_label(widbase, value = ' ') ; on saute une ligne455 ; widbase2 choice of attributes 456 ;------------------------------------------------------------ 457 rien = widget_label(widbase, value = ' ') ; We jump a line 258 458 widbase2 = widget_base(widbase, /column) 259 ; pour chaque attribut, on cree un widget (widbase21) qui contient en ligne un260 ; bouton oui/non (widbase211), et deux wigdet text (widbase212,261 ; widbase213)comportant le nom et la valeur de l''attribut.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. 262 462 widbase21 = lonarr(varcontient.natts) 263 463 widbase211 = lonarr(varcontient.natts) 264 464 widbase2111 = lonarr(varcontient.natts) 265 ; vecteur qui serviera a savoir quels boutons oui/non sont 266 ; selectiones. cf. wid_var_event 465 ; Vector which will serve to know which yes/no are selected. see. wid_var_event 267 466 selectatt = lonarr(varcontient.natts) 268 467 selectatt[*] = 0 269 468 widbase212 = lonarr(varcontient.natts) 270 469 widbase213 = lonarr(varcontient.natts) 271 for attid = 0, varcontient.natts-1 do BEGIN ; boucle sur le nombre d''attributs470 for attid = 0, varcontient.natts-1 do BEGIN ;Lop on the number of attribute. 272 471 widbase21[attid] = widget_base(widbase2, /row) 273 472 name=ncdf_attname(cdfid,varid,attid) … … 279 478 endfor 280 479 ;------------------------------------------------------------ 281 ; widbase3 b outons du bas480 ; widbase3 buttons of the bottom. 282 481 ;------------------------------------------------------------ 283 482 widbase3 = widget_base(widbase, /row,/align_center) … … 286 485 widbase33=widget_button(widbase3,value='DONE', uvalue=33) 287 486 ;------------------------------------------------------------ 288 ;execution de la fentre de base et des sous-fenetres487 ;execution of the base window and of sub-window. 289 488 ;------------------------------------------------------------ 290 489 widget_control,widbase,/realize … … 295 494 ;------------------------------------------------------------ 296 495 496 ;------------------------------------------------------------ 497 ;------------------------------------------------------------ 498 ;------------------------------------------------------------ 499 ;+ 500 ; @file_comments 501 ; Procedure called by xmanager when we press a button of the first widget 502 ; created by par xncdf_lec 503 ; 504 ; @param EVENT 505 ; A structure caracterising the event type which arrive at the widget number 1. 506 ; 507 ; @uses 508 ; resultat, infovariable, motcle 509 ; 510 ; @version 511 ; $Id$ 512 ;- 513 ;------------------------------------------------------------ 514 ;------------------------------------------------------------ 515 ;------------------------------------------------------------ 297 516 PRO xncdf_lec_event, event 298 ;------------------------------------------------------------299 ;------------------------------------------------------------300 ;------------------------------------------------------------301 ; NAME:xncdf_lec_event302 ;303 ; PURPOSE: procedure appele par xmanager qd on appuie sur un bouton du304 ; 1ere widget cree par xncdf_lec305 ;306 ; INPUTS: event, une structure caracterisant le type d''evenement qui307 ; arrive au widget numero1308 ;309 ; COMMON BLOCKS:resultat, infovariable, motcle310 ;311 ;------------------------------------------------------------312 ;------------------------------------------------------------313 ;------------------------------------------------------------314 517 ; 315 518 compile_opt idl2, strictarrsubs … … 318 521 COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient 319 522 COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar 320 ; quel est le type d''evenement?523 ; What is the type of event? 321 524 widget_control, event.id, get_uvalue=uval 322 ; case sur le type d''evenement525 ; case on the type of event. 323 526 case uval of 324 1:BEGIN ; on veut lire un autre fichier325 widget_control, event.id, get_value = nom ; on recupere le nom326 widget_control, event.top, /destroy ; on ferme le widget327 ncdf_close,cdfid ; on ferme le mauvais fichier qui a ete ouvert328 ; on reapellexncdf_lec527 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 329 532 res = xncdf_lec(nom[0], ATT = mcatt, COUNT = mccount, OFFSET = mcoffset, IODIR = mciodir $ 330 533 , SHIFT = mcshift, STRIDE = mcstride, VAR = mcvar) 331 534 return 332 535 END 333 2:BEGIN ; une variable est selectionee334 varid = event.index ; on recupere son numero ds le fichierNetcdf536 2:BEGIN ; A variable is selected. 537 varid = event.index ; We recuperat its number in the file Netcdf 335 538 varcontient = ncdf_varinq(cdfid,varid) 336 wid_var, event.top ; on appelle le programme qui lance le 2eme widget. cf. + haut539 wid_var, event.top ; We call the program which launch the second widget. See sooner. 337 540 END 338 3:BEGIN ; b outon done339 widget_control, event.top, /destroy ; on tue le widget340 ncdf_close,cdfid ; on ferme le fichier541 3:BEGIN ; button done 542 widget_control, event.top, /destroy ; We delete the widget 543 ncdf_close,cdfid ; We shut the file. 341 544 END 342 545 ELSE: … … 344 547 return 345 548 end 346 ;------------------------------------------------------------347 ;------------------------------------------------------------348 ;------------------------------------------------------------349 ;+350 ; NAME: xncdf_lec351 ;352 ; PURPOSE: lecture d''un fichier Net Cdf avec des widgets !353 ;354 ; CATEGORY: lecture de fichiers avec widgets355 ;356 ; CALLING SEQUENCE: res=xncdf_lec([nom_fichier])357 ;358 ; INPUTS:359 ; OPTIONNEL, nom_fichier: c''est un string qui donne le nom du360 ; fichier a ouvrir.Si nomfichier ne contient pas le caractere361 ; separateur de repertoirte ('/' sous unix par ex), Le fichier362 ; sera cherche ds le repertoire courant363 ;364 ; KEYWORD PARAMETERS:365 ;366 ; IODIR: string contenant le repertoire ou aller chercher le367 ; fichier a lire. Si nomfichier ne contient pas le caractere368 ; separateur de repertoirte ('/' sous unix par ex), Le fichier369 ; cherche s''appelera iodir+nom_fichier.370 ;371 ; COUNT: An optional vector containing the counts to be used in372 ; reading Value. COUNT is a 1-based vector with an element for373 ; each dimension of the data to be written.The default matches374 ; the size of the variable so that all data is written out.375 ;376 ; GROUP: The widget ID of the widget that calls XNCDF_LEC. When377 ; this ID is specified, a death of the caller results in a death378 ; of XNCDF_LEC.379 ;380 ; OFFSET: An optional vector containing the starting position381 ; for the read. The default start position is [0, 0, ...].382 ;383 ; SHIFT: un vecteur d''entiers, specifiant pour chaque dimension384 ; de combien il faut la shifter. Par defaut c''est385 ; [0,0,...]. cf. la fonction shift pour +386 ; d''explications. ATTENTION, le shift est effectue sur le387 ; tableau de taille maximum avant la reduction eventuelle388 ; determinee par OFFSET et COUNT. Par contre il est effectue389 ; apres l''extraction eventuelle cree par le STRIDE.390 ;391 ; STRIDE: An optional vector containing the strides, or sampling392 ; intervals, between accessed values of the netCDF variable. The393 ; default stride vector is that for a contiguous read, [1, 1,394 ; ...].395 ;396 ; OUTPUTS: 2 cas possibles:397 ; 1) aucun attributs n''a ete selectionne. Dans ce cas res est398 ; le tableau que l''on voulait lire.399 ; 2) Des attributs ont ete selectionnes. Dans ce cas res est une400 ; structre dont le premier element portant le nom de la variable401 ; est le tableau de valeurs et les autre auguments sont les402 ; arguments selectiones403 ;404 ; COMMON BLOCKS: wididbase, infovariable, resultat, motcle405 ;406 ; SIDE EFFECTS:407 ;408 ; RESTRICTIONS:409 ;410 ; EXAMPLE: help, xncdf_lec()411 ;412 ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)413 ; 24/8/1999414 ;-415 ;------------------------------------------------------------416 ;------------------------------------------------------------417 ;------------------------------------------------------------418 FUNCTION xncdf_lec, nom, ATT = att, COUNT = count, GROUP = group, OFFSET = offset, IODIR = iodir, SHIFT = shift, STRIDE = stride, VAR = var419 ;420 compile_opt idl2, strictarrsubs421 ;422 COMMON wididbase, base423 COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient424 COMMON resultat, res425 COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar426 ;------------------------------------------------------------427 ; bidouille pour utiliser les mots cles (on passe par des variables428 ; declarees ds un common)429 ;------------------------------------------------------------430 res = -1431 if keyword_set(att) then mcatt = att ELSE mcatt = 0432 if keyword_set(count) then mccount =count ELSE mccount = 0433 if keyword_set(offset) then mcoffset = offset ELSE mcoffset = 0434 if keyword_set(shift) then mcshift = shift ELSE mcshift = 0435 if keyword_set(stride) then mcstride = stride ELSE mcstride = 0436 if keyword_set(var) then mcvar = var ELSE mcvar = 0437 ;------------------------------------------------------------438 ; choix du nom du fichier439 ;------------------------------------------------------------440 ; Quel type de machine est utiliee441 thisOS = strupcase(strmid(!version.os_family, 0, 3))442 CASE thisOS of443 'MAC':sep = ':'444 'WIN':sep = '\'445 ELSE: sep = '/'446 ENDCASE447 ; si iodir n''est pas definit on l''initialise au repertoire courant448 if NOT keyword_set(iodir) then cd, current = iodir449 mciodir = iodir450 ; on complete iodir d''un caractere separateur de repertoire si besoin451 ; est.452 IF rstrpos(iodir, sep) NE strlen(iodir)-1 THEN iodir = iodir+sep453 if n_elements(nom) EQ 0 then BEGIN ; si nom n''est pas definit454 ; on en trouve un grace au programme dialog_pickfile455 nom = dialog_pickfile(filter = iodir+'*.nc')456 if nom[0] EQ '' then return, -1 ; si on a rien trouve on sort457 ;on complete nom par iodir si nom ne contient pas de caractere458 ;separateur derepertoire459 ENDIF ELSE if strpos(nom, sep) EQ -1 then nom = iodir+nom460 test = findfile(nom) ; le nom cherche correspond bien a un fichier?461 while test[0] EQ '' OR n_elements(test) GT 1 do BEGIN ; on en cherche un tant qu''il ne correspond a rien!462 test = test[0]463 nom = dialog_pickfile(filter = iodir+'*.nc')464 if nom EQ '' then return, -1465 test = findfile(nom)466 endwhile467 ;------------------------------------------------------------468 ; ouverture du fichier nom469 ;------------------------------------------------------------470 cdfid=ncdf_open(nom)471 contient=ncdf_inquire(cdfid)472 ;------------------------------------------------------------473 ; que contient le fichier??474 ;------------------------------------------------------------475 ; ouverture de la fenetre de base sous forme de colonnes476 if n_elements(group) EQ 0 then base = widget_base(/column, title='Fichier: '+nom, /align_left) $477 ELSE base = widget_base(/column, title='Fichier: '+nom, /align_left, GROUP_LEADER = group)478 ; ouverture de sous-fenetres de base ;479 ;------------------------------------------------------------480 ; base 1 titre portant le nom du fichier481 ;------------------------------------------------------------482 base1 = widget_base(base, /column, /align_center)483 rien = widget_label(base1, value = 'Net Cdf filename', /align_center) ; blabla484 rien = widget_text(base1, value = nom, /align_center, uvalue=1, /editable) ;nom du fichier que l''on peut changer485 rien = widget_label(base1, value = ' ') ; on saute une ligne486 ;------------------------------------------------------------487 ; base 2 informations generales sur le fichier488 ;------------------------------------------------------------489 base2 = widget_base(base, /column)490 ;------------------------------------------------------------491 ; informations sur les attributs globaux492 ;------------------------------------------------------------493 if contient.ngatts NE -1 then begin494 rien = widget_label(base2, value = 'Nombre de attributs globaux: '+ strtrim(contient.ngatts,1), /align_left)495 for attiq=0,contient.ngatts-1 do BEGIN ; bouble sur le nombre d'attributs globaux496 name=ncdf_attname(cdfid,attiq,/global) ;nom de l''atribut497 ncdf_attget,cdfid,name,value,/global ;valeur de l''atribut498 rien = widget_text(base2, value = name+': '+strtrim(string(value),1), xsize = 60, /scroll, /wrap, /align_right)499 endfor500 rien = widget_label(base2, value = ' ')501 endif502 ;------------------------------------------------------------503 ; informations sur les dimensions504 ;------------------------------------------------------------505 rien = widget_label(base2, value = 'Nombre de dimensions: '+strtrim(contient.ndims,1), /align_left)506 if contient.recdim NE -1 then begin ; bouble sur le nombre de dimensions507 ncdf_diminq,cdfid,contient.recdim,name,value ; nom et valeur de la dimension508 rien = widget_label(base2, value = 'nom de la dimension infinie: '+name, /align_left)509 endif510 ;511 nomdim =strarr(contient.ndims) ; vecteur contenant le nom des dimensions512 tailledim=lonarr(contient.ndims) ; vecteur contenant la valeur des dimensions513 for dimiq=0,contient.ndims-1 do begin ; bouble sur le nombre de dimensions514 ncdf_diminq,cdfid,dimiq,name,value ; nom et valeur de la dimension515 nomdim[dimiq]=name516 tailledim[dimiq]=value517 rien = widget_label(base2, value = name+' de taille: '+strtrim(value,1), /align_right)518 ENDFOR519 rien = widget_label(base2, value = ' ') ; on saute une ligne520 ;------------------------------------------------------------521 ; base 3 choix de la variable522 ;------------------------------------------------------------523 base3 = widget_base(base, /column)524 rien = widget_label(base3, value = 'Nombre de variables: '+strtrim(contient.nvars,1), /align_left)525 base31 = widget_base(base3, /row, /align_center)526 ;creation d'un vecteur listename contenant le nom de toutes les527 ;variables du fichier528 listename = strarr(contient.nvars)529 for varid=0,contient.nvars-1 do begin530 varcontient=ncdf_varinq(cdfid,varid) ; que contient la variable531 listename[varid] = varcontient.name532 endfor533 rien= widget_label(base31, value = 'variable')534 ; creation d''un bouton a menu deroulant535 base311=widget_droplist(base31,value=listename, uvalue=2)536 rien = widget_label(base3, value = '')537 ;------------------------------------------------------------538 ; base 4 bouton done539 ;------------------------------------------------------------540 base4 = widget_base(base, /row)541 base42=widget_button(base4,value='done', uvalue=3, /align_right)542 ;execution de la fentre de base et des sous-fenetres543 widget_control,base,/realize544 ;------------------------------------------------------------545 xmanager,'xncdf_lec',base546 ;------------------------------------------------------------547 ;------------------------------------------------------------548 ;------------------------------------------------------------549 return, res550 end
Note: See TracChangeset
for help on using the changeset viewer.