0

I'm working with an older proprietary FORTRAN legacy code from specific corporation (so can't post much source code), I'm having an issue with the file interactions. My compiler bash shell Install is calling make newspaper which calls a series of other functions via the makefile bash shell to create newspaper. However, when newspaper is then called within Install with an input file to compare to an output file newspaper then returns not found. I've tried opening the file newspaper to look at it for the error.

I've tried converting newspaper into text, simply yielding a text file filled with numbers. I need to read the file as "code" to figure out whats going wrong and causing not found to crop up.

For Clarification:

  • newspaper is a binary file as when doing less newspaper in the terminal my Linux operator said its a binary file
  • the calling of newspaper inside Install has the following format newspaper < xfile1R.in > f1.test this is followed by diff xfile1R.out f1.test > f1.dif
  • gfortran is the compiler being used in Ubuntu, the c drive is a mounted drive
  • little endian should be the binary format used according to this site

I'm a noob when it comes to Linux and FORTRAN, I may just be making a rookie mistake, would really appreciate any advice, im not sure if this is a Linux or FORTRAN issue.

roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ sh ./Install.sh
cat makefile.sh >makefile
chmod a+x makefile
make: 'newspaper' is up to date.
./Install.sh: 10: newspaper: not found
./Install.sh: 12: newspaper: not found
./Install.sh: 14: newspaper: not found
./Install.sh: 16: newspaper: not found
./Install.sh: 18: newspaper: not found
./Install.sh: 20: newspaper: not found
 84 -rwxrwxrwx 1 roman roman  83071 Feb 17 16:08 f1.dif
152 -rwxrwxrwx 1 roman roman 153543 Feb 17 16:08 f2.dif
108 -rwxrwxrwx 1 roman roman 109718 Feb 17 16:08 f3.dif
232 -rwxrwxrwx 1 roman roman 236209 Feb 17 16:08 f4.dif
164 -rwxrwxrwx 1 roman roman 166612 Feb 17 16:08 f5.dif
 48 -rwxrwxrwx 1 roman roman  48898 Feb 17 16:08 f6.dif
./Install.sh: 31: Syntax error: newline unexpected

Edit 1: tried file newspaper to check PATH

roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ file newspaper
newspaper: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=8ac6de30da50639d7e3ea55a09416b049a5291c0, for GNU/Linux 3.2.0, not stripped

Edit 2: Make file fix?

#
# Makefile for newspaper
#

OBJF = \
    sfun1.o \
    sfun2.o \
    sfun3.o \
    sfun4.o \
    sfun5.o \
    sfun6.o \
    sfun7.o 


FLAGS = -O2 -static -std=legacy
COMP  = gfortran

newspaper: $(OBJF)
    $(COMP) $(FLAGS) -o newspaper $(OBJF)

.f.o:
    $(COMP) $(FLAGS) -c $< -o $*.o

Edit 3: Install error

#! /bin/csh -f

make flops

./newspaper < xfile1R.in > f1.test
diff xfile1R.out f1.test > f1.dif
./newspaper < xfile2R.in > f2.test
diff xfile2R.out f2.test > f2.dif
./newspaper < xfile3R.in > f3.test
diff xfile3R.out f3.test > f3.dif
./newspaper < xfile4R.in > f4.test
diff xfile4R.out f4.test > f4.dif
./newspaper < xfile5R.in > f5.test
diff xfile5R.out f5.test > f5.dif
./newspaper < xfile6.in > f6.test
diff xfile6.out f6.test > f6.dif

ls -als *.dif

# User input for directory to put executable
if ( $1 == '' ) then
   echo " "
   echo -n "Enter directory for executable file: "
   set Edir = $<
else
   set Edir = $1
endif

if ( $Edir != '' ) then
   mv newspaper $Edir
endif

Edit 4: More Syntax error, same error

./Install.sh: 30: Syntax error: newline unexpected
roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ ./
-bash: ./: Is a directory
roman@DESKTOP-QKJTF3S:

Edit 5: csh check

roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ sudo apt-get install csh
Reading package lists... Done
Building dependency tree
Reading state information... Done
csh is already the newest version (20110502-5).
0 upgraded, 0 newly installed, 0 to remove and 20 not upgraded.

Edit 6: It worked!! Courtesy to @steeldriver for guiding myself the noob

164 -rwxrwxrwx 1 roman roman 164829 Feb 17 21:36 f1.dif
304 -rwxrwxrwx 1 roman roman 307257 Feb 17 21:36 f2.dif
216 -rwxrwxrwx 1 roman roman 217791 Feb 17 21:36 f3.dif
460 -rwxrwxrwx 1 roman roman 468651 Feb 17 21:36 f4.dif
324 -rwxrwxrwx 1 roman roman 331213 Feb 17 21:36 f5.dif
 96 -rwxrwxrwx 1 roman roman  96955 Feb 17 21:36 f6.dif

