Ignore:
Timestamp:
08/09/06 12:12:54 (18 years ago)
Author:
navarro
Message:

english and nicer header (3a)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/ToBeReviewed/LECTURE/read_ncdf.pro

    r142 r150  
    1 ;------------------------------------------------------------ 
    2 ;------------------------------------------------------------ 
    3 ;------------------------------------------------------------ 
    41;+ 
    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$  
    7090;- 
    71 ;------------------------------------------------------------ 
    72 ;------------------------------------------------------------ 
    73 ;------------------------------------------------------------ 
    74 FUNCTION read_ncdf, name, debut, fin, pour_etre_compatible, BOXZOOM = boxzoom, FILENAME = filename $ 
     91;--------------------------------------------------------- 
     92;--------------------------------------------------------- 
     93;--------------------------------------------------------- 
     94 
     95FUNCTION read_ncdf, name, beginning, ending, compatibility, BOXZOOM = boxzoom, FILENAME = filename $ 
    7596                    , PARENTIN = parentin, TIMESTEP = timestep, TIMEVAR = timevar $ 
    7697                    , TOUT = tout, NOSTRUCT = nostruct, CONT_NOFILL = CONT_NOFILL, INIT = init $ 
     
    98119  filename = isafile(filename = filename, IODIRECTORY = iodir, _EXTRA = ex) 
    99120;------------------------------------------------------------ 
    100 ; ouverture du fichier nom 
     121; Opening of the name file 
    101122;------------------------------------------------------------ 
    102123  if size(filename, /type) NE 7 then $ 
     
    118139  if keyword_set(init) THEN initncdf, filename, _extra = ex 
    119140;------------------------------------------------------------ 
    120 ; check the time axis and the debut and fin dates 
    121 ;------------------------------------------------------------ 
    122   if n_elements(debut) EQ 0 then begin 
    123     debut = 0 
     141; check the time axis and the debut and ending dates 
     142;------------------------------------------------------------ 
     143  if n_elements(beginning) EQ 0 then begin 
     144    beginning = 0 
    124145    timestep = 1 
    125146  endif 
    126147  if keyword_set(timestep) then begin 
    127     firsttps = debut[0] 
    128     if n_elements(fin) NE 0 then lasttps = fin[0] ELSE lasttps = firsttps 
     148    firsttps = beginning[0] 
     149    if n_elements(ending) NE 0 then lasttps = ending[0] ELSE lasttps = firsttps 
    129150    jpt = lasttps-firsttps+1 
    130151    time = julday(1, 1, 1) + lindgen(jpt) 
     
    136157      currentfile = (where(filelist EQ filename))[0] 
    137158      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 = date1 
     159      date1 = date2jul(beginning[0]) 
     160      if n_elements(ending) NE 0 then date2 = date2jul(ending[0]) ELSE date2 = date1 
    140161      firsttps = where(time EQ date1) & firsttps = firsttps[0] 
    141162      lasttps = where(time EQ date2) & lasttps = lasttps[0] 
     
    159180; we find the FIRST time axis       
    160181        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. 
    164184          timeid = timeid+1 
    165185        endrep until (n_elements(timecontient.dim) EQ 1 $ 
     
    188208; 
    189209; now we try to find the attribut called calendar... 
    190 ; the the attribute "calendar" exists? 
     210; the attribute "calendar" exists? 
    191211; If no, we suppose that the calendar is gregorian calendar 
    192212; 
     
    248268        end 
    249269      ENDCASE 
    250       date1 = date2jul(debut[0]) 
    251       if n_elements(fin) NE 0 then date2 = date2jul(fin[0]) ELSE date2 = date1 
     270      date1 = date2jul(beginning[0]) 
     271      if n_elements(ending) NE 0 then date2 = date2jul(ending[0]) ELSE date2 = date1 
    252272      time = double(time) 
    253273      firsttps = where(time GE date1) & firsttps = firsttps[0] 
     
    271291  ENDELSE 
    272292;------------------------------------------------------------ 
    273 ; nom de la grille a laquelle se rapporte le champ 
     293; Name of the grid on which the field refer to. 
    274294;------------------------------------------------------------ 
    275295  IF keyword_set(grid) THEN vargrid = strupcase(grid) ELSE BEGIN 
     
    294314 
    295315;--------------------------------------------------------------- 
    296 ; redefinition du domaine  
     316; redefinition of the  domain 
    297317;--------------------------------------------------------------- 
    298318  if keyword_set(tout) then begin 
     
    331351    ENDIF 
    332352    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! 
    334354  ENDELSE 
    335355;--------------------------------------------------------------------- 
    336 ; on initialise les ixmindta, iymindta au besoin 
     356; We initializate ixmindta, iymindta if needed 
    337357;--------------------------------------------------------------------- 
    338358  if n_elements(jpidta) EQ 0 THEN jpidta = jpiglo 
     
    352372  IF izmaxdta EQ -1 then izmaxdta = jpkdta-1 
    353373;---------------------------------------------------------------- 
    354 ; on va lire le fichier 
     374; We will read the file 
    355375;--------------------------------------------------------------- 
    356376  if n_elements(key_stride) LE 2 then key_stride = [1, 1, 1] 
     
    401421    AND (strupcase(vargrid) EQ 'U' OR strupcase(vargrid) EQ 'F') THEN key_shift =  key_shift+1 
    402422;--------------------------------------------------------------------- 
    403 ; on definit les variables globales rattachees a la variable 
     423; We define global variable joined with the variable. 
    404424;--------------------------------------------------------------------- 
    405425; varname 
     
    434454  ENDELSE 
    435455; vardate 
    436 ; on construit une belle date lisible en fonction du langage specifie !!! 
    437   year = long(debut[0])/10000 
    438   month = (long(debut[0])/100) MOD 100 
    439   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) 
    440460  vardate = string(format = '(C(CMoA))', 31*(month-1))+' '+strtrim(day, 1)+', '+strtrim(year, 1) 
    441461  varexp = file_basename(filename) 
     
    446466  if keyword_set(key_zreverse) AND (size(res))[0] EQ 4 THEN res = reverse(temporary(res), 3) 
    447467 
    448 ; on applique la valeur valmask sur les points terre 
     468; We apply the value valmask on land points. 
    449469  if NOT keyword_set(cont_nofill) then begin 
    450470    valmask = 1e20 
     
    482502;    ENDIF ELSE missing = -1 
    483503  ENDIF ELSE missing = -1 
    484 ; on applique les add_offset, scale_factor et missing_value 
     504; we apply add_offset, scale_factor and missing_value  
    485505  if scale_factor NE 1 then res = temporary(res)*scale_factor 
    486506  if add_offset NE 0 then res = temporary(res)+add_offset 
Note: See TracChangeset for help on using the changeset viewer.