srv2sra.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. int DimX;
  4. int DimY;
  5. int DimT;
  6. int head[10];
  7. int Count;
  8. float *F;
  9. int main(int argc, char *argv[])
  10. {
  11. int i,j;
  12. FILE *ifp;
  13. FILE *ofp;
  14. ifp = fopen(argv[1],"r");
  15. ofp = fopen(argv[2],"w");
  16. fread(head,sizeof(int),10,ifp);
  17. DimX = head[5];
  18. DimY = head[6];
  19. DimT = DimX * DimY;
  20. F = (float *)malloc((DimT+2) * sizeof(float));
  21. while (!feof(ifp))
  22. {
  23. ++Count;
  24. fread(F,sizeof(float),DimT+2,ifp);
  25. for (i = 1 ; i < 9 ; ++i) fprintf(ofp,"%9d",head[i]);
  26. fprintf(ofp,"\n");
  27. for (j = 1 ; j <= DimT ; j += 8)
  28. {
  29. for (i = j ; i < j + 8 && i <= DimT ; ++i)
  30. fprintf(ofp," %8.3f",F[i]);
  31. fprintf(ofp,"\n");
  32. }
  33. fread(head,sizeof(int),10,ifp);
  34. }
  35. if (Count == 0) printf("\n*** Error - no service array found ***\n");
  36. else if (Count == 1)
  37. printf("\nConverted one array from binary service (srv) to ASCII service (sra)\n");
  38. else
  39. printf("\nConverted %d arrays from binary service (srv) to ASCII service (sra)\n",Count);
  40. return 0;
  41. }