Introduction to Programming with Fortran ---------------------------------------- Practical Exercise 09 --------------------- Question 1 ---------- 1.1 Write a module that defines a derived type My_complex containing two INTEGERs (note), and contains a function to add two My_complex values (as if they were complex numbers) and return the result. Save a copy of the source. 1.2 Write a program to define two My_complex variables, set them to (123, 456) and (432, 876) using constructors, copy the first one to a third variable, and print out the value of the second and third variables. 1.3 Extend the program to create a fourth variable by multiplying the second variable by -i (i.e. reversing the order of its components) and print out the value of the sum of the first, second, third and fourth variables by calling the module's function. You need not create a new scratch variable or overwrite any of them. 1.4 Change the module written in 1.1 to add a PRIVATE statement inside the definition of the derived type and see what fails. Question 2 ---------- 2.1 File `Midden.data' contains data in the following format: 'Leechford' 5 13.17 42.62 46.24 5.51 23.23 The first line is a quoted string and an integer, which gives the count of the number of reals on the next line. Write a module that defines a derived type `Midden' containing a CHARACTER variable of length 16, and an ALLOCATABLE array, and contains a function and a subroutine. The function takes an assumed length CHARACTER argument and an assumed shape REAL array and returns a value of type `Midden'. The subroutine takes a value of type Midden and prints its contents (you need not quote the string). If the name and array are both null, it prints a message saying so. 2.2 Write a program to allocate an array of type `Midden', read in `Midden.data' and call the function to initialise it, and then the subroutine to print it. You may assume that there are never more than 100 real values per entry. Unused elements should be set to a `Midden' with a null name and empty array. Save the source of the program and module. 2.3 Change the module written in 2.1 to add a PRIVATE statement inside the definition of the derived type and check that it still works.