Combining NCL and Fortran in C-shell

Slides:



Advertisements
Similar presentations
Computational Physics Linear Algebra Dr. Guy Tel-Zur Sunset in Caruaru by Jaime JaimeJunior. publicdomainpictures.netVersion , 14:00.
Advertisements

Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
A Guide to Unix Using Linux Fourth Edition
CSE 303 Lecture 16 Multi-file (larger) programs
Web Technologies Using the Internet to publish data and applications.
Objected Oriented Perl An introduction – because I don’t have the time or patience for an in- depth OOP lecture series…
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 17 JavaScript.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
External Fortran-C Codes external codes, Fortran, C, or local commerical libraries may be executed from within NCL generic process – develop a wrapper.
Chapter 2, Linear Systems, Mainly LU Decomposition.
Chapter 6 Programming with Functions. FUNCTIONS Intrinsic Functions (or called library functions) Function Subprograms: programmer-defined functions.
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Fortran 9x HTML version. New F90 features Free source form Modules User-defined data types and operators Generic user-defined procedures Interface blocks.
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
Guide To UNIX Using Linux Third Edition
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Review of C++ Programming Part II Sheng-Fang Huang.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
The NCAR Command Language (NCL) Ethan Alpert Visualization and Enabling Technologies Section, SCD, NCAR.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
Fortran: Specification Statements Session Six ICoCSIS.
Introduction to FORTRAN
1 VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
259 Lecture 13 Spring 2013 Advanced Excel Topics – Arrays.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Module and Data Sharing. Programming in the Large Software, in general, is large having multiple units Multiple units designed and developed independently.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room , Chris Hill, Room ,
Beginning Fortran Fortran (77) Advanced 29 October 2009 *Black text on white background provided for easy printing.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Programming with Microsoft Visual Basic th Edition
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Engineering Optimization Most engineering design involves using optimization software Minimizes or maximizes a merit function Applies functional constraints.
ENG College of Engineering Engineering Education Innovation Center 1 Functions 1 in MATLAB Topics Covered: 1.Uses of Functions Organizational Tool.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
Dynamic Data Structures. Point to Derived Data Values So far, we saw examples where pointers pointed to targets that are simple or array variables Targets.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Linux Administration Working with the BASH Shell.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Sets and Maps Chapter 9.
Unit 2 Technology Systems
Advanced Excel Topics – Arrays
Chapter 9: Value-Returning Functions
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Chapter 2, Linear Systems, Mainly LU Decomposition
Linear Systems, Mainly LU Decomposition
classes and objects review
2. Understanding VB Variables
Peer Instruction 6 Java Arrays.
Chapter 6 Variables What is VBScript?
Variables Title slide variables.
CS285 Introduction - Visual Basic
Tonga Institute of Higher Education
Sets and Maps Chapter 9.
mdul-cntns-sub-cmmnts2.f90
Presentation transcript:

Combining NCL and Fortran in C-shell #!/usr/bin/csh # =========== NCL ============ cat >! main.ncl << "END_NCL" load ”$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load ”$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl“ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl“ external SUB "./sub.so" ; sub.so created below begin ... NCL script(s) end "END_NCL" # ===========FORTRAN ======== cat >! sub.f << "END_SUBF" C NCLFORTSTART ... can be many fortran codes …. C NCLEND "END_SUBF" # =========== WRAPIT========== WRAPIT sub.f # =========== EXECUTE ======== ncl main.ncl >&! main.out This can be convenient when debugging an NCL-Fortran script

Accessing LAPACK (1 of 2) double precision LAPACK (BLAS) => distributed with NCL explicitly link LAPACK lib via fortran interface: WRAPIT eg LAPACK subroutine dgels solves [over/under] determined real linear system create an interface subroutine (here: dgels_interface.f) C NCLFORTSTART SUBROUTINE DGELSI( M, N, NRHS, A, B, LWORK, WORK ) IMPLICIT NONE INTEGER M, N, NRHS, LWORK DOUBLE PRECISION A( M, N ), B( M, NRHS), WORK(LWORK) C NCLEND C declare local variables INTEGER INFO CHARACTER*1 TRANS TRANS = "N” CALL DGELS(TRANS, M,N,NRHS,A,LDA,B,LDB,WORK,LWORK,INFO) RETURN END WRAPIT –L $NCARG_ROOT/lib -l lapack_ncl dgels_interface.f

