File Input / Output Dennis Shea Input Output

Slides:



Advertisements
Similar presentations
The NCAR Command Language (NCL) and the NetCDF Data Format Research Tools Presentation Matthew Janiga 10/30/2012.
Advertisements

Input from STDIN STDIN, standard input, comes from the keyboard. STDIN can also be used with file re-direction from the command line. For instance, if.
COSC 120 Computer Programming
NCL NCL stands for NCAR Command Language. It is similar to IDL and MATLAB. It is most convenient for reading NetCDF files and plotting maps, but there.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Guide To UNIX Using Linux Third Edition
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
FORTRAN Short Course Week 3 Kate Thayer-Calder February 23, 2009.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Status of netCDF-3, netCDF-4, and CF Conventions Russ Rew Community Standards for Unstructured Grids Workshop, Boulder
The NCAR Command Language (NCL) Ethan Alpert Visualization and Enabling Technologies Section, SCD, NCAR.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Lesson 11-Locating, Printing, and Archiving User Files.
FORTRAN Short Course Week 4 Kate Thayer-Calder March 10, 2009.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
NCL Introduction Dennis Shea National Center for Atmospheric Research.
Slides based on lectures from the NCL workshop Also see the NCL homepage.
NetCDF Operators 1 netCDF Operators [NCO]
Introduction Dennis Shea NCAR is sponsored by the National Science Foundation.
Accessing Remote Datasets using the DAP protocol through the netCDF interface. Dr. Dennis Heimbigner Unidata netCDF Workshop August 3-4, 2009.
File IO Dennis Shea National Center for Atmospheric Research pdf Vis5D png NCAR is sponsored by the National Science Foundation Shapefiles.
Advanced Utilities Extending ncgen to support the netCDF-4 Data Model Dr. Dennis Heimbigner Unidata netCDF Workshop August 3-4, 2009.
Brief Overview: GRIB, HDF, WRF.nc
The HDF Group HDF/HDF-EOS Workshop XV1 Tools to Improve the Usability of NASA HDF Data Kent Yang and Joe Lee The HDF Group April 17, 2012.
Climate Data Formats Deniz Bozkurt
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Eurasia Institute of Earth Sciences Istanbul Technical University NCL Introduction Deniz Bozkurt web.itu.edu.tr/bozkurtd ITU Eurasia Institute of Earth.
EARTH SCIENCE MARKUP LANGUAGE Tutorial on how to write an ESML Description File (for ESML Schema v3.0) “Define Once Use Anywhere” INFORMATION TECHNOLOGY.
NCL Sample Scripts Dennis Shea Climate and Global Dynamics Division Climate Analysis Section.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
The HDF Group Introduction to netCDF-4 Elena Pourmal The HDF Group 110/17/2015.
Dennis Shea National Center for Atmospheric Research
16. Python Files I/O Printing to the Screen: The simplest way to produce output is using the print statement where you can pass zero or more expressions,
SCD User Briefing NCL and PyNGL Visualization for the Geosciences Don Middleton with presentation material developed by Luca Cinquini, Mary Haley, Fred.
Postgraduate Computing Lectures PAW 1 PAW: Physicist Analysis Workstation What is PAW? –A tool to display and manipulate data. Learning PAW –See ref. in.
B Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Working with PDF and eText Templates.
CF 2.0 Coming Soon? (Climate and Forecast Conventions for netCDF) Ethan Davis ESO Developing Standards - ESIP Summer Mtg 14 July 2015.
NetCDF Operators 1 netCDF Operators [NCO]
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Introduction Dennis Shea NCAR is sponsored by the National Science Foundation.
NcBrowse: A Graphical netCDF File Browser Donald Denbo NOAA-PMEL/UW-JISAO
Utilities for netCDF-4 Dr. Dennis Heimbigner Unidata Advanced netCDF Workshop July 25, 2011.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Lesson 5-Exploring Utilities
DAP+NETCDF Using the netCDF-4 Data Model
Input from STDIN STDIN, standard input, comes from the keyboard.
Chapter 6 Filters.
NetCDF 資料格式介紹 NCL 變數設定介紹
National Scientific Library at Tbilisi State University
Intro to PHP & Variables
MATLAB: Structures and File I/O
Unidata Advanced netCDF Workshop
Topics Introduction to File Input and Output
Using SQL*Loader The SQL*Loader command needs to be run from a DOS window or NT. The SQL*Loader uses the following three files: control file: contains.
IO Overview CSCE 121 J. Michael Moore
NetCDF and Scientific Data Standard
Chapter Four UNIX File Processing.
Perl I/O Learning Objectives:
Functions continued.
Tour of NCL Website Modified by R. Grotjahn
NCL variable based on a netCDF variable model
Topics Introduction to File Input and Output
Week 10 FILE PROCESSING.
IO Overview CSCE 121 Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch.
Presentation transcript:

