100% found this document useful (1 vote)
44 views

Download ebooks file An Introduction to Python Programming for Scientists and Engineers Johnny Wei-Bing Lin all chapters

Programming

Uploaded by

sharnironlor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
44 views

Download ebooks file An Introduction to Python Programming for Scientists and Engineers Johnny Wei-Bing Lin all chapters

Programming

Uploaded by

sharnironlor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Experience Seamless Full Ebook Downloads for Every Genre at ebookmeta.

com

An Introduction to Python Programming for


Scientists and Engineers Johnny Wei-Bing Lin

https://ebookmeta.com/product/an-introduction-to-python-
programming-for-scientists-and-engineers-johnny-wei-bing-
lin/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Introduction to Python for Engineers and Scientists: Open


Source Solutions for Numerical Computation 1st Edition
Sandeep Nagar
https://ebookmeta.com/product/introduction-to-python-for-engineers-
and-scientists-open-source-solutions-for-numerical-computation-1st-
edition-sandeep-nagar/
ebookmeta.com

Introduction to Scilab: For Engineers and Scientists 1st


Edition Sandeep Nagar

https://ebookmeta.com/product/introduction-to-scilab-for-engineers-
and-scientists-1st-edition-sandeep-nagar/

ebookmeta.com

Introduction to Octave: For Engineers and Scientists 1st


Edition Sandeep Nagar

https://ebookmeta.com/product/introduction-to-octave-for-engineers-
and-scientists-1st-edition-sandeep-nagar/

ebookmeta.com

Serial Sabotage 1st Edition Carolyn Keene

https://ebookmeta.com/product/serial-sabotage-1st-edition-carolyn-
keene/

ebookmeta.com
Yard Birds The Lives and Times of America s Urban Chickens
First Edition Philip Levy

https://ebookmeta.com/product/yard-birds-the-lives-and-times-of-
america-s-urban-chickens-first-edition-philip-levy/

ebookmeta.com

Swaiman’s Pediatric Neurology. Principles and Practice 6th


Edition Kenneth F. Swaiman

https://ebookmeta.com/product/swaimans-pediatric-neurology-principles-
and-practice-6th-edition-kenneth-f-swaiman/

ebookmeta.com

Handbook of Pediatric Epilepsy Case Studies 2nd Edition


Maria Augusta Montenegro

https://ebookmeta.com/product/handbook-of-pediatric-epilepsy-case-
studies-2nd-edition-maria-augusta-montenegro/

ebookmeta.com

Electrophysiological Recording Techniques 2nd Edition


Robert P Vertes Editor Timothy Allen Editor

https://ebookmeta.com/product/electrophysiological-recording-
techniques-2nd-edition-robert-p-vertes-editor-timothy-allen-editor/

ebookmeta.com

Prince Musical Icon 1st Edition Stephanie Watson

https://ebookmeta.com/product/prince-musical-icon-1st-edition-
stephanie-watson/

ebookmeta.com
Joseph Portraits Through the Ages 1st Edition Alan T.
Levenson

https://ebookmeta.com/product/joseph-portraits-through-the-ages-1st-
edition-alan-t-levenson/

ebookmeta.com
An Introduction to Python Programming for
Scientists and Engineers

Python is one of the most popular programming languages, widely used for data analysis
and modelling, and is fast becoming the leading choice for scientists and engineers. Unlike
other textbooks introducing Python, typically organised by language syntax, this book uses
many examples from across Biology, Chemistry, Physics, Earth science, and Engineering to
teach and motivate students in science and engineering. The text is organised by the tasks
and workflows students undertake day-to-day, helping them see the connections between
programming tools and their disciplines. The pace of study is carefully developed for complete
beginners, and a spiral pedagogy is used so concepts are introduced across multiple chapters,
allowing readers to engage with topics more than once. “Try This!” exercises and online
Jupyter notebooks encourage students to test their new knowledge, and further develop their
programming skills. Online solutions are available for instructors, alongside discipline-specific
homework problems across the sciences and engineering.

Johnny Wei-Bing Lin is an Associate Teaching Professor and Director of Undergraduate


Computing Education in the Division of Computing and Software Systems at the University
of Washington Bothell, and an Affiliate Professor of Physics and Engineering at North Park
University. He was the founding Chair of the American Meteorological Society’s annual
Python Symposium.

Hannah Aizenman is a Ph.D. candidate in Computer Science at The Graduate Center, City
University of New York. She studies visualization and is a core developer of the Python
library Matplotlib.

Erin Manette Cartas Espinel graduated with a Ph.D. in physics from the University of
California, Irvine. After more than 10 years at the University of Washington Bothell, she
is now a software development engineer.

Kim Gunnerson recently retired as an Associate Teaching Professor at the University of


Washington Bothell, where she taught chemistry and introductory computer programming.

Joanne Liu received her Ph.D. in Bioinformatics and Systems Biology from the University of
California San Diego.
“This book provides an excellent introduction to the Python language especially targeted at those
interested in carrying out calculations in the physical sciences. I especially like the strong coverage of
graphics and of good coding practice.”
Raymond Pierrehumbert, University of Oxford

“An excellent introduction to Python for scientists and engineers. Much more than teaching you how to
program with Python, it teaches you how to do science with Python.”
Eric Shaffer, University of Illinois at Urbana-Champaign

“Python has achieved an essential role in many disciplines within science, engineering, and beyond.
Students and professionals are expected to be fluent in it, and (as I see in my daily job of helping users of a
high-performance computing facility) they often struggle to reach that fluency. The authors have succeeded
in the daunting task of writing a single book to help people reach a very advanced level of fluency, starting
very gently and assuming no background. Unlike other books on the subject, An Introduction to Python
Programming for Scientists and Engineers focuses on teaching for the intended end goal of scientists and
engineers – investigating their scientific problems – not writing software for its own sake. I am looking
forward to working with the generation who will learn how to program in Python using this book!”
Davide Del Vento, NCAR Computational & Information Services Laboratory

“An Introduction to Python Programming for Scientists and Engineers introduces programming in Python
using evidence-based approaches to active learning. The exercises help both students and instructors
identify misconceptions in programming, allowing students to build a strong foundation in Python
programming. The book streamlines content such that there is a focus on mastering immediately useful
concepts, normalizing errors, and demonstrating recovery.”
Kari L. Jordan, Executive Director, The Carpentries
An Introduction to Python
Programming for Scientists
and Engineers

Johnny Wei-Bing Lin


University of Washington Bothell and North Park University

Hannah Aizenman
City College of New York

Erin Manette Cartas Espinel


Envestnet Tamarac

Kim Gunnerson
University of Washington Bothell

Joanne Liu
Novozymes A/S
University Printing House, Cambridge CB2 8BS, United Kingdom

One Liberty Plaza, 20th Floor, New York, NY 10006, USA

477 Williamstown Road, Port Melbourne, VIC 3207, Australia

314-321, 3rd Floor, Plot 3, Splendor Forum, Jasola District Centre,


New Delhi – 110025, India

103 Penang Road, #05–06/07, Visioncrest Commercial, Singapore 238467

Cambridge University Press is part of the University of Cambridge.

It furthers the University’s mission by disseminating knowledge in the pursuit of


education, learning, and research at the highest international levels of excellence.

www.cambridge.org
Information on this title: www.cambridge.org/highereducation/isbn/9781108701129
DOI: 10.1017/9781108571531

© Johnny Wei-Bing Lin, Hannah Aizenman, Erin Manette Cartas Espinel,


Kim Gunnerson, and Joanne Liu 2022

This publication is in copyright. Subject to statutory exception


and to the provisions of relevant collective licensing agreements,
no reproduction of any part may take place without the written
permission of Cambridge University Press.
First published 2022

Printed in the United Kingdom by TJ Books Limited, Padstow Cornwall

A catalogue record for this publication is available from the British Library.

Library of Congress Cataloging-in-Publication Data


Names: Lin, Johnny Wei-Bing, 1972– author. | Aizenman, Hannah, 1987– author. |
Espinel, Erin Manette Cartas, 1965– author. | Gunnerson, Kim Noreen, 1965– author. |
Liu, Joanne (Joanne K.), author.
Title: An introduction to Python programming for scientists and engineers /
Johnny Wei-Bing Lin, University of Washington, Bothell, Hannah Aizenman,
City College of New York, Erin Manette Cartas Espinel, Envestnet Tamarac,
Kim Gunnerson, University of Washington, Bothell, Joanne Liu, Biota Technology Inc.
Description: First edition. | Cambridge, United Kingdom ; New York, NY :
Cambridge University Press, 2022. | Includes bibliographical references and index.
Identifiers: LCCN 2022000136 | ISBN 9781108701129 (paperback)
Subjects: LCSH: Python (Computer program language) | Computer programming. |
Engneering–Data processing. | BISAC: SCIENCE / Earth Sciences / General
Classification: LCC QA76.73.P98 L55 2022 | DDC 005.13/3–dc23/eng/20220304
LC record available at https://lccn.loc.gov/2022000136

ISBN 978-1-108-70112-9 Paperback

Cambridge University Press has no responsibility for the persistence or accuracy


