1 / 11

NetCDF and binary read in MATLAB

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.

jed
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NetCDFand binary read in MATLAB Pierre Chien 2009/03/19

  2. NetCDF in FORTRAN 77

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. Read and Write binary file in MATLAB

  9. 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)

  10. 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)

  11. 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);

More Related