Skip to content

Commit 19d7696

Browse files
committed
Moved Fortran helper functions from napi.h to a separate file
Fixes #388 Also moved the corresponding function definitions from napi.c Only compile the code if one of the fortran bindings is being built
1 parent 3730be9 commit 19d7696

5 files changed

Lines changed: 232 additions & 172 deletions

File tree

include/napi.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,6 @@ typedef struct {
249249
# define NXlinkexternaldataset MANGLE(nxilinkexternaldataset)
250250
# define NXgetversion MANGLE(nxigetversion)
251251

252-
/*
253-
* FORTRAN helpers - for NeXus internal use only
254-
*/
255-
# define NXfopen MANGLE(nxifopen)
256-
# define NXfclose MANGLE(nxifclose)
257-
# define NXfflush MANGLE(nxifflush)
258-
# define NXfmakedata MANGLE(nxifmakedata)
259-
# define NXfcompmakedata MANGLE(nxifcompmakedata)
260-
# define NXfcompress MANGLE(nxifcompress)
261-
# define NXfputattr MANGLE(nxifputattr)
262-
# define NXfgetpath MANGLE(nxifgetpath)
263-
264252
/*
265253
* Standard interface
266254
*
@@ -993,22 +981,6 @@ extern NXstatus NXsetcache(long newVal);
993981
/*---------------------*/
994982
extern long nx_cacheSize;
995983

996-
/* FORTRAN internals */
997-
998-
extern NXstatus NXfopen(char * filename, NXaccess* am,
999-
NXhandle pHandle);
1000-
extern NXstatus NXfclose (NXhandle pHandle);
1001-
extern NXstatus NXfputattr(NXhandle fid, const char *name, const void *data,
1002-
int *pDatalen, int *pIType);
1003-
extern NXstatus NXfcompress(NXhandle fid, int *compr_type);
1004-
extern NXstatus NXfcompmakedata(NXhandle fid, char *name,
1005-
int *pDatatype,
1006-
int *pRank, int dimensions[],
1007-
int *compression_type, int chunk[]);
1008-
extern NXstatus NXfmakedata(NXhandle fid, char *name, int *pDatatype,
1009-
int *pRank, int dimensions[]);
1010-
extern NXstatus NXfflush(NXhandle pHandle);
1011-
extern NXstatus NXfgetpath(NXhandle fid, char *path, int *pathlen);
1012984
#ifdef __cplusplus
1013985
};
1014986
#endif /* __cplusplus */

include/napi_fortran_helper.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*---------------------------------------------------------------------------
2+
NeXus - Neutron & X-ray Common Data Format
3+
4+
Application Program Interface Header File
5+
6+
Copyright (C) 2015 NeXus International Advisory Committee
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License as published by the Free Software Foundation; either
11+
version 2 of the License, or (at your option) any later version.
12+
13+
This library is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
Lesser General Public License for more details.
17+
18+
You should have received a copy of the GNU Lesser General Public
19+
License along with this library; if not, write to the Free Software
20+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
22+
For further information, see <http://www.nexusformat.org>
23+
24+
----------------------------------------------------------------------------*/
25+
26+
#include <napi.h>
27+
28+
/*
29+
* FORTRAN helpers - for NeXus internal use only
30+
*/
31+
32+
# define NXfopen MANGLE(nxifopen)
33+
# define NXfclose MANGLE(nxifclose)
34+
# define NXfflush MANGLE(nxifflush)
35+
# define NXfmakedata MANGLE(nxifmakedata)
36+
# define NXfcompmakedata MANGLE(nxifcompmakedata)
37+
# define NXfcompress MANGLE(nxifcompress)
38+
# define NXfputattr MANGLE(nxifputattr)
39+
# define NXfgetpath MANGLE(nxifgetpath)
40+
41+
extern NXstatus NXfopen(char * filename, NXaccess* am,
42+
NXhandle pHandle);
43+
extern NXstatus NXfclose (NXhandle pHandle);
44+
extern NXstatus NXfputattr(NXhandle fid, const char *name, const void *data,
45+
int *pDatalen, int *pIType);
46+
extern NXstatus NXfcompress(NXhandle fid, int *compr_type);
47+
extern NXstatus NXfcompmakedata(NXhandle fid, char *name,
48+
int *pDatatype,
49+
int *pRank, int dimensions[],
50+
int *compression_type, int chunk[]);
51+
extern NXstatus NXfmakedata(NXhandle fid, char *name, int *pDatatype,
52+
int *pRank, int dimensions[]);
53+
extern NXstatus NXfflush(NXhandle pHandle);
54+
extern NXstatus NXfgetpath(NXhandle fid, char *path, int *pathlen);

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ add_definitions(-DIN_NEXUS_LIBRARY=1 ${NX_CPP})
3333
set (NAPISRC napi.c napiu.c nxstack.c nxstack.h stptok.c nxdataset.c
3434
nxdataset.h nx_stptok.h)
3535