of URLs for external or third-party internet websites referred to in this publication
and does not guarantee that any content on such websites is, or will remain,
accurate or appropriate.
Contents

Detailed Contents page vii


Preface xvii
To the Student xxiii
Notices and Disclaimers xxvi
Acknowledgments xxix

Part I Getting Basic Tasks Done 1


1 Prologue: Preparing to Program 3

2 Python as a Basic Calculator 8

3 Python as a Scientific Calculator 27

4 Basic Line and Scatter Plots 52

5 Customized Line and Scatter Plots 88

6 Basic Diagnostic Data Analysis 124

7 Two-Dimensional Diagnostic Data Analysis 176

8 Basic Prognostic Modeling 209

9 Reading In and Writing Out Text Data 261

10 Managing Files, Directories, and Programs 327

Part II Doing More Complex Tasks 353

11 Segue: How to Write Programs 355

12 n-Dimensional Diagnostic Data Analysis 365

13 Basic Image Processing 394

v
vi Contents

14 Contour Plots and Animation 439

15 Handling Missing Data 483

Part III Advanced Programming Concepts 503


16 More Data and Execution Structures 505

17 Classes and Inheritance 536

18 More Ways of Storing Information in Files 570

19 Basic Searching and Sorting 595

20 Recursion 633

Part IV Going from a Program Working to Working Well 655


21 Make It Usable to Others: Documentation and Sphinx 657

22 Make It Fast: Performance 666

23 Make It Correct: Linting and Unit Testing 683

24 Make It Manageable: Version Control and Build Management 693

25 Make It Talk to Other Languages 702

Appendix A List of Units 706

Appendix B Summary of Data Structures 708

Appendix C Contents by Programming Topic 709

Glossary 719
Acronyms and Abbreviations 726
Bibliography 727
Index 729
Detailed Contents

Preface page xvii


To the Student xxiii
Notices and Disclaimers xxvi
Acknowledgments xxix

Part I Getting Basic Tasks Done 1


1 Prologue: Preparing to Program 3
1.1 What Is a Program and Why Learn to Program? 3
1.2 What Is Python and Why Learn This Language? 5
1.3 Software We Will Need 6

2 Python as a Basic Calculator 8


2.1 Example of Python as a Basic Calculator 8
2.2 Python Programming Essentials 10
2.2.1 Expressions and Operators 10
2.2.2 Variables 13
2.2.3 The Python Interpreter 15
2.3 Try This! 18
2.4 More Discipline-Specific Practice 24
2.5 Chapter Review 24
2.5.1 Self-Test Questions 24
2.5.2 Chapter Summary 25
2.5.3 Self-Test Answers 26

3 Python as a Scientific Calculator 27


3.1 Example of Python as a Scientific Calculator 27
3.2 Python Programming Essentials 28
3.2.1 Using Prewritten Functions 29
3.2.2 Importing Modules and Using Module Items 30
3.2.3 Writing and Using Our Own Functions 32
3.2.4 A Programmable Calculator 35
3.2.5 Python Interpreter and Code-Writing Environments for
More Complex Programs 38
3.3 Try This! 41

vii
viii Detailed Contents

3.4 More Discipline-Specific Practice 47


3.5 Chapter Review 47
3.5.1 Self-Test Questions 47
3.5.2 Chapter Summary 48
3.5.3 Self-Test Answers 49

4 Basic Line and Scatter Plots 52


4.1 Example of Making Basic Line and Scatter Plots 52
4.2 Python Programming Essentials 54
4.2.1 Positional Input Parameters for Required Input 55
4.2.2 Introduction to Lists and Tuples 58
4.2.3 Introduction to Strings 62
4.2.4 Introduction to Commenting and Jupyter Markdown 66
4.3 Try This! 69
4.4 More Discipline-Specific Practice 81
4.5 Chapter Review 81
4.5.1 Self-Test Questions 81
4.5.2 Chapter Summary 83
4.5.3 Self-Test Answers 85

5 Customized Line and Scatter Plots 88


5.1 Example of Customizing Line Plots 88
5.2 Python Programming Essentials 91
5.2.1 Optional Input into Functions Using Keyword Input Parameters 91
5.2.2 Customizing How the Plot Looks 93
5.2.3 Handling Multiple Figures or Curves 96
5.2.4 Adjusting the Plot Size 97
5.2.5 Saving Figures to a File 98
5.2.6 Introduction to Array Calculations 99
5.2.7 The Concept of Typing 103
5.3 Try This! 106
5.4 More Discipline-Specific Practice 117
5.5 Chapter Review 117
5.5.1 Self-Test Questions 117
5.5.2 Chapter Summary 119
5.5.3 Self-Test Answers 121

6 Basic Diagnostic Data Analysis 124


6.1 Example of Basic Diagnostic Data Analysis 124
6.2 Python Programming Essentials 126
6.2.1 More on Creating Arrays and Inquiring about Arrays 128
6.2.2 More on Functions on Arrays 132
Detailed Contents ix

6.2.3 Going Through Array Elements and an Introduction to Loops 134


6.2.4 Introduction to Asking Questions of Data and Branching 139
6.2.5 Examples of One-Dimensional Loops and Branching 148
6.2.6 Docstrings 153
6.2.7 Three Tips on Writing Code 155
6.3 Try This! 158
6.4 More Discipline-Specific Practice 170
6.5 Chapter Review 170
6.5.1 Self-Test Questions 170
6.5.2 Chapter Summary 171
6.5.3 Self-Test Answers 173

7 Two-Dimensional Diagnostic Data Analysis 176


7.1 Example of Two-Dimensional Diagnostic Data Analysis 176
7.2 Python Programming Essentials 182
7.2.1 The Shape of Two-Dimensional Arrays 183
7.2.2 Creating Two-Dimensional Arrays 184
7.2.3 Accessing, Setting, and Slicing in a Two-Dimensional Array 186
7.2.4 Array Syntax and Functions in Two-Dimensional Arrays 190
7.2.5 Nested for Loops 191
7.3 Try This! 194
7.4 More Discipline-Specific Practice 203
7.5 Chapter Review 203
7.5.1 Self-Test Questions 203
7.5.2 Chapter Summary 205
7.5.3 Self-Test Answers 207

8 Basic Prognostic Modeling 209


8.1 Example of a Basic Prognostic Model 209
8.2 Python Programming Essentials 217
8.2.1 Random Numbers in Computers 217
8.2.2 Scalar Boolean Type and Expressions 221
8.2.3 Nested Branching 230
8.2.4 Looping an Indefinite Number of Times Using while 232
8.2.5 Making Multiple Subplots 236
8.2.6 More on Nested Loops 237
8.2.7 Conditionals Using Floating-Point Numbers 239
8.3 Try This! 241
8.4 More Discipline-Specific Practice 252
8.5 Chapter Review 252
8.5.1 Self-Test Questions 252
8.5.2 Chapter Summary 254
8.5.3 Self-Test Answers 257
x Detailed Contents

9 Reading In and Writing Out Text Data 261


9.1 Example of Reading In and Writing Out Text Data 262
9.2 Python Programming Essentials 267
9.2.1 Introduction to Objects 268
9.2.2 Arrays as Objects 269
9.2.3 Lists as Objects 277
9.2.4 Strings as Objects 280
9.2.5 Copying Variables, Data, and Objects 286
9.2.6 Reading and Writing Files 290
9.2.7 Catching File Opening and Other Errors 298
9.3 Try This! 300
9.4 More Discipline-Specific Practice 317
9.5 Chapter Review 317
9.5.1 Self-Test Questions 317
9.5.2 Chapter Summary 319
9.5.3 Self-Test Answers 321

10 Managing Files, Directories, and Programs 327


10.1 Example of Managing Files, Directories, and Programs 328
10.2 Python Programming Essentials 331
10.2.1 Filenames, Paths, and the Working Directory 332
10.2.2 Making and Removing Empty Directories 335
10.2.3 Moving and Renaming Files and Directories 337
10.2.4 Copying and Deleting Files and Directories 338
10.2.5 Listing the Contents of a Directory 340
10.2.6 Testing to See What Kind of “File” Something Is 341
10.2.7 Running Non-Python Programs in Python 342
10.3 Try This! 343
10.4 More Discipline-Specific Practice 347
10.5 Chapter Review 347
10.5.1 Self-Test Questions 347
10.5.2 Chapter Summary 348
10.5.3 Self-Test Answers 350

Part II Doing More Complex Tasks 353


11 Segue: How to Write Programs 355
11.1 From Blank Screen to Program: A Process to Follow 355
11.2 The Importance of Testing 360
11.3 The Importance of Style Conventions 363
Detailed Contents xi

12 n-Dimensional Diagnostic Data Analysis 365


12.1 Example of n-Dimensional Diagnostic Data Analysis 365
12.2 Python Programming Essentials 367
12.2.1 The Shape of and Indexing n-Dimensional Arrays 368
12.2.2 Selecting Subarrays from n-Dimensional Arrays 370
12.2.3 Array Syntax and Functions in n-Dimensional Arrays 372
12.2.4 Reshaping n-Dimensional Arrays and Memory Locations of Array
Elements 374
12.2.5 Subarrays and Index Offset Operations 376
12.2.6 Triple Nested Loops and Mixing Array Syntax/Selection and Looping 378
12.2.7 Summary Table of Some Array Functions 380
12.3 Try This! 382
12.4 More Discipline-Specific Practice 386
12.5 Chapter Review 387
12.5.1 Self-Test Questions 387
12.5.2 Chapter Summary 389
12.5.3 Self-Test Answers 391

