Skip to content

pysharc compiles, but cannot read input files. #22

@diegoarmino

Description

@diegoarmino

Hi, everyone.

I've been dealing with a very slippery issue (at least to me). I compile pysharc as the manual indicates with a few modifications to the source/Makefile (apart from setting compiler and libs to gnu). The output of the command git diff source/Makefile is

$ git diff source/Makefile
diff --git a/source/Makefile b/source/Makefile
index 20b244f3..ad81917a 100644
--- a/source/Makefile
+++ b/source/Makefile
@@ -32,10 +32,10 @@
 USE_PYSHARC := true
 
 #intel, gnu
-USE_COMPILER := intel
+USE_COMPILER := gnu
 
 #mkl,gnu
-USE_LIBS := mkl
+USE_LIBS := gnu
 
 #Static libraries
 COMP_STATIC := false
@@ -79,8 +79,8 @@ ifeq ($(USE_COMPILER), )
   USE_COMPILER:=gnu
 endif
 ifeq ($(USE_COMPILER), gnu)
-  CC :=gcc
-  F90 :=gfortran 
+  CC :=$(CC)
+  F90 :=$(FC)
   EXTRAFLAGS := -ffree-line-length-none 
 else ifeq ($(USE_COMPILER), intel)
   CC:=icc

I set CC and F90 to the conda provided compilers. Also made the following changes to pysharc/netcdf/Makefile

diff --git a/pysharc/netcdf/Makefile b/pysharc/netcdf/Makefile
index 84e76e25..19d79b73 100644
--- a/pysharc/netcdf/Makefile
+++ b/pysharc/netcdf/Makefile
@@ -51,7 +51,7 @@ all: lib
 
 lib: $(OBJ_LIB)
        [ -d ../lib ] || mkdir ../lib
-       ar -cvq ../lib/$(library) $(OBJ_LIB)
+       $(AR) -cvq ../lib/$(library) $(OBJ_LIB)
 
 clean:
        rm ../lib/$(library)

In other words, I changed the hardcoded ar comand by $(AR) which corresponds to the conda provided version. All these changes avoided previous version mismatches between system, possible module loaded (lmod) and conda-provided compilers/libraries, in favor of the later ones.

The code compiled without errors, however when running tests 15 and 16 (LVC related) I run into a very confusing error. Sharc did not seem to be able to read the input file at all.

