Blame view

SRC/GENERAL_MODULES/frequency_spec.F90 7.98 KB
886c558b   Steve Greedy   SACAMOS Public Re...
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
!
! This file is part of SACAMOS, State of the Art CAble MOdels in Spice. 
! It was developed by the University of Nottingham and the Netherlands Aerospace 
! Centre (NLR) for ESA under contract number 4000112765/14/NL/HK.
! 
! Copyright (C) 2016-2017 University of Nottingham
! 
! SACAMOS is free software: you can redistribute it and/or modify it under the 
! terms of the GNU General Public License as published by the Free Software 
! Foundation, either version 3 of the License, or (at your option) any later 
! version.
! 
! SACAMOS is distributed in the hope that it will be useful, but 
! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
! or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
! for more details.
! 
! A copy of the GNU General Public License version 3 can be found in the 
! file GNU_GPL_v3 in the root or at <http://www.gnu.org/licenses/>.
! 
! SACAMOS uses the EISPACK library (in /SRC/EISPACK). EISPACK is subject to 
! the GNU Lesser General Public License. A copy of the GNU Lesser General Public 
! License version can be found in the file GNU_LGPL in the root of EISPACK 
! (/SRC/EISPACK ) or at <http://www.gnu.org/licenses/>.
! 
! The University of Nottingham can be contacted at: ggiemr@nottingham.ac.uk
!
! File Contents:
! MODULE frequency_spec
! SUBROUTINE read_and_set_up_frequency_specification
! SUBROUTINE reset_frequency_specification
! SUBROUTINE set_up_frequency_specification
! SUBROUTINE deallocate_frequency_specification
!
! NAME
!     frequency_spec
!
! AUTHORS
!     Chris Smartt
!
! DESCRIPTION
!     Module to deal with all aspects of frequency range specifications
!     The module defines a struncture for a frequency range
!     subroutine to read a frequency specification and set up the structure
!     subroutine to reset the frequency_specification
!     subroutine to set up the frequency_specification
!     subroutine to deallocate the frequency_specification
!
! COMMENTS
!      
!
! HISTORY
!
!     started 22/08/2016 CJS 
!     Add some checks etc for robustness 15/12/2016 CJS 
!
!
MODULE frequency_spec

USE type_specifications

IMPLICIT NONE

TYPE :: frequency_specification

character(LEN=3):: freq_range_type ! frequency range type, 'log' or 'lin'
real(dp)        :: fmin            ! minimum frequency
real(dp)        :: fmax            ! maximum frequency
integer         :: n_frequencies   ! number of frequencies
real(dp),allocatable ::freq_list(:)! list of frequencies

END TYPE frequency_specification

CONTAINS
 
! NAME
!     read_and_set_up_frequency_specification
!
! AUTHORS
!     Chris Smartt
!
! DESCRIPTION
!     Set up frequency range specifications based on information read from file
!
! COMMENTS
!      
!
! HISTORY
!
!     started 22/08/2016 CJS 
!
SUBROUTINE read_and_set_up_frequency_specification(freq_data,unit)

USE general_module

IMPLICIT NONE

! variables passed to subroutine

TYPE(frequency_specification),intent(INOUT) :: freq_data
integer,intent(IN)                          :: unit
  
! local variables  
  
real(dp)        :: fstep               ! frequency step

real(dp)        :: log_fmin            ! log of minimum frequency
real(dp)        :: log_fmax            ! log of maximum frequency
real(dp)        :: log_fstep           ! log of frequency step
real(dp)        :: log_f               ! log of frequency

integer         :: ierr

! START

  read(unit,'(A3)',IOSTAT=ierr)freq_data%freq_range_type  
  if (ierr.NE.0) then
    run_status='ERROR reading .spice_model_spec file:  '// &
               'The frequency range type needs to be specified (log or lin)'
    CALL write_program_status()
    STOP 1
  end if
  
  read(unit,*,IOSTAT=ierr)freq_data%fmin,   &
                          freq_data%fmax,   &
                          freq_data%n_frequencies
  if (ierr.NE.0) then
    run_status='ERROR: reading .spice_model_spec file: '// &
               'The frequency range  needs to be specified (fmin fmax n_frequenceis)'
    CALL write_program_status()
    STOP 1
  end if