13 Basic Image Processing 394


13.1 Example of Image Processing 394
13.2 Python Programming Essentials 400
13.2.1 Reading, Displaying, and Writing Images in Matplotlib 401
13.2.2 Boolean Arrays 404
13.2.3 Array Syntax and Functions and Asking Questions of Data in Arrays 408
13.2.4 Performance of Looping and Array Syntax and Functions 414
13.2.5 The NumPy reduce Method 416
13.2.6 Looping Through Lists of Objects 417
13.3 Try This! 419
13.4 More Discipline-Specific Practice 430
13.5 Chapter Review 431
13.5.1 Self-Test Questions 431
13.5.2 Chapter Summary 432
13.5.3 Self-Test Answers 434

14 Contour Plots and Animation 439


14.1 Example of Making Contour Plots and Animations 440
14.2 Python Programming Essentials 445
14.2.1 An Introduction to Matplotlib’s Object API 446
14.2.2 Line and Shaded Contour Plots 451
14.2.3 Using cartopy to Overlay Maps 453
14.2.4 Basic Animation Using Matplotlib 456
14.2.5 Flexible Functions and Dictionaries 459
xii Detailed Contents

14.3 Try This! 465


14.4 More Discipline-Specific Practice 477
14.5 Chapter Review 477
14.5.1 Self-Test Questions 477
14.5.2 Chapter Summary 479
14.5.3 Self-Test Answers 481

15 Handling Missing Data 483


15.1 Example of Handling Missing Data 483
15.2 Python Programming Essentials 487
15.2.1 Approach 1: Define a Data Value as Missing and Process
with Boolean Arrays or Expressions 488
15.2.2 Approach 2: Use Series and IEEE NaN Values 490
15.2.3 Approach 3: Use Masked Arrays 492
15.2.4 Which Approach Is Better? 493
15.3 Try This! 494
15.4 More Discipline-Specific Practice 498
15.5 Chapter Review 498
15.5.1 Self-Test Questions 498
15.5.2 Chapter Summary 499
15.5.3 Self-Test Answers 501

Part III Advanced Programming Concepts 503


16 More Data and Execution Structures 505
16.1 Example of Using More Advanced Data and Execution Structures 505
16.1.1 Solution 1: Explicitly Call Functions and Store Results in Variables 506
16.1.2 Solution 2: Explicitly Call Functions and Store Results in Arrays 507
16.1.3 Solution 3: Explicitly Call Functions and Store Results in Dictionaries 508
16.1.4 Solution 4: Store Results and Functions in Dictionaries 509
16.2 Python Programming Essentials 511
16.2.1 More Data Structures 511
16.2.2 More Execution Structures 519
16.2.3 When to Use Different Data and Execution Structures 521
16.3 Try This! 523
16.4 More Discipline-Specific Practice 529
16.5 Chapter Review 530
16.5.1 Self-Test Questions 530
16.5.2 Chapter Summary 531
16.5.3 Self-Test Answers 533
Detailed Contents xiii

17 Classes and Inheritance 536


17.1 Examples of Classes and Inheritance 536
17.1.1 Scientific Modeling Example 537
17.1.2 Scientific Bibliography Example 544
17.2 Python Programming Essentials 546
17.2.1 Defining and Using a Class 546
17.2.2 Inheritance 550
17.2.3 More Sophisticated Sorting Using sorted 553
17.2.4 Why Create Our Own Classes? 554
17.2.5 Automating Handling of Objects and Modules 557
17.3 Try This! 560
17.4 More Discipline-Specific Practice 564
17.5 Chapter Review 564
17.5.1 Self-Test Questions 564
17.5.2 Chapter Summary 566
17.5.3 Self-Test Answers 568

18 More Ways of Storing Information in Files 570


18.1 Examples of Using Other File Formats 570
18.2 Python Programming Essentials 576
18.2.1 Excel Files 576
18.2.2 pickle Files 578
18.2.3 netCDF files 579
18.3 Try This! 583
18.4 More Discipline-Specific Practice 589
18.5 Chapter Review 589
18.5.1 Self-Test Questions 589
18.5.2 Chapter Summary 590
18.5.3 Self-Test Answers 592

19 Basic Searching and Sorting 595


19.1 Examples of Searching and Sorting 595
19.2 Python Programming Essentials 598
19.2.1 Summary of Some Ways to Search and Sort 598
19.2.2 Searching and Sorting Algorithms 601
19.2.3 Basic Searching and Sorting Using pandas 611
19.3 Try This! 622
19.4 More Discipline-Specific Practice 628
19.5 Chapter Review 628
19.5.1 Self-Test Questions 628
19.5.2 Chapter Summary 629
19.5.3 Self-Test Answers 631
xiv Detailed Contents

20 Recursion 633
20.1 Example of Recursion 633
20.2 Python Programming Essentials 635
20.2.1 Using the walk Generator 635
20.2.2 Recursion and Writing Recursive Code 637
20.2.3 More Applications of Recursion 642
20.3 Try This! 645
20.4 More Discipline-Specific Practice 649
20.5 Chapter Review 649
20.5.1 Self-Test Questions 649
20.5.2 Chapter Summary 650
20.5.3 Self-Test Answers 651

Part IV Going from a Program Working to Working Well 655


21 Make It Usable to Others: Documentation and Sphinx 657
21.1 Introduction 657
21.2 Principles of Documenting 657
21.3 General Convention for Docstrings: The NumPy Format 659
21.4 The Sphinx Documentation Generator 660

22 Make It Fast: Performance 666


22.1 Introduction 666
22.2 Preliminaries 666
22.2.1 Describing the Complexity of Code 666
22.2.2 Practices That Can Result in Inefficient Code 668
22.3 Finding the Bottlenecks Using Profilers 670
22.3.1 timeit 671
22.3.2 cProfile 672
22.3.3 line-profiler 674
22.3.4 memory-profiler 676
22.4 Fixing the Bottlenecks 678
22.4.1 Generators 678
22.4.2 Just-in-Time Compilation 680
22.5 Pitfalls When Trying to Improve Performance 682

23 Make It Correct: Linting and Unit Testing 683


23.1 Introduction 683
23.2 Linting 683
23.3 Unit Testing 686
23.3.1 unittest 687
23.3.2 pytest 688
23.4 The “Test-Driven Development” Process 690
Detailed Contents xv

24 Make It Manageable: Version Control and Build Management 693


24.1 Introduction 693
24.2 Version Control 693
24.2.1 Using Git as a Single User 694
24.2.2 Using Git as a User Who Is Part of a Collaboration 696
24.2.3 Using Git with Branching 697
24.3 Packaging 698
24.4 Build Management and Continuous Integration 699

25 Make It Talk to Other Languages 702


25.1 Introduction 702
25.2 Talking with Fortran Programs 702
25.3 Talking with C/C++ Programs 704

Appendix A List of Units 706

Appendix B Summary of Data Structures 708

Appendix C Contents by Programming Topic 709


C.1 Introductory Programming Topics 709
C.1.1 What Is a Program and General Elements of Python 709
C.1.2 Variables and Expressions 710
C.1.3 Typing and Some Basic Types 710
C.1.4 Strings 711
C.1.5 Functions 711
C.1.6 Branching, Conditionals, and Booleans 712
C.1.7 Looping 712
C.1.8 Console Input and Output 713
C.1.9 Text File Input and Output 713
C.1.10 Exceptions 713
C.1.11 Arrays 714
C.1.12 Classes 715
C.2 Intermediate Programming Topics 715
C.2.1 Abstract Data Types and Structures 715
C.2.2 Algorithm Analysis 716
C.2.3 Searching and Sorting 716
C.2.4 Recursion 717
C.3 Other Topics 717
C.3.1 How to Program and Programming Style 717
C.3.2 Distributions and Interactive Development Environments (IDEs) 717
Random documents with unrelated
content Scribd suggests to you:
She was confessedly an experiment. Her engine-space meant one-
tenth less cargo-space, but it was the owner’s idea that, if the
voyage were accomplished with so much greater rapidity than the
ordinary packet ships could achieve as to recompense them for the
loss of tonnage, the experiment would be a success. Her owner was
Mr. R. B. Forbes of Boston, and she cost altogether about £16,000.
She sailed from Liverpool for New York, beating such well-known
sailing ships as the Shenandoah and Adirondack by thirteen days,
and the Henry Clay by five days.

The “Massachusetts.”

The United States Nautical Magazine in 1845 said: “Let it be