36+
if (ENABLE_FORTRAN90 OR ENABLE_FORTRAN77)
37+
set (NAPISRC ${NAPISRC} napi_fortran_helper.c)
38+
endif(ENABLE_FORTRAN90 OR ENABLE_FORTRAN77)
39+
3640
set (NAPILINK)
3741

3842
#-----------------------------------------------------------------------------

src/napi.c

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,150 +2022,6 @@ char *NXIformatNeXusTime()
20222022
return time_buffer;
20232023
}
20242024

2025-
/*----------------------------------------------------------------------
2026-
F77 - API - Support - Routines
2027-
----------------------------------------------------------------------*/
2028-
/*
2029-
* We store the whole of the NeXus file in the array - that way
2030-
* we can just pass the array name to C as it will be a valid
2031-
* NXhandle. We could store the NXhandle value in the FORTRAN array
2032-
* instead, but that would mean writing far more wrappers
2033-
*/
2034-
NXstatus NXfopen(char *filename, NXaccess * am, NXhandle pHandle)
2035-
{
2036-
NXstatus ret;
2037-
NXhandle fileid = NULL;
2038-
ret = NXopen(filename, *am, &fileid);
2039-
if (ret == NX_OK) {
2040-
memcpy(pHandle, fileid, getFileStackSize());
2041-
} else {
2042-
memset(pHandle, 0, getFileStackSize());
2043-
}
2044-
if (fileid != NULL) {
2045-
free(fileid);
2046-
}
2047-
return ret;
2048-
}
2049-
2050-
/*
2051-
* The pHandle from FORTRAN is a pointer to a static FORTRAN
2052-
* array holding the NexusFunction structure. We need to malloc()
2053-
* a temporary copy as NXclose will try to free() this
2054-
*/
2055-
NXstatus NXfclose(NXhandle pHandle)
2056-
{
2057-
NXhandle h;
2058-
NXstatus ret;
2059-
h = (NXhandle) malloc(getFileStackSize());
2060-
memcpy(h, pHandle, getFileStackSize());
2061-
ret = NXclose(&h); /* does free(h) */
2062-
memset(pHandle, 0, getFileStackSize());
2063-
return ret;
2064-
}
2065-
2066-
/*---------------------------------------------------------------------*/
2067-
NXstatus NXfflush(NXhandle pHandle)
2068-
{
2069-
NXhandle h;
2070-
NXstatus ret;
2071-
h = (NXhandle) malloc(getFileStackSize());
2072-
memcpy(h, pHandle, getFileStackSize());
2073-
ret = NXflush(&h); /* modifies and reallocates h */
2074-
memcpy(pHandle, h, getFileStackSize());
2075-
return ret;
2076-
}
2077-
2078-
/*----------------------------------------------------------------------*/
2079-
NXstatus NXfmakedata(NXhandle fid, char *name, int *pDatatype,
2080-
int *pRank, int dimensions[])
2081-
{
2082-
NXstatus ret;
2083-
static char buffer[256];
2084-
int i, *reversed_dimensions;
2085-
reversed_dimensions = (int *)malloc(*pRank * sizeof(int));
2086-
if (reversed_dimensions == NULL) {
2087-
sprintf(buffer,
2088-
"ERROR: Cannot allocate space for array rank of %d in NXfmakedata",
2089-
*pRank);
2090-
NXReportError(buffer);
2091-
return NX_ERROR;
2092-
}
2093-
/*
2094-
* Reverse dimensions array as FORTRAN is column major, C row major
2095-
*/
2096-
for (i = 0; i < *pRank; i++) {
2097-
reversed_dimensions[i] = dimensions[*pRank - i - 1];
2098-
}
2099-
ret = NXmakedata(fid, name, *pDatatype, *pRank, reversed_dimensions);
2100-
free(reversed_dimensions);
2101-
return ret;
2102-
}
2103-
2104-
/*-----------------------------------------------------------------------*/
2105-
NXstatus NXfcompmakedata(NXhandle fid, char *name,
2106-
int *pDatatype,
2107-
int *pRank, int dimensions[],
2108-
int *compression_type, int chunk[])
2109-
{
2110-
NXstatus ret;
2111-
static char buffer[256];
2112-
int i, *reversed_dimensions, *reversed_chunk;
2113-
reversed_dimensions = (int *)malloc(*pRank * sizeof(int));
2114-
reversed_chunk = (int *)malloc(*pRank * sizeof(int));
2115-
if (reversed_dimensions == NULL || reversed_chunk == NULL) {
2116-
sprintf(buffer,
2117-
"ERROR: Cannot allocate space for array rank of %d in NXfcompmakedata",
2118-
*pRank);
2119-
NXReportError(buffer);
2120-
return NX_ERROR;
2121-
}
2122-
/*
2123-
* Reverse dimensions array as FORTRAN is column major, C row major
2124-
*/
2125-
for (i = 0; i < *pRank; i++) {
2126-
reversed_dimensions[i] = dimensions[*pRank - i - 1];
2127-
reversed_chunk[i] = chunk[*pRank - i - 1];
2128-
}
2129-
ret = NXcompmakedata(fid, name, *pDatatype, *pRank,
2130-
reversed_dimensions, *compression_type,
2131-
reversed_chunk);
2132-
free(reversed_dimensions);
2133-
free(reversed_chunk);
2134-
return ret;
2135-
}
2136-
2137-
/*-----------------------------------------------------------------------*/
2138-
NXstatus NXfcompress(NXhandle fid, int *compr_type)
2139-
{
2140-
return NXcompress(fid, *compr_type);
2141-
}
2142-
2143-
/*-----------------------------------------------------------------------*/
2144-
NXstatus NXfputattr(NXhandle fid, const char *name, const void *data,
2145-
int *pDatalen, int *pIType)
2146-
{
2147-
return NXputattr(fid, name, data, *pDatalen, *pIType);
2148-
}
2149-
2150-
/*
2151-
* implement snprintf when it is not available
2152-
*/
2153-
int nxisnprintf(char *buffer, int len, const char *format, ...)
2154-
{
2155-
int ret;
2156-
va_list valist;
2157-
va_start(valist, format);
2158-
ret = vsprintf(buffer, format, valist);
2159-
va_end(valist);
2160-
return ret;
2161-
}
2162-
2163-
/*--------------------------------------------------------------------------*/
2164-
NXstatus NXfgetpath(NXhandle fid, char *path, int *pathlen)
2165-
{
2166-
return NXgetpath(fid, path, *pathlen);
2167-
}
2168-
21692025
const char *NXgetversion()
21702026
{
21712027
return NEXUS_VERSION;

0 commit comments

Comments
 (0)