source: trunk/step1_diff.pro @ 48

Last change on this file since 48 was 48, checked in by pinsard, 10 years ago

fix thanks to coding rules

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