V3FIT
mddc_T.f
1 
2 !*******************************************************************************
3 ! File mddc_T.f
4 ! Contains module mddc_T
5 ! Defines derived-types: mddc_desc, mddc_mrf
6 ! A type of Diagnostic - Magnetic Diagnostic-Dot Coil
7 ! (A magnetic diagnostic coil, with original data from a diagnostic-dot file)
8 !
9 !*******************************************************************************
10 ! MODULE mddc_T
11 ! (MDDC Type Definition, for the V3FIT code)
12 ! SECTION I. VARIABLE DECLARATIONS
13 ! SECTION II. DERIVED-TYPE DECLARATIONS
14 ! SECTION III. INTERFACE BLOCKS
15 ! SECTION IV. CONSTRUCTION SUBROUTINES
16 ! SECTION V. DESTRUCTION SUBROUTINES
17 ! SECTION VI. ASSIGNMENT SUBROUTINES
18 ! SECTION VII. OUTPUT SUBROUTINES
19 
20 ! SECTION XVI. COMMENTS FOR DIFFERENT REVISIONS
21 !*******************************************************************************
22  MODULE mddc_t
23 
24 !*******************************************************************************
25 ! SECTION I. VARIABLE DECLARATIONS
26 !*******************************************************************************
27 
28 !-------------------------------------------------------------------------------
29 ! Type declarations - lengths of reals, integers, and complexes.
30 ! Frequently used mathematical constants, lots of extra precision.
31 !-------------------------------------------------------------------------------
32  USE stel_kinds, only : rprec, cprec
33  USE stel_constants, only : pi, twopi, one, zero
34 
35 !-------------------------------------------------------------------------------
36 ! Use Statements for other structures, V3 Utilities
37 !-------------------------------------------------------------------------------
38  USE bsc_t
39  USE v3_utilities
40 
41 !-------------------------------------------------------------------------------
42 ! Implicit None comes after USE statements, before other declarations
43 !-------------------------------------------------------------------------------
44  IMPLICIT NONE
45 
46 !-------------------------------------------------------------------------------
47 ! Make type declarations and constants Private, so there are no conflicts.
48 !-------------------------------------------------------------------------------
49  PRIVATE rprec, cprec, pi, twopi, one, zero
50 
51 !-------------------------------------------------------------------------------
52 ! Lengths of Character Variables
53 !-------------------------------------------------------------------------------
54  INTEGER, PARAMETER, PRIVATE :: type_len=10
55  INTEGER, PARAMETER, PRIVATE :: sn_len=30
56  INTEGER, PARAMETER, PRIVATE :: ln_len=80
57  INTEGER, PARAMETER, PRIVATE :: units_len=30
58 
59 !*******************************************************************************
60 ! SECTION II. DERIVED-TYPE DECLARATIONS
61 ! 1) MDDC Description:
62 ! mddc_desc
63 ! Type of diagnostic specified by % d_type = 'mddc'.
64 !
65 ! 2) MDDC Magnetic Response Functions:
66 ! mddc_mrf
67 !
68 ! A mddc_mrf is a specialized structure, particular to magnetic diagnostics. The
69 ! model signal computation is an integration over the plasma volume, and
70 ! much of the integrand can be pre-computed, knowing only information about the
71 ! magnetic diagnostic. A mddc_mrf contains this pre-computed information, so
72 ! that the model signal computation will be faster. The model signal
73 ! also contains a contribution due to the external field-coil groups. This
74 ! coil-response information is also contained in a mddc_mrf.
75 !
76 ! Note that mddc_mrf is declared first, so that the type is known to a
77 ! mddc_desc.
78 !
79 !*******************************************************************************
80 !-------------------------------------------------------------------------------
81 !-------------------------------------------------------------------------------
82 ! Declare type mddc_mrf
83 ! ---- Identification Variables ----
84 ! code_name Character: name of the code which computed the responses
85 ! code_version Character: version of the code
86 ! date_run Character: date and time when the code was run
87 ! field_coils_id Character: identifier of field-coils
88 !
89 ! ---- Coil Response Function Variables----
90 ! n_field_cg number of field-coil groups (external currents)
91 ! (size of the mresponse_extcur array)
92 ! rdiag_coilg_1 array of diagnostic - field-coil-group responses
93 ! (Single row of the rdiag_coilg array)
94 ! ^ USE AS ALLOCATABLE ARRAY!
95 ! extcur_mg array of external currents - 'MGRID'
96 ! Used for normalization with 'raw' or 'scaled' mode
97 ! ^ USE AS ALLOCATABLE ARRAY!
98 !
99 ! ---- Plasma Response Grid Variables ----
100 ! ir number of grid points in R, plasma grid
101 ! jz number of grid points in z, plasma grid
102 ! kp number of phi planes per field period in plasma grid
103 ! kp_store number of phi planes actually store in plasma grid
104 ! (With lstell_sym = .true., don't need to store all planes)
105 ! rmin Minimum R for plasma grid
106 ! rmax Maximum R for plasma grid
107 ! zmin Minimum z for plasma grid
108 ! zmax Maximum z for plasma grid
109 ! n_field_periods Number of field periods
110 ! lstell_sym Logical - True for stellarator symmetry
111 !
112 ! ---- Plasma Response Arrays ----
113 ! a_r R component of plasma response function
114 ! a_f phi component of plasma response function
115 ! a_z Z component of plasma response function
116 ! ^ USE AS ALLOCATABLE ARRAYS!
117 !-------------------------------------------------------------------------------
118  TYPE mddc_mrf
119  CHARACTER(len=80) :: code_name
120  CHARACTER(len=80) :: code_version
121  CHARACTER(len=80) :: date_run
122  CHARACTER(len=80) :: field_coils_id
123 
124  INTEGER :: n_field_cg
125  REAL(rprec), DIMENSION(:), POINTER :: rdiag_coilg_1 => null()
126  REAL(rprec), DIMENSION(:), POINTER :: extcur_mg => null()
127 
128  INTEGER :: ir
129  INTEGER :: jz
130  INTEGER :: kp
131  INTEGER :: kp_store
132  REAL(rprec) :: rmin
133  REAL(rprec) :: rmax
134  REAL(rprec) :: zmin
135  REAL(rprec) :: zmax
136  INTEGER :: n_field_periods
137  LOGICAL :: lstell_sym
138 
139  REAL(rprec), DIMENSION(:,:,:), POINTER :: a_r => null()
140  REAL(rprec), DIMENSION(:,:,:), POINTER :: a_f => null()
141  REAL(rprec), DIMENSION(:,:,:), POINTER :: a_z => null()
142 
143  LOGICAL :: use_con_shell
144  INTEGER :: n_u
145  INTEGER :: kp_shell
146  INTEGER :: kp_shell_store
147  REAL(rprec), DIMENSION(:,:), POINTER :: a_s_r => null()
148  REAL(rprec), DIMENSION(:,:), POINTER :: a_s_f => null()
149  REAL(rprec), DIMENSION(:,:), POINTER :: a_s_z => null()
150 
151  END TYPE mddc_mrf
152 !-------------------------------------------------------------------------------
153 ! Declare type mddc_desc
154 ! s_name character, short name of diagnostic
155 ! l_name character, long name of diagnostic
156 ! units character, physical units that the data is measured in
157 ! sigma_default real, default value of the uncertainty in the data
158 ! mddc_type character, keyword from the diagnostic_dot file
159 ! l_mdcoil_def logical, definition status of the mdcoil component
160 ! flux_factor real, factor to convert from flux to appropriate units
161 ! mdcoil type bsc_coil, description of coil
162 ! mrf type mddc_mrf, magnetic response functions
163 !!-------------------------------------------------------------------------------
165  CHARACTER (len=sn_len) :: s_name
166  CHARACTER (len=ln_len) :: l_name
167  CHARACTER (len=units_len) :: units
168  CHARACTER (len=30) :: mddc_type
169  LOGICAL :: l_mdcoil_def
170  REAL(rprec) :: sigma_default
171  REAL(rprec) :: flux_factor
172  TYPE (bsc_coil) :: mdcoil
173  TYPE (mddc_mrf) :: mrf
174  END TYPE mddc_desc
175 
176 !*******************************************************************************
177 ! SECTION III. INTERFACE BLOCKS
178 !*******************************************************************************
179 !-------------------------------------------------------------------------------
180 ! Assignment for structures
181 !-------------------------------------------------------------------------------
182  INTERFACE ASSIGNMENT (=)
183  MODULE PROCEDURE mddc_desc_assign, &
184  & mddc_mrf_assign
185  END INTERFACE
186 
187 !-------------------------------------------------------------------------------
188 ! Generic construct
189 !-------------------------------------------------------------------------------
190  INTERFACE mddc_construct
191  MODULE PROCEDURE mddc_desc_construct, &
192  & mddc_mrf_construct
193  END INTERFACE
194 
195 !-------------------------------------------------------------------------------
196 ! Generic destroy
197 !-------------------------------------------------------------------------------
198  INTERFACE mddc_destroy
199  MODULE PROCEDURE mddc_desc_destroy, &
200  & mddc_mrf_destroy
201  END INTERFACE
202 
203 !-------------------------------------------------------------------------------
204 ! Generic write
205 !-------------------------------------------------------------------------------
206  INTERFACE mddc_write
207  MODULE PROCEDURE mddc_desc_write, &
208  & mddc_mrf_write
209  END INTERFACE
210 
211 !-------------------------------------------------------------------------------
212 ! Interface block for testing goes here.
213 !-------------------------------------------------------------------------------
214 
215  CONTAINS
216 !*******************************************************************************
217 ! SECTION IV. CONSTRUCTION SUBROUTINES
218 !*******************************************************************************
219 !-------------------------------------------------------------------------------
220 ! Construct a mddc_desc
221 !
222 ! For d_type = 'mddc' (magnetic mddc-dot coil)
223 !-------------------------------------------------------------------------------
224  SUBROUTINE mddc_desc_construct(this,s_name,l_name,units, &
225  & sigma_default,mddc_type,mdcoil,mrf,flux_factor)
226 
227 ! NB.
228 ! The mdcoil argument is assigned to the 'this' component. Do NOT call this
229 ! subroutine with this % mdcoil as the mdcoil argument.
230 
231  IMPLICIT NONE
232 
233 ! Declare Arguments
234  TYPE (mddc_desc), INTENT(inout) :: this
235  CHARACTER (len=*), INTENT(in) :: s_name
236  CHARACTER (len=*), INTENT(in) :: l_name
237  CHARACTER (len=*), INTENT(in) :: units
238  CHARACTER (len=*), INTENT(in) :: mddc_type
239  REAL(rprec), INTENT(in) :: sigma_default
240  TYPE (bsc_coil), INTENT(in), TARGET :: mdcoil ! Why a TARGET ? 2007-06-11
241  TYPE (mddc_mrf), INTENT(in), OPTIONAL :: mrf
242  REAL(rprec), INTENT(in), OPTIONAL :: flux_factor
243 
244 ! Declare local variables
245  CHARACTER(len=*), PARAMETER :: sub_name = &
246  & 'mddc_desc_construct: '
247 
248 ! Start of executable code
249 
250 ! Destroy the mdcoil component
251  CALL bsc_destroy(this % mdcoil)
252 
253 ! Destroy the mrf component
254  CALL mddc_mrf_destroy(this % mrf)
255 
256 ! Scalar assignments
257  this % s_name = trim(adjustl(s_name))
258  this % l_name = trim(adjustl(l_name))
259  this % units = trim(adjustl(units))
260  this % mddc_type = trim(adjustl(mddc_type))
261  this % l_mdcoil_def = .true.
262  IF (PRESENT(flux_factor)) THEN
263  this % flux_factor = flux_factor
264  ELSE
265  this % flux_factor = one
266  ENDIF
267 
268 ! Derived Type Assignments
269  this % mdcoil = mdcoil
270  IF (PRESENT(mrf)) THEN
271  this % mrf = mrf
272  ENDIF
273 
274  END SUBROUTINE mddc_desc_construct
275 
276 !-------------------------------------------------------------------------------
277 ! Construct a mddc_mrf
278 !-------------------------------------------------------------------------------
279  SUBROUTINE mddc_mrf_construct(this,code_name,code_version, &
280  & date_run,field_coils_id,rdiag_coilg_1,extcur_mg,kp, &
281  & rmin,rmax,zmin,zmax,n_field_periods,lstell_sym,a_r,a_f,a_z, &
282  & use_con_shell, a_s_r, a_s_f, a_s_z, kp_shell)
283 
284  IMPLICIT NONE
285 
286 ! Declare Arguments
287  TYPE (mddc_mrf), INTENT(inout) :: this
288  CHARACTER(len=*), INTENT(in) :: code_name
289  CHARACTER(len=*), INTENT(in) :: code_version
290  CHARACTER(len=*), INTENT(in) :: date_run
291  CHARACTER(len=*), INTENT(in) :: field_coils_id
292  REAL(rprec), DIMENSION(:), INTENT(in) :: rdiag_coilg_1
293  REAL(rprec), DIMENSION(:), INTENT(in) :: extcur_mg
294  INTEGER, INTENT(in) :: kp
295  REAL(rprec), INTENT(in) :: rmin
296  REAL(rprec), INTENT(in) :: rmax
297  REAL(rprec), INTENT(in) :: zmin
298  REAL(rprec), INTENT(in) :: zmax
299  INTEGER, INTENT(in) :: n_field_periods
300  LOGICAL, INTENT(in) :: lstell_sym
301  REAL(rprec), DIMENSION(:,:,:), INTENT(in) :: a_r
302  REAL(rprec), DIMENSION(:,:,:), INTENT(in) :: a_f
303  REAL(rprec), DIMENSION(:,:,:), INTENT(in) :: a_z
304 
305  LOGICAL, INTENT(in) :: use_con_shell
306  REAL(rprec), DIMENSION(:,:), INTENT(in) :: a_s_r
307  REAL(rprec), DIMENSION(:,:), INTENT(in) :: a_s_f
308  REAL(rprec), DIMENSION(:,:), INTENT(in) :: a_s_z
309  INTEGER, INTENT(in) :: kp_shell
310 
311 ! Declare local variables
312  INTEGER :: ir1, ir2, ir3, if1, if2, if3, iz1, &
313  & iz2, iz3
314  INTEGER :: ier1, ier2, ier3
315  CHARACTER(len=*), PARAMETER :: sub_name = &
316  & 'mddc_mrf_construct: '
317 
318 ! Start of executable code
319 
320 ! Destroy existing arrays
321  CALL mddc_mrf_destroy(this)
322 
323 ! Scalar variables
324  this % code_name = adjustl(code_name)
325  this % code_version = adjustl(code_version)
326  this % date_run = adjustl(date_run)
327  this % field_coils_id = adjustl(field_coils_id)
328  this % kp = kp
329  this % rmin = rmin
330  this % rmax = rmax
331  this % zmin = zmin
332  this % zmax = zmax
333  this % n_field_periods = n_field_periods
334  this % lstell_sym = lstell_sym
335 
336 ! Array Sizes
337  this % n_field_cg = SIZE(rdiag_coilg_1)
338  ir1 = SIZE(a_r,1)
339  ir2 = SIZE(a_r,2)
340  ir3 = SIZE(a_r,3)
341  if1 = SIZE(a_f,1)
342  if2 = SIZE(a_f,2)
343  if3 = SIZE(a_f,3)
344  iz1 = SIZE(a_z,1)
345  iz2 = SIZE(a_z,2)
346  iz3 = SIZE(a_z,3)
347  CALL assert_eq(ir1,if1,iz1,sub_name // 'a_ first dims different')
348  CALL assert_eq(ir2,if2,iz2,sub_name // 'a_ 2nd dims different')
349  CALL assert_eq(ir3,if3,iz3,sub_name // 'a_ 3rd dims different')
350  this % ir = ir1
351  this % jz = ir2
352  this % kp_store = ir3
353  CALL assert_eq(this % n_field_cg,SIZE(extcur_mg), &
354  & sub_name // 'rd - extcur dims different')
355 
356 ! Allocate space for arrays
357  ALLOCATE(this % rdiag_coilg_1(this % n_field_cg),stat=ier1)
358  CALL assert_eq(0,ier1,sub_name // 'alloc rdiag_coilg_1')
359  ALLOCATE(this % extcur_mg(this % n_field_cg),stat=ier1)
360  CALL assert_eq(0,ier1,sub_name // 'alloc extcur_mg')
361 
362  ALLOCATE(this % a_r(ir1,ir2,ir3),stat=ier1)
363  ALLOCATE(this % a_f(ir1,ir2,ir3),stat=ier2)
364  ALLOCATE(this % a_z(ir1,ir2,ir3),stat=ier3)
365  CALL assert_eq(0,ier1,ier2,ier3,sub_name // 'alloc a_')
366 
367  this % use_con_shell = use_con_shell
368  IF (use_con_shell) THEN
369  this % kp_shell = kp_shell
370 
371  ir1 = SIZE(a_s_r,1)
372  ir2 = SIZE(a_s_r,2)
373  if1 = SIZE(a_s_f,1)
374  if2 = SIZE(a_s_f,2)
375  iz1 = SIZE(a_s_z,1)
376  iz2 = SIZE(a_s_z,2)
377  CALL assert_eq(ir1,if1,iz1,sub_name // &
378  & 'a_s_ first dims different')
379  CALL assert_eq(ir2,if2,iz2,sub_name // &
380  & 'a_s_ 2nd dims different')
381 
382  this % n_u = ir1
383  this % kp_shell_store = ir2
384 
385  ALLOCATE(this % a_s_r(ir1,ir2),stat=ier1)
386  ALLOCATE(this % a_s_f(ir1,ir2),stat=ier2)
387  ALLOCATE(this % a_s_z(ir1,ir2),stat=ier3)
388  CALL assert_eq(0,ier1,ier2,sub_name // 'alloc a_s_')
389  END IF
390 
391 
392 ! Move arrays
393  this % rdiag_coilg_1 = rdiag_coilg_1
394  this % extcur_mg = extcur_mg
395  this % a_r = a_r
396  this % a_f = a_f
397  this % a_z = a_z
398 
399  IF (use_con_shell) THEN
400  this%a_s_r = a_s_r
401  this%a_s_f = a_s_f
402  this%a_s_z = a_s_z
403  END IF
404 
405  END SUBROUTINE mddc_mrf_construct
406 
407 !*******************************************************************************
408 ! SECTION V. DESTRUCTION SUBROUTINES
409 !*******************************************************************************
410 !-------------------------------------------------------------------------------
411 ! Destroy a mddc_desc
412 !-------------------------------------------------------------------------------
413  SUBROUTINE mddc_desc_destroy(this)
414  IMPLICIT NONE
415 
416 ! Declare Arguments
417  TYPE (mddc_desc), INTENT(inout) :: this
418 
419 ! Declare local variables
420  CHARACTER(len=*), PARAMETER :: sub_name = &
421  & 'mddc_desc_destroy: '
422 
423 ! Start of executable code
424 
425 ! Destroy scalar components
426  this % s_name = ' '
427  this % l_name = ' '
428  this % units = ' '
429  this % mddc_type = ' '
430  this % sigma_default = zero
431  this % flux_factor = zero
432  this % l_mdcoil_def = .false.
433 
434 ! Destroy Derived Types
435  CALL bsc_destroy(this % mdcoil)
436  CALL mddc_destroy(this % mrf)
437 
438  END SUBROUTINE mddc_desc_destroy
439 
440 !-------------------------------------------------------------------------------
441 ! Destroy a mddc_mrf
442 !-------------------------------------------------------------------------------
443  SUBROUTINE mddc_mrf_destroy(this)
444  IMPLICIT NONE
445 
446 ! Declare Arguments
447  TYPE (mddc_mrf), INTENT(inout) :: this
448 
449 ! Declare local variables
450  CHARACTER(len=*), PARAMETER :: sub_name = &
451  & 'mddc_mrf_destroy: '
452  INTEGER :: ier1
453 
454 ! Start of executable code
455 
456 ! Get rid of all components
457 
458 ! Scalar variables
459  this % code_name = ' '
460  this % code_version = ' '
461  this % date_run = ' '
462  this % field_coils_id = ' '
463  this % kp = 0
464  this % rmin = zero
465  this % rmax = zero
466  this % zmin = zero
467  this % zmax = zero
468  this % n_field_periods = 0
469  this % lstell_sym = .false.
470 
471 ! Array Sizes
472  this % n_field_cg = 0
473  this % ir = 0
474  this % jz = 0
475  this % kp_store = 0
476 
477  this % use_con_shell = .false.
478  this % n_u = 0
479  this % kp_shell = 0
480  this % kp_shell_store = 0
481 
482 ! Deallocate space for arrays
483  IF (ASSOCIATED(this % rdiag_coilg_1)) THEN
484  DEALLOCATE(this % rdiag_coilg_1,stat=ier1)
485  CALL assert_eq(0,ier1,sub_name // 'dealloc rdiag_coilg_1')
486  ENDIF
487  IF (ASSOCIATED(this % extcur_mg)) THEN
488  DEALLOCATE(this % extcur_mg,stat=ier1)
489  CALL assert_eq(0,ier1,sub_name // 'dealloc extcur_mg')
490  ENDIF
491  IF (ASSOCIATED(this % a_r)) THEN
492  DEALLOCATE(this % a_r,stat=ier1)
493  CALL assert_eq(0,ier1,sub_name // 'dealloc a_r')
494  ENDIF
495  IF (ASSOCIATED(this % a_f)) THEN
496  DEALLOCATE(this % a_f,stat=ier1)
497  CALL assert_eq(0,ier1,sub_name // 'dealloc a_f')
498  ENDIF
499  IF (ASSOCIATED(this % a_z)) THEN
500  DEALLOCATE(this % a_z,stat=ier1)
501  CALL assert_eq(0,ier1,sub_name // 'dealloc a_z')
502  ENDIF
503  IF (ASSOCIATED(this % a_s_r)) THEN
504  DEALLOCATE(this % a_s_r,stat=ier1)
505  CALL assert_eq(0,ier1,sub_name // 'dealloc a_s_r')
506  ENDIF
507  IF (ASSOCIATED(this % a_s_f)) THEN
508  DEALLOCATE(this % a_s_f,stat=ier1)
509  CALL assert_eq(0,ier1,sub_name // 'dealloc a_s_f')
510  ENDIF
511  IF (ASSOCIATED(this % a_s_z)) THEN
512  DEALLOCATE(this % a_s_z,stat=ier1)
513  CALL assert_eq(0,ier1,sub_name // 'dealloc a_s_z')
514  ENDIF
515 
516  END SUBROUTINE mddc_mrf_destroy
517 
518 !*******************************************************************************
519 ! SECTION VI. ASSIGNMENT SUBROUTINES
520 !*******************************************************************************
521 !-------------------------------------------------------------------------------
522 ! Assignment for mddc_desc
523 !-------------------------------------------------------------------------------
524  SUBROUTINE mddc_desc_assign(left,right)
525 
526 ! 12-11-04. Can't get by with intrinsic assignment, because intrinsic
527 ! assignment for the mdcoil component would give incorrect results.
528 
529  IMPLICIT NONE
530 
531 ! Declare Arguments
532  TYPE (mddc_desc), INTENT (inout) :: left
533  TYPE (mddc_desc), INTENT (in) :: right
534 
535 ! Declare local variables
536  CHARACTER(len=*), PARAMETER :: sub_name = &
537  & 'mddc_desc_assign: '
538 
539 ! Start of executable code
540  left % s_name = right % s_name
541  left % l_name = right % l_name
542  left % units = right % units
543  left % mddc_type = right % mddc_type
544  left % l_mdcoil_def = right % l_mdcoil_def
545  left % sigma_default = right % sigma_default
546  left % flux_factor = right % flux_factor
547  left % mdcoil = right % mdcoil
548  left % mrf = right % mrf
549 
550  END SUBROUTINE mddc_desc_assign
551 
552 !-------------------------------------------------------------------------------
553 ! Assignment for mddc_mrf
554 !-------------------------------------------------------------------------------
555  SUBROUTINE mddc_mrf_assign(left,right)
556  IMPLICIT NONE
557 
558 ! Declare Arguments
559  TYPE (mddc_mrf), INTENT (inout) :: left
560  TYPE (mddc_mrf), INTENT (in) :: right
561 
562 ! Declare local variables
563  CHARACTER(len=*), PARAMETER :: sub_name = &
564  & 'mddc_mrf_assign: '
565  CHARACTER (len=*), PARAMETER :: err_mess1 = &
566  & 'left-right pointers are the same?. FIX IT'
567  INTEGER :: ier1, ier2, ier3
568  LOGICAL, DIMENSION(5) :: lassert
569 
570 ! Start of executable code
571 
572 ! Check to see if the 'use as allocatable array' pointers are pointing
573 ! to the same location
574  lassert(1) = .not.ASSOCIATED(left % a_r,right % a_r)
575  lassert(2) = .not.ASSOCIATED(left % a_f,right % a_f)
576  lassert(3) = .not.ASSOCIATED(left % a_z,right % a_z)
577  lassert(4) = .not.ASSOCIATED(left % rdiag_coilg_1, &
578  & right % rdiag_coilg_1)
579  lassert(5) = .not.ASSOCIATED(left % extcur_mg,right % extcur_mg)
580  CALL assert(lassert,sub_name // err_mess1)
581 
582 ! Destroy left
583  CALL mddc_mrf_destroy(left)
584 
585 ! Scalar variables
586  left % code_name = right % code_name
587  left % code_version = right % code_version
588  left % date_run = right % date_run
589  left % field_coils_id = right % field_coils_id
590  left % kp = right % kp
591  left % rmin = right % rmin
592  left % rmax = right % rmax
593  left % zmin = right % zmin
594  left % zmax = right % zmax
595  left % n_field_periods = right % n_field_periods
596  left % lstell_sym = right % lstell_sym
597  left % n_field_cg = right % n_field_cg
598  left % ir = right % ir
599  left % jz = right % jz
600  left % kp_store = right % kp_store
601 
602  left % use_con_shell = right % use_con_shell
603  left % n_u = right % n_u
604  left % kp_shell = right % kp_shell
605  left % kp_shell_store = right % kp_shell_store
606 
607 ! Allocate space for arrays (Were deallocated in _destroy)
608  ALLOCATE(left % rdiag_coilg_1(left % n_field_cg),stat=ier1)
609  CALL assert_eq(0,ier1,sub_name // 'alloc rdiag_coilg_1')
610  ALLOCATE(left % extcur_mg(left % n_field_cg),stat=ier1)
611  CALL assert_eq(0,ier1,sub_name // 'alloc extcur_mg')
612 
613  ALLOCATE(left % a_r(left % ir,left % jz,left % kp_store), &
614  & stat=ier1)
615  ALLOCATE(left % a_f(left % ir,left % jz,left % kp_store), &
616  & stat=ier2)
617  ALLOCATE(left % a_z(left % ir,left % jz,left % kp_store), &
618  & stat=ier3)
619  CALL assert_eq(0,ier1,ier2,ier3,sub_name // 'alloc a_')
620 
621  IF (left % use_con_shell) THEN
622  ALLOCATE(left % a_s_r(left % n_u,left % kp_shell_store), &
623  & stat=ier1)
624  ALLOCATE(left % a_s_f(left % n_u,left % kp_shell_store), &
625  & stat=ier2)
626  ALLOCATE(left % a_s_z(left % n_u,left % kp_shell_store), &
627  & stat=ier3)
628  CALL assert_eq(0,ier1,ier2,ier3,sub_name // 'alloc a_s_')
629  END IF
630 
631 ! Move arrays
632 ! JDH 2010-07-20. IF statements to avoid segmentation fault with
633 ! gfortran compiler.
634  IF ( ASSOCIATED(right % rdiag_coilg_1)) THEN
635  left % rdiag_coilg_1 = right % rdiag_coilg_1
636  ENDIF
637  IF ( ASSOCIATED(right % extcur_mg)) THEN
638  left % extcur_mg = right % extcur_mg
639  ENDIF
640  IF ( ASSOCIATED(right % a_r)) THEN
641  left % a_r = right % a_r
642  ENDIF
643  IF ( ASSOCIATED(right % a_f)) THEN
644  left % a_f = right % a_f
645  ENDIF
646  IF ( ASSOCIATED(right % a_z)) THEN
647  left % a_z = right % a_z
648  ENDIF
649 
650  IF (left % use_con_shell) THEN
651  IF ( ASSOCIATED(right % a_s_r)) THEN
652  left % a_s_r = right % a_s_r
653  ENDIF
654  IF ( ASSOCIATED(right % a_s_f)) THEN
655  left % a_s_f = right % a_s_f
656  ENDIF
657  IF ( ASSOCIATED(right % a_s_z)) THEN
658  left % a_s_z = right % a_s_z
659  ENDIF
660  ENDIF
661 
662  END SUBROUTINE mddc_mrf_assign
663 
664 !*******************************************************************************
665 ! SECTION VII. OUTPUT SUBROUTINES
666 !*******************************************************************************
667 !-------------------------------------------------------------------------------
668 ! Write out the contents of a mddc_desc
669 !-------------------------------------------------------------------------------
670 
671  SUBROUTINE mddc_desc_write(this,identifier,unit,verbose)
672  IMPLICIT NONE
673 
674 ! Declare Arguments
675  TYPE (mddc_desc), INTENT (in) :: this
676  CHARACTER (len=*), INTENT(in), OPTIONAL :: identifier
677  INTEGER, INTENT(in), OPTIONAL :: unit
678  INTEGER, INTENT(in), OPTIONAL :: verbose
679 ! identifier character variable, also written out
680 ! unit I/O unit number to write to
681 ! verbose integer, to specify verbosity level of write
682 
683 ! Declare local variables and constants
684  INTEGER :: iv_default = 1
685  integer :: iv
686  INTEGER :: iou_default = 6
687  integer :: iou
688  CHARACTER (len=60) :: id
689 
690 ! Declare Format array
691  CHARACTER(len=*), PARAMETER, DIMENSION(10) :: fmt1 = (/ &
692  & '(" start mddc_desc write, called with id = ",a) ', &
693  & '(" s_name = ",a) ', &
694  & '(" l_name = ",a) ', &
695  & '(" units = ",a) ', &
696  & '(" l_mdcoil_def = ",L1) ', &
697  & '(" mddc_type = ",a) ', &
698  & '(" bsc_coil s_name = ",a) ', &
699  & '(" flux_factor = ",es12.5) ', &
700  & '(" sigma_default = ",es12.5) ', &
701  & '(" end mddc_desc write, called with id = ",a) ' &
702  & /)
703 
704 ! start of executable code
705 ! Check for arguments present
706  IF (PRESENT(identifier)) THEN
707  id = identifier
708  ELSE
709  id = ' '
710  END IF
711 
712  IF (PRESENT(unit)) THEN
713  iou = unit
714  ELSE
715  iou = iou_default
716  END IF
717 
718  IF (PRESENT(verbose)) THEN
719  iv = verbose
720  ELSE
721  iv = iv_default
722  END IF
723 
724 ! Select Case of Verbosity Level
725  SELECT CASE(iv)
726  CASE( :0) ! VERY Terse
727  WRITE(iou,*) this % s_name
728  WRITE(iou,*) this % l_name
729  WRITE(iou,*) this % units
730  WRITE(iou,*) this % l_mdcoil_def
731  WRITE(iou,*) this % mddc_type
732  WRITE(iou,*) this % mdcoil % s_name
733  WRITE(iou,*) this % flux_factor
734  WRITE(iou,*) this % sigma_default
735 
736  CASE(1:) ! Default, more verbose
737  WRITE(iou,fmt1(1)) id
738  WRITE(iou,fmt1(2)) this % s_name
739  WRITE(iou,fmt1(3)) this % l_name
740  WRITE(iou,fmt1(4)) this % units
741  WRITE(iou,fmt1(5)) this % l_mdcoil_def
742  WRITE(iou,fmt1(6)) this % mddc_type
743  WRITE(iou,fmt1(7)) this % mdcoil % s_name
744  WRITE(iou,fmt1(8)) this % flux_factor
745  WRITE(iou,fmt1(9)) this % sigma_default
746  WRITE(iou,fmt1(10)) id
747 
748  END SELECT
749 
750  END SUBROUTINE mddc_desc_write
751 
752 !-------------------------------------------------------------------------------
753 ! Write out the contents of a mddc_mrf
754 !-------------------------------------------------------------------------------
755 !
756  SUBROUTINE mddc_mrf_write(this,identifier,unit,verbose)
757  IMPLICIT NONE
758 
759 ! Declare Arguments
760  TYPE (mddc_mrf), INTENT (in) :: this
761  CHARACTER (len=*), INTENT(in), OPTIONAL :: identifier
762  INTEGER, INTENT(in), OPTIONAL :: unit
763  INTEGER, INTENT(in), OPTIONAL :: verbose
764 ! identifier character variable, also written out
765 ! unit I/O unit number to write to
766 ! verbose integer, to specify verbosity level of write
767 
768 ! Declare local variables and constants
769  INTEGER :: iv_default = 1
770  integer :: iv
771  INTEGER :: iou_default = 6
772  integer :: iou
773  CHARACTER (len=60) :: id
774  INTEGER :: i, n_data
775  INTEGER :: i1, i2, i3, i4, i5
776 
777 ! Declare Format array
778  CHARACTER(len=*), PARAMETER, DIMENSION(25) :: fmt1 = (/ &
779  & '(" start mddc_mrf write, called with id = ",a) ', &
780  & '(" code_name = ",a) ', &
781  & '(" code_version = ",a) ', &
782  & '(" date_run = ",a) ', &
783  & '(" field_coils_id = ",a) ', &
784  & '(" number of field-coil groups (n_field_cg) = ",i4) ', &
785  & '(" index rdiag_coilg_1: ",/,(1x,i4,3x,es12.5)) ', &
786  & '(" index extcur_mg: ",/,(1x,i4,3x,es12.5)) ', &
787  & '(" number of grid points in R (ir) = ",i4) ', &
788  & '(" number of grid points in z (jz) = ",i4) ', &
789  & '(" number of grid points in phi (kp) = ",i4) ', &
790  & '(" number of g. p. in phi stored (kp_store) = ",i4) ', &
791  & '(" minimum R in grid (rmin) = ",es12.5) ', &
792  & '(" maximum R in grid (rmax) = ",es12.5) ', &
793  & '(" minimum Z in grid (zmin) = ",es12.5) ', &
794  & '(" maximum Z in grid (zmax) = ",es12.5) ', &
795  & '(" number of field periods (n_field_periods) = ",i4) ', &
796  & '(" Stellarator symmetry logical (lstell_sym) = ",l1) ', &
797  & '(" Three indices for a_ are ",i4,2x,i4,2x,i4) ', &
798  & '(" a_r, a_f, a_z = ",3(3x,es12.5)) ', &
799  & '(" Two indices for a_s_ are ",i4,2x,i4) ', &
800  & '(" a_s_r, a_s_f, a_s_z = ",3(3x,es12.5)) ', &
801  & '(" end mddc_mrf write, called with id = ",a) ', &
802  & '(" number of s grid points in phi ",i4) ', &
803  & '(" number of s g. p. in phi stored ",i4) ' &
804  & /)
805 
806 ! start of executable code
807 ! Check for arguments present
808  IF (PRESENT(identifier)) THEN
809  id = identifier
810  ELSE
811  id = ' '
812  END IF
813 
814  IF (PRESENT(unit)) THEN
815  iou = unit
816  ELSE
817  iou = iou_default
818  END IF
819 
820  IF (PRESENT(verbose)) THEN
821  iv = verbose
822  ELSE
823  iv = iv_default
824  END IF
825 
826 ! Index values for single array value print out
827  i1 = this % ir / 2
828  i2 = this % jz / 2
829  i3 = this % kp_store / 2
830  i4 = this % n_u / 2
831  i5 = this % kp_shell_store / 2
832 
833 ! Select Case of Verbosity Level
834  SELECT CASE(iv)
835  CASE( :0) ! VERY Terse
836  WRITE(iou,*) this % code_name
837  WRITE(iou,*) this % code_version
838  WRITE(iou,*) this % date_run
839  WRITE(iou,*) this % field_coils_id
840  WRITE(iou,*) this % n_field_cg
841  WRITE(iou,*) (i,this % rdiag_coilg_1(i),i=1,this % n_field_cg)
842  WRITE(iou,*) (i,this % extcur_mg(i),i=1,this % n_field_cg)
843  WRITE(iou,*) this % ir
844  WRITE(iou,*) this % jz
845  WRITE(iou,*) this % kp
846  WRITE(iou,*) this % kp_store
847  WRITE(iou,*) this % rmin
848  WRITE(iou,*) this % rmax
849  WRITE(iou,*) this % zmin
850  WRITE(iou,*) this % zmax
851  WRITE(iou,*) this % n_field_periods
852  WRITE(iou,*) this % lstell_sym
853  WRITE(iou,*) i1, i2, i3
854  WRITE(iou,*) this % a_r(i1,i2,i3), this % a_f(i1,i2,i3), &
855  & this % a_z(i1,i2,i3)
856  WRITE(iou,*) this % use_con_shell
857  WRITE(iou,*) i4, i3
858  IF (this % use_con_shell) THEN
859  WRITE(iou,*) this % kp_shell
860  WRITE(iou,*) this % kp_shell_store
861  WRITE(iou,*) this % a_s_r(i4,i5), this % a_s_f(i4,i5), &
862  & this % a_s_z(i4,i5)
863  END IF
864 
865  CASE(1:) ! Default, more verbose
866  WRITE(iou,fmt1(1)) id
867  WRITE(iou,fmt1(2)) this % code_name
868  WRITE(iou,fmt1(3)) this % code_version
869  WRITE(iou,fmt1(4)) this % date_run
870  WRITE(iou,fmt1(5)) this % field_coils_id
871  WRITE(iou,fmt1(6)) this % n_field_cg
872  WRITE(iou,fmt1(7)) (i,this % rdiag_coilg_1(i), &
873  & i=1,this % n_field_cg)
874  WRITE(iou,fmt1(8)) (i,this % extcur_mg(i), &
875  & i=1,this % n_field_cg)
876  WRITE(iou,fmt1(9)) this % ir
877  WRITE(iou,fmt1(10)) this % jz
878  WRITE(iou,fmt1(11)) this % kp
879  WRITE(iou,fmt1(12)) this % kp_store
880  WRITE(iou,fmt1(13)) this % rmin
881  WRITE(iou,fmt1(14)) this % rmax
882  WRITE(iou,fmt1(15)) this % zmin
883  WRITE(iou,fmt1(16)) this % zmax
884  WRITE(iou,fmt1(17)) this % n_field_periods
885  WRITE(iou,fmt1(18)) this % lstell_sym
886  WRITE(iou,fmt1(19)) i1, i2, i3
887  WRITE(iou,fmt1(20)) this % a_r(i1,i2,i3), this % a_f(i1,i2,i3), &
888  & this % a_z(i1,i2,i3)
889  WRITE(iou,fmt1(21)) i4, i3
890  IF (this % use_con_shell) THEN
891  WRITE(iou,fmt1(24)) this % kp_shell
892  WRITE(iou,fmt1(25)) this % kp_shell_store
893  WRITE(iou,fmt1(22)) this % a_s_r(i4,i5), &
894  & this % a_s_f(i4,i5), &
895  & this % a_s_z(i4,i5)
896  END IF
897  WRITE(iou,fmt1(23)) id
898 
899  END SELECT
900 
901  END SUBROUTINE mddc_mrf_write
902 
903 !*******************************************************************************
904 ! SECTION XVI. COMMENTS FOR DIFFERENT REVISIONS
905 !*******************************************************************************
906 !
907 ! JDH 2007-06-11. First version of mddc_T. Copied and edited from diagnostic_T
908 !
909 !
910 !-------------------------------- (diagnostic_T comments below) ----------------
911 ! JDH 07-16-04. Modifying bsc.f to get diagnostic_mod.f
912 ! JDH 08-11-04. More modifications. File diagnostic_T.f
913 !
914 ! JDH 08-16-2004
915 ! Add comments for collection, _ptr
916 ! Think about n_data, and where it belongs
917 ! JDH 08-19-2004
918 ! Eliminated n_data as a component
919 ! JDH 08-23-2004
920 ! Cleaned up sigma logic a bit.
921 ! JDH 09-10-2004
922 ! Added mddc_type component
923 ! JDH 12-11-2004
924 ! Removed 'pointer' attribute from mdcoil component of diagnostic_desc.
925 ! Added l_mdcoil_def component to diagnostic_desc. Added subroutine
926 ! diagnostic_desc_assign.
927 !
928 ! JDH 2008-01-19 - Added => null() to pointer declarations
929 !
930 ! JDH 2008-01-21
931 ! SPH Jan 2008 eliminated iprec. Completed elimination.
932 ! Initialized STAT variables in mddc_data_destroy
933 !
934 ! JDH 2009-06-15
935 ! Eliminated mddc_data derived type - not needed.
936 !
937 ! JDH 2010-07-20
938 ! Added IF test for association in mddc_mrf_assign, to avoid
939 ! segmentation fault with gfortran compiler. Thanks to J Geiger.
940 
941 
942  END MODULE mddc_t
bsc_t::bsc_destroy
Definition: bsc_T.f:189
v3_utilities::assert_eq
Definition: v3_utilities.f:62
mddc_t::mddc_write
Definition: mddc_T.f:206
v3_utilities::assert
Definition: v3_utilities.f:55
mddc_t::mddc_mrf
Definition: mddc_T.f:118
mddc_t::mddc_construct
Definition: mddc_T.f:190
mddc_t::mddc_destroy
Definition: mddc_T.f:198
mddc_t::mddc_desc
Definition: mddc_T.f:164