source: trunk/step1_diff.pro @ 17

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

remove xxx_oneplot.pro and for_createpro.pro which are not supposed to be here : They interfere with xxx temporary files in myuniquetmpdir

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