distinctly understood that we do not call her a steamer or expect her
to make steamboat speed except under canvas; her steam-power is
strictly auxiliary to her canvas.” The Massachusetts was the first ship
of a line intended to run between New York and Liverpool under the
American flag. Her length on deck was 161 feet, and her beam 31
feet 9 inches, with 20 feet depth of hold, and she was about 751
tonnage. Her full poop extended as far forward as the main-mast,
and contained accommodation for thirty-five passengers. Her bow
was very sharp. She carried what is known as a false bow, which
increased her sharpness, and was filled in on somewhat original
lines. In her equipment everything that could be devised was
provided. She carried lensed lights on each bow, and also aft
between the main and mizzen masts. Her ventilators were similar to
those on the Cunard steamers. Each stool, chair, and settee had
airtight compartments, so that it could be used as a lifebuoy; she
was well supplied with boats in case of accidents. The fact that she
had an engine did not interfere with her sail equipment, for she was
square-rigged throughout and carried skysails on all three masts.
Her sail area was 3833 yards. A peculiarity of her rig was that all the
masts were fidded abaft the lower masthead; but the advantages of
this innovation were not found, in this or any other ship in which
they were tried, to be very great, and it was not commonly adopted.
It was thought that by fidding the masts in this fashion a vessel
might be kept more steadily on her course when it became
necessary for the sailors to reef or take in sail. She carried a
condensing engine with two cylinders, working nearly at right
angles, of 26 inches diameter with a stroke of three feet. She had
two “waggon” boilers, each 14 feet long, 7 feet wide, and 9 feet
high, with a furnace to each, and a blowing engine and blower for
raising steam quickly. The diameter of the propeller was nine and a
half feet. It was made of wrought copper and composition metal,
and could be raised out of the water when the steam-power was not
required. This was effected by means of a shaft from the engine-
room through the stern, above and parallel to the propeller shaft.
The upper shaft revolving raised the propeller and placed it close
against the flat of the stern, where it was secured with chains. The
propeller shaft passed close to the stern-post on the larboard side,
and rested in a socket bolted to the stern-post, and was further
supported by a massive brace above. Messrs. Hogg and Co. of New
York constructed the engines to Captain Ericsson’s design. The
rudder had the peculiarity of a “shark’s mouth” cut across it. This is
an opening or gap extending a considerable distance across the
rudder so that the rudder itself shall not be impeded by the screw-
shaft which extends beyond it, the upper and lower portions of the
rudder passing above and below the shaft when turned in that
direction. Several steam auxiliary vessels were thus fitted, but it was
not long ere the plan was adopted of cutting away the dead wood in
front of the rudder-post and placing the screw before the rudder
instead of behind.
This enterprise was short-lived, as the vessel made but two round
voyages and thereafter remained in American waters. A sister boat,
the Edith, was purchased by the United States Government before
she had made a voyage. The Massachusetts was chartered to carry
American troops to Mexico in 1846, and continued in the United
States Navy until 1870, when she was sold and converted into the
sailing ship Alaska, under which name she made some good
passages.
The Vanderbilt, also an auxiliary steamer, built by Simonson of
New York for his uncle, Commodore Vanderbilt, in 1855, was 331
feet in length, and had a gross tonnage of 3360. She was probably
the first and perhaps the only American-built vessel with two
overhead beams to cross the Atlantic; certainly her appearance
attracted no small amount of attention. Her two cylinders were each
90 inches diameter and 12 feet stroke; her indicated horse-power
was 2800 and her boiler-pressure was as high as 18 lb. The engines
were built at the Allaire works. She ran on the New York, Havre, and
Cowes route until November 1860, besides going once to Bremen in
1858, and on the outbreak of war was presented by the Commodore
to the United States Government. She was afterwards laid up and
bought in 1873 by a San Francisco firm, who removed the engines
and turned her into the full-rigged three-masted ship The Three
Brothers; she was next bought by a British firm to end her days as a
hulk at Gibraltar.
One of the last of the vessels carrying steam for admittedly
auxiliary purposes only was the clipper Annette, built by Messrs.
Russell and Co. in 1863. She was fitted with a screw and a small
oscillating engine with cylinders 3 feet in diameter and 3 feet stroke,
and a tubular boiler 9¹⁄₂ feet long by 13 feet high gave steam at 20
lb. pressure. Her screw was 11 feet in diameter with 22 feet pitch,
and a universal joint connected it to the engine-shaft so that it could
be lowered or raised as desired. The masts carried 1418 square
yards of canvas.
The full-rigged, fast-sailing clipper ships, fitted with auxiliary screw
propellers, found one of the finest representatives of their class in
the Sea King, which was built at Glasgow for the trade with China,
where several splendid vessels, fast under sail and carrying powerful
auxiliary engines, were engaged. They were peculiarly suitable for
those waters, for the coaling stations were few and far between, and
coal was expensive, and their engines consumed a great deal more
fuel in proportion to results than do those of modern steamers. The
Sea King was composite built; that is, she had an iron frame with
wood planking. Her screw could be lifted when the wind was
favourable, and her ability to show a clean pair of heels to most
sailing craft afloat is proved by her making the passage home from
Shanghai in seventy-nine days, or, after allowing time for coaling en
route, seventy-four days. She was of 1018 registered tonnage, and
her engines were of 200 nominal horse-power; she was 220 feet in
length by 32¹⁄₂ feet beam, and 20¹⁄₂ feet depth.
Her career for a time was exciting. She was one of the many
vessels bought by the agents of the Confederate States in 1864,
nominally as a blockade-runner, but she became a privateer—pirate
the Northerners called her—and as such she had the distinction of
being the only vessel which carried the Confederate flag round the
world. Her name was changed to Shenandoah when she was
purchased; she was neither the first nor the last famous sailing
vessel of that name. The last Shenandoah, the biggest wooden
sailing vessel ever built in America, a four-masted barque, returned
the fire of a Spanish gunboat in the recent Spanish-American War,
and then out-sailed her. The commander of the Shenandoah of the
’sixties was James Tredell Waddell, whose record justified his
appointment. He was formerly an officer in the United States Navy,
and was wounded and lamed for life in a duel in 1842. He
nevertheless served in the Mexican War and then commanded the
American storeship Release at the building of the Panama Railway.
All his officers and crew were down with yellow fever, but with a few
convalescent seamen he sailed his vessel to Boston. He declined, in
1862, the offer to command one of the vessels in the bomb fleet
then being fitted out to attack New Orleans, but instead he got
through the blockade from Annapolis to Richmond and joined the
Confederate Navy. He was in command of the ram Louisiana when
the Southern fleet was attacked and scattered by the Federal fleet
under Admiral Farragut, and sank the Louisiana rather than let her
be captured. Next he was ordered to take command of the
Shenandoah, then being fitted out at Liverpool for a cruise in the
Pacific. He commissioned his ship off Madeira in October 1864 and
set sail for the south. He captured and either burnt or sank nine
American sailing ships before he arrived at Melbourne on January
25, 1865, but the ship’s stay was a short one, for it was expected an
American vessel or two would be on her track, and she left Port
Phillip on February 8, 1865. Three months later she began her
destructive work among the whalers in the Okhotsk and Behring
Seas and the Arctic Ocean. Three months after General Lee had
surrendered at Appomattox Court-house, the Shenandoah continued
her activity, and it was not until the British barque Barracouta was
spoken that Waddell learnt that the war was ended. Waddell then
sailed the Shenandoah to Liverpool and surrendered her to the
British Government, by whom she was handed over in November
1865 to the United States Consul. During her career under Waddell’s
command she captured thirty-eight vessels, of which six were
released on bond and thirty-two were sunk or burnt. She afterwards
passed into the possession of the Sultan of Zanzibar, and some years
later was lost with all hands in a gale. Waddell returned to America
in due time and commanded the San Francisco, of the Pacific Mail
Line, until she struck a rock and went to the bottom. All the
passengers were saved and Waddell was the last to leave the ship.
[69]

[69] Appleton’s “Cyclopædia of American Biography.”


The other most notorious blockade-runner and commerce-harrier
was the Liverpool-built Alabama, a wooden three-masted screw
steamer, rigged as a barque; she was of 1040 tons register and 220
feet in length and had horizontal engines of 300 nominal horse-
power, operating one propeller and giving her a speed, under steam,
of nearly 13 knots, while with steam and sail together she could
cover 15 knots. The story of her exploits and of her destruction by
the United States wooden cruiser Kearsarge off Cherbourg in June
1864, and of the “Alabama claims,” is too well known to need
repetition here.[70]
[70] A good account may be found in Appleton’s “Cyclopædia.”

