de65914f43
- modifiche per integrare vroni con le nostre librerie - spostamento header in Extern per evitare duplicati.
254 lines
9.5 KiB
C++
254 lines
9.5 KiB
C++
/*****************************************************************************/
|
|
/* */
|
|
/* Copyright (C) 2002--2023 M. Held */
|
|
/* */
|
|
/* This code is not in the public domain. All rights reserved! Please make */
|
|
/* sure to read the full copyright statement contained in "README.pdf" or in */
|
|
/* the "main" file of this code, such as "main.cc". */
|
|
/* */
|
|
/*****************************************************************************/
|
|
/* */
|
|
/* Written by: Martin Held */
|
|
/* */
|
|
/* E-Mail: held@cs.sbg.ac.at */
|
|
/* Fax Mail: (+43 662) 8044-172 */
|
|
/* Voice Mail: (+43 662) 8044-6304 */
|
|
/* Snail Mail: Martin Held */
|
|
/* FB Informatik */
|
|
/* Universitaet Salzburg */
|
|
/* A-5020 Salzburg, Austria */
|
|
/* */
|
|
/*****************************************************************************/
|
|
/* */
|
|
/* get standard libraries */
|
|
/* */
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include "vronivector.h"
|
|
|
|
/* */
|
|
/* get my header files */
|
|
/* */
|
|
#include "fpkernel.h"
|
|
#include "vroni_object.h"
|
|
#include "defs.h"
|
|
#include "ext_appl_defs.h"
|
|
|
|
|
|
/* */
|
|
/* the following functions provide the basic functionality for parsing my */
|
|
/* data files. you are welcome to adapt them to your needs. however, please */
|
|
/* note that my own data files do not contain "exterior application" data. */
|
|
/* thus, you won't be able to parse my sample data files after switching to */
|
|
/* "exterior application" or after modifying the I/O strings. all input */
|
|
/* functions return "false" if EOF or an incorrect data format is */
|
|
/* encountered, and "true" otherwise. you are welcome to modify those */
|
|
/* functions according to your needs. in particular, please note that the */
|
|
/* exterior application macros (e.g., ExtApplFuncReadOptNumber) allow you */
|
|
/* to modify the code in a non-invasive manner. however, please make sure */
|
|
/* not to change the characteristics of the functions' return values! */
|
|
/* */
|
|
/* see io_basic.c for details on my input routines that use those functions. */
|
|
/* */
|
|
|
|
|
|
|
|
vr_bool vroniObject::ReadOptionalNumber(FILE *input, int *data)
|
|
{
|
|
ExtApplFuncReadOptNumber;
|
|
|
|
if (EOF == fscanf(input, "%d", data))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
|
|
vr_bool vroniObject::ReadOptionalCoord(FILE *input, double *xy)
|
|
{
|
|
ExtApplFuncReadOptCoord;
|
|
|
|
if (EOF == FP_fscanf(input, "%lf", xy))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
vr_bool vroniObject::ReadNumber(FILE *input, int *data)
|
|
{
|
|
ExtApplFuncReadNumber;
|
|
|
|
if (EOF == fscanf(input, "%d", data))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
|
|
#ifdef EXT_APPL_PNTS
|
|
vr_bool vroniObject::ReadPntData(FILE *input, double *xc, double *yc, eap_type *eap_data)
|
|
{
|
|
/*
|
|
* sample line for user-specific eap data:
|
|
* if (EOF == fscanf(input, "%lf, %lf, %ld, %s", xc, yc,
|
|
* &(eap_data->id), eap_data->ch))
|
|
*/
|
|
|
|
ExtApplFuncReadPntData;
|
|
|
|
if (EOF == FP_fscanf(input, "%lf %lf", xc, yc))
|
|
return false;
|
|
else
|
|
return true;
|
|
|
|
}
|
|
#else
|
|
vr_bool vroniObject::ReadPntData(FILE *input, double *xc, double *yc)
|
|
{
|
|
ExtApplFuncReadPntData;
|
|
|
|
if (EOF == FP_fscanf(input, "%lf %lf", xc, yc))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
|
|
#ifdef EXT_APPL_SITES
|
|
vr_bool vroniObject::ReadSiteData(FILE *input, double *xc, double *yc, eas_type *eas_data)
|
|
{
|
|
ExtApplFuncReadSiteData;
|
|
|
|
if (EOF == FP_fscanf(input, "%lf %lf %d %d", xc, yc, &( eas_data->first), &( eas_data->second)))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
#else
|
|
vr_bool vroniObject::ReadSiteData(FILE *input, double *xc, double *yc)
|
|
{
|
|
ExtApplFuncReadSiteData;
|
|
|
|
if (EOF == FP_fscanf(input, "%lf %lf", xc, yc))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
|
|
vr_bool vroniObject::ReadVectorData(FILE *input, double *xc, double *yc)
|
|
{
|
|
ExtApplFuncReadVectorData;
|
|
|
|
if (EOF == FP_fscanf(input, "%lf %lf", xc, yc))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
|
|
#ifdef EXT_APPL_PNTS
|
|
void vroniObject::WritePntData(FILE *output, double_arg xc, double_arg yc, eap_type *eap_data)
|
|
{
|
|
ExtApplFuncWritePntData;
|
|
|
|
FP_fprintf(output, "%f %f \n", FP_PRNTARG(xc), FP_PRNTARG(yc));
|
|
/*
|
|
* sample line for user-specific eap data
|
|
*
|
|
* fprintf(output, "%10d %10d %12ld %10s\n",
|
|
* (int) (xc + 0.5), (int) (yc + 0.5),
|
|
* eap_data->id, eap_data->ch);
|
|
*/
|
|
|
|
return;
|
|
}
|
|
#else
|
|
void vroniObject::WritePntData(FILE *output, double_arg xc, double_arg yc)
|
|
{
|
|
ExtApplFuncWritePntData;
|
|
|
|
FP_fprintf(output, "%20.16f %20.16f\n", FP_PRNTARG(xc), FP_PRNTARG(yc));
|
|
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
/* */
|
|
/* This function sets the file pointer of file "input" after the next */
|
|
/* occurrence of one of the input strings. It returns the position (index+1) */
|
|
/* of the string found in the array of strings. If EOF is reached before any */
|
|
/* of the strings was found, zero is returned. */
|
|
/* */
|
|
short vroniObject::fSeeks(FILE *input, /* pointer to the file handle */
|
|
const char *strings[], /* array of strings to be searched for */
|
|
short nbr) /* number of strings in strings[] */
|
|
{
|
|
int *p = (int*) NULL; /* array of indices of current string position */
|
|
int *len = (int*) NULL; /* array of string lengths */
|
|
char sc; /* char sought */
|
|
char rc; /* char read */
|
|
short fidx; /* index of string found */
|
|
short cidx; /* index of current string */
|
|
|
|
len = (int*) ReallocateArray(len, nbr, sizeof(int), "fSeek:len");
|
|
for (cidx = 0; cidx < nbr; cidx++)
|
|
len[cidx] = (int) strlen(strings[cidx]);
|
|
|
|
p = (int*) ReallocateArray(p, nbr, sizeof(int), "fSeek:p");
|
|
for(cidx = 0; cidx < nbr; cidx++)
|
|
p[cidx] = 0;
|
|
|
|
fidx = 0;
|
|
cidx = 0;
|
|
|
|
/* */
|
|
/* loop through file */
|
|
/* */
|
|
while(!fidx && ((rc=fgetc(input))!=EOF)) {
|
|
|
|
/* */
|
|
/* loop over all search strings */
|
|
/* */
|
|
for(cidx = 0; (cidx < nbr) && !fidx; cidx++) {
|
|
/* */
|
|
/* retrieve char sought */
|
|
/* */
|
|
sc = strings[cidx][p[cidx]];
|
|
/* */
|
|
/* has the char sought been found ? */
|
|
/* */
|
|
if(rc == sc) {
|
|
/* */
|
|
/* was it the last char of the current string */
|
|
/* */
|
|
if((p[cidx] + 1) == len[cidx])
|
|
fidx = cidx + 1; /* ready for exit */
|
|
|
|
else
|
|
p[cidx]++; /* try next char of current string */
|
|
|
|
}
|
|
else {
|
|
/* */
|
|
/* restart at first char of current string */
|
|
/* */
|
|
p[cidx] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
FreeMemory((void**) &len, "fSeek:len");
|
|
FreeMemory((void**) &p, "fSeek:p");
|
|
|
|
return fidx;
|
|
}
|