Hablas otro idioma?

Showing posts with label hydrological modelling. Show all posts
Showing posts with label hydrological modelling. Show all posts

Wednesday, 3 August 2011

C++ Example 2: Reading data in text (.txt) format.

Ejemplo 2 para C++: Lectura de datos en formato .txt

After more than a month of not having updated this section of the blog (the others are being updated regularly though), this entry will show how to read .txt data using C++.

The input data for rainfall-runoff and environmental models is commonly provided by external sources, such as data loggers or the responsible of the IT department at the meteorological institutions, which rewrite the collected data in a certain format. Such data is often saved into binary (.bin) or text (.txt) format.  The former (.bin) is more efficient because it is the mother langauge of our computers. Data written in .bin format can be stored using less space than any other format, and can be retrieved at high speed; however, I have faced some situations where the writers of the .bin file forgot to write some details about the format of the data (e.g., is the data type Integer, Float, Double Long?), which made the data retrieval very difficult to accomplish . That is why throughout this example I am presenting some lines written in C++ that can be used to read a .txt file, a format that is popular among some groups of users.

Thus, the example shows:

i) how to read .txt data in C++, and
ii) how to format the input data into the format that our model uses.

A detailed explanation accompanies each line of the sample program, because I want to provide a practical example for those engineers interested in learning the C++ programming language.
Related Posts Plugin for WordPress, Blogger...