NASA-LIS / LISF

Land Information System Framework
Apache License 2.0
118 stars 156 forks source link

Filename length limited to 100 characters #371

Open jmroth opened 5 years ago

jmroth commented 5 years ago

It seems that the length of filenames is limited to 100 characters. This is not a problem if one uses relative paths. Absolute paths on clusters however tend to be very long, which results in LIS not finding input files. I think a possible fix would be to change the maximum string length for input files in the lisrc declaration, i.e. change lines like

     character*100, allocatable :: shdmaxfile(:) 
     character*100, allocatable :: shdminfile(:) 

to

     character*200, allocatable :: shdmaxfile(:) 
     character*200, allocatable :: shdminfile(:) 

Since I am not sure if this breaks anything, I will work with relative paths for now but might send a pull request in the future.

emkemp commented 5 years ago

Thank you for opening this issue. The filename length has been on our unofficial TODO list for a while. My current thinking is to define a global integer parameter with a value of 255 (the max file length guaranteed by the POSIX standard, which many operating systems follow), and to use that parameter everywhere.

Also, please note that the max line length in the lis.config file is 250 characters (specified by the ESMF library). This can also effectively constrain the length of a file path if the full path is specified in the lis.config file.

bmcandr commented 2 years ago

Should we define (or replace) our internal constant for max path length with ESMF's max path length constant (ESMF_MAXPATHLEN)?


I recently made a fix for this issue in LIS' metforcing readers (#944) by defining a path length constant (LIS_CONST_PATH_LEN) of 500 characters to declare the size of strings that hold paths. 500 characters was selected by doubling the maximum line length of 250 characters listed in ESMF's resource/config file documentation to provide space for the relative path to individual files that LIS tacks onto the paths read from the config. However, ESMF's documentation appears to be out of date and the max line length is actually 1024 characters as of v7.1.0:

In ESMF_Config.F90, the ESMF_ConfigGetString routine reads attributes from config files and stores them in strings declared with a size defined by the local constant LSZ:

!       integer,   parameter :: LSZ = 256  ! Maximum line size
       integer,   parameter :: LSZ = max (1024,ESMF_MAXPATHLEN)  ! Maximum line size
                                          ! should be at least long enough
                                          ! to read in a file name with full
                                          ! path prepended.

The value of ESMF_MAXPATHLEN is also set to 1024 in ESMF_UtilTypes.F90:

! Maximum length of a file name, including its path.
integer, parameter :: ESMF_MAXPATHLEN = 1024

Rather than using our own arbitrary max path length, we could adopt ESMF's constant which would ensure compatibility between ESMF and LIS. The only caveat is that users passing absurdly long paths in their config may get bit by the same bug described in this issue, but I feel this would be a rare edge case.

Note: The system configuration variable PATHMAX represents an upper bound on path lengths and is set to 4096 characters in Linux and 1024 characters on Mac OS. Using ESMF_MAXPATHLEN should not conflict with this system variable on most systems.

emkemp commented 2 years ago

I like this suggestion.