Defines | Functions

utils.c File Reference

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Defines

#define STRING   0
#define INTEGER   1
#define FLOAT   2

Functions

int InputType ()
void WrongType ()
float GetResol (float, float, float)
void RemoveBlanks ()
void swapshort ()
void swaplong ()
int InputType (char *string)
void WrongType (int type, char *key, char *string)
void RemoveBlanks (char *str)
void swaplong (char *data, int nbytes)
void swapshort (unsigned short *data, int n)

Define Documentation

#define FLOAT   2

Definition at line 24 of file utils.c.

Referenced by InputType(), and WrongType().

#define INTEGER   1

Definition at line 23 of file utils.c.

Referenced by InputType(), and WrongType().

#define STRING   0

Definition at line 22 of file utils.c.

Referenced by InputType().


Function Documentation

float GetResol ( float  radius,
float  distance,
float  wave 
)

Definition at line 37 of file utils.c.

Referenced by MarXF::get_header_values().

{
float   res;

        if ( distance < 1.0 ) return 0.0;

        res = atan( radius/distance);   /* Two theta !!! */

        if ( res < 0.0001 ) return 0.0;

        res = wave/(2.0*sin(res/2.0)); 
        
        return( res );
}
int InputType ( )
int InputType ( char *  string)

Definition at line 56 of file utils.c.

References FLOAT, i, INTEGER, j, and STRING.

{
int             i,j=0,k=0,l=0;

        for ( i=0 ; i<strlen(string)-1; i++ ) {
                if ( isspace( string[i] ) ) {
                        string[i] = ' ';
                        j++;
                }
                else if ( string[i] == '.' ) {
                        k++;
                        continue;
                }

                else if ( string[i] == '-' || string[i] == '+' ) {
                        l++;
                        continue;
                }
                else if ( isdigit( string[i] ) ) {
                        j++;
                        continue;
                }
        }

        if ( k == 1 && l == 0 && j == i-1 )
                return( FLOAT );
        else if ( k == 1 && l == 1 && j == i-2 )
                return( FLOAT );
        else if ( k == 0 && l == 1 && j == i-1 )
                return( INTEGER );
        else if ( k == 0 && l == 0 && j == i )
                return( INTEGER );
        else
                return( STRING  );

}
void RemoveBlanks ( )
void RemoveBlanks ( char *  str)

Definition at line 113 of file utils.c.

References i, and j.

Referenced by Command::BadInput(), GetConfig(), Getmar345Header(), GetmarNBHeader(), and Command::TestDirectory().

{
int i, j=0, len=strlen(str);

        for(i=0;i<len;i++) {
                if (!isspace(str[i]))
                        str[j++] = str[i];
        }
        if ( j>0)
                str[j] = 0;
}
void swaplong ( char *  data,
int  nbytes 
)

Definition at line 129 of file utils.c.

References i.

Referenced by Getmar300Header(), MarXF::mar_start_scan_readout(), MarNet::net_comm(), MarNet::net_stat(), and MarHW::print_msg().

{
        register int i, t1, t2, t3, t4;

        for(i=nbytes/4;i--;) {
                t1 = data[i*4+3];
                t2 = data[i*4+2];
                t3 = data[i*4+1];
                t4 = data[i*4+0];
                data[i*4+0] = t1;
                data[i*4+1] = t2;
                data[i*4+2] = t3;
                data[i*4+3] = t4;
        }
}
void swaplong ( )
void swapshort ( unsigned short *  data,
int  n 
)

Definition at line 151 of file utils.c.

References i.

{
        register int i;
        register unsigned short t;

        for(i=(n>>1)+1;--i;) {
                /*t = (( (*data)&0xFF) << 8 ) | (( (*data)&0xFF00) >> 8);*/
                t = (((*data) << 8) | ((*data) >> 8));
                *data++ = t;
        }
}
void swapshort ( )
void WrongType ( )
void WrongType ( int  type,
char *  key,
char *  string 
)

Definition at line 97 of file utils.c.

References FLOAT, and INTEGER.

{

        fprintf(stderr,"INPUT ERROR at key '%s' and argument '%s'!\n",key,string);

        if ( type == FLOAT )
                fprintf(stderr,"            Expected data type is: FLOAT...\n");
        else if ( type == INTEGER )
                fprintf(stderr,"            Expected data type is: INTEGER...\n");

}