@@ -13,6 +13,7 @@ program dmreport
1313 integer , parameter :: APP_PATCH = 0
1414
1515 character (* ), parameter :: APP_SUFFIX_EPS = ' .eps' ! ! EPS file ending.
16+ character (* ), parameter :: APP_SUFFIX_MS = ' .ms' ! ! Troff file ending.
1617 character (* ), parameter :: APP_SUFFIX_PDF = ' .pdf' ! ! PDF file ending.
1718 character (* ), parameter :: APP_SUFFIX_PS = ' .ps' ! ! PS file ending.
1819
@@ -275,28 +276,40 @@ subroutine make_ps(report, error)
275276 type (report_type), intent (inout ) :: report ! ! Report type.
276277 integer , intent (out ), optional :: error ! ! Error code.
277278
278- integer :: rc
279+ character (:), allocatable :: input, output
280+ integer :: rc, stat, unit
281+
282+ ! Create output file (PostScript).
283+ output = dm_time_parse_string(report% output)
284+
285+ call dm_file_touch(output, error= rc)
286+
287+ if (dm_is_error(rc)) then
288+ call dm_error_out(rc, ' failed to create output file ' // output)
289+ return
290+ end if
291+
292+ ! Open input file (troff).
293+ input = temporary_file(APP_TMP_DIR, APP_SUFFIX_MS)
294+
295+ rc = E_IO
296+ open (action= ' write' , file= input, iostat= stat, newunit= unit, status= ' replace' )
297+
298+ if (stat /= 0 ) then
299+ call dm_error_out(rc, ' failed to create input file ' // input)
300+ return
301+ end if
279302
280303 ps_block: block
281304 character (* ), parameter :: RULE = ROFF_REQUEST_BR // ROFF_ESC_MVUP // ROFF_ESC_HR // ASCII_LF
282305 character (* ), parameter :: SUB = ' sub'
283306 integer , parameter :: SUBR = 128 , SUBG = 128 , SUBB = 128 ! RGB colour of sub-heading.
284307
285- character (:), allocatable :: path, roff
286308 character (FILE_PATH_LEN), allocatable :: eps_files(:)
287309 integer :: i, n
288310
289311 allocate (eps_files(0 ))
290312
291- ! Create output file.
292- path = dm_time_parse_string(report% output)
293- call dm_file_touch(path, error= rc)
294-
295- if (dm_is_error(rc)) then
296- call dm_error_out(rc, ' failed to open output file ' // path)
297- exit ps_block
298- end if
299-
300313 ! Add document header.
301314 roff_block: block
302315 integer , parameter :: NCOL = 4 , NFMT = 1 , NROW = 2
@@ -315,19 +328,22 @@ subroutine make_ps(report, error)
315328 exit ps_block
316329 end if
317330
318- ! Create MS header and define colour.
319331 date = dm_time_date()
320- roff = dm_roff_ms_header(title= report% title, author= report% author, institution= date, font_family= APP_ROFF_FONT, font_size= 10 , &
321- left_header= report% title, center_header= report% subtitle, right_header= date, &
322- left_footer= ' DMPACK ' // DM_VERSION_STRING, center_footer= ROFF_ESC_ENDASH // ' % ' // ROFF_ESC_ENDASH)
323- roff = roff // dm_roff_defcolor(SUB, SUBR, SUBG, SUBB)
332+
333+ ! Create MS header and define colour.
334+ write (unit, ' (a)' , advance= ' no' ) dm_roff_ms_header(title= report% title, author= report% author, institution= date, &
335+ font_family= APP_ROFF_FONT, font_size= 10 , left_header= report% title, &
336+ center_header= report% subtitle, right_header= date, &
337+ left_footer= ' DMPACK ' // DM_VERSION_STRING, &
338+ center_footer= ROFF_ESC_ENDASH // ' % ' // ROFF_ESC_ENDASH)
339+ write (unit, ' (a)' , advance= ' no' ) dm_roff_defcolor(SUB, SUBR, SUBG, SUBB)
324340
325341 ! Add report overview table.
326342 format = reshape ([ character (FMT_LEN) :: ' lb' , ' l' , ' lb' , ' l' ], [ NCOL, NFMT ])
327343 data = reshape ([ character (COL_LEN) :: ' Node Name:' , node% name, ' From:' , dm_time_to_human(report% from), &
328- ' Node ID:' , node% id, ' To:' , dm_time_to_human(report% to ) ], &
329- [ NCOL, NROW ])
330- roff = roff // dm_roff_tbl(format , data ) // dm_roff_ms_lp(report% meta)
344+ ' Node ID:' , node% id, ' To:' , dm_time_to_human(report% to ) ], [ NCOL, NROW ])
345+
346+ write (unit, ' (2a) ' , advance = ' no ' ) dm_roff_tbl(format , data ), dm_roff_ms_lp(report% meta)
331347 end block roff_block
332348
333349 ! Add plots.
@@ -343,7 +359,9 @@ subroutine make_ps(report, error)
343359 allocate (eps_files(n), source= repeat (' ' , FILE_PATH_LEN))
344360
345361 ! Add plot section title and meta description.
346- roff = roff // dm_roff_ms_sh(2 , report% plot% title) // RULE // dm_roff_ms_lp(report% plot% meta)
362+ write (unit, ' (3a)' , advance= ' no' ) dm_roff_ms_sh(2 , report% plot% title), & ! Section title.
363+ RULE, & ! Horizontal rule.
364+ dm_roff_ms_lp(report% plot% meta) ! Meta description.
347365
348366 ! Plot subsection loop.
349367 do i = 1 , n
@@ -364,23 +382,22 @@ subroutine make_ps(report, error)
364382 ! Add title, subtitle, and meta description.
365383 if (dm_is_ok(rc) .or. report% verbose) then
366384 if (dm_string_has(observ% subtitle)) then
367- roff = roff // dm_roff_ms_sh(3 , trim (observ% title) // ROFF_ESC_NBSP // &
368- dm_roff_m(SUB, dm_roff_s(1 , observ% subtitle, rel= ' -' )))
385+ write (unit, ' (a)' , advance= ' no' ) dm_roff_ms_sh(3 , trim (observ% title) // ROFF_ESC_NBSP // dm_roff_m(SUB, dm_roff_s(1 , observ% subtitle, rel= ' -' )))
369386 else
370- roff = roff // dm_roff_ms_sh(3 , observ% title)
387+ write (unit, ' (a) ' , advance = ' no ' ) dm_roff_ms_sh(3 , observ% title)
371388 end if
372389
373- if (dm_string_has(observ% meta)) roff = roff // dm_roff_ms_lp(observ% meta)
390+ if (dm_string_has(observ% meta)) write (unit, ' (a) ' , advance = ' no ' ) dm_roff_ms_lp(observ% meta)
374391 end if
375392
376393 ! Handle errors.
377394 if (rc == E_DB_NO_ROWS) then
378- if (report% verbose) roff = roff // roff_error_message(' no observations found in database ' // report% plot% database)
395+ if (report% verbose) write (unit, ' (a) ' , advance = ' no ' ) roff_error_message(' no observations found in database ' // report% plot% database)
379396 cycle
380397 end if
381398
382399 if (dm_is_error(rc)) then
383- if (report% verbose) roff = roff // roff_error_message(dm_error_message(rc))
400+ if (report% verbose) write (unit, ' (a) ' , advance = ' no ' ) roff_error_message(dm_error_message(rc))
384401 cycle
385402 end if
386403
@@ -412,10 +429,10 @@ subroutine make_ps(report, error)
412429 call dm_plot_close(plot)
413430
414431 ! Add EPS to markup.
415- roff = roff // dm_roff_pspic(eps_files(i))
432+ write (unit, ' (a) ' , advance = ' no ' ) dm_roff_pspic(eps_files(i))
416433
417434 ! Add page break.
418- if (observ% pagebreak) roff = roff // ROFF_REQUEST_BP
435+ if (observ% pagebreak) write (unit, ' (a) ' , advance = ' no ' ) ROFF_REQUEST_BP
419436 end associate
420437 end do
421438 end block plot_block
@@ -443,18 +460,19 @@ subroutine make_ps(report, error)
443460
444461 ! Add log section title and meta description.
445462 if (dm_is_ok(rc) .or. report% verbose) then
446- roff = roff // dm_roff_ms_sh(2 , report% log% title) // RULE // &
447- dm_roff_ms_lp(report% log% meta)
463+ write (unit, ' (3a)' , advance= ' no' ) dm_roff_ms_sh(2 , report% log% title), & ! Section title.
464+ RULE, & ! Horizontal rule.
465+ dm_roff_ms_lp(report% log% meta) ! Meta description.
448466 end if
449467
450468 ! Handle errors.
451469 if (rc == E_DB_NO_ROWS) then
452- if (report% verbose) roff = roff // roff_error_message(' no logs found in database ' // report% log% database)
470+ if (report% verbose) write (unit, ' (a) ' , advance = ' no ' ) roff_error_message(' no logs found in database ' // report% log% database)
453471 exit log_block
454472 end if
455473
456474 if (dm_is_error(rc)) then
457- if (report% verbose) roff = roff // roff_error_message(dm_error_message(rc))
475+ if (report% verbose) write (unit, ' (a) ' , advance = ' no ' ) roff_error_message(dm_error_message(rc))
458476 exit log_block
459477 end if
460478
@@ -468,6 +486,7 @@ subroutine make_ps(report, error)
468486 ' -' , ' -' , ' -' , ' -' , ' -' , & ! Horizontal rule.
469487 ' l' , ' l' , ' l' , ' l' , ' lw36' ], & ! Left aligned, with min. width.
470488 [ NCOL, NFMT ])
489+
471490 data (:, 1 ) = [ character (COL_LEN) :: ' Timestamp' , ' Source' , ' Level' , ' Error' , ' Message' ]
472491
473492 ! Add table rows.
@@ -483,19 +502,22 @@ subroutine make_ps(report, error)
483502 end associate
484503 end do
485504
486- roff = roff // dm_roff_tbl(format , data , expand= .true. )
505+ write (unit, ' (a) ' , advance = ' no ' ) dm_roff_tbl(format , data , expand= .true. )
487506 end block log_block
488507
489508 ! Create PostScript file.
490- rc = dm_roff_to_ps(roff, report % output, macro= ROFF_MACRO_MS, preconv= .true. , tbl= .true. )
509+ rc = dm_roff_to_ps(input, output, macro= ROFF_MACRO_MS, preconv= .true. , tbl= .true. )
491510
492511 ! Remove temporary files.
512+ call dm_file_delete(input)
513+
493514 do i = 1 , size (eps_files)
494- if (.not. dm_string_has(eps_files(i))) cycle
495- call dm_file_delete(eps_files(i))
515+ if (dm_string_has(eps_files(i))) call dm_file_delete(eps_files(i))
496516 end do
497517 end block ps_block
498518
519+ close (unit)
520+
499521 if (present (error)) error = rc
500522 end subroutine make_ps
501523
@@ -613,8 +635,8 @@ function html_plot(dps, response, unit, terminal, title, meta, color, width, hei
613635 ! Select MIME type according to format.
614636 select case (plot% terminal)
615637 case (PLOT_TERMINAL_GIF); mime = MIME_GIF
616- case (PLOT_TERMINAL_PNG, &
617- PLOT_TERMINAL_PNGCAIRO); mime = MIME_PNG
638+ case (PLOT_TERMINAL_PNG); mime = MIME_PNG
639+ case ( PLOT_TERMINAL_PNGCAIRO); mime = MIME_PNG
618640 case (PLOT_TERMINAL_SVG); mime = MIME_SVG
619641 case default
620642 ! Fail-safe: should never occur.
@@ -729,8 +751,7 @@ integer function read_config(app) result(rc)
729751 rc = config% open (app% config, app% name)
730752
731753 if (dm_is_ok(rc)) then
732- ! Take the table from the top of the Lua stack,
733- ! do not load a table field.
754+ ! Take the table from the top of the Lua stack, do not load a table field.
734755 call config% get(app% name, app% report, field= .false. )
735756 end if
736757
0 commit comments