[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: I have question!2' read first'
- Subject: Re: I have question!2' read first'
- Date: Thu, 06 Jan 2000 20:59:00 -0700
Hi Hong sook jung,
> I am studying for meteorological science in Korea.
> I need your help.
> I have question about netcdf.
> I have nc files, such as A_C_JAN_NC, A_C_FEB_NC, A_C_MAR......,
> A_C_DEC.NC.
> I want to read and write nc files using fortran programming.
> What I want to know is JJA and DJF average.
> First I used grads options such as binary file
> for example,
> gradsnc
> sdfopen (file name)
> sdfopen (file name)
>
> d (variable).1
> d (variable).2
> d ave(var1+var2)
> but I can't display more than two files.
> As I wrote above, I want to read and write nc files using fortran
> programming.
> if you have example fortran program, I want to get it.
>
> If you know that, teach me.
> I am waiting for your reply.
>
> My English is very poor, so I hope you understand.
Yes, I understood fine.
There are many small examples of using Fortran to read and write
netCDF files in the NetCDF Users Guide for Fortran, available in
several versions (including HTML) from:
http://www.unidata.ucar.edu/packages/netcdf/docs.html
Another more extensive Fortran example is the appended "example.f"
program. Finally, you can use the "ncgen -f" program that comes with
netCDF to generate programs to write a "foo.nc" file, and you can use
the "GENNET.F" program availabe from
ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/gennet.f
to generate programs to read a given netCDF file.
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
PROGRAM wrt_ncdf
C Example program (from Jeremy Kepner <address@hidden>)
C that creates a netCDF file.
IMPLICIT NONE
INCLUDE '/usr/local/include/netcdf.inc'
INTEGER n_dim,x_dim,y_dim,z_dim
PARAMETER(n_dim = 3, x_dim = 20, y_dim = 10, z_dim = 5)
INTEGER dim_array(n_dim)
INTEGER start(n_dim),count(n_dim)
INTEGER ncid, errcode
INTEGER x_id,y_id,z_id,arr_id
REAL array(x_dim,y_dim,z_dim)
INTEGER i,j,k
C Put something into the array.
DO i=1,x_dim
DO j=1,y_dim
DO k=1,z_dim
array(i,j,k) = (i-1) + x_dim*(j-1) + x_dim*y_dim*(k-1)
ENDDO
ENDDO
ENDDO
C Create file.
ncid = NCCRE('test.nc', NCCLOB, errcode)
C Create Dimensions.
x_id = NCDDEF(ncid, 'X', x_dim, errcode)
y_id = NCDDEF(ncid, 'Y', y_dim, errcode)
z_id = NCDDEF(ncid, 'Z', z_dim, errcode)
C Create a variable.
C Assign dimensions to array.
dim_array(1) = z_id
dim_array(2) = y_id
dim_array(3) = x_id
arr_id = NCVDEF(ncid,'array',NCFLOAT,n_dim,dim_array,errcode)
C Skip attributes.
C Leave definitions.
CALL NCENDF(ncid, errcode)
C Write variable to file.
start(1) = 1
start(2) = 1
start(3) = 1
count(1) = z_dim
count(2) = y_dim
count(3) = x_dim
CALL NCVPT(ncid,arr_id,start,count,array,errcode)
C Close the file.
CALL NCCLOS(ncid, errcode)
END