source: trunk/step1_diff.pro @ 16

Last change on this file since 16 was 16, checked in by pinsard, 17 years ago

minor syntax correction

  • Property svn:keyword set to Id
File size: 6.1 KB
Line 
1;+
2; @file_comments
3; compute delta between cond_sed*.pro Netcdf files with same dimension
4;
5; @param file1 {in}{required} {type=string}
6; name of the first file to be read
7;
8; @param file2 {in}{required} {type=string}
9; name of the second file to be read
10;
11; @param file3 {in}{required} {type=string}
12; file where differences between variables are written
13;
14; @examples
15; test (for header and delta)
16; to compute difference between cond_sed in cond_sed_ORCA2.nc and
17; itself and write it in ginette.nc :
18; rhodes\@reee522$ cd /home/rech/eee/reee522/incas/geomag/geomag_ws
19; rhodes\@reee522$ idl
20; IDL> step1_diff, 'cond_sed_ORCA2.nc', 'cond_sed_ORCA2.nc', 'ginette.nc'
21; values of delta must be 0 everywhere
22; rhodes\@reee522$ rm ginette.nc
23; idem with BR file
24; IDL> step1_diff, 'Br_ORCA2.nc', 'Br_ORCA2.nc', 'ginette.nc'
25;
26; real life
27; to compute difference between cond_sed in cond_sed_ORCA2.nc and
28; /home/rech/eee/reee522/geomag_d/cond_sed_ORCA2.nc and write it in
29; cond_sed_ORCA2_diff.nc :
30; rhodes\@reee522$ cd /home/rech/eee/reee522/incas/geomag/geomag_ws
31; rhodes\@reee522$ idl
32; IDL> step1_diff, 'cond_sed_ORCA2.nc', $
33;      '/home/rech/eee/reee522/geomag_d/cond_sed_ORCA2.nc', $
34;      'cond_sed_ORCA2_diff.nc'
35; IDL> step1_diff, 'Br_ORCA2.nc', $
36;      '/home/rech/eee/reee522/geomag_d/Br_ORCA2.nc', $
37;      'Br_ORCA2_diff.nc'
38;
39; to see the difference, for example
40; IDL> xxx,'cond_sed_ORCA2_diff.nc'
41; IDL> xxx,'Br_ORCA2_diff.nc'
42; select xy on plt wigdet
43;
44; @history
45; reee522 2006-12-18T10:38:49Z rhodes (IRIX64)
46; thanks to example in SAXO
47; SRC/ReadWrite/idl-NetCDF/ncdf_quickread/README_ncdf_quickread.txt
48;
49; @todo
50; check difference between headers
51;
52; @version
53; $Id$
54;
55PRO step1_diff, file1,file2,file3
56;
57ncverbose=1
58;
59; check if file1 exists
60fullfile1 = isafile(file1, NEW=0,/MUST_EXIST)
61IF fullfile1[0] EQ '' THEN BEGIN
62   msg = 'eee : the file ' + fullfile1 + ' was not found.'
63   PRINT, msg
64   RETURN
65ENDIF
66;
67; protection
68IF (FILE_TEST(fullfile1[0], /READ) EQ 0) THEN BEGIN
69   msg = 'eee : the file ' + fullfile1[0] + ' is not readable.'
70   PRINT, msg
71   RETURN
72ENDIF
73;
74; check if file2 exists
75fullfile2 = isafile(file2, NEW=0,/MUST_EXIST)
76IF fullfile2[0] EQ '' THEN BEGIN
77   msg = 'eee : the file ' + fullfile2 + ' was not found.'
78   PRINT, msg
79   RETURN
80ENDIF
81;
82; protection
83IF (FILE_TEST(fullfile2[0], /READ) EQ 0) THEN BEGIN
84   msg = 'eee : the file ' + fullfile2[0] + ' is not readable.'
85   PRINT, msg
86   RETURN
87ENDIF
88;
89; read the first file
90ncdf_read,  fullfile1[0], file1info, file1dinfo, file1vinfo, $
91            file1gatts, file1vatts, file1data
92;
93; read the second file
94ncdf_read,  fullfile2[0], file2info, file2dinfo, file2vinfo, $
95            file2gatts, file2vatts, file2data
96;
97; compute delta
98delta = *file1data[3] - *file2data[3]
99minarr = min(delta, max = maxarr)
100;
101; check for number of non zero in delta
102checknonzero=where(delta NE 0.,count)
103IF count EQ 0 THEN BEGIN
104   msg = ' iii : delta is zero everywhere'
105   PRINT, msg
106ENDIF ELSE BEGIN
107   msg = ' iii : delta is not zero ' + STRING(count)  + ' times'
108   PRINT, msg
109ENDELSE
110;
111;
112; write output
113; in order to avoid unexpected overwritten
114IF (FILE_TEST(file3) EQ 1) THEN BEGIN
115   msg = 'eee : the file ' + file3  + ' already exists.'
116   PRINT, msg
117   RETURN
118ENDIF
119;
120;
121;---------------------------
122; Creation of the NetCdf output file
123;---------------------------
124;
125  netcdf_id = NCDF_CREATE(file3, /clobber)
126  NCDF_CONTROL, netcdf_id, /NOFILL
127;
128; dimension
129  dimidx = NCDF_DIMDEF(netcdf_id, file1dinfo[0].name ,  file1dinfo[0].size)
130  dimidy = NCDF_DIMDEF(netcdf_id, file1dinfo[1].name ,  file1dinfo[1].size)
131  dimidt = NCDF_DIMDEF(netcdf_id, file1dinfo[2].name, /UNLIMITED)
132;
133; global attributes
134  NCDF_ATTPUT, netcdf_id, 'Conventions', 'GDT 1.2', /GLOBAL ; ++ conformite
135  NCDF_ATTPUT, netcdf_id, 'file_name'  , file3, /GLOBAL
136  NCDF_ATTPUT, netcdf_id, 'Title'      , $
137               'delta between '+ file1 + ' and ' + file2, /GLOBAL
138;
139; declaration of variables
140; 4 common variables for the two files to produce
141  varid = lonarr(4)
142;
143  varid[0] = NCDF_VARDEF(netcdf_id, file1vinfo[0].name  , [dimidx, dimidy], /FLOAT)
144  NCDF_ATTPUT, netcdf_id, varid[0], $
145               (*file1vatts[0])[0].name , $
146               STRING(*(*file1vatts[0])[0].values)
147  NCDF_ATTPUT, netcdf_id, varid[0], $
148               (*file1vatts[0])[1].name, $
149               *(*file1vatts[0])[1].values
150  NCDF_ATTPUT, netcdf_id, varid[0], $
151               (*file1vatts[0])[2].name, $
152               *(*file1vatts[0])[2].values
153  NCDF_ATTPUT, netcdf_id, varid[0], $
154               (*file1vatts[0])[3].name, $
155               STRING(*(*file1vatts[0])[3].values)
156;
157  varid[1] = NCDF_VARDEF(netcdf_id, file1vinfo[1].name  , [dimidx, dimidy], /FLOAT)
158  NCDF_ATTPUT, netcdf_id, varid[1], $
159               (*file1vatts[1])[0].name, $
160               STRING(*(*file1vatts[1])[0].values)
161  NCDF_ATTPUT, netcdf_id, varid[1], $
162               (*file1vatts[1])[1].name, $
163               *(*file1vatts[1])[1].values
164  NCDF_ATTPUT, netcdf_id, varid[1], $
165               (*file1vatts[1])[2].name, $
166               *(*file1vatts[1])[2].values
167  NCDF_ATTPUT, netcdf_id, varid[1], $
168               (*file1vatts[1])[3].name, $
169               STRING(*(*file1vatts[1])[3].values)
170;
171  varid[2] = NCDF_VARDEF(netcdf_id, file1vinfo[2].name, [dimidt], /FLOAT)
172;
173  varid[3] =  NCDF_VARDEF(netcdf_id, 'delta', [dimidx, dimidy, dimidt], /FLOAT)
174  NCDF_ATTPUT, netcdf_id, varid[3], 'long_name', 'delta'
175  NCDF_ATTPUT, netcdf_id, varid[3], $
176               (*file1vatts[3])[0].name, $
177               STRING(*(*file1vatts[3])[0].values)
178;
179  NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', minarr ,/FLOAT
180  NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', maxarr ,/FLOAT
181;
182;---------------------------
183; end of header definition, writing of the NetCdf files
184;---------------------------
185;
186  NCDF_CONTROL, netcdf_id, /ENDEF
187;
188  NCDF_VARPUT, netcdf_id, file1vinfo[0].name, (*file1data[0])
189  NCDF_VARPUT, netcdf_id, file1vinfo[1].name, (*file1data[1])
190  NCDF_VARPUT, netcdf_id, file1vinfo[2].name, (*file1data[2])
191;
192; write the data
193  NCDF_VARPUT, netcdf_id, 'delta', delta
194;
195;---------------------------
196; close the netcdf files
197  NCDF_CLOSE, netcdf_id
198;
199  msg = 'iii : ' + file3 + ' created'
200  PRINT, msg
201;
202END
Note: See TracBrowser for help on using the repository browser.