! Some checks that the specified frequency range is sensible

  if (freq_data%fmin.LT.0d0) then
    run_status='ERROR: read_and_set_up_frequency_specification.   fmin < 0'
    CALL write_program_status()
    STOP 1
  end if

  if (freq_data%fmax.LT.freq_data%fmin) then
    run_status='ERROR: read_and_set_up_frequency_specification.   fmax < fmin'
    CALL write_program_status()
    STOP 1
  end if

  if (freq_data%n_frequencies.LT.0d01) then
    run_status='ERROR: read_and_set_up_frequency_specification.  number of frequencies < 1'
    CALL write_program_status()
    STOP 1
  end if
  
  CALL set_up_frequency_specification(freq_data)

  RETURN

END SUBROUTINE read_and_set_up_frequency_specification
!
! NAME
!     reset_frequency_specification
!
! AUTHORS
!     Chris Smartt
!
! DESCRIPTION
!     reset frequency range specifications
!
! COMMENTS
!      
!
! HISTORY
!
!     started 15/12/2016 CJS 
!
SUBROUTINE reset_frequency_specification(freq_data)

IMPLICIT NONE

! variables passed to subroutine

TYPE(frequency_specification),intent(INOUT) :: freq_data
  
! local variables  

! START

  freq_data%freq_range_type='lin'
  freq_data%fmin=0d0
  freq_data%fmax=0d0
  freq_data%n_frequencies=1
  
  RETURN

END SUBROUTINE reset_frequency_specification
!
! NAME
!     set_up_frequency_specification
!
! AUTHORS
!     Chris Smartt
!
! DESCRIPTION
!     Set up frequency range specifications i.e. given the frequency range specification, 
!     allocate and set the frequency list array.
!
! COMMENTS
!      
!
! HISTORY
!
!     started 22/08/2016 CJS 
!     16/09/2016 CJS process separated from read_and_set_up_frequency_specification
!
SUBROUTINE set_up_frequency_specification(freq_data)

USE general_module

IMPLICIT NONE

! variables passed to subroutine

TYPE(frequency_specification),intent(INOUT) :: freq_data
  
! local variables  
  
real(dp)        :: fstep               ! frequency step

real(dp)        :: log_fmin            ! log of minimum frequency
real(dp)        :: log_fmax            ! log of maximum frequency
real(dp)        :: log_fstep           ! log of frequency step
real(dp)        :: log_f               ! log of frequency

integer         :: floop               ! frequency loop variable

integer         :: ierr

! START

  if (freq_data%freq_range_type.EQ.'log') then

    log_fmin=log10(freq_data%fmin)
    log_fmax=log10(freq_data%fmax)
    log_fstep=0d0                  ! this is the value used if freq_data%n_frequencies=1
    if (freq_data%n_frequencies.ne.1) then
      log_fstep=(log_fmax-log_fmin)/dble(freq_data%n_frequencies-1)
    end if
    
  else if (freq_data%freq_range_type.EQ.'lin') then

    fstep=0d0                      ! this is the value used if freq_data%n_frequencies=1
    if (freq_data%n_frequencies.ne.1) then
      fstep=(freq_data%fmax-freq_data%fmin)/dble(freq_data%n_frequencies-1)
    end if
        
  else 

    run_status='ERROR in set_up_frequency_specification: frequency range type should be log or lin'
    CALL write_program_status()
    STOP 1
  
  end if
  
  if ( ALLOCATED(freq_data%freq_list) ) CALL deallocate_frequency_specification(freq_data)

  ALLOCATE(freq_data%freq_list(1:freq_data%n_frequencies))
  
  do floop=1,freq_data%n_frequencies
    
    if (freq_data%freq_range_type.EQ.'log') then

      log_f=log_fmin+(floop-1)*log_fstep
      freq_data%freq_list(floop)=10d0**(log_f)
    
    else if (freq_data%freq_range_type.EQ.'lin') then

      freq_data%freq_list(floop)=freq_data%fmin+(floop-1)*fstep

    end if
    
  end do ! next frequency

END SUBROUTINE set_up_frequency_specification
 
! NAME
!     deallocate_frequency_specification
!
! AUTHORS
!     Chris Smartt
!
! DESCRIPTION
!     deallocate the frequency range specification
!
! COMMENTS
!      
!
! HISTORY
!
!     started 22/08/2016 CJS 
!

SUBROUTINE deallocate_frequency_specification(freq_data)

IMPLICIT NONE

! variables passed to subroutine

TYPE(frequency_specification),intent(INOUT) :: freq_data

! START

  if (ALLOCATED(freq_data%freq_list)) DEALLOCATE(freq_data%freq_list)

END SUBROUTINE deallocate_frequency_specification

END MODULE frequency_spec