Enter directory for executable file: ./Outputs
roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/
  • Is the working directory in your `PATH`? Is `newspaper` a statically or dynamically linked executable (what does `ldd newspaper` say)? – steeldriver Feb 17 '22 at 23:38
  • @steeldriver The working directory should be in the `PATH` doing `ls` will list `newspaper` as in the directory. I did `ldd newspaper` its not a dynamic executable (should it be a dynamic executable?) – The Immortal Feb 17 '22 at 23:49
  • The fact that `ls` lists `newspaper` doesn't tell you that the directory is on your `PATH`. Did `make` say `'newspaper' is up to date` *the very first time that you ran it*? If so it may be an old binary that was built for a different machine architecture. Check with `file newspaper`. – steeldriver Feb 17 '22 at 23:56
  • @steeldriver I see thanks for the clarification, I'm not sure about the first time, I first began working on this a few days ago but `make` does say `'newspaper' is up to date` every time I run it. The file created `newspaper` there's three with the same name, one is has the extension 'file' the other a 'bash shell' and the last is a 'application'. The bash shell and one with a 'file' extension are identical – The Immortal Feb 18 '22 at 00:10
  • Is your machine architecture also `x86-64`? Have you tried running `./newspaper` directly in the terminal (instead of via `make`)? – steeldriver Feb 18 '22 at 00:57
  • @steeldriver When I run `./newspaper` in the terminal the `newspaper` with the Application extension is launched, this successfully runs `newspaper` the application but it requires all the inputs etc. to be input manually in the terminal, (inputs exceed 300 different values), I'm wanting to use `install` so I can input a file that is read, used, and the results are then compared to other output files. – The Immortal Feb 18 '22 at 01:18
  • OK so the problem *does* seem to be that the location of `newspaper` is not in your `PATH`. You can either add it, or modify the Makefile to prepend `./` to the binary name. See [Why do we use "./" (dot slash) to execute a file in Linux/UNIX?](https://unix.stackexchange.com/questions/4430/why-do-we-use-dot-slash-to-execute-a-file-in-linux-unix). – steeldriver Feb 18 '22 at 01:21
  • @steeldriver Okay, I've added the makefile code to the post as Edit 2, I'm not sure where I need to add the ./ in this file to add it to the `PATH`. Thanks for all your help steel – The Immortal Feb 18 '22 at 02:06
  • Apologies - it would be in the `Install.sh` file: `./newspaper < xfile1R.in > f1.test` – steeldriver Feb 18 '22 at 02:09
  • @steeldriver It worked!! Thanks a bunch mate. I posted the entire `Install` code in Edit 3, I'm getting a syntax error on line 31 (which is the line where `else` is) is that because there isn't a path set in line 30? The terminal doesn't ask me to input a path for the executable, when I'm fairly sure it should given the echo statement – The Immortal Feb 18 '22 at 02:20
  • OK so I wish you'd posted that earlier - all you should need to do is enter `./` in response to the `"Enter directory for executable file: "` prompt. No need to modify the file itself. Also possibly correct the shebang from `#\!` to `#!`. – steeldriver Feb 18 '22 at 02:30
  • @steeldriver Yeah, sorry about that, would've been more helpful if I had. I made the correction of the shebang but `Install` does the same as before not even giving me a chance to make a response, nor printing the prompt to the terminal. I put the terminal output in Edit 4. (be aware there's still the rwxrwx output stuff from before directly above the syntax error but no need to include in edit 4) – The Immortal Feb 18 '22 at 02:39
  • Is a csh actually installed on your system? `Syntax error: newline unexpected` suggests that the script is being run by a different shell (perhaps `dash`). – steeldriver Feb 18 '22 at 02:53
  • @steeldriver Just checked, see Edit 5, a C shell is already is already installed, 'Bash' and 'Csh' (also known as Tcsh) were already installed. Bash is supposedly good for older scripts as it will still support them as I heard – The Immortal Feb 18 '22 at 03:27
  • OK so I just noticed **you are explicitly running the script with** `sh`. Don't do that. Fix the shebang, then run it with `./Install`. Neither sh nor bash are any good for csh scripts, regardless of how old they are. – steeldriver Feb 18 '22 at 03:32
  • @steeldriver It worked!! you're a genius, I've finally built the application, now I've got to figure out creating an input file – The Immortal Feb 18 '22 at 03:46

1 Answers1

1

Debugged successfully, the makefile required some edits due to bash shells being used so newspaper <input_file.in>... would then become ./newspaper <input_file.in>.... Most of the fixes were in the explicitly running a script with sh this is the wrong way to do it because the Install file specifically stated csh which is a different shell compiler, better to run Install with ./Install this causes the file newspaper to generate completely.