ROMS
Loading...
Searching...
No Matches
mod_netcdf::netcdf_get_lvar Interface Reference

Public Member Functions

subroutine netcdf_get_lvar_0d (ng, model, ncname, myvarname, a, ncid, start, total)
 
subroutine netcdf_get_lvar_1d (ng, model, ncname, myvarname, a, ncid, start, total)
 

Detailed Description

Definition at line 65 of file mod_netcdf.F.

Member Function/Subroutine Documentation

◆ netcdf_get_lvar_0d()

subroutine mod_netcdf::netcdf_get_lvar::netcdf_get_lvar_0d ( integer, intent(in) ng,
integer, intent(in) model,
character (len=*), intent(in) ncname,
character (len=*), intent(in) myvarname,
logical, intent(out) a,
integer, intent(in), optional ncid,
integer, dimension(:), intent(in), optional start,
integer, dimension(:), intent(in), optional total )

Definition at line 4600 of file mod_netcdf.F.

4602!
4603!=======================================================================
4604! !
4605! This routine reads requested logical scalar variable from specified !
4606! NetCDF file. The variable can be stored as an interger (0 or 1) or !
4607! as a character ('T' or 'F'). Reading a character variable is very !
4608! inefficient in parallel I/O. !
4609! !
4610! On Input: !
4611! !
4612! ng Nested grid number (integer) !
4613! model Calling model identifier (integer) !
4614! ncname NetCDF file name (string) !
4615! myVarName Variable name (string) !
4616! ncid NetCDF file ID (integer, OPTIONAL) !
4617! start Starting index where the first of the data values !
4618! will be read along each dimension (integer, !
4619! OPTIONAL) !
4620! total Number of data values to be read along each !
4621! dimension (integer, OPTIONAL) !
4622! !
4623! On Ouput: !
4624! !
4625! A Read scalar variable (logical) !
4626! !
4627! Examples: !
4628! !
4629! CALL netcdf_get_lvar (ng, iNLM, 'file.nc', 'VarName', lvar) !
4630! CALL netcdf_get_lvar (ng, iNLM, 'file.nc', 'VarName', lvar(1)) !
4631! !
4632!=======================================================================
4633!
4634! Imported variable declarations.
4635!
4636 integer, intent(in) :: ng, model
4637
4638 integer, intent(in), optional :: ncid
4639 integer, intent(in), optional :: start(:)
4640 integer, intent(in), optional :: total(:)
4641!
4642 character (len=*), intent(in) :: ncname
4643 character (len=*), intent(in) :: myVarName
4644!
4645 logical, intent(out) :: A
4646!
4647! Local variable declarations.
4648!
4649 integer :: my_ncid, my_type, status, varid
4650
4651 integer :: AI
4652 integer, dimension(1) :: my_AI
4653
4654#if !defined PARALLEL_IO && defined DISTRIBUTE
4655 integer, dimension(2) :: ibuffer
4656#endif
4657!
4658 character (len=1) :: Achar
4659
4660 character (len=*), parameter :: MyFile = &
4661 & __FILE__//", netcdf_get_lvar_0d"
4662!
4663!-----------------------------------------------------------------------
4664! Read in an integer scalar variable.
4665!-----------------------------------------------------------------------
4666!
4667! If NetCDF file ID is not provided, open NetCDF for reading.
4668!
4669 IF (.not.PRESENT(ncid)) THEN
4670 CALL netcdf_open (ng, model, trim(ncname), 0, my_ncid)
4671 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
4672 ELSE
4673 my_ncid=ncid
4674 END IF
4675!
4676! Read in variable.
4677!
4678 IF (inpthread) THEN
4679 status=nf90_inq_varid(my_ncid, trim(myvarname), varid)
4680 IF (status.eq.nf90_noerr) THEN
4681 status=nf90_inquire_variable(my_ncid, varid, &
4682 & xtype = my_type)
4683 IF (status.eq.nf90_noerr) THEN
4684 IF (my_type.eq.nf90_int) THEN
4685 IF (PRESENT(start).and.PRESENT(total)) THEN
4686 status=nf90_get_var(my_ncid, varid, my_ai, start, total)
4687 ai=my_ai(1)
4688 ELSE
4689 status=nf90_get_var(my_ncid, varid, ai)
4690 END IF
4691 IF (status.eq.nf90_noerr) THEN
4692 IF (ai.eq.0) THEN
4693 a=.false.
4694 ELSE
4695 a=.true.
4696 END IF
4697 END IF
4698 ELSE IF (my_type.eq.nf90_char) THEN
4699 IF (PRESENT(start).and.PRESENT(total)) THEN
4700 status=nf90_get_var(my_ncid, varid, achar, start, total)
4701 ELSE
4702 status=nf90_get_var(my_ncid, varid, achar)
4703 END IF
4704 IF (status.eq.nf90_noerr) THEN
4705 a=.false.
4706 IF ((achar.eq.'t').or.(achar.eq.'T')) THEN
4707 a=.true.
4708 END IF
4709 END IF
4710 END IF
4711 IF (founderror(status, nf90_noerr, __line__, myfile)) THEN
4712 WRITE (stdout,10) trim(myvarname), trim(ncname), &
4713 & trim(sourcefile), nf90_strerror(status)
4714 exit_flag=2
4715 ioerror=status
4716 END IF
4717 ELSE
4718 WRITE (stdout,20) trim(myvarname), trim(ncname), &
4719 & trim(sourcefile), nf90_strerror(status)
4720 exit_flag=2
4721 ioerror=status
4722 END IF
4723 ELSE
4724 WRITE (stdout,30) trim(myvarname), trim(ncname), &
4725 & trim(sourcefile), nf90_strerror(status)
4726 exit_flag=2
4727 ioerror=status
4728 END IF
4729 END IF
4730
4731#if !defined PARALLEL_IO && defined DISTRIBUTE
4732!
4733! Broadcast read variable to all processors in the group.
4734!
4735 ibuffer(1)=exit_flag
4736 ibuffer(2)=ioerror
4737 CALL mp_bcasti (ng, model, ibuffer)
4738 exit_flag=ibuffer(1)
4739 ioerror=ibuffer(2)
4740 IF (exit_flag.eq.noerror) THEN
4741 CALL mp_bcastl (ng, model, a)
4742 END IF
4743#endif
4744!
4745! If NetCDF file ID is not provided, close input NetCDF file.
4746!
4747 IF (.not.PRESENT(ncid)) THEN
4748 CALL netcdf_close (ng, model, my_ncid, ncname, .false.)
4749 END IF
4750!
4751 10 FORMAT (/,' NETCDF_GET_LVAR_0D - error while reading variable:', &
4752 & 2x,a,/,22x,'in input file:',2x,a,/,22x,'call from:',2x,a, &
4753 & /,22x,a)
4754 20 FORMAT (/,' NETCDF_GET_LVAR_0D - error while inquiring type for ',&
4755 & 'variable:',2x,a,/,22x,'in input file:',2x,a,/,22x, &
4756 & 'call from:',2x,a,/,22x,a)
4757 30 FORMAT (/,' NETCDF_GET_LVAR_0D - error while inquiring ID for ', &
4758 & 'variable:',2x,a,/,22x,'in input file:',2x,a,/,22x, &
4759 & 'call from:',2x,a,/,22x,a)
4760!
4761 RETURN

