Functions
studynr.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "include/studynr.h"
#include "include/substitutions.h"
Include dependency graph for studynr.c:

Functions

int studynr_in_fname (char *fname, char *studynr)
int studynr_from_fname2 (char *fname, char *studynr, int force)
int studynr_from_fname (char *fname, char *studynr)
int fnmatch (char *key, char *fname)
int fncasematch (char *key, char *fname)
int rnameSplit (char *rname, char *name1, char *name2, char *name3, int max_name_len)
int rnameMatch (char *rname, int rnr, char *test_str)
int studynr_match (char *studynr1, char *studynr2)
int studynr_validity_check2 (char *studynr, int zero_ok)
int studynr_validity_check (char *studynr)
int studynr_rm_zeroes (char *studynr)
int studynr_to_lowercase (char *studynr)

Function Documentation

int fncasematch ( char *  key,
char *  fname 
)

Case-independent check whether string fname matches string key, which may contain wildcards ? and *.

Parameters:
keykey string
fnamefilename that is evaluated
Returns:
1 if strings do match and 0 if not.

References fnmatch().

Referenced by rnameMatch().

Here is the call graph for this function:

int fnmatch ( char *  key,
char *  fname 
)

Check if string fname matches string key, which may contain wildcards ? and *.

Parameters:
keykey string
fnamefilename that is evaluated
Returns:
1 if strings do match and 0 if not.

References fnmatch().

Referenced by fncasematch(), and fnmatch().

Here is the call graph for this function:

int rnameMatch ( char *  rname,
int  rnr,
char *  test_str 
)

Test whether region name or number matches with a test string. Test string can contain wildcards. If test string contains only one subname, it is tested against whole rname. If it contains 2-3 subnames, those are tested against the corresponding tokens in rname. Subname '.' stands for empty name. Number is tested only if test string contains one token of all digits.

Parameters:
rnameRegion name which is tested
rnrRegion number (1..)
test_strTest string
Returns:
1, in case of match or 0 if not matched.

References fncasematch(), MAX_REGIONNAME_LEN, and rnameSplit().

Here is the call graph for this function:

int rnameSplit ( char *  rname,
char *  name1,
char *  name2,
char *  name3,
int  max_name_len 
)

Split region name into 1-3 subparts of given max length.

Parameters:
rnameRegion name to split (string is not edited)
name1Pointer to 1st subname (anatomical region)
name2Pointer to 2nd subname (usually hemisphere)
name3Pointer to 3rd subname (usually image plane)
max_name_lenMax lenght of subnames, excluding terminal null
Returns:
the number of subparts.

References MAX_REGIONNAME_LEN.

Referenced by rnameMatch().

int studynr_from_fname ( char *  fname,
char *  studynr 
)

Extract study number (max MAX_STUDYNR_LEN chars) from filename. This function removes initial zeroes from the number part, and converts uppercase letters to lowercase, if necessary.

Parameters:
fnameFilename may include path. Filename is not modified.
studynrPointer for the resulting study number. Memory (>=MAX_STUDYNR_LEN+1 chars) for it must be allocated before calling this.
Returns:
0 if successful.

References studynr_from_fname2().

Here is the call graph for this function:

int studynr_from_fname2 ( char *  fname,
char *  studynr,
int  force 
)

Extract study number (max MAX_STUDYNR_LEN chars) from filename. This function removes initial zeroes from the number part, and converts uppercase letters to lowercase, if necessary.

Returns:
Returns 0 if successful.
Parameters:
fnameFilename, which may include the path. Filename is not modified.
studynrPointer for the resulting study number. Memory (>=MAX_STUDYNR_LEN+1 chars) must be allocated before calling this.
forceValidity of studynr is verified (0) or not verified (1)

References MAX_STUDYNR_LEN, studynr_in_fname(), studynr_rm_zeroes(), studynr_to_lowercase(), and studynr_validity_check().

Referenced by studynr_from_fname().

Here is the call graph for this function:

int studynr_in_fname ( char *  fname,
char *  studynr 
)

Find study number (max MAX_STUDYNR_LEN chars) inside filename; Study number must contain 1-5 letters followed by 1-5 digits, if such string is not found then error code is returned. Initial zeroes are removed if necessary and uppercase letters are changed to lowercase.

Returns:
Returns 0 if successful, otherwise <>0.
Parameters:
fnameFilename may include path. Filename is not modified.
studynrPointer to string (>=MAX_STUDYNR_LEN+1 chars) where the resulting study number is written.

References MAX_STUDYNR_LEN, studynr_rm_zeroes(), studynr_to_lowercase(), and studynr_validity_check2().

Referenced by studynr_from_fname2().

Here is the call graph for this function:

int studynr_match ( char *  studynr1,
char *  studynr2 
)

Check whether two valid study numbers are the same. If either of study numbers is shorter than the other, the end parts are compared; thus study numbers that are changed by SPM can be matched. Argument strings are not modified.

Parameters:
studynr1compared number
studynr2compared number
Returns:
1 if study numbers match exactly, 2 if the match is probable, and zero, if no match is found.

References MAX_STUDYNR_LEN.

int studynr_rm_zeroes ( char *  studynr)

Remove zeroes from the number part of the PET study number.

Parameters:
studynrmodified study number
Returns:
nonzero in case of failure.

Referenced by studynr_from_fname2(), and studynr_in_fname().

int studynr_to_lowercase ( char *  studynr)

Convert the PET study number letters to lowercase. Conversion is not done to non-valid study number.

Parameters:
studynrmodified study number
Returns:
nonzero in case of failure.

Referenced by studynr_from_fname2(), and studynr_in_fname().

int studynr_validity_check ( char *  studynr)

Check that the argument string is a valid TPC study number containing 1-5 letters (upper- or lowercase) followed by 1-5 digits. Argument string is not modified.

Parameters:
studynrevaluated study number
Returns:
1 if study number is valid, zero if not valid or in case of failure.

References studynr_validity_check2().

Referenced by studynr_from_fname2().

Here is the call graph for this function:

int studynr_validity_check2 ( char *  studynr,
int  zero_ok 
)

Check that the argument string is a valid TPC study number containing 1-5 letters (upper- or lowercase) followed by 1-5 digits. Argument string is not modified.

Returns:
1 if study number is valid, zero if not valid or in case of failure.
Parameters:
studynrString to be evaluated as study number. Not modified here.
zero_okNumber part of study number may start with zero (1) or may not (0)

References MAX_STUDYNR_LEN.

Referenced by studynr_in_fname(), and studynr_validity_check().