program write_cdf integer indx(10) parameter (MX = 6, MY = 5, MZ = 4, MT = 3) real xx(500), yy(500), zz(500), tt(500), var(MX, MY, MZ, MT) character*80 arg, file, vname, xname, yname, zname, tname data file, vname, xname, yname, zname, tname * /'odb.nc', 'sstt', 'X', 'Y', 'Z', 'T'/ integer function iargc c --- first allow some command line options to the executable: i = 0 c --- nargs = number of arguments to the executable nargs = iargc() do while (i .lt. nargs) i = i + 1 c --- get the i'th argument call getarg (i, arg) if (arg .eq. '-f') then i = i + 1 call getarg (i, file) elseif (arg .eq. '-x') then i = i + 1 call getarg (i, xname) elseif (arg .eq. '-y') then i = i + 1 call getarg (i, yname) elseif (arg .eq. '-z') then i = i + 1 call getarg (i, zname) elseif (arg .eq. '-t') then i = i + 1 call getarg (i, tname) elseif (arg .eq. '-v') then i = i + 1 call getarg (i, vname) elseif (arg .eq. '-h') then goto 100 endif enddo c --- construct some dummy fields: call filld (nx, ny, nz, nt, xx, yy, zz, tt, var) c --- create the file called 'file' (overwriting existing, if present) call odb_open (id1, file, 2) c --- define some grids: call odb_dfgr (id1, 'X', nx) call odb_dfgr (id1, 'Y', ny) call odb_dfgr (id1, 'Z', nz) c --- define the 'unlimited' or 'growable' grid: call odb_dftm (id1, 'T') c --- define some two dimensional variables: call odb_dfvar2 (id1, 'X', 'Y', 'VARX') call odb_dfvar2 (id1, 'X', 'Y', 'VARY') call odb_dfvar2 (id1, 'X', 'Y', 'VARXY') c --- define a three dimensional variable: call odb_dfvar3 (id1, 'X', 'Y', 'T', 'VARXYT') c --- write the X and Y grid values call odb_wrgr (id1, 'X', xx) call odb_wrgr (id1, 'Y', yy) c THERE ARE MANY METHODS TO STORE VARIOUS SLICES OF THE DATA INTO VARIOUS c SLICES OF THE OUTPUT. HERE ARE A FEW: c --- write 4d - var(1:NX,1:NY,1,1) into 2d - VARXY call odb_wrvar (id1, 'VARXY', var) c --- write the 1d - 'xx(1:nx)' into 2d - VARX(1:nx,3): call odb_wr1v2 (id1, 3, 'VARX', xx) c --- VARY is two dimensional, but we would like yy to be in the first column of VARY indx(1) = 1 indx(2) = 0 c --- write the one dimensional 'yy(1:ny)' into VARY(1,1:ny): call odb_wrxv (id1, indx, 'VARY', yy) indx(1) = 0 ! i.e., all values of the first index of VARXYT indx(2) = 0 ! i.e., all values of the second index of VARXYT indx(3) = 3 ! i.e., the third value of the third index of VARXYT c --- write var(1:nx,1:ny,1,1) into VARXYT(1:nx,1:ny,3): call odb_wrxv (id1, indx, 'VARXYT', var) indx(3) = 2 ! i.e., the second value of the third index of VARXYT c --- write var(1:nx,1:ny,4,3) into VARXYT(1:nx,1:ny,2): call odb_wrxv (id1, indx, 'VARXYT', var(1,1,4,3)) indx(3) = 1 ! i.e., the first value of the third index of VARXYT c --- write var(1:nx,1:ny,1,1) into VARXYT(1:nx,1:ny,1): call odb_wrxv (id1, indx, 'VARXYT', var) c --- close the netcdf file call odb_close (id1) return 100 write (6, *) * 'usage: '//arg(1:lnblnk(arg))//' [-h][-f cdf_file][-{x,y,z,t} * gridname][-v varname]' write (6,*) stop stop end subroutine filld (nx, ny, nz, nt, xx, yy, zz, tt, var) c------------------------------------------------------------- parameter (MX = 6, MY = 5, MZ = 4, MT = 3) real xx(1), yy(1), zz(1), tt(1), var(MX, MY, MZ, MT) nx = MX do i = 1, nx xx(i) = real(i) enddo ny = MY do i = 1, ny yy(i) = 10.*i enddo nz = MZ do i = 1, nz zz(i) = 100.*i enddo nt = MT do i = 1, nt tt(i) = 1000.*i enddo do it = 1, nt do iz = 1, nz do iy = 1, ny do ix = 1, nx var(ix, iy, iz, it) = 1000*it + 100*iz + 10*iy + ix enddo enddo enddo enddo return end