getcdfvar.pro
2.11 KB
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
function getCdfVar, files, paramName, dims, StartDouble, IntDouble, Time, Data
Size = N_elements(Time);
TIMESHIFT = 62167219200.D0
startIndex = 0L;
datapath = getenv("USER_DATA_PATH") eq '' ? '../DATA/' : getenv("USER_DATA_PATH");
for i = 0, n_elements(files) - 1 do begin
fileName = datapath + files[i];
id = CDF_OPEN(fileName);
CDF_CONTROL, id, SET_ZMODE=2
; CDF_CONTROL, id, GET_VAR_INFO=info, VARIABLE=0, /ZVARIABLE
dataType = "UNKNOWN"
timeId = 0L;
while (dataType ne "CDF_EPOCH" AND dataType ne "CDF_EPOCH16") do begin
rest = cdf_varinq(id, timeId, /ZVARIABLE)
dataType = rest.datatype;
timeId += 1L;
endwhile
timeId -= 1L;
recs = getcdfnbrecs_(FileName, timeId);
; CDF_CONTROL, id, GET_VAR_INFO=info, VARIABLE=0, /ZVARIABLE
;EXTENDRECS MAXALLOCREC MAXREC MAXRECS NINDEXENTRIES NINDEXRECORDS
if (dataType eq "CDF_EPOCH16") then begin
CDF_VARGET, id, timeId, EPOCH16, REC_COUNT = recs+1, /ZVARIABLE
EPOCH = dblarr(recs);
for j = 0, recs -1 do begin
CDF_EPOCH16, EPOCH16[j], yr, mo, dy, hr, min, sec, milli, micro, pico, /BREAKDOWN_EPOCH
CDF_EPOCH, EPOCH8, yr, mo, dy, hr, min, sec, milli, /COMPUTE_EPOCH
EPOCH[j] = EPOCH8;
endfor
endif else CDF_VARGET, id, timeId, EPOCH, REC_COUNT = recs+1, /ZVARIABLE
Time1 = reform(EPOCH/1000.D0 - TIMESHIFT)
num = where(Time1 GE StartDouble AND Time1 LT StartDouble+IntDouble, Index);
if ((Index eq 0 AND startIndex eq 0) OR (startIndex + Index gt Size)) then begin
return, 0
endif
if (Index gt 0) then begin
Time[startIndex:startIndex+Index-1] = Time1[num];
varId = CDF_VARNUM(id, paramName);
CDF_VARGET, id, varId, data1, REC_COUNT = recs+1, /ZVARIABLE
if (dims eq 1) then Data[startIndex:startIndex+Index-1] = reform(Data1[num]) $
else Data[*, startIndex:startIndex+Index-1] = Data1[*, num]
endif
CDF_CLOSE, id
startIndex += Index;
endfor
return,startIndex;
end