Accessing LAPACK (2 of 2) external DGELS "./dgels_interface.so” ; NAG example: http://www.nag.com/lapack-ex/node45.html ; These are transposed from the fortran example A = (/ (/ -0.57, -1.93, 2.30, -1.93, 0.15, -0.02 /), \ ; (4,6) (/ -1.28, 1.08, 0.24, 0.64, 0.30, 1.03 /), \ (/ -0.39, -0.31, 0.40, -0.66, 0.15, -1.43 /), \ (/ 0.25, -2.14,-0.35, 0.08,-2.13, 0.50 /) /)*1d0 ; must be double dimA = dimsizes(A) N = dimA(0) ; 4 M = dimA(1) ; 6 B = (/-2.67 ,-0.55 ,3.34, -0.77, 0.48, 4.10/)*1d0 ; must be double ; LAPACK wants 2D nrhs = 1 B2 = conform_dims ( (/nrhs,M/), B, 1 ) ; (1,6) B2(0,:) = B lwork = 500 ; allocate space work = new ( lwork, "double", "No_FillValue") ; must be double DGELS::dgelsi(M, N, nrhs, A , B2, lwork, work ) ; call interface print(B2(0,0:N-1))

Global Variables and Scope [1 of 2] by definition: can be accessed from any function or procedure different from local variables NCL does not have explicit “global variables” requires understanding of NCL’s variable scope [identical to Pascal] http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml#Scoping load “dummy_1.ncl” ; not aware of constants below GRAVITY = 9.8 RGAS = 204 load “dummy_2.ncl” ; can use GRAVITY and RGAS REARTH = 6371.009 ; km load “dummy_3.ncl” ; can use GRAVITY, RGAS, REARTH begin ; can use GRAVITY, RGAS, REARTH : end

Global Variables and Scope [2 of 2] knowledgeable user can simulate … one approach create a file, eg GLOBAL.ncl (no: begin / end ) populate with desired constants best to follow some user defined conventions [e.g. capital letters to ensure uniqueness] ; contents of GLOBAL.ncl GRAVITY = 9.8 ; GRAVITY@units = “m/s” GRAVITY_d = 9.81d ; m/s (type double) RDRY = 286.9 ; J/(kg-K) REARTH = 6371.009 ; km load "/my/path/GLOBAL.ncl“ load "foo_1.ncl“ ; can ‘see’ constants in GLOBAL.ncl begin ; main script ; can ‘see’ constants in GLOBAL.ncl … end

list variable [1 of 3] ‘container’ for one or more variables of any type (file, string, numeric) elements of a list are accessed via square brackets […] three ways to create a variable of type list f = addfiles(…) x = [/…/] ; list constructor a = NewList(…) q = addfiles (fil_names, "r") ; q is of type “list” x = q[:]->X ; [:] mean all elements of list s = q[2:8:2]->X ; extract x from files 2,4,6,8 f = addfile(…., “r”) ; type file i = ispan(1,10,2) ; integer z = (/ “example”, “wkshop”/) ; array constructor variable (/.../) delete( [/ f, i, z /] ) ; delete multiple variables

list variable [2 of 3] r = random_normal(mean, stdev, N) ; create numeric variable s = (/ “sample” , “string” /) ; create a string variable lst = NewList (“fifo”) ; create a list variable ListPush (lst, r ) ; add ‘r’ to ‘lst’ ListPush (lst, r^2 ) ; add r^2 ListPush (lst, s ) ; add s nlst = ListCount( lst ) ; number of items in ‘lst’ do n=0,nlst-1 print( lst[n] ) ; print contents of list item ‘n’, use […] end do

list variable [3 of 3] function foo(….) A list variable may be used to return multiple variables from a function  Similar to (say) Matlab ……. but not as nice  function foo(….) begin x = … some calculation … ; x(:,:,:) with meta data s = (/ “string1”, “string2”/) ; s(2) … s(0)=“string1”, s(1)=”string2” z = … some calculation … ; z(:) return( [/s, x, z /]) ; return multiple variables as a list end ;---------------- Main ---------------------------- ….. NCL code ….. result = foo(…) ; result is a list variable s = result[0] ; explicitly extract each variable x = result[1] ; convenience/clarity only z = result[2] delete(result) ; no longer needed Could access list elements directly but it is cumbersome, less clear print( result[0](1) ) ;  “string2” …. not at all clear