| Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
| Version 1.9 Build 803 |
|
The previous sections of this example demonstrated the use of templates. The next two, briefer, sections will demonstrate polymorphism, namely the ability to define a function with two or more sets of different argument types. In particular, we will add to the definition of ReadAsciiFile a module to read Vectors instead of Matrices. The following is the program which calls the new functions (The source code for this program is found in $AIPSROOT/code/trial/implement/test/tExample4.cc).
1 #include <aips/aips.h>
2 #include <aips/IO/AipsIO.h>
3 #include <aips/Arrays/ArrayIO.h>
4 #include <aips/Inputs/Input.h>
5 #include <aips/Mathematics/Math.h>
6 #include <aips/Arrays/Matrix.h>
7
8 main(int argc, char **argv)
9 {
10 Input inputs(1);
11 inputs.Version("$@w{Revision}$");
12 inputs.Create("infile1","Input1","Float Input file name?","Infile");
13 inputs.Create("infile2","Input2","Vector Input file name?","Infile");
14 inputs.Create("outfile","Output","Vector Output file name?","Outfile");
15 inputs.ReadArguments(argc, argv);
16
17 const char *filein1 = inputs.GetString("infile1");
18 const char *filein2 = inputs.GetString("infile2");
19 const char *fileout = inputs.GetString("outfile");
20
21 Int rows, cols;
22 try {
23 Matrix <Float> mat1;
24 Vector <Float> vect1;
25
26 readAsciiFile(filein1, mat1); mat1.shape(rows, cols);
27 cout << "The Matrix is " << rows << " by " << cols << endl;
28 readAsciiFile(filein2, vect1); vect1.shape(rows);
29 cout << "The Vector is " << rows << " long" << endl;
30
31 writeAsciiFile(fileout, vect1);
32 cout << mat1 << vect1 << endl;
33 }
34
35 catch (AipsIOError x) {
36 cerr << "aipsioerror: error " << x.getMesg() << endl;
37 return 1;
38 }
39 catch (AipsError x) {
40 cerr << "aipserror: error " << x.getMesg() << endl;
41 return 1;
42 }
43 return 0;
44 }