The mail route between England and India via the Cape was
admittedly slow; and it seemed possible to carry the mails by way of
Suez in a much shorter time. The eastern half of this service was
maintained in a very inefficient manner by the East India Company.
The British Government had inaugurated in February 1830 its mail
steam-packet service from Falmouth to the Mediterranean. Up to this
date the mails had been carried in sailing brigs, although steam
navigation with the Mediterranean had already been established and
the steamers beat the sailing brigs by many days. The first of these
Government steam packets was the Meteor, and the others
employed included the African, Messenger, Firebrand, Echo, Hermes,
Colombia, Confiance, and Carron.
The Dublin and London Steam Packet Company, under the
management of Messrs. Bourne, decided in 1834 upon establishing a
line of steamers between London and the Spanish peninsula. The
proposed line was to be called the Peninsular Steam Navigation
Company, and its first steamer was probably the Royal Tar. This
steamer, by the way, had previously been chartered in 1834 to Don
Pedro and then to the Queen Regent of Spain.
It is hardly correct, however, to describe these Admiralty vessels
as warships, for the Admiralty steam vessels at that time were
gunboats, or despatch vessels, steam for line-of-battle ships not
being used until some years later.
The Peninsular Company chartered a number of vessels for its
early service, but it was not until 1837 that it commenced to
despatch mail-packets regularly from London to Lisbon and Gibraltar
under contract with the British Government, which at that time and
for twenty years afterwards was represented by the Lords
Commissioners of the Admiralty. This contract was tendered for by
both the Peninsular Steam Navigation Company and a concern called
the British and Foreign Steam Navigation Company, but the latter
was unable to convince the Government that it possessed the
resources, both financial and shipping, which would enable it to
carry out the engagement. The Peninsular Company, on the other
hand, was able to give the required assurance. The company
undertook, in return for an annual subsidy of £29,600, to convey the
mails monthly to the Peninsula. The pioneer vessel of this service
was the Iberia, of 690 tons and 200 horse-power, which sailed in
September 1837. Altogether the company had ten vessels, two of
which were chartered from the City of Dublin Company.
The statement is often made that the steamer William Fawcett[71]
was the first boat of the company; she was built in 1829 by Caleb
Smith of Liverpool, and her engines were by Messrs. Fawcett and
Preston, also of Liverpool; and after being used for some years as a
ferry-boat on the Mersey she was placed on the Liverpool and Dublin
route and may have been “chartered for a short time to the
Peninsular Steam Navigation Company in 1835 or 1836, as she does
not appear in the company’s advertised sailing list for 1838.”[72]
[71] See the Frontispiece to this book.
[72] Kennedy’s “History of Steam Navigation.”

In 1839 the British and French Governments arranged that the


Indian mails should be sent by way of Marseilles and thence taken
by an Admiralty packet to Malta to be transhipped to another
Admiralty packet for conveyance to Alexandria. As was to be
expected, an arrangement of this sort, involving such possibilities of
delay, did not last long, and the Government advertised for tenders
for the mails to be carried between Alexandria and England, with
calls at Gibraltar and Malta both ways. Four tenders were sent in,
and that of the Peninsular Company, which offered to do what was
required for £34,200, was accepted. The company also offered to
charge reduced fares to officers travelling on the public service and
to carry Admiralty packages for nothing.
The urgency of a more regular steam communication between
England and India than was supplied by the sailing or auxiliary
Indiamen was now being extensively discussed, and the Government
was asked to subsidise a line of steamers between England and
Calcutta which should make the passage in thirty days. The
Peninsular Company offered to carry the mails between England and
Alexandria with the two steamers Great Liverpool and Oriental, and
in 1840 the company was incorporated by Royal Charter under the
name of the Peninsular and Oriental Steam Navigation Company,
with a view to the extension of its operations to the Far East. The
Great Liverpool was of 1540 tons, and had been built for the
Liverpool and New York trade, and the Oriental was of 1600 tons
and 450 horse-power. The company was afterwards requested to
place two smaller steamers on the Malta and Corfu branch of the
mail service, and did so for no less than £10,712 below what it had
cost to maintain the Admiralty packets.
The “Hindostan” (P. & O. Company, 1842).

The inadequate service maintained between Calcutta and Suez


had given rise to many complaints, and at last, after considerable
pressure had been brought to bear on the East India Company by
the Government in London, the former consented to enter into a
contract with the P. & O. Company for the conveyance of the mails
between these two points. The company despatched its first steamer
to India in September 1842, this being the Hindostan, a fine vessel
of 2017 tons, and 520 horse-power. She was a three-masted vessel,
and carried square sails on the foremast, and of her two funnels one
was set before and the other abaft the paddles. Her departure was
regarded as of national importance, and the warships she passed as
she left port were manned in her honour. She was placed on the
route between Calcutta and Suez, with calls at Madras and Ceylon;
and as other steamers followed, the company was soon able to
contract for the conveyance of the mails monthly from Ceylon to
Hong-Kong, with calls at Penang and Singapore, for a subvention of
£45,000. The company received £115,000 for its service between
Calcutta and Suez. The Eastern services were attended with no little
difficulty. At Suez and Aden fresh-water supplies had to be
organised, and coaling stations, docks, and store establishments had
to be established wherever necessary.
The scramble over the isthmus of Suez, whence came the name of
the “overland route,” was one of the great drawbacks of this way to
the East, and many persons preferred to travel to India by way of
the Cape. In spite of its name the overland route was mostly a
waterway, for the Mahmoudieh Canal enabled the P. & O. Company
to transport its passengers and goods from Alexandria to the Nile,
where they travelled by steamer to Cairo, and the land portion of the
journey was rather less than 100 miles across the desert from Cairo
to Suez. Caravans, sometimes numbering more than three thousand
camels, were employed to convey a single steamer’s loading
between Suez and Cairo. In passing from the Red Sea to the
Mediterranean port every package had to undergo three separate
transfers.
“For nearly twenty years this system of working the company’s
traffic continued in operation, but it sufficed for carrying on a trade
which, for the value of the merchandise in proportion to its bulk,
has, it may safely be said, never been equalled. It attained
sometimes the annual value of forty millions sterling.”[73]
[73] P. & O. Handbook, 1905 edition.

The East India Company’s service between Suez and Bombay was
as bad as that formerly maintained with Calcutta, owing to
indifferent management and unsuitable steamers, and as it cost
about 30s. per mile, whereas the P. & O. maintained its services to
India and China for 17s. per mile, there was a renewal of the
agitation for the service to be taken out of the control of the East
India Company and entrusted to a concern which could work it
better and more economically. Parliament in 1851 supported the
agitation, but the East India Company would not give way until the
fates were too strong for it; one lot of Bombay mails went to the
bottom in a native sailing vessel in which they had been placed at
Aden, as the company had no steamer ready for them at Suez. At
the request of the Government, the P. & O. Company agreed to take
over this service for a subvention of £24,000 per annum, as against
the £105,000, or thereabouts, which the old arrangement had cost.
The P. & O. Company opened its Australian service in 1852 as a
branch line, but this connection proved so beneficial to the company
and the Australian Colonies alike, that in course of time it was made
a main-line service, to the mutual advantage of the company and
the Colonies. So many of the company’s steamers were employed in
the Crimean War and during the Indian Mutiny for the Army, that the
Australian portion of the service was dropped for some time.

H.M. Troopship “Himalaya” in Plymouth Sound. (The “Royal George,” 120


Guns, in background.)

In 1852 the company added eleven vessels to its fleet, including


the celebrated Himalaya, then the largest steam-ship afloat and the
fastest ocean-going vessel, with the possible exception of a few on
the North Atlantic. Eleven of the company’s steamers were chartered
to the Government as transports during the Crimean War, and one of
them, the Colombo, was nicknamed Santa Claus when she arrived at
Sebastopol one Christmas Eve with presents and sorely needed
stores and provisions for the troops.
The East India Company in 1855 asked for tenders for the Calcutta
and Burmah mails, and an agreement was entered into with Messrs.
McKinnon and Co. of Glasgow, but the steamers they employed were
unsuitable and small and the enterprise was a failure. Two steamers,
the Baltic and Cape of Good Hope, were sent out for the work, and
fortunately for the owners were acquired soon afterwards as
transports during the Indian Mutiny.
This undertaking was known as the Calcutta and Burmah Steam
Navigation Company, and was at that time purely local in its
operations. Its steamer the Cape of Good Hope was lost in a collision
in the Hoogly, and another steamer of the line was wrecked while on
her way out to India on her first voyage while off the coast of
Ireland.
However, the company changed its name in 1862 to the British
India Steam Navigation Company, Ltd., and notwithstanding its
inauspicious start under its old name, it has grown apace and is now
one of the principal lines trading between England and the Eastern
Hemisphere.
The opening of the Suez Canal in 1869, which threatened serious
financial loss to the P. & O. Company, proved of great benefit to the
British India Company. The P. & O. “for thirty years had built up and
depended for existence upon the only traffic which was possible in
connection with the transit through Egypt, viz., the conveyance of
passengers and goods at rates which were necessarily high, owing
to the conditions under which the work had to be carried on. These
conditions and the rates depending on them were swept away by
the opening of the canal, and the financial consequences were such
that for some time the future existence of the company appeared to
hang doubtfully in the balance. The company’s work had therefore to
be reorganised, and a new fleet procured with what diligence was
possible under the adverse condition of reduced, and at one time of
vanished, profit.”
This extract from the company’s Handbook is interesting, but
considering how long the Suez Canal was in building, the company
can hardly be said to have made any undue haste in anticipating the
coming change.
The difficulties of the P. & O. Company, caused by the opening of
the Suez Canal, were increased by the objections which the Post
Office raised to the use of the canal for the passage of the mails
instead of the Egyptian Railway, but it gave way on this point “for a
pecuniary consideration, that is to say, for a sensible abatement of
the subsidy, which was not an easy matter to arrange at a time
when the company was struggling for existence. However, the
company made some concession, and it was finally arranged that
the heavy mails which were then sent from England by sea should in
future be carried by the Suez Canal, but it was not till 1888, when
the company had reduced their charge for the conveyance of the
mails by nearly £100,000 per annum, that the accelerated mails sent
via Brindisi were also transferred to the Canal Route. The company’s
connection with the Overland Route through Egypt, which had
existed for half a century, was then finally closed.”[74]
[74] P. & O. Handbook.
H.M. Troopship “Himalaya.”

