Correct Fortran - C interop in wsprd code

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5571 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2015-06-10 14:48:26 +00:00
parent 68abfbfe5e
commit ac3c7babf7
6 changed files with 32 additions and 17 deletions

View File

@ -70,13 +70,10 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
#define SELF_TEST 1 #define SELF_TEST 1
#include "nhash.h"
#include <stdio.h> /* defines printf for tests */ #include <stdio.h> /* defines printf for tests */
#include <time.h> /* defines time_t for timings in the test */ #include <time.h> /* defines time_t for timings in the test */
#ifdef Win32
#include "win_stdint.h" /* defines uint32_t etc */
#else
#include <stdint.h> /* defines uint32_t etc */
#endif
//#include <sys/param.h> /* attempt to define endianness */ //#include <sys/param.h> /* attempt to define endianness */
//#ifdef linux //#ifdef linux
//# include <endian.h> /* attempt to define endianness */ //# include <endian.h> /* attempt to define endianness */
@ -205,7 +202,7 @@ acceptable. Do NOT use for cryptographic purposes.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*/ */
uint32_t nhash_( const void *key, size_t length, uint32_t initval) uint32_t nhash( const void *key, size_t length, uint32_t initval)
{ {
uint32_t a,b,c; /* internal state */ uint32_t a,b,c; /* internal state */
union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
@ -374,3 +371,11 @@ uint32_t nhash_( const void *key, size_t length, uint32_t initval)
return c; return c;
} }
/*
* Fortran argument compatible wrapper
*/
uint32_t nhash_( const void * key, size_t const * length, uint32_t const * initval)
{
return nhash (key, *length, *initval);
}

13
lib/wsprd/nhash.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef NHASH_H_
#define NHASH_H_
#ifdef Win32
#include "win_stdint.h" /* defines uint32_t etc */
#else
#include <stdint.h> /* defines uint32_t etc */
#endif
uint32_t nhash( const void * key, size_t length, uint32_t initval);
uint32_t nhash_( void const * key, size_t const * length, uint32_t const * initval);
#endif

View File

@ -6,10 +6,9 @@
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#include "nhash.h"
#include "wsprd_utils.h" #include "wsprd_utils.h"
unsigned int nhash_( const void *key, size_t length, uint32_t initval);
void unpk_(signed char message[], int *nhashtab, char call_loc_pow[]) void unpk_(signed char message[], int *nhashtab, char call_loc_pow[])
{ {
int i,n1,n2,n3,ndbm,ihash,nadd,noprint,nh; int i,n1,n2,n3,ndbm,ihash,nadd,noprint,nh;
@ -74,7 +73,7 @@ void unpk_(signed char message[], int *nhashtab, char call_loc_pow[])
strncat(call_loc_pow," ",1); strncat(call_loc_pow," ",1);
strncat(call_loc_pow,cdbm,2); strncat(call_loc_pow,cdbm,2);
strncat(call_loc_pow,"\0",1); strncat(call_loc_pow,"\0",1);
ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
strcpy(*hashtab+ihash*13,callsign); strcpy(*hashtab+ihash*13,callsign);
} else { } else {
nadd=nu; nadd=nu;
@ -89,7 +88,7 @@ void unpk_(signed char message[], int *nhashtab, char call_loc_pow[])
strncat(call_loc_pow," ",1); strncat(call_loc_pow," ",1);
strncat(call_loc_pow,cdbm,2); strncat(call_loc_pow,cdbm,2);
strncat(call_loc_pow,"\0",1); strncat(call_loc_pow,"\0",1);
ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
strcpy(*hashtab+ihash*13,callsign); strcpy(*hashtab+ihash*13,callsign);
noprint=0; noprint=0;
} }

View File

@ -723,7 +723,6 @@ int main(int argc, char *argv[])
memset(cdbm,0,sizeof(char)*3); memset(cdbm,0,sizeof(char)*3);
char hashtab[32768][13]; char hashtab[32768][13];
memset(hashtab,0,sizeof(char)*32768*13); memset(hashtab,0,sizeof(char)*32768*13);
uint32_t nhash_( const void *, size_t, uint32_t);
int nh; int nh;
if( usehashtable ) { if( usehashtable ) {

View File

@ -27,6 +27,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "wsprd_utils.h" #include "wsprd_utils.h"
#include "nhash.h"
#ifndef int32_t #ifndef int32_t
#define int32_t int #define int32_t int
@ -261,7 +262,7 @@ int unpk_(signed char *message, char hashtab[32768][13], char *call_loc_pow, cha
strncat(call_loc_pow," ",1); strncat(call_loc_pow," ",1);
strncat(call_loc_pow,cdbm,2); strncat(call_loc_pow,cdbm,2);
strncat(call_loc_pow,"\0",1); strncat(call_loc_pow,"\0",1);
ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
strcpy(*hashtab+ihash*13,callsign); strcpy(*hashtab+ihash*13,callsign);
} else { } else {
nadd=nu; nadd=nu;
@ -278,7 +279,7 @@ int unpk_(signed char *message, char hashtab[32768][13], char *call_loc_pow, cha
strncat(call_loc_pow,"\0",1); strncat(call_loc_pow,"\0",1);
int nu=ndbm%10; int nu=ndbm%10;
if( nu == 0 || nu == 3 || nu == 7 || nu == 10 ) { //make sure power is OK if( nu == 0 || nu == 3 || nu == 7 || nu == 10 ) { //make sure power is OK
ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
strcpy(*hashtab+ihash*13,callsign); strcpy(*hashtab+ihash*13,callsign);
} else noprint=1; } else noprint=1;
} }
@ -294,7 +295,7 @@ int unpk_(signed char *message, char hashtab[32768][13], char *call_loc_pow, cha
// not testing 4'th and 5'th chars because of this case: <PA0SKT/2> JO33 40 // not testing 4'th and 5'th chars because of this case: <PA0SKT/2> JO33 40
// grid is only 4 chars even though this is a hashed callsign... // grid is only 4 chars even though this is a hashed callsign...
// isalpha(grid6[4]) && isalpha(grid6[5]) ) ) { // isalpha(grid6[4]) && isalpha(grid6[5]) ) ) {
ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
strcpy(*hashtab+ihash*13,callsign); strcpy(*hashtab+ihash*13,callsign);
} else noprint=1; } else noprint=1;

View File

@ -19,6 +19,4 @@ void deinterleave(unsigned char *sym);
// used by qsort // used by qsort
int floatcomp(const void* elem1, const void* elem2); int floatcomp(const void* elem1, const void* elem2);
unsigned int nhash_( const void *key, size_t length, uint32_t initval);
int unpk_( signed char *message, char hashtab[32768][13], char *call_loc_pow, char *callsign); int unpk_( signed char *message, char hashtab[32768][13], char *call_loc_pow, char *callsign);