Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
5011cem-2021/TestText.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
61 lines (46 sloc)
1.83 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Script to examine NetCDF data formats and check for non-numeric values (chars only) | |
clear all | |
close all | |
%% Define plain text variable types | |
DataTypes = {'NC_Byte', 'NC_Char', 'NC_Short', 'NC_Int', 'NC_Float', 'NC_Double'}; | |
%% Test a good file | |
%% Set file to test | |
FileName = '../Model/o3_surface_20180701000000.nc'; % define our test file | |
Contents = ncinfo(FileName); % Store the file content information in a variable. | |
FileID = netcdf.open(FileName,'NC_NOWRITE'); % open file read only and create handle | |
for idx = 0:size(Contents.Variables,2)-1 % loop through each variable | |
% read data type for each variable and store | |
[~, datatype(idx+1), ~, ~] = netcdf.inqVar(FileID,idx); | |
end | |
%% display data types | |
DataInFile = DataTypes(datatype)' | |
%% find character data types | |
FindText = strcmp('NC_Char', DataInFile); | |
%% print results | |
fprintf('Testing file: %s\n', FileName) | |
if any(FindText) | |
fprintf('Error, text variables present:\n') | |
else | |
fprintf('All data is numeric, continue analysis.\n') | |
end | |
%% ##### | |
%% Test File with Errors | |
%% Set file to test | |
FileName = '../Model/TestFileText.nc'; % define our test file | |
Contents = ncinfo(FileName); % Store the file content information in a variable. | |
FileID = netcdf.open(FileName,'NC_NOWRITE'); % open file read only and create handle | |
for idx = 0:size(Contents.Variables,2)-1 % loop through each variable | |
% read data type for each variable and store | |
[~, datatype(idx+1), ~, ~] = netcdf.inqVar(FileID,idx); | |
end | |
%% display data types | |
DataInFile = DataTypes(datatype)' | |
%% find character data types | |
FindText = strcmp('NC_Char', DataInFile); | |
%% print results | |
fprintf('Testing file: %s\n', FileName) | |
if any(FindText) | |
fprintf('Error, text variables present:\n') | |
else | |
fprintf('All data is numeric, continue analysis.\n') | |
end |