The Union Line was founded in 1853 as the Union Steam Collier
Company, and it made a start with five little steamers, the largest of
which were the Dane and Norman of 530 tons. The outbreak of the
Crimean War, and the consequent withdrawal of the P. & O.
steamers from the Southampton and Constantinople service for use
as transports, saw the Union vessels placed upon that service till
they also were engaged as transports, and a sixth vessel was
acquired. When the war was ended, the steamers were placed for a
time in the Southampton and Brazil trade, but it was not a very
profitable venture and they were diverted to the South African trade,
the company receiving a subsidy of £30,000 a year for five years for
carrying the mails to and from the Cape of Good Hope. The first
sailing was made by the Dane in September 1857, and the sailings
thereafter were monthly. The subsidy was increased by £3000 the
following year on condition that calls were made at St. Helena and
Ascension.
In 1857, Rennie’s “Aberdeen” Line, after having been for many
years in sail, went in for steam and despatched its first steamers,
Madagascar and Waldensian, from London to South Africa, carrying
the mails between Cape Town and Durban. These are stated to have
been the first steamers on the South African coast. The Madagascar,
of 500 tons, was commanded by Captain George Rennie. Like all the
long-distance steamers of her time, she carried a large spread of
sail, but her engines, like those of most of her contemporaries, were
calculated to be able to render her independent of the wind if it did
not happen to be suitable, and therein they marked a great
improvement upon those of an earlier type, which were merely
assistants to sail. The steamers built in the later ’fifties were
intended to place reliance principally on their engines, because of
the regularity of passage thereby secured, rather than upon their
sail-power; so that even by this time, although the vessels were
described as auxiliary steamers, a more correct description would
have been that they were steam-propelled vessels carrying a large
spread of canvas.
In March 1859, Messrs. J. and W. Dudgeon issued a circular on the
subject of steam navigation direct to Calcutta round the Cape,
pointing out that “steam hereafter will be almost exclusively
employed in the transport of goods between East India and Australia
and the United Kingdom may be taken for granted; this is merely a
matter of time.” The circular continued that the Cape route would
certainly be simple and safe, and therefore superior to the overland
route, especially if it could be rendered expeditious and profitable.
The conditions required that vessels of not less than 5500 tons,
builders’ measurement, be supplied at a total cost per vessel of
£150,000; the voyage, it was anticipated, would take thirty or thirty-
five days, or only a couple of days more than the overland route. As
a correct forecast of the size of vessels which until a few years ago
conveyed the great bulk of the merchandise between Britain and the
Far East, this statement is interesting and shows how accurately the
needs of the traffic were estimated.
The “Norman” (Union-Castle Line, 1894).

In 1855 Messrs. A. and J. Inglis of Pointhouse, Glasgow, entered


into a contract “with a degree of boldness which only complete
success could have justified. They undertook to build the steamer
Tasmanian to the order of the European and Australian Steam
Navigation Company. The machinery, of over 3000 horse-power, was
at that time considered of the largest size, and to undertake the
erection of it in a little wooden shop barely twenty feet high, and
furnished with a fifteen-ton crane, was almost heroic. The soleplate
of this set of engines weighed 40 tons, and had to be lowered with
screw-jacks into a pit dug out to give height under the travelling
crane. Messrs. Inglis actually built up the crank-shaft themselves,
working the material in the smithy. The Tasmanian proved one of the
fastest screw steamers built up to that time, having easily attained
over 14¹⁄₂ knots at Stokes Bay. Her consumption of coal, about
three pounds per indicated horse-power, was for that day extremely
moderate. The engines were constructed with three cylinders, had a
built crank-shaft, valves at the side, variable expansion, steam
reversing gear, a built propeller, and other fittings which are still
reckoned in that comprehensive term, ‘all modern improvements.’
The engines worked most successfully until the general adoption of
the compound engine made so many admirable contrivances
obsolete.”[75] Shortly after building the Tasmanian, Messrs. A. and J.
Inglis began to build for the British India Company with excellent
results to all concerned, and since then they have constructed many
vessels for this famous company.
[75] Engineering, July 30, 1897.

In July 1858, owing to the failure of the European and Australian


Mail Company, the Royal Mail Steam Packet Company agreed with
the Lords Commissioners of the Admiralty to continue the Australian
mail service, and entered into a mail contract for eight months for a
subsidy at the rate of £185,000 per annum, giving a monthly sailing,
with Government guarantee of £6000 a month under certain
circumstances if there were loss in the working.
The line of mail packets between Panama, New Zealand, and
Sydney was maintained in connection with the R.M.S.P. service to
the West Indies and Panama with the mails, and was regarded as a
useful alternative to the line from Point de Galle to King George’s
Sound and other Australian ports. The Panama, New Zealand, and
Australian Royal Mail Company was granted a yearly subsidy of
£9000 for the main line, excluding the intercolonial services, the
amount to be increased to £110,000 if the New Zealand Government
should afterwards stipulate for a higher rate of speed. The Ruahine,
the second vessel laid down, but the first completed for this line,
was constructed by Messrs. Dudgeon, and was a brig-rigged steamer
of 1500 tons, and was 265 feet long, 34 feet beam, and 25 feet 7
inches deep, and had engines of 354 nominal horse-power, driving
Dudgeon’s double screws. She had accommodation for 100 cabin
passengers, 40 second cabin, and 65 in the steerage. She left
London on her maiden voyage in April 1865, and made the voyage
to her final Australian port in 63 days, of which she was only 55 days
actually at sea, the other days being accounted for by calls en route.
She was expected to make the passage between Panama and
Wellington in 25 days.
The Pacific Steam Navigation Company, which celebrated the
seventieth anniversary of its foundation in February 1910, owes its
inception to the enterprise of William Wheelwright, an American,
who was born at Newburyport, Massachusetts, in 1794, and died in
London while visiting England in September 1873. He began his
business life as a printer’s apprentice, but soon went to sea, and by
the time he was nineteen years old he was in command of a ship.
He was captain of the Rising Empire when she was wrecked in 1823
off the Plate, and then shipped as supercargo on a vessel bound
from Buenos Ayres to Valparaiso. The following year he was
appointed United States Consul at Guayaquil and five years later
removed to Valparaiso. With the view of extending American
commerce and supplying better communication than then existed on
the coast, he established in 1829 a line of passenger vessels
between Valparaiso and Cobija, and in 1835 decided to place
steamers on the west coast. It took him three years to obtain the
necessary concessions from the South American countries
concerned. American capitalists fought shy of his proposals, so in
1838 he came to England, where he was well received. His plan
included the adoption of the route across the Isthmus of Panama,
though many years passed before this portion of it was realised. The
necessary capital, £250,000, was raised in 5000 shares of £50 each,
and a Royal Charter was granted on February 17, 1840. The two
wooden paddle-steamers, Chili and Peru, were built for the line by
Messrs. Curling, Young and Co. of London in 1839; they were sister
vessels and were each about 198 feet long by about 50 feet over the
paddle-boxes and were brig-rigged, of about 700 tons gross, and
had side-lever engines of about 150 horse-power by Miller and
Ravenhill. In 1840 they passed through the Straits of Magellan, Mr.
Wheelwright being on board one of them, and received a series of
national welcomes along the west coast. Coaling difficulties were
serious, and at one time the boats were laid up for three months. At
last, in order to secure a sufficient supply, Mr. Wheelwright began to
operate mines in Chili. These vessels were not, as has often been
stated, the first steamers to enter the Pacific, for in 1825 a small
steamer, the Telica, belonging to a Spaniard, tried to trade on the
coast, but was a financial failure and the owner blew up his vessel
and himself with gunpowder at Guayaquil.
The Pacific Steam Navigation Company came near to being a
failure, but held on, and in 1852, having secured a further postal
contract, the company added four larger vessels of about 1000 tons
each to its fleet, all of them being employed on the purely local
service.
In 1852 there was a bimonthly service from Valparaiso to Panama,
where the line had a connection across the isthmus with the Atlantic
navigation. In 1855 the Panama Railway was opened, and the
company’s activity was greatly increased. In the following year also
the company adopted the compound type of engines, which was
only just brought out, being, it is stated, the first steam-ship
proprietary to do so for ocean traffic, and influenced probably by the
immense saving thereby made in fuel consumption.
Contracts were made in 1848 by the United States Government
with George Law, an American financier and shipowner, and his
associates, to carry the American mails from New York to Aspinwall
on the Isthmus of Panama, and with C. H. Aspinwall to convey the
mails on the Pacific side from Panama to San Francisco and ports
beyond. This was the inauguration of the Pacific Mail Line, and its
first steamer, the California, sailed from New York in October of that
year for San Francisco. The gold rush was at its height and the
demand for the steam-ships was so great that she was quickly
followed by the Pacific and Oregon, the latter built in 1845. All three
were wooden paddle-steamers about 200 feet long and of nearly
1060 tonnage, and made good passages round Cape Horn.
With the arrival of the three steamers on the west coast, the
transisthmian route was adopted for passengers and light
merchandise, and the Ohio and Georgia, which Law had built,
carried, in 1849, the first passengers by steam-ship to the isthmus
from New York.[76]
[76] Marvin’s “American Merchant Marine.”
When the Pacific Mail Company established a competing line
between New York and Chagres, Law placed an opposition line of
four steamers on the Pacific. In 1851 the rivalry was ended by his
purchasing their steamers on the Atlantic side, and selling to them
his new line from Panama to San Francisco.
Twenty-nine fine steamers, of a total of 38,000 tons, were built in
ten years for the two branches of the Californian trade, and the
Pacific Mail Company, representing an amalgamation of the Law and
Aspinwall interests, assumed the position, which it has retained ever
since, of the leading American steam-ship company in the Pacific.
The company is asserted to have carried 175,000 passengers to the
“golden west” in that decade and to have brought back gold to the
value of forty million pounds sterling.
“The Administration, which was so liberal in helping the Collins
Line to beat the British, contracted with the Pacific Mail Steamship
Company, formed in 1847, for a service from Panama to Astoria, and
from New York, Charleston, and New Orleans to Havana, from which
port the company already had a connecting line to Chagres (Colon),
thus completing the connection between the coasts.... The speed
from Panama to San Francisco was more than ten miles an hour.
Thus the United States had line traffic of first-class character
connecting its remote coasts before it had an American line to
Europe. At Panama it connected with the Pacific Steam Navigation
Company, giving service to Peru and Chili, so that before the middle
of the century the Pacific had at least 5000 miles continuous steam
line traffic.”[77]
[77] “The Ocean Carrier,” by J. Russell Smith.