File Input / Output Dennis Shea Input Output NCAR Command Language An Integrated Processing Environment X11 PS EPS PDF SVG PNG NCGM NetCDF 3/4 HDF-EOS 2/5 HDF 4/5 GRIB 1/2 Shapefile ASCII CCM Binary Input Compute Output NetCDF 3/4 HDF ASCII Binary Fortran / C Dennis Shea National Center for Atmospheric Research NCAR is sponsored by the National Science Foundation

自我描述檔案 (self-described data)

ncl_filedump http://www.ncl.ucar.edu/Document/Tools/ncl_filedump.shtml ncl_filedump [-c] [-v var1[,…]] [–h] file_name command line utility with options provides textual overview of any supported file’s contents behavior analogous to Unidata’s ncdump -h file_name must have a file type suffix on command line .nc .grb .hdf .hdfeos .he5 .h5 .ccm .shp [case insensitive] suffix used as identifier only, actual file need not have A complicated ascii file might look like: Q123.7 Apple 17.3 789 xD-90.7 ncl_filedump file_name.[grb/nc/hdf/hdfeos] output can be sent to file or viewer via Unix redirection/ pipe ncl_filedump foo.grb > foo.txt [send to file] ncl_filedump foo.hdf | less [send to viewer]

addfile Opens a supported format Variables look like netCDF (Grib, HDF, HDF-EOS) f = addfile (file_name.ext, status ) file_name => any valid file name; string ext => extension that identifies the type of file; string netCDF: "nc" or "cdf" [read/write] HDF: "hdf" , "hdfeos”, "h5”, "he5" [read/write] GRIB: "grb" , "grib" [read only; GRIB1 or GRIB2] CCMHT: "ccm" [read only] SHAPE (GIS): ”shp" [read only] extension not required to be attached to file status [read/write status] "r", "c", "w" f reference/pointer to a single file; any valid variable name may have attributes (file attributes or global attributes) http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclFormatSupport.shtml

Import Variable from Supported Fmt u = f->U read variable and all meta data into memory [structure] no space allowed to left/right of -> [ fatal error] use "$" syntax to represent variable name if type string f = addfile ("foo.grb", "r") vNam = getfilevarnames (f) ; all variables on file or vNam = (/ ”SLP", ”T" /) ; manually specify do n=0,dimsizes(vNam)-1 x := f->$vNam(n)$ ; $..$ substitute string ..... end do u = (/ f->U /) - read data values only and _FillValue attribute

netCDF [NCL] Variable model X Scalar or Array f = addfile(“foo.nc”, “r”) ; grb/hdf x = f->X NCL reads the scalar/array, attributes, and coordinate variables as an object attributes long_name _FillValue units add_offset scale_factor etc. X accessed via @ accessed via & values Scalar or Array attributes long_name _FillValue units add_offset scale_factor etc. time lev lat lon etc. coord var time lev lat lon etc. coordinates

