Netcdf and binary read in matlab
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

NetCDF and binary read in MATLAB PowerPoint PPT Presentation


  • 100 Views
  • Uploaded on
  • Presentation posted in: General

NetCDF and binary read in MATLAB. Pierre Chien 2009/03/19. NetCDF in FORTRAN 77. NetCDF (network Common Data Form) is a set of software libraries and machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. Use NetCDF in MATLAB.

Download Presentation

NetCDF and binary read in MATLAB

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Netcdf and binary read in matlab

NetCDFand binary read in MATLAB

Pierre Chien

2009/03/19


Netcdf in fortran 77

NetCDF in FORTRAN 77


Netcdf and binary read in matlab

  • NetCDF (network Common Data Form) is a set of software libraries and machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data


Use netcdf in matlab

Use NetCDF in MATLAB

  • Two path were required to be added before using NetCDF

    • addpath mexnc

    • addpath matlab_netCDF_OPeNDAP

  • Two common way to read NetCDF

    • inqnc(‘file’)

      • To see what do they have in this nc file

    • getnc(‘file’,‘variable_name’);

      • To get the variable in the nc file


Use netcdf in linux

Use NetCDF in Linux

  • ncdump -h file

    • Output the title for this nc file

  • ncdump -v variable file

    • Output the value in this variable for this nc file


Use netcdf in fortran

PROGRAM MAIN

include ‘netcdf.inc’

INTEGER start(3),count(3),strid(3)

INTEGER ncid,varid,status

REAL TEMP(No,Na,itime)

DATA start /1,1,1/

DATA count /1,1,1/

DATA strid /1,1,1/

status=nf_open(input, nf_nowrite, ncid)

If (status .ne. nf_noerr)print *, nf_strerror(status)

status = nf_inq_varid (ncid, ‘U10’, varid)

status = nf_get_varS_real (ncid, varid, start, count, strid, TEMP)

nfclose = nf_close(ncid)

Use NetCDF in FORTRAN


Write netcdf in fortran

PROGRAM MAIN

include ‘netcdf.inc’

INTEGER start(3),count(3)

INTEGER ncid,varid,status

REAL TEMP(No,Na,itime)

DATA start /1,1,1/

DATA count /1,1,1/

status=nf_open(input, nf_write, ncid)

status = nf_inq_varid (ncid, ‘U10’, varid)

status = nf_get_varA_real (ncid, varid, start, count, TEMP)

status = nf_put_varA_real(ncid, varid, start, count, TEMP)

nfclose = nf_close(ncid)

Write NetCDF in FORTRAN


Read and write binary file in matlab

Read and Write binary file in MATLAB


Ascii file in fortran

ASCII file in FORTRAN

OPEN(174, file='T2_test', form='formatted')

WRITE(174,*) 'ITF=', ITF-1

DO J = 1, J0

write(174,999) ((T2(I,J,1)+T2(I,J,2))*.5, I = 1, I0)

ENDDO

999 format(122f8.3)


Binary file in fortran

Binary file in FORTRAN

OPEN(175, file='T2_testa', form='unformatted')

WRITE(175) ((REAL(T2(I,J,1)+T2(I,J,2))*.5,I=1,I0),J=1,J0)


Reading binary file in matlab

Reading binary file in MATLAB

INTSIZE4=‘int32’; REALSIZE = ‘real*4’;

fid = fopen(‘file’,‘r’,‘b’);

fread(fid,1,INTSIZE4)

TEMP = fread(fid,I0*J0,REALSIZE);

SST = reshape(TEMP,I0,J0);

fread(fid,1,INTSIZE4)

fclose(fid);


  • Login