The Royal Mail Steam Packet Company in the seventy years of its
existence has played an eventful part in the history of the mercantile
marine. Its earliest steamers were wooden paddle-boats, and were
among the best, but in spite of their excellence they experienced an
extraordinary run of misfortunes, and losses by fire and wreck
marred the records of the company for several years after its
incorporation in 1839. Its charter has been revised and extended
from time to time, one clause being that the whole of the share
capital must be British owned, and the management British. In its
long career it has served almost every port in the West Indies with
the mails, and has had no less than fifty-three contracts. At one
stage its management was subjected to some strong criticism, but
under its present management the company has prospered by leaps
and bounds, affording an excellent illustration of the value of well-
directed energy and enterprise.
The history of the Royal Mail Steam Packet Company is the record
of the development of the steamship connection between this
country and the West Indian Colonies. In 1840 the original contract
was entered into with the Admiralty Commissioners for executing the
office of Lord High Admiral for the commencement of the mail
service to the West India Colonies, the Spanish Main, New York,
Halifax, Mexico, Cuba, &c.
The conditions under which the mail contract was to be carried
out were somewhat onerous. One was that the company should
receive on board every vessel a naval officer or other person and his
servant to take charge of the mails, and that every such person
should be recognised and considered by the company as the agent
of the Commissioners in charge of the mails. He was empowered to
require a strict observance of the contract and “to determine every
question whenever arising relative to proceeding to sea, or putting
into harbour, or to the necessity of stopping to assist any vessel in
distress, or to save human life.” A suitable first-class cabin was to be
furnished at the company’s expense, and appropriated to the
officer’s use; he was to be victualled by the company as a first-cabin
passenger without charge, and should he require a servant, such
servant, “and also any person appointed to take charge of the mails
on board,” should also be carried at the company’s cost. From which
it would appear that some very comfortable places were at the
disposal of the Admiralty. The Admiralty representative was also to
be allowed a properly manned four-oared boat to take him ashore
whenever he felt inclined to go. Various penalties were applicable for
breaches of the contract, the fines ranging from £100 for doing
something of which the official did not approve to £500 for a delay
of twelve hours, and a further £500 for every twelve hours “which
shall elapse until such vessel shall proceed direct on her voyage in
the performance of this contract,” so far as the Barbadoes mails
were concerned, and of £200 for mails for other places. Another
stipulation was that naval officers were to be charged only two-
thirds of the ordinary fares as passengers. The company’s subsidy
was to be £240,000 per annum.
The company’s first steamer, the Forth, was launched at Leith in
1841, and on January 1, 1842, the West Indian mail service was
established by the sailing of the steamer Thames from Falmouth. On
completion of her voyage she proceeded to Southampton, which has
been the terminal port of the company ever since. The company
organised transit by mules and canoes across the Isthmus of
Panama in 1846, opening up the route via Colon and Panama to the
Pacific ports.
In the same year the Admiralty, in order to make a through mail
communication between England and the West Coast of South
America, contracted with the Pacific Steam Navigation Company for
the carrying of mails from Panama in connection with the R.M.S.P.
service to Colon, and the next year the latter company made
through arrangements with the Pacific Steam Navigation Company
and the Panama Railroad Company for traffic from Southampton (via
Panama) to the South Pacific Ports.
Enough has been written to indicate in some detail the progress
made in steam-ship construction. Wood was the material chiefly
used until near the middle of the nineteenth century. Iron then
began to take its place and the screw-propeller to supersede the
paddle-wheel. Some iron screw steamers have already been
mentioned, but this was inevitable, as no hard and fast line can be
drawn across the history of invention and commercial enterprise, to
separate iron from wood and screw from paddle. The screw
propeller had actually been tried by Stevens in 1802, and iron boats
for inland waters were built as early as 1787.
But the general adoption of iron for building steam-ships and of
the screw for the propulsion of ocean-going ships marks a new era
in the history of steam-ship building.
CHAPTER VIII
EXPERIMENTAL IRON SHIPBUILDING

he suitability of iron for shipbuilding purposes had


been admitted long before the construction of
wooden vessels reached its limit as a profitable
undertaking. The first experiments with iron were on
a small scale, but they demonstrated the theory of
displacement, so that observant marine builders had
it borne in upon them that flotation depended rather
upon the displacement of the floating body than upon the specific
gravity of the material for which the floating body was constructed.
But the general public was unconvinced, and making deductions
from a limited knowledge of the subject, cried: “Put a piece of iron
on the water and see if it will float.” With the increase in the size of
wooden steamers and sailing vessels there came the demand for
stronger, heavier, and thicker timbers for all parts. This meant so
much more unremunerative weight of hull to be carried and so much
less space available in proportion to the size of the vessel; so that in
time the limit of carrying cargo at a profit and of staunchness of
construction was bound to be reached.
In wooden steam-ships the limit of length was about 275 feet over
all; the Great Eastern, built in 1858, proved that there was
apparently no limit to the length of the iron ship.[78]
[78] Mr. John Ward’s Presidential Address to the Institution of
Engineers and Shipbuilders in Scotland, 1907.

This length has been exceeded by a few American wooden sailing


