Program netCDF_Serial_example !.. !..This simple example asks 1 processor, Processor 0, !..to create a netcdf file called s_ex1.nc that !..contains 1 variable 'rel_humid' in !..three dimensions: Latitude, Longtitude, and Time. !.. !..Then, processor 0 fills out values !..in Time = 1, 2, ..., NPROCS, respectively. !..The value of rel_humid( Latitude = I, !..Longtitude = J, Time = K )is 100*K + 10*J + I !.. Implicit None include "mpif.h" include "netcdf.inc" Integer N_Dims, N_Lat, N_Lon, N_Time Parameter (N_Dims = 3) Parameter (N_Lat = 4, N_Lon = 5) Integer Dim_ID(N_Dims), Start(N_Dims), Count(N_Dims) Integer FILE_ID, Lat_ID, Lon_ID, Time_ID, RH_ID Integer RCODE, FillMode, I, J, Slice integer myid,nprocs,ierr Real local_array( N_Lat, N_Lon ), tol tol = 1.0e-5 call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr) !..Begin definition of file !.....Only Processor 0 create file If ( myid .eq. 0 ) then RCODE = nf_create( 's_ex1.nc', nf_clobber, File_ID ) call check_err(RCODE,myid) RCODE = nf_set_fill( File_ID, nf_nofill, FillMode) call check_err(RCODE,myid) !.....Define the three dimensions RCODE = nf_def_dim( File_ID, 'Latitude', $ N_Lat, Lat_ID ) call check_err(RCODE,myid) RCODE = nf_def_dim( File_ID, 'Longtitude', & N_Lon, Lon_ID ) call check_err(RCODE,myid) RCODE = nf_def_dim( File_ID, 'Time', $ nprocs, Time_ID ) call check_err(RCODE,myid) !.....Define the variable 'rel_humid' in three !.....dimensions Latitude varies fastest; Time !.....varies slowest Dim_ID(1) = Lat_ID Dim_ID(2) = Lon_ID Dim_ID(3) = Time_ID RCODE = nf_def_var(File_ID,'rel_humid', $ nf_double,N_Dims,Dim_ID,RH_ID) call check_err(RCODE,myid) RCODE = nf_enddef( File_ID) call check_err(RCODE,myid) !..Finishes definition of the file !..Now, Processor 0 fill in NROCS slices !..(hyperslab) of values !.....Create the 1-timeslize values in a !.....local arrary Do Slice = 1, NPROCS Do J = 1, N_Lon Do I = 1, N_Lat local_array(I,J) = Slice*100 + J*10 + I Enddo Enddo !.....Get ready to put values. Set up starting !.....location and counts Start(1) = 1 Start(2) = 1 Start(3) = Slice Count(1) = N_Lat Count(2) = N_Lon Count(3) = 1 RCODE = nf_put_vara_real( File_ID, RH_ID, $ Start, Count, local_array) call check_err(RCODE,myid) Enddo !.....Reading it back !.....Create the 1-timeslize values in a !.....local arrary Do Slice = 1, NPROCS !.....Get ready to put values. Set up starting !.....location and counts Start(1) = 1 Start(2) = 1 Start(3) = Slice Count(1) = N_Lat Count(2) = N_Lon Count(3) = 1 RCODE = nf_get_vara_real( File_ID, RH_ID, $ Start, Count, local_array) call check_err(RCODE,myid) Do J = 1, N_Lon Do I = 1, N_Lat If ( abs( local_array(I,J) - $ (Slice*100.+J*10.+I)) .gt. tol ) then Write (6,*) ' ***ERROR DETECTED*** ' Endif Enddo Enddo Enddo !..Processor 0 closes file !..Closing the file RCODE= nf_close(File_ID) call check_err(RCODE,myid) Else Write (6,*) ' Processor ', myid, ' is unemployed.' Endif call MPI_FINALIZE(ierr) Stop End subroutine check_err(iret,myid) integer iret, myid include 'netcdf.inc' if (iret .ne. NF_NOERR) then print *, 'PE ',myid, nf_strerror(iret) stop endif return end