source: TOOLS/CMIP6_FORCING/AER_TROP_EMISSIONS/REGRID/netcdf.pro @ 3391

Last change on this file since 3391 was 3391, checked in by oboucher, 4 years ago

Current version of regrid scripts for creating aerosol emissions files for CMIP6

File size: 2.4 KB
Line 
1pro netcdfshow,filename
2;
3fileID = ncdf_open(filename)
4
5;
6;find the number of variables
7fileinq_struct = ncdf_inquire(fileID)
8nvars = fileinq_struct.nvars
9;
10print,filename
11;
12print,filename
13print, nvars, ' variables in file'
14;
15for varndx = 0,nvars-1 do begin
16
17   ; get the name, datatype, dims, number of attributes
18     varstruct = ncdf_varinq(fileID,varndx)
19   ; print the variable index, name, datatype, dims
20     print, '--------------------------------------------------------'
21     print,varndx,'    ',varstruct.name, '     ',varstruct.datatype
22     print,'dims = ',varstruct.dim
23   ; loop through attributes
24     for attndx = 0, varstruct.natts-1 do begin
25
26       ; get attribute name, then use it to get the value
27         attname = ncdf_attname(fileID,varndx,attndx)
28         ncdf_attget,fileID,varndx,attname,value
29
30       ; print name and value to file
31         print,attname, '     ',string(value)
32     endfor
33endfor ; attribute loop
34end
35;
36pro netcdfread_era, filename, variable_name, data_variable, scale_factor, add_offset, dims
37; This procedure will read netCDF data and place it in an IDL variable
38; INPUT: filename - a string variable that includes the filepath
39;        variable_name - a string that must match exactly that produced by       
40;                        ncdfshow.pro
41; OUTPUT: data_variable - a user supplied variable for the data
42;         dims - a vector of the dimensions
43
44; get fileID, variable ID
45  fileID = ncdf_open(filename)
46  varID = ncdf_varid(fileID,variable_name)
47
48; get the data and dimensions
49  ncdf_varget,fileID, varID, data_variable
50  ncdf_attget,fileID, varID, 'scale_factor', scale_factor
51  ncdf_attget,fileID, varID, 'add_offset',   add_offset
52  dims = size(data_variable,/dimensions)
53end
54;---------------------
55;---LMDZ
56pro netcdfread, filename,variable_name, data_variable, dims
57; This procedure will read netCDF data and place it in an IDL variable
58; INPUT: filename - a string variable that includes the filepath
59;        variable_name - a string that must match exactly that produced by       
60;                        ncdfshow.pro
61; OUTPUT: data_variable - a user supplied variable for the data
62;         dims - a vector of the dimensions
63
64; get fileID, variable ID
65  fileID = ncdf_open(filename)
66  varID = ncdf_varid(fileID,variable_name)
67
68; get the data and dimensions
69  ncdf_varget,fileID, varID, data_variable
70  dims = size(data_variable,/dimensions)
71end
72;---------------------
Note: See TracBrowser for help on using the repository browser.