Example: open, read, output netCDF ;--------------------------------------------- fin = addfile ("in.nc, "r") ; open file and read in data u = fin->U ; import a variable (time,lev,lat,lon) fout = addfile("out.nc" , "c") ; create reference to output file fout@title = "I/O Example 1" ; add a global attribute to the file ;---------------------------------------------- ;Output variable : ;----------------------------------------------- fout->U2 = u ; output variable u to nc file

讀取大量檔案 (exercise 5) addfiles

addfiles (1 of 2) span multiple supported files q = addfiles (fNames, "r") fNames is a 1D array of file names (strings) can be used for any supported format technically, "q" is a variable of type list T = q[:]->T ; [:] read all files read T [with meta data] from each file in list ‘q’ T must exist in each file and be same shape [rank] a list is used to sequence results of addfiles normal file variable selection is used with "[…]" lat = q[0]->lat ; [0] read from first file Z = q[2:6:2]->Z ; extract Z only from files 2,4,6

addfiles (2 of 2) 2 options on variable merging ListSetType (a, "cat") [default; "cat" => concatenation] ListSetType (a, "join") when to use "cat" and "join" [rule of thumb] cat: continuous record join: creating ensembles a record dimension will be added

Example: Read "T" across 5 files ["cat"] [Each file has 12 months] fils = systemfunc ("ls ./ann*.nc") f = addfiles (fils, "r") ListSetType(f, "cat") ; not necessary [default] T = f[:]->T ; read T from all files printVarSummary(T) Variable: T Type: float Total Size: 5529600 bytes 1382400 values Attributes: 2 units: K long_name: temp Number of Dimensions: 4 Dimensions and sizes: [time|60] x [lev|5] x [lat | 48] x [lon | 96] Coordinates: time: [2349 … 4123] lat: [-87.159..87.159] lev: [85000 … 25000] lon: [0..356.25]

addfiles: option ["join"] fils = systemfunc ("ls ./ann*.nc") f = addfiles (fils, "r") ListSetType (f, "join") T = f[:]->T printVarSummary (T) Variable: T Type: float Total Size: 5529600 bytes 1382400 values Attributes: 2 units: K long_name: temperature Number of Dimensions: 5 Dim/sizes: [case | 5] x [time|12] x [lev|5] x [lat | 48] x [lon | 96] Coordinates: time: [2349 … 2683] lat: [-87.159..87.159] lev: [85000 … 25000] lon: [0..356.25]

純文字與二進位檔案 (exercise 7~9)

Reading Simple ASCII Table 1881 -999.9 0.2 -999.9 -999.9 1.5 -999.9 -999.9 -0.2 1882 -1.7 -0.5 0.6 0.1 0.9 -1.9 -3.5 -4.6 1995 -1.0 -0.8 0.4 -1.8 -1.2 -0.4 0.6 -0.1 0 1 2 3 4 5 6 7 8 ; read in data ncols = 9 nrows = 3 ksoi = asciiread ("ascii.in", (/nrows,ncols/), "float") ; partition total array into individual vector arrays yrs = ksoi(:, 0) mon1 = ksoi(:, 1) data = ksoi(:, 1:) ; all but leftmost column ;if you were going to plot/compute, must assign meta data data@_FillValue = -999.9 ; manually assign

Reading Binary/ASCII data 7 functions for reading binary: fbinrecread: reads multiple unformatted sequential records [Fortran; ieee] fbinnumrec: returns the number of unformatted sequential records [Fortran; ieee] fbindirread: reads specified record from a Fortran direct access file [ieee] fbinread: same as fbinrecread but reads only one ieee rec craybinrecread: like fbinrecread but for COS blocked data craybinnumrec: like fbinnumrec but for COS blocked data cbinread: read binary created via C block IO function "write" 1 function for reading ASCII data: asciiread [contributed.ncl: readAsciiTable] use NCL str_* functions; Fortran/C to read complicated ASCII files all above functions allow data to be shaped x = fbinrecread ("foo_ieee", rnum, (/10,20,30/), "float") a = asciiread ("foo_ascii", (/64,128/) , "float")

Writing Binary/ASCII data 4 procedures for writing (ieee) binary data fbinrecwrite: write unformatted fortran sequential recs fbindirwrite: write specified record; fortran direct access fbinwrite: write a binary file containing a single record cbinwrite: write binary file ; mimics C block IO "write“ setfileoption: can be used to alter default behavior 2 procedures to write ascii data asciiwrite: write a file containing ASCII characters writes a single flat ASCII file. One value per line. No user control of format write_matrix: write a multi-dim array to std out or to a file user has format control … pretty-print options for title and row numbering use Fortran/C to write complicated ASCII files.