6 USE vparams,
ONLY: nlog, nlog0, nthreed
7 USE vmec_params,
ONLY: more_iter_flag,
9 & restart_flag, readin_flag, timestep_flag,
10 & output_flag, cleanup_flag,
11 & norm_term_flag, successful_term_flag
12 USE parallel_include_module
13 USE parallel_vmec_module,
ONLY: myenvvariables,
20 INTEGER,
PARAMETER :: nseq0 = 12
21 CHARACTER(LEN=*),
PARAMETER ::
22 & increase_niter =
"Try increasing NITER",
23 & bad_jacobian =
"The jacobian was non-definite!",
24 & full_3d1output_request =
"Full threed1-output request!"
28 INTEGER :: numargs, ierr_vmec, index_end,
29 & iopen, isnml, iread, iseq, index_seq,
30 & index_dat, iunit, ncount, nsteps, i
32 CHARACTER(LEN=120) :: input_file, seq_ext, reset_file_name, arg
33 CHARACTER(LEN=120) :: log_file
34 CHARACTER(LEN=120),
DIMENSION(10) :: command_arg
39 REAL(dp) :: totalton, totaltoff
141 SUBROUTINE runvmec(ictrl_array, input_file0,
142 & lscreen, RVC_COMM, reset_file_name)
144 INTEGER,
INTENT(inout),
TARGET :: ictrl_array(5)
145 LOGICAL,
INTENT(in) :: lscreen
146 CHARACTER(LEN=*),
INTENT(in) :: input_file0
147 INTEGER,
INTENT(in),
OPTIONAL :: RVC_COMM
148 CHARACTER(LEN=*),
OPTIONAL :: reset_file_name
149 END SUBROUTINE runvmec
153 CALL initializeparallel
154 CALL mpi_comm_dup(mpi_comm_world,rvc_comm,mpi_err)
155 CALL second0(totalton)
158 CALL getcarg(1, command_arg(1), numargs)
160 CALL getcarg(iseq, command_arg(iseq), numargs)
164 get_args_time = get_args_time + (toff -ton)
167 IF(grank.EQ.0) lscreen = .true.
168 reset_file_name =
" "
170 IF (numargs .lt. 1)
THEN
171 stop
'Invalid command line'
172 ELSE IF (command_arg(1).eq.
'-h' .or. command_arg(1).eq.
'/h')
THEN
174 &
' ENTER INPUT FILE NAME OR INPUT-FILE SUFFIX ON COMMAND LINE'
176 print *,
' For example: '
177 print *,
' xvmec input.tftr OR xvmec tftr ',
178 &
'OR xvmec ../input.tftr'
180 print *,
' Sequence files, containing a list of input files',
181 &
' are also allowed. For example: '
182 print *,
' xvmec input.tftr_runs'
184 print *,
' Here, input.tftr_runs contains a &VSEQ namelist',
187 print *,
' Additional (optional) command arguments are',
190 print *,
' xvmec <filename> [noscreen] [reset=reset_wout_file]'
192 print *,
' noscreen: supresses all output to screen ',
193 &
' (default, or "screen", displays output)'
194 print *,
' name of reset wout file (defaults to none)'
198 DO iseq = 2, min(numargs,10)
199 arg = command_arg(iseq)
200 IF (trim(arg) .eq.
'noscreen' .or.
201 & trim(arg) .eq.
'NOSCREEN')
THEN
204 index_end = index(arg,
"reset=")
205 index_seq = max(index(arg,
"RESET="), index_end)
206 IF (index_seq .gt. 0) reset_file_name = arg(index_seq+6:)
224 index_dat = index(arg,
'.')
225 index_end = len_trim(arg)
226 IF (index_dat .gt. 0)
THEN
227 seq_ext = arg(index_dat + 1:index_end)
228 input_file = trim(arg)
231 input_file =
'input.'//trim(seq_ext)
236 extension(1) = input_file
244 IF (iseq .EQ. 1)
THEN
250 CALL safe_open(iunit, iopen, trim(arg),
'old',
'formatted')
252 safe_open_time = safe_open_time + (toff - ton)
253 IF (iopen .eq. 0)
THEN
254 DO ncount = 1, nseqmax
255 nseq_select(ncount) = ncount
259 CALL read_namelist (iunit, isnml,
'vseq')
262 read_namelist_time = read_namelist_time + (toff - ton)
266 IF (isnml .eq. 0)
THEN
267 IF (nseq .gt. nseqmax) stop
'NSEQ>NSEQMAX'
268 log_file =
'log.'//seq_ext
271 CALL safe_open(nlog, iread, log_file,
'replace',
275 safe_open_time = safe_open_time + (toff - ton)
277 IF (iread .NE. 0)
THEN
279 &
' LOG FILE IS INACCESSIBLE: IOSTAT= ',iread
305 seq:
DO iseq = 1, nseq
306 index_seq = nseq_select(iseq)
307 ictrl(1) = restart_flag + readin_flag + timestep_flag
308 & + output_flag + cleanup_flag
314 IF (iseq .GT. 1)
THEN
317 &
'wout_' // trim(extension(index_seq-1)) //
".nc"
319 &
'wout.' // trim(extension(index_seq-1))
320 WRITE (*,*)
'WARNING: Text based wout files are no ' \\
321 &
'longer maintained and may be removed in ' \\
332 CALL runvmec(ictrl, extension(index_seq), lscreen, rvc_comm,
337 SELECT CASE (ierr_vmec)
338 CASE (more_iter_flag)
339 IF (grank .EQ. 0)
THEN
340 IF(lscreen)
WRITE (6,
'(1x,a)') increase_niter
341 WRITE (nthreed,
'(1x,a)') increase_niter
342 WRITE (nthreed,
'(1x,a)')
"PARVMEC aborting..."
349 DO i = 2, max_main_iterations
350 ictrl(1) = timestep_flag
353 CALL runvmec(ictrl, extension(1), lscreen,
354 & rvc_comm, reset_file_name)
355 IF (ictrl(2) .EQ. more_iter_flag .and.
357 WRITE (nthreed,
'(1x,a)') increase_niter
358 IF(lscreen)
WRITE (6,
'(1x,a)') increase_niter
361 ictrl(1) = output_flag + cleanup_flag
362 IF (ictrl(2) .ne. successful_term_flag)
THEN
363 ictrl(2)=successful_term_flag
367 CALL runvmec(ictrl, extension(1), lscreen, rvc_comm,
371 CALL mpi_barrier(rvc_comm, mpi_err)
374 ictrl(1) = output_flag + cleanup_flag
376 IF (lfull3d1out)
THEN
377 ictrl(2) = successful_term_flag
378 IF (grank .EQ. 0)
THEN
379 WRITE(6,
'(1x,a)') full_3d1output_request
380 WRITE(nthreed,
'(1x,a)') full_3d1output_request
386 CALL runvmec(ictrl, extension(1), lscreen, rvc_comm,
391 CASE (bad_jacobian_flag)
392 IF (grank .EQ. 0)
THEN
393 IF (lscreen)
WRITE (6,
'(/,1x,a)') bad_jacobian
394 WRITE (nthreed,
'(/,1x,a)') bad_jacobian
407 ictrl(1) = restart_flag + readin_flag
411 CALL runvmec(ictrl, extension(1), lscreen, rvc_comm,
414 ictrl(1) = timestep_flag + output_flag
415 ictrl(1) = timestep_flag
419 DO ncount = 1, max(1,niter/nsteps)
421 CALL runvmec(ictrl, extension(1), lscreen, rvc_comm,
423 print *,
' BREAK HERE'
425 IF (ierr_vmec .ne. more_iter_flag)
EXIT
429 ictrl(1) = output_flag+cleanup_flag
431 CALL runvmec(ictrl, extension(1), lscreen, rvc_comm,
438 CALL second0(totaltoff)
439 total_time = total_time + (totaltoff - totalton)
441 IF (.NOT.lv3fitcall .AND. lactive)
CALL writetimes(
'timings.txt')
442 CALL finalizeparallel