2.4: File Input and Output - Biology

2.4: File Input and Output - Biology

We are searching data for your request:

Forums and discussions:
Manuals and reference books:
Data from registers:
Wait the end of the search in all databases.
Upon completion, a link will appear to access the found materials.

So far, all the data we’ve been working with have been “hard-coded” into our programs. In real life, though, we’ll be seeking data from external files.

We can access data that exist in an external file (a text file, usually) using a file handle, a special kind of data type we can connect to using an external source. In its simplest form, a file handle for reading data works sort of like a pipe: the operating system puts data (usually strings) in one end, and we extract data out of the other end, usually one line at a time. File handles for writing to files move the data in the opposite direction.

To use a file handle in Python, we have to tell the interpreter that we want to utilize some input/output functions by first putting the special commandimport ionear the top of our program. This command imports theiomodule, making available extra functions that exist within it. These functions also use a dot syntax to specify the module they exist in, which is confusingly similar to the dot syntax discussed previously for methods. To associate a file handle calledfhandlewith the file “filename.txt", for example, the command isfhandle ="filename.txt", "rU"), whereopen()is a function in the importediomodule. Therindicates that we’re creating a read-only file handle, and theUlets the interpreter know that we want a “universal” interpretation for newlines, to allow reading files created on Microsoft Windows systems or Unix-like systems.[1] The file handle data type has a method called.readline(), which returns the next available line from the pipe as a string; so,line = fhandle.readline()extracts a string (line) from the file handle and assigns it toline.

Let’s create a small file with three lines each containing a gene ID, a tab, and a corresponding GC-content value.

Now let’s create a program that reads and prints the data. When we are finished reading data from a file, we need to run the file handle’s.close()method. Using.close()causes the file handle to alert the operating system that we are done reading data from the handle. At this point the operating system is free to remove the back-end “pipe” and any data that might be in it.

If the file doesn’t exist or is not readable by the program, you will get anIOErrorindicating eitherNo such file or directoryorPermission deniedwith the file name you attempted to open.[2] Because our file does exist, we can successfully execute the code and inspect the results:

There are a few things to note here. First, each time we callfhandle.readline(), the file handle returns a different string: the next string waiting to be popped out of the pipe. Second, we see that the output contains our three lines, but separated by blank lines: this is because there are “newline” characters already in the file. We don’t see these newline characters, but we can represent them ourselves if we like, in a string with the control code . Similarly, tab characters have a control code like . The file is actually a single serial string, and the.readline()method asks the file handle to return everything up to and including the next .

In the end, the reason for the blank lines in our output is that theprint()function, for our convenience, appends a to the end of any string that we print (otherwise, most of our output would all be on the same line). Thus each line read in from the file is being printed with two characters. We’ll learn how to print without an additional newline later, when we learn how to write data to files. For now, we’ll solve the problem by removing leading and trailing whitespace (spaces, tabs, and newlines) by asking a string to run its.strip()method.

Although we’re callingimport ioagain, it is just for clarity: a program only needs to import a module once (and usually these are collected near the top of the program). Here’s the modified output:

If you feel adventurous (and you should!), you can try method chaining, where the dot syntax for methods can be appended so long as the previous method returned the correct type.

To tie this into earlier concepts, after we’ve extracted each line and stripped off the trailing whitespace, we can use.split(" ")to split each line into a list of strings. From there, we can usefloat()to convert the second element of each into a float type, and compute the mean GC content.

The above prints the average GC content of the three lines as0.523333333. (Because.strip()also returns a string, we could have further chained methods, as inline1_list = fhandle.readline().strip().split(" ").)

Because file handles work like a pipe, they don’t allow for “random access”; we can get the next bit of data out of the end of the pipe, but that’s it.[3] One might think that a command likeline5 = fhandle[4]would work, but instead it would produce an error likeTypeError: '_io.BufferedReader' object has no attribute '__getitem__'.

On the other hand, like lists, file handles are iterable, meaning we can use a for-loop to access each line in order. A simple program to read lines of a file and print them one at a time (without extra blank lines) might look like this:

Like.readline(), using a for-loop extracts lines from the pipe. So, if you call.readline()twice on a file handle attached to a file with 10 lines, and then run a for-loop on that file handle, the for-loop will iterate over the remaining 8 lines. This call could be useful if you want to remove a header line from a text table before processing the remaining lines with a loop, for example.

Writing Data

Writing data to a file works much the same way as reading data: we open a file handle (which again works like a pipe), and call a method on the handle called.write()to write strings to it. In this case, instead of using the"rU"parameter in, we’ll use"w"to indicate that we want to write to the file. Be warned: when you open a file handle for writing in this manner, it overwrites any existing contents of the file. If you’d rather append to the file, you can instead use"a".[4]

Unlike theprint()function, the.write()method of a file handle does not automatically include an additional newline character" ". Thus, if you wish to write multiple lines to a file handle, you have to add them yourself. Here’s an example that prints the numbers0through9to a file, one per line.

As mentioned above, a file handle opened for writing works like a pipe that is set up by the operating system. When writing, however, we put data into the pipe, and the operating system pulls the data out the other side, writing it to the file on disk.

Because the operating system is busy handling similar requests for many programs on the system, it may not get around to pulling the data from the pipe and writing to the file on disk right away. So, it’s important that we remember to call the.close()method on the file handle when we are done writing data; this tells the operating system that any information left in the pipe should be flushed out and saved to disk, and that the pipe structure can be cleaned up. If our program were to crash (or were to be killed) before the handle was properly closed, data in the pipe may never get written.

Computing a Mean

Let’s put many of the skills we’ve learned so far into practice to compute the mean of the E values from the output of BLAST, which is formatted as a simple text table with tabs separating the columns. Here’s what the file, pz_blastx_yeast_top1.txt, looks like inless -S. Although the reader will have to take our word for it, the eleventh column of this file contains E values like5e-14,2e-112, and1e-18.

When solving a problem like this, it’s usually a good idea to first write, in simple English (or your nonprogramming language of choice), the strategy you intend to use to solve the problem. The strategy here will be as follows: the mean of a set of numbers is defined as their sum, divided by the count of them. We’ll need to keep at least two important variables,eval_sumandcounter. After opening the file, we can loop through the lines and extract each E value. (This will require cleaning up the line with.strip(), splitting it into pieces using.split(" "), and finally converting the E value to a float rather than using the string.) For each line that we see, we can add the E value extracted to theeval_sumvariable, and we’ll add1to thecountervariable as well. In the end, we can simply reporteval_sum/counter.

It often helps to convert this strategy into something partway between natural language and code, called pseudocode, which can help tremendously in organizing your thoughts, particularly for complex programs:

import ioopen fhandlecounter = 0sum_eval = 0.0for each line in fhandlelinestripped = line.strip()break into a list of strings with line_list = linestripped.split("	")eval as a string is in line_list at index 10 (11th column)add float(eval) to sum_eval and save in sum_evaladd 1 to count and save in countmean = sum_eval divided by counterprint("mean is " + mean)

With the pseudocode sketched out, we can write the actual code for our program. When executed, it reliably printsMean is: 1.37212611293e-08.

