#include #include #include #include #include #define LINE_MAX_LEN 1024 char input[LINE_MAX_LEN]; int main ( int argc, char **argv ); int pcl_to_pure ( FILE *filein, FILE *fileout ); int picl_read ( FILE *filein ); /******************************************************************************/ int main ( int argc, char **argv ) { /******************************************************************************/ /* Purpose: PCL_READ reads a PCL file for Arabidopsis and writes out a pure data file. Discussion: The PCL file has a (long) first line containing titles. There follow N lines, each containing 3 labels, and 14 floating values, separated by TAB characters. The output file contains N lines, each containing 14 floating values, separated by spaces. Modified: 01 July 2001 Author: John Burkardt */ FILE *filein; char filein_name[81]; FILE *fileout; char fileout_name[81]; int iarg; int status; char *string; printf ( "\n" ); printf ( "PCL_READ:\n" ); printf ( " Read an Arabidopsis PCL file.\n" ); printf ( " Write a copy containing just the numeric data.\n" ); iarg = 0; /* Determination of input file name. */ if ( argc <= 1 ) { printf ( "\n" ); printf ( "Enter the input PCL file name.\n" ); string = fgets ( input, LINE_MAX_LEN, stdin ); if ( string == NULL ) { return 1; } sscanf ( input, "%s", filein_name ); } else { iarg = iarg + 1; strcpy ( filein_name, argv[iarg] ); } /* Open the input file. */ filein = fopen ( filein_name, "r" ); if ( filein == NULL ) { printf ( "\n" ); printf ( "PCL_READ - Fatal error!\n" ); printf ( " Could not open the input file '%s'!\n", filein_name ); return 1; } printf ( "\n" ); printf ( "Data will be read from %s.\n", filein_name ); /* Determine the output file name. */ if ( argc <= 2 ) { printf ( "\n" ); printf ( "Enter the output file name.\n" ); string = fgets ( input, LINE_MAX_LEN, stdin ); if ( string == NULL ) { return 1; } sscanf ( input, "%s", fileout_name ); } else { iarg = iarg + 1; strcpy ( fileout_name, argv[iarg] ); } printf ( "\n" ); printf ( "Data will be written to %s.\n", fileout_name ); /* Open the output file. */ fileout = fopen ( fileout_name, "w" ); if ( fileout == NULL ) { printf ( "\n" ); printf ( "PCL_READ - Fatal error!\n" ); printf ( " Could not open the output file '%s'!\n", fileout_name ); return 1; } status = pcl_to_pure ( filein, fileout ); status = fclose ( filein ); status = fclose ( fileout ); printf ( "\n" ); printf ( "PCL_READ:\n" ); printf ( " Normal end of execution.\n" ); return status; } /******************************************************************************/ int pcl_to_pure ( FILE *filein, FILE *fileout ) { /******************************************************************************/ /* Purpose: PCL_TO_PURE reads data from a PCL file and writes the numeric data to another file. */ int i; int skip; char *string; int text_num = 0; int width; float x[14]; for ( ;; ) { /* Read a line from the file. */ string = fgets ( input, LINE_MAX_LEN, filein ); if ( string == NULL ) { break; } text_num = text_num + 1; /* First line is the title. */ if ( text_num == 1 ) { printf ( "\n" ); printf ( "PCL_TO_PURE: Title:\n" ); printf ( " %s\n", input ); continue; } /* All other lines have the form of 17 fields separated by tabs. The first 3 fields are identifiers. The following 14 are numeric. */ skip = 0; for ( i = 0; i < 3; i++ ) { while ( *string != '\t' ) { string = string + 1; skip = skip + 1; } string = string + 1; skip = skip + 1; } /* Read the next word from the line. */ for ( i = 0; i < 14; i++ ) { sscanf ( string, "%f%n", &x[i], &width ); string = string + width; } for ( i = 0; i < 14; i++ ) { fprintf ( fileout, "%f ", x[i] ); } fprintf ( fileout, "\n" ); } printf ( "\n" ); printf ( "PCL_TO_PURE:\n" ); printf ( " Number of input lines read was %d.\n", text_num ); return 0; }