# Read FORTRAN binary build code as FORTRAN - Help

**URL:** <https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818>\
**Category:** Help\
**Created:** [February 17, 2022, 11:08pm UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818 "2022-02-17T23:08:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheImmortal](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@TheImmortal](https://fortran-lang.discourse.group/u/TheImmortal)\
**Post date:** [February 17, 2022, 11:08pm UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/1 "2022-02-17T23:08:40Z")

</div>

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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [February 18, 2022, 3:35am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/2 "2022-02-18T03:35:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TheImmortal](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@TheImmortal](https://fortran-lang.discourse.group/u/TheImmortal)\
**Post date:** [February 18, 2022, 3:53am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/3 "2022-02-18T03:53:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [February 18, 2022, 3:56am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/4 "2022-02-18T03:56:57Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [February 18, 2022, 4:03am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/5 "2022-02-18T04:03:52Z")

</div>

“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.

---

<div class="post-metadata">

**Author:** ![TheImmortal](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@TheImmortal](https://fortran-lang.discourse.group/u/TheImmortal)\
**Post date:** [February 18, 2022, 4:22am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/6 "2022-02-18T04:22:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [February 18, 2022, 5:00am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/7 "2022-02-18T05:00:40Z")

</div>

Your Install.sh script is showing it reads and writes from stdin and stdout, so

```bash
./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.

---

<div class="post-metadata">

**Author:** ![TheImmortal](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@TheImmortal](https://fortran-lang.discourse.group/u/TheImmortal)\
**Post date:** [February 18, 2022, 5:05am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/8 "2022-02-18T05:05:40Z")

</div>

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?)

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [February 18, 2022, 5:10am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/9 "2022-02-18T05:10:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [February 18, 2022, 5:36am UTC](https://fortran-lang.discourse.group/t/read-fortran-binary-build-code-as-fortran-help/2818/10 "2022-02-18T05:36:04Z")

</div>

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++).
