From 7dfcc480ba1e19bd3232349fc733caef94034292 Mon Sep 17 00:00:00 2001 From: stainer_t Date: Mon, 8 Sep 2025 13:48:49 +0200 Subject: Initial commit from Polytechnique Montreal --- Ganlib/src/lcmc_aux.c | 346 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 Ganlib/src/lcmc_aux.c (limited to 'Ganlib/src/lcmc_aux.c') diff --git a/Ganlib/src/lcmc_aux.c b/Ganlib/src/lcmc_aux.c new file mode 100644 index 0000000..357c33a --- /dev/null +++ b/Ganlib/src/lcmc_aux.c @@ -0,0 +1,346 @@ + +/**********************************/ +/* C API for lcm object support */ +/* (auxiliary functions) */ +/* author: A. Hebert (30/04/2002) */ +/**********************************/ + +/* + Copyright (C) 2002 Ecole Polytechnique de Montreal + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + */ + +#include +#include +#include "lcm.h" + +static char AbortString[132]; + +void lcmput_c(lcm **iplist,const char *namp,int_32 ilong,int_32 itype,int_32 *idata) +/* + *---------------------------------------------------------------------- + * + * copy a block of data from memory into a table. + * + * input parameters: + * iplist : address of the table. + * namp : character*12 name of the current block. + * ilong : number of information elements stored in the current block. + * itype : type of information elements stored in the current block. + * 0: directory 1: integer + * 2: single precision 3: character*4 + * 4: double precision 5: logical + * 6: complex 99: undefined + * idata : information elements. + * + *---------------------------------------------------------------------- + */ +{ + if ((*iplist)->header == 200) { + /* USE A XSM FILE. */ + xsmput_c((xsm **)iplist,namp,ilong,itype,idata); + } else { + int_32 i, *iofdat; + int_32 jlong = ilong; + if (itype == 4 || itype == 6) jlong = 2*ilong; + iofdat = (int_32 *)malloc(jlong*sizeof(int_32)); /* setara_c(jlong); */ + for (i = 0; i < jlong; ++i) iofdat[i] = idata[i]; + lcmppd_c(iplist,namp,ilong,itype,iofdat); + } +} + +void lcmpdl_c(lcm **iplist,int_32 iset,int_32 ilong,int_32 itype,int_32 *idata) +/* + *---------------------------------------------------------------------- + * + * copy a block of data from memory into a list. + * + * input parameters: + * iplist : address of the list. + * iset : position of the specific element. + * ilong : number of information elements stored in the current block. + * itype : type of information elements stored in the current block. + * 0: directory 1: integer + * 2: single precision 3: character*4 + * 4: double precision 5: logical + * 6: complex 99: undefined + * idata : information elements. + * + *---------------------------------------------------------------------- + */ +{ + if ((*iplist)->header == 200) { + /* USE A XSM FILE. */ + xsm *ipxsm = (xsm *)*iplist + iset; + xsmput_c(&ipxsm," ",ilong,itype,idata); + } else { + int_32 i, *iofdat; + int_32 jlong = ilong; + if (itype == 4 || itype == 6) jlong = 2*ilong; + iofdat = (int_32 *)malloc(jlong*sizeof(int_32)); /* setara_c(jlong); */ + for (i = 0; i < jlong; ++i) iofdat[i] = idata[i]; + lcmppl_c(iplist,iset,ilong,itype,iofdat); + } +} + +void lcmpcd_c(lcm **iplist,const char *namp,int_32 ilong,char *hdata[]) +/* + *---------------------------------------------------------------------- + * + * copy an array of c string variables from memory into a table. + * + * input parameters: + * iplist : address of the table. + * namp : character*12 name of the block. + * ilong : dimension of the string array. + * hdata : array of ilong strings. + * + *---------------------------------------------------------------------- + */ +{ + int_32 iset; + lcm *jplist; + jplist = lcmlid_c(iplist, namp, ilong); + for (iset=0; iset0; j--) { + if (hdata[iset][j] != ' ') break; + hdata[iset][j]='\0'; + } + } +} + +void lcmpcl_c(lcm **iplist,int_32 iset,int_32 ilong,char *hdata[]) +/* + *---------------------------------------------------------------------- + * + * copy an array of c string variables from memory into a list. + * + * input parameters: + * iplist : address of the table. + * iset : position of the block in the list. + * ilong : dimension of the character variable. + * hdata : array of ilong strings. + * + *---------------------------------------------------------------------- + */ +{ + int_32 jset; + lcm *jplist; + jplist=lcmlil_c(iplist, iset, ilong); + for (jset=0; jset0; j--) { + if (hdata[jset][j] != ' ') break; + hdata[jset][j]='\0'; + } + } +} + +void lcmpsd_c(lcm **iplist,const char *namp,char *hdata) +/* + *---------------------------------------------------------------------- + * + * copy a single c string variable from memory into a table. + * + * input parameters: + * iplist : address of the table. + * namp : character*12 name of the block. + * hdata : c string. + * + *---------------------------------------------------------------------- + */ +{ + int_32 i, ilong, *iofset; + ilong = (strlen(hdata) + 4 ) / 4; + iofset = (int_32 *)malloc(ilong*sizeof(int_32)); /* setara_c(ilong); */ + for (i=0; i 132) { + sprintf(AbortString,"%s: CHARACTER DATA OVERFLOW.",nomsub); + xabort_c(AbortString); + } + + iass = (int_32 *)malloc(ilong*sizeof(int_32)); /* setara_c(ilong); */ + lcmget_c(iplist, namp, iass); + for (i=0; i0; i--) { + if(nomstatic[i] != ' ') break; + nomstatic[i] = '\0'; + } + return nomstatic; +} + +void lcmpsl_c(lcm **iplist,int_32 iset,char *hdata) +/* + *---------------------------------------------------------------------- + * + * copy a single c string variable from memory into a list. + * + * input parameters: + * iplist : address of the table. + * iset : position of the block in the list. + * hdata : c string. + * + *---------------------------------------------------------------------- + */ +{ + int_32 i, ilong, *iofset; + ilong = (strlen(hdata) + 4 ) / 4; + iofset = (int_32 *)malloc(ilong*sizeof(int_32)); /* setara_c(ilong); */ + for (i=0; i 132) { + sprintf(AbortString,"%s: CHARACTER DATA OVERFLOW.",nomsub); + xabort_c(AbortString); + } + + iass = (int_32 *)malloc(ilong*sizeof(int_32)); /* setara_c(ilong); */ + lcmgdl_c(iplist, iset, iass); + for (i=0; i0; i--) { + if(nomstatic[i] != ' ') break; + nomstatic[i] = '\0'; + } + return nomstatic; +} -- cgit v1.2.3