Note that the actual Python code (in ended up looking quite a lot like the pseudocode—this is one of the frequently cited selling points for Python. (For this reason, we’ll also skip the pseudocode step for most examples in this book, though it can still be a valuable technique when programming in any language.)

This may seem like a fair amount of work to compute a simple mean, but it is a consequence of writing software “from scratch,” and we have to start somewhere! Additionally, the benefit of learning these techniques will pay off over the long run when it comes to solving novel problems.

The Process of Programming

Although the process of designing a strategy (and pseudocode) seems tedious, it’s highly recommended. As you progress in your abilities, your strategies and pseudocode will become more terse and higher level, but you should never skip the planning steps before coding. (On the other hand, there is also the danger of over-planning, but this more often effects teams of coders working on large projects.)

There’s another thing worth noting at this point: programs like the above are almost never written top-to-bottom in their entirety, at least not without requiring significant debugging! You may forget that the result of splitting a string results in a list of strings, resulting in an error on a line likeeval_sum = eval_sum + eval_strbecauseeval_sumis a float, whileeval_stris a string. After finding and fixing this error, you may find yet another error if you attempt to print with a line likeprint("Mean is: " + mean), because again the types don’t match and can’t be concatenated. After all this, perhaps you find the resulting mean to unexpectedly be a large number, like131.18, only to find out it was because you accidently usedeval_str = line_list[11], forgetting that list indices start at0.

There are two strategies for avoiding long chains of annoying bugs like this, and harder-to-find (and thus more dangerous) bugs that result in incorrect output that isn’t obviously incorrect. The first strategy is to only write a few lines at a time, and test newly added lines withprint()statements that reveal whether they are doing what they are supposed to. In the example above, you might write a few lines and do some printing to ensure that you can successfully open the file handle and read from it (if the file is large, create a smaller version for testing). Then write a simple for-loop and do some printing to ensure you can successfully loop over the lines of the file and split them into lists of strings. Continue on by filling in some of the code in the for-loop, again printing and testing to ensure the code is doing what you think it is. And so on via iterative development.

The second strategy, to avoid the more dangerous bugs that aren’t immediately obvious, is to test and develop your programs using small files for which you can calculate the answer by hand (or some other trusted process). When you know from testing that your program or even just parts of your program produces the intended output, hidden bugs are much less likely to slip through the cracks. Some people produce several small inputs that represent the variety of different input situations, run the tests, and compare the outputs to the expected results in an automated fashion. This is known as “unit testing,” a common practice in professional software development.

Finally, remember that every programmer, no matter her experience level, gets frustrated from time to time! This is entirely normal, and a good strategy when this happens is to take a brief walk, or even take a break for the day, picking up again the next day. Some find they program efficiently in the morning, others late at night. Whatever you do, avoid the temptation to program by trial and error, mindlessly tweaking the code in the hopes that it will produce the output you want. Even if you succeed this way (which rarely happens), you’re likely to produce code with insidious bugs, and it may well be unreadable even to yourself in a few days’ time.


  1. Write a Python program to compute the sample standard deviation of the E values in the file pz_blastx_yeast_top1.txt. As a reminder, the sample standard deviation is defined as the square root of the sum of squared differences from the mean, divided by the number of values minus 1:

    To accomplish this, you’ll need to make two passes over the data: one as in the example to compute the mean, and another to compute the sum of squared differences. This means you’ll need to access the E values twice. Rather than close and reopen the data file, you should create an initially empty list to which you can append each E value (in your first pass over the data) for later use.

    To compute the square root of a float, you will need to import themathmodule by callingimport mathnear the top of your program. Then themath.sqrt()function will return the square root of a float; for example,math.sqrt(3.0)will return the float1.7320508.

  2. Ifa_listis a list, thenb_list = reversed(a_list)creates a “listreverseiterator” allowing one to loop over the elements with a for-loop in reverse order. Using this information, write a program calledreverse_blast.pythat reads the contents of pz_blastx_yeast_top1.txt and writes the lines in reverse order to a file calledpz_blastx_yeast_top1_reversed.txt.
  3. A quine (after the logician and philosopher W. V. Quine) is a nonempty program that prints its own source code exactly. Use theiomodule and file handles to write a quine (Quine programs aren’t technically allowed to open files. Can you write a program that prints its own source code without using theiomodule?)

So far we’ve encountered two ways of writing values: expression statements and the print() function. (A third way is using the write() method of file objects the standard output file can be referenced as sys.stdout . See the Library Reference for more information on this.)

Often you’ll want more control over the formatting of your output than simply printing space-separated values. There are several ways to format output.

To use formatted string literals , begin a string with f or F before the opening quotation mark or triple quotation mark. Inside this string, you can write a Python expression between < and >characters that can refer to variables or literal values.

The str.format() method of strings requires more manual effort. You’ll still use < and >to mark where a variable will be substituted and can provide detailed formatting directives, but you’ll also need to provide the information to be formatted.

Finally, you can do all the string handling yourself by using string slicing and concatenation operations to create any layout you can imagine. The string type has some methods that perform useful operations for padding strings to a given column width.

When you don’t need fancy output but just want a quick display of some variables for debugging purposes, you can convert any value to a string with the repr() or str() functions.

The str() function is meant to return representations of values which are fairly human-readable, while repr() is meant to generate representations which can be read by the interpreter (or will force a SyntaxError if there is no equivalent syntax). For objects which don’t have a particular representation for human consumption, str() will return the same value as repr() . Many values, such as numbers or structures like lists and dictionaries, have the same representation using either function. Strings, in particular, have two distinct representations.

The string module contains a Template class that offers yet another way to substitute values into strings, using placeholders like $x and replacing them with values from a dictionary, but offers much less control of the formatting.

7.1.1. Formatted String Literals¶

Formatted string literals (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string with f or F and writing expressions as .

An optional format specifier can follow the expression. This allows greater control over how the value is formatted. The following example rounds pi to three places after the decimal:

Passing an integer after the ':' will cause that field to be a minimum number of characters wide. This is useful for making columns line up.

Other modifiers can be used to convert the value before it is formatted. '!a' applies ascii() , '!s' applies str() , and '!r' applies repr() :

For a reference on these format specifications, see the reference guide for the Format Specification Mini-Language .

7.1.2. The String format() Method¶

Basic usage of the str.format() method looks like this:

The brackets and characters within them (called format fields) are replaced with the objects passed into the str.format() method. A number in the brackets can be used to refer to the position of the object passed into the str.format() method.

If keyword arguments are used in the str.format() method, their values are referred to by using the name of the argument.

Positional and keyword arguments can be arbitrarily combined:

If you have a really long format string that you don’t want to split up, it would be nice if you could reference the variables to be formatted by name instead of by position. This can be done by simply passing the dict and using square brackets '[]' to access the keys.

This could also be done by passing the table as keyword arguments with the ‘**’ notation.

This is particularly useful in combination with the built-in function vars() , which returns a dictionary containing all local variables.

As an example, the following lines produce a tidily-aligned set of columns giving integers and their squares and cubes:

For a complete overview of string formatting with str.format() , see Format String Syntax .

7.1.3. Manual String Formatting¶

Here’s the same table of squares and cubes, formatted manually:

(Note that the one space between each column was added by the way print() works: it always adds spaces between its arguments.)

The str.rjust() method of string objects right-justifies a string in a field of a given width by padding it with spaces on the left. There are similar methods str.ljust() and . These methods do not write anything, they just return a new string. If the input string is too long, they don’t truncate it, but return it unchanged this will mess up your column lay-out but that’s usually better than the alternative, which would be lying about a value. (If you really want truncation you can always add a slice operation, as in x.ljust(n)[:n] .)

There is another method, str.zfill() , which pads a numeric string on the left with zeros. It understands about plus and minus signs:

7.1.4. Old string formatting¶

The % operator (modulo) can also be used for string formatting. Given 'string' % values , instances of % in string are replaced with zero or more elements of values . This operation is commonly known as string interpolation. For example:

More information can be found in the printf-style String Formatting section.


The advent of high throughput technologies for the parallel analysis of large groups of genes and proteins has challenged bioinformatics with diverse analytical needs to exploit and interpret the large volume of data produced [1] Many commercial and freeware software packages are available to assist the various phases of generating and analyzing genomics and proteomics data from data acquisition through processing, integration and final data interpretation [2]. The results usually converge in one list of genes or proteins observed to share a common feature like differential regulation, expression pattern and cellular localization.

To assess the scientific novelty of the results obtained – e.g. a list of genes found to be differentially expressed in liver cancer – a number of publicly available text mining tools, such as PubMatrix [3] or MedMiner [4] can be used to explore the scientific literature in a systematic way.

PubMatrix is a web-based tool for text-based mining of the NCBI literature search service PubMed [5], finding associations between one or more gene names and a list of relevant research area keywords such as 'cancer', 'liver', 'over-expressed'. Co-occurrence of a gene's name with specific keywords indicates a possible connection that can be further explored.

To date no equivalent software tools are publicly available to assist researchers in assessing the novelty of findings from the viewpoint of intellectual property (IP) and thus a detailed study of many patents related to each gene or protein in the list is generally necessary. Given the large number of patents usually associated with genes and proteins and the amount of information contained in each patent entry, this is a cumbersome and time consuming activity that needs to be carried out by expert patent professionals. PatentMatrix aims at facilitating a preliminary patent overview by applying a PubMatrix-like approach to the proprietary GENESEQ™ patent sequence database (provided by Derwent Thomson Scientific [6]. The patent entries are accessed through the Sequence Retrieval System (SRS, provided by Biowisdom [7]) and screened for the occurrence of user-defined keywords. In this way it is possible to identify connections between the genes/proteins described in patents and a specific research context as defined by the user-defined keywords. The software also extracts from each GENESEQ™ entry the basic information for a preliminary assessment of the gene/protein IP status. The user is presented with a 'standard' and an 'aggregated' output providing respectively a detailed and a more concise overview – grouped by gene – of the patent analysis results.

2.4: File Input and Output - Biology

Before we describe more about the SMOKE processing, we first need to explain the types of files you will encounter in this documentation. SMOKE primarily uses two types of file formats: ASCII files and I/O API files. In addition, the output file format for the UAM-based air quality model is a Fortran binary file format. Chapter 8, SMOKE Input Files, Chapter 9, SMOKE Intermediate Files, and Chapter 10, SMOKE Output Files describe all input, intermediate, and output files, including the file format for each one. Input files are files that are read by at least one core SMOKE program (listed in Chapter 6, SMOKE Core Programs), but are not written by a core program. Intermediate files are files that are written by a core program and read by at least one other core program. Output files are files output by a SMOKE core program but not read by any of them these files include reports, log files, and the model-ready files to be input to an air quality model. (Exception: one intermediate file [used by a core program] is also an output file [used by an AQM]: the STACK_GROUPS file, described in Section 9.3.2, “ STACK_GROUPS ”.) In this section, we further describe the ASCII and I/O API files, and then provide information about the two approaches for formatting the model-ready output files produced by SMOKE (the CMAQ/Models-3 approach and the UAM-based approach).

SMOKE’s input files are primarily ASCII files, although a few I/O API files are used. The intermediate files in SMOKE are primarily I/O API files, although there are several important ACSII files as well. The output files from SMOKE are primarily I/O API files and Fortran binary files for model-ready emissions files, and ASCII files for reports and logs.

2.5.1. ASCII files

ASCII files are simply the text files with which most computer users are familiar. The ASCII files input by SMOKE come in two structures: column-specific and list-directed . Column-specific ASCII files

In column-specific files, the fields in the files must appear in certain columns in the file. Each character on a line represents a single column. The lines below represent a column-specific ASCII data file:

The letters TEST are in columns 1 through 4 of the file and the numbers 1, 2, and 3 are in columns 6, 8, and 10 respectively: List-directed ASCII files

In list-directed files, the exact positioning of the fields on a line is not important, but the order of the fields on that line is crucial. The fields must be delimited (separated) by special characters called delimiters in SMOKE, valid delimiters are spaces , commas , or semicolons . If a particular field happens to contain any of these delimiters within it, then that field must be surrounded by single or double quotes in the input file.

2.4: File Input and Output - Biology

For some unfathomable reason , Java has never made it easy to read data typed in by the user of a program. You've already seen that output can be displayed to the user using the subroutine System.out.print . This subroutine is part of a pre-defined object called System.out . The purpose of this object is precisely to display output to the user. There is a corresponding object called that exists to read data input by the user, but it provides only very primitive input facilities, and it requires some advanced Java programming skills to use it effectively.

Java 5.0 finally makes input a little easier with a new Scanner class. However, it requires some knowledge of object-oriented programming to use this class, so it's not appropriate for use here at the beginning of this course. (Furthermore, in my opinion, Scanner still does not get things quite right.)

There is some excuse for this lack of concern with input, since Java is meant mainly to write programs for Graphical User Interfaces, and those programs have their own style of input/output, which is implemented in Java. However, basic support is needed for input/output in old-fashioned non-GUI programs. Fortunately, it is possible to extend Java by creating new classes that provide subroutines that are not available in the standard part of the language. As soon as a new class is available, the subroutines that it contains can be used in exactly the same way as built-in routines.

Along these lines, I've written a class called TextIO that defines subroutines for reading values typed by the user of a non-GUI program. The subroutines in this class make it possible to get input from the standard input object, , without knowing about the advanced aspects of Java that are needed to use Scanner or to use directly. TextIO also contains a set of output subroutines. The output subroutines are similar to those provided in System.out , but they provide a few additional features. You can use whichever set of output subroutines you prefer, and you can even mix them in the same program.

To use the TextIO class, you must make sure that the class is available to your program. What this means depends on the Java programming environment that you are using. In general, you just have to add the source code file, , to the same directory that contains your main program. See Section 2.6 for more information about how to use TextIO .

2.4.1 A First Text Input Example

The input routines in the TextIO class are static member functions. (Static member functions were introduced in the previous section.) Let's suppose that you want your program to read an integer typed in by the user. The TextIO class contains a static member function named getlnInt that you can use for this purpose. Since this function is contained in the TextIO class, you have to refer to it in your program as TextIO.getlnInt . The function has no parameters, so a complete call to the function takes the form " TextIO.getlnInt() ". This function call represents the int value typed by the user, and you have to do something with the returned value, such as assign it to a variable. For example, if userInput is a variable of type int (created with a declaration statement " int userInput "), then you could use the assignment statement

When the computer executes this statement, it will wait for the user to type in an integer value. The value typed will be returned by the function, and it will be stored in the variable, userInput . Here is a complete program that uses TextIO.getlnInt to read a number typed by the user and then prints out the square of the number that the user types:

When you run this program, it will display the message "Please type a number:" and will pause until you type a response, including a carriage return after the number. Here is an applet that simulates the program. (Note: If the applet does not respond to your typing, you might have to click on it to activate it. In some browsers, you might also need to leave the mouse cursor inside the applet for it to recognize your typing.)

2.4.2 Text Output

The TextIO class contains static member subroutines TextIO.put and TextIO.putln that can be used in the same way as System.out.print and System.out.println . For example, although there is no particular advantage in doing so in this case, you could replace the two lines

For the next few chapters, I will use TextIO for input in all my examples, and I will often use it for output. Keep in mind that TextIO can only be used in a program if it is available to that program. It is not built into Java in the way that the System class is.

Let's look a little more closely at the built-in output subroutines System.out.print and System.out.println . Each of these subroutines can be used with one parameter, where the parameter can be a value of any of the primitive types byte , short , int , long , float , double , char , or boolean . The parameter can also be a String , a value belonging to an enum type, or indeed any object. That is, you can say " System.out.print(x) " or " System.out.println(x) ", where x is any expression whose value is of any type whatsoever. The expression can be a constant, a variable, or even something more complicated such as 2*distance*time . Now, in fact, the System class actually includes several different subroutines to handle different parameter types. There is one System.out.print for printing values of type double , one for values of type int , another for values that are objects, and so on. These subroutines can have the same name since the computer can tell which one you mean in a given subroutine call statement, depending on the type of parameter that you supply. Having several subroutines of the same name that differ in the types of their parameters is called overloading . Many programming languages do not permit overloading, but it is common in Java programs.

The difference between System.out.print and System.out.println is that the println version outputs a carriage return after it outputs the specified parameter value. There is a version of System.out.println that has no parameters. This version simply outputs a carriage return, and nothing else. A subroutine call statement for this version of the program looks like " System.out.println() ", with empty parentheses. Note that " System.out.println(x) " is exactly equivalent to " System.out.print(x) System.out.println() " the carriage return comes after the value of x . (There is no version of System.out.print without parameters. Do you see why?)

As mentioned above, the TextIO subroutines TextIO.put and TextIO.putln can be used as replacements for System.out.print and System.out.println . The TextIO functions work in exactly the same way as the System functions, except that, as we will see below, TextIO can also be used to write to other destinations.

2.4.3 TextIO Input Functions

The TextIO class is a little more versatile at doing output than is System.out . However, it's input for which we really need it.

With TextIO , input is done using functions. For example, TextIO.getlnInt() , which was discussed above, makes the user type in a value of type int and returns that input value so that you can use it in your program. TextIO includes several functions for reading different types of input values. Here are examples of the ones that you are most likely to use:

For these statements to be legal, the variables on the left side of each assignment statement must already be declared and must be of the same type as that returned by the function on the right side. Note carefully that these functions do not have parameters. The values that they return come from outside the program, typed in by the user as the program is running. To "capture" that data so that you can use it in your program, you have to assign the return value of the function to a variable. You will then be able to refer to the user's input value by using the name of the variable.

When you call one of these functions, you are guaranteed that it will return a legal value of the correct type. If the user types in an illegal value as input -- for example, if you ask for an int and the user types in a non-numeric character or a number that is outside the legal range of values that can be stored in in a variable of type int -- then the computer will ask the user to re-enter the value, and your program never sees the first, illegal value that the user entered. For TextIO.getlnBoolean() , the user is allowed to type in any of the following: true, false, t, f, yes, no, y, n, 1, or 0. Furthermore, they can use either upper or lower case letters. In any case, the user's input is interpreted as a true/false value. It's convenient to use TextIO.getlnBoolean() to read the user's response to a Yes/No question.

You'll notice that there are two input functions that return Strings. The first, getlnWord() , returns a string consisting of non-blank characters only. When it is called, it skips over any spaces and carriage returns typed in by the user. Then it reads non-blank characters until it gets to the next space or carriage return. It returns a String consisting of all the non-blank characters that it has read. The second input function, getln() , simply returns a string consisting of all the characters typed in by the user, including spaces, up to the next carriage return. It gets an entire line of input text. The carriage return itself is not returned as part of the input string, but it is read and discarded by the computer. Note that the String returned by this function might be the empty string , "" , which contains no characters at all. You will get this return value if the user simply presses return, without typing anything else first.

All the other input functions listed -- getlnInt() , getlnDouble() , getlnBoolean() , and getlnChar() -- behave like getWord() in that they will skip past any blanks and carriage returns in the input before reading a value.

Furthermore, if the user types extra characters on the line after the input value, all the extra characters will be discarded, along with the carriage return at the end of the line. If the program executes another input function, the user will have to type in another line of input. It might not sound like a good idea to discard any of the user's input, but it turns out to be the safest thing to do in most programs. Sometimes, however, you do want to read more than one value from the same line of input. TextIO provides the following alternative input functions to allow you to do this:

The names of these functions start with "get" instead of "getln". "Getln" is short for "get line" and should remind you that the functions whose names begin with "getln" will get an entire line of data. A function without the "ln" will read an input value in the same way, but will then save the rest of the input line in a chunk of internal memory called the input buffer . The next time the computer wants to read an input value, it will look in the input buffer before prompting the user for input. This allows the computer to read several values from one line of the user's input. Strictly speaking, the computer actually reads only from the input buffer. The first time the program tries to read input from the user, the computer will wait while the user types in an entire line of input. TextIO stores that line in the input buffer until the data on the line has been read or discarded (by one of the "getln" functions). The user only gets to type when the buffer is empty.

Clearly, the semantics of input is much more complicated than the semantics of output! Fortunately, for the majority of applications, it's pretty straightforward in practice. You only need to follow the details if you want to do something fancy. In particular, I strongly advise you to use the "getln" versions of the input routines, rather than the "get" versions, unless you really want to read several items from the same line of input, precisely because the semantics of the "getln" versions is much simpler.

Note, by the way, that although the TextIO input functions will skip past blank spaces and carriage returns while looking for input, they will not skip past other characters. For example, if you try to read two int s and the user types "2,3", the computer will read the first number correctly, but when it tries to read the second number, it will see the comma. It will regard this as an error and will force the user to retype the number. If you want to input several numbers from one line, you should make sure that the user knows to separate them with spaces, not commas. Alternatively, if you want to require a comma between the numbers, use getChar() to read the comma before reading the second number.

There is another character input function, TextIO.getAnyChar() , which does not skip past blanks or carriage returns. It simply reads and returns the next character typed by the user, even if it's a blank or carriage return. If the user typed a carriage return, then the char returned by getAnyChar() is the special linefeed character ' '. There is also a function, TextIO.peek() , that lets you look ahead at the next character in the input without actually reading it. After you "peek" at the next character, it will still be there when you read the next item from input. This allows you to look ahead and see what's coming up in the input, so that you can take different actions depending on what's there.

The TextIO class provides a number of other functions. To learn more about them, you can look at the comments in the source code file, .

(You might be wondering why there are only two output routines, print and println , which can output data values of any type, while there is a separate input routine for each data type. As noted above, in reality there are many print and println routines, one for each data type. The computer can tell them apart based on the type of the parameter that you provide. However, the input routines don't have parameters, so the different input routines can only be distinguished by having different names.)

Using TextIO for input and output, we can now improve the program from Section 2.2 for computing the value of an investment. We can have the user type in the initial value of the investment and the interest rate. The result is a much more useful program -- for one thing, it makes sense to run it more than once!

Try out an equivalent applet here. (If the applet does not respond to your typing, you might have to click on it to activate it.)

By the way, the applets on this page don't actually use TextIO itself. The TextIO class is only for use in programs, not applets. For applets, I have written a separate class that provides similar input/output capabilities in a Graphical User Interface program. Remember that the applets are only simulations of the programs.

2.4.4 Formatted Output

If you ran the preceding Interest2 example, you might have noticed that the answer is not always written in the format that is usually used for dollar amounts. In general, dollar amounts are written with two digits after the decimal point. But the program's output can be a number like 1050.0 or 43.575. It would be better if these numbers were printed as 1050.00 and 43.58.

Java 5.0 introduced a formatted output capability that makes it much easier than it used to be to control the format of output numbers. A lot of formatting options are available. I will cover just a few of the simplest and most commonly used possibilities here.

You can use the function System.out.printf to produce formatted output. (The name "printf," which stands for "print formatted," is copied from the C and C++ programming languages, which have always have a similar formatting capability). System.out.printf takes two or more parameters. The first parameter is a String that specifies the format of the output. This parameter is called the format string . The remaining parameters specify the values that are to be output. Here is a statement that will print a number in the proper format for a dollar amount, where amount is a variable of type double :

TextIO can also do formatted output. The function TextIO.putf has the same functionality as System.out.printf . Using TextIO , the above example would be: TextIO.printf("%1.2",amount) and you could say TextIO.putln("%1.2f",principal) instead of TextIO.putln(principal) in the Interest2 program to get the output in the right format.

The output format of a value is specified by a format specifier . The format string (in the simple cases that I cover here) contains one format specifier for each of the values that is to be output. Some typical format specifiers are %d , %12d , %10s , %1.2f , %15.8e and %1.8g . Every format specifier begins with a percent sign ( % ) and ends with a letter, possibly with some extra formatting information in between. The letter specifies the type of output that is to be produced. For example, in %d and %12d , the "d" specifies that an integer is to be written. The "12" in %12d specifies the minimum number of spaces that should be used for the output. If the integer that is being output takes up fewer than 12 spaces, extra blank spaces are added in front of the integer to bring the total up to 12. We say that the output is "right-justified in a field of length 12." The value is not forced into 12 spaces if the value has more than 12 digits, all the digits will be printed, with no extra spaces. The specifier %d means the same as %1d that is an integer will be printed using just as many spaces as necessary. (The "d," by the way, stands for "decimal" (base-10) numbers. You can use an "x" to output an integer value in hexadecimal form.)

The letter "s" at the end of a format specifier can be used with any type of value. It means that the value should be output in its default format, just as it would be in unformatted output. A number, such as the "10" in %10s can be added to specify the (minimum) number of characters. The "s" stands for "string," meaning that the value is converted into a String value in the usual way.

The format specifiers for values of type double are even more complicated. An "f", as in %1.2f , is used to output a number in "floating-point" form, that is with digits after the decimal point. In %1.2f , the "2" specifies the number of digits to use after the decimal point. The "1" specifies the (minimum) number of characters to output, which effectively means that just as many characters as are necessary should be used. Similarly, %12.3f would specify a floating-point format with 3 digits after the decimal point, right-justified in a field of length 12.

Very large and very small numbers should be written in exponential format, such as 6.00221415e23, representing "6.00221415 times 10 raised to the power 23." A format specifier such as %15.8e specifies an output in exponential form, with the "8" telling how many digits to use after the decimal point. If you use "g" instead of "e", the output will be in floating-point form for small values and in exponential form for large values. In %1.8g , the 8 gives the total number of digits in the answer, including both the digits before the decimal point and the digits after the decimal point.

In addition to format specifiers, the format string in a printf statement can include other characters. These extra characters are just copied to the output. This can be a convenient way to insert values into the middle of an output string. For example, if x and y are variables of type int , you could say

When this statement is executed, the value of x is substituted for the first %d in the string, the value of y for the second %d , and the value of the expression x*y for the third, so the output would be something like "The product of 17 and 42 is 714" (quotation marks not included in output!).

2.4.5 Introduction to File I/O

System.out sends its output to the output destination known as "standard output." But standard output is just one possible output destination. For example, data can be written to a file that is stored on the user's hard drive. The advantage to this, of course, is that the data is saved in the file even after the program ends, and the user can print the file, email it to someone else, edit it with another program, and so on.

TextIO has the ability to write data to files and to read data from files. When you write output using the put , putln , or putf method in TextIO , the output is sent to the current output destination. By default, the current output destination is standard output. However, TextIO has some subroutines that can be used to change the current output destination. To write to a file named "result.txt", for example, you would use the statement:

After this statement is executed, any output from TextIO output statements will be sent to the file named "result.txt" instead of to standard output. The file should be created in the same directory that contains the program. Note that if a file with the same name already exists, its previous contents will be erased! In many cases, you want to let the user select the file that will be used for output. The statement

will open a typical graphical-user-interface file selection dialog where the user can specify the output file. If you want to go back to sending output to standard output, you can say

You can also specify the input source for TextIO's various "get" functions. The default input source is standard input. You can use the statement TextIO.readFile("data.txt") to read from a file named "data.txt" instead, or you can let the user select the input file by saying TextIO.readUserSelectedFile() , and you can go back to reading from standard input with TextIO.readStandardInput() .

When your program is reading from standard input, the user gets a chance to correct any errors in the input. This is not possible when the program is reading from a file. If illegal data is found when a program tries to read from a file, an error occurs that will crash the program. (Later, we will see that is is possible to "catch" such errors and recover from them.) Errors can also occur, though more rarely, when writing to files.

A complete understanding of file input/output in Java requires a knowledge of object oriented programming. We will return to the topic later, in Chapter 11. The file I/O capabilities in TextIO are rather primitive by comparison. Nevertheless, they are sufficient for many applications, and they will allow you to get some experience with files sooner rather than later. Output¶

This section of the primary FAST input file deals with what can be output from a FAST simulation, except for linearization and visualization output, which are included in the subsequent sections.

Print summary data to “<RootName>.sum” [T/F]

When set to “True”, FAST will generate a file named “<RootName>.sum”. This summary file contains the version number of all modules being used, the time steps for each module, and information about the channels being written to the time-marching output file(s). If SumPrint is “False”, no summary file will be generated.

Amount of time between screen status messages [s]

During a FAST simulation, the program prints a message like this: SttsTime sets how frequently this message is updated. For example, if SttsTime is 2 seconds, you will see this message updated every 2 seconds of simulated time.

Amount of time between creating checkpoint files for potential restart [s]

This input determines how frequently checkpoint files should be written. Checkpoint files are used for restart capability we recommend that short simulations set ChkptTime to be larger than the simulation time, TMax. For more information on checkpoint files and restart capability in FAST, see sections “Checkpoint Files (Restart Capability)”and “Restart: Starting FAST from a checkpoint file” in this document. ChkptTime is ignored in the FAST-Simulink interface, and must be larger than TMax when using the FAST-OrcaFlex interface (CompMooring = 4).

Time step for tabular output [s]

This is the time step of the data in the tabular (time-marching) output files. DT_Out must be an integer multiple of DT. Alternatively, DT_Out can be entered as the string “default”, which will set DT_Out = DT.

Time to begin tabular output [s]

This is the time step that must be reached before FAST will begin writing data in the tabular (time-marching) output files. Note that the output files may not actually start at TStart seconds if TStart is not an integer multiple of DT_Out.

Format for tabular output [1, 2, or 3]

Use tab delimiters in text tabular output file? [T/F]

When OutFileFmt = 1 or 3, setting TabDelim to “True” will put tabs between columns in the text tabular (time-marching) output file. Otherwise, spaces will separate columns in the text tabular output file. If OutFileFmt = 2, TabDelim has no effect.

Format used for text tabular output, excluding the time channel [-]

When OutFileFmt = 1 or 3, FAST will use OutFmt to format the channels printed in the text tabular output file. OutFmt should result in a field that is 10 characters long (channel headers are 10 characters long, and NWTC post-processing software sometimes assume 10 characters). The time channel is printed using the “F10.4” format. We commonly specify OutFmt to be “ES10.3E2”. If OutFileFmt = 2, OutFmt has no effect.

(*) This indicates which type of tabular (time-marching) output files will be generated. If OutFileFmt is 1, only a text file will be written. If OutFileFmt is 2, only a binary file will be written. If OutFileFmt is 3, both text and binary files will be written. Text files write a line to the file each output time step. This can make the simulation run slower, but it can be useful for debugging, particularly if a simulation doesn’t run to completion or if you want to look at some results before the entire simulation finishes. Binary files are written in their entirety at the end of the simulation . If a lot of output channels are requested for a long simulation, this can take up a moderate amount of memory. However, they tend to run faster and the resulting files take up much less space. The binary files contain more precise output data than text files, which are limited by the chosen output format specifier—see OutFmt below. We recommend you use text files for debugging and binary files for production work. A MATLAB script for reading FAST binary output files is included in the OpenFAST Matlab Toolbox repository. Python code to read FAST output files is distributed with OpenFAST in the regression test framework’s fast_io module. The NREL post-processors Crunch and MCrunch can also read these binary files.

2.2. Modeling styles¶

In Verilog, the model can be designed in four ways as shown in this section. Two bit comparator is designed with different styles which generates the output ‘1’ if the numbers are equal, otherwise output is set to ‘0’.

2.2.1. Continuous assignment statements¶

In this modeling style, the relation between input and outputs are defined using signal assignments. ‘assign’ keyword is used for this purpose. In the other words, we do not define the structure of the design explicitly we only define the relationships between the signals and structure is implicitly created during synthesis process.

Explanation Listing 2.1 :

Listing 2.1 is the example of ‘Continuous assignment statements’ design, where relationship between inputs and output are given in line 8. In verilog, ‘&’ sign is used for ‘and’ operation (line 8), and ‘//’ is used for comments (line 1). The ‘and gate (i.e. RTL view)’ generated by Listing 2.1 is shown in Fig. 2.1 .


To see the RTL view of the design, go to Tools–>Netlist Viewers–>RTL viewer

Note that, in lines 4 and 5, ‘wire’ keyword is used which is the ‘data type’. For continuous assignment statements ‘wire’ keyword is used whereas ‘reg’ keyword is used for procedural assignment statement. Further, input ports can not be defined as ‘reg’. Note that, these keyword are not interchangeable and the differences between these ‘data types’ are discussed in Section 2.2.4 . Further, more operators e.g. ‘and’, ‘not’ and ‘nand’ etc. are discussed in Chapter 3 .

Listing 2.1 can be written as Listing 2.2 , where module-definition contains name of ports only (Line 3) and types of ports are defined outside the module (Lines 5-6).

2.2.2. Comparators using Continuous assignment statements¶

In this section, two more examples of Continuous assignment statements are shown i.e. ‘1 bit’ and ‘2 bit’ comparators which are used to demonstrate the differences between various modeling styles in the tutorial. Fig. 2.2 and Fig. 2.3 show the truth tables of ‘1 bit’ and ‘2 bit’ comparators. As the name suggests, the comparator compare the two values and sets the output ‘eq’ to 1, when both the input values are equal otherwise ‘eq’ is set to zero. The corresponding boolean expressions are shown below,

Above two expressions are implemented using verilog in Listing 2.3 and Listing 2.4 , which are explained below.

Explanation Listing 2.3 :

Listing 2.3 implements the 1 bit comparator based on (2.1). Two intermediate signals are defined in Line 8. These two signals (s0 and s1) are defined to store the values of x’y’ and xy respectively. Values to these signals are assigned at Lines 10 and 11. In verilog, ‘not’ and ‘or’ operations are implemented using ‘

’ and ‘|’ signs as shown in Line 10 and 12 respectively. Finally (2.1) performs ‘or’ operation on these two signals, which is done at Line 12. When we compile this code using ‘Quartus software’, it implements the code into hardware design as shown in Fig. 2.4 .

The compilation process to generate the design is shown in Appendix 17 . Also, we can check the input-output relationships of this design using Modelsim, which is also discussed briefly in Appendix 17 .

Note that, the statements in ‘Continuous assignment statements’ and ‘structural modeling’ (described in Section 2.2.3 ) are the concurrent statements, i.e. these statements execute in parallel. In the other words, order of statements do not affect the behavior of the circuit e.g. if we exchange the Lines 10, 11 and 12 in Listing 2.3 , again we will get the Fig. 2.4 as implementation.

On the other hand, statements in ‘Procedural assignment statements’ (described in Section 2.2.4 ) executes sequentially and any changes in the order of statements will change the behavior of circuit.

Explanation :numref: Fig. 2.4

Fig. 2.4 is generated by Quartus software according to the verilog code shown in Listing 2.3 . Here, s0 is the ‘and’ gate with inverted inputs x and y, which are generated according to Line 10 in Listing 2.3 . Similarly, s1 ‘and’ gate is generated according to Line 11. Finally output of these two gates are applied to ‘or’ gate (named as ‘eq’) which is defined at Line 12 of the Listing 2.3 .

Explanation Listing 2.4

This listing implements the equation (2.2). Here, we are using two bit input, therefore ‘wire[1:0]’ is used at line 4. ‘1:0’ sets the 1 as MSB (most significant bit) and 0 as LSB(least significant bit) i.e. the a[1] and b[1] are the MSB, whereas a[0] and b[0] are the LSB. Since we need to store four signals (lines 10-13), therefore ‘s’ is defined as 4-bit vector in line 8. Rest of the working is same as Listing 2.3 . The implementation of this listing is shown in Fig. 2.5 .

2.2.3. Structural modeling¶

In previous section, we designed the 2 bit comparator based on equation (2.2) . Further, we can design the 2 bit comparator using 1-bit comparator as well, with following steps,

  • First compare each bit of 2-bit numbers using 1-bit comparator i.e. compare a[0] with b[0] and a[1] with b[1] using 1-bit comparator (as shown in Fig. 2.3 ).
  • If both the values are equal, then set the output ‘eq’ as 1, otherwise set it to zero.

This method is known as ‘structural’ modeling, where we use the pre-defined designs to create the new designs (instead of implementing the ‘boolean’ expression). This method is quite useful, because most of the large-systems are made up of various small design units. Also, it is easy to create, simulate and check the various small units instead of one large-system. Listing 2.5 is the example of structural designs, where 1-bit comparator is used to created a 2-bit comparator.

Explanation Listing 2.5

In this listing, Lines 4-5 define the two input ports of 2-bit size and one 1-bit output port. Then two signals are defined (Line 8) to store the outputs of two 1-bit comparators, as discussed below.

‘eq_bit0’ and ‘eq_bit1’ in Lines 10 and 11 are the names of the two 1-bit comparator, which are used in this design. We can see these names in the resulted design, which is shown in Listing 2.5 .

Next, ‘comparator1Bit’ in Lines 10 and 11 is the name of the 1-bit comparator (defined in Listing 2.3 ). With this declaration, i.e. comparator1bit, we are calling the design of 1-bit comparator to current design.

Then, mapping statements e.g. .x(a[0]) in Lines 10 and 11, are assigning the values to the input and output port of 1-bit comparator. For example, in Line 10, input ports of 1-bit comparator i.e. x and y, are assigned the values of a[0] and b[0] respectively from this design and the output y of 1-bit comparator is stored in the signal s0. Further, in Line 13, if signals s0 and s1 are 1 then ‘eq’ is set to 1 using ‘and’ gate, otherwise it will be set to 0. Final design generated by Quartus software for Listing 2.5 is shown in Fig. 2.6 .

Explanation Fig. 2.6

In this figure, a[1..0] and b[1..0] are the input bits whereas ‘eq’ is the output bit. Thick Lines after a[1..0] and b[1..0] show that there are more than 1 bits e.g. in this case these Lines have two bits. These thick Lines are changed to thin Lines before going to comparators which indicates that only 1 bit is sent as input to comparator.

In ‘comparator1Bit: eq_bit0’, ‘comparator1Bit’ is the name of the module defined for 1-bit comparator ( Listing 2.3 ) whereas the ‘eq_bit0’ is the name of this module defined in Line 10 of listing Listing 2.5 . Lastly outputs of two 1-bit comparator are sent to ‘and’ gate according to Line 13 in listing Listing 2.5 .

Hence, from this figure we can see that the 2-bit comparator can be designed by using two 1-bit comparator.

2.2.4. Procedural assignment statements¶

In Procedural assignment statements, the ‘always’ keyword is used and all the statements inside the always statement execute sequentially. Various conditional and loop statements can be used inside the process block as shown in Listing 2.6 . Further, always blocks are concurrent blocks, i.e. if the design has multiple always blocks (see Listing 2.7 ), then all the always blocks will execute in parallel.

Explanation Listing 2.6 :

The ‘always’ block is declared in Line 8, which begins and ends at Line 9 and 14 respectively. Therefore all the statements between Line 9 to 14 will execute sequentially and Quartus Software will generate the design based on the sequences of the statements. Any changes in the sequences will result in different design.

Note that, the output port ‘eq’ is declared as reg at Line 5. If we assign value to the signal inside the ‘always’ block then that signal must be declared as ‘reg’ e.g. value of ‘eq’ is assigned in Line 11 and 13, which are inside the ‘always’ block hence ‘eq’ is declared as reg.

The ‘always’ keyword takes two arguments in Line 8 (known as ‘sensitivity list’), which indicates that the process block will be executed if and only if there are some changes in ‘a’ and ‘b’. ‘@’ is used after ‘always’ for defining the sensitivity list. In Line 10-13, the ‘if’ statement is declared which sets the value of ‘eq’ to 1 if both the bits are equal (Line 10-11), otherwise ‘eq’ will be set to 0 (Line 12-13). Fig. 2.7 shows the design generated by the Quartus Software for this listing. ‘==’ in Line 10 is one of the condition operators whereas && is the logical operator, which are discussed in detail in Chapter 3 .

Section 33. Command Codes EFTNT, EFTAD and EFTOF for Electronic Funds Transfer

Manual Transmittal


(1) This transmits revised IRM 2.4.33, IDRS Terminal Input, Command Codes EFTNT, EFTAD and EFTOF for Electronic Funds Transfer.

Material Changes

(1) Command Code EFTNT will now require that the Bank Number and Bank Account Number be entered twice on the input screen. If the two fields are not equal an error will be returned.

Effect on Other Documents


Effective Date

Terence V. Milholland
Chief Technology Officer

General Information of EFT Command Codes

This section contains instructions for accessing and using Command Codes (CC) EFTNT, EFTAD, and EFTOF. These Command Codes are utilized by Collection personnel in the Campuses for establishing, reviewing, updating or skipping Electronic Fund Transfers (EFT) for Direct Debit Installment Agreements (DDIA).

Command Code EFTNT

Command Code EFTNT is used for entering new DDIA EFT bank information. OR CORRECTING Existing Bank Information.

Command Code EFTNT with a blank definer

Command Code EFTNT should only be accessed by using Command Code IAGRE, IAORG or IAREV. This is the prerequisite for accessing Command Code EFTNT for inputting new or changing existing bank information. Exhibit 2.4.33–3. Command Code EFTNT with definer F is the prerequisite for inputting Command Code EFTNT with a blank definer.

Terminal Output Responses for EFTNT:

"REQUEST COMPLETED " , displayed on screen line 24 indicates that no error conditions occurred in accepting the bank information input from CC IAORG, IAPND, or IAREV.

"PLEASE CORRECT INVALID DATA" , displayed on screen line 24 indicates that an input field is not properly formatted or contains an improper value. The invalid field will be marked with an asterisk (*).

"ACCOUNT TRANSFERRED UPDATE NOT ALLOWED" , displayed on screen line 24 indicates that the account has been transferred to another Service Center.

"PAYMNT PRESENT ON EFT ACCNT-CHECK CC EFTAD" , displayed on screen line 24 indicates that there is a payment request to be extracted today. A pre-note cannot be processed if a payment request is present.

Command Code EFTNT with definer F

Command Code EFTNT with F definer is used only to update or correct existing bank information. To use this Command Code it must be entered after accessing either IAGRE, IAORG or IAREV (See IRM 2.4.30) . These are the prerequisite CC for using EFTNT with definer F. Exhibit 2.4.33–1

See exhibit 2.4.33-2 for bank information format

Terminal Output Responses for EFTNT with definer F:

"REQUEST DENIED/IMPROPER INITIALIZATION " , displayed on screen line 24 indicates CC EFTNT with definer F was not preceded by CC IAGRE, IAORG or IAREV.

"ACCOUNT NOT EFT INSTALLMENT STATUS" , displayed on screen line 24 indicates that the preceding CC IAGRE, IAORG or IAREV input did not contain the EFT indicator.

"REQUEST COMPLETED" , displayed on screen line 24 indicates that no error conditions occurred in accepting the bank information input from CC IAORG, IAPND, or IAREV.

"PLEASE CORRECT INVALID DATA" , displayed on screen line 24 indicates that an input field is not properly formatted or contains an improper value. The invalid field will be marked with an asterisk (*).

Command Code EFTAD

This Command Code with a blank definer is used to obtain bank information and payment data for a specified TIN. Exhibit 2.4.33–4.

Terminal Output Responses for CC EFTAD

See Exhibit 2.4.33–5 for bank information and payment data format.

"INVALID TIN" , displayed on screen line 24 indicates that the input TIN is not formatted properly or contains an invalid value.

"ACCOUNT NOT ON FILE" , displayed on screen line 24 indicates that the input TIN is not present on the EFT File.

"PAYT REJECTED BY ACH BANK" , displayed on screen line 9 indicates that the EFT request was processed by the bank and returned for non-payment.

Command Code EFTAD with definer D

This Command Code with definer D and a valid two digit Service Center Code (07,08,09,17,18,19,28,29,49 and 89) are used to obtain deposit information and payment data for a specified deposit date. Exhibit 2.4.33–6.

Terminal Output Responses:

See Exhibit 2.4.33–7 for deposit information and payment data format.

"INVALID DATE" , displayed on screen line 24 indicates that the input date is not formatted properly or contains an invalid value.

"NO DATA AVAILABLE FOR ALN XX" , displayed on screen line 24 indicates that the requested date for the particular ALN is not an actual deposit date (weekend or holiday) or the requested date has not yet been processed.

YOU MUST ENTER A VALID CAMPUS CODE displayed on screen line 24 indicates that a valid two digit campus code needs to be entered to see the deposit dates for that campus

Command Code EFTAD with definer Z

This Command Code with definer Z with a valid two digit Service Center Code (07,08,09,17,18,19,28,29,49 and 89) will be used to obtain deposit dates which are 10 days before and 5 days after current date on the Electronic Funds Transfer File. Exhibit 2.4.33–8.

Terminal Output Responses:

See Exhibit 2.4.33–9 for deposit dates format.

"NO DATA AVAILABLE FOR ALN XX" , displayed on screen line 24 indicates that no deposit dates are present on EFTF.

"NOT SENT" , displayed on screen indicates that the deposit date is present on the EFTF but has not yet been extracted for transmission to the clearing house bank.

"SENT TO BANK" , displayed on screen indicates that the deposit date is present on the EFTF and pre-notes and payment requests associated with this deposit date have been extracted to be sent to the clearing house bank.

YOU MUST ENTER A VALID CAMPUS CODE displayed on screen line 24 indicates that a valid two digit campus code needs to be entered to see the requested range of deposit t dates for that campus


Terminal Output Response "INVALID DEFINER" , displayed on screen line 24 indicates that the definer was not blank, "D" , or " Z" .

Command Code EFTOF

This Command Code is used to stop an Electronic Funds Transfer request to the bank for a specified TIN and installment date. This request is used only when the EFT File has been updated to include the input installment date. Also, the request must precede the transmittance of the EFT payment request to the Clearing House Bank. Exhibit 2.4.33–10.

Terminal Output Responses: Exhibit 2.4.33–11.

"REQUEST COMPLETED " , displayed on screen line 13 indicates that the EFT stop payment request has been processed.

"INVALID TIN" , displayed on screen line 13 indicates that the input TIN is not formatted properly or contains an invalid value.

"INVALID DATE" , displayed on screen line 13 indicates that the request date is not formatted properly or contains an invalid value.

"EFT DATA NOT AVAILABLE " , displayed on screen line 13 indicates that the input TIN is not present on the EFT File.

"ERRONEOUS INSTALLMENT DATE" , displayed on screen line 13 indicates that the requested date is not a correct installment date for the input TIN or that the EFT File has not been updated to include the requested date.

"PAYMENT REQUEST SENT TO BANK" , displayed on screen line 13 indicates that the EFT request has been generated to the bank for processing.

"PAYMENT REQUEST REJECTED BY BANK" , displayed on screen line 13 indicates that the EFT request was processed by the bank and returned for non-payment.

"PAYMENT REQUEST PREVIOUSLY SUPPRESSED" , displayed on screen line 13 indicates that CC EFTOF had been input previously for the input TIN and installment date.

"ACCOUNT TRANSFERRED UPDATE NOT ALLOWED" , displayed on screen line 13 indicates that the account has been transferred to another Service Center.

"INVALID DEFINER " , displayed on screen line 13 indicates that the definer was not blank.

"PAYMENT REQUEST REJECTED PRE NOTE INFO" , displayed on screen line 13 indicates that pre-note was rejected by bank.

YOU MUST ENTER A VALID CAMPUS CODEdisplayed on screen line 24 indicates that a valid two digit campus code in which the account resides needs to be entered. (07,08,09,17,18,19,28,29,49 and 89)

Exposing Filters as an HTTP Service

Filters can be used to process content originating from the client in addition to processing content originating on the server using the mod_reflector module.

mod_reflector accepts POST requests from clients, and reflects the content request body received within the POST request back in the response, passing through the output filter stack on the way back to the client.

This technique can be used as an alternative to a web service running within an application server stack, where an output filter provides the transformation required on the request body. For example, the mod_deflate module might be used to provide a general compression service, or an image transformation filter might be turned into an image transformation service.

Basic Input/Output

The example programs of the previous sections provided little interaction with the user, if any at all. They simply printed simple values on screen, but the standard library provides many additional ways to interact with the user via its input/output features. This section will present a short introduction to some of the most useful.

C++ uses a convenient abstraction called streams to perform input and output operations in sequential media such as the screen, the keyboard or a file. A is an entity where a program can either insert or extract characters to/from. There is no need to know details about the media associated to the stream or any of its internal specifications. All we need to know is that streams are a source/destination of characters, and that these characters are provided/accepted sequentially (i.e., one after another).

The standard library defines a handful of stream objects that can be used to access what are considered the standard sources and destinations of characters by the environment where the program runs:

cin standard input stream
cout standard output stream
cerr standard error (output) stream
clog standard logging (output) stream

We are going to see in more detail only cout and cin (the standard output and input streams) cerr and clog are also output streams, so they essentially work like cout , with the only difference being that they identify streams for specific purposes: error messages and logging which, in many cases, in most environment setups, they actually do the exact same thing: they print on screen, although they can also be individually redirected.

Standard output (cout)

On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout .

For formatted output operations, cout is used together with the insertion operator, which is written as << (i.e., two "less than" signs).

The << operator inserts the data that follows it into the stream that precedes it. In the examples above, it inserted the literal string Output sentence , the number 120 , and the value of variable x into the standard output stream cout . Notice that the sentence in the first statement is enclosed in double quotes ( " ) because it is a string literal, while in the last one, x is not. The double quoting is what makes the difference when the text is enclosed between them, the text is printed literally when they are not, the text is interpreted as the identifier of a variable, and its value is printed instead. For example, these two sentences have very different results:

Multiple insertion operations (<<) may be chained in a single statement:

This last statement would print the text This is a single C++ statement . Chaining insertions is especially useful to mix literals and variables in a single statement:

Assuming the age variable contains the value 24 and the zipcode variable contains 90064, the output of the previous statement would be:

I am 24 years old and my zipcode is 90064
What cout does not do automatically is add line breaks at the end, unless instructed to do so. For example, take the following two statements inserting into cout :
cout << "This is a sentence."
cout << "This is another sentence."

The output would be in a single line, without any line breaks in between. Something like:

This is a sentence.This is another sentence.
To insert a line break, a new-line character shall be inserted at the exact position the line should be broken. In C++, a new-line character can be specified as (i.e., a backslash character followed by a lowercase n ). For example:

This produces the following output:

First sentence.
Second sentence.
Third sentence.

Alternatively, the endl manipulator can also be used to break lines. For example:

First sentence.
Second sentence.

The endl manipulator produces a newline character, exactly as the insertion of ' ' does but it also has an additional behavior: the stream's buffer (if any) is flushed, which means that the output is requested to be physically written to the device, if it wasn't already. This affects mainly fully buffered streams, and cout is (generally) not a fully buffered stream. Still, it is generally a good idea to use endl only when flushing the stream would be a feature and ' ' when it would not. Bear in mind that a flushing operation incurs a certain overhead, and on some devices it may produce a delay.

Standard input (cin)

In most program environments, the standard input by default is the keyboard, and the C++ stream object defined to access it is cin .

For formatted input operations, cin is used together with the extraction operator, which is written as >> (i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored. For example:

The first statement declares a variable of type int called age , and the second extracts from cin a value to be stored in it. This operation makes the program wait for input from cin generally, this means that the program will wait for the user to enter some sequence with the keyboard. In this case, note that the characters introduced using the keyboard are only transmitted to the program when the ENTER (or RETURN ) key is pressed. Once the statement with the extraction operation on cin is reached, the program will wait for as long as needed until some input is introduced.

The extraction operation on cin uses the type of the variable after the >> operator to determine how it interprets the characters read from the input if it is an integer, the format expected is a series of digits, if a string a sequence of characters, etc.

As you can see, extracting from cin seems to make the task of getting input from the standard input pretty simple and straightforward. But this method also has a big drawback. What happens in the example above if the user enters something else that cannot be interpreted as an integer? Well, in this case, the extraction operation fails. And this, by default, lets the program continue without setting a value for variable i , producing undetermined results if the value of i is used later.

This is very poor program behavior. Most programs are expected to behave in an expected manner no matter what the user types, handling invalid values appropriately. Only very simple programs should rely on values extracted directly from cin without further checking. A little later we will see how stringstreams can be used to have better control over user input.
Extractions on cin can also be chained to request more than one datum in a single statement:

In both cases, the user is expected to introduce two values, one for variable a , and another for variable b . Any kind of space is used to separate two consecutive input operations this may either be a space, a tab, or a new-line character.

Cin and strings

The extraction operator can be used on cin to get strings of characters in the same way as with fundamental data types:

However, cin extraction always considers spaces (whitespaces, tabs, new-line. ) as terminating the value being extracted, and thus extracting a string means to always extract a single word, not a phrase or an entire sentence.

To get an entire line from cin , there exists a function, called getline , that takes the stream ( cin ) as first argument, and the string variable as second. For example:

Notice how in both calls to getline , we used the same string identifier ( mystr ). What the program does in the second call is simply replace the previous content with the new one that is introduced.

The standard behavior that most users expect from a console program is that each time the program queries the user for input, the user introduces the field, and then presses ENTER (or RETURN ). That is to say, input is generally expected to happen in terms of lines on console programs, and this can be achieved by using getline to obtain input from the user. Therefore, unless you have a strong reason not to, you should always use getline to get input in your console programs instead of extracting from cin .


The standard header <sstream> defines a type called stringstream that allows a string to be treated as a stream, and thus allowing extraction or insertion operations from/to strings in the same way as they are performed on cin and cout . This feature is most useful to convert strings to numerical values and vice versa. For example, in order to extract an integer from a string we can write:

This declares a string with initialized to a value of "1204" , and a variable of type int . Then, the third line uses this variable to extract from a stringstream constructed from the string. This piece of code stores the numerical value 1204 in the variable called myint .

In this example, we acquire numeric values from the standard input indirectly: Instead of extracting numeric values directly from cin , we get lines from it into a string object ( mystr ), and then we extract the values from this string into the variables price and quantity . Once these are numerical values, arithmetic operations can be performed on them, such as multiplying them to obtain a total price.

Watch the video: Need for input u0026 output A (September 2022).


  1. Nazir

    looked ... VERY COOL! I advise everyone ..

  2. Khalfani

    that we would do without your very good idea

  3. Sruthair

    and how is it necessary to act in this case?

  4. Akir

    There is something in this. Now everything is clear, thank you very much for the explanation.

  5. Anzety


  6. Arazuru

    well done, what an excellent message

Write a message