NCAR / DART

Data Assimilation Research Testbed
https://dart.ucar.edu/
Apache License 2.0
184 stars 139 forks source link

Feature request: make it easier to compile parse_args_mod.f90 without special compiler flags #607

Closed nancycollins closed 6 months ago

nancycollins commented 7 months ago

Use case

make it easier to compile the dart code by avoiding the need for special compiler flags

Is your feature request related to a problem?

the parse_args_mod.f90 file should have the existing code changed from using double backslash to:

! in re-reading this thread i am reminded that ACHAR is a way to set a character variable 
! without having an explicit backslash in the code and having to fool with compiler flags. 
! i think the fix for this and issue #555 should be:

character(len=1), parameter :: BACKSLASH = ACHAR(92)

...

if (thisc == BACKSLASH) then

Describe your preferred solution

don't depend on compiler flags to parse \\ (double backslash)

Describe any alternatives you have considered

this is related to a long discussion in issue #219 which is closed now, and #555.
marlee is trying to clean up the code and bring it up to current standards.
this seems like a fix that fits into that goal.

nancycollins commented 6 months ago

i made this change on the fix_parse branch.

hkershaw-brown commented 6 months ago

related #231

Here is the relevant code change (fix_parse has airs_obs_mod.f90 changes on also)


character(len=*), parameter :: source = 'parse_args_mod.f90'

! the ascii code for the backslash character is 92.
character(len=1), parameter :: BACKSLASH = ACHAR(92)

contains

!------------------------------------------------------------------------------
    @@ -135,7 +138,7 @@ subroutine get_args_from_string(inline, argcount, argwords)
                     inword, '"'//endword//'"', ' ', '"'//thisc//'"'

   ! escaped chars - backslash prevents interpretation of next char
   if (thisc == BACKSLASH) then
      ! move the remainder of the string over, overwriting the \ and
      ! skipping the next char.
      do i=thisoff, finaloff-1
    @@ -309,7 +312,7 @@ subroutine get_name_val_pairs_from_string(inline, argcount, argnames, argvals, c

   ! escaped chars - backslash prevents interpretation of next char
   ! shift remainder of line 1 char to the left.
   if (thisc == BACKSLASH) then
      do i=thisoff, finaloff-1
         argline(i:i) = argline(i+1:i+1)
      enddo
    @@ -492,7 +495,7 @@ subroutine get_next_arg(inline, startoff, argword, endoff)
                     inword, '"'//endword//'"', ' ', '"'//thisc//'"'

   ! escaped chars - backslash prevents interpretation of next char
   if (thisc == BACKSLASH) then
      ! move the remainder of the string over, overwriting the \ and
      ! skipping the next char.
      do i=thisoff, finaloff-1

Screen Shot 2024-01-04 at 10 07 36 AM

mjs2369 commented 6 months ago

Files that use this flag: mkmf.template.nvhpv, mkmf.template.pgi.linux, mkmf.template.pgi.osx

nancycollins commented 5 months ago

if this does go into the repo as part of the 'fortran cleanup' effort, i've made a 'fix_parse' branch on my fork of the repo, and it only has the parse file changes without the unintended AIRS converter changes.