-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathread_sme.f90
236 lines (160 loc) · 5.86 KB
/
read_sme.f90
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
! Copyright (C) 2002 Regents of the University of Michigan, portions used with permission
! For more information, see http://csem.engin.umich.edu/tools/swmf
!==============================================================================
subroutine read_al_onset_list(iOutputError, StartTime, EndTime)
use ModKind
use ModIndices
use ModTimeConvert, ONLY: time_int_to_real
implicit none
integer, intent(out) :: iOutputError
real(Real8_), intent(in) :: EndTime, StartTime
integer :: ierror, iAE, j, npts
logical :: IsDone
! One line of input
character (len=100) :: line
real (Real8_) :: TimeDelay, BufferTime
integer, dimension(7) :: itime
!------------------------------------------------------------------------
iOutputError = 0
BufferTime = 24.0*3600.0 * 31.0
IsDone = .false.
npts = 0
TimeDelay = 0.0
if (NameOfSecondIndexFile == "none" .and. nIndices_V(onsetut_) == 1) return
call init_mod_indices
! If we have been here before and we read the entire file, leave
if (.not.ReReadOnsetFile .and. nIndices_V(onsetut_) > 0) return
! This if statement makes sure that we have been here before and
! want to be here again
if (ReReadOnsetFile) then
! If we still have a lot of data in memory, then don't bother
! reading more.
if (StartTime + BufferTime < IndexTimes_TV(nIndices_V(onsetut_),onsetut_)) &
return
endif
! Assume that we can read the entire file
ReReadOnsetFile = .false.
if (nIndices_V(onsetut_) == 0) NameOfOnsetFile = NameOfSecondIndexFile
open(LunIndices_, file=NameOfOnsetFile, status="old", iostat = ierror)
if (ierror.ne.0) then
iOutputError = 1
return
endif
iAE = 1
iTime = 0
do while (.not.IsDone)
read(LunIndices_,*,iostat=iError) &
(iTime(j),j=1,5), &
Indices_TV(iAE,onsetmlat_), &
Indices_TV(iAE,onsetmlt_)
iTime(6) = 0
if (ierror /= 0) then
IsDone = .true.
! This means that the GITM time is all AFTER the first
! line in the file!
if (StartTime > IndexTimes_TV(iAE,onsetut_)) then
iAE = iAE +1
endif
else
call time_int_to_real(iTime,IndexTimes_TV(iAE,onsetut_))
Indices_TV(iAE,onsetut_) = IndexTimes_TV(iAE,onsetut_) - StartTime
! This makes sure that we only store the values that we
! are really interested in
if ( IndexTimes_TV(iAE,onsetut_) >= StartTime-BufferTime .and. &
IndexTimes_TV(iAE,onsetut_) <= EndTime+BufferTime .and. &
iAE < MaxIndicesEntries) then
IndexTimes_TV(iAE,onsetmlat_) = IndexTimes_TV(iAE,onsetut_)
IndexTimes_TV(iAE,onsetmlt_) = IndexTimes_TV(iAE,onsetut_)
iAE = iAE + 1
else
! This means that the GITM time is all BEFORE the first
! line in the file!
if (EndTime < IndexTimes_TV(iAE,onsetut_) .and. iAE == 1) then
iAE = iAE +1
endif
endif
endif
enddo
close(LunIndices_)
if (iAE >= MaxIndicesEntries) ReReadOnsetFile = .true.
nIndices_V(onsetut_) = iAE - 1
nIndices_V(onsetmlat_) = iAE - 1
nIndices_V(onsetmlt_) = iAE - 1
end subroutine read_al_onset_list
!==============================================================================
subroutine read_sme(iOutputError, StartTime, EndTime)
use ModKind
use ModIndices
use ModTimeConvert, ONLY: time_int_to_real
implicit none
integer, intent(out) :: iOutputError
real(Real8_), intent(in) :: EndTime, StartTime
integer :: ierror, iAE, j, npts
logical :: IsDone
! One line of input
character (len=100) :: line
real (Real8_) :: TimeDelay, BufferTime = 180.0
integer, dimension(7) :: itime
!------------------------------------------------------------------------
iOutputError = 0
IsDone = .false.
npts = 0
TimeDelay = 0.0
if (NameOfIndexFile == "none" .and. nIndices_V(ae_) == 1) return
call init_mod_indices
! If we have been here before and we read the entire file, leave
if (.not.ReReadSMEFile .and. nIndices_V(ae_) > 0) return
! This if statement makes sure that we have been here before and
! want to be here again
if (ReReadSMEFile) then
! If we still have a lot of data in memory, then don't bother
! reading more.
if (StartTime + BufferTime < IndexTimes_TV(nIndices_V(ae_),ae_)) &
return
endif
! Assume that we can read the entire file
ReReadSMEFile = .false.
if (nIndices_V(ae_) == 0) NameOfSMEFile = NameOfIndexFile
open(LunIndices_, file=NameOfSMEFile, status="old", iostat = ierror)
if (ierror.ne.0) then
iOutputError = 1
return
endif
iAE = 1
iTime = 0
do while (.not.IsDone)
read(LunIndices_,*,iostat=iError) &
(iTime(j),j=1,6), &
Indices_TV(iAE,ae_), &
Indices_TV(iAE,al_), &
Indices_TV(iAE,au_)
if (ierror /= 0) then
IsDone = .true.
! This means that the GITM time is all AFTER the first
! line in the file!
if (StartTime > IndexTimes_TV(iAE,ae_)) then
iAE = iAE +1
endif
else
call time_int_to_real(iTime,IndexTimes_TV(iAE,ae_))
! This makes sure that we only store the values that we
! are really interested in
if ( IndexTimes_TV(iAE,ae_) >= StartTime-BufferTime .and. &
IndexTimes_TV(iAE,ae_) <= EndTime+BufferTime .and. &
iAE < MaxIndicesEntries) then
iAE = iAE + 1
else
! This means that the GITM time is all BEFORE the first
! line in the file!
if (EndTime < IndexTimes_TV(iAE,ae_) .and. iAE == 1) then
iAE = iAE +1
endif
endif
endif
enddo
close(LunIndices_)
if (iAE >= MaxIndicesEntries) ReReadSMEFile = .true.
nIndices_V(ae_) = iAE - 1
nIndices_V(au_) = iAE - 1
nIndices_V(al_) = iAE - 1
end subroutine read_sme