V3FIT
bmw.f
Go to the documentation of this file.
1 !*******************************************************************************
5 !
6 ! Note separating the Doxygen comment block here so detailed decription is
7 ! found in the Module not the file.
8 !
26 !*******************************************************************************
27 !*******************************************************************************
28 ! MAIN PROGRAM
29 !*******************************************************************************
30 !-------------------------------------------------------------------------------
35 !-------------------------------------------------------------------------------
36  PROGRAM bmw
37  USE bmw_context
39  use, INTRINSIC :: iso_fortran_env, only : output_unit
40  USE bmw_state_flags
41  USE safe_open_mod
42 
43  IMPLICIT NONE
44 
45 ! local variables
46  TYPE (bmw_parallel_context_class), POINTER :: parallel => null()
47  TYPE (bmw_context_class), POINTER :: context => null()
48  TYPE (bmw_commandline_parser_class), POINTER :: &
49  & cl_parser => null()
50  INTEGER :: flags
51  INTEGER :: num_p
52  INTEGER :: io_unit
53  INTEGER :: status
54  REAL (rprec) :: start_time
55 
56 ! Start of executable code
57 #if defined (mpi_opt)
58  CALL mpi_init(status)
59 #endif
60  CALL profiler_construct
61 
62  start_time = profiler_get_start_time()
63 
64  parallel => bmw_parallel_context_construct( &
65 #if defined (MPI_OPT)
66  & mpi_comm_world &
67 #endif
68  & )
69 
70  cl_parser => bmw_commandline_parser_construct(parallel)
71 
72 ! Check if the required flags are set.
73  IF (.not.bmw_commandline_parser_is_flag_set(cl_parser, &
74  & '-mgridf')) THEN
75  WRITE (*,1001) '-mgridf'
77  END IF
78  IF (.not.bmw_commandline_parser_is_flag_set(cl_parser, &
79  & '-woutf')) THEN
80  WRITE (*,1001) '-woutf'
82  END IF
83  IF (.not.bmw_commandline_parser_is_flag_set(cl_parser, &
84  & '-outf')) THEN
85  WRITE (*,1001) '-outf'
87  END IF
88 
89  CALL bmw_parallel_context_set_threads(parallel, &
90  & bmw_commandline_parser_get_integer(cl_parser, '-para', 1))
91 
92  flags = bmw_state_flags_off
93  IF (bmw_commandline_parser_is_flag_set(cl_parser, '-force')) THEN
94  flags = ibset(flags, bmw_state_flags_force)
95  END IF
96  IF (bmw_commandline_parser_is_flag_set(cl_parser, '-ju')) THEN
97  flags = ibset(flags, bmw_state_flags_ju)
98  END IF
99  IF (bmw_commandline_parser_is_flag_set(cl_parser, '-jv')) THEN
100  flags = ibset(flags, bmw_state_flags_jv)
101  flags = ibclr(flags, bmw_state_flags_ju)
102  END IF
103  IF (bmw_commandline_parser_is_flag_set(cl_parser, &
104  & '-siestaf')) THEN
105  flags = ibset(flags, bmw_state_flags_siesta)
106  flags = ibclr(flags, bmw_state_flags_ju)
107  flags = ibclr(flags, bmw_state_flags_jv)
108  END IF
109 
110  flags = ibset(flags, bmw_state_flags_mgrid)
111  num_p = 0
112 
113  io_unit = output_unit
114  IF (bmw_commandline_parser_is_flag_set(cl_parser, '-logf')) THEN
115  CALL safe_open(io_unit, status, &
116  & bmw_commandline_parser_get_string(cl_parser, '-logf'), &
117  & 'replace', 'formatted', delim_in='none')
118  END IF
119 
120  IF (parallel%offset .eq. 0) THEN
121  WRITE (io_unit,*)
122  WRITE (io_unit,1000) series
123  WRITE (io_unit,*)
124  END IF
125  CALL bmw_parallel_context_report(parallel, io_unit)
126 
127  context => bmw_context_construct( &
128  & bmw_commandline_parser_get_string(cl_parser, '-mgridf'), &
129  & bmw_commandline_parser_get_string(cl_parser, '-woutf'), &
130  & bmw_commandline_parser_get_string(cl_parser, '-siestaf'), &
131  & flags, num_p, parallel, io_unit)
132  CALL bmw_context_set_up_grid(context, &
133  & bmw_commandline_parser_get_integer(cl_parser, '-p_start', -1), &
134  & bmw_commandline_parser_get_integer(cl_parser, '-p_end', -1), &
135  & parallel, io_unit)
136  CALL bmw_context_write(context, &
137  & bmw_commandline_parser_get_string(cl_parser, '-outf'), &
138  & parallel)
139 
140  CALL bmw_context_destruct(context)
141  CALL bmw_commandline_parser_destruct(cl_parser)
142 
143  CALL profiler_set_stop_time('bmw_main', start_time)
144  IF (parallel%offset .eq. 0) THEN
145  CALL profiler_write(io_unit)
146  END IF
147  CALL profiler_destruct
148 
149  CLOSE(io_unit)
150 
151  CALL bmw_parallel_context_destruct(parallel &
152 #if defined (MPI_OPT)
153  & ,.true. &
154 #endif
155  & )
156 
157 1000 FORMAT('BMW ',i4,' Series.')
158 1001 FORMAT('Required flag ',a,' not set.')
159 
160  END PROGRAM
bmw_commandline_parser::bmw_commandline_parser_construct
type(bmw_commandline_parser_class) function, pointer bmw_commandline_parser_construct(parallel)
Construct a bmw_commandline_parser_class object.
Definition: bmw_commandline_parser.f:118
bmw_context::bmw_context_write
subroutine bmw_context_write(this, result_file_name, parallel)
Write NetCDF based result file.
Definition: bmw_context.f:319
bmw_state_flags::bmw_state_flags_jv
integer, parameter bmw_state_flags_jv
Bit position for the use curl jv response flag.
Definition: bmw_state_flags.f:33
bmw_context::bmw_context_destruct
subroutine bmw_context_destruct(this)
Deconstruct a bmw_context_class object.
Definition: bmw_context.f:140
bmw_state_flags
Contains parameters defining the bit positions for flags that mark different options.
Definition: bmw_state_flags.f:11
bmw_context::series
integer, parameter series
Version number.
Definition: bmw_context.f:23
bmw_commandline_parser::bmw_commandline_parser_get_string
character(len=path_length) function bmw_commandline_parser_get_string(this, arg)
Get the value of an argument as a string.
Definition: bmw_commandline_parser.f:234
bmw
program bmw
BMW is a code for extending fields belond the VMEC domain in a manner that ensures divergence free fi...
Definition: bmw.f:36
bmw_commandline_parser::bmw_commandline_parser_is_flag_set
logical function bmw_commandline_parser_is_flag_set(this, arg)
Check if a command line argument was set.
Definition: bmw_commandline_parser.f:393
bmw_commandline_parser
Defines the base class of the type bmw_commandline_parser_class.
Definition: bmw_commandline_parser.f:57
bmw_state_flags::bmw_state_flags_force
integer, parameter bmw_state_flags_force
Bit position for force override of errors flag.
Definition: bmw_state_flags.f:29
bmw_commandline_parser::bmw_commandline_parser_destruct
subroutine bmw_commandline_parser_destruct(this)
Deconstruct a bmw_commandline_parser_class object.
Definition: bmw_commandline_parser.f:198
bmw_commandline_parser::bmw_commandline_parser_class
Base class containing a parsed bmw_commandline.
Definition: bmw_commandline_parser.f:89
bmw_state_flags::bmw_state_flags_off
integer, parameter bmw_state_flags_off
Clear all flags.
Definition: bmw_state_flags.f:26
bmw_state_flags::bmw_state_flags_ju
integer, parameter bmw_state_flags_ju
Bit position for the use curl ju response flag.
Definition: bmw_state_flags.f:31
bmw_context
Defines the base class of the type bmw_context_class. This contains the state variables needed by BMW...
Definition: bmw_context.f:11
bmw_context::bmw_context_class
Base class representing a bmw context. This contains all memory needed to operate bmw.
Definition: bmw_context.f:34
bmw_state_flags::bmw_state_flags_mgrid
integer, parameter bmw_state_flags_mgrid
Bit position for mgrid specified number of phi planes.
Definition: bmw_state_flags.f:37
bmw_context::bmw_context_construct
type(bmw_context_class) function, pointer bmw_context_construct(mgrid_file_name, wout_file_name, siesta_file_name, flags, num_p, parallel, io_unit)
Construct a bmw_context_class object.
Definition: bmw_context.f:72
bmw_commandline_parser::bmw_commandline_parser_print_help
subroutine bmw_commandline_parser_print_help
Print out help text.
Definition: bmw_commandline_parser.f:492
bmw_commandline_parser::bmw_commandline_parser_get_integer
integer function bmw_commandline_parser_get_integer(this, arg, default_value)
Get the value of an argument as an integer.
Definition: bmw_commandline_parser.f:285
bmw_state_flags::bmw_state_flags_siesta
integer, parameter bmw_state_flags_siesta
Bit position for the use siesta instead of vmec.
Definition: bmw_state_flags.f:35
bmw_context::bmw_context_set_up_grid
Interface to set the unprimed grid.
Definition: bmw_context.f:46