vessels. The largest square-rigged vessel ever built in America, the
shipentine Shenandoah, was of wood; her dimensions being 299·7
feet, beam 49·1 feet, and depth 19·9 feet; 3407 tons gross and
3154 net. She was built at Bath (Maine) in 1890 for Messrs. A.
Sewall and Co., and was acquired a couple of years ago by the
United States Government for a hulk at San Francisco, but has since
been recommissioned. Though not a clipper in the strict sense of the
word, she was a fast sailer and is sometimes called the last of the
Yankee wooden clippers.
As wooden hulls were made larger they displayed a tendency,
especially when they were built to carry propelling engines, to sag or
hog, that is to say, to droop amidships or at the ends. This difficulty
was ingeniously overcome in America, where wooden steamers were
built longer and lighter and shallower than in Great Britain to suit the
vast rivers of that country, by Stevens, who introduced his hogging
frame, to which fuller reference has been made in Chapter II. But in
the steamers of Great Britain, which were entirely for deep sea, this
arrangement was impossible, and the solution of the difficulty had to
be found in the use of a material other than wood.
The only substitute was iron. The change from wood to iron
meant a saving in weight of hull of about thirty to forty per cent.,
while it is asserted that in a few cases there has been an even
greater difference. The saving also meant that the difference in
weight could be added to the weight of the cargo, without increasing
the displacement; while another advantage was that the beams and
ribs and stringers were of smaller dimensions, and the space thus
gained, added to that obtained by the substitution of thin iron plates
for wooden planking several inches thick, also very considerably
increased the space available for the stowage of cargo. Practically
every part of a ship was of wood until 1810, in which year the
scarcity of oak resulting from the extensive felling of trees in the
English forests compelled the use of iron for the knees or
connections between the deck-houses and the ribs, and for the
breast-hooks and pillars of ships.
An experimental iron barge was made in 1787 by J. Wilkinson the
ironmaster.
As early as 1809 it was proposed by Richard Trevithick and Robert
Dickenson that ships should be built of iron, but the proposal was
received with derision. The Vulcan, built in 1818 at Faskine near
Glasgow, is, so far as is known, the first iron vessel constructed for
commercial purposes, and so well was she built that as recently as
1875 she was engaged in transporting coal on the Forth and Clyde
Canal, and looked little the worse for wear. Her builder was one
Thomas Wilson.
The first iron steamer, however, was the Aaron Manby, built in
1821 at the Horseley Iron Works near Birmingham, to the order of
Captain Napier, afterwards Admiral Sir Charles Napier, and Mr.
Manby. She was put together at Rotherhithe, and in May 1822 at
Parliament Stairs took on board a distinguished party of naval
officers and engineers, whom she conveyed for a trip of several
hours up and down the river between Blackfriars and Battersea. A
contemporary newspaper described her as “the most complete
specimen of workmanship in the iron way that has ever been
witnessed.” This little vessel was 106 feet long and 17 feet broad,
and carried a 30-horse-power engine. Her wheels were of the type
known as Oldham’s revolving bars. Her only sea voyage was to
France under the command of Captain Napier. Upon arrival she was
employed on the Seine or Loire. Another iron vessel intended for
navigation on the Seine was shortly afterwards made in this country,
and the parts sent to France to be put together.
Little appears to have been attempted in this country for some
years in the way of iron shipbuilding, although in Ireland three or
four small iron sailers or steamers were constructed for inland
navigation purposes. But in 1828 John Laird of Birkenhead had his
attention directed to iron shipbuilding, and completed his first iron
vessel there the following year. Other builders followed where he
showed the way, and in less than three years there were
shipbuilders on the Thames, Clyde, and east coast of Scotland who
were launching iron vessels, the great majority of which were sailing
ships. The famous yards on the Cheshire side of the Mersey
remained for some time the headquarters of the new industry. The
first iron vessels for the United States—not the first iron-plated
vessels, and this is a distinction which should be noted—were
launched there, and so immediate was the recognition of the
advantages of iron ships over wooden ones that by 1835 there had
been built at Laird’s the first iron vessels for use on the rivers
Euphrates, Indus, Nile, Vistula, and Don. They were small compared
with the wooden vessels afloat.
The Garry Owen, built in 1834 by MacGregor, Laird and Co. of
iron, was only 125 feet in length, 21 feet 6 inches beam, with two
engines totalling 90 horse-power. There were no Lloyd’s rules as to
scantlings for iron steamers in those days, and builders put in as
much material as they thought necessary for the strength of the
vessel, which usually meant a liberal allowance. The Garry Owen
was not much to look at, but she was very strongly built, a
circumstance which had a great deal to do with the development of
iron steam-ship building. She nearly came to grief on her first
voyage, for she was overtaken by a violent storm, which drove her
and several other vessels ashore. These others were of wood. Some
of them were soon pounded to pieces by the heavy seas, and those
that escaped total loss were badly damaged; but the Garry Owen,
though bumped and dented somewhat, was able to get afloat again
little the worse and return under her own steam.
If a steamer strongly built of iron could survive a storm and
stranding which ended the careers of several wooden ships of larger
dimensions, it was admitted that there was no valid reason why
other iron vessels should not prove equally safe, especially if they
were larger. It was considered that iron steamers might find useful
employment in short voyages, and several were built.
One of the chief of these vessels was the Rainbow, launched in
1837 for the London and coastal trade. She was 185 feet long by 25
feet beam, and of 600 tons, with engines of 180 horse-power.
The use of iron in construction was not the only factor in the
tremendous change which was coming in shipbuilding. A new form
of propulsion was necessary, and it was found in the screw propeller.
Before considering this, however, the development in the
construction of paddle-wheels and of the engines designed for
paddle-boats may be noticed.
The ordinary paddle-wheel had the floats fixed upon the radial
arms, but it was soon found that an improvement could be made by
causing the floats to assume a position vertical, or nearly so, at the
moment of contact with the surface of the water, and to retain that
position until the float had left the water. To effect this the floats are
not bolted to the arms but pivoted, and are retained in the required
position by means of levers operated by an eccentric pin. By this
means a much greater propulsive force was exerted. The old style of
paddle-wheel with fixed floats is now very seldom employed. These
wheels are now only to be found in vessels in which the expense of
construction has to be cut down to a minimum, or in a certain type
of steamer plying in shallow rivers, where the wheel is rather large,
and the dip of the float slight; but here again economy of
construction may count for more with the proprietor of the boat than
the increased speed he could obtain with the more expensive
feathering wheels. Many of the modern wheeled vessels have floats
of steel, but in the great majority of cases wood is employed, elm
being largely used for this purpose. The floats are usually about four
times as long as they are broad. Various forms are used, some being
left square at the corners, others are rounded, others again have the
outer edge elliptical in shape, and the experiment has also been
tried with a fair measure of success of inclining the floats to the axis
of the wheel, instead of having them parallel to it. The advantages
claimed for this last method are that the stream of water formed by
the rotatory motion of the paddles is driven slightly away from the
sides of the vessel, instead of in a direction parallel with her length.
Wheels of this type, however, lose much of their effectiveness when
the engines are reversed. Radial wheels are sometimes made with
the floats adjusted so that they enter the water almost
perpendicularly, but they are much more oblique under this
arrangement when leaving the water.
A difficulty which paddle-vessels have to contend with is that of
securing a proper immersion of the floats. For a vessel in smooth
water the immersion of the top edge is usually calculated at about
one-eighth of the breadth of the float; but for a vessel intended for
general sea service, an immersion of not less than half the breadth
of the float is allowed, that is to say, the float at its moment of
deepest immersion has a height of water above it equal to half its
diameter. If the float goes much deeper the efficiency of the wheel
becomes impaired. This is a point which has to be taken into
consideration in designing paddle-boats, so that the maximum
power shall be available when the vessel is fully laden, and shall not
be much lessened when the vessel is running light. The earliest
steamers suffered greatly in this respect as their designers had not
discovered the right size of wheels or floats to suit the hulls. A
loaded vessel consequently went very slowly owing to the great
depth to which her floats were immersed. To overcome this difficulty
an ingenious system of what can best be called reefing was
invented. Affixed to the axle of the wheel was a rod with an
arrangement of cogs at the end, and these fitted into a series of
teeth in rods affixed to the floats, so that it was a simple matter to
expand or contract the effective diameter of the wheel by altering
the position of the floats as required. The same result has
sometimes been obtained by a system of levers, but the toothed
wheel business was the older. It was tried on a few of the earlier
boats on the Clyde, not always, however, with success.
A peculiarity of some of the larger paddle-wheels in use in
America is that they are not only of much greater size than those in
use in Great Britain in proportion to the size of the boat, but they
have a proportionately less immersion and the wheel is constructed
in a very different fashion. The floats, instead of being of one piece,
as here, are constructed of three narrow fixed strips, two of which
are on the same radius but have a space between them equal to the
breadth of the third strip, which is placed a few inches behind the
vacant space. It is contended that this method disturbs the water
less than the broad float and increases the propelling efficiency.
Probably the most notable instance is the great wheel of the
Sprague.
Referring now to the construction of the engines of the earliest
boats, Symington’s Charlotte Dundas used a horizontal direct-acting
engine, and the general arrangement of her machinery would be
considered creditable even at the present day.[79] The engine of the
Savannah was of the inclined direct-acting type. The type of engine
which Newcomen invented has been retained for many years, but
the oscillating or walking beam which is such a conspicuous feature
of nearly all the American river craft has been placed by engineers in
this country below the crank axle instead of above. The type of
engine with the beam below the crank axle is known as the side
lever. It is a type peculiarly suitable to paddle-wheels, and this being
the only method of propulsion adopted on this side of the Atlantic
for many years, there was little change for a considerable period in
the shape of the engines, which therefore attained to a high stage of
perfection until the limit of their profitable employment was reached.
When larger engines became necessary, in consequence of the
rapidly increasing size of vessels, the great weight of the side-lever
engines proved a serious drawback.
[79] Sennet and Oram’s “The Marine Steam-Engine,” 1898.

Engineers were not long in devising a more compact form of


machinery, and direct-acting engines were introduced, these
involving the abandonment of the use of the heavy side levers. As
the side-lever engines were made larger it became customary to use
two beams, one on each side, and a rod from one end of each of
these connected with a cross-piece at the top of the piston-rod. The
other ends of the double beam were united by a cross-piece which
carried from its centre the rod or lever which worked the crank of
the paddle-shaft. Where it became necessary to use two engines in
one vessel, they were so arranged that while one rod and crank
were at their period of least activity, the other pair were exerting
their greatest effort. The system of condensation of steam, which it
would take too much space to describe in detail, is also a matter of
great importance in determining the power of the engine, but the
principle upon which the condensation is effected is well known, and
the various methods of condensation can easily be ascertained from
the numerous handbooks on engineering.
Maudslay’s Oscillating Engine.

Another early form of marine engine was that in which the side
levers were arranged as levers of the third order, the fulcrum being
at one end and the steam cylinder placed between it and the
connecting-rod. The peculiar motion thereby given to the machinery
caused this type to be known as the grasshopper engine, from a
fancied resemblance to the long legs of a grasshopper. The direct-
acting engines were much more compact, more powerful, and lighter
than the old side levers. The necessity of providing a connecting-rod
of sufficient length was met by Messrs. Maudslay by the provision of
two cylinders. The cross-head was not unlike the letter T, the foot of
which passed down between the cylinders, and the lower end of this
was fitted with a journal from which the connecting-rod extended to
the crank in the axle. A still further improvement was made when

You might also like