home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 308_01 / pad.c < prev    next >
Text File  |  1990-06-17  |  2KB  |  61 lines

  1. /* File pad.c
  2. /* Reads commandline file
  3. /* Writes file "padded.dat" with commandline number of data points
  4. /* Writes "0.0"s if needed to create sufficient points
  5. /* Useful for zero padding short impulse response sequences so
  6. /* that long FFT can be used to obtain good frequency resolution
  7.  */
  8.  
  9. #include "stdio.h"
  10.  
  11. main(argc, argv) int argc; char *argv[];{
  12. char nam[16];
  13. char temp[80];
  14. static char nam1[16] = "padded.dat";
  15. int i,j,size;
  16. float *p;
  17. FILE *chan;
  18. FILE *chan1;
  19.  
  20. if(argc < 3) {
  21.    printf("Usage:    pad [filename] [total data points]\n");
  22.    printf("Example:  pad impulse.rmz 512\n");
  23.    exit();
  24. }
  25.  
  26. else strcpy (nam,argv[1]); /* get commandline filename into nam */
  27. size = atoi(argv[2]);
  28.  
  29. chan = fopen(nam,"r");     /* opens file for read */
  30. if (chan == 0){
  31.    printf("Cannot open file %s\n",nam);
  32.    return;           /* bail out if can't open file */
  33. }
  34.  
  35. /* OPEN FILE FOR WRITE */
  36. chan1 = 0;
  37. while(chan1 == 0){
  38.       chan1 = fopen(nam1,"wb");  /* opens file for write binary */
  39.       if (chan1 == 0){printf("Cannot open file %s\n",nam1);exit();}
  40. }
  41.  
  42. i = 1;
  43. do{
  44.    j = fscanf(chan,"%s",temp);
  45.    if(j == 0){printf("Error reading %s\n",nam);exit();}
  46.    if(j == EOF || i > size) break;
  47.    fprintf(chan1,"%s ",temp);
  48.    if(!(i%6)){fprintf(chan1,"\r"); fprintf(chan1,"\n");}
  49. }while(i++);
  50.  
  51. i--;
  52. while(i++ < size){
  53.    fprintf(chan1,"%s ","0.0");
  54.    if(!(i%6)){fprintf(chan1,"\r"); fprintf(chan1,"\n");}
  55. }
  56.  
  57. printf("Done writing padded.dat\n");
  58. fclose(chan);
  59. fclose(chan1);
  60. }
  61.