Download presentation
Presentation is loading. Please wait.
Published byCollin Butler Modified over 8 years ago
1
NetCDF and 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
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)
7
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)
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);
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.