- 积分
- 1128
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-11-2
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本想上传到 FORTRAN 板块,但是觉得 ncl 这儿比较需要 贴在这儿
为了方便 已经上手ncl 画图的兄弟们,
找到一篇以前的 FORTRAN程序写nc 的程序》
提供 麻雀程序一篇,供大家 玩味
FORTRAN 写 ncl
program CREATENCF
!C... include the usefully NetCDF include file
include 'netcdf.inc'
!C... define the variables used in this program !
integer status, ncid ! status is a test flag and ncid is the unit of open(creat) files
integer LATID, LONID, TIMEID !dimention's ID
integer PM10ID,PM2_5ID ! variable's ID
integer PM10dim(3), PM2_5dim(3)
integer nlon, nlat, ntime
parameter (nlon=10, nlat=10, ntime=10)
real PM10array(nlon, nlat, ntime) ! variable's array ==>this is data array
real PM2_5array(nlon, nlat, ntime)
integer start(3), count(3)
data start /1,1,1/
data count /nlon, nlat, ntime/
!C... get the library version of NetCDF in this mashine
write(*,*), 'The NetCDFs Library version is ==> ', nf_inq_libvers()
!C... begin to creat a new NetCDF file
status=nf_create('create.nc', nf_clobber, ncid)
if (status .NE. nf_noerr) call handle_err(status)
write(*,*), 'create an NetCDF file, and its ID is => ', ncid
!C... begin to define your dimentions
status=nf_def_dim(ncid, 'lat', 10, LATID)
if (status .NE. nf_noerr) call handle_err(status)
status=nf_def_dim(ncid, 'lon', 10, LONID)
if (status .NE. nf_noerr) call handle_err(status)
status=nf_def_dim(ncid, 'time', nf_unlimited, TIMEID) ! the time is unlimited in this program
if (status .NE. nf_noerr) call handle_err(status)
write(*,*), 'define the dimentions lat, lon, and time, the ID is => ',LATID, LONID, TIMEID
!C... begin to define your varibles
PM10dim(1)=lonid
PM10dim(2)=latid
PM10dim(3)=timeid
PM2_5dim(1)=lonid
PM2_5dim(2)=latid
PM2_5dim(3)=timeid
status=nf_def_var(ncid, 'PM10', nf_float, 3, PM10dim, PM10ID)
status=nf_def_var(ncid, 'PM2_5', nf_float, 3, PM2_5dim, PM2_5ID)
if (status .NE. nf_noerr) call handle_err(status)
write(*,*), 'define varialbes, and the ID is => ', PM10ID, PM2_5ID
!C... Put your attribute of your variables
status=nf_put_att_text(ncid, PM10ID, 'long_name', 35, 'particulate metter with dp < 10 ')
status=nf_put_att_text(ncid, PM10ID, 'unit', 35, 'ug/m3')
status=nf_put_att_text(ncid, PM2_5ID, 'long_name', 35, 'particulate metter with dp < 2.5 ')
status=nf_put_att_text(ncid, PM2_5ID, 'unit', 35, 'ug/m3 ')
status=nf_put_att_text(ncid, nf_global, 'Title_of_this_program', 30, 'A NetCDF test program. ')
if (status .NE. nf_noerr) call handle_err(status)
!C... end of define mode (this function is must be used)
status=nf_enddef(ncid)
if (status .NE. nf_noerr) call handle_err(status)
print *, 'end_define'
!C... To get your data !
do 10 ilon=1, nlon
do 10 ilat=1, nlat
do 10 itime=1, ntime
PM10array(ilon, ilat, itime)=50.0
PM2_5array(ilon, ilat, itime)=30.0
10 continue
print *, 'get data'
!C... begin to put your data in to this file!
status=nf_put_vara_real(ncid, PM10ID, start, count, PM10array)
status=nf_put_vara_real(ncid, PM2_5ID, start, count, PM2_5array)
if (status .NE. nf_noerr) call handle_err(status)
print *, 'put variables'
!C... close this file..
status=nf_close(ncid)
if (status .NE. nf_noerr) call handle_err(status)
write(*,*), 'OK! your have created a NetCDF file, you can use the command to look your file'
write(*,*), 'ncdump create.ncf|more'
end
!C... Make the error control program!
subroutine handle_err(status)
integer status
if (status .NE. NF_NOERR) then
write(*,*), NF_STRERROR(status), status
stop 'program stoped, and you must find the error in your source code.'
endif
end
运行 :
ifort 2_example.f90 -L/opt/soft-install/intel_soft/netcdf362/lib -lnetcdf -lm -I/opt/soft-install/intel_soft/netcdf362/include -o gui.out
|
评分
-
查看全部评分
|