Scripting with executables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting with executables
# 1  
Old 05-11-2013
Scripting with executables

Hi everyone,

I am working with an executable (let's say work) in bash shell. When I run this work
executable it asks the following information;
1- choose task a or b
2- input file
3- output file
4- some operational choices

after it reads the given input file, does some algebraic operations with the input files data and
writes to the given output file. The question is the following, I need to run this executable many times with large number of input files, for each time my answers and choices are the same. So how can I run everything in one single script.

./work a input.file output.file choices

this command does not work, evidently the work executable can not read arguments.

any help will be highly appreciated.
# 2  
Old 05-11-2013
Post some examples of what the prompts(i.e. questions) look like on your screen that the application prompts you with, you probably can do what you want with "expect".
# 3  
Old 05-12-2013
I have the source code of executable

here are the relevant parts where it prompts on the screen:

1st prompt;
Code:
      
write(*,*)
write(*,*) '  Input run mode:'
write(*,*) '  ---------------'
write(*,*)
write(*,*) '  0 = calculates decay widths'
write(*,*) '  1 = decay events in file'
write(*,*)

read(*,'(i1)')  run_mode

2nd prompt;
Code:
write(*,*) 'input event file: (e.g. events.lhe)'
read(*,'(a)')  infile

3rd prompt;
Code:
write(*,*) 'name for output file: (e.g. dec-events.lhe)'
read(*,'(a)')  outfile

4th prompt;
Code:
write(*,*) ' Implemented decays are for:'
write(*,*) ' ---------------------------'
write(*,*)
write(*,*) ' Leptons: ta- ta+' 
write(*,*) ' Quarks : t t~' 
write(*,*) ' Bosons : z w+ w- h'        
write(*,*) ' Input particle to be decayed (e.g. t~):'
read(*,'(a3)',err=99)  name

5th prompt;
Code:
if(ip.eq.15) then  ! tau-
string(1) =  ' ta- -> vt   e- ve~  '
string(2) =  ' ta- -> vt  mu- vm~  '
string(3) =  ' ta- -> vt   l- vl~ (e+mu) '
string(4) =  ' ta- -> vt   pi-     '
string(5) =  ' ta- -> vt  rho(770)-'
write(*,'(i2,2x,a30)') (i,string(i),i=1,5)
write(*,*) ' '
write(*,*) 'your choice is:'   
read (*,*) imode

I tried to replace the 2nd argument of read statements with $1, $2, $3 etc. and recompiled. But it complains at the compilation level.
# 4  
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
# 5  
Old 05-12-2013
Hi drl,

thanks for your suggestion, but I could not completely understand your solution and I don't think it will solve my problem. Let me tell you in this way; my answers for prompt questions are the same for all files,
so I would like to run my executable with arguments so that it will not be disturbed during its operation;
simply like

Code:
./work 1 events.lhe dec-events.lhe ta- 2

I can send you the whole source code, but there is no attach option here. I don't want to paste all here since it is a bit long. My OS is OpenSUSE and the language is Fortran for sure.

thanks for your help.
# 6  
Old 05-12-2013
Hi.

Yes, I understand your desire to use the same set of parameters with different datasets. The demo script showed different ways to get the parameters into the program without changing the code, and without repeatedly requiring interactive input.

However, to continue I need to know how the code handles the data files.

Please post the (presumably) small sections of the code that opens the input and output files ... cheers, drl
# 7  
Old 05-12-2013
Code:
      open(lunr,file=infile,status='old')
      open(lunw,status='scratch')
      open(luni,file=outfile,status='unknown')
c
c     copy old banner into new banner and the param_card.dat into the scratch file
c
      done=.false.
      lwrite=.false.
      newbanner=.false.
      read(lunr,'(a132)',err=99) buff
      do while(index(buff,'<init>') .eq. 0)
         if(index(buff,"<header>") .ne. 0) newbanner=.true.
         if (index(buff,"<slha>") .ne. 0 .or.
     $        index(buff,"Begin param_card.dat") .ne. 0) lwrite=.true.
         if (index(buff,"</slha>") .ne. 0 .or.
     $        index(buff,"End param_card.dat") .ne. 0) lwrite=.false.
c         
         if(index(buff,'</header>') .eq. 0 .and.
     $        (newbanner .or. index(buff,'-->') .eq. 0 ))
     $      write(luni,'(a)') buff(1:len_trim(buff))
         if(lwrite) write(lunp,'(a)') buff(1:len_trim(buff))
c         if(lwrite) write(*,'(a50)') 'found in param_card: ',buff
c         if(.not.lwrite) write(*,'(a50)') 'found in banner: ',buff
         read(lunr,'(a132)',err=99) buff
      enddo
c
      rewind(lunr)
c
      endif

here it is where it opens input and output files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question