/* Expodata - An implementation of the raw data listmode extractor LLDATA */ /* for Expo-32 on Unix and DOS/Windows (c) may 2001 */ #include #include #include void usage(); /**********************************************************/ main(int argc, char *argv[]) { FILE *in, *out; char temp[1024], *ptr; int j, channel, param; long i, dsize; if(argc == 1) { printf("%s: file name missing.\n", argv[0]); usage(argv[0]); } else if(argc > 3) { printf("%s: too much arguments.\n", argv[0]); usage(argv[0]); } in = NULL; out = NULL; if(argc == 2 || (argc == 3 && !strcmp(argv[2], "-"))) { out = stdout; if(out == NULL) { printf("%s: cannot open standard output.\n", argv[0]); exit(1); } } in = fopen(argv[1], "rb"); if(in == NULL) { printf("%s: cannot open input file '%s'.\n", argv[0], argv[1]); exit(1); } if((strstr(argv[1], ".lmd") == NULL) && (strstr(argv[1],".LMD") == NULL)) { printf("%s: '%s' is not a LMD file.\n", argv[0], argv[1]); fclose(in); exit(1); } ptr = &temp[0]; for(i = 0; i <= 5; ++i) { *ptr = fgetc(in); ++ ptr; } if((strspn(temp, "FCS0.2")) != 6) { printf("%s: LMD file '%s' does not satisfy FCS 2.0 standard.\n", argv[0], argv[1]); fclose(in); exit(1); } fseek(in, 0x1e, SEEK_SET); ptr = &temp[0]; for(i = 0; i <= 3; ++i) { *ptr = fgetc(in); ++ptr; } if((strspn(temp, "8192")) != 4) { printf("%s: FCS 2.0 LMD file '%s' is not an Expo 32 file.\n", argv[0], argv[1]); fclose(in); exit(1); } if(out == NULL) { strcpy(temp, argv[2]); out = fopen(temp, "w"); if(out == NULL) { printf("%s: cannot open output file '%s'.\n", argv[0], argv[2]); fclose(in); exit(1); } } fseek(in, 0x100, SEEK_SET); ptr = &temp[0]; for(i = 0; i <= 1023; ++i) { *ptr = fgetc(in); ++ptr; } param = atoi(strstr(temp, "\\$PAR\\") + 6); fseek(in, 0x22, SEEK_SET); ptr = &temp[0]; for (i = 0; i <= 7; ++i) { *ptr = fgetc(in); ++ptr; } dsize = 0; for(i = 0; i <= 7; ++i) dsize = (dsize * 10) + (temp[i] & 0x0F); dsize = dsize - 8192; fseek(in, 8192, SEEK_SET); for(i =1; i <= dsize / param / 2; ++i) { for(j = 1; j <= param; ++j) { channel = fgetc(in); channel = channel + fgetc(in) * 0x100; fprintf(out, "%8i", channel); } fprintf(out,"\n"); } fclose(in); fclose(out); } /**********************************************************/ void usage(name) char *name; { fprintf(stderr, "Usage: %s input_file [output_file]\n", name); fprintf(stderr, " input_file - name of LMD input file\n"); fprintf(stderr, " output_file - name of output file\n"); fprintf(stderr, " may be \"-\" as standard output.\n"); exit(1); }