Sponsored Content
Full Discussion: Scripting with executables
Top Forums Shell Programming and Scripting Scripting with executables Post 302806049 by drl on Sunday 12th of May 2013 08:59:12 AM
Old 05-12-2013
Hi.

It's useful if you post your OS and language with your question.

Your program is clearly Fortran.

I'll assume that you want to change your program as little as possible. With that assumption, here are some techniques for entering data that is requested with read(*,*) statements:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate data input into Fortran.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C gfortran

VALUE=${1-17.4}

pl " Script value argument: $VALUE"

pl " Sample choices text file inputs:"
head choices*

pl " Demonstration Fortran code:"
F=f2.f90
cat $F

# Compile code.
pe
gfortran $F
file a.out

pl " Execute, enter data from keyboard:"
./a.out

pl " Execute, read from choices-1:"
./a.out < choices-1.txt

pl " Execute, read from choices-2:"
./a.out < choices-2.txt

pl " Execute, read from in-line data, a \"here\" document:"
./a.out <<SIGNAL
97
SIGNAL

pl " Execute, read from in-line data, a \"here\" document, script parameter:"
./a.out <<CHEWING_GUM
$VALUE
CHEWING_GUM

exit 0

producing:
Code:
./s1 101.55

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2

-----
 Script value argument: 101.55

-----
 Sample choices text file inputs:
==> choices-1.txt <==
33

==> choices-2.txt <==
67.24

-----
 Demonstration Fortran code:
program f2

! @(#) f2	Demonstrate Fortran-90.

write(*,*) " First number:"
read(*,*) x
write(*,*) " You entered: ", x

end program f2

a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped

-----
 Execute, enter data from keyboard:
  First number:
22
  You entered:    22.000000    

-----
 Execute, read from choices-1:
  First number:
  You entered:    33.000000    

-----
 Execute, read from choices-2:
  First number:
  You entered:    67.239998    

-----
 Execute, read from in-line data, a "here" document:
  First number:
  You entered:    97.000000    

-----
 Execute, read from in-line data, a "here" document, script parameter:
  First number:
  You entered:    101.55000

There are standard modules that one can call to process the control statement. They might be of use in processing the file arguments. However, it would be useful if you would post the code for initializing the input and output files: where the filenames are defined, the open & close statements, etc.

Best wishes ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cksum all executables on drive

I know I can run the cksum command for multiple files in a directory and send the results to a new file. EX.) # cd /usr # cksum *_ex* > /tmp/cksumusr.txt But I can't figure out how to run this command on multiple files in all directories on drive. Is it possible to do this, without having... (2 Replies)
Discussion started by: crazykelso
2 Replies

2. UNIX for Dummies Questions & Answers

cannot create executables

I am trying to install PROFTPD-1.2.7 on a SCO OpenServer 5.0.6 Server with a gcc-2.95.2 installed the VOLS files from http://www.caldera.com/skunkware. The problem I am having is when I try to run ./configure in the proftpd directory I get this error: # ./configure checking build system... (6 Replies)
Discussion started by: stufine
6 Replies

3. Programming

executables ending with *

Hi All, I m very new to unix. I have a basic doubt .. In unix I m seeing that there is a * at the end of by executable name (exe1*).. Wht is the significance of that Thanks a lot in advance (2 Replies)
Discussion started by: binums
2 Replies

4. Programming

Error creating executables

hi, I am getting error when trying to create binaaries for Xerces C++ error is configure:error:installation:cofihuration error:compiler cant create executables ??????????? Thanks in advance im using AIX flavour of IBM Im using ./configure command to create binaries.Its saying c... (6 Replies)
Discussion started by: chetan2309
6 Replies

5. UNIX for Dummies Questions & Answers

Regarding shell scripts to executables

Hi, I have written a shell script for automating some of our repetitive activities. I want all my colleagues to use my script and do the activities automatically by just running the script. But I do not want them to see the code. Is there a way we can generate something like an executable... (16 Replies)
Discussion started by: lokachari
16 Replies

