-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsc_read_ncdf.pro
133 lines (115 loc) · 5.14 KB
/
fsc_read_ncdf.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
PRO FSC_Read_NCDF
; this function is to read the contents of a NETCDF format file
tstart1 = SYSTIME(/seconds); timer for each daily time step
;Reading NetCDF Files
;tempdata1=fltarr(2L, 32881L)
tempdata2=fltarr(3L, 32881L*19L)
;tempdata3=fltarr(4L, 499791200L)
;The following commands should be used to read data from a netCDF file:
Tempfile = NCDF_OPEN('m99091.t.nc', /NOWRITE) ; Open an existing netCDF file.
;Tempfileformat = NCDF_INQUIRE(Tempfile) ; Call this function to find the format of the netCDF file.
;PRINT, 'File format: {Ndims, Nvars, Ngatts, Recdim}'
;PRINT,Tempfileformat; { NDIMS:0L, NVARS:0L, NGATTS:0L, RECDIM:0L }
;DimID = NCDF_DIMID(Tempfile, 'time')
;PRINT, DimID
;;NCDF_DIMINQ, Tempfile, DimID, 'time', 800 ; Retrieve the names and sizes of dimensions in the file.
VarID = INTARR(7)
VarID[0] = NCDF_VARID(Tempfile, 'time')
VarID[1] = NCDF_VARID(Tempfile, 'lon')
VarID[2] = NCDF_VARID(Tempfile, 'lat')
VarID[3] = NCDF_VARID(Tempfile, 'depth')
VarID[4] = NCDF_VARID(Tempfile, 'sigma')
VarID[5] = NCDF_VARID(Tempfile, 'd3d')
VarID[6] = NCDF_VARID(Tempfile, 'temp')
NCDF_CLOSE, Tempfile ; Close the file.
;VarID2 = string([VarID[0], VarID[1], VarID[2], VarID[3]])
;PRINT, VarID2
; VarID: 0=tiem; 1=lon; 2=lat; 3=depth; 4=sigma; 5=d3d; 6=temp
;VarStruc = NCDF_VARINQ(Tempfile, 6) ; Retrieve the names, types, and sizes of variables in the file.
;PRINT, '{ NAME:"", DATATYPE:"", NDIMS:0L, NATTS:0L, DIM:LONARR(NDIMS) }'
;PRINT, VarStruc
;AttName = NCDF_ATTNAME(Tempfile, 6, /GLOBAL) ; Optionally, retrieve attribute names.
;PRINT, AttName
;AttStruc = NCDF_ATTINQ(Tempfile, 0, /GLOBAL) ; Optionally, retrieve the types and lengths of attributes.
;DIRECTORY: c:\~
;FILENAME: m99091.t.nc
;INSTITUTION: University of Michigan
;COMMENT1: Lake Michigan 2 km bathymetric grid
;COMMENT2: 6-hourly model output starting at validtime plus 6 hr
;VALIDTIME: 01-APR-1999 00:00 GMT
;VALIDTIME_DOY: 091, 1999 00:00 GMT
;AUTHOR: [email protected]
;CREATION_DATE: Wed Apr 24 15:35:57 2013 GMT
;NCDF_ATTGET,Tempfile, /GLOBAL, 'CREATION_DATE', filename; Optionally, retrieve the attributes.
;; Read the data back out:
;NCDF_VARGET, id, vid, output_data
;NCDF_ATTGET, id, vid, 'long_name', ztitle
;NCDF_ATTGET, id, hid, 'long_name', ytitle
;NCDF_ATTGET, id, vid, 'units', subtitle
;!P.CHARSIZE = 2.5
;!X.TITLE = 'Location'
;!Y.TITLE = STRING(ytitle) ; Convert from bytes to strings.
;!Z.TITLE = STRING(ztitle) + '!C' + STRING(subtitle)
;NCDF_CLOSE, id ; Close the NetCDF file.
;SHOW3, output_data ; Display the data.
;n = 196608
;tempfile2 = FLTARR(4L, N)
Tempfile = NCDF_OPEN('m99091.t.nc', /NOWRITE) ; Open an existing netCDF file.
NCDF_VARGET, Tempfile, VarID[0], timedata ; Read the data from the variables.
print, n_elements(timedata)
;tempdata3 = FLTARR(3L, n_elements(timedata))
;tempdata3[0, *] = timedata
NCDF_CLOSE, Tempfile ; Close the file.
Tempfile = NCDF_OPEN('m99091.t.nc', /NOWRITE) ; Open an existing netCDF file.
NCDF_VARGET, Tempfile, VarID[1], londata ; Read the data from the variables.
print, n_elements(londata)
;Tempdata1[0,*] = londata
NCDF_CLOSE, Tempfile ; Close the file.
;Tempdata1[0,*] = londata
Tempfile = NCDF_OPEN('m99091.t.nc', /NOWRITE) ; Open an existing netCDF file.
NCDF_VARGET, Tempfile, VarID[2], latdata ; Read the data from the variables.
print, n_elements(latdata)
;Tempdata1[1,*] = latdata
NCDF_CLOSE, Tempfile ; Close the file.
;Tempdata1[1,*] = latdata
;Tempfile = NCDF_OPEN('m99091.t.nc', /NOWRITE) ; Open an existing netCDF file.
;NCDF_VARGET, Tempfile, VarID[3], depthdata ; Read the data from the variables.
;;print, n_elements(depthdata)
;NCDF_CLOSE, Tempfile ; Close the file.
Tempfile = NCDF_OPEN('m99091.t.nc', /NOWRITE) ; Open an existing netCDF file.
NCDF_VARGET, Tempfile, VarID[4], sigmadata ; Read the data from the variables.
print, n_elements(sigmadata);
NCDF_CLOSE, Tempfile ; Close the file.
;print, sigmadata
Tempfile = NCDF_OPEN('m99091.t.nc', /NOWRITE) ; Open an existing netCDF file.
NCDF_VARGET, Tempfile, VarID[6], tempdata ; Read the data from the variables.
print, n_elements(tempdata)
;Tempdata3[3,*] = tempdata
NCDF_CLOSE, Tempfile ; Close the file.
; Create 19-vertical layer array for each x&y cell
;depth = INDGEN(20) + 1L; 1 = top layer; 20 = bottom layer
zl = (sigmadata) # REPLICATE(1., 32881L)
;print, zl
n=32881L
;FOR i = 0L, n - 1L, 19L DO BEGIN
; Tempdata4[0, i:i+18L] = londata[i]; # REPLICATE(1., 19L)
; Tempdata4[1, i:i+18L] = latdata[i]; # REPLICATE(1., 19L)
;ENDFOR
FOR i = 0L, n - 1L, 19L DO Tempdata2[0, i:i+18L] = londata[i]; # REPLICATE(1., 19L)
FOR i = 0L, n - 1L, 19L DO Tempdata2[1, i:i+18L] = latdata[i]; # REPLICATE(1., 19L)
Tempdata2[2, *]=zl
;print, tempdata2[*, 0:100L]
londata2 = transpose(Tempdata2[0,*]) # REPLICATE(1., 800L)
latdata2 = transpose(Tempdata2[1,*]) # REPLICATE(1., 800L)
sigmadata2 = transpose(Tempdata2[2,*]) # REPLICATE(1., 800L)
;print, londata2[0:100L]
;print, latdata2[0:100L]
;print, sigmadata2[0:100L]
;print, tempdata[0:100L]
t_elapsed = systime(/seconds) - tstart1
;PRINT, 'Elapesed time (seconds) for all simulations:', t_elapsed
PRINT, 'Elapesed time (minutes) for all simulations:', t_elapsed/60.
PRINT, 'end of input'
;tempdata2[3, *] = tempdata
;NCDF_CLOSE, Tempfile ; Close the file.
END