subroutine instant_probe_init use modglobal, only : ifinput implicit none integer :: n, vn integer :: point_dimid, time_dimid integer :: varid_xt, varid_yt, varid_zt ! integer :: varid_xm, varid_ym, varid_zm real, allocatable :: xt(:), xm(:), yt(:), ym(:), zt(:), zm(:) character(2) :: varname character(80) :: chmess if (.not. lprobedump) return ! Validate probe inputs before proceeding call instant_validate_output_vars(nprobevars, probevars, 'probevars', 'lprobedump') if (nprobe <= 0) then write(0, *) 'ERROR: lprobedump=.true. but nprobe=', nprobe, ' (must be > 0)' stop 1 end if ! read global probe point indices if(myid==0) then open (ifinput,file='probe.inp.'//cexpnr) read (ifinput,'(a80)') chmess do n = 1, nprobe read (ifinput,*) iprobe(n), jprobe(n), kprobe(n) end do close (ifinput) end if ! Broadcast the probe point indices to all processes call MPI_BCAST(iprobe, nprobe, MPI_INTEGER, 0, comm3d, mpierr) call MPI_BCAST(jprobe, nprobe, MPI_INTEGER, 0, comm3d, mpierr) call MPI_BCAST(kprobe, nprobe, MPI_INTEGER, 0, comm3d, mpierr) do n = 1, nprobe if (iprobe(n) < 1 .or. iprobe(n) > itot) then write(0, *) 'ERROR: iprobe(', n, ')=', iprobe(n), ' is out of bounds (1 to ', itot, ')' stop 1 end if if (jprobe(n) < 1 .or. jprobe(n) > jtot) then write(0, *) 'ERROR: jprobe(', n, ')=', jprobe(n), ' is out of bounds (1 to ', jtot, ')' stop 1 end if if (kprobe(n) < 1 .or. kprobe(n) > ktot) then write(0, *) 'ERROR: kprobe(', n, ')=', kprobe(n), ' is out of bounds (1 to ', ktot, ')' stop 1 end if end do if (myid == 0) then allocate(varid_vals(nprobevars)) ! write(*,*) "=== Probe Output Init (Gather to Rank 0) ===" ! write(*,*) "Number of probes:", nprobe ! write(*,*) "Variables:", trim(probevars) filenameprobe = 'ins_probe.xxx.nc' filenameprobe(11:13) = cexpnr ! Create NetCDF file call check( nf90_create(trim(filenameprobe), NF90_CLOBBER, ncidprobe) ) ! Define Dimensions call check( nf90_def_dim(ncidprobe, 'point', nprobe, point_dimid) ) call check( nf90_def_dim(ncidprobe, 'time', NF90_UNLIMITED, time_dimid) ) ! Define Variables Dimensions ! Coordinates (cell center and cell edge) call check( nf90_def_var(ncidprobe, 'xt', NF90_FLOAT, (/point_dimid/), varid_xt) ) call check( nf90_put_att(ncidprobe, varid_xt, 'long_name', 'x-coordinate (cell center)') ) call check( nf90_put_att(ncidprobe, varid_xt, 'units', 'm') ) ! call check( nf90_def_var(ncidprobe, 'xm', NF90_FLOAT, (/point_dimid/), varid_xm) ) ! call check( nf90_put_att(ncidprobe, varid_xm, 'long_name', 'x-coordinate (cell edge)') ) ! call check( nf90_put_att(ncidprobe, varid_xm, 'units', 'm') ) call check( nf90_def_var(ncidprobe, 'yt', NF90_FLOAT, (/point_dimid/), varid_yt) ) call check( nf90_put_att(ncidprobe, varid_yt, 'long_name', 'y-coordinate (cell center)') ) call check( nf90_put_att(ncidprobe, varid_yt, 'units', 'm') ) ! call check( nf90_def_var(ncidprobe, 'ym', NF90_FLOAT, (/point_dimid/), varid_ym) ) ! call check( nf90_put_att(ncidprobe, varid_ym, 'long_name', 'y-coordinate (cell edge)') ) ! call check( nf90_put_att(ncidprobe, varid_ym, 'units', 'm') ) call check( nf90_def_var(ncidprobe, 'zt', NF90_FLOAT, (/point_dimid/), varid_zt) ) call check( nf90_put_att(ncidprobe, varid_zt, 'long_name', 'z-coordinate (cell center)') ) call check( nf90_put_att(ncidprobe, varid_zt, 'units', 'm') ) ! call check( nf90_def_var(ncidprobe, 'zm', NF90_FLOAT, (/point_dimid/), varid_zm) ) ! call check( nf90_put_att(ncidprobe, varid_zm, 'long_name', 'z-coordinate (cell edge)') ) ! call check( nf90_put_att(ncidprobe, varid_zm, 'units', 'm') ) ! Time call check( nf90_def_var(ncidprobe, 'time', NF90_FLOAT, (/time_dimid/), varid_time) ) call check( nf90_put_att(ncidprobe, varid_time, 'long_name', 'Time') ) call check( nf90_put_att(ncidprobe, varid_time, 'units', 's') ) ! Data Variables do vn = 1, nprobevars varname = probevars(3*vn-2 : 3*vn-1) call check( nf90_def_var(ncidprobe, trim(instant_get_nc_varname(varname)), NF90_FLOAT, & (/point_dimid, time_dimid/), varid_vals(vn)) ) call instant_add_var_atts(ncidprobe, varid_vals(vn), varname) end do call check( nf90_enddef(ncidprobe) ) ! Write Static Coordinates immediately allocate(xt(nprobe), xm(nprobe)) allocate(yt(nprobe), ym(nprobe)) allocate(zt(nprobe), zm(nprobe)) do n=1, nprobe xt(n) = xf(iprobe(n)) ! cell center ! xm(n) = xh(iprobe(n)) ! cell edge yt(n) = yf(jprobe(n)) ! cell center ! ym(n) = yh(jprobe(n)) ! cell edge zt(n) = zf(kprobe(n)) ! cell center ! zm(n) = zh(kprobe(n)) ! cell edge end do call check( nf90_put_var(ncidprobe, varid_xt, xt, start=(/1/), count=(/nprobe/)) ) ! call check( nf90_put_var(ncidprobe, varid_xm, xm, start=(/1/), count=(/nprobe/)) ) call check( nf90_put_var(ncidprobe, varid_yt, yt, start=(/1/), count=(/nprobe/)) ) ! call check( nf90_put_var(ncidprobe, varid_ym, ym, start=(/1/), count=(/nprobe/)) ) call check( nf90_put_var(ncidprobe, varid_zt, zt, start=(/1/), count=(/nprobe/)) ) ! call check( nf90_put_var(ncidprobe, varid_zm, zm, start=(/1/), count=(/nprobe/)) ) call check( nf90_sync(ncidprobe) ) deallocate(xt, xm, yt, ym, zt, zm) end if end subroutine instant_probe_init