6. UNIX for Dummies Questions & Answers

Searching executables datewise

I want to search executable files after a particular time and date , i.e. in a folder if a file has been accessed,modified or changed after a particular date and time ,then that file should be listed , and current date and time should be stored in a file so that when i again run the script ,it ... (6 Replies)
Discussion started by: glamo_2312
6 Replies

7. Programming

Compare two executables

Hi - I have two complex (for me at least) make files. The older one creates a succesful executable. The later one uses if statements to conditionally make different versions of the executable. The 2nd produces an executable that fails. I have "eyeballed" the differences in the Make files and run... (18 Replies)
Discussion started by: BrighterLater
18 Replies

8. Solaris

C compiler cannot create executables

Hi, I'm trying to compile Apache2.2 (I know it is available as a package) on a fresh install of Solaris Express 11. I've installed gcc-3 and gnu-bintutils via pkg. The config.log is attached (as config.txt). I don't see what I'm missing. Thanks, Doug (1 Reply)
Discussion started by: Doug_M
1 Replies

9. Shell Programming and Scripting

Searching for executables

Hello Unix users, this is my first post here. :) I want to search a directory (and subdirectories) for executable files (files with rwx------ permission) and move them to a different folder. What Unix commands can accomplish this? (2 Replies)
Discussion started by: Sagan_Radiation
2 Replies

10. UNIX for Advanced & Expert Users

Finding All Pro *C executables

Hi , I want to find all Pro *C executables in a directory say /. When i fire file command on Pro*c file it gives below o/p ELF-64 executable object file - PA-RISC 2.0 (LP64) my system is HP-UX eux012 B.11.23 U 9000/800 151107499 unlimited-user license but when i fire file on a C... (2 Replies)
Discussion started by: Jcpratap
2 Replies
OPENVT(1)                                                            Linux 1.x                                                           OPENVT(1)

NAME
openvt - start a program on a new virtual terminal (VT). SYNOPSIS
openvt [-c vtnumber] [OPTIONS] [--] command DESCRIPTION
openvt will find the first available VT, and run on it the given command with the given command options, standard input, output and error are directed to that terminal. The current search path ($PATH) is used to find the requested command. If no command is specified then the environment variable $SHELL is used. OPTIONS -c, --console=VTNUMBER Use the given VT number and not the first available. Note you must have write access to the supplied VT for this to work; -f, --force Force opening a VT without checking whether it is already in use; -e, --exec Directly execute the given command, without forking. This option is meant for use in /etc/inittab. If you want to use this feature in another context, be aware that openvt has to be a session leader in order for -e to work. See setsid(2) or setsid(1) on how to achieve this. -s, --switch Switch to the new VT when starting the command. The VT of the new command will be made the new current VT; -u, --user Figure out the owner of the current VT, and run login as that user. Suitable to be called by init. Shouldn't be used with -c or -l; -l, --login Make the command a login shell. A - is prepended to the name of the command to be executed; -v, --verbose Be a bit more verbose; -w, --wait wait for command to complete. If -w and -s are used together then openvt will switch back to the controlling terminal when the com- mand completes; -V, --version print program version and exit; -h, --help show this text and exit. -- end of options to openvt. NOTE
If openvt is compiled with a getopt_long() and you wish to set options to the command to be run, then you must supply the end of options -- flag before the command. EXAMPLES
openvt can be used to start a shell on the next free VT, by using the command: openvt bash To start the shell as a login shell, use: openvt -l bash To get a long listing you must supply the -- separator: openvt -- ls -l HISTORY
Earlier, openvt was called open. It was written by Jon Tombs <jon@gtex02.us.es or jon@robots.ox.ac.uk>. The -w idea is from "sam". SEE ALSO
chvt(1), doshell(8), login(1) 19 Jul 1996 V1.4 OPENVT(1)
All times are GMT -4. The time now is 12:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy