aboutsummaryrefslogtreecommitdiff
path: root/CarpetAttic/CarpetIOFlexIO
diff options
context:
space:
mode:
authoreschnett <>2001-03-01 11:40:00 +0000
committereschnett <>2001-03-01 11:40:00 +0000
commit310f0ea48d18866b773136aed11200b6eda6378b (patch)
tree445d3e34ce8b89812994b6614f7bc9f4acbc7fe2 /CarpetAttic/CarpetIOFlexIO
Initial revision
darcs-hash:20010301114010-f6438-12fb8a9ffcc80e86c0a97e37b5b0dae0dbc59b79.gz
Diffstat (limited to 'CarpetAttic/CarpetIOFlexIO')
-rw-r--r--CarpetAttic/CarpetIOFlexIO/COPYING341
-rw-r--r--CarpetAttic/CarpetIOFlexIO/README8
-rw-r--r--CarpetAttic/CarpetIOFlexIO/configuration.ccl4
-rw-r--r--CarpetAttic/CarpetIOFlexIO/interface.ccl22
-rw-r--r--CarpetAttic/CarpetIOFlexIO/param.ccl91
-rw-r--r--CarpetAttic/CarpetIOFlexIO/schedule.ccl13
-rw-r--r--CarpetAttic/CarpetIOFlexIO/src/ioflexio.cc1095
-rw-r--r--CarpetAttic/CarpetIOFlexIO/src/ioflexio.h22
-rw-r--r--CarpetAttic/CarpetIOFlexIO/src/ioflexio.hh39
-rw-r--r--CarpetAttic/CarpetIOFlexIO/src/make.code.defn5
10 files changed, 1640 insertions, 0 deletions
diff --git a/CarpetAttic/CarpetIOFlexIO/COPYING b/CarpetAttic/CarpetIOFlexIO/COPYING
new file mode 100644
index 000000000..1942c4334
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/COPYING
@@ -0,0 +1,341 @@
+ 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
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) 19yy <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/CarpetAttic/CarpetIOFlexIO/README b/CarpetAttic/CarpetIOFlexIO/README
new file mode 100644
index 000000000..77a46db46
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/README
@@ -0,0 +1,8 @@
+Cactus Code Thorn CarpetIOFlexIO
+Authors : Erik Schnetter <schnetter@uni-tuebingen.de>
+CVS info : $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/README,v 1.4 2004/01/25 14:57:29 schnetter Exp $
+--------------------------------------------------------------------------
+
+Purpose of the thorn:
+
+This thorn provides FlexIO based file I/O for Carpet.
diff --git a/CarpetAttic/CarpetIOFlexIO/configuration.ccl b/CarpetAttic/CarpetIOFlexIO/configuration.ccl
new file mode 100644
index 000000000..01dc1a2cf
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/configuration.ccl
@@ -0,0 +1,4 @@
+# Configuration definitions for thorn CarpetIOFlexIO
+# $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/configuration.ccl,v 1.2 2003/11/19 17:12:20 schnetter Exp $
+
+Requires Thorns: Carpet CarpetLib FlexIO IOUtil
diff --git a/CarpetAttic/CarpetIOFlexIO/interface.ccl b/CarpetAttic/CarpetIOFlexIO/interface.ccl
new file mode 100644
index 000000000..103a9b594
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/interface.ccl
@@ -0,0 +1,22 @@
+# Interface definition for thorn CarpetIOFlexIO
+# $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/interface.ccl,v 1.9 2003/09/04 16:23:21 tradke Exp $
+
+implements: IOFlexIO
+
+uses include header: carpet.hh
+
+uses include header: bbox.hh
+uses include header: vect.hh
+
+uses include header: data.hh
+uses include header: gdata.hh
+
+uses include header: ggf.hh
+
+# FlexIO header files
+uses include header: IO.hh
+uses include header: IEEEIO.hh
+uses include header: HDFIO.hh
+uses include header: H5IO.hh
+uses include header: AMRwriter.hh
+uses include header: AmrGridReader.hh
diff --git a/CarpetAttic/CarpetIOFlexIO/param.ccl b/CarpetAttic/CarpetIOFlexIO/param.ccl
new file mode 100644
index 000000000..6c1f7cdca
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/param.ccl
@@ -0,0 +1,91 @@
+# Parameter definitions for thorn CarpetIOFlexIO
+# $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/param.ccl,v 1.9 2004/02/07 16:21:40 schnetter Exp $
+
+
+
+shares: IO
+
+USES STRING out_dir
+
+USES CCTK_INT out_every
+
+
+
+private:
+
+
+
+BOOLEAN verbose "Produce log output"
+{
+} "no"
+
+
+
+CCTK_STRING out3D_dir "Name of 3D FlexIO output directory, overrides out_dir" STEERABLE = ALWAYS
+{
+ .* :: "A regex which matches everything"
+} "."
+
+CCTK_STRING out3D_vars "Variables to output in 3D FlexIO file format" STEERABLE = ALWAYS
+{
+ .* :: "A regex which matches everything"
+} ""
+
+KEYWORD out3D_format "File format to use for 3D FlexIO output" STEERABLE = ALWAYS
+{
+ "IEEE" :: "IEEE, readable by the FlexIO library"
+ "HDF4" :: "The old HDF format"
+ "HDF5" :: "The new HDF format"
+} "HDF5"
+
+CCTK_STRING out3D_extension "File extension to use for 3D FlexIO output" STEERABLE = ALWAYS
+{
+ .* :: "A regex which matches everything"
+} ""
+
+CCTK_INT out3D_every "How often to do 3D FlexIO output, overrides out_every" STEERABLE = ALWAYS
+{
+ -1:* :: "Values <= 0 disable 3D output"
+} -1
+
+
+
+CCTK_INT out3D_max_num_lower_ghosts "Maximum number of lower ghost zones that are output" STEERABLE = ALWAYS
+{
+ -1 :: "output all ghost zones"
+ 0:* :: "output that many ghost zones"
+} -1
+
+CCTK_INT out3D_max_num_upper_ghosts "Maximum number of upper ghost zones that are output" STEERABLE = ALWAYS
+{
+ -1 :: "output all ghost zones"
+ 0:* :: "output that many ghost zones"
+} -1
+
+BOOLEAN out3D_output_outer_boundary "Output all of the outer boundary ghost zones even if not all ghost zones are output" STEERABLE = ALWAYS
+{
+} "yes"
+
+
+
+CCTK_STRING in3D_dir "Name of 3D FlexIO input directory" STEERABLE = ALWAYS
+{
+ .* :: "A regex which matches everything"
+} "."
+
+CCTK_STRING in3D_vars "Variables to input in 3D FlexIO file format" STEERABLE = ALWAYS
+{
+ .* :: "A regex which matches everything"
+} ""
+
+KEYWORD in3D_format "File format to use for 3D FlexIO input" STEERABLE = ALWAYS
+{
+ "IEEE" :: "IEEE, readable by the FlexIO library"
+ "HDF4" :: "The old HDF format"
+ "HDF5" :: "The new HDF format"
+} "HDF5"
+
+CCTK_STRING in3D_extension "File extension to use for 3D FlexIO input" STEERABLE = ALWAYS
+{
+ .* :: "A regex which matches everything"
+} ""
diff --git a/CarpetAttic/CarpetIOFlexIO/schedule.ccl b/CarpetAttic/CarpetIOFlexIO/schedule.ccl
new file mode 100644
index 000000000..39a3f7ad5
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/schedule.ccl
@@ -0,0 +1,13 @@
+# Schedule definitions for thorn CarpetIOFlexIO
+# $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/schedule.ccl,v 1.6 2003/11/05 16:18:37 schnetter Exp $
+
+schedule CarpetIOFlexIOStartup at STARTUP after IOUtil_Startup
+{
+ LANG: C
+} "Startup routine"
+
+schedule CarpetIOFlexIOReadData at INITIAL
+{
+ LANG: C
+ OPTIONS: global
+} "Read initial data from file"
diff --git a/CarpetAttic/CarpetIOFlexIO/src/ioflexio.cc b/CarpetAttic/CarpetIOFlexIO/src/ioflexio.cc
new file mode 100644
index 000000000..1ce401607
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/src/ioflexio.cc
@@ -0,0 +1,1095 @@
+#include <assert.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <algorithm>
+#include <fstream>
+#include <sstream>
+#include <vector>
+
+#include "cctk.h"
+#include "cctk_Parameters.h"
+
+extern "C" {
+ static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/src/ioflexio.cc,v 1.46 2004/03/08 09:12:29 schnetter Exp $";
+ CCTK_FILEVERSION(Carpet_CarpetIOFlexIO_ioflexio_cc);
+}
+
+#include "AMRwriter.hh"
+#include "AmrGridReader.hh"
+#ifdef HDF4
+# include "HDFIO.hh"
+#endif
+#ifdef HDF5
+# include "H5IO.hh"
+#endif
+#include "IEEEIO.hh"
+#include "IO.hh"
+
+// Hack to stop FlexIO data type clash with LAM MPI
+#undef BYTE
+#undef CHAR
+
+#include "CactusBase/IOUtil/src/ioGH.h"
+#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h"
+
+#include "bbox.hh"
+#include "data.hh"
+#include "gdata.hh"
+#include "ggf.hh"
+#include "vect.hh"
+
+#include "carpet.hh"
+
+#include "ioflexio.hh"
+
+
+
+namespace CarpetIOFlexIO {
+
+ using namespace std;
+ using namespace Carpet;
+
+
+
+ // Variable definitions
+ int GHExtension;
+ int IOMethod;
+ vector<bool> do_truncate;
+ vector<vector<vector<int> > > last_output; // [ml][rl][var]
+
+
+
+ static const char* GetStringParameter (const char* const parametername,
+ const char* const fallback);
+ static int GetIntParameter (const char* const parametername, int fallback);
+ static bool CheckForVariable (const cGH* const cgh,
+ const char* const varlist, const int vindex);
+ static void SetFlag (int index, const char* optstring, void* arg);
+
+ static int ReadAttribute (IObase* reader, const char* name,
+ int& value);
+ static int ReadAttribute (IObase* reader, const char* name,
+ int* values, int nvalues);
+ static int ReadAttribute (IObase* reader, const char* name,
+ CCTK_REAL& value);
+ static int ReadAttribute (IObase* reader, const char* name,
+ CCTK_REAL* values, int nvalues);
+ static int ReadAttribute (IObase* reader, const char* name,
+ char& value);
+ static int ReadAttribute (IObase* reader, const char* name,
+ char*& values);
+ static int ReadAttribute (IObase* reader, const char* name,
+ char* values, int nvalues);
+
+ static void WriteAttribute (IObase* writer, const char* name,
+ int value);
+ static void WriteAttribute (IObase* writer, const char* name,
+ const int* values, int nvalues);
+ static void WriteAttribute (IObase* writer, const char* name,
+ CCTK_REAL value);
+ static void WriteAttribute (IObase* writer, const char* name,
+ const CCTK_REAL* values, int nvalues);
+ static void WriteAttribute (IObase* writer, const char* name,
+ char value);
+ static void WriteAttribute (IObase* writer, const char* name,
+ const char* values);
+ static void WriteAttribute (IObase* writer, const char* name,
+ const char* values, int nvalues);
+
+
+
+ int CarpetIOFlexIOStartup ()
+ {
+ int ierr;
+
+ CCTK_RegisterBanner ("AMR 3D FlexIO I/O provided by CarpetIOFlexIO");
+
+ GHExtension = CCTK_RegisterGHExtension ("CarpetIOFlexIO");
+ CCTK_RegisterGHExtensionSetupGH (GHExtension, SetupGH);
+
+ IOMethod = CCTK_RegisterIOMethod ("CarpetIOFlexIO");
+ CCTK_RegisterIOMethodOutputGH (IOMethod, OutputGH);
+ CCTK_RegisterIOMethodOutputVarAs (IOMethod, OutputVarAs);
+ CCTK_RegisterIOMethodTimeToOutput (IOMethod, TimeToOutput);
+ CCTK_RegisterIOMethodTriggerOutput (IOMethod, TriggerOutput);
+
+ ierr = IOUtil_RegisterRecover ("CarpetIOFlexIO", Recover);
+ assert (! ierr);
+
+ return 0;
+ }
+
+
+
+ void* SetupGH (tFleshConfig* const fc,
+ const int convLevel, cGH* const cgh)
+ {
+ DECLARE_CCTK_PARAMETERS;
+
+ // Truncate all files if this is not a restart
+ do_truncate.resize(CCTK_NumVars(), true);
+
+ // No iterations have yet been output
+ last_output.resize(mglevels);
+ for (int ml=0; ml<mglevels; ++ml) {
+ last_output.at(ml).resize(maxreflevels);
+ for (int rl=0; rl<maxreflevels; ++rl) {
+ last_output.at(ml).at(rl).resize(CCTK_NumVars(), INT_MIN);
+ }
+ }
+
+ // We register only once, ergo we get only one handle. We store
+ // that statically, so there is no need to pass anything to
+ // Cactus.
+ return 0;
+ }
+
+
+
+ int OutputGH (const cGH* const cgh) {
+ for (int vindex=0; vindex<CCTK_NumVars(); ++vindex) {
+ if (TimeToOutput(cgh, vindex)) {
+ TriggerOutput(cgh, vindex);
+ }
+ }
+ return 0;
+ }
+
+
+
+ int OutputVarAs (const cGH* const cgh, const char* const varname,
+ const char* const alias) {
+ DECLARE_CCTK_PARAMETERS;
+
+ const int n = CCTK_VarIndex(varname);
+ assert (n>=0 && n<CCTK_NumVars());
+ const int group = CCTK_GroupIndexFromVarI (n);
+ assert (group>=0 && group<(int)Carpet::arrdata.size());
+ const int n0 = CCTK_FirstVarIndexI(group);
+ assert (n0>=0 && n0<CCTK_NumVars());
+ const int var = n - n0;
+ assert (var>=0 && var<CCTK_NumVars());
+ const int tl = 0;
+
+ // Check for storage
+ if (! CCTK_QueryGroupStorageI(cgh, group)) {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Cannot output variable \"%s\" because it has no storage",
+ varname);
+ return 0;
+ }
+
+ const int grouptype = CCTK_GroupTypeI(group);
+ switch (grouptype) {
+ case CCTK_SCALAR:
+ case CCTK_ARRAY:
+ assert (do_global_mode);
+ break;
+ case CCTK_GF:
+ /* do nothing */
+ break;
+ default:
+ assert (0);
+ }
+ const int rl = grouptype==CCTK_GF ? reflevel : 0;
+
+ // Get grid hierarchy extentsion from IOUtil
+ const ioGH * const iogh = (const ioGH *)CCTK_GHExtension (cgh, "IO");
+ assert (iogh);
+
+ // Create the output directory
+ const char* const myoutdir = GetStringParameter("out3D_dir", out_dir);
+ if (CCTK_MyProc(cgh)==0) {
+ CCTK_CreateDirectory (0755, myoutdir);
+ }
+
+ // Invent a file name
+ const char* extension = 0;
+ if (CCTK_Equals(out3D_format, "IEEE")) {
+ extension = ".raw";
+#ifdef HDF4
+ } else if (CCTK_Equals(out3D_format, "HDF4")) {
+ extension = ".hdf";
+#endif
+#ifdef HDF5
+ } else if (CCTK_Equals(out3D_format, "HDF5")) {
+ extension = ".h5";
+#endif
+ } else {
+ assert (0);
+ }
+ extension = GetStringParameter ("out3D_extension", extension);
+
+ ostringstream filenamebuf;
+ filenamebuf << myoutdir << "/" << alias << extension;
+ string filenamestr = filenamebuf.str();
+ const char * const filename = filenamestr.c_str();
+
+ IObase* writer = 0;
+ AMRwriter* amrwriter = 0;
+
+ // Write the file only on the root processor
+ if (CCTK_MyProc(cgh)==0) {
+
+ // If this is the first time, then create and truncate the file
+ if (do_truncate.at(n)) {
+ struct stat fileinfo;
+ if (! iogh->recovered
+ || stat(filename, &fileinfo)!=0) {
+ writer = 0;
+ if (CCTK_Equals(out3D_format, "IEEE")) {
+ writer = new IEEEIO(filename, IObase::Create);
+#ifdef HDF4
+ } else if (CCTK_Equals(out3D_format, "HDF4")) {
+ writer = new HDFIO(filename, IObase::Create);
+#endif
+#ifdef HDF5
+ } else if (CCTK_Equals(out3D_format, "HDF5")) {
+ writer = new H5IO(filename, IObase::Create);
+#endif
+ } else {
+ assert (0);
+ }
+ delete writer;
+ writer = 0;
+ }
+ }
+
+ // Open the file
+ if (CCTK_Equals(out3D_format, "IEEE")) {
+ writer = new IEEEIO(filename, IObase::Append);
+#ifdef HDF4
+ } else if (CCTK_Equals(out3D_format, "HDF4")) {
+ writer = new HDFIO(filename, IObase::Append);
+#endif
+#ifdef HDF5
+ } else if (CCTK_Equals(out3D_format, "HDF5")) {
+ writer = new H5IO(filename, IObase::Append);
+#endif
+ } else {
+ assert (0);
+ }
+ assert (writer->isValid());
+ amrwriter = new AMRwriter(*writer);
+
+ // Set datatype
+ assert (CCTK_VarTypeI(n) == CCTK_VARIABLE_REAL8
+ || (sizeof(CCTK_REAL) == sizeof(CCTK_REAL8)
+ && CCTK_VarTypeI(n) == CCTK_VARIABLE_REAL));
+ // TODO: Set datatype correctly
+ amrwriter->setType (IObase::Float64);
+
+ const int gpdim = CCTK_GroupDimI(group);
+
+ // Set coordinate information
+ double origin[dim], delta[dim], timestep;
+ for (int d=0; d<dim; ++d) {
+ origin[d] = cgh->cctk_origin_space[d];
+ delta[d] = cgh->cctk_delta_space[d];
+ }
+ timestep = cgh->cctk_delta_time;
+ amrwriter->setTopLevelParameters
+ (gpdim, origin, delta, timestep, maxreflevels);
+
+ // Set refinement information
+ int interlevel_timerefinement;
+ int interlevel_spacerefinement[dim];
+ int initial_gridplacementrefinement[dim];
+ interlevel_timerefinement = reffact;
+ for (int d=0; d<dim; ++d) {
+ interlevel_spacerefinement[d] = reffact;
+ initial_gridplacementrefinement[d] = 1;
+ }
+ amrwriter->setRefinement
+ (interlevel_timerefinement, interlevel_spacerefinement,
+ initial_gridplacementrefinement);
+
+ // Set level
+ amrwriter->setLevel (rl);
+
+ // Set current time
+ amrwriter->setTime (cgh->cctk_iteration);
+ }
+
+ // Traverse all components
+ BEGIN_MAP_LOOP(cgh, grouptype) {
+ BEGIN_COMPONENT_LOOP(cgh, grouptype) {
+
+ const ggf<dim>* ff = 0;
+
+ assert (var < (int)arrdata.at(group).at(Carpet::map).data.size());
+ ff = (ggf<dim>*)arrdata.at(group).at(Carpet::map).data.at(var);
+
+ const gdata<dim>* const data
+ = (*ff) (tl, rl, component, mglevel);
+
+ // Make temporary copy on processor 0
+ bbox<int,dim> ext = data->extent();
+ vect<int,dim> lo = ext.lower();
+ vect<int,dim> hi = ext.upper();
+ vect<int,dim> str = ext.stride();
+
+ // Ignore ghost zones if desired
+ for (int d=0; d<dim; ++d) {
+ const int max_lower_ghosts = (cgh->cctk_bbox[2*d ] && out3D_output_outer_boundary) ? -1 : out3D_max_num_lower_ghosts;
+ const int max_upper_ghosts = (cgh->cctk_bbox[2*d+1] && out3D_output_outer_boundary) ? -1 : out3D_max_num_upper_ghosts;
+
+ const int num_lower_ghosts = max_lower_ghosts == -1 ? cgh->cctk_nghostzones[d] : min(out3D_max_num_lower_ghosts, cgh->cctk_nghostzones[d]);
+ const int num_upper_ghosts = max_upper_ghosts == -1 ? cgh->cctk_nghostzones[d] : min(out3D_max_num_upper_ghosts, cgh->cctk_nghostzones[d]);
+
+ lo[d] += (cgh->cctk_nghostzones[d] - num_lower_ghosts) * str[d];
+ hi[d] -= (cgh->cctk_nghostzones[d] - num_upper_ghosts) * str[d];
+ }
+
+ ext = bbox<int,dim>(lo,hi,str);
+
+ gdata<dim>* const tmp = data->make_typed (n);
+ tmp->allocate (ext, 0);
+ for (comm_state<dim> state; !state.done(); state.step()) {
+ tmp->copy_from (state, data, ext);
+ }
+
+ // Write data
+ if (CCTK_MyProc(cgh)==0) {
+ int origin[dim], dims[dim];
+ for (int d=0; d<dim; ++d) {
+ origin[d] = (ext.lower() / ext.stride())[d];
+ dims[d] = (ext.shape() / ext.stride())[d];
+ }
+ amrwriter->write (origin, dims, (void*)tmp->storage());
+
+ // Write some additional attributes
+
+ // Legacy arguments
+ {
+ char * fullname = CCTK_FullName(n);
+ assert (fullname);
+ WriteAttribute (writer, "name", fullname);
+ free (fullname);
+ }
+
+ // Group arguments
+ WriteAttribute (writer, "group_version", 1);
+ {
+ char * fullname = CCTK_FullName(n);
+ assert (fullname);
+ WriteAttribute (writer, "group_fullname", fullname);
+ free (fullname);
+ }
+ WriteAttribute (writer, "group_varname", CCTK_VarName(n));
+ {
+ char * groupname = CCTK_GroupName(group);
+ assert (groupname);
+ WriteAttribute (writer, "group_groupname", groupname);
+ free (groupname);
+ }
+ switch (grouptype) {
+ case CCTK_GF:
+ WriteAttribute (writer, "group_grouptype", "CCTK_GF");
+ break;
+ case CCTK_ARRAY:
+ WriteAttribute (writer, "group_grouptype", "CCTK_ARRAY");
+ break;
+ case CCTK_SCALAR:
+ WriteAttribute (writer, "group_grouptype", "CCTK_SCALAR");
+ break;
+ default:
+ assert (0);
+ }
+ WriteAttribute (writer, "group_dim", CCTK_GroupDimI(group));
+ WriteAttribute (writer, "group_timelevel", tl);
+ WriteAttribute (writer, "group_numtimelevels", CCTK_NumTimeLevelsI(group));
+
+ // Cactus arguments
+ WriteAttribute (writer, "cctk_version", 1);
+ WriteAttribute (writer, "cctk_dim", cgh->cctk_dim);
+ WriteAttribute (writer, "cctk_iteration", cgh->cctk_iteration);
+// TODO: disable temporarily
+// WriteAttribute (writer, "cctk_nmaps", cgh->cctk_nmaps);
+// WriteAttribute (writer, "cctk_map", cgh->cctk_map);
+ WriteAttribute (writer, "cctk_gsh", cgh->cctk_gsh, dim);
+ WriteAttribute (writer, "cctk_lsh", cgh->cctk_lsh, dim);
+ WriteAttribute (writer, "cctk_lbnd", cgh->cctk_lbnd, dim);
+ WriteAttribute (writer, "cctk_delta_time", cgh->cctk_delta_time);
+ WriteAttribute (writer, "cctk_delta_space", cgh->cctk_delta_space, dim);
+ WriteAttribute (writer, "cctk_origin_space", cgh->cctk_origin_space, dim);
+ WriteAttribute (writer, "cctk_bbox", cgh->cctk_bbox, 2*dim);
+ WriteAttribute (writer, "cctk_levfac", cgh->cctk_levfac, dim);
+ WriteAttribute (writer, "cctk_levoff", cgh->cctk_levoff, dim);
+ WriteAttribute (writer, "cctk_levoffdenom", cgh->cctk_levoffdenom, dim);
+ WriteAttribute (writer, "cctk_timefac", cgh->cctk_timefac);
+ WriteAttribute (writer, "cctk_convlevel", cgh->cctk_convlevel);
+ WriteAttribute (writer, "cctk_convfac", cgh->cctk_convfac);
+ WriteAttribute (writer, "cctk_nghostzones", cgh->cctk_nghostzones, dim);
+ WriteAttribute (writer, "cctk_time", cgh->cctk_time);
+
+ // Carpet arguments
+ WriteAttribute (writer, "carpet_version", 1);
+ WriteAttribute (writer, "carpet_dim", dim);
+ WriteAttribute (writer, "carpet_basemglevel", basemglevel);
+ WriteAttribute (writer, "carpet_mglevel", mglevel);
+ WriteAttribute (writer, "carpet_mglevels", mglevels);
+ WriteAttribute (writer, "carpet_mgface", mgfact);
+ WriteAttribute (writer, "carpet_reflevel", reflevel);
+ WriteAttribute (writer, "carpet_reflevels", reflevels);
+ WriteAttribute (writer, "carpet_reffact", reffact);
+ WriteAttribute (writer, "carpet_map", Carpet::map);
+ WriteAttribute (writer, "carpet_maps", maps);
+ WriteAttribute (writer, "carpet_component", component);
+ WriteAttribute (writer, "carpet_components", vhh.at(Carpet::map)->components(reflevel));
+ }
+
+ // Delete temporary copy
+ delete tmp;
+
+ } END_COMPONENT_LOOP;
+ } END_MAP_LOOP;
+
+ // Close the file
+ if (CCTK_MyProc(cgh)==0) {
+ delete amrwriter;
+ amrwriter = 0;
+ delete writer;
+ writer = 0;
+ }
+
+ // Don't truncate again
+ do_truncate.at(n) = false;
+
+ return 0;
+ }
+
+
+
+ int TimeToOutput (const cGH* const cctkGH, const int vindex) {
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ assert (vindex>=0 && vindex<CCTK_NumVars());
+
+ const int grouptype = CCTK_GroupTypeFromVarI(vindex);
+ switch (grouptype) {
+ case CCTK_SCALAR:
+ case CCTK_ARRAY:
+ if (! do_global_mode) return 0;
+ break;
+ case CCTK_GF:
+ /* do nothing */
+ break;
+ default:
+ assert (0);
+ }
+
+ const int myoutevery = GetIntParameter("out3D_every", out_every);
+
+ if (myoutevery < 0) {
+ // Nothing should be output at all
+ return 0;
+ }
+
+ if (cctk_iteration % myoutevery != 0) {
+ // Nothing should be output during this iteration
+ return 0;
+ }
+
+ if (! CheckForVariable(cctkGH, GetStringParameter("out3D_vars",""), vindex)) {
+ // This variable should not be output
+ return 0;
+ }
+
+ if (last_output.at(mglevel).at(reflevel).at(vindex) == cctk_iteration) {
+ // Has already been output during this iteration
+ char* varname = CCTK_FullName(vindex);
+ CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Skipping output for variable \"%s\", because this variable "
+ "has already been output during the current iteration -- "
+ "probably via a trigger during the analysis stage",
+ varname);
+ free (varname);
+ return 0;
+ }
+
+ assert (last_output.at(mglevel).at(reflevel).at(vindex) < cctk_iteration);
+
+ // Should be output during this iteration
+ return 1;
+ }
+
+
+
+ int TriggerOutput (const cGH* const cgh, const int vindex) {
+ assert (vindex>=0 && vindex<CCTK_NumVars());
+
+ char* varname = CCTK_FullName(vindex);
+ const int retval = OutputVarAs (cgh, varname, CCTK_VarName(vindex));
+ free (varname);
+
+ last_output.at(mglevel).at(reflevel).at(vindex) = cgh->cctk_iteration;
+
+ return retval;
+ }
+
+
+
+ int InputGH (const cGH* const cgh) {
+ int retval = 0;
+ for (int vindex=0; vindex<CCTK_NumVars(); ++vindex) {
+ if (CheckForVariable(cgh, GetStringParameter("in3D_vars",""), vindex)) {
+ char* varname = CCTK_FullName(vindex);
+ retval = InputVarAs (cgh, varname, CCTK_VarName(vindex));
+ free (varname);
+ if (retval != 0) return retval;
+ }
+ }
+ return retval;
+ }
+
+
+
+ int InputVarAs (const cGH* const cgh, const char* const varname,
+ const char* const alias) {
+ DECLARE_CCTK_PARAMETERS;
+
+ const int n = CCTK_VarIndex(varname);
+ assert (n>=0 && n<CCTK_NumVars());
+ const int group = CCTK_GroupIndexFromVarI (n);
+ assert (group>=0 && group<(int)Carpet::arrdata.size());
+ const int n0 = CCTK_FirstVarIndexI(group);
+ assert (n0>=0 && n0<CCTK_NumVars());
+ const int var = n - n0;
+ assert (var>=0 && var<CCTK_NumVars());
+ const int tl = 0;
+
+ // Check for storage
+ if (! CCTK_QueryGroupStorageI(cgh, group)) {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Cannot input variable \"%s\" because it has no storage",
+ varname);
+ return 0;
+ }
+
+ const int grouptype = CCTK_GroupTypeI(group);
+ const int rl = grouptype==CCTK_GF ? reflevel : 0;
+
+ // Find the input directory
+ const char* myindir = GetStringParameter("in3D_dir", ".");
+
+ // Invent a file name
+ const char* extension = 0;
+ if (CCTK_Equals(in3D_format, "IEEE")) {
+ extension = ".raw";
+#ifdef HDF4
+ } else if (CCTK_Equals(in3D_format, "HDF4")) {
+ extension = ".hdf";
+#endif
+#ifdef HDF5
+ } else if (CCTK_Equals(in3D_format, "HDF5")) {
+ extension = ".h5";
+#endif
+ } else {
+ assert (0);
+ }
+ extension = GetStringParameter ("in3D_extension", extension);
+
+ ostringstream filenamebuf;
+ filenamebuf << myindir << "/" << alias << extension;
+ string filenamestr = filenamebuf.str();
+ const char * const filename = filenamestr.c_str();
+
+ IObase* reader = 0;
+ AmrGridReader* amrreader = 0;
+ int ndatasets = -1;
+
+ const int gpdim = CCTK_GroupDimI(group);
+
+ int rank;
+ int dims[dim];
+ int nbytes;
+
+ // Read the file only on the root processor
+ if (CCTK_MyProc(cgh)==0) {
+
+ // Open the file
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Opening file \"%s\"", filename);
+ if (CCTK_Equals(in3D_format, "IEEE")) {
+ reader = new IEEEIO(filename, IObase::Read);
+#ifdef HDF4
+ } else if (CCTK_Equals(in3D_format, "HDF4")) {
+ reader = new HDFIO(filename, IObase::Read);
+#endif
+#ifdef HDF5
+ } else if (CCTK_Equals(in3D_format, "HDF5")) {
+ reader = new H5IO(filename, IObase::Read);
+#endif
+ } else {
+ assert (0);
+ }
+ if (!reader->isValid()) {
+ CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Could not open file \"%s\" for reading", filename);
+ }
+ assert (reader->isValid());
+
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Reading AMR info");
+ amrreader = new AmrGridReader(*reader);
+
+ // Read information about dataset
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Reading dataset info");
+ IObase::DataType numbertype;
+ reader->readInfo (numbertype, rank, dims);
+ nbytes = IObase::nBytes(numbertype,rank,dims);
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "type=%d rank=%d dims=[%d,%d,%d] nbytes=%d", (int)numbertype, rank, dims[0], dims[1], dims[2], nbytes);
+
+ // Check rank
+ assert (rank==gpdim);
+
+ // Check datatype
+ // TODO: Check datatype correctly
+ assert (CCTK_VarTypeI(n) == CCTK_VARIABLE_REAL8
+ || (sizeof(CCTK_REAL) == sizeof(CCTK_REAL8)
+ && CCTK_VarTypeI(n) == CCTK_VARIABLE_REAL));
+
+ // TODO: check grid spacing
+
+ // Number of datasets
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Reading number of datasets");
+ ndatasets = reader->nDatasets();
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "ndatasets=%d", ndatasets);
+ assert (ndatasets>=0);
+ }
+
+ // Broadcast rank, dimensions, and nbytes
+ MPI_Bcast (&rank, 1, MPI_INT, 0, dist::comm);
+ assert (rank>=1);
+ MPI_Bcast (&dims, rank, MPI_INT, 0, dist::comm);
+ for (int d=0; d<rank; ++d) assert (dims[d]>=0);
+ MPI_Bcast (&nbytes, 1, MPI_INT, 0, dist::comm);
+ assert (nbytes>=0);
+
+ // Broadcast number of datasets
+ MPI_Bcast (&ndatasets, 1, MPI_INT, 0, dist::comm);
+ assert (ndatasets>=0);
+
+ // Read some datasets
+ bool did_read_something = false;
+ vector<ibset> regions_read(Carpet::maps);
+ for (int dataset=0; dataset<ndatasets; ++dataset) {
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Handling dataset #%d", dataset);
+
+ // Read grid
+ AmrGrid* amrgrid = 0;
+ int want_dataset;
+ int amr_level;
+ int amr_origin[dim];
+ int amr_dims[dim];
+
+ if (CCTK_MyProc(cgh)==0) {
+
+ // Read data
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Reading AMR data");
+ amrgrid = amrreader->getGrid(dataset);
+ assert (amrgrid!=0);
+ assert (amrgrid->data!=0);
+
+ {
+ char * name;
+ ReadAttribute (reader, "name", name);
+ if (verbose) {
+ if (name) {
+ CCTK_VInfo (CCTK_THORNSTRING, "Dataset name is \"%s\"", name);
+ }
+ }
+ want_dataset = name && CCTK_EQUALS(name, varname);
+ free (name);
+ }
+
+ // If iorigin attribute is absent, assume file has unigrid
+ // data.
+ {
+ IObase::DataType atype;
+ int alength;
+ if (reader->readAttributeInfo("iorigin", atype, alength) < 0) {
+ amrgrid->level = 0;
+ for (int d=0; d<gpdim; ++d) {
+ amrgrid->iorigin[d] = 0;
+ }
+ }
+ }
+
+ amr_level = amrgrid->level;
+ for (int d=0; d<gpdim; ++d) {
+ amr_origin[d] = amrgrid->iorigin[d];
+ amr_dims[d] = amrgrid->dims[d];
+ }
+ for (int d=gpdim; d<dim; ++d) {
+ amr_origin[d] = 0;
+ amr_dims[d] = 1;
+ }
+
+ } // MyProc == 0
+
+ MPI_Bcast (&want_dataset, 1, MPI_INT, 0, dist::comm);
+ MPI_Bcast (&amr_level, 1, MPI_INT, 0, dist::comm);
+ MPI_Bcast (amr_origin, dim, MPI_INT, 0, dist::comm);
+ MPI_Bcast (amr_dims, dim, MPI_INT, 0, dist::comm);
+
+ if (want_dataset && amr_level == reflevel) {
+ did_read_something = true;
+
+ // Traverse all components on all levels
+ BEGIN_MAP_LOOP(cgh, grouptype) {
+ BEGIN_COMPONENT_LOOP(cgh, grouptype) {
+
+ ggf<dim>* ff = 0;
+
+ assert (var < (int)arrdata.at(group).at(Carpet::map).data.size());
+ ff = (ggf<dim>*)arrdata.at(group).at(Carpet::map).data.at(var);
+
+ gdata<dim>* const data = (*ff) (tl, rl, component, mglevel);
+
+ // Create temporary data storage on processor 0
+ const vect<int,dim> str
+ = vect<int,dim>(maxreflevelfact/reflevelfact);
+ const vect<int,dim> lb = vect<int,dim>::ref(amr_origin) * str;
+ const vect<int,dim> ub
+ = lb + (vect<int,dim>::ref(amr_dims) - 1) * str;
+ const bbox<int,dim> ext(lb,ub,str);
+
+ gdata<dim>* const tmp = data->make_typed (n);
+
+ if (CCTK_MyProc(cgh)==0) {
+ tmp->allocate (ext, 0, amrgrid->data);
+ } else {
+ tmp->allocate (ext, 0);
+ }
+
+ // Initialise with what is found in the file -- this does
+ // not guarantee that everything is initialised.
+ const bbox<int,dim> overlap = tmp->extent() & data->extent();
+ regions_read.at(Carpet::map) |= overlap;
+
+ // Copy into grid function
+ for (comm_state<dim> state; !state.done(); state.step()) {
+ data->copy_from (state, tmp, overlap);
+ }
+
+ // Delete temporary copy
+ delete tmp;
+
+ } END_COMPONENT_LOOP;
+ } END_MAP_LOOP;
+
+ } // if want_dataset && level == reflevel
+
+ if (CCTK_MyProc(cgh)==0) {
+ free (amrgrid->data);
+ free (amrgrid);
+ amrgrid = 0;
+ }
+
+ } // loop over datasets
+
+ // Close the file
+ if (CCTK_MyProc(cgh)==0) {
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Deleting AMR info");
+ delete amrreader;
+
+ amrreader = 0;
+ if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Closing file");
+ delete reader;
+ reader = 0;
+ }
+
+ // Was everything initialised?
+ if (did_read_something) {
+ for (int m=0; m<Carpet::maps; ++m) {
+ dh<dim>& thedd = *arrdata.at(group).at(m).dd;
+ ibset all_exterior;
+ for (size_t c=0; c<thedd.boxes.at(rl).size(); ++c) {
+ all_exterior |= thedd.boxes.at(rl).at(c).at(mglevel).exterior;
+ }
+ if (regions_read.at(m) != all_exterior) {
+ CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Variable \"%s\" could not be initialised from file \"%s\" -- the file contains data for this variable, but the grids therein are too small",
+ varname, filename);
+ }
+ }
+ } // if did_read_something
+
+ return did_read_something ? 0 : -1;
+ }
+
+
+
+ /** returns the number of recovered variables */
+ int Recover (cGH* const cgh, const char *basefilename,
+ const int called_from)
+ {
+ assert (cgh);
+ assert (basefilename);
+ assert (called_from == CP_INITIAL_DATA
+ || called_from == CP_EVOLUTION_DATA
+ || called_from == CP_RECOVER_PARAMETERS
+ || called_from == CP_RECOVER_DATA
+ || called_from == FILEREADER_DATA);
+
+ // the other modes are not supported yet
+ assert (called_from == FILEREADER_DATA);
+
+ const ioGH * const iogh = (const ioGH *) CCTK_GHExtension (cgh, "IO");
+ assert (iogh);
+
+ int num_vars_read = 0;
+ assert (iogh->do_inVars);
+ for (int n=0; n<CCTK_NumVars(); ++n) {
+ if (iogh->do_inVars[n]) {
+ char * const fullname = CCTK_FullName(n);
+ assert (fullname);
+ const int ierr = InputVarAs (cgh, fullname, basefilename);
+ if (! ierr) {
+ ++ num_vars_read;
+ }
+ free (fullname);
+ }
+ }
+
+ return num_vars_read;
+ }
+
+
+
+ int CarpetIOFlexIOReadData (CCTK_ARGUMENTS)
+ {
+ DECLARE_CCTK_ARGUMENTS;
+ return InputGH(cctkGH);
+ }
+
+
+
+ const char* GetStringParameter (const char* const parametername,
+ const char* const fallback)
+ {
+ if (CCTK_ParameterQueryTimesSet (parametername, CCTK_THORNSTRING) > 0) {
+ int ptype;
+ const char* const* const ppval = (const char* const*)CCTK_ParameterGet
+ (parametername, CCTK_THORNSTRING, &ptype);
+ assert (ppval);
+ const char* const pval = *ppval;
+ assert (ptype == PARAMETER_STRING);
+ return pval;
+ }
+
+ return fallback;
+ }
+
+
+
+ int GetIntParameter (const char* const parametername, int fallback)
+ {
+ if (CCTK_ParameterQueryTimesSet (parametername, CCTK_THORNSTRING) > 0) {
+ int ptype;
+ const int* const ppval = (const int*)CCTK_ParameterGet
+ (parametername, CCTK_THORNSTRING, &ptype);
+ assert (ppval);
+ const int pval = *ppval;
+ assert (ptype == PARAMETER_INT);
+ return pval;
+ }
+
+ return fallback;
+ }
+
+
+
+ bool CheckForVariable (const cGH* const cgh,
+ const char* const varlist, const int vindex)
+ {
+ const int numvars = CCTK_NumVars();
+ assert (vindex>=0 && vindex<numvars);
+
+ vector<bool> flags(numvars);
+
+ CCTK_TraverseString (varlist, SetFlag, &flags, CCTK_GROUP_OR_VAR);
+
+ return flags.at(vindex);
+ }
+
+ void SetFlag (int index, const char* optstring, void* arg)
+ {
+ vector<bool>& flags = *(vector<bool>*)arg;
+ flags.at(index) = true;
+ }
+
+
+
+ int ReadAttribute (IObase* reader, const char* name, int& value)
+ {
+ return ReadAttribute (reader, name, &value, 1);
+ }
+
+ int ReadAttribute (IObase* reader, const char* name,
+ int* values, int nvalues)
+ {
+ assert (reader);
+ assert (name);
+ assert (values);
+
+ IObase::DataType atype;
+ int alength;
+ const int attrnum = reader->readAttributeInfo (name, atype, alength);
+ if (attrnum<0) return attrnum;
+ if (atype != IObase::Int32) return -100;
+
+ vector<CCTK_INT4> values1(alength);
+ reader->readAttribute (attrnum, &values1.at(0));
+ for (int i=0; i<min(alength, nvalues); ++i) {
+ values[i] = values1[i];
+ }
+
+ return alength;
+ }
+
+
+
+ int ReadAttribute (IObase* reader, const char* name, CCTK_REAL& value)
+ {
+ return ReadAttribute (reader, name, &value, 1);
+ }
+
+ int ReadAttribute (IObase* reader, const char* name,
+ CCTK_REAL* values, int nvalues)
+ {
+ assert (reader);
+ assert (name);
+ assert (values);
+
+ IObase::DataType atype;
+ int alength;
+ const int attrnum = reader->readAttributeInfo (name, atype, alength);
+ if (attrnum<0) return attrnum;
+ if (atype != IObase::Float64) return -100;
+
+ vector<CCTK_REAL8> values1(alength);
+ reader->readAttribute (attrnum, &values1.at(0));
+ for (int i=0; i<min(alength, nvalues); ++i) {
+ values[i] = values1[i];
+ }
+
+ return alength;
+ }
+
+
+
+ int ReadAttribute (IObase* reader, const char* name, char& value)
+ {
+ return ReadAttribute (reader, name, &value, 1);
+ }
+
+ int ReadAttribute (IObase* reader, const char* name, char*& values)
+ {
+ assert (reader);
+ assert (name);
+
+ values = NULL;
+
+ IObase::DataType atype;
+ int alength;
+ const int attrnum = reader->readAttributeInfo (name, atype, alength);
+ if (attrnum<0) return attrnum;
+ if (atype != IObase::Char8) return -100;
+
+ values = (char *) malloc (alength+1);
+ if (!values) return -101;
+
+ reader->readAttribute (attrnum, values);
+
+ return alength;
+ }
+
+ int ReadAttribute (IObase* reader, const char* name,
+ char* values, int nvalues)
+ {
+ assert (reader);
+ assert (name);
+ assert (values);
+
+ IObase::DataType atype;
+ int alength;
+ const int attrnum = reader->readAttributeInfo (name, atype, alength);
+ if (attrnum<0) return attrnum;
+ if (atype != IObase::Char8) return -100;
+
+ vector<char> values1(alength);
+ reader->readAttribute (attrnum, &values1.at(0));
+ for (int i=0; i<min(alength, nvalues); ++i) {
+ values[i] = values1[i];
+ }
+
+ return alength;
+ }
+
+
+
+ void WriteAttribute (IObase* writer, const char* name, int value)
+ {
+ WriteAttribute (writer, name, &value, 1);
+ }
+
+ void WriteAttribute (IObase* writer, const char* name,
+ const int* values, int nvalues)
+ {
+ assert (writer);
+ assert (name);
+ assert (values);
+ vector<CCTK_INT4> values1(nvalues);
+ for (int i=0; i<nvalues; ++i) {
+ values1[i] = values[i];
+ }
+ writer->writeAttribute (name, IObase::Int32, nvalues, &values1.at(0));
+ }
+
+ void WriteAttribute (IObase* writer, const char* name, CCTK_REAL value)
+ {
+ WriteAttribute (writer, name, &value, 1);
+ }
+
+ void WriteAttribute (IObase* writer, const char* name,
+ const CCTK_REAL* values, int nvalues)
+ {
+ assert (writer);
+ assert (name);
+ assert (values);
+ vector<CCTK_REAL8> values1(nvalues);
+ for (int i=0; i<nvalues; ++i) {
+ values1[i] = values[i];
+ }
+ writer->writeAttribute (name, IObase::Float64, nvalues, &values1.at(0));
+ }
+
+ void WriteAttribute (IObase* writer, const char* name, char value)
+ {
+ WriteAttribute (writer, name, &value, 1);
+ }
+
+ void WriteAttribute (IObase* writer, const char* name, const char * values)
+ {
+ WriteAttribute (writer, name, values, strlen(values) + 1);
+ }
+
+ void WriteAttribute (IObase* writer, const char* name,
+ const char * values, int nvalues)
+ {
+ assert (writer);
+ assert (name);
+ assert (values);
+ writer->writeAttribute (name, IObase::Char8, nvalues, values);
+ }
+
+
+
+} // namespace CarpetIOFlexIO
diff --git a/CarpetAttic/CarpetIOFlexIO/src/ioflexio.h b/CarpetAttic/CarpetIOFlexIO/src/ioflexio.h
new file mode 100644
index 000000000..7e759749a
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/src/ioflexio.h
@@ -0,0 +1,22 @@
+/* $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/src/ioflexio.h,v 1.5 2003/11/05 16:18:38 schnetter Exp $ */
+
+#ifndef CARPETIOFLEXIO_H
+#define CARPETIOFLEXIO_H
+
+#include "cctk_Arguments.h"
+
+#ifdef __cplusplus
+namespace CarpetIOFlexIO {
+ extern "C" {
+#endif
+
+ /* Scheduled functions */
+ int CarpetIOFlexIOStartup (void);
+ int CarpetIOFlexIOReadData (CCTK_ARGUMENTS);
+
+#ifdef __cplusplus
+ } /* extern "C" */
+} /* namespace CarpetIOFlexIO */
+#endif
+
+#endif /* !defined(CARPETIOFLEXIO_H) */
diff --git a/CarpetAttic/CarpetIOFlexIO/src/ioflexio.hh b/CarpetAttic/CarpetIOFlexIO/src/ioflexio.hh
new file mode 100644
index 000000000..156f9baaf
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/src/ioflexio.hh
@@ -0,0 +1,39 @@
+// $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/src/ioflexio.hh,v 1.8 2004/02/27 16:23:34 schnetter Exp $
+
+#ifndef CARPETIOFLEXIO_HH
+#define CARPETIOFLEXIO_HH
+
+#include <vector>
+
+#include "cctk.h"
+#include "cctk_Arguments.h"
+
+#include "ioflexio.h"
+
+namespace CarpetIOFlexIO {
+
+ // Variable definitions
+ extern int GHExtension;
+ extern int IOMethod;
+ extern vector<bool> do_truncate;
+ extern vector<vector<vector<int> > > last_output; // [ml][rl][var]
+
+ void* SetupGH (tFleshConfig* const fc,
+ const int convLevel, cGH* const cgh);
+
+ int OutputGH (const cGH* const cgh);
+ int OutputVarAs (const cGH* const cgh, const char* const varname,
+ const char* const alias);
+ int TimeToOutput (const cGH* const cgh, const int vindex);
+ int TriggerOutput (const cGH* const cgh, const int vindex);
+
+ int InputGH (const cGH* const cgh);
+ int InputVarAs (const cGH* const cgh, const char* const varname,
+ const char* const alias);
+
+ int Recover (cGH* const cgh, const char *basefilename,
+ const int called_from);
+
+} // namespace CarpetIOFlexIO
+
+#endif // !defined(CARPETIOFLEXIO_HH)
diff --git a/CarpetAttic/CarpetIOFlexIO/src/make.code.defn b/CarpetAttic/CarpetIOFlexIO/src/make.code.defn
new file mode 100644
index 000000000..a18d9d672
--- /dev/null
+++ b/CarpetAttic/CarpetIOFlexIO/src/make.code.defn
@@ -0,0 +1,5 @@
+# Main make.code.defn file for thorn CarpetIOFlexIO
+# $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIO/src/make.code.defn,v 1.6 2003/07/04 16:03:57 tradke Exp $
+
+# Source files in this directory
+SRCS = ioflexio.cc