I’m working with an older FORTRAN legacy code from specific corporation (so can’t post 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
I’m a noob when it comes to Linux and FORTRAN, I may just be making a rookie mistake, would really appreciate any advice.
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
without actually seeing script the “not found” error is probably because you do not have the directory you created the “newspaper” executable in in your search path. Assuming the script is being executed in the directory where “newspaper” is created, changing “newspaper” to “./newspaper” or adding a line to the top of the Install.sh script saying "export PATH=$PATH:.
will fix that if that is the case. You could add “.” to your PATH variable all the time by adding that line to your .bashrc script but I would not recommend ever putting “.” in your path all the time. You also seem to have a syntax error in line 31 of the Install.sh script but that is another problem, probably caused by not having a terminator for a “here” document or a missing closing quote somewhere else. If you run the script by running it as “bash -x -v ./Install.sh” it might show you exactly what is missing.
Worked! I edited the Install
file adding ./
to the newspaper calls to get ./newspaper
. Also, on the ball with the Bash, I was forcing Install
to run with sh
I switched to csh
due to it being legacy code switching to csh
fixed the syntax error in Install
. I was able to get the file correctly, but its in .file instead of .exe odd.
GNU/Linux does not require file suffixes and does not create them by default. If you use the command “file newspaper” it will confirm it is an executable. If you manually change the name to newspaper.exe you will have to use the name literally to execute it, as in “./newspaper.exe” instead of simply “newspaper”.
1 Like
“file Install.sh” will also tell you the file is a shell script; and if Install.sh is truly a csh shell you want to make sure the first line of the file is “#!/bin/csh -f” and probably rename it to “Install” or “Install.csh”. If it is very old the first line determined if it was csh or sh (the only shells that were usually available) by whether the first line started with a “#” or not; but GNU uses “magic” strings at the beginning of the file instead file suffixes to tell what type of file it is, and the magic string in the case of shell scripts is “#!” followed by the command, as in “#!/bin/bash”. You might want to search for “shebang lines”. Then you can say something like “file *” and see the type of all the files in a directory, even if they do not have suffixes. Suffixes are often used for data files, but rarely used for executables.
Interesting, thanks for the clarification. The Install
does specify #! /bin/csh -f
. I was able to compile and run the .file
created called newspaper
but I’m blanking on how to handle executing an input file .in
as an input into newspaper
and have the output recorded into a .out
or .dif
file rather than entering everything manually
Your Install.sh script is showing it reads and writes from stdin and stdout, so
./newspaper < input_file_name > output_file_name
diff file_with_expacted_answers output_file_name > file_name.dif
is probably what you are looking for; but back to Fortran you can name your output and input files with the OPEN() statement. The issues you have so far are not really Fortran problems so far, although you did not initially know that; you probably want to find an intro to GNU/Linux or Unix, which covers things like setting your path, redirection, and so on since you mentioned you were new to it.
I see! Thanks for all the help Urbanjost, this is a gold mine for me. Yeah, you’re on the ball there, think I’ll start with Linux file structures, if it’s not obvious I’m quite new to Linux and Unix only been using it about a week now, mainly use MATLAB, Java, or Python. (which should be marked the solution?)
Does not matter much, probably the first one answers the initial question. There is a lot of support here for Fortran, so as you get into the code remember that is available.
1 Like
PS; Fortran is a compiled language, looking in the compiled program for what is wrong with the code will not be fruitful. Do not look in the file “newspaper”. The script you are executing is compiiling the program from source files, that probably end in .f, maybe .ftn, .for, or .f90. That is a BIG difference between the interpreted languages you mentioned and Fortran (and C and C++).
1 Like