1 | pro netcdfshow,filename |
---|
2 | ; |
---|
3 | fileID = ncdf_open(filename) |
---|
4 | |
---|
5 | ; |
---|
6 | ;find the number of variables |
---|
7 | fileinq_struct = ncdf_inquire(fileID) |
---|
8 | nvars = fileinq_struct.nvars |
---|
9 | ; |
---|
10 | print,filename |
---|
11 | ; |
---|
12 | print,filename |
---|
13 | print, nvars, ' variables in file' |
---|
14 | ; |
---|
15 | for 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 |
---|
33 | endfor ; attribute loop |
---|
34 | end |
---|
35 | ; |
---|
36 | pro 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) |
---|
53 | end |
---|
54 | ;--------------------- |
---|
55 | ;---LMDZ |
---|
56 | pro 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) |
---|
71 | end |
---|
72 | ;--------------------- |
---|