From: <ro...@us...> - 2003-04-19 00:11:56
|
Update of /cvsroot/nsclspectcl/SpecTcl/SpectrumIO In directory sc8-pr-cvs1:/tmp/cvs-serv7438 Modified Files: NSCLAsciiSpectrumFormatter.h NSCLAsciiSpectrumFormatter.cpp Log Message: Move to format version 2.0: Supply mapping information about the range covered by each axis of a spectrum. Note that reads are backwards compatible with version 1.0 and will default the range to 0 - nchans-1. Index: NSCLAsciiSpectrumFormatter.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/SpectrumIO/NSCLAsciiSpectrumFormatter.h,v retrieving revision 4.1 retrieving revision 4.2 diff -C2 -d -r4.1 -r4.2 *** NSCLAsciiSpectrumFormatter.h 2 Jan 2003 17:11:33 -0000 4.1 --- NSCLAsciiSpectrumFormatter.h 19 Apr 2003 00:11:50 -0000 4.2 *************** *** 1,279 **** - /* - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your - freedom to share and change it. By contrast, the GNU General Public - License is intended to guarantee your freedom to share and change free - software--to make sure the software is free for all its users. This - General Public License applies to most of the Free Software - Foundation's software and to any other program whose authors commit to - using it. (Some other Free Software Foundation software is covered by - the GNU Library General Public License instead.) You can apply it to - your programs, too. - - When we speak of free software, we are referring to freedom, not - price. Our General Public Licenses are designed to make sure that you - have the freedom to distribute copies of free software (and charge for - this service if you wish), that you receive source code or can get it - if you want it, that you can change the software or use pieces of it - in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid - anyone to deny you these rights or to ask you to surrender the rights. - These restrictions translate to certain responsibilities for you if you - distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether - gratis or for a fee, you must give the recipients all the rights that - you have. You must make sure that they, too, receive or can get the - source code. And you must show them these terms so they know their - rights. - - We protect your rights with two steps: (1) copyright the software, and - (2) offer you this license which gives you legal permission to copy, - distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain - that everyone understands that there is no warranty for this free - software. If the software is modified by someone else and passed on, we - want its recipients to know that what they have is not the original, so - that any problems introduced by others will not reflect on the original - authors' reputations. - - Finally, any free program is threatened constantly by software - patents. We wish to avoid the danger that redistributors of a free - program will individually obtain patent licenses, in effect making the - program proprietary. To prevent this, we have made it clear that any - patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and - modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains - a notice placed by the copyright holder saying it may be distributed - under the terms of this General Public License. The "Program", below, - refers to any such program or work, and a "work based on the Program" - means either the Program or any derivative work under copyright law: - that is to say, a work containing the Program or a portion of it, - either verbatim or with modifications and/or translated into another - language. (Hereinafter, translation is included without limitation in - the term "modification".) Each licensee is addressed as "you". - - Activities other than copying, distribution and modification are not - covered by this License; they are outside its scope. The act of - running the Program is not restricted, and the output from the Program - is covered only if its contents constitute a work based on the - Program (independent of having been made by running the Program). - Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's - source code as you receive it, in any medium, provided that you - conspicuously and appropriately publish on each copy an appropriate - copyright notice and disclaimer of warranty; keep intact all the - notices that refer to this License and to the absence of any warranty; - and give any other recipients of the Program a copy of this License - along with the Program. - - You may charge a fee for the physical act of transferring a copy, and - you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion - of it, thus forming a work based on the Program, and copy and - distribute such modifications or work under the terms of Section 1 - above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - - These requirements apply to the modified work as a whole. If - identifiable sections of that work are not derived from the Program, - and can be reasonably considered independent and separate works in - themselves, then this License, and its terms, do not apply to those - sections when you distribute them as separate works. But when you - distribute the same sections as part of a whole which is a work based - on the Program, the distribution of the whole must be on the terms of - this License, whose permissions for other licensees extend to the - entire whole, and thus to each and every part regardless of who wrote it. - - Thus, it is not the intent of this section to claim rights or contest - your rights to work written entirely by you; rather, the intent is to - exercise the right to control the distribution of derivative or - collective works based on the Program. - - In addition, mere aggregation of another work not based on the Program - with the Program (or with a work based on the Program) on a volume of - a storage or distribution medium does not bring the other work under - the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, - under Section 2) in object code or executable form under the terms of - Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - - The source code for a work means the preferred form of the work for - making modifications to it. For an executable work, complete source - code means all the source code for all modules it contains, plus any - associated interface definition files, plus the scripts used to - control compilation and installation of the executable. However, as a - special exception, the source code distributed need not include - anything that is normally distributed (in either source or binary - form) with the major components (compiler, kernel, and so on) of the - operating system on which the executable runs, unless that component - itself accompanies the executable. - - If distribution of executable or object code is made by offering - access to copy from a designated place, then offering equivalent - access to copy the source code from the same place counts as - distribution of the source code, even though third parties are not - compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program - except as expressly provided under this License. Any attempt - otherwise to copy, modify, sublicense or distribute the Program is - void, and will automatically terminate your rights under this License. - However, parties who have received copies, or rights, from you under - this License will not have their licenses terminated so long as such - parties remain in full compliance. - - 5. You are not required to accept this License, since you have not - signed it. However, nothing else grants you permission to modify or - distribute the Program or its derivative works. These actions are - prohibited by law if you do not accept this License. Therefore, by - modifying or distributing the Program (or any work based on the - Program), you indicate your acceptance of this License to do so, and - all its terms and conditions for copying, distributing or modifying - the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the - Program), the recipient automatically receives a license from the - original licensor to copy, distribute or modify the Program subject to - these terms and conditions. You may not impose any further - restrictions on the recipients' exercise of the rights granted herein. - You are not responsible for enforcing compliance by third parties to - this License. - - 7. If, as a consequence of a court judgment or allegation of patent - infringement or for any other reason (not limited to patent issues), - conditions are imposed on you (whether by court order, agreement or - otherwise) that contradict the conditions of this License, they do not - excuse you from the conditions of this License. If you cannot - distribute so as to satisfy simultaneously your obligations under this - License and any other pertinent obligations, then as a consequence you - may not distribute the Program at all. For example, if a patent - license would not permit royalty-free redistribution of the Program by - all those who receive copies directly or indirectly through you, then - the only way you could satisfy both it and this License would be to - refrain entirely from distribution of the Program. - - If any portion of this section is held invalid or unenforceable under - any particular circumstance, the balance of the section is intended to - apply and the section as a whole is intended to apply in other - circumstances. - - It is not the purpose of this section to induce you to infringe any - patents or other property right claims or to contest validity of any - such claims; this section has the sole purpose of protecting the - integrity of the free software distribution system, which is - implemented by public license practices. Many people have made - generous contributions to the wide range of software distributed - through that system in reliance on consistent application of that - system; it is up to the author/donor to decide if he or she is willing - to distribute software through any other system and a licensee cannot - impose that choice. - - This section is intended to make thoroughly clear what is believed to - be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in - certain countries either by patents or by copyrighted interfaces, the - original copyright holder who places the Program under this License - may add an explicit geographical distribution limitation excluding - those countries, so that distribution is permitted only in or among - countries not thus excluded. In such case, this License incorporates - the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the Program - specifies a version number of this License which applies to it and "any - later version", you have the option of following the terms and conditions - either of that version or of any later version published by the Free Software - Foundation. If the Program does not specify a version number of this License, - you may choose any version ever published by the Free Software Foundation. - - 10. If you wish to incorporate parts of the Program into other free - programs whose distribution conditions are different, write to the author to - ask for permission. For software which is copyrighted by the Free Software - Foundation, write to the Free Software Foundation; we sometimes make - exceptions for this. Our decision will be guided by the two goals of - preserving the free status of all derivatives of our free software and of - promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR - THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN - OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE - THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND - PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, - YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING - WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR - REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, - INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING - OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO - LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR - THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), - EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - DAMAGES. - - END OF TERMS AND CONDITIONS - */ // Class: CNSCLAsciiSpectrumFormatter //ANSI C++ // --- 1,2 ---- *************** *** 291,294 **** --- 14,24 ---- // + /* + Change log: + $Log$ + Revision 4.2 2003/04/19 00:11:50 ron-fox + Move to format version 2.0: Supply mapping information about the range covered by each axis of a spectrum. Note that reads are backwards compatible with version 1.0 and will default the range to 0 - nchans-1. + + */ #ifndef __NSCLASCIISPECTRUMFORMATTER_H //Required for current class #define __NSCLASCIISPECTRUMFORMATTER_H *************** *** 313,318 **** #endif ! class CNSCLAsciiSpectrumFormatter : public CSpectrumFormatter { --- 43,70 ---- #endif + /*! + Class: CNSCLAsciiSpectrumFormatter + does I/O to spectrum in a simple ASCII format. + The format is as follows: + line 1: "name" (dimensions) \n + line 2: date/time \n + line 3: 2.0\n [note 2.0 is file format version]. + line 4: spectrum type (SpecTcl coding)\n + line 5: List of parameters in spectrum.\n + line 6: List of axis ranges (new in format 2.0). + line 7: "-------------------------------------------\n" + data lines: (coords) data + end line (-1 for all coords) -1 for data. ! \note that missing coordinates have data values of zero. ! (zero supression). ! \note this format allows for several spectra to fit into a file as ! well as for mixed spectrum other data files. ! \note The axis range format is : (low high) once for each dimension. ! \note This class is able to read in format level 1.0 as well (same ! format as above, but line 6 is missing. In this case, the ! spectrum axis is assumed to run from 0 - size-1 ! ! */ class CNSCLAsciiSpectrumFormatter : public CSpectrumFormatter { *************** *** 380,384 **** DataType_t& rDataType, vector<UInt_t>& rDimensions, ! vector<string>& rParameters); static string ReadLine(istream& rStream); static Bool_t CompatibleFormat(Float_t nFormat); --- 132,138 ---- DataType_t& rDataType, vector<UInt_t>& rDimensions, ! vector<string>& rParameters, ! vector<Float_t>& rLows, ! vector<Float_t>& rHighs); static string ReadLine(istream& rStream); static Bool_t CompatibleFormat(Float_t nFormat); *************** *** 391,394 **** --- 145,150 ---- static void DecodeParenList(istream& rStream, vector<string>& rList); + static void DecodeListOfParenLists(istream& rStream, + vector<string>& rList); static void CheckIndices(vector<UInt_t>& Dimensions, vector<UInt_t>& Indices); Index: NSCLAsciiSpectrumFormatter.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/SpectrumIO/NSCLAsciiSpectrumFormatter.cpp,v retrieving revision 4.3 retrieving revision 4.4 diff -C2 -d -r4.3 -r4.4 *** NSCLAsciiSpectrumFormatter.cpp 2 Apr 2003 18:20:12 -0000 4.3 --- NSCLAsciiSpectrumFormatter.cpp 19 Apr 2003 00:11:50 -0000 4.4 *************** *** 1,298 **** ! /* ! GNU GENERAL PUBLIC LICENSE ! Version 2, June 1991 ! ! Copyright (C) 1989, 1991 Free Software Foundation, Inc. ! 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! Everyone is permitted to copy and distribute verbatim copies ! of this license document, but changing it is not allowed. ! ! Preamble ! ! The licenses for most software are designed to take away your ! freedom to share and change it. By contrast, the GNU General Public ! License is intended to guarantee your freedom to share and change free ! software--to make sure the software is free for all its users. This ! General Public License applies to most of the Free Software ! Foundation's software and to any other program whose authors commit to ! using it. (Some other Free Software Foundation software is covered by ! the GNU Library General Public License instead.) You can apply it to ! your programs, too. ! ! When we speak of free software, we are referring to freedom, not ! price. Our General Public Licenses are designed to make sure that you ! have the freedom to distribute copies of free software (and charge for ! this service if you wish), that you receive source code or can get it ! if you want it, that you can change the software or use pieces of it ! in new free programs; and that you know you can do these things. ! ! To protect your rights, we need to make restrictions that forbid ! anyone to deny you these rights or to ask you to surrender the rights. ! These restrictions translate to certain responsibilities for you if you ! distribute copies of the software, or if you modify it. ! ! For example, if you distribute copies of such a program, whether ! gratis or for a fee, you must give the recipients all the rights that ! you have. You must make sure that they, too, receive or can get the ! source code. And you must show them these terms so they know their ! rights. ! ! We protect your rights with two steps: (1) copyright the software, and ! (2) offer you this license which gives you legal permission to copy, ! distribute and/or modify the software. ! ! Also, for each author's protection and ours, we want to make certain ! that everyone understands that there is no warranty for this free ! software. If the software is modified by someone else and passed on, we ! want its recipients to know that what they have is not the original, so ! that any problems introduced by others will not reflect on the original ! authors' reputations. ! ! Finally, any free program is threatened constantly by software ! patents. We wish to avoid the danger that redistributors of a free ! program will individually obtain patent licenses, in effect making the ! program proprietary. To prevent this, we have made it clear that any ! patent must be licensed for everyone's free use or not licensed at all. ! ! The precise terms and conditions for copying, distribution and ! modification follow. ! ! GNU GENERAL PUBLIC LICENSE ! TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION ! ! 0. This License applies to any program or other work which contains ! a notice placed by the copyright holder saying it may be distributed ! under the terms of this General Public License. The "Program", below, ! refers to any such program or work, and a "work based on the Program" ! means either the Program or any derivative work under copyright law: ! that is to say, a work containing the Program or a portion of it, ! either verbatim or with modifications and/or translated into another ! language. (Hereinafter, translation is included without limitation in ! the term "modification".) Each licensee is addressed as "you". ! ! Activities other than copying, distribution and modification are not ! covered by this License; they are outside its scope. The act of ! running the Program is not restricted, and the output from the Program ! is covered only if its contents constitute a work based on the ! Program (independent of having been made by running the Program). ! Whether that is true depends on what the Program does. ! ! 1. You may copy and distribute verbatim copies of the Program's ! source code as you receive it, in any medium, provided that you ! conspicuously and appropriately publish on each copy an appropriate ! copyright notice and disclaimer of warranty; keep intact all the ! notices that refer to this License and to the absence of any warranty; ! and give any other recipients of the Program a copy of this License ! along with the Program. ! ! You may charge a fee for the physical act of transferring a copy, and ! you may at your option offer warranty protection in exchange for a fee. ! ! 2. You may modify your copy or copies of the Program or any portion ! of it, thus forming a work based on the Program, and copy and ! distribute such modifications or work under the terms of Section 1 ! above, provided that you also meet all of these conditions: ! ! a) You must cause the modified files to carry prominent notices ! stating that you changed the files and the date of any change. ! ! b) You must cause any work that you distribute or publish, that in ! whole or in part contains or is derived from the Program or any ! part thereof, to be licensed as a whole at no charge to all third ! parties under the terms of this License. ! ! c) If the modified program normally reads commands interactively ! when run, you must cause it, when started running for such ! interactive use in the most ordinary way, to print or display an ! announcement including an appropriate copyright notice and a ! notice that there is no warranty (or else, saying that you provide ! a warranty) and that users may redistribute the program under ! these conditions, and telling the user how to view a copy of this ! License. (Exception: if the Program itself is interactive but ! does not normally print such an announcement, your work based on ! the Program is not required to print an announcement.) ! ! These requirements apply to the modified work as a whole. If ! identifiable sections of that work are not derived from the Program, ! and can be reasonably considered independent and separate works in ! themselves, then this License, and its terms, do not apply to those ! sections when you distribute them as separate works. But when you ! distribute the same sections as part of a whole which is a work based ! on the Program, the distribution of the whole must be on the terms of ! this License, whose permissions for other licensees extend to the ! entire whole, and thus to each and every part regardless of who wrote it. ! ! Thus, it is not the intent of this section to claim rights or contest ! your rights to work written entirely by you; rather, the intent is to ! exercise the right to control the distribution of derivative or ! collective works based on the Program. ! ! In addition, mere aggregation of another work not based on the Program ! with the Program (or with a work based on the Program) on a volume of ! a storage or distribution medium does not bring the other work under ! the scope of this License. ! ! 3. You may copy and distribute the Program (or a work based on it, ! under Section 2) in object code or executable form under the terms of ! Sections 1 and 2 above provided that you also do one of the following: ! ! a) Accompany it with the complete corresponding machine-readable ! source code, which must be distributed under the terms of Sections ! 1 and 2 above on a medium customarily used for software interchange; or, ! ! b) Accompany it with a written offer, valid for at least three ! years, to give any third party, for a charge no more than your ! cost of physically performing source distribution, a complete ! machine-readable copy of the corresponding source code, to be ! distributed under the terms of Sections 1 and 2 above on a medium ! customarily used for software interchange; or, ! ! c) Accompany it with the information you received as to the offer ! to distribute corresponding source code. (This alternative is ! allowed only for noncommercial distribution and only if you ! received the program in object code or executable form with such ! an offer, in accord with Subsection b above.) ! ! The source code for a work means the preferred form of the work for ! making modifications to it. For an executable work, complete source ! code means all the source code for all modules it contains, plus any ! associated interface definition files, plus the scripts used to ! control compilation and installation of the executable. However, as a ! special exception, the source code distributed need not include ! anything that is normally distributed (in either source or binary ! form) with the major components (compiler, kernel, and so on) of the ! operating system on which the executable runs, unless that component ! itself accompanies the executable. ! ! If distribution of executable or object code is made by offering ! access to copy from a designated place, then offering equivalent ! access to copy the source code from the same place counts as ! distribution of the source code, even though third parties are not ! compelled to copy the source along with the object code. ! ! 4. You may not copy, modify, sublicense, or distribute the Program ! except as expressly provided under this License. Any attempt ! otherwise to copy, modify, sublicense or distribute the Program is ! void, and will automatically terminate your rights under this License. ! However, parties who have received copies, or rights, from you under ! this License will not have their licenses terminated so long as such ! parties remain in full compliance. ! ! 5. You are not required to accept this License, since you have not ! signed it. However, nothing else grants you permission to modify or ! distribute the Program or its derivative works. These actions are ! prohibited by law if you do not accept this License. Therefore, by ! modifying or distributing the Program (or any work based on the ! Program), you indicate your acceptance of this License to do so, and ! all its terms and conditions for copying, distributing or modifying ! the Program or works based on it. ! ! 6. Each time you redistribute the Program (or any work based on the ! Program), the recipient automatically receives a license from the ! original licensor to copy, distribute or modify the Program subject to ! these terms and conditions. You may not impose any further ! restrictions on the recipients' exercise of the rights granted herein. ! You are not responsible for enforcing compliance by third parties to ! this License. ! ! 7. If, as a consequence of a court judgment or allegation of patent ! infringement or for any other reason (not limited to patent issues), ! conditions are imposed on you (whether by court order, agreement or ! otherwise) that contradict the conditions of this License, they do not ! excuse you from the conditions of this License. If you cannot ! distribute so as to satisfy simultaneously your obligations under this ! License and any other pertinent obligations, then as a consequence you ! may not distribute the Program at all. For example, if a patent ! license would not permit royalty-free redistribution of the Program by ! all those who receive copies directly or indirectly through you, then ! the only way you could satisfy both it and this License would be to ! refrain entirely from distribution of the Program. ! ! If any portion of this section is held invalid or unenforceable under ! any particular circumstance, the balance of the section is intended to ! apply and the section as a whole is intended to apply in other ! circumstances. ! ! It is not the purpose of this section to induce you to infringe any ! patents or other property right claims or to contest validity of any ! such claims; this section has the sole purpose of protecting the ! integrity of the free software distribution system, which is ! implemented by public license practices. Many people have made ! generous contributions to the wide range of software distributed ! through that system in reliance on consistent application of that ! system; it is up to the author/donor to decide if he or she is willing ! to distribute software through any other system and a licensee cannot ! impose that choice. ! ! This section is intended to make thoroughly clear what is believed to ! be a consequence of the rest of this License. ! ! 8. If the distribution and/or use of the Program is restricted in ! certain countries either by patents or by copyrighted interfaces, the ! original copyright holder who places the Program under this License ! may add an explicit geographical distribution limitation excluding ! those countries, so that distribution is permitted only in or among ! countries not thus excluded. In such case, this License incorporates ! the limitation as if written in the body of this License. ! ! 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. ! ! Each version is given a distinguishing version number. If the Program ! specifies a version number of this License which applies to it and "any ! later version", you have the option of following the terms and conditions ! either of that version or of any later version published by the Free Software ! Foundation. If the Program does not specify a version number of this License, ! you may choose any version ever published by the Free Software Foundation. ! ! 10. If you wish to incorporate parts of the Program into other free ! programs whose distribution conditions are different, write to the author to ! ask for permission. For software which is copyrighted by the Free Software ! Foundation, write to the Free Software Foundation; we sometimes make ! exceptions for this. Our decision will be guided by the two goals of ! preserving the free status of all derivatives of our free software and of ! promoting the sharing and reuse of software generally. ! ! NO WARRANTY ! ! 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR ! THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN ! OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE ! THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND ! FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND ! PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, ! YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. ! ! 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING ! WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR ! REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, ! INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING ! OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO ! LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR ! THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), ! EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH ! DAMAGES. ! ! END OF TERMS AND CONDITIONS ! */ ! static const char* Copyright = "(C) Copyright Michigan State University 2009, All rights reserved"; ! // Class: CNSCLAsciiSpectrumFormatter ! // does I/O to spectrum in a simple ASCII format. ! // The format is as follows: ! // line 1: "name" (dimensions) \n ! // line 2: date/time \n ! // line 3: 1.0\n [note 1.0 is file format version]. ! // line 4: spectrum type (SpecTcl coding)\n ! // line 5: List of parameters in spectrum.\n ! // line 6: "-------------------------------------------\n" ! // data lines: (coords) data ! // end line (-1 for all coords) -1 for data. ! // ! // Note that missing coordinates have data values of zero. ! // (zero supression). ! // Note: this format allows for several spectra to fit into a file as ! // well as for mixed spectrum other data files. ! // ! // // // Author: --- 1,3 ---- ! // // Author: *************** *** 304,307 **** --- 9,20 ---- // //////////////////////////.cpp file///////////////////////////////////////////////////// + /* + Change Log: + $Log$ + Revision 4.4 2003/04/19 00:11:50 ron-fox + Move to format version 2.0: Supply mapping information about the range covered by each axis of a spectrum. Note that reads are backwards compatible with version 1.0 and will default the range to 0 - nchans-1. + + */ + #include "NSCLAsciiSpectrumFormatter.h" #include <Spectrum.h> *************** *** 321,326 **** #include <ctype.h> ! static float FormatLevel = 1.0; static char* HeaderEnding= "--------------------------------------------\n"; --- 34,41 ---- #include <ctype.h> + static char* pCopyrightNotice = + "(C) Copyright 1999 NSCL, All rights reserved NSCLAsciiSpectrumFormatter.cpp \n"; ! static float FormatLevel = 2.0; static char* HeaderEnding= "--------------------------------------------\n"; *************** *** 451,502 **** DataType_t eDataType; // Data type of spectrum. vector<UInt_t> vDimensions; // # channels in each dimension. ! vector<UInt_t> vResolutions; // Spectrum channel resolutions. vector<string> vParameters; // Vector of parameter names. ReadHeader(rStream, Name, Date, nRevision, eSpecType, eDataType, ! vDimensions, vParameters); if(!CompatibleFormat(nRevision)) { throw CSpectrumFormatError(CSpectrumFormatError::IncompatibleFormat, "Reading NSCLAscii spectrum header"); } ! // Convert sizes into resolutions: ! // ! // Summary spectra need special handling since only the second ! // resolution is important >sigh< ! // if(eSpecType == keSummary) { ! Float_t res = (Float_t)vDimensions[1]; // Second res is important. ! #ifdef Darwin ! res = logb(res); ! #else ! res = log2f(res); ! #endif ! vResolutions.push_back((UInt_t) res); } else { ! for(UInt_t i = 0; i < vDimensions.size(); i++) { ! Float_t res = (Float_t)vDimensions[i]; ! #ifdef Darwin ! res = logb(res); ! #else ! res = log2f(res); ! #endif ! vResolutions.push_back((UInt_t)res); ! } } // // Create an appropriate spectrum: // - - // Create dummy vectors - vector<Float_t> vTransform; - vector<UInt_t> vChannels; - CSpectrumFactory Factory; Factory.ExceptionMode(kfFALSE); - /// - /// BUGBUGBUG - creation needs to be figured out and fixed!! - // CSpectrum* pSpectrum = Factory.CreateSpectrum(Name, eSpecType, eDataType, ! vParameters, vChannels); // Fill in the spectrum: // --- 166,212 ---- DataType_t eDataType; // Data type of spectrum. vector<UInt_t> vDimensions; // # channels in each dimension. ! // vector<UInt_t> vResolutions; // Spectrum channel resolutions. vector<string> vParameters; // Vector of parameter names. + vector<Float_t> vLows; + vector<Float_t> vHighs; ReadHeader(rStream, Name, Date, nRevision, eSpecType, eDataType, ! vDimensions, vParameters, vLows, vHighs); if(!CompatibleFormat(nRevision)) { throw CSpectrumFormatError(CSpectrumFormatError::IncompatibleFormat, "Reading NSCLAscii spectrum header"); } ! // Summary spectra are weird... Although 2-d, they only have a single ! // low/high specification, and that's determined by their ! // second dimension. Here we do that special case translation: ! ! vector<Float_t> createLows; ! vector<Float_t> createHighs; ! vector<UInt_t> createDims; ! if(eSpecType == keSummary) { ! UInt_t nChannels = vDimensions[1]; ! Float_t fLow = vLows[1]; ! Float_t fHigh = vHighs[1]; ! ! createDims.push_back(nChannels); ! createLows.push_back(fLow); ! createHighs.push_back(fHigh); ! } else { ! createDims = vDimensions; ! createLows = vLows; ! createHighs= vHighs; } // // Create an appropriate spectrum: // CSpectrumFactory Factory; Factory.ExceptionMode(kfFALSE); CSpectrum* pSpectrum = Factory.CreateSpectrum(Name, eSpecType, eDataType, ! vParameters, ! createDims, ! &createLows, ! &createHighs); // Fill in the spectrum: // *************** *** 584,587 **** --- 294,320 ---- } rStream << ")\n"; + // + // List of axis ranges. This is gotten from + // calling AxisToMappedParameter for each axis for channel 0 and size-1. + // + // First dimension is easy: + + Float_t xlow, xhigh; + UInt_t nChannels = rSpectrum.Dimension(0); // Everyone has this.. + xlow = rSpectrum.AxisToMapped(0, 0); + xhigh= rSpectrum.AxisToMapped(0, nChannels-1); + + rStream << '(' << xlow << " " << xhigh << ") "; + if(rSpectrum.Dimensionality() == 2) { + UInt_t nymap = 1; // By default second axis is second map.. + if(rSpectrum.getSpectrumType() == keG2D) { + nymap = Parameters.size(); // All x maps are first in gamma 2ds. + } + xlow = rSpectrum.AxisToMapped(nymap, 0); + xhigh= rSpectrum.AxisToMapped(nymap, rSpectrum.Dimension(1) - 1); + rStream << '(' << xlow << " " << xhigh << ")"; + } + rStream << "\n"; + // // This concludes the header: *************** *** 750,753 **** --- 483,527 ---- // Utility // + /*! + \par Description: + This function reads in a header for an ASCII formatted file, or + throws an exception if it is unabled to do so. + Two types of exceptions might be thrown, CSpectrumFormatError if + the header format doesn't make sense or alternatively, + CStreamIOError if there is an error reading the stream or unexpected + eof condition. + + \par Formal Parameters: + \param <TT>rStream (istream& [modified]):</TT> + Stream from which the data is taken. + \param <TT>rName: (string& [out]):</TT> + Name of the spectrum from the header. + \param <TT>rDate (string& [out]):</TT> + Date at which the spectrum was generated. The format + of this date string is somewhat operating system dependent. + however it is suitable for human consumption. + \param <TT>rRevisionLevel (Float_t [out]) </TT> + Revision level of the file format. + \param <TT>rSpecType (SpectrumType_t& [out])</TT> + Type of the spectrum (e.g. 1,2,s or b). + \param <TT>rDataType (DataType_t& [out])</TT> + Type of data being written (e.g. word). + \param <TT>rDimensions (vector<UInt_t>& [out])</TT> + The set of spectrum dimensions read from the header + for each axis of the histogram. + \param <TT>rParameters (vector<string>& [out])</TT> + The set of parameter names read from the file header. + \param <TT>rLows (vector<Float_t>& [out])</TT> + vector of spectrum low limits. This will be filled with + 0.0 for level 1 formatted files, otherwise read from the + Line 6 of the header. + \param <TT>rHighs (vector<Float_t>& [out]</TT> + Vector of spectrum high limits. This will be filled in + with dimension-1 for level 1 format otherwise read + from line 6 of the header. + \para Throws: + \throw CStreamIOError + \throw CSpectrumFormaterror + */ void CNSCLAsciiSpectrumFormatter::ReadHeader(istream& rStream, *************** *** 758,795 **** DataType_t& rDataType, vector<UInt_t>& rDimensions, ! vector<string>& rParameters) { - // This function reads in a header for an ASCII formatted file, or - // throws an exception if it is unabled to do so. - // Two types of exceptions might be thrown, CSpectrumFormatError if - // the header format doesn't make sense or alternatively, - // CStreamIOError if there is an error reading the stream or unexpected - // eof condition. - // - // Formal Parameters: - // istream& rStream: - // Stream from which the data is taken. - // string& rName: - // [out] - Name of the spectrum from the header. - // string& rDate: - // [out] - Date at which the spectrum was generated. The format - // of this date string is somewhat operating system dependent. - // however it is suitable for human consumSwriteption. - // Float_t& rRevisionLevel: - // [out] Revision level of the file format. - // SpectrumType_t& rSpecType: - // [out] Type of the spectrum (e.g. 1,2,s or b). - // DataType_t& rDataType: - // [out] Type of data being written (e.g. word). - // vector<UInt_t>& rDimensions: - // [out] The set of spectrum dimensions read from the header - // for each axis of the histogram. - // vector<string>& rParameters: - // [out] The set of parameter names read from the file header. - // Throws: - // CStreamIOError - // CSpectrumFormaterror ! // The header consists of 5 lines and a separator line: string idanddims; --- 532,541 ---- DataType_t& rDataType, vector<UInt_t>& rDimensions, ! vector<string>& rParameters, ! vector<Float_t>& rLows, ! vector<Float_t>& rHighs) { ! // The header consists of 6 lines and a separator line: string idanddims; *************** *** 818,823 **** ThrowStreamError(rStream, "Reading parameter list header line"); - separator = ReadLine(rStream); - ThrowStreamError(rStream, "Reading separator line"); --- 564,567 ---- *************** *** 888,891 **** --- 632,693 ---- rParameters[i].size()-2); } + + // if this is format 2.0 or greater, we have a new line to decode + // that has limit information for each axis: + + if(rRevisionLevel >= 2.0) { + + string LimitString = ReadLine(rStream); + ThrowStreamError(rStream, "Reading limit line (rev. 2.0)"); + + istrstream strLimits(LimitString.c_str()); + vector<string> Limits; + DecodeListOfParenLists(strLimits, Limits); + + if(Limits.size() != rDimensions.size()) { + throw + CSpectrumFormatError( + CSpectrumFormatError::InvalidHeader, + "Axis limit count differs from dimensionality"); + } + for(int i = 0; i < rDimensions.size(); i++ ) { // process limits. + vector<string> LimitPair; + istrstream strPair(Limits[i].c_str()); + DecodeParenList(strPair, LimitPair); + if(LimitPair.size() != 2) { + throw + CSpectrumFormatError( + CSpectrumFormatError::InvalidHeader, + "Axis limit pair is not a pair"); + } + Float_t fValue; + if(sscanf(LimitPair[0].c_str(), "%f", &fValue) != 1) { + throw + CSpectrumFormatError( + CSpectrumFormatError::InvalidHeader, + "Decoding an axis limit value."); + } + rLows.push_back(fValue); + if(sscanf(LimitPair[1].c_str(), "%f", &fValue) != 1) { + CSpectrumFormatError( + CSpectrumFormatError::InvalidHeader, + "Decoding an axis limit value."); + } + rHighs.push_back(fValue); + + } + + + + } else { // Older stuff, calculate limits: + for(int i = 0; i < rDimensions.size(); i++) { + rLows.push_back(0.0); + rHighs.push_back(((Float_t)rDimensions[i]) - 1.0); + } + } + + separator = ReadLine(rStream); + ThrowStreamError(rStream, "Reading separator line"); + } //////////////////////////////////////////////////////////////////////////// *************** *** 923,927 **** CNSCLAsciiSpectrumFormatter::CompatibleFormat(Float_t nFormat) { ! return (nFormat == FormatLevel); } //////////////////////////////////////////////////////////////////////// --- 725,729 ---- CNSCLAsciiSpectrumFormatter::CompatibleFormat(Float_t nFormat) { ! return (nFormat <= FormatLevel); // for now we're compatible with all older revs. } //////////////////////////////////////////////////////////////////////// *************** *** 1183,1184 **** --- 985,1038 ---- } + /*! + \para Functionality: + Decodes a list of parenthesized lists. e.g. a line that + looks like: + \verbatim + ( stuff ) ( stuff ) ... + \endverbatim + Each parenthesized list is stuffed into the output array, + parentheses and all. + Note that we don't support nested + lists. + + \para Parameters: + \param rStream + \param rList + + \para Throws: + \throw CStreamError + \throw CSpectrumFormatError + + */ + void + CNSCLAsciiSpectrumFormatter::DecodeListOfParenLists( + istream& rStream, + vector<string>& rList) + { + char paren = '('; + skipwhite(rStream); // Skip leading whitspace... + while(! rStream.eof()) { + char c; + string List; // One item. + rStream.read(&c,1); // Should be a paren... + ThrowStreamError(rStream,"Reading what should be a paren"); + if(c != paren) { + throw + CSpectrumFormatError(CSpectrumFormatError::FileFormatCorrupt, + "Looking for opening ("); + } + List += c; + while(1) { + rStream.read(&c,1); + ThrowStreamError(rStream,"Reading a list body"); + List += c; + if(c == ')') break; + + } + rList.push_back(List); + List = ""; + skipwhite(rStream); // Skip to next item or end. + } + } + |