netcdf-c/nc_test/tst_misc.c

81 lines
1.8 KiB
C
Raw Permalink Normal View History

2010-06-03 21:24:43 +08:00
/*
2018-12-07 05:56:42 +08:00
Copyright 2018, UCAR/Unidata
2010-06-03 21:24:43 +08:00
See COPYRIGHT file for copying and redistribution conditions.
This is part of netCDF.
2010-06-03 21:24:43 +08:00
This program runs some extra tests.
$Id: tst_misc.c,v 1.6 2010/05/05 22:15:36 dmh Exp $
*/
2015-08-16 06:26:35 +08:00
#include "config.h"
2010-06-03 21:24:43 +08:00
#include <stdio.h>
#include <stdlib.h>
2015-08-16 06:26:35 +08:00
#include "netcdf.h"
#include "nc_tests.h"
#include "err_macros.h"
2015-08-16 06:26:35 +08:00
#ifdef USE_PARALLEL
#include "netcdf_par.h"
#endif
2010-06-03 21:24:43 +08:00
#define FILE_NAME "tst_misc.nc"
int
main(int argc, char **argv)
2010-06-03 21:24:43 +08:00
{
2015-08-16 06:26:35 +08:00
#ifdef TEST_PNETCDF
MPI_Init(&argc, &argv);
#endif
2010-06-03 21:24:43 +08:00
printf("\n*** Testing some extra stuff.\n");
printf("*** Trying to open non-netCDF files of tiny length...");
{
#define DATA_LEN 32
int ncid,openstat;
2010-06-03 21:24:43 +08:00
char dummy_data[DATA_LEN];
FILE *file;
int i;
2010-11-30 06:23:16 +08:00
/* Appease valgrind by initializing our data. */
for (i = 0; i < DATA_LEN; i++)
2024-03-12 01:48:42 +08:00
dummy_data[i] = (char)i;
2010-11-30 06:23:16 +08:00
2024-03-12 01:48:42 +08:00
for (size_t i = DATA_LEN; i--> 0;)
2010-06-03 21:24:43 +08:00
{
/* Create a small file which is not a netCDF file. */
Improve UTF8 Support On Windows re: Issue https://github.com/Unidata/netcdf-c/issues/2190 The primary purpose of this PR is to improve the utf8 support for windows. This is persuant to a change in Windows that supports utf8 natively (almost). The almost means that it is still utf16 internally and the set of characters representable by utf8 is larger than those representable by utf16. This leaves open the question in the Issue about handling the Windows 1252 character set. This required the following changes: 1. Test the Windows build and major version in order to see if native utf8 is supported. 2. If native utf8 is supported, Modify dpathmgr.c to call the 8-bit version of the windows fopen() and open() functions. 3. In support of this, programs that use XGetOpt (Windows versions) need to get the command line as utf8 and then parse to arc+argv as utf8. This requires using a homegrown command line parser named XCommandLineToArgvA. 4. Add a utility program called "acpget" that prints out the current Windows code page and locale. Additionally, some technical debt was cleaned up as follows: 1. Unify all the places which attempt to read all or a part of a file into the dutil.c#NC_readfile code. 2. Similary unify all the code that creates temp files into dutil.c#NC_mktmp code. 3. Convert almost all remaining calls to fopen() and open() to NCfopen() and NCopen3(). This is to ensure that path management is used consistently. This touches a number of files. 4. extern->EXTERNL as needed to get it to work under Windows.
2022-02-09 11:53:30 +08:00
if (!(file = NCfopen(FILE_NAME, "w+"))) ERR;
2010-06-03 21:24:43 +08:00
if (fwrite(dummy_data, 1, i, file) != i) ERR;
if (fclose(file)) ERR;
2010-06-03 21:24:43 +08:00
/* Make sure that netCDF rejects this file politely. */
2015-08-16 06:26:35 +08:00
#ifdef TEST_PNETCDF
2018-09-23 09:22:34 +08:00
openstat = nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid);
2015-08-16 06:26:35 +08:00
#else
openstat = nc_open(FILE_NAME, 0, &ncid);
#endif
/* Some platforms (OSX, buddy) return stat = 2 (file not found)
for index i == 2. Not sure why, but this is a work around. */
if(openstat != NC_ENOTNC && openstat != 2) ERR;
2010-06-03 21:24:43 +08:00
}
}
SUMMARIZE_ERR;
#ifndef USE_HDF5
printf("*** Trying to create netCDF-4 file without netCDF-4...");
{
int ncid;
2018-12-07 05:56:42 +08:00
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid) != NC_ENOTBUILT)
ERR;
}
SUMMARIZE_ERR;
#endif /* USE_HDF5 undefined */
2018-12-07 05:56:42 +08:00
2015-08-16 06:26:35 +08:00
#ifdef TEST_PNETCDF
MPI_Finalize();
#endif
2018-12-07 05:56:42 +08:00
2010-06-03 21:24:43 +08:00
FINAL_RESULTS;
}