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