<Example Program>
| Module temperature_module Real,Protected :: temperature_c = 0, temperature_f = 32 Contains Subroutine set_temperature_c(new_value_c) Real,Intent(In) :: new_value_c temperature_c = new_value_c temperature_f = temperature_c*(9.0/5.0) + 32 End Subroutine Subroutine set_temperature_f(new_value_f) Real,Intent(In) :: new_value_f temperature_f = new_value_f temperature_c = (temperature_f - 32)*(5.0/9.0) End Subroutine End Program protected_example Use temperature_module ! ! We can print temperature_c and temperature_f directly, ! but can only change using the module procedures. ! Call set_temperature_c(20.0) Print '(1X,F6.2)',temperature_f Call set_temperature_f(100.0) Print '(1X,F6.2)',temperature_c End Program |
|
Execution Results68.00 37.78 |
|