@@ -364,25 +364,35 @@ subroutine populate_param_data(iounit, filename, param_data)
364
364
365
365
! Local variables
366
366
character (len= INPUT_STR_LENGTH) :: line
367
- character (len= INPUT_STR_LENGTH), allocatable , dimension (:) :: lines_in
368
- integer :: n, num_lines
367
+ character (len= 1 ), allocatable , dimension (:) :: char_buf
368
+ integer , allocatable , dimension (:) :: line_len ! The trimmed length of each processed input line
369
+ integer :: n, num_lines, total_chars, ch, rsc, llen, int_buf(2 )
369
370
logical :: inMultiLineComment
370
371
372
+ character (len= 80 ) :: frag1, frag2
373
+
374
+
371
375
! Find the number of keyword lines in a parameter file
372
376
if (all_PEs_read .or. is_root_pe()) then
373
377
! rewind the parameter file
374
378
rewind(iounit)
375
379
376
380
! count the number of valid entries in the parameter file
377
381
num_lines = 0
382
+ total_chars = 0
378
383
inMultiLineComment = .false.
379
384
do while (.true. )
380
385
read (iounit, ' (a)' , end= 8 ) line
381
386
line = replaceTabs(line)
382
387
if (inMultiLineComment) then
383
388
if (closeMultiLineComment(line)) inMultiLineComment= .false.
384
389
else
385
- if (lastNonCommentNonBlank(line)>0 ) num_lines = num_lines + 1
390
+ if (lastNonCommentNonBlank(line)>0 ) then
391
+ line = removeComments(line)
392
+ line = simplifyWhiteSpace(line(:len_trim (line)))
393
+ num_lines = num_lines + 1
394
+ total_chars = total_chars + len_trim (line)
395
+ endif
386
396
if (openMultiLineComment(line)) inMultiLineComment= .true.
387
397
endif
388
398
enddo ! while (.true.)
@@ -392,18 +402,22 @@ subroutine populate_param_data(iounit, filename, param_data)
392
402
call MOM_error(FATAL, ' MOM_file_parser : A C-style multi-line comment ' // &
393
403
' (/* ... */) was not closed before the end of ' // trim (filename))
394
404
395
- param_data% num_lines = num_lines
405
+
406
+ int_buf(1 ) = num_lines
407
+ int_buf(2 ) = total_chars
396
408
endif ! (is_root_pe())
397
409
398
410
! Broadcast the number of valid entries in parameter file
399
411
if (.not. all_PEs_read) then
400
- call broadcast(param_data% num_lines, root_pe())
412
+ call broadcast(int_buf, 2 , root_pe())
413
+ num_lines = int_buf(1 )
414
+ total_chars = int_buf(2 )
401
415
endif
402
416
403
417
! Set up the space for storing the actual lines.
404
- num_lines = param_data % num_lines
405
- allocate (lines_in (num_lines))
406
- lines_in(:) = ' '
418
+ param_data % num_lines = num_lines
419
+ allocate (line_len (num_lines), source = 0 )
420
+ allocate (char_buf(total_chars), source = " " )
407
421
408
422
! Read the actual lines.
409
423
if (all_PEs_read .or. is_root_pe()) then
@@ -412,6 +426,7 @@ subroutine populate_param_data(iounit, filename, param_data)
412
426
413
427
! Populate param_data%fln%line
414
428
num_lines = 0
429
+ rsc = 0
415
430
do while (.true. )
416
431
read (iounit, ' (a)' , end= 18 ) line
417
432
line = replaceTabs(line)
@@ -422,7 +437,10 @@ subroutine populate_param_data(iounit, filename, param_data)
422
437
line = removeComments(line)
423
438
line = simplifyWhiteSpace(line(:len_trim (line)))
424
439
num_lines = num_lines + 1
425
- lines_in(num_lines) = line
440
+ llen = len_trim (line)
441
+ line_len(num_lines) = llen
442
+ do ch= 1 ,llen ; char_buf(rsc+ ch)(1 :1 ) = line(ch:ch) ; enddo
443
+ rsc = rsc + llen
426
444
endif
427
445
if (openMultiLineComment(line)) inMultiLineComment= .true.
428
446
endif
@@ -434,21 +452,26 @@ subroutine populate_param_data(iounit, filename, param_data)
434
452
// ' reading of ' // trim (filename))
435
453
endif ! (is_root_pe())
436
454
437
- ! Broadcast the populated array lines_in
455
+ ! Broadcast the populated arrays line_len and char_buf
438
456
if (.not. all_PEs_read) then
439
- call broadcast(lines_in, INPUT_STR_LENGTH, root_pe())
457
+ call broadcast(line_len, num_lines, root_pe())
458
+ call broadcast(char_buf(1 :total_chars), 1 , root_pe())
440
459
endif
441
460
442
461
! Allocate space to hold contents of the parameter file, including the lines in param_data%fln
443
462
allocate (param_data% fln(num_lines))
444
463
allocate (param_data% line_used(num_lines))
445
464
param_data% line_used(:) = .false.
446
465
! Populate param_data%fln%line with the keyword lines from parameter file
466
+ rsc = 0
447
467
do n= 1 ,num_lines
448
- param_data% fln(n)% line = lines_in(n)
468
+ line(1 :INPUT_STR_LENGTH) = " "
469
+ do ch= 1 ,line_len(n) ; line(ch:ch) = char_buf(rsc+ ch)(1 :1 ) ; enddo
470
+ param_data% fln(n)% line = trim (line)
471
+ rsc = rsc + line_len(n)
449
472
enddo
450
473
451
- deallocate (lines_in )
474
+ deallocate (char_buf) ; deallocate (line_len )
452
475
453
476
end subroutine populate_param_data
454
477
0 commit comments