-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-ordered topics to better support feature dependencies
- Loading branch information
Showing
12 changed files
with
462 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
title: "Extended Types" | ||
teaching: 10 | ||
exercises: 0 | ||
questions: | ||
- "How do you extend a type?" | ||
objectives: | ||
- "Create an extend a type." | ||
keypoints: | ||
- "Type extension allows you to build upon an existing derived type to create a new derived type." | ||
--- | ||
|
||
<div class="gitfile" markdown="1"> | ||
~~~ | ||
module m_vector | ||
implicit none | ||
type t_vector | ||
integer:: num_elements | ||
real,dimension(:),allocatable:: elements | ||
end type | ||
type,extends(t_vector):: t_vector_3 | ||
end type | ||
contains | ||
type(t_vector) function create_empty_vector() | ||
implicit none | ||
create_empty_vector%num_elements=0 | ||
end function | ||
type(t_vector) function create_sized_vector(vec_size) | ||
implicit none | ||
integer,intent(in):: vec_size | ||
create_sized_vector%num_elements=vec_size | ||
allocate(create_sized_vector%elements(vec_size)) | ||
end function | ||
type(t_vector_3) function create_size_3_vector() | ||
implicit none | ||
create_size_3_vector%num_elements=3 | ||
allocate(create_size_3_vector%elements(3)) | ||
end function | ||
end module | ||
program main | ||
use m_vector | ||
implicit none | ||
type(t_vector) numbers_none,numbers_some | ||
type(t_vector_3) location | ||
numbers_none=create_empty_vector() | ||
print*, "numbers_none%num_elements=",numbers_none%num_elements | ||
numbers_some=create_sized_vector(4) | ||
numbers_some%elements(1)=2 | ||
print*, "numbers_some%num_elements=",numbers_some%num_elements | ||
print*, "numbers_some%elements(1)=",numbers_some%elements(1) | ||
location=create_size_3_vector() | ||
location%elements(1)=1.0 | ||
print*, "location%elements(1)=",location%elements(1) | ||
end program | ||
~~~ | ||
{: .fortran} | ||
[type_extension.f90](https://github.com/acenet-arc/fortran_oop_as_a_second_language/blob/gh-pages/code/type_extension.f90) | ||
</div> | ||
|
||
{% include links.md %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.