Looking for guidance (comments) on a piece of code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looking for guidance (comments) on a piece of code
# 1  
Old 05-23-2012
Looking for guidance (comments) on a piece of code

Hello -- I am trying to learn to do a little sed and awk scripting to search for text and numbers in text files (text processing/manipulation). My professor gave me a piece of uncommented code and I am very unfamiliar w/ the language. Can someone help me with comments so I can understand what is happening in each line? I have cygwin running to run scripts.

thanks

Code:
BEGIN {ifreq=0; iint=0; ithresh=0.5; maxint=0.0}

/Wavenum|Frequencies/ {
  for (i=3; i<=NF; i++) {
    if ($i<freqs[ifreq-1] && ifreq>0) exit;
    freqs[ifreq]=$i;
    ifreq++;
  }
}
/Inten/ {  for (i=4; i<=NF; i++) {
    ints[iint]=$i;
    if (ints[iint]>maxint) maxint=ints[iint];
    iint++;
  }
}

END {
  if (ifreq!=iint) {
    print "Error: no. of Freqs doesn't match no. of ints.";
    print "No. freqs = " ifreq "  No. ints = " iint;
    exit;
  }
  delta=0.001;

  for (i=0; i<ifreq; i++) {
    iscale=ints[i]/maxint;
      print freqs[i], ints[i], iscale;
  }
}

Moderator's Comments:
Mod Comment please use code tags

Last edited by jim mcnamara; 05-24-2012 at 12:11 AM..
# 2  
Old 05-24-2012
It looks like some kind of frequency distribution/report.

What does the input data look like? Please provide a sample.
# 3  
Old 05-24-2012
Attached is the frequency calculation section of an output file. The 1st section looks for a stationary point in the calculations (lowest energy state), so this code ignores that section. After the stationary point is found, the program runs through calculations for the frequencies and intensities corresponding to that stationary point structure along with some other information (population analyses,etc), so the file is a little long due to all of the other calculations completed along with frequencies, but a quick word search of the file with "frequencies" gets to the pertinent information for this code.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Time:Piece

Hi I am trying to find out difference between two dates with Time:Piece. I am able to get the days difference, but I want the Days as wells as hours, mins and sec difference. Below is my code for both, but the later is now working. Can anyone help me out. With only days use... (0 Replies)
Discussion started by: sauravrout
0 Replies

2. Programming

what is the name of this piece of code

while ((numRead = read(inputFd, buf, BUF_SIZE)) > 0) if (write(outputFd, buf, numRead) != numRead) fatal("couldn't write whole buffer"); if (numRead == -1) errExit("read"); if (close(inputFd) == -1) errExit("close input"); if (close(outputFd) == -1) errExit("close output"); ... (1 Reply)
Discussion started by: fwrlfo
1 Replies

3. Shell Programming and Scripting

perl extraction of code between comments /* .. */

Hi, I am using the following code to retrieve the contents between C-style comments "/* .. */". perl -lne 'while(/(\/\*.*?\*\/)/g) {print "$1";}' This works fine when the commented section of code is present in a single line. But I also need to extract the data which is present inside... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. Shell Programming and Scripting

Need help optimizing this piece of code (Shell script Busybox)

I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox. Example of data: $SORTEDTMP= it is a... (16 Replies)
Discussion started by: snappy46
16 Replies

5. UNIX for Advanced & Expert Users

grep source code and exclude comments

I often find myself grepping source code for a variable name and many times the name would be present in comment lines that I 'd prefer not to see. Do you guys know any tricks to filter out comments? Example: snippet of the source code /*** * type comment 1 ***/ void ... (7 Replies)
Discussion started by: migurus
7 Replies

6. Shell Programming and Scripting

Sed script, changing all C-comments to C++-comments

I must write a script to change all C++ like comments: // this is a comment to this one /* this is a comment */ How to do it by sed? With file: #include <cstdio> using namespace std; //one // two int main() { printf("Example"); // three }//four the result should be: (2 Replies)
Discussion started by: black_hawk
2 Replies

7. Shell Programming and Scripting

script or piece of code where the data returned by a stored procedure you are writing

hi fndz. Can you please help me with the code if I call a stored procedure from my shell script and stored procedure returns a cursor, cursor output should be saved to a file (3 Replies)
Discussion started by: enigma_83
3 Replies

8. Shell Programming and Scripting

what does this piece of code do?

Hi All, I am trying to understand and change some code written by some programmer a while ago. There are following three lines of code that I am unable to grasp. Could anybody please help me understand it? 1) cd - > /dev/null 2) fname=`basename "$1"` where $1 = /dirA/dirB/a.txt ... (3 Replies)
Discussion started by: Vikas Sood
3 Replies

9. Shell Programming and Scripting

a piece of code, plz help to review

use "getopts" to get params from command. Need replace black with a specified string like "%20 DEFAULT_DELIM=%20 ... while getopts dek:f:t:vh OPTION do case $OPTION in t) DELIM=`tvar=/'"$OPTARG"'/ svar="$DEFAULT_DELIM" awk 'BEGIN{T=ENVIRON;S=ENVIRON; while(index(T,S)!=0){S=S"0"};print... (0 Replies)
Discussion started by: anypager
0 Replies
Login or Register to Ask a Question