OpenCMISS-Iron Internal API Documentation
FieldExport.c
Go to the documentation of this file.
1 /* \file
2  * \author Caton Little
3  * \brief
4  *
5  * \section LICENSE
6  *
7  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8  *
9  * The contents of this file are subject to the Mozilla Public License
10  * Version 1.1 (the "License"); you may not use this file except in
11  * compliance with the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS"
15  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
16  * License for the specific language governing rights and limitations
17  * under the License.
18  *
19  * The Original Code is OpenCMISS
20  *
21  * The Initial Developer of the Original Code is University of Auckland,
22  * Auckland, New Zealand, the University of Oxford, Oxford, United
23  * Kingdom and King's College, London, United Kingdom. Portions created
24  * by the University of Auckland, the University of Oxford and King's
25  * College, London are Copyright (C) 2007-2010 by the University of
26  * Auckland, the University of Oxford and King's College, London.
27  * All Rights Reserved.
28  *
29  * Contributor(s):
30  *
31  * Alternatively, the contents of this file may be used under the terms of
32  * either the GNU General Public License Version 2 or later (the "GPL"), or
33  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
34  * in which case the provisions of the GPL or the LGPL are applicable instead
35  * of those above. If you wish to allow use of your version of this file only
36  * under the terms of either the GPL or the LGPL, and not to allow others to
37  * use your version of this file under the terms of the MPL, indicate your
38  * decision by deleting the provisions above and replace them with the notice
39  * and other provisions required by the GPL or the LGPL. If you do not delete
40  * the provisions above, a recipient may use your version of this file under
41  * the terms of any one of the MPL, the GPL or the LGPL.
42  *
43  */
44 
45 #ifdef WIN32
46 #include <windows.h>
47 #else
48 #include <stdarg.h>
49 #endif
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 
54 //#include <hdf5.h>
55 #ifdef H5_VERS_MAJOR
56 #define USE_HDF5
57 #endif
58 
59 #include "FieldExportConstants.h"
60 
61 /**********************************************************
62 
63  Fortran constants. Audit regularly. These aren't in
64  FieldExport.h, because the Fortran code #includes
65  that file, which leads to a #define collision.
66 
67  **********************************************************/
68 
69 #define BASIS_LAGRANGE_HERMITE_TP_TYPE 1 //< Lagrange Hermite tensor product basis \see BASIS_ROUTINES_BasisTypes,BASIS_ROUTINES
70 #define BASIS_SIMPLEX_TYPE 2 //< Simplex basis \see BASIS_ROUTINES_BasisTypes,BASIS_ROUTINES
71 
72 
73 #define BASIS_LINEAR_LAGRANGE_INTERPOLATION 1 //< Linear Lagrange interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
74 #define BASIS_QUADRATIC_LAGRANGE_INTERPOLATION 2 //< Quadratic Lagrange interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
75 #define BASIS_CUBIC_LAGRANGE_INTERPOLATION 3 //< Cubic Lagrange interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
76 #define BASIS_CUBIC_HERMITE_INTERPOLATION 4 //< Cubic Hermite interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
77 #define BASIS_QUADRATIC1_HERMITE_INTERPOLATION 5 //< Quadratic Hermite (no derivative at xi=0) interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
78 #define BASIS_QUADRATIC2_HERMITE_INTERPOLATION 6 //< Quadratic Hermite (no derivative at xi=1) interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
79 #define BASIS_LINEAR_SIMPLEX_INTERPOLATION 7 //< Linear Simplex interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
80 #define BASIS_QUADRATIC_SIMPLEX_INTERPOLATION 8 //< Quadratic Simplex interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
81 #define BASIS_CUBIC_SIMPLEX_INTERPOLATION 9 //< Cubic Simplex interpolation specification \see BASIS_ROUTINES_InterpolationSpecifications,BASIS_ROUTINES
82 
83 #define FIELD_IO_INTERPOLATION_HEADER_SCALE 4
84 #define FIELD_IO_INTERPOLATION_HEADER_NODAL 5
85 #define FIELD_IO_INTERPOLATION_HEADER_GRID 6
86 #define FIELD_IO_INTERPOLATION_HEADER_GAUSS 7
87 #define FIELD_IO_INTERPOLATION_HEADER_CONSTANT 8
88 
89 
90 #define FIELD_GEOMETRIC_TYPE 1 //Geometric field \see FIELD_ROUTINES_FieldTypes,FIELD_ROUTINES
91 #define FIELD_FIBRE_TYPE 2 //Fibre field \see FIELD_ROUTINES_FieldTypes,FIELD_ROUTINES
92 #define FIELD_GENERAL_TYPE 3 //General field \see FIELD_ROUTINES_FieldTypes,FIELD_ROUTINES
93 #define FIELD_MATERIAL_TYPE 4 //Material field \see FIELD_ROUTINES_FieldTypes,FIELD_ROUTINES
94 #define FIELD_GEOMETRIC_GENERAL_TYPE 5 //Geometric general field \see FIELD_ROUTINES_FieldTypes,FIELD_ROUTINES
95 
96 #define FIELD_U_VARIABLE_TYPE 1 //Standard variable type i.e., u \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
97 #define FIELD_DELUDELN_VARIABLE_TYPE 2 //Normal derivative variable type i.e., du/dn \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
98 #define FIELD_DELUDELT_VARIABLE_TYPE 3 //First time derivative variable type i.e., du/dt \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
99 #define FIELD_DEL2UDELT2_VARIABLE_TYPE 4 //Second type derivative variable type i.e., d^2u/dt^2 \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
100 #define FIELD_V_VARIABLE_TYPE 5 //Second standard variable type i.e., v \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
101 #define FIELD_DELVDELN_VARIABLE_TYPE 6 //Second normal variable type i.e., dv/dn \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
102 #define FIELD_U1_VARIABLE_TYPE 9 //Third standard variable type i.e., v \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
103 #define FIELD_U2_VARIABLE_TYPE 13 //Fourth standard variable type i.e., v \see FIELD_ROUTINES_VariableTypes,FIELD_ROUTINES
104 
105 #define COORDINATE_RECTANGULAR_CARTESIAN_TYPE 1 //Rectangular Cartesian coordinate system type \see COORDINATE_ROUTINES_CoordinateSystemTypes,COORDINATE_ROUTINES
106 #define COORDINATE_CYCLINDRICAL_POLAR_TYPE 2 //Cylindrical polar coordinate system type \see COORDINATE_ROUTINES_CoordinateSystemTypes,COORDINATE_ROUTINES
107 #define COORDINATE_SPHERICAL_POLAR_TYPE 3 //Spherical polar coordinate system type \see COORDINATE_ROUTINES_CoordinateSystemTypes,COORDINATE_ROUTINES
108 #define COORDINATE_PROLATE_SPHEROIDAL_TYPE 4 //Prolate spheroidal coordinate system type \see COORDINATE_ROUTINES_CoordinateSystemTypes,COORDINATE_ROUTINES
109 #define COORDINATE_OBLATE_SPHEROIDAL_TYPE 5 //Oblate spheroidal coordinate system type \see COORDINATE_ROUTINES_CoordinateSystemTypes,COORDINATE_ROUTINES
110 
111 #define NO_PART_DERIV 1 //No partial derivative i.e., u \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
112 
113 #define FIRST_PART_DERIV 2 //First partial derivative i.e., du/ds \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
114 #define SECOND_PART_DERIV 3 //Second partial derivative i.e., d^2u/ds^2 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
115 
116 #define PART_DERIV_S1 2 //First partial derivative in the s1 direction i.e., du/ds1 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
117 #define PART_DERIV_S1_S1 3 //Second partial derivative in the s1 direction i.e., d^2u/ds1ds1 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
118 #define PART_DERIV_S2 4 //First partial derivative in the s2 direction i.e., du/ds2 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
119 #define PART_DERIV_S2_S2 5 //Second partial derivative in the s2 direction i.e., d^2u/ds2ds2 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
120 #define PART_DERIV_S1_S2 6 //Cross derivative in the s1 and s2 direction i.e., d^2u/ds1ds2 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
121 #define PART_DERIV_S3 7 //First partial derivative in the s3 direction i.e., du/ds3 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
122 #define PART_DERIV_S3_S3 8 //Second partial derivative in the s3 direction i.e., d^2u/ds3ds3 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
123 #define PART_DERIV_S1_S3 9 //Cross derivative in the s1 and s3 direction i.e., d^2u/ds1ds3 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
124 #define PART_DERIV_S2_S3 10 //Cross derivative in the s2 and s3 direction i.e., d^2u/ds2ds3 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
125 #define PART_DERIV_S1_S2_S3 11 //Cross derivative in the s1, s2 and s3 direction i.e., d^3u/ds1ds2ds3 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
126 #define PART_DERIV_S4 12 //First partial derivative in the s4 direction i.e., du/ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
127 #define PART_DERIV_S4_S4 13 //Second partial derivative in the s4 direction i.e., d^2u/ds4ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
128 #define PART_DERIV_S1_S4 14 //Cross derivative in the s1 and s4 direction i.e., d^2u/ds1ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
129 #define PART_DERIV_S2_S4 15 //Cross derivative in the s2 and s4 direction i.e., d^2u/ds2ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
130 #define PART_DERIV_S3_S4 16 //Cross derivative in the s3 and s4 direction i.e., d^2u/ds3ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
131 #define PART_DERIV_S1_S2_S4 17 //Cross derivative in the s1, s2 and s4 direction i.e., d^3u/ds1ds2ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
132 #define PART_DERIV_S1_S3_S4 18 //Cross derivative in the s1, s3 and s4 direction i.e., d^3u/ds1ds3ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
133 #define PART_DERIV_S2_S3_S4 19 //Cross derivative in the s2, s3 and s4 direction i.e., d^3u/ds2ds3ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
134 #define PART_DERIV_S1_S2_S3_S4 20 //Cross derivative in the s1, s2, s3 and s4 direction i.e., d^4u/ds1ds2ds3ds4 \see CONSTANTS_PartialDerivativeConstants,CONSTANTS
135 
136 /**********************************************************
137 
138  Fortran constants. Audit regularly.
139 
140  **********************************************************/
141 
142 /*
143  API-local structs.
144 */
145 typedef struct
146 {
147  FILE *file;
148 #ifdef USE_HDF5
149  hid_t hd5Handle;
150 #endif
151 
152  int error;
153 }
155 
156 typedef struct _SessionListEntry
157 {
158  int handle;
159 
160  int type;
161 
162  union
163  {
165  };
166 
168 }
170 
171 //This is the head of the session list. For convenience, the head itself is a stub, so it exists even for a zero-entry list.
173 
174 static int nextHandle = 0;
175 
176 #ifdef USE_HDF5
177 static void eep()
178 {
179  int *i = NULL;
180  int j;
181 
182  FILE *f = fopen( "D:\\err.txt", "w" );
183  H5Eprint1(f);
184  fclose(f);
185 
186  j = *i;
187 }
188 #endif
189 
190 
191 static int FieldExport_FPrintf( FileSession *const session, const char *format, ... )
192 {
193  va_list args;
194 
195  if( session->error == FIELD_EXPORT_NO_ERROR )
196  {
197  va_start( args, format );
198  if( vfprintf( session->file, format, args ) < 0 )
199  {
201  }
202  va_end( args );
203  }
204 
205  return session->error;
206 }
207 
208 
210 {
211  SessionListEntry *entry = sessions.next;
212 
213  while( entry != NULL )
214  {
215  if( entry->handle == handle )
216  {
217  return entry;
218  }
219 
220  entry = entry->next;
221  }
222 
223  return NULL;
224 }
225 
226 int FieldExport_InterpolationType( const int interpType );
227 
228 /*
229  CMISS-formatted file export routines.
230 */
231 static int FieldExport_File_Group( FileSession *const session, const char *const label )
232 {
233  return FieldExport_FPrintf( session, " Group name: %s\n", label );
234  //return FieldExport_FPrintf( session, " Region: /%s\n", label );
235 }
236 
237 
238 static int FieldExport_File_MeshDimensions( FileSession *const session, const int dimensions, const int basisType )
239 {
240  switch( basisType )
241  {
243  return FieldExport_FPrintf( session, " Shape. Dimension=%d\n", dimensions );
244  case BASIS_SIMPLEX_TYPE:
245  switch( dimensions )
246  {
247  case 1:
248  return FieldExport_FPrintf( session, " Shape. Dimension=%d\n", dimensions );
249  case 2:
250  return FieldExport_FPrintf( session, " Shape. Dimension=%d, simplex(2)*simplex\n", dimensions );
251  case 3:
252  return FieldExport_FPrintf( session, " Shape. Dimension=%d, simplex(2;3)*simplex*simplex\n", dimensions );
253  default:
254  return FieldExport_FPrintf( session, " Shape. Dimension=%d\n", dimensions );
255  }
256  default:
257  return FieldExport_FPrintf( session, " Shape. Dimension=%d\n", dimensions );
258  }
259 }
260 
261 static int FieldExport_File_ScalingFactorCount( FileSession *const session, const int scalingFactorCount )
262 {
263  return FieldExport_FPrintf( session, " #Scale factor sets= %d\n", scalingFactorCount );
264 }
265 
266 
267 static int FieldExport_File_InterpolationHeader( FileSession *const session, const int labelType, const int numberOfXi, const int* const interpolationXi)
268 {
269  int i, j;
270  const char * label;
271  int *linked = malloc( sizeof(int) * numberOfXi );
272  int linkCount = 0;
273 
274  for( i = 0; i < numberOfXi; i++ )
275  {
276  switch( interpolationXi[i] )
277  {
281  linked[i] = 1;
282  linkCount++;
283  break;
284  default:
285  linked[i] = 0;
286  break;
287  }
288  }
289 
290  FieldExport_FPrintf( session, " " );
291 
292  for( i = 0; i < numberOfXi; i++ )
293  {
294  if( labelType == FIELD_IO_INTERPOLATION_HEADER_GRID )
295  {
296  label = "l.Lagrange";
297  }
298  else if( labelType == FIELD_IO_INTERPOLATION_HEADER_CONSTANT )
299  {
300  label = "constant";
301  }
302  else if( labelType == FIELD_IO_INTERPOLATION_HEADER_GAUSS )
303  {
304  label = "l.Lagrange";
305  }
306  else
307  {
308  switch( interpolationXi[i] )
309  {
311  label = "l.Lagrange";
312  break;
314  label = "q.Lagrange";
315  break;
317  label = "c.Lagrange";
318  break;
320  label = "c.Hermite";
321  break;
323  label = "LagrangeHermite";
324  break;
326  label = "HermiteLagrange";
327  break;
329  label = "l.simplex";
330  break;
332  label = "q.simplex";
333  break;
335  label = "c.simplex";
336  break;
337  default:
338  free( linked );
340  }
341  }
342 
343  FieldExport_FPrintf( session, "%s", label );
344 
345  if( linkCount > 0 )
346  {
347  linkCount--;
348  FieldExport_FPrintf( session, "(", label );
349  for( j = i+1; j < numberOfXi; j++ )
350  {
351  if( linked[j] == 1 )
352  {
353  FieldExport_FPrintf( session, "%d", j+1 );
354  }
355  if( linkCount > 1 )
356  {
357  FieldExport_FPrintf( session, ";" );
358  }
359  linkCount--;
360  }
361  FieldExport_FPrintf( session, ")", label );
362  }
363 
364  if( i < ( numberOfXi - 1 ) )
365  {
366  FieldExport_FPrintf( session, "*" );
367  }
368  }
369 
370  free( linked );
371 
372  switch( labelType )
373  {
375  FieldExport_FPrintf( session, ", no modify, standard node based.\n" );
376  break;
378  FieldExport_FPrintf( session, ", no modify, grid based.\n" );
379  break;
381  FieldExport_FPrintf( session, ", no modify, grid based.\n" );
382  break;
384  FieldExport_FPrintf( session, ", no modify, grid based.\n" );
385  break;
386  default:
388  }
389 
390  return session->error;
391 }
392 
393 
394 static int FieldExport_File_InterpolationHeaderScale( FileSession *const session, const int numberOfXi, const int* const interpolationXi,
395  const int numberOfScaleFactors)
396 {
397  int i, j;
398  const char * label;
399  int *linked = malloc( sizeof(int) * numberOfXi );
400  int linkCount = 0;
401 
402  for( i = 0; i < numberOfXi; i++ )
403  {
404  switch( interpolationXi[i] )
405  {
409  linked[i] = 1;
410  linkCount++;
411  break;
412  default:
413  linked[i] = 0;
414  break;
415  }
416  }
417 
418  FieldExport_FPrintf( session, " " );
419 
420  for( i = 0; i < numberOfXi; i++ )
421  {
422  switch( interpolationXi[i] )
423  {
425  label = "l.Lagrange";
426  break;
428  label = "q.Lagrange";
429  break;
431  label = "c.Lagrange";
432  break;
434  label = "c.Hermite";
435  break;
437  label = "LagrangeHermite";
438  break;
440  label = "HermiteLagrange";
441  break;
443  label = "l.simplex";
444  break;
446  label = "q.simplex";
447  break;
449  label = "c.simplex";
450  break;
451  default:
452  free( linked );
454  }
455  FieldExport_FPrintf( session, "%s", label );
456 
457  if( linkCount > 0 )
458  {
459  linkCount--;
460  FieldExport_FPrintf( session, "(", label );
461  for( j = i+1; j < numberOfXi; j++ )
462  {
463  if( linked[j] == 1 )
464  {
465  FieldExport_FPrintf( session, "%d", j+1 );
466  }
467  if( linkCount > 1 )
468  {
469  FieldExport_FPrintf( session, ";" );
470  }
471  linkCount--;
472  }
473  FieldExport_FPrintf( session, ")", label );
474  }
475 
476  if( i < ( numberOfXi - 1 ) )
477  {
478  FieldExport_FPrintf( session, "*" );
479  }
480  }
481 
482  free( linked );
483 
484  FieldExport_FPrintf( session, ", #Scale factors=%d\n", numberOfScaleFactors );
485 
486  return session->error;
487 }
488 
489 
490 static char *FieldExport_GetVariableLabel( const int fieldType, const int variableType )
491 {
492  switch( fieldType )
493  {
495  switch( variableType )
496  {
498  return "unknown";
500  return "field, normal derivative of variable";
502  return "field, first time derivative of variable";
504  return "field, second time derivative of variable";
505  default:
506  return "field, real";
507  }
508  case FIELD_FIBRE_TYPE:
509  switch( variableType )
510  {
512  return "anatomical, fibre";
514  return "normal derivative of variable";
516  return "first time derivative of variable";
518  return "second time derivative of variable";
519  default:
520  return "real";
521  }
522  case FIELD_GENERAL_TYPE:
523  switch( variableType )
524  {
526  return "field, rectangular cartesian";
528  return "field, rectangular cartesian";
530  return "field, rectangular cartesian";
532  return "field, rectangular cartesian";
534  return "field, rectangular cartesian";
536  return "field, first time derivative of variable";
538  return "field, second time derivative of variable";
539  default:
540  return "field, real";
541  }
542  case FIELD_MATERIAL_TYPE:
543  switch( variableType )
544  {
546  return "field, rectangular cartesian";
548  return "field, normal derivative of variable";
550  return "field, first time derivative of variable";
552  return "field, second time derivative of variable";
553  default:
554  return "field, real";
555  }
557  switch( variableType )
558  {
560  return "field, rectangular cartesian";
562  return "field, rectangular cartesian";
564  return "field, first time derivative of variable";
566  return "field, second time derivative of variable";
567  default:
568  return "field, real";
569  }
570  default:
571  switch( variableType )
572  {
574  return "field, unknown standand variable type";
576  return "field, unknown normal derivative of variable";
578  return "field, unknown first time derivative of variable";
580  return "field, unknown second time derivative of variable";
581  default:
582  return "field, real";
583  }
584  }
585 }
586 
587 
588 static char *FieldExport_GetCoordinateVariableLabel( int coordinateSystemType )
589 {
590  switch( coordinateSystemType )
591  {
593  return "coordinate, rectangular cartesian";
594  //MUSTDO non-rectangular coordinate systems
595  /*
596  case COORDINATE_CYCLINDRICAL_POLAR_TYPE:
597  case COORDINATE_SPHERICAL_POLAR_TYPE:
598  case COORDINATE_PROLATE_SPHEROIDAL_TYPE:
599  case COORDINATE_OBLATE_SPHEROIDAL_TYPE:
600  */
601  default:
602  return "unknown";
603  }
604 }
605 
606 
607 static char *FieldExport_GetCoordinateComponentLabel( int coordinateSystemType, int componentNumber )
608 {
609  switch( coordinateSystemType )
610  {
612  if( componentNumber == 1 )
613  {
614  return "x";
615  }
616  else if( componentNumber == 2 )
617  {
618  return "y";
619  }
620  else if( componentNumber == 3 )
621  {
622  return "z";
623  }
624  break;
625  /*
626  case COORDINATE_CYCLINDRICAL_POLAR_TYPE:
627  case COORDINATE_SPHERICAL_POLAR_TYPE:
628  case COORDINATE_PROLATE_SPHEROIDAL_TYPE:
629  case COORDINATE_OBLATE_SPHEROIDAL_TYPE:
630  */
631  default:
632  break;
633  }
634 
635  return NULL;
636 }
637 
638 
639 static int FieldExport_File_NodeCount( FileSession *const session, const int nodeCount )
640 {
641  return FieldExport_FPrintf( session, " #Nodes= %d\n", nodeCount );
642 }
643 
644 
645 static int FieldExport_File_FieldCount( FileSession *const session, const int fieldCount )
646 {
647  return FieldExport_FPrintf( session, " #Fields=%d\n", fieldCount );
648 }
649 
650 
651 static int FieldExport_File_CoordinateVariable( FileSession *const session, const char *variableName, const int variableIndex,
652  int coordinateSystemType, const int componentCount )
653 {
654  char *coordinateLabel;
655 
656  coordinateLabel = FieldExport_GetCoordinateVariableLabel( coordinateSystemType );
657 
658  return FieldExport_FPrintf( session, " %d) %s, %s, #Components=%d\n", variableIndex, variableName, coordinateLabel, componentCount );
659 }
660 
661 
662 static int FieldExport_File_Variable( FileSession *const session, const char *variableName, const int variableIndex,
663  const int fieldType, const int variableType, const int componentCount )
664 {
665  char *variableLabel;
666 
667  variableLabel = FieldExport_GetVariableLabel( fieldType, variableType );
668 
669  return FieldExport_FPrintf( session, " %d) %s, %s, #Components=%d\n", variableIndex, variableName, variableLabel, componentCount );
670 }
671 
672 
673 static int FieldExport_File_CoordinateComponent( FileSession *const session, int coordinateSystemType,
674  const int componentNumber, const int interpType, const int numberOfXi, const int *const interpolationXi )
675 {
676  const char * const componentLabel = FieldExport_GetCoordinateComponentLabel( coordinateSystemType, componentNumber );
677  int headerType;
678 
679  headerType = FieldExport_InterpolationType( interpType );
680  if( componentLabel == NULL )
681  {
682  FieldExport_FPrintf( session, " %d. ", componentNumber );
683  }
684  else
685  {
686  FieldExport_FPrintf( session, " %s. ", componentLabel );
687  }
688 
689  if( session->error != FIELD_EXPORT_NO_ERROR )
690  {
691  return session->error;
692  }
693 
694  return FieldExport_File_InterpolationHeader( session, headerType, numberOfXi, interpolationXi );
695 }
696 
697 
698 static int FieldExport_File_Component( FileSession *const session,
699  const int componentNumber, const int interpType, const int numberOfXi, const int *const interpolationXi )
700 {
701  const int headerType = FieldExport_InterpolationType( interpType );
702 
703  if( FieldExport_FPrintf( session, " %d. ", componentNumber ) != FIELD_EXPORT_NO_ERROR )
704  {
705  return session->error;
706  }
707 
708  return FieldExport_File_InterpolationHeader( session, headerType, numberOfXi, interpolationXi );
709 }
710 
711 
712 static int FieldExport_File_ElementGridSize( FileSession *const session, const int interpType, const int numberOfXi, const int *const numberGauss )
713 {
714  int i,numGrid[3];
715  const int headerType = FieldExport_InterpolationType( interpType );
716 
717  if( headerType == FIELD_IO_INTERPOLATION_HEADER_CONSTANT)
718  {
719  numGrid[0]=0;
720  numGrid[1]=0;
721  numGrid[2]=0;
722  }
723  else if( headerType == FIELD_IO_INTERPOLATION_HEADER_GRID )
724  {
725  numGrid[0]=1;
726  numGrid[1]=1;
727  numGrid[2]=1;
728  }
729  else if( headerType == FIELD_IO_INTERPOLATION_HEADER_GAUSS )
730  {
731  for( i = 0; i < numberOfXi; i++ )
732  {
733  numGrid[i]=numberGauss[i]-1;
734  }
735  }
736  else
737  {
738  numGrid[0]=1;
739  numGrid[1]=1;
740  numGrid[2]=1;
741  }
742 
743  if( FieldExport_FPrintf( session, " " ) != FIELD_EXPORT_NO_ERROR )
744  {
745  return session->error;
746  }
747 
748  for( i = 0; i < numberOfXi; i++ )
749  {
750  if( FieldExport_FPrintf( session, "#xi%d=%d", i+1, numGrid[i] ) != FIELD_EXPORT_NO_ERROR )
751  {
752  return session->error;
753  }
754 
755  if( i < ( numberOfXi - 1 ) )
756  {
757  if( FieldExport_FPrintf( session, ", " ) != FIELD_EXPORT_NO_ERROR )
758  {
759  return session->error;
760  }
761  }
762  }
763  if( FieldExport_FPrintf( session, "\n" ) != FIELD_EXPORT_NO_ERROR )
764  {
765  return session->error;
766  }
767 
768  return session->error;
769 }
770 
771 
772 static int FieldExport_File_NodeScaleIndexes( FileSession *const session, const int nodeCount, const int *const derivativeCount,
773  const int *const elementDerivatives, const int *const nodeIndexes, const int *const scaleIndexes )
774 {
775  int i, j;
776  int derivativeIndex = 0;
777  int scaleIndex = 0;
778 
779  FieldExport_FPrintf( session, " #Nodes= %d\n", nodeCount );
780 
781  for( i = 0; i < nodeCount; i++ )
782  {
783  FieldExport_FPrintf( session, " %5d. #Values=%d\n", nodeIndexes[i], derivativeCount[i] );
784  FieldExport_FPrintf( session, " Value indices: " );
785  for( j = 0; j < derivativeCount[i]; j++ )
786  {
787  FieldExport_FPrintf( session, " %3d", elementDerivatives[ derivativeIndex++ ] );
788  }
789  FieldExport_FPrintf( session, "\n" );
790  FieldExport_FPrintf( session, " Scale factor indices: " );
791  for( j = 0; j < derivativeCount[i]; j++ )
792  {
793  //We're currently using firstScaleIndex == -1 to tell us that there's no scaling. Ugly but functional.
794  if( scaleIndex >= 0 )
795  {
796  FieldExport_FPrintf( session, " %3d", scaleIndexes[scaleIndex++] );
797  }
798  else
799  {
800  FieldExport_FPrintf( session, " 0" );
801  }
802  }
803  FieldExport_FPrintf( session, "\n" );
804  }
805 
806  return session->error;
807 }
808 
809 
810 static int FieldExport_File_ElementIndex( FileSession *session, const int dimensionCount, const int elementIndex )
811 {
812  if( dimensionCount == 3 )
813  {
814  return FieldExport_FPrintf( session, " Element: %d 0 0\n", elementIndex );
815  }
816  else if( dimensionCount == 2 )
817  {
818  /* return FieldExport_FPrintf( session, " Element: 0 %d 0\n", elementIndex ); */
819  return FieldExport_FPrintf( session, " Element: %d 0 0\n", elementIndex );
820  }
821  else
822  {
823  /* return FieldExport_FPrintf( session, " Element: 0 0 %d\n", elementIndex ); */
824  return FieldExport_FPrintf( session, " Element: %d 0 0\n", elementIndex );
825  }
826 }
827 
828 
829 static int FieldExport_File_ElementNodeIndices( FileSession *session, const int nodeCount, const int *const indices )
830 {
831  int i;
832 
833  FieldExport_FPrintf( session, " Nodes:\n" );
834 
835  for( i = 0; i < nodeCount; i++ )
836  {
837  FieldExport_FPrintf( session, " %10d", indices[i] );
838  }
839 
840  FieldExport_FPrintf( session, "\n" );
841 
842  return session->error;
843 }
844 
845 
846 static int FieldExport_File_ElementNodeScales( FileSession *session, const int isFirstSet, const int scaleCount, const double *const scales )
847 {
848  int i;
849 
850  if( isFirstSet )
851  {
852  FieldExport_FPrintf( session, " Scale factors:\n" );
853  }
854 
855  FieldExport_FPrintf( session, " " );
856 
857  for( i = 0; i < scaleCount; i++ )
858  {
859  FieldExport_FPrintf( session, " %.16E", scales[i] );
860  }
861 
862  FieldExport_FPrintf( session, "\n" );
863 
864  return session->error;
865 }
866 
867 
868 static int FieldExport_File_ElementGridValues( FileSession *session, const int isFirstSet, const int valueCount, const double value )
869 {
870  int i;
871  /* int valueCount = 1 << dimensionCount; */
872 
873  if( isFirstSet )
874  {
875  FieldExport_FPrintf( session, " Values:\n" );
876  }
877 
878  FieldExport_FPrintf( session, " " );
879 
880  for( i = 0; i < valueCount; i++ )
881  {
882  FieldExport_FPrintf( session, " %.16E", value );
883  }
884 
885  FieldExport_FPrintf( session, "\n" );
886 
887  return session->error;
888 }
889 
890 
891 static int FieldExport_File_OpenSession( const char *const name, int * const handle )
892 {
893  SessionListEntry *session = calloc( 1, sizeof( SessionListEntry ) );
894  char hd5Name[256];
895 
896  strcpy( hd5Name, name );
897  strcat( hd5Name, ".h5" );
898 
899  session->type = EXPORT_TYPE_FILE;
900  session->handle = nextHandle++;
901  session->fileSession.file = fopen( name, "w" );
902 
903 #ifdef USE_HDF5
904  session->fileSession.hd5Handle = H5Fcreate( hd5Name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
905 #endif
906 
908 
909 #ifdef USE_HDF5
910  if( ( session->fileSession.file == NULL )
911  || ( session->fileSession.hd5Handle < 0 ) )
912 #else
913  if( session->fileSession.file == NULL )
914 #endif
915  {
916  if( session->fileSession.file != NULL )
917  {
918  fclose( session->fileSession.file );
919  }
920 #ifdef USE_HDF5
921  if( session->fileSession.hd5Handle >= 0 )
922  {
923  H5Fclose( session->fileSession.hd5Handle );
924  }
925 #endif
926  free( session );
928  }
929 
930  session->next = sessions.next;
931  sessions.next = session;
932 
933  *handle = session->handle;
934 
935  return FIELD_EXPORT_NO_ERROR;
936 }
937 
938 
940 {
941  fclose( session->fileSession.file );
942 
943 #ifdef USE_HDF5
944  H5Fclose( session->fileSession.hd5Handle );
945 #endif
946 
947  session->type = EXPORT_TYPE_CLOSED;
948 
949  return FIELD_EXPORT_NO_ERROR;
950 }
951 
952 
953 #ifdef USE_HDF5
954 static int FieldExport_File_HD5_NodeValues( FileSession *session, const int nodeNumber, const int valueCount, const double *const values )
955 {
956  hid_t dataset_id, dataspace_id, attribute_id, attribute_dataspace_id;
957  hsize_t dims[1];
958  int attributes[1];
959  herr_t status;
960  char setName[256];
961 
962  dims[0] = valueCount;
963  if( ( dataspace_id = H5Screate_simple( 1, dims, NULL ) ) < 0 )
964  {
965  return dataspace_id;
966  }
967 
968  sprintf( setName, "/node%d", nodeNumber );
969  if( ( dataset_id = H5Dcreate( session->hd5Handle, setName, H5T_NATIVE_DOUBLE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) ) < 0 )
970  {
971  return dataset_id;
972  }
973 
974  dims[0] = 1;
975  if( ( attribute_dataspace_id = H5Screate_simple( 1, dims, NULL ) ) < 0 )
976  {
977  return dataspace_id;
978  }
979  if( ( attribute_id = H5Acreate( dataset_id, "Node", H5T_STD_I32BE, attribute_dataspace_id, H5P_DEFAULT, H5P_DEFAULT ) ) < 0 )
980  {
981  return attribute_id;
982  }
983 
984  attributes[0] = nodeNumber;
985  if( ( status = H5Awrite( attribute_id, H5T_NATIVE_INT, attributes ) ) < 0 )
986  {
987  return status;
988  }
989 
990  if( ( status = H5Aclose( attribute_id ) ) < 0 )
991  {
992  return status;
993  }
994 
995  if( ( status = H5Dwrite( dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, values ) ) < 0 )
996  {
997  return status;
998  }
999 
1000  if( ( status = H5Dclose( dataset_id ) ) < 0 )
1001  {
1002  return status;
1003  }
1004 
1005  if( ( status = H5Sclose( attribute_dataspace_id ) ) < 0 )
1006  {
1007  return status;
1008  }
1009 
1010  if( ( status = H5Sclose( dataspace_id ) ) < 0 )
1011  {
1012  return status;
1013  }
1014 
1015  return 0;
1016 }
1017 #endif
1018 
1019 static int FieldExport_File_NodeValues( FileSession *session, const int nodeNumber, const int valueCount, const double *const values )
1020 {
1021  int i;
1022 #ifdef USE_HDF5
1023  herr_t status;
1024 #endif
1025  static int lastNodeNumber = -1; //A little bit of a hack, but then so is the whole file format.
1026 
1027  if( nodeNumber != lastNodeNumber )
1028  {
1029  lastNodeNumber = nodeNumber;
1030  FieldExport_FPrintf( session, " Node: %d\n", nodeNumber );
1031  }
1032 
1033  for( i = 0; i < valueCount; i++ )
1034  {
1035  FieldExport_FPrintf( session, " %.16E", values[i] );
1036  }
1037  FieldExport_FPrintf( session, "\n" );
1038 
1039 #ifdef USE_HDF5
1040  status = FieldExport_File_HD5_NodeValues( session, nodeNumber, valueCount, values );
1041 
1042  if( status < 0 )
1043  {
1044  eep();
1046  }
1047 #endif
1048 
1049  return session->error;
1050 }
1051 
1052 
1053 static int FieldExport_FieldDerivateLabels( FileSession *session, const int numberOfDerivatives, const int *const derivatives )
1054 {
1055  int i;
1056 
1057  if( ( numberOfDerivatives == 1 ) && ( derivatives[0] == NO_PART_DERIV ) )
1058  {
1059  return session->error;
1060  }
1061 
1062  FieldExport_FPrintf( session, "(" );
1063  for( i = 0; i < numberOfDerivatives; i++ )
1064  {
1065  if( i > 1 )
1066  {
1067  FieldExport_FPrintf( session, "," );
1068  }
1069  switch( derivatives[i] )
1070  {
1071  case NO_PART_DERIV:
1072  break;
1073  case PART_DERIV_S1:
1074  FieldExport_FPrintf( session, "d/ds1" );
1075  break;
1076  case PART_DERIV_S1_S1:
1077  FieldExport_FPrintf( session, "d2/ds1ds1" );
1078  break;
1079  case PART_DERIV_S2:
1080  FieldExport_FPrintf( session, "d/ds2" );
1081  break;
1082  case PART_DERIV_S2_S2:
1083  FieldExport_FPrintf( session, "d2/ds2ds2" );
1084  break;
1085  case PART_DERIV_S3:
1086  FieldExport_FPrintf( session, "d/ds3" );
1087  break;
1088  case PART_DERIV_S3_S3:
1089  FieldExport_FPrintf( session, "d2/ds3ds3" );
1090  break;
1091  case PART_DERIV_S1_S2:
1092  FieldExport_FPrintf( session, "d2/ds1ds2" );
1093  break;
1094  case PART_DERIV_S1_S3:
1095  FieldExport_FPrintf( session, "d2/ds1ds3" );
1096  break;
1097  case PART_DERIV_S2_S3:
1098  FieldExport_FPrintf( session, "d2/ds2ds3" );
1099  break;
1100  case PART_DERIV_S1_S2_S3:
1101  FieldExport_FPrintf( session, "d3/ds1ds2ds3" );
1102  break;
1103  case PART_DERIV_S4:
1104  FieldExport_FPrintf( session, "d/ds4" );
1105  break;
1106  case PART_DERIV_S4_S4:
1107  FieldExport_FPrintf( session, "d2/ds4ds4" );
1108  break;
1109  case PART_DERIV_S1_S4:
1110  FieldExport_FPrintf( session, "d2/ds1ds4" );
1111  break;
1112  case PART_DERIV_S2_S4:
1113  FieldExport_FPrintf( session, "d2/ds2ds4" );
1114  break;
1115  case PART_DERIV_S3_S4:
1116  FieldExport_FPrintf( session, "d2/ds3ds4" );
1117  break;
1118  case PART_DERIV_S1_S2_S4:
1119  FieldExport_FPrintf( session, "d3/ds1ds2ds4" );
1120  break;
1121  case PART_DERIV_S1_S3_S4:
1122  FieldExport_FPrintf( session, "d3/ds1ds3ds4" );
1123  break;
1124  case PART_DERIV_S2_S3_S4:
1125  FieldExport_FPrintf( session, "d3/ds2ds3ds4" );
1126  break;
1128  FieldExport_FPrintf( session, "d4/ds1ds2ds3ds4" );
1129  break;
1130  default:
1131  FieldExport_FPrintf( session, "real" );
1132  }
1133  }
1134  FieldExport_FPrintf( session, ")" );
1135 
1136  return session->error;
1137 }
1138 
1139 
1140 static int FieldExport_File_DerivativeIndices( FileSession *session, const int componentNumber, const int fieldType,
1141  const int variableType, const int numberOfDerivatives, const int *const derivatives, const int valueIndex )
1142 {
1143  //MUSTDO add a proper GetComponentLabel( fieldType, variableType, componentNumber ) function.
1144  FieldExport_FPrintf( session, " %d. Value index= %d, #Derivatives= %d", componentNumber, valueIndex, numberOfDerivatives - 1 );
1145 
1146  FieldExport_FieldDerivateLabels( session, numberOfDerivatives, derivatives );
1147 
1148  return session->error;
1149 }
1150 
1151 
1152 static int FieldExport_File_CoordinateDerivativeIndices( FileSession *session, const int componentNumber, int coordinateSystemType,
1153  const int numberOfDerivatives, const int *const derivatives, const int valueIndex )
1154 {
1155  const char * const componentLabel = FieldExport_GetCoordinateComponentLabel( coordinateSystemType, componentNumber );
1156 
1157  //MUSTDO add a proper GetComponentLabel( fieldType, variableType, componentNumber ) function.
1158  if( componentLabel == NULL )
1159  {
1160  FieldExport_FPrintf( session, " %d. Value index= %d, #Derivatives= %d", componentNumber, valueIndex, numberOfDerivatives - 1 );
1161  }
1162  else
1163  {
1164  FieldExport_FPrintf( session, " %s. Value index= %d, #Derivatives= %d", componentLabel, valueIndex, numberOfDerivatives - 1 );
1165  }
1166 
1167  FieldExport_FieldDerivateLabels( session, numberOfDerivatives, derivatives );
1168 
1169  return session->error;
1170 }
1171 
1172 
1173 /*
1174  Public API implementation
1175 */
1176 
1177 int FieldExport_InterpolationType( const int interpType )
1178 {
1179  if(interpType == 1)
1180  {
1182  }
1183  else if(interpType == 2)
1184  {
1186  }
1187  else if(interpType == 3)
1188  {
1190  }
1191  else if(interpType == 4)
1192  {
1194  }
1195  else if(interpType == 5)
1196  {
1198  }
1199  else if(interpType == 6)
1200  {
1202  }
1203  else
1204  {
1206  }
1207 
1208 }
1209 
1210 
1211 int FieldExport_OpenSession( const int type, const char *const name, int * const handle )
1212 {
1213  if( type == EXPORT_TYPE_FILE )
1214  {
1215  return FieldExport_File_OpenSession( name, handle );
1216  }
1217  else
1218  {
1220  }
1221 }
1222 
1223 
1224 int FieldExport_Group( const int handle, const char *const label )
1225 {
1226  SessionListEntry *session = FieldExport_GetSession( handle );
1227 
1228  if( session == NULL )
1229  {
1231  }
1232  else if( session->type == EXPORT_TYPE_FILE )
1233  {
1234  return FieldExport_File_Group( &session->fileSession, label );
1235  }
1236  else
1237  {
1239  }
1240 }
1241 
1242 
1243 int FieldExport_MeshDimensions( const int handle, const int dimensions, const int basisType )
1244 {
1245  SessionListEntry *session = FieldExport_GetSession( handle );
1246 
1247  if( session == NULL )
1248  {
1250  }
1251  else if( session->type == EXPORT_TYPE_FILE )
1252  {
1253  return FieldExport_File_MeshDimensions( &session->fileSession, dimensions, basisType );
1254  }
1255  else
1256  {
1258  }
1259 }
1260 
1261 
1262 int FieldExport_ScalingFactorCount( const int handle, const int scalingFactorCount )
1263 {
1264  SessionListEntry *session = FieldExport_GetSession( handle );
1265 
1266  if( session == NULL )
1267  {
1269  }
1270  else if( session->type == EXPORT_TYPE_FILE )
1271  {
1272  return FieldExport_File_ScalingFactorCount( &session->fileSession, scalingFactorCount );
1273  }
1274  else
1275  {
1277  }
1278 }
1279 
1280 
1281 int FieldExport_ScaleFactors( const int handle, const int numberOfXi, const int* const interpolationXi, const int numberOfScaleFactors )
1282 {
1283  SessionListEntry *session = FieldExport_GetSession( handle );
1284 
1285  if( session == NULL )
1286  {
1288  }
1289  else if( session->type == EXPORT_TYPE_FILE )
1290  {
1291  return FieldExport_File_InterpolationHeaderScale( &session->fileSession, numberOfXi, interpolationXi, numberOfScaleFactors );
1292  }
1293  else
1294  {
1296  }
1297 }
1298 
1299 
1300 int FieldExport_NodeCount( const int handle, const int nodeCount )
1301 {
1302  SessionListEntry *session = FieldExport_GetSession( handle );
1303 
1304  if( session == NULL )
1305  {
1307  }
1308  else if( session->type == EXPORT_TYPE_FILE )
1309  {
1310  return FieldExport_File_NodeCount( &session->fileSession, nodeCount );
1311  }
1312  else
1313  {
1315  }
1316 }
1317 
1318 
1319 int FieldExport_FieldCount( const int handle, const int fieldCount )
1320 {
1321  SessionListEntry *session = FieldExport_GetSession( handle );
1322 
1323  if( session == NULL )
1324  {
1326  }
1327  else if( session->type == EXPORT_TYPE_FILE )
1328  {
1329  return FieldExport_File_FieldCount( &session->fileSession, fieldCount );
1330  }
1331  else
1332  {
1334  }
1335 }
1336 
1337 
1338 int FieldExport_CoordinateVariable( const int handle, const char *variableName, const int variableNumber, int coordinateSystemType,
1339  const int componentCount )
1340 {
1341  SessionListEntry *session = FieldExport_GetSession( handle );
1342 
1343  if( session == NULL )
1344  {
1346  }
1347  else if( session->type == EXPORT_TYPE_FILE )
1348  {
1349  return FieldExport_File_CoordinateVariable( &session->fileSession, variableName, variableNumber, coordinateSystemType, componentCount );
1350  }
1351  else
1352  {
1354  }
1355 }
1356 
1357 
1358 int FieldExport_Variable( const int handle, const char *variableName, const int variableNumber, const int fieldType, const int variableType,
1359  const int componentCount )
1360 {
1361  SessionListEntry *session = FieldExport_GetSession( handle );
1362 
1363  if( session == NULL )
1364  {
1366  }
1367  else if( session->type == EXPORT_TYPE_FILE )
1368  {
1369  // need to avoid using the region path separator in names
1370  char* escapedName = (char*)malloc(strlen(variableName)+1);
1371  strcpy(escapedName, variableName);
1372  size_t i;
1373  for (i=0;i<strlen(escapedName);++i) if (escapedName[i] == '/') escapedName[i] = '_';
1374  return FieldExport_File_Variable( &session->fileSession, escapedName, variableNumber, fieldType, variableType, componentCount );
1375  }
1376  else
1377  {
1379  }
1380 }
1381 
1382 
1383 int FieldExport_CoordinateComponent( const int handle, int coordinateSystemType,
1384  const int componentNumber, const int interpType, const int numberOfXi, const int * const interpolationXi )
1385 {
1386  SessionListEntry *session = FieldExport_GetSession( handle );
1387 
1388  if( session == NULL )
1389  {
1391  }
1392  else if( session->type == EXPORT_TYPE_FILE )
1393  {
1394  return FieldExport_File_CoordinateComponent( &session->fileSession, coordinateSystemType, componentNumber, interpType, numberOfXi, interpolationXi );
1395  }
1396  else
1397  {
1399  }
1400 }
1401 
1402 
1403 int FieldExport_Component( const int handle, const int componentNumber, const int interpType, const int numberOfXi, const int * const interpolationXi )
1404 {
1405  SessionListEntry *session = FieldExport_GetSession( handle );
1406 
1407  if( session == NULL )
1408  {
1410  }
1411  else if( session->type == EXPORT_TYPE_FILE )
1412  {
1413  return FieldExport_File_Component( &session->fileSession, componentNumber, interpType, numberOfXi, interpolationXi );
1414  }
1415  else
1416  {
1418  }
1419 }
1420 
1421 
1422 int FieldExport_ElementGridSize( const int handle, const int interpType, const int numberOfXi, const int *const numberGauss )
1423 {
1424  SessionListEntry *session = FieldExport_GetSession( handle );
1425 
1426  if( session == NULL )
1427  {
1429  }
1430  else if( session->type == EXPORT_TYPE_FILE )
1431  {
1432  return FieldExport_File_ElementGridSize( &session->fileSession, interpType, numberOfXi, numberGauss );
1433  }
1434  else
1435  {
1437  }
1438 }
1439 
1440 
1441 int FieldExport_NodeScaleIndexes( const int handle, const int nodeCount, const int *const derivativeCount,
1442  const int *const elementDerivatives, const int *const nodeIndexes, const int *const scaleIndexes )
1443 {
1444  SessionListEntry *session = FieldExport_GetSession( handle );
1445 
1446  if( session == NULL )
1447  {
1449  }
1450  else if( session->type == EXPORT_TYPE_FILE )
1451  {
1452  return FieldExport_File_NodeScaleIndexes( &session->fileSession, nodeCount, derivativeCount, elementDerivatives, nodeIndexes, scaleIndexes );
1453  }
1454  else
1455  {
1457  }
1458 }
1459 
1460 
1461 int FieldExport_ElementIndex( const int handle, const int dimensionCount, const int index )
1462 {
1463  SessionListEntry *session = FieldExport_GetSession( handle );
1464 
1465  if( session == NULL )
1466  {
1468  }
1469  else if( session->type == EXPORT_TYPE_FILE )
1470  {
1471  return FieldExport_File_ElementIndex( &session->fileSession, dimensionCount, index );
1472  }
1473  else
1474  {
1476  }
1477 }
1478 
1479 
1480 int FieldExport_ElementNodeIndices( const int handle, const int nodeCount, const int* const indices )
1481 {
1482  SessionListEntry *session = FieldExport_GetSession( handle );
1483 
1484  if( session == NULL )
1485  {
1487  }
1488  else if( session->type == EXPORT_TYPE_FILE )
1489  {
1490  return FieldExport_File_ElementNodeIndices( &session->fileSession, nodeCount, indices );
1491  }
1492  else
1493  {
1495  }
1496 }
1497 
1498 
1499 int FieldExport_ElementNodeScales( const int handle, const int isFirstSet, const int scaleCount, const double* const scales )
1500 {
1501  SessionListEntry *session = FieldExport_GetSession( handle );
1502 
1503  if( session == NULL )
1504  {
1506  }
1507  else if( session->type == EXPORT_TYPE_FILE )
1508  {
1509  return FieldExport_File_ElementNodeScales( &session->fileSession, isFirstSet, scaleCount, scales );
1510  }
1511  else
1512  {
1514  }
1515 }
1516 
1517 
1518 int FieldExport_ElementGridValues( const int handle, const int isFirstSet, const int dimensionCount, const double value )
1519 {
1520  SessionListEntry *session = FieldExport_GetSession( handle );
1521 
1522  if( session == NULL )
1523  {
1525  }
1526  else if( session->type == EXPORT_TYPE_FILE )
1527  {
1528  return FieldExport_File_ElementGridValues( &session->fileSession, isFirstSet, dimensionCount, value );
1529  }
1530  else
1531  {
1533  }
1534 }
1535 
1536 
1538 {
1539  SessionListEntry *session = FieldExport_GetSession( handle );
1540 
1541  if( session == NULL )
1542  {
1544  }
1545  else if( session->type == EXPORT_TYPE_FILE )
1546  {
1547  return FieldExport_File_CloseSession( session );
1548  }
1549  else
1550  {
1552  }
1553 
1554  return FIELD_EXPORT_NO_ERROR;
1555 }
1556 
1557 
1558 int FieldExport_NodeValues( const int handle, const int nodeNumber, const int valueCount, const double* const values )
1559 {
1560  SessionListEntry *session = FieldExport_GetSession( handle );
1561 
1562  if( session == NULL )
1563  {
1565  }
1566  else if( session->type == EXPORT_TYPE_FILE )
1567  {
1568  return FieldExport_File_NodeValues( &session->fileSession, nodeNumber, valueCount, values );
1569  }
1570  else
1571  {
1573  }
1574 
1575  return FIELD_EXPORT_NO_ERROR;
1576 }
1577 
1578 
1579 int FieldExport_CoordinateDerivativeIndices( const int handle, const int componentNumber, const int coordinateSystemType,
1580  const int numberOfDerivatives, const int *const derivatives, const int valueIndex )
1581 {
1582  SessionListEntry *session = FieldExport_GetSession( handle );
1583 
1584  if( session == NULL )
1585  {
1587  }
1588  else if( session->type == EXPORT_TYPE_FILE )
1589  {
1590  return FieldExport_File_CoordinateDerivativeIndices( &session->fileSession, componentNumber, coordinateSystemType, numberOfDerivatives, derivatives, valueIndex );
1591  }
1592  else
1593  {
1595  }
1596 
1597  return FIELD_EXPORT_NO_ERROR;
1598 }
1599 
1600 
1601 int FieldExport_DerivativeIndices( const int handle, const int componentNumber, const int fieldType, const int variableType,
1602  const int numberOfDerivatives, const int *const derivatives, const int valueIndex )
1603 {
1604  SessionListEntry *session = FieldExport_GetSession( handle );
1605 
1606  if( session == NULL )
1607  {
1609  }
1610  else if( session->type == EXPORT_TYPE_FILE )
1611  {
1612  return FieldExport_File_DerivativeIndices( &session->fileSession, componentNumber, fieldType, variableType, numberOfDerivatives, derivatives, valueIndex );
1613  }
1614  else
1615  {
1617  }
1618 
1619  return FIELD_EXPORT_NO_ERROR;
1620 }
1621 
1622 int FieldExport_VersionInfo( const int handle, const int numberOfVersions )
1623 {
1624  SessionListEntry *session = FieldExport_GetSession( handle );
1625 
1626  if( session == NULL )
1627  {
1629  }
1630  else if( session->type == EXPORT_TYPE_FILE )
1631  {
1632  if (numberOfVersions > 1) {
1633  return FieldExport_FPrintf( &session->fileSession, ", #Versions=%d", numberOfVersions );
1634  }
1635  }
1636  else
1637  {
1639  }
1640 
1641  return FIELD_EXPORT_NO_ERROR;
1642 }
1643 
1645 {
1646  SessionListEntry *session = FieldExport_GetSession( handle );
1647 
1648  if( session == NULL )
1649  {
1651  }
1652  else if( session->type == EXPORT_TYPE_FILE )
1653  {
1654  return FieldExport_FPrintf( &session->fileSession, "\n" );
1655  }
1656  else
1657  {
1659  }
1660 
1661  /* Shouldn't get to here */
1663 }
static int FieldExport_File_ElementNodeScales(FileSession *session, const int isFirstSet, const int scaleCount, const double *const scales)
Definition: FieldExport.c:846
static int FieldExport_File_Component(FileSession *const session, const int componentNumber, const int interpType, const int numberOfXi, const int *const interpolationXi)
Definition: FieldExport.c:698
int FieldExport_CoordinateComponent(const int handle, int coordinateSystemType, const int componentNumber, const int interpType, const int numberOfXi, const int *const interpolationXi)
Definition: FieldExport.c:1383
#define PART_DERIV_S1_S2_S3
Definition: FieldExport.c:125
static char * FieldExport_GetCoordinateVariableLabel(int coordinateSystemType)
Definition: FieldExport.c:588
#define PART_DERIV_S3_S3
Definition: FieldExport.c:122
FILE * file
Definition: FieldExport.c:147
#define BASIS_SIMPLEX_TYPE
Definition: FieldExport.c:70
#define FIELD_DELUDELT_VARIABLE_TYPE
Definition: FieldExport.c:98
static int FieldExport_File_ElementNodeIndices(FileSession *session, const int nodeCount, const int *const indices)
Definition: FieldExport.c:829
static char * FieldExport_GetCoordinateComponentLabel(int coordinateSystemType, int componentNumber)
Definition: FieldExport.c:607
#define PART_DERIV_S1
Definition: FieldExport.c:116
#define FIELD_U1_VARIABLE_TYPE
Definition: FieldExport.c:102
#define BASIS_CUBIC_LAGRANGE_INTERPOLATION
Definition: FieldExport.c:75
static SessionListEntry sessions
Definition: FieldExport.c:172
static int FieldExport_File_CoordinateDerivativeIndices(FileSession *session, const int componentNumber, int coordinateSystemType, const int numberOfDerivatives, const int *const derivatives, const int valueIndex)
Definition: FieldExport.c:1152
static int FieldExport_File_NodeValues(FileSession *session, const int nodeNumber, const int valueCount, const double *const values)
Definition: FieldExport.c:1019
int FieldExport_ScalingFactorCount(const int handle, const int scalingFactorCount)
Definition: FieldExport.c:1262
#define FIELD_GEOMETRIC_GENERAL_TYPE
Definition: FieldExport.c:94
#define BASIS_LINEAR_SIMPLEX_INTERPOLATION
Definition: FieldExport.c:79
#define FIELD_IO_INTERPOLATION_HEADER_CONSTANT
Definition: FieldExport.c:87
int FieldExport_NodeValues(const int handle, const int nodeNumber, const int valueCount, const double *const values)
Definition: FieldExport.c:1558
static int FieldExport_File_Group(FileSession *const session, const char *const label)
Definition: FieldExport.c:231
int FieldExport_ElementGridValues(const int handle, const int isFirstSet, const int dimensionCount, const double value)
Definition: FieldExport.c:1518
int FieldExport_OpenSession(const int type, const char *const name, int *const handle)
Definition: FieldExport.c:1211
#define FIELD_GEOMETRIC_TYPE
Definition: FieldExport.c:90
#define PART_DERIV_S4
Definition: FieldExport.c:126
#define FIELD_EXPORT_ERROR_HDF5_ERROR
#define BASIS_CUBIC_SIMPLEX_INTERPOLATION
Definition: FieldExport.c:81
#define FIELD_FIBRE_TYPE
Definition: FieldExport.c:91
int type
Definition: FieldExport.c:160
#define FIELD_IO_INTERPOLATION_HEADER_GAUSS
Definition: FieldExport.c:86
#define BASIS_QUADRATIC_LAGRANGE_INTERPOLATION
Definition: FieldExport.c:74
#define FIELD_EXPORT_ERROR_CLOSED_HANDLE
#define PART_DERIV_S1_S4
Definition: FieldExport.c:128
int FieldExport_InterpolationType(const int interpType)
Definition: FieldExport.c:1177
#define BASIS_QUADRATIC_SIMPLEX_INTERPOLATION
Definition: FieldExport.c:80
static int FieldExport_File_CloseSession(SessionListEntry *session)
Definition: FieldExport.c:939
int FieldExport_ElementGridSize(const int handle, const int interpType, const int numberOfXi, const int *const numberGauss)
Definition: FieldExport.c:1422
#define FIELD_EXPORT_ERROR_UNKNOWN_TYPE
int FieldExport_VersionInfo(const int handle, const int numberOfVersions)
Definition: FieldExport.c:1622
int FieldExport_Variable(const int handle, const char *variableName, const int variableNumber, const int fieldType, const int variableType, const int componentCount)
Definition: FieldExport.c:1358
#define FIELD_EXPORT_ERROR_FILE_IO
#define FIELD_EXPORT_NO_ERROR
#define PART_DERIV_S4_S4
Definition: FieldExport.c:127
#define FIELD_DELUDELN_VARIABLE_TYPE
Definition: FieldExport.c:97
struct _SessionListEntry SessionListEntry
static int FieldExport_File_FieldCount(FileSession *const session, const int fieldCount)
Definition: FieldExport.c:645
static int FieldExport_File_Variable(FileSession *const session, const char *variableName, const int variableIndex, const int fieldType, const int variableType, const int componentCount)
Definition: FieldExport.c:662
static int FieldExport_File_CoordinateComponent(FileSession *const session, int coordinateSystemType, const int componentNumber, const int interpType, const int numberOfXi, const int *const interpolationXi)
Definition: FieldExport.c:673
#define BASIS_CUBIC_HERMITE_INTERPOLATION
Definition: FieldExport.c:76
#define PART_DERIV_S2_S3
Definition: FieldExport.c:124
#define PART_DERIV_S2
Definition: FieldExport.c:118
Definition: FieldExport.c:156
int FieldExport_ElementNodeIndices(const int handle, const int nodeCount, const int *const indices)
Definition: FieldExport.c:1480
#define FIELD_IO_INTERPOLATION_HEADER_GRID
Definition: FieldExport.c:85
static int FieldExport_File_ElementGridValues(FileSession *session, const int isFirstSet, const int valueCount, const double value)
Definition: FieldExport.c:868
static int FieldExport_File_MeshDimensions(FileSession *const session, const int dimensions, const int basisType)
Definition: FieldExport.c:238
static int FieldExport_File_ScalingFactorCount(FileSession *const session, const int scalingFactorCount)
Definition: FieldExport.c:261
#define FIELD_U2_VARIABLE_TYPE
Definition: FieldExport.c:103
static int nextHandle
Definition: FieldExport.c:174
#define FIELD_EXPORT_ERROR_FILE_WRITE
static int FieldExport_File_OpenSession(const char *const name, int *const handle)
Definition: FieldExport.c:891
int FieldExport_CoordinateVariable(const int handle, const char *variableName, const int variableNumber, int coordinateSystemType, const int componentCount)
Definition: FieldExport.c:1338
#define PART_DERIV_S2_S3_S4
Definition: FieldExport.c:133
#define FIELD_EXPORT_ERROR_BAD_HANDLE
int FieldExport_DerivativeIndices(const int handle, const int componentNumber, const int fieldType, const int variableType, const int numberOfDerivatives, const int *const derivatives, const int valueIndex)
Definition: FieldExport.c:1601
static int FieldExport_File_ElementIndex(FileSession *session, const int dimensionCount, const int elementIndex)
Definition: FieldExport.c:810
#define BASIS_QUADRATIC1_HERMITE_INTERPOLATION
Definition: FieldExport.c:77
int handle
Definition: FieldExport.c:158
int FieldExport_CoordinateDerivativeIndices(const int handle, const int componentNumber, const int coordinateSystemType, const int numberOfDerivatives, const int *const derivatives, const int valueIndex)
Definition: FieldExport.c:1579
static int FieldExport_FieldDerivateLabels(FileSession *session, const int numberOfDerivatives, const int *const derivatives)
Definition: FieldExport.c:1053
struct _SessionListEntry * next
Definition: FieldExport.c:167
static int FieldExport_File_ElementGridSize(FileSession *const session, const int interpType, const int numberOfXi, const int *const numberGauss)
Definition: FieldExport.c:712
#define FIELD_EXPORT_ERROR_UNKNOWN_INTERPOLATION
static SessionListEntry * FieldExport_GetSession(const int handle)
Definition: FieldExport.c:209
#define BASIS_LAGRANGE_HERMITE_TP_TYPE
Definition: FieldExport.c:69
int FieldExport_NodeScaleIndexes(const int handle, const int nodeCount, const int *const derivativeCount, const int *const elementDerivatives, const int *const nodeIndexes, const int *const scaleIndexes)
Definition: FieldExport.c:1441
static int FieldExport_File_InterpolationHeader(FileSession *const session, const int labelType, const int numberOfXi, const int *const interpolationXi)
Definition: FieldExport.c:267
int FieldExport_FieldCount(const int handle, const int fieldCount)
Definition: FieldExport.c:1319
static int FieldExport_File_NodeScaleIndexes(FileSession *const session, const int nodeCount, const int *const derivativeCount, const int *const elementDerivatives, const int *const nodeIndexes, const int *const scaleIndexes)
Definition: FieldExport.c:772
int FieldExport_ElementNodeScales(const int handle, const int isFirstSet, const int scaleCount, const double *const scales)
Definition: FieldExport.c:1499
FileSession fileSession
Definition: FieldExport.c:164
static int FieldExport_File_InterpolationHeaderScale(FileSession *const session, const int numberOfXi, const int *const interpolationXi, const int numberOfScaleFactors)
Definition: FieldExport.c:394
#define BASIS_QUADRATIC2_HERMITE_INTERPOLATION
Definition: FieldExport.c:78
int FieldExport_ElementIndex(const int handle, const int dimensionCount, const int index)
Definition: FieldExport.c:1461
int FieldExport_Component(const int handle, const int componentNumber, const int interpType, const int numberOfXi, const int *const interpolationXi)
Definition: FieldExport.c:1403
int FieldExport_EndComponent(const int handle)
Definition: FieldExport.c:1644
int FieldExport_MeshDimensions(const int handle, const int dimensions, const int basisType)
Definition: FieldExport.c:1243
#define FIELD_GENERAL_TYPE
Definition: FieldExport.c:92
static int FieldExport_File_NodeCount(FileSession *const session, const int nodeCount)
Definition: FieldExport.c:639
#define PART_DERIV_S1_S3
Definition: FieldExport.c:123
#define FIELD_MATERIAL_TYPE
Definition: FieldExport.c:93
#define EXPORT_TYPE_FILE
int FieldExport_ScaleFactors(const int handle, const int numberOfXi, const int *const interpolationXi, const int numberOfScaleFactors)
Definition: FieldExport.c:1281
#define NO_PART_DERIV
Definition: FieldExport.c:111
#define FIELD_V_VARIABLE_TYPE
Definition: FieldExport.c:100
static int FieldExport_FPrintf(FileSession *const session, const char *format,...)
Definition: FieldExport.c:191
int FieldExport_CloseSession(const int handle)
Definition: FieldExport.c:1537
#define FIELD_U_VARIABLE_TYPE
Definition: FieldExport.c:96
#define PART_DERIV_S2_S2
Definition: FieldExport.c:119
#define PART_DERIV_S1_S1
Definition: FieldExport.c:117
static int FieldExport_File_DerivativeIndices(FileSession *session, const int componentNumber, const int fieldType, const int variableType, const int numberOfDerivatives, const int *const derivatives, const int valueIndex)
Definition: FieldExport.c:1140
#define PART_DERIV_S1_S2_S4
Definition: FieldExport.c:131
#define FIELD_EXPORT_ERROR_UNKNOWN_LABEL_TYPE
int FieldExport_NodeCount(const int handle, const int nodeCount)
Definition: FieldExport.c:1300
#define FIELD_IO_INTERPOLATION_HEADER_NODAL
Definition: FieldExport.c:84
int FieldExport_Group(const int handle, const char *const label)
Definition: FieldExport.c:1224
static char * FieldExport_GetVariableLabel(const int fieldType, const int variableType)
Definition: FieldExport.c:490
static int FieldExport_File_CoordinateVariable(FileSession *const session, const char *variableName, const int variableIndex, int coordinateSystemType, const int componentCount)
Definition: FieldExport.c:651
#define BASIS_LINEAR_LAGRANGE_INTERPOLATION
Definition: FieldExport.c:73
#define PART_DERIV_S1_S2
Definition: FieldExport.c:120
#define PART_DERIV_S3_S4
Definition: FieldExport.c:130
#define PART_DERIV_S2_S4
Definition: FieldExport.c:129
#define COORDINATE_RECTANGULAR_CARTESIAN_TYPE
Definition: FieldExport.c:105
#define PART_DERIV_S3
Definition: FieldExport.c:121
#define PART_DERIV_S1_S3_S4
Definition: FieldExport.c:132
#define FIELD_DEL2UDELT2_VARIABLE_TYPE
Definition: FieldExport.c:99
#define EXPORT_TYPE_CLOSED
#define PART_DERIV_S1_S2_S3_S4
Definition: FieldExport.c:134