1 | ;+ |
---|
2 | ; |
---|
3 | ; compute point-wise correlation of two 3D (x,y,t) fields |
---|
4 | ; |
---|
5 | ; @param FILE_NAME {in}{required}{type=string} |
---|
6 | ; |
---|
7 | ; @param NCDF_DB {in}{required}{type=string} |
---|
8 | ; <location>:<path> or just <path> |
---|
9 | ; |
---|
10 | ; @keyword BOXZOOM |
---|
11 | ; |
---|
12 | ; @keyword TIME_1 |
---|
13 | ; |
---|
14 | ; @keyword TIME_2 |
---|
15 | ; |
---|
16 | ; @keyword ALL_DATA |
---|
17 | ; |
---|
18 | ; @returns |
---|
19 | ; structure |
---|
20 | ; -1 in case of error |
---|
21 | ; |
---|
22 | ; @uses |
---|
23 | ; <pro>common</pro> |
---|
24 | ; <propost_it>com_eg</propost_it> |
---|
25 | ; |
---|
26 | ; @history |
---|
27 | ; - fplod 20100119T094252Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
28 | ; |
---|
29 | ; * check parameters |
---|
30 | ; |
---|
31 | ; - fplod 20091208T102329Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
32 | ; |
---|
33 | ; * syntax of array |
---|
34 | ; |
---|
35 | ; @version |
---|
36 | ; $Id$ |
---|
37 | ; |
---|
38 | ;- |
---|
39 | FUNCTION make_correlation, file_name, ncdf_db $ |
---|
40 | , BOXZOOM=boxzoom $ |
---|
41 | , TIME_1=time_1 $ |
---|
42 | , TIME_2=time_2 $ |
---|
43 | , ALL_DATA=all_data |
---|
44 | ; |
---|
45 | compile_opt idl2, strictarrsubs |
---|
46 | ; |
---|
47 | @common |
---|
48 | @com_eg |
---|
49 | |
---|
50 | IF debug_w THEN BEGIN |
---|
51 | info = report('enter ...') |
---|
52 | ENDIF |
---|
53 | |
---|
54 | usage='result=make_correlation(file_name, ncdf_db ' $ |
---|
55 | + ', BOXZOOM=boxzoom ' $ |
---|
56 | + ', TIME_1=time_1 ' $ |
---|
57 | + ', TIME_2=time_2 ' $ |
---|
58 | + ', ALL_DATA=all_data)' |
---|
59 | |
---|
60 | nparam = N_PARAMS() |
---|
61 | IF (nparam LT 2) THEN BEGIN |
---|
62 | ras = report(['Incorrect number of arguments.' $ |
---|
63 | + '!C' $ |
---|
64 | + 'Usage : ' + usage]) |
---|
65 | return, -1 |
---|
66 | ENDIF |
---|
67 | |
---|
68 | arg_type = size(file_name,/type) |
---|
69 | IF (arg_type NE 7) THEN BEGIN |
---|
70 | ras = report(['Incorrect arg type file_name' $ |
---|
71 | + '!C' $ |
---|
72 | + 'Usage : ' + usage]) |
---|
73 | return, -1 |
---|
74 | ENDIF |
---|
75 | |
---|
76 | arg_type = size(ncdf_db,/type) |
---|
77 | IF (arg_type NE 7) THEN BEGIN |
---|
78 | ras = report(['Incorrect arg type ncdf_db' $ |
---|
79 | + '!C' $ |
---|
80 | + 'Usage : ' + usage]) |
---|
81 | return, -1 |
---|
82 | ENDIF |
---|
83 | |
---|
84 | ; |
---|
85 | var_name1 = (strsplit(macro_base_fld, ',', ESCAPE = ' ', /EXTRACT))[0] |
---|
86 | var_name2 = (strsplit(macro_base_fld, ',', ESCAPE = ' ', /EXTRACT))[1] |
---|
87 | |
---|
88 | ; Build file_name2 if different |
---|
89 | |
---|
90 | IF strpos (cmd1_back.grid, '#') NE -1 THEN BEGIN |
---|
91 | varpos = strpos(file_name, var_name1) |
---|
92 | file_name2= strmid(file_name, 0, varpos)+var_name2+'.nc' |
---|
93 | IF debug_w THEN print, ' file_name2 = ', file_name2 |
---|
94 | ENDIF ELSE file_name2 = file_name |
---|
95 | |
---|
96 | ; Read the variables in the correspondent netcdf file |
---|
97 | var1 = nc_read(file_name, var_name1, ncdf_db, BOXZOOM = boxzoom, TIME_1 = time_1, TIME_2 = time_2) |
---|
98 | var2 = nc_read(file_name2, var_name2, ncdf_db, BOXZOOM = boxzoom, TIME_1 = time_1, TIME_2 = time_2) |
---|
99 | |
---|
100 | varname = var1.name+'/'+var2.name+' corr.' |
---|
101 | varunit = '[-1/1]' |
---|
102 | |
---|
103 | nxa = (size(var1.data))[1] |
---|
104 | nya = (size(var1.data))[2] |
---|
105 | |
---|
106 | pt_correl = fltarr(nxa, nya) |
---|
107 | pt_correl[*, *] = 0 |
---|
108 | |
---|
109 | |
---|
110 | ; Sampling of data and computation of new numbers of values |
---|
111 | |
---|
112 | @mth_decode |
---|
113 | |
---|
114 | FOR imth = 0, nmth-1 DO BEGIN |
---|
115 | |
---|
116 | IF debug_w THEN print, ' month idx/value: ', imth, strd[imth] |
---|
117 | |
---|
118 | data1 = (var1.data)[*, *, reform(idxm[imth,*], njpt)] |
---|
119 | data2 = (var2.data)[*, *, reform(idxm[imth,*], njpt)] |
---|
120 | nval = njpt |
---|
121 | |
---|
122 | ; Compute correlation |
---|
123 | |
---|
124 | pt_correl = pt_correl + c_timecorrelate(data1, data2) |
---|
125 | |
---|
126 | ENDFOR |
---|
127 | |
---|
128 | idm = where(var1.data[*, *, 0] GE valmask/10.) |
---|
129 | |
---|
130 | pt_correl = pt_correl/float(nmth) |
---|
131 | |
---|
132 | IF idm[0] NE -1 THEN pt_correl[idm] = valmask |
---|
133 | |
---|
134 | varname = varname+' '+ntxt |
---|
135 | |
---|
136 | ; Define the outputs of the function |
---|
137 | field = {name: varname, data: pt_correl, legend: '', units: '', origin: '', dim: 0, direc:'xy'} |
---|
138 | field.origin = var1.origin |
---|
139 | field.dim = var1.dim |
---|
140 | |
---|
141 | field.legend = ' '+ntxt+' ['+cmdm.date1+'-'+cmdm.spec+']' |
---|
142 | |
---|
143 | IF debug_w THEN BEGIN |
---|
144 | info = report('leaving...') |
---|
145 | ENDIF |
---|
146 | |
---|
147 | return, field |
---|
148 | |
---|
149 | END |
---|