Note: full documentation here http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f90.txt This file merely provides my own notes on what to do. ~~~~~~~~~~~~~~~~~~~~~~~~~ Creating a NETCDF file ~~~~~~~~~~~~~~~~~~~~~~~~~ This is the first step that must be done before using a netcdf file > nf90_create($outputname, $data_flag, $data_id) $outputname is the file output name (string assigned by user) $data_flag is the type of data being output. I use nf90_64bit_offset which allows large numbers (netcdf variable) $data_id is the internal data name of the file (integer assigned by netcdf) The next step is to create a dimension of the arrays, For this example suppose we have a 2D complex matrix that is being evolved. The characteristics are (x,y,t,Re/Im) The size of x is N, y is N, t=$num_dumps, Re/Im is 2 (one for real, one for complex) To create these arrays we would use the following > nf90_def_dim($data_id,$dimname,$size,$dim_id) $data_id is the internal data name from above $dimname is the string name of the particular dimension (string assigned by user) $size is the size of the array (integer assigned by user) $dim_id is the internal dimension name (integer assigned by netcdf) Now that we have created dimensions, we need a dimensional array to access them > dimids=(/ x_dimid, y_dimid, t_id, cmplx_id /) would be what we have to create for the above example so netcdf knows which dimension ids to use Now we must create the variables. This is done with > nf90_def_var($data_id,$varname,$netcdf_vartype,dimids,$varid) $data_id is the internal data name from above $varname is the string name of the particular variable (string assigned by user) $netcdf_vartype is the data type for netcdf to operate, I use nf90_double (netcdf variable) dimids is the dimension id variable array $varid is the internal variable name (integer assigned by netcdf) Finally we close the allocation by calling > nf90_enddef($data_id) ~~~~~~~~~~~~~~~~~~~~~~~~~ Calling a NETCDF file ~~~~~~~~~~~~~~~~~~~~~~~~~ Now that we have created a netcdf file, we now need to figure out how to dump data to it. The first step is to define two arrays that contain the start and end values of the dimension values. For example, from above the variables are (x,y,t,cmplx) which range from (1,1,1,1) to (N,N,1,1) which would write an NxN array to time-value 1 and that is real. If we wanted to evaluate at timestep 100 we would need to allocate (1,1,100,2) to (N,N,100,2) which allocates an NxN array at timestep 100 that is complex. Now to dump data we define > nf90_out_var($data_id,$var_id,$variable,$start_id,$end_id) $data_id is the netcdf file we want to dump to, assigned above $var_id is the variable id assigned above $variable is the actual fortran variable $start_id is the start array (integer array assigned by user) $end_id is the end array (integer array assigned by user) We repeat this for all the various variables we want. When we are finally done we must close netcdf so we call > nf90_close($data_id) $data_id is the data id from above. This completely closes that netcdf file. ALWAYS CLOSE THE NETCDF FILE BEFORE VIEWING. ALWAYS ALWAYS ALWAYS ALWAYS. IF NOT IT FUCKS THINGS UP ROYALLY AND FOR NO REASON. ~~~~~~~~~~~~~~~~~~~~~~~~~ Example Code ~~~~~~~~~~~~~~~~~~~~~~~~~ ! do NETCDF allocation outputname='kz.'//trim(kzs)//'.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'.nc' call check(nf90_create(outputname,nf90_64bit_offset,mdata_id)) call check(nf90_def_dim(mdata_id,"X",N,x_dimid)) call check(nf90_def_dim(mdata_id,"Y",N,y_dimid)) !num_dumps + 2 to include first and last call check(nf90_def_dim(mdata_id,"t",num_dumps+2,t_id)) call check(nf90_def_dim(mdata_id,"cmplx",2,cmplx_id)) dimids=(/ x_dimid,y_dimid,t_id,cmplx_id /) call check(nf90_def_var(mdata_id,"u",nf90_double,dimids,uid)) call check(nf90_def_var(mdata_id,"v",nf90_double,dimids,vid)) call check(nf90_def_var(mdata_id,"w",nf90_double,dimids,wid)) call check(nf90_def_var(mdata_id,"rho",nf90_double,dimids,rhoid)) call check(nf90_enddef(mdata_id)) ... curr_dim=(/1,1,1,1/) count_dim=(/N,N,1,1/) call check(nf90_put_var(mdata_id,uid,real(ur),curr_dim,count_dim)) call check(nf90_put_var(mdata_id,vid,real(vr),curr_dim,count_dim)) call check(nf90_put_var(mdata_id,wid,real(wr),curr_dim,count_dim)) call check(nf90_put_var(mdata_id,rhoid,real(rr),curr_dim,count_dim)) curr_dim=(/1,1,1,2/) call check(nf90_put_var(mdata_id,uid,imag(ur),curr_dim,count_dim)) call check(nf90_put_var(mdata_id,vid,imag(vr),curr_dim,count_dim)) call check(nf90_put_var(mdata_id,wid,imag(wr),curr_dim,count_dim)) call check(nf90_put_var(mdata_id,rhoid,imag(rr),curr_dim,count_dim)) .... call check(nf90_close(mdata_id)) .. !provides error checking subroutine check(status) integer, intent(in) :: status if(status/=nf90_noerr) then print *, trim(nf90_strerror(status)) stop "Stopped. Error in netcdf." end if end subroutine check