libtpcimgio
 All Data Structures Files Functions Variables Typedefs Enumerator Defines
Functions
interfile.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "libtpcmisc.h"
#include "include/interfile.h"
Include dependency graph for interfile.c:

Go to the source code of this file.

Functions

int interfile_read (char headerName[256], char searchWord[256], char returnValue[256], char errorMessage[300])
int interfileIsHeader (const char *hdrfile, char *imgfile)
int interfileExists (const char *fname, char *hdrfile, char *imgfile, int verbose)

Function Documentation

int interfile_read ( char  headerName[256],
char  searchWord[256],
char  returnValue[256],
char  errorMessage[300] 
)

The function searches the keyword in the header and passes the value belonging to that value back to the main program. The name of the header (string 'headerName') and the requested keyword (string 'searchWord') are passed to the function. It passes back the value of the keyword (string 'returnValue') and possibly an error message or warning (string 'errorMessage'). So the values are passed back as strings. The interpretation (conversion to integer, float, time etc) is up to the programmer.

The interfile header has to comply to the following rules:

  • first line in the file is '!INTERFILE'
  • maximal length of a line is 512 characters
  • A line has two fields sperated by ':=' (keyword := value)
  • maximal length of keyword and value is 256 characters.
  • no header entries after a line '!END OF INTERFILE'
  • a line starting with a semicolon ';' is a comment
Parameters:
headerNameheader file name
searchWordkeyword to look for
returnValuevalue for keyword in header
errorMessageerror message/warnings. In case there is a error message it will be returnd as string in the variable 'errmsg'.
Returns:
0 if ok, 1 keyword appears more than once in the interfile header (value of last occurence of keyword is returned), 2 keyword not found in interfile header (returned value is empty (i.e. contains '/0's only)), 3 interfile header cold not be opened for reading (returned value is empty (i.e. contains '/0's only)), 4 wrong file format?! (No '!INTERFILE' in the first line) (returned value is empty (i.e. contains '/0's only))

Definition at line 82 of file interfile.c.

int interfileExists ( const char *  fname,
char *  hdrfile,
char *  imgfile,
int  verbose 
)

Check if specified image filename is a Interfile data.

Returns:
Returns 0 if it is not, 1 if it is, and both image and header is found.
Parameters:
fnameFilename, either header file, image file, or base name without extensions. If file is found, then
hdrfileIf fname is Interfile, then header filename will be written in this char pointer (space needs to allocated by caller); NULL if not needed.
imgfileIf fname is Interfile, then image filename will be written in this char pointer (space needs to allocated by caller); NULL if not needed. Note that filename is stored without path.
verboseVerbose level; if zero, then nothing is printed into stdout or stderr

Definition at line 226 of file interfile.c.

References interfileIsHeader().

Referenced by imgFormatDetermine(), and imgReadHeader().

Here is the call graph for this function:

int interfileIsHeader ( const char *  hdrfile,
char *  imgfile 
)

Verify that given file is a valid Interfile header file.

Returns:
Returns 0 if not, and 1 if it is a valid header file. If image data filename is requested and found in header, then 2 is returned.
Parameters:
hdrfileInterfile header filename, with correct extension
imgfilePointer to allocated string where Interfile image data filename is written if found in header; enter NULL if not needed.

Definition at line 189 of file interfile.c.

Referenced by interfileExists().