(sharc4.0) darmino@e03:/scratch/darmino/RUNNING_TESTS/LVC_pysharc$ cat output.log 

                                ,._gz,                                        ,._\
                               .g@@@p                                       ._Q@$+
                            ,.Q@@@@@f                                    ._Q@@@+  
                           .g@@@@@@@I                                 ._g@@@@F!   
                       ,,_zQ@@@@@@@@Q_,                            ,_zQ@@@@$+     
                .__ggQ@@@@@@@@@@@@@@@@@L_.              ,         _Q@@@@@@v       
       , __zg@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@QQz_z_zzQ@@L,    .zQ@@@@@@F`        
   .__gQ@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Q\__zQ@@@@@@$+          
  G@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@D            
    =4A@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@A@$@@@@@L,           
        =vVAA@$@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@p=VX@@@B*   <V@$@@@Q_,         
                   @@@@@@@@@@P^^^^^^--`     -q@@$=`     =4V`       =X@@@@_        
                   1@@@@@@@$!                  ^`                       -`        
                   -q@@@@@@]                                                      
                    ($@@@@$`                                                      
                     4@@@@p                                                       
                      d@@@p                                                       
                       d@@b                                                       
                        =4!                                                       


 EXECUTION INFORMATION:
 Start date: Wed Feb 18 14:15:20 2026
 Run host: e03
 Run directory: /scratch/darmino/RUNNING_TESTS/LVC_pysharc

 BUILD INFORMATION:
 Build date: Wed Feb 18 13:41:02 -03 2026
 Build host: e03
 Build directory: /home/darmino/programas/sharc4-4.0.2/source
 Compiler: /home/darmino/miniconda3/envs/sharc4.0/bin/x86_64-conda-linux-gnu-gfortran
 PYSHARC activated: true

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<============================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   Program SHARC started    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<============================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 Version: 4.0 (April 1, 2025)
 
 Print level:            2

 =============================================================
                          Input File
 =============================================================

 =============================================================
                             Restart
 =============================================================
 NO RESTART requested. Setting up the initial data from input files...

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<============================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   Initializing Dynamics    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<============================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                                                    Wed Feb 18 14:15:20 2026

Saving output data in NetCDF format (output.dat [header] + output.dat.nc)
Use data_extractor_NetCDF.x

 Keyword CHARGE not found.

After a long session of trial and error debugging, I managed to round up the problem to the subroutine read_input_list_from_file in the file source/input_list.f90. If I added a write statement like
write(,) "DEBUG: ", keyword, value
somewhere in the subroutine, the test ran successfully. However without it the error returned. It appears it is due to an optimization issue. If I turn off optimization for this file the problem fixes.
The complete set of changes I made to the code are summarized by the following git diff commands:

(sharc4.0) darmino@e03:~/programas/sharc4$ git diff source/Makefile
diff --git a/source/Makefile b/source/Makefile
index 20b244f3..ad81917a 100644
--- a/source/Makefile
+++ b/source/Makefile
@@ -32,10 +32,10 @@
 USE_PYSHARC := true
 
 #intel, gnu
-USE_COMPILER := intel
+USE_COMPILER := gnu
 
 #mkl,gnu
-USE_LIBS := mkl
+USE_LIBS := gnu
 
 #Static libraries
 COMP_STATIC := false
@@ -79,8 +79,8 @@ ifeq ($(USE_COMPILER), )
   USE_COMPILER:=gnu
 endif
 ifeq ($(USE_COMPILER), gnu)
-  CC :=gcc
-  F90 :=gfortran 
+  CC :=$(CC)
+  F90 :=$(FC)
   EXTRAFLAGS := -ffree-line-length-none 
 else ifeq ($(USE_COMPILER), intel)
   CC:=icc
@@ -122,6 +122,7 @@ CINCLUDE= -I$(ANACONDA)/include
 
 # flags
 F90FLAGS = -O3 -fPIC -g  $(EXTRAFLAGS)
+F90FLAGS_NOOPT = -O0 -fPIC -g  $(EXTRAFLAGS)
 
 # debug
 DEBUGFLAGS  = #-Wall -Wextra -Winline -Wno-unused-parameter -Wimplicit-interface -fbounds-check -fimplicit-none -fbacktrace -g 
@@ -309,7 +310,8 @@ clean:
 
 test_path:
        echo $(MAKEFILEPATH)
-
+input_list.o: input_list.f90
+       $(F90) $(FINCLUDE) $(DEBUGFLAGS) $(F90FLAGS_NOOPT) -c $<
 %.o: %.f90 
        $(F90) $(FINCLUDE) $(DEBUGFLAGS) $(F90FLAGS) -c $<
 
(sharc4.0) darmino@e03:~/programas/sharc4$ git diff source/input_list.f90
diff --git a/source/input_list.f90 b/source/input_list.f90
index b5000a90..802e19dc 100644
--- a/source/input_list.f90
+++ b/source/input_list.f90
@@ -56,12 +56,17 @@ private alloc_list, resize_list
     implicit none
     
     integer, intent(in) :: nunit
-    character*8000 :: keyword, value
+    character(len=8000) :: keyword, value
     integer :: io
     
     ! read all keywords into the variable size list and copy to output
     do 
       io=0 !no idea why something has to be here but without it the next line is not executed correctly
+
+      ! Initialize strings with spaces before use. This avoids garbage data or data from previous loops.
+      keyword = " "
+      value   = " "
+
       ! reads the next non-comment line from input file
       call next_keyword(nunit, keyword, value, io)
       if (io/=0) exit
(sharc4.0) darmino@e03:~/programas/sharc4$ git diff pysharc/netcdf/Makefile
diff --git a/pysharc/netcdf/Makefile b/pysharc/netcdf/Makefile
index 84e76e25..19d79b73 100644
--- a/pysharc/netcdf/Makefile
+++ b/pysharc/netcdf/Makefile
@@ -51,7 +51,7 @@ all: lib
 
 lib: $(OBJ_LIB)
        [ -d ../lib ] || mkdir ../lib
-       ar -cvq ../lib/$(library) $(OBJ_LIB)
+       $(AR) -cvq ../lib/$(library) $(OBJ_LIB)
 
 clean:
        rm ../lib/$(library)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions