source: trunk/step1_diff.pro @ 42

Last change on this file since 42 was 41, checked in by pinsard, 15 years ago

small headers improvements

  • 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;
117; write output
118; in order to avoid unexpected overwritten
119IF (FILE_TEST(file3) EQ 1) THEN BEGIN
120   msg = 'eee : the file ' + file3  + ' already exists.'
121   ras = report(msg)
122   RETURN
123ENDIF
124;
125;
126;---------------------------
127; Creation of the NetCdf output file
128;---------------------------
129;
130  netcdf_id = NCDF_CREATE(file3, /clobber)
131  NCDF_CONTROL, netcdf_id, /NOFILL
132;
133; dimension
134  dimidx = NCDF_DIMDEF(netcdf_id, file1dinfo[0].name ,  file1dinfo[0].size)
135  dimidy = NCDF_DIMDEF(netcdf_id, file1dinfo[1].name ,  file1dinfo[1].size)
136  dimidt = NCDF_DIMDEF(netcdf_id, file1dinfo[2].name, /UNLIMITED)
137;
138; global attributes
139  NCDF_ATTPUT, netcdf_id, 'Conventions', 'GDT 1.2', /GLOBAL ; ++ conformite
140  NCDF_ATTPUT, netcdf_id, 'file_name'  , file3, /GLOBAL
141  NCDF_ATTPUT, netcdf_id, 'Title'      , $
142               'delta between '+ file1 + ' and ' + file2, /GLOBAL
143;
144; declaration of variables
145; 4 common variables for the two files to produce
146  varid = lonarr(4)
147;
148  varid[0] = NCDF_VARDEF(netcdf_id, file1vinfo[0].name  , [dimidx, dimidy], /FLOAT)
149  NCDF_ATTPUT, netcdf_id, varid[0], $
150               (*file1vatts[0])[0].name , $
151               STRING(*(*file1vatts[0])[0].values)
152  NCDF_ATTPUT, netcdf_id, varid[0], $
153               (*file1vatts[0])[1].name, $
154               *(*file1vatts[0])[1].values
155  NCDF_ATTPUT, netcdf_id, varid[0], $
156               (*file1vatts[0])[2].name, $
157               *(*file1vatts[0])[2].values
158  NCDF_ATTPUT, netcdf_id, varid[0], $
159               (*file1vatts[0])[3].name, $
160               STRING(*(*file1vatts[0])[3].values)
161;
162  varid[1] = NCDF_VARDEF(netcdf_id, file1vinfo[1].name  , [dimidx, dimidy], /FLOAT)
163  NCDF_ATTPUT, netcdf_id, varid[1], $
164               (*file1vatts[1])[0].name, $
165               STRING(*(*file1vatts[1])[0].values)
166  NCDF_ATTPUT, netcdf_id, varid[1], $
167               (*file1vatts[1])[1].name, $
168               *(*file1vatts[1])[1].values
169  NCDF_ATTPUT, netcdf_id, varid[1], $
170               (*file1vatts[1])[2].name, $
171               *(*file1vatts[1])[2].values
172  NCDF_ATTPUT, netcdf_id, varid[1], $
173               (*file1vatts[1])[3].name, $
174               STRING(*(*file1vatts[1])[3].values)
175;
176  varid[2] = NCDF_VARDEF(netcdf_id, file1vinfo[2].name, [dimidt], /FLOAT)
177;
178  varid[3] =  NCDF_VARDEF(netcdf_id, 'delta', [dimidx, dimidy, dimidt], /FLOAT)
179  NCDF_ATTPUT, netcdf_id, varid[3], 'long_name', 'delta'
180  NCDF_ATTPUT, netcdf_id, varid[3], $
181               (*file1vatts[3])[0].name, $
182               STRING(*(*file1vatts[3])[0].values)
183;
184  NCDF_ATTPUT, netcdf_id, varid[3], 'valid_min', minarr ,/FLOAT
185  NCDF_ATTPUT, netcdf_id, varid[3], 'valid_max', maxarr ,/FLOAT
186;
187;---------------------------
188; end of header definition, writing of the NetCdf files
189;---------------------------
190;
191  NCDF_CONTROL, netcdf_id, /ENDEF
192;
193  NCDF_VARPUT, netcdf_id, file1vinfo[0].name, (*file1data[0])
194  NCDF_VARPUT, netcdf_id, file1vinfo[1].name, (*file1data[1])
195  NCDF_VARPUT, netcdf_id, file1vinfo[2].name, (*file1data[2])
196;
197; write the data
198  NCDF_VARPUT, netcdf_id, 'delta', delta
199;
200;---------------------------
201; close the netcdf files
202  NCDF_CLOSE, netcdf_id
203;
204  msg = 'iii : ' + file3 + ' created'
205  ras = report(msg)
206;
207END
Note: See TracBrowser for help on using the repository browser.