00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <cstdlib>
00019 #include <iostream>
00020 #include "matpackI.h"
00021 #include "bifstream.h"
00022
00023
00024
00025 typedef long PPHeader[65];
00026
00027 void readppheader (bifstream& is, PPHeader& pph);
00028 void readppdata (bifstream& is, PPHeader& pph, Vector& v);
00029
00030 void readppheader (bifstream& is, PPHeader& pph)
00031 {
00032 for (int j = 0; j < 65 && is.good (); j++)
00033 {
00034 pph[j] = is.readInt (4);
00035 #ifdef VERBOSE
00036 cout << j << " " << pph[j] << " " << is.error () << endl;
00037 #endif
00038 }
00039 }
00040
00041 void readppdata (bifstream& is, PPHeader& pph, Vector& v)
00042 {
00043 const int EXTRA_DATA = 3;
00044 v.resize (pph[15] + EXTRA_DATA);
00045
00046 for (int j = 0; j < pph[15] + EXTRA_DATA && is.good (); j++)
00047 {
00048 v[j] = is.readFloat (binio::Single);
00049 }
00050
00051 if (!is.good ())
00052 {
00053 cerr << "Error: " << is.error() << endl;
00054 }
00055 }
00056
00057 int main (int argc, char *argv[])
00058 {
00059 if (argc < 2)
00060 {
00061 cerr << "Usage: " << argv[0] << " PPFILE [MAXFIELDS]" << endl;
00062 exit (EXIT_FAILURE);
00063 }
00064
00065 long maxfields = -1;
00066 if (argc > 2) maxfields = strtol (argv[2], NULL, 10);
00067
00068 bifstream is (argv[1]);
00069 if (is.good())
00070 {
00071 PPHeader pph;
00072 Vector v;
00073 long field = 0;
00074
00075 is.setFlag (binio::BigEndian, true);
00076 while (is.good() && field != maxfields)
00077 {
00078 binio::Error e;
00079 field++;
00080
00081
00082 is.peekInt (4);
00083 if (is.error () & 32) return (EXIT_FAILURE);
00084
00085 readppheader (is, pph);
00086 if ((e = is.error ()))
00087 {
00088 cerr << "Reading " << field << ". header failed with error "
00089 << e << endl;
00090 exit (EXIT_FAILURE);
00091 }
00092 else
00093 {
00094 cout << "Field # " << setw(5) << field
00095 << " -- STASH code " << setw(5) << pph[42]
00096 << " -- PP code " << setw(4) << pph[23]
00097 << " -- PP VCT " << setw(3) << pph[26] << endl;
00098 }
00099
00100 readppdata (is, pph, v);
00101 if ((e = is.error ()))
00102 {
00103 cerr << "Reading " << field << ". data failed with error "
00104 << e << endl;
00105 exit (EXIT_FAILURE);
00106 }
00107 }
00108 }
00109 else
00110 {
00111 cerr << "Error reading from " << argv[1] << endl;
00112 return (EXIT_FAILURE);
00113 }
00114
00115 return (EXIT_SUCCESS);
00116 }
00117