Exemple #1
0
void
freeAllData(SpecFile *sf)
{
    if (sf->motor_pos != (double *)NULL) {
         free(sf->motor_pos);
         sf->motor_pos    = (double *)NULL;
         sf->no_motor_pos = -1;
    }
    if (sf->motor_names != (char **)NULL) {
         freeArrNZ((void ***)&(sf->motor_names),sf->no_motor_names);
         sf->motor_names    = (char **)NULL;
         sf->no_motor_names = -1;
    }
    if (sf->labels != (char **)NULL) {
         freeArrNZ((void ***)&(sf->labels),sf->no_labels);
         sf->labels    = (char **)NULL;
         sf->no_labels = -1;
    }
    if (sf->data_info != (long *)NULL) {
         freeArrNZ((void ***)&(sf->data),sf->data_info[ROW]);
         free(sf->data_info);
         sf->data      = (double **)NULL;
         sf->data_info = (long *)NULL;
    }
}
Exemple #2
0
DllExport char *
SfMotor( SpecFile *sf, long index, long motnum, int *error )
{

     char   **motors=NULL;
     long     nb_mot;
     char    *motor=NULL;
     long     selection;

    /*
     * go to scan
     */
     if (sfSetCurrent(sf,index,error) == -1) {
          return((char *)NULL);
     }

     if ( sf->no_motor_names != -1 ) {
        nb_mot = sf->no_motor_names;
     } else {
        nb_mot = SfAllMotors(sf,index,&motors,error);
     }

     if (nb_mot == 0 || nb_mot == -1)  return((char *)NULL);

     if ( motnum < 0 ) {
           selection = nb_mot + motnum;   
     } else {
           selection = motnum - 1;
     }

     if (selection < 0 || selection > nb_mot - 1 ) {
         *error = SF_ERR_COL_NOT_FOUND;
          if (motors != (char **) NULL)
              freeArrNZ((void ***)&motors,nb_mot);
          return((char *)NULL);
     }

     if (motors != (char **) NULL) {
         motor = (char *)strdup(motors[selection]);
         freeArrNZ((void ***)&motors,nb_mot);
     } else {
         motor = (char *)strdup(sf->motor_names[selection]);
     }
     return( motor );
}
Exemple #3
0
/*********************************************************************
 *   Function:		char *SfLabel( sf, index, column, error )
 *
 *   Description:	Reads one label.
 *
 *   Parameters:
 *		Input :	(1) SpecScan pointer
 *			(2) Scan index
 *			(3) Column number
 *		Output:	(4) Error number 
 *   Returns:
 *			Pointer to the label ,
 *			or NULL if errors occured.			
 *   Possible errors:
 *			SF_ERR_MEMORY_ALLOC	| => getStrFromArr()
 *			SF_ERR_LABEL_NOT_FOUND
 *			SF_ERR_LINE_EMPTY	|
 *			SF_ERR_LINE_NOT_FOUND	|
 *			SF_ERR_SCAN_NOT_FOUND	| => SfAllLabels()
 *			SF_ERR_FILE_READ	|
 *
 *   Remark:  The memory allocated should be freed by the application
 *
 *********************************************************************/
DllExport char *
SfLabel( SpecFile *sf, long index, long column, int *error )
{

     char   **labels=NULL;
     long     no_labels;
     char    *label=NULL;
     long     selection;

     if (sfSetCurrent(sf,index,error) == -1)
          return((char *)NULL);

     if (sf->no_labels != -1 ) {
        no_labels = sf->no_labels;
     } else {
        no_labels = SfAllLabels(sf,index,&labels,error);
     }

     if (no_labels == 0 || no_labels == -1)  return((char *)NULL);

     if ( column < 0 ) {
           selection = no_labels + column;   
     } else {
           selection = column - 1;
     }

     if (selection < 0 || selection > no_labels - 1 ) {
         *error = SF_ERR_COL_NOT_FOUND;
          if (labels != (char **) NULL )
              freeArrNZ((void ***)&labels,no_labels);
          return((char *)NULL);
     }

     if (labels != (char **)NULL) {
         label = (char *)strdup(labels[selection]);
         freeArrNZ((void ***)&labels,no_labels);
     } else {
         label = (char *) strdup(sf->labels[selection]);
     }
     return( label );
}
Exemple #4
0
DllExport double 
SfMotorPosByName( SpecFile *sf, long index, char *name, int *error )
{
     char **motors=NULL;

     long  nb_mot,
           idx,
           selection;
     short tofree=0;

     if (sfSetCurrent(sf,index,error) == -1)
          return(HUGE_VAL);

     if ( sf->no_motor_names != -1 ) {
        nb_mot = sf->no_motor_names;
        motors = sf->motor_names;
     } else {
        nb_mot = SfAllMotors(sf,index,&motors,error);
        tofree=1;
     }

     if (nb_mot == 0 || nb_mot == -1)  return(HUGE_VAL);

     for (idx = 0;idx<nb_mot;idx++) {
         if (!strcmp(name,motors[idx])) break;
     }

     if (idx == nb_mot) {
           if (tofree) freeArrNZ((void ***)&motors,nb_mot);
          *error = SF_ERR_MOTOR_NOT_FOUND;
           return(HUGE_VAL);
     }

     selection = idx+1; 

     return(SfMotorPos(sf,index,selection,error)); 
}