[15] | 1 | ;+ |
---|
| 2 | ; @file_comments |
---|
| 3 | ; compute delta between cond_sed*.pro Netcdf files with same dimension |
---|
| 4 | ; |
---|
[16] | 5 | ; @param file1 {in}{required} {type=string} |
---|
[15] | 6 | ; name of the first file to be read |
---|
| 7 | ; |
---|
[16] | 8 | ; @param file2 {in}{required} {type=string} |
---|
[15] | 9 | ; name of the second file to be read |
---|
| 10 | ; |
---|
[16] | 11 | ; @param file3 {in}{required} {type=string} |
---|
[15] | 12 | ; file where differences between variables are written |
---|
| 13 | ; |
---|
| 14 | ; @examples |
---|
[17] | 15 | ; test (for header and delta) |
---|
[15] | 16 | ; to compute difference between cond_sed in cond_sed_ORCA2.nc and |
---|
| 17 | ; itself and write it in ginette.nc : |
---|
[17] | 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' |
---|
[15] | 23 | ; values of delta must be 0 everywhere |
---|
[17] | 24 | ; $ rm ginette.nc |
---|
[15] | 25 | ; idem with BR file |
---|
[17] | 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' |
---|
[15] | 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 : |
---|
[17] | 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' |
---|
[15] | 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 |
---|
[17] | 47 | ; |
---|
[15] | 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 |
---|
[16] | 57 | ; $Id$ |
---|
[15] | 58 | ; |
---|
[17] | 59 | PRO step1_diff, file1, file2, file3 |
---|
[15] | 60 | ; |
---|
| 61 | ncverbose=1 |
---|
| 62 | ; |
---|
| 63 | ; check if file1 exists |
---|
| 64 | fullfile1 = isafile(file1, NEW=0,/MUST_EXIST) |
---|
| 65 | IF fullfile1[0] EQ '' THEN BEGIN |
---|
| 66 | msg = 'eee : the file ' + fullfile1 + ' was not found.' |
---|
| 67 | PRINT, msg |
---|
| 68 | RETURN |
---|
| 69 | ENDIF |
---|
| 70 | ; |
---|
| 71 | ; protection |
---|
| 72 | IF (FILE_TEST(fullfile1[0], /READ) EQ 0) THEN BEGIN |
---|
| 73 | msg = 'eee : the file ' + fullfile1[0] + ' is not readable.' |
---|
| 74 | PRINT, msg |
---|
| 75 | RETURN |
---|
| 76 | ENDIF |
---|
| 77 | ; |
---|
| 78 | ; check if file2 exists |
---|
| 79 | fullfile2 = isafile(file2, NEW=0,/MUST_EXIST) |
---|
| 80 | IF fullfile2[0] EQ '' THEN BEGIN |
---|
| 81 | msg = 'eee : the file ' + fullfile2 + ' was not found.' |
---|
| 82 | PRINT, msg |
---|
| 83 | RETURN |
---|
| 84 | ENDIF |
---|
| 85 | ; |
---|
| 86 | ; protection |
---|
| 87 | IF (FILE_TEST(fullfile2[0], /READ) EQ 0) THEN BEGIN |
---|
| 88 | msg = 'eee : the file ' + fullfile2[0] + ' is not readable.' |
---|
| 89 | PRINT, msg |
---|
| 90 | RETURN |
---|
| 91 | ENDIF |
---|
| 92 | ; |
---|
| 93 | ; read the first file |
---|
| 94 | ncdf_read, fullfile1[0], file1info, file1dinfo, file1vinfo, $ |
---|
| 95 | file1gatts, file1vatts, file1data |
---|
| 96 | ; |
---|
| 97 | ; read the second file |
---|
| 98 | ncdf_read, fullfile2[0], file2info, file2dinfo, file2vinfo, $ |
---|
| 99 | file2gatts, file2vatts, file2data |
---|
| 100 | ; |
---|
| 101 | ; compute delta |
---|
| 102 | delta = *file1data[3] - *file2data[3] |
---|
| 103 | minarr = min(delta, max = maxarr) |
---|
| 104 | ; |
---|
| 105 | ; check for number of non zero in delta |
---|
| 106 | checknonzero=where(delta NE 0.,count) |
---|
| 107 | IF count EQ 0 THEN BEGIN |
---|
[17] | 108 | msg = 'iii : delta is zero everywhere' |
---|
[15] | 109 | PRINT, msg |
---|
| 110 | ENDIF ELSE BEGIN |
---|
[17] | 111 | msg = 'iii : delta is not zero ' + STRING(count) + ' times' |
---|
[15] | 112 | PRINT, msg |
---|
| 113 | ENDELSE |
---|
| 114 | ; |
---|
| 115 | ; |
---|
| 116 | ; write output |
---|
| 117 | ; in order to avoid unexpected overwritten |
---|
| 118 | IF (FILE_TEST(file3) EQ 1) THEN BEGIN |
---|
| 119 | msg = 'eee : the file ' + file3 + ' already exists.' |
---|
| 120 | PRINT, msg |
---|
| 121 | RETURN |
---|
| 122 | ENDIF |
---|
| 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 | ; |
---|
| 206 | END |
---|