References mod_scalars::exit_flag, mod_parallel::inpthread, mod_iounits::ioerror, mod_netcdf::netcdf_close(), mod_netcdf::netcdf_open(), mod_scalars::noerror, mod_iounits::sourcefile, and mod_iounits::stdout.

Here is the call graph for this function:

◆ netcdf_get_lvar_1d()

subroutine mod_netcdf::netcdf_get_lvar::netcdf_get_lvar_1d ( integer, intent(in) ng,
integer, intent(in) model,
character (len=*), intent(in) ncname,
character (len=*), intent(in) myvarname,
logical, dimension(:), intent(out) a,
integer, intent(in), optional ncid,
integer, dimension(:), intent(in), optional start,
integer, dimension(:), intent(in), optional total )

Definition at line 4764 of file mod_netcdf.F.

4766!
4767!=======================================================================
4768! !
4769! This routine reads requested logical 1D-array variable from !
4770! specified NetCDF file. The variable can be stored as an !
4771! interger (0 or 1) or as a character ('T' or 'F'). Reading !
4772! a character variable is very inefficient in parallel I/O. !
4773! !
4774! On Input: !
4775! !
4776! ng Nested grid number (integer) !
4777! model Calling model identifier (integer) !
4778! ncname NetCDF file name (string) !
4779! myVarName Variable name (string) !
4780! ncid NetCDF file ID (integer, OPTIONAL) !
4781! start Starting index where the first of the data values !
4782! will be read along each dimension (integer, !
4783! OPTIONAL) !
4784! total Number of data values to be read along each !
4785! dimension (integer, OPTIONAL) !
4786! !
4787! On Ouput: !
4788! !
4789! A Read 1D-array variable (logical) !
4790! !
4791! Examples: !
4792! !
4793! CALL netcdf_get_lvar (ng, iNLM, 'file.nc', 'VarName', lvar) !
4794! CALL netcdf_get_lvar (ng, iNLM, 'file.nc', 'VarName', lvar(0:)) !
4795! CALL netcdf_get_lvar (ng, iNLM, 'file.nc', 'VarName', lvar(:,1)) !
4796! !
4797!=======================================================================
4798!
4799! Imported variable declarations.
4800!
4801 integer, intent(in) :: ng, model
4802
4803 integer, intent(in), optional :: ncid
4804 integer, intent(in), optional :: start(:)
4805 integer, intent(in), optional :: total(:)
4806!
4807 character (len=*), intent(in) :: ncname
4808 character (len=*), intent(in) :: myVarName
4809!
4810 logical, intent(out) :: A(:)
4811!
4812! Local variable declarations.
4813!
4814 integer :: i, my_ncid, my_type, status, varid
4815
4816 integer, dimension(SIZE(A,1)) :: AI
4817
4818#if !defined PARALLEL_IO && defined DISTRIBUTE
4819 integer, dimension(2) :: ibuffer
4820#endif
4821!
4822 character (len=1), dimension(SIZE(A,1)) :: Achar
4823
4824 character (len=*), parameter :: MyFile = &
4825 & __FILE__//", netcdf_get_lvar_1d"
4826!
4827!-----------------------------------------------------------------------
4828! Read in an integer scalar variable.
4829!-----------------------------------------------------------------------
4830!
4831! If NetCDF file ID is not provided, open NetCDF for reading.
4832!
4833 IF (.not.PRESENT(ncid)) THEN
4834 CALL netcdf_open (ng, model, trim(ncname), 0, my_ncid)
4835 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
4836 ELSE
4837 my_ncid=ncid
4838 END IF
4839!
4840! Read in variable.
4841!
4842 IF (inpthread) THEN
4843 status=nf90_inq_varid(my_ncid, trim(myvarname), varid)
4844 IF (status.eq.nf90_noerr) THEN
4845 status=nf90_inquire_variable(my_ncid, varid, &
4846 & xtype = my_type)
4847 IF (status.eq.nf90_noerr) THEN
4848 IF (my_type.eq.nf90_int) THEN
4849 IF (PRESENT(start).and.PRESENT(total)) THEN
4850 status=nf90_get_var(my_ncid, varid, ai, start, total)
4851 ELSE
4852 status=nf90_get_var(my_ncid, varid, ai)
4853 END IF
4854 IF (status.eq.nf90_noerr) THEN
4855 DO i=1,SIZE(a,1)
4856 IF (ai(i).eq.0) THEN
4857 a(i)=.false.
4858 ELSE
4859 a(i)=.true.
4860 END IF
4861 END DO
4862 END IF
4863 ELSE IF (my_type.eq.nf90_char) THEN
4864 IF (PRESENT(start).and.PRESENT(total)) THEN
4865 status=nf90_get_var(my_ncid, varid, achar, start, total)
4866 ELSE
4867 status=nf90_get_var(my_ncid, varid, achar)
4868 END IF
4869 IF (status.eq.nf90_noerr) THEN
4870 DO i=1,SIZE(a,1)
4871 a(i)=.false.
4872 IF ((achar(i).eq.'t').or.(achar(i).eq.'T')) THEN
4873 a(i)=.true.
4874 END IF
4875 END DO
4876 END IF
4877 END IF
4878 IF (founderror(status, nf90_noerr, __line__, myfile)) THEN
4879 WRITE (stdout,10) trim(myvarname), trim(ncname), &
4880 & trim(sourcefile), nf90_strerror(status)
4881 exit_flag=2
4882 ioerror=status
4883 END IF
4884 ELSE
4885 WRITE (stdout,20) trim(myvarname), trim(ncname), &
4886 & trim(sourcefile), nf90_strerror(status)
4887 exit_flag=2
4888 ioerror=status
4889 END IF
4890 ELSE
4891 WRITE (stdout,30) trim(myvarname), trim(ncname), &
4892 & trim(sourcefile), nf90_strerror(status)
4893 exit_flag=2
4894 ioerror=status
4895 END IF
4896 END IF
4897
4898#if !defined PARALLEL_IO && defined DISTRIBUTE
4899!
4900! Broadcast read variable to all processors in the group.
4901!
4902 ibuffer(1)=exit_flag
4903 ibuffer(2)=ioerror
4904 CALL mp_bcasti (ng, model, ibuffer)
4905 exit_flag=ibuffer(1)
4906 ioerror=ibuffer(2)
4907 IF (exit_flag.eq.noerror) THEN
4908 CALL mp_bcastl (ng, model, a)
4909 END IF
4910#endif
4911!
4912! If NetCDF file ID is not provided, close input NetCDF file.
4913!
4914 IF (.not.PRESENT(ncid)) THEN
4915 CALL netcdf_close (ng, model, my_ncid, ncname, .false.)
4916 END IF
4917!
4918 10 FORMAT (/,' NETCDF_GET_LVAR_1D - error while reading variable:', &
4919 & 2x,a,/,22x,'in input file:',2x,a,/,22x,'call from:',2x,a, &
4920 & /,22x,a)
4921 20 FORMAT (/,' NETCDF_GET_LVAR_1D - error while inquiring type for ',&
4922 & 'variable:',2x,a,/,22x,'in input file:',2x,a,/,22x, &
4923 & 'call from:',2x,a,/,22x,a)
4924 30 FORMAT (/,' NETCDF_GET_LVAR_1D - error while inquiring ID for ', &
4925 & 'variable:',2x,a,/,22x,'in input file:',2x,a,/,22x, &
4926 & 'call from:',2x,a,/,22x,a)
4927!
4928 RETURN

References mod_scalars::exit_flag, mod_parallel::inpthread, mod_iounits::ioerror, mod_netcdf::netcdf_close(), mod_netcdf::netcdf_open(), mod_scalars::noerror, mod_iounits::sourcefile, and mod_iounits::stdout.

Here is the call graph for this function:

The documentation for this interface was generated from the following file: