source: trunk/MESOSCALE/PLOT/SPEC/LES/getget2d.pro @ 205

Last change on this file since 205 was 85, checked in by aslmd, 14 years ago

LMD_MM_MARS et LMD_LES_MARS: ajout des routines IDL pour tracer les sorties --> voir mesoscale/PLOT

File size: 3.2 KB
Line 
1function getget2d, name, charvar, count=count, offset=offset, stride=stride, coordmean=coordmean, anomaly=anomaly
2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3; name: char
4; charvar: char
5; count: 4 elements array   ; The dimensions of the sub-image
6; offset: 4 elements array  ; A variable that contains the offset for the sub-image
7; stride: 4 elements array  ; Create a variable to be used as a value for the STRIDE keyword
8; coordmean: 1 to 4 elements array (dimension 1 is 1)
9; anomaly: a non-null element that would be filled with mean
10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
12
13nosave = 1  ;; comment to get an IDL data file
14notime = 1  ;; comment to get mention of time taken
15if (n_elements(notime) eq 0) then timetime = SYSTIME(1)
16
17;
18; MINIMAL ARGUMENTS
19;
20if (n_elements(name) eq 0) then stop
21if (n_elements(charvar) eq 0) then stop
22
23;
24; IDL DATA DIRECTORY
25;
26name_idl = charvar+name+'.idl'
27  if (n_elements(coordmean) ne 0) then begin
28    nc = n_elements(coordmean)
29    for i=0,nc-1 do begin
30     name_idl = string(coordmean(i),'(I0)')+name_idl   
31    endfor
32  endif
33name_idl = './idl_dat/'+name_idl
34
35;
36; TEST IF FILE EXISTS
37;
38openr,unit,name_idl,/get_lun,error=err
39
40;
41; IF IDL FILE EXISTS, THAT IS RATHER SIMPLE
42;
43IF (err EQ 0) THEN BEGIN
44
45   print, 'read from file'
46   free_lun,unit
47   restore, filename=name_idl
48
49;
50; IF IDL FILE DOES NOT EXIST, WELL, READ NETCDF
51;
52ENDIF ELSE BEGIN
53
54  ;
55  ; check save directory
56  ;
57  if (n_elements(nosave) eq 0) then SPAWN, 'mkdir -p idl_dat' 
58
59  ;
60  ; open file
61  ;
62  id=ncdf_open(name)
63
64  ;
65  ; get dimensions
66  ;
67  var = intarr(3)
68  NCDF_DIMINQ, id, NCDF_DIMID(id, 'west_east'    ), toto, titi & var(0) = titi
69  NCDF_DIMINQ, id, NCDF_DIMID(id, 'south_north'  ), toto, titi & var(1) = titi
70  NCDF_DIMINQ, id, NCDF_DIMID(id, 'Time'         ), toto, titi & var(2) = titi
71  ;print, var
72
73  ;
74  ; define default data windows
75  ;
76  if (n_elements(offset) le 3) then offset=[0,0,0]
77  if (n_elements(stride) le 3) then stride=[1,1,1]
78  if (n_elements(count) le 3) then count=intarr(3)
79  w = where(count eq 0) & if (w(0) ne -1) then count[w] = var[w] / stride[w]
80
81  ;
82  ; read variable
83  ;
84  varid=ncdf_varid(id,charvar) ;& print, 'get '+charvar
85  if (n_elements(notime) eq 0) then timetime = SYSTIME(1) ;& help, /memory
86  ncdf_varget, id, varid, invar, count=count, offset=offset, stride=stride & if (n_elements(notime) eq 0) then print, SYSTIME(1) - timetime, ' s' ;& help, /memory
87  ncdf_close, id
88
89  ;
90  ; OPTIONAL: ANOMALY (value is returned in the keyword)
91  ;
92  if (n_elements(anomaly) ne 0) then begin
93    anomaly=TOTAL(TOTAL(invar,1),1)/float(var[0])/float(var[1])
94    for i=0,var[0]-1 do for j=0,var[1]-1 do invar(i,j,*) = TEMPORARY(invar(i,j,*)) - anomaly  ; coute cher
95  endif
96
97  ;
98  ; OPTIONAL: MEAN
99  ;
100  if (n_elements(coordmean) ne 0) then begin
101  for i=0,nc-1 do begin
102   print, 'mean over dimension '+string(coordmean(i),'(I0)')+' - '+string(var(coordmean(i)),'(I0)')+' elements'
103   invar=total(TEMPORARY(invar),coordmean(i))/var(coordmean(i))
104  endfor
105  endif
106
107  ;
108  ; SAVE
109  ;
110  if (n_elements(nosave) eq 0) then save, invar, filename=name_idl
111
112ENDELSE
113
114if (n_elements(notime) eq 0) then print, SYSTIME(1) - timetime, ' s'
115
116;
117; RETURN FIELD
118;
119return, invar
120
121end
Note: See TracBrowser for help on using the repository browser.