Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case sensitivity in file names #11

Open
Huite opened this issue Jul 28, 2024 · 0 comments
Open

Case sensitivity in file names #11

Huite opened this issue Jul 28, 2024 · 0 comments

Comments

@Huite
Copy link
Collaborator

Huite commented Jul 28, 2024

This mostly comes up in relation with #7 and #10.

GFLOW has been set up to run on DOS and Windows, which do not care about lower versus upper case for file names. Linux and macOS do care.

This creates trouble almost immediately, as the input argument is almost immediately changed into upper case. E.g. well_uflow.dat becomes WELL_UFLOW.DAT. Then, when this file is opened on Linux, it doesn't exist; then GFLOW seems to assume it's supposed to read input from the command line which never arrives. On Linux, it's erroring continuously which becomes apparent if you check fort.7.

Some approaches:

  • Require upper case file names. That way any transformation just results in the same file. However, this should be enforced: any entry point should check whether a file contains lower case letters, and if so, it should error. For a start though, we could just make sure the .dat file is upper case only.
  • Require lower case file names. Similar to the proposal above; with the note that lower case is basically superior to upper case letters because of better readability due to more variety in letter forms. This basically requires checking ALL filename interactions; pretty tedious.
  • Make it nice, make it robust: GFLOW does not alter the case of incoming file names. Unfortunately, this requires either checking for both lower and upper case forms, or ad hoc lowering before checking (which is what I'd do in Python).

It's worth noting that the first one is extremely simple to implement and that it provides really only a modicum of annoyance. In particular, if we assume that e.g. the QGIS plugin does the setting up of the input file, we can simply create upper case only there; no user will be much the wiser.

However, for backwards compatibility it's not very nice, since on Windows it would run.
Also pragmatically solving that: only check and error on Linux or macOS:

program main
    implicit none
    character(len=256) :: filename
    logical :: has_lowercase

    ! Get filename from command line
    call get_command_argument(1, filename)

    #if defined(__linux__) || defined(__APPLE__)
        ! Check for lowercase on Linux and macOS
        if (has_lowercase(filename)) then
            print *, "Error: Lowercase characters are not allowed in the filename on this system."
            stop
        end if
    #endif

    ! Rest of your program...

contains

    function has_lowercase(str) result(res)
        character(len=*), intent(in) :: str
        logical :: res
        integer :: i
        
        res = .false.
        do i = 1, len_trim(str)
            if (str(i:i) >= 'a' .and. str(i:i) <= 'z') then
                res = .true.
                return
            end if
        end do
    end function has_lowercase

end program main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant