File: avtLODIFileFormat.C

package info (click to toggle)
paraview 4.0.1-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 526,572 kB
  • sloc: cpp: 2,284,430; ansic: 816,374; python: 239,936; xml: 70,162; tcl: 48,295; fortran: 39,116; yacc: 5,466; java: 3,518; perl: 3,107; lex: 1,620; sh: 1,555; makefile: 932; asm: 471; pascal: 228
file content (724 lines) | stat: -rw-r--r-- 23,042 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400124
* All rights reserved.
*
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

#include <avtLODIFileFormat.h>
#include <NETCDFFileObject.h>
#include "vtk_netcdf.h"

#include <avtDatabaseMetaData.h>
#include <avtMTSDFileFormatInterface.h>

#include <vtkRectilinearGrid.h>
#include <vtkUnsignedCharArray.h>
#include <vtkShortArray.h>
#include <vtkIntArray.h>
#include <vtkLongArray.h>
#include <vtkFloatArray.h>
#include <vtkDoubleArray.h>

#include <InvalidVariableException.h>
#include <DebugStream.h>

// ****************************************************************************
// Method: avtLODIFileFormat::Identify
//
// Purpose: 
//   This method checks to see if the file is a LODI file.
//
// Arguments:
//   fileObject : The file to check.
//
// Returns:    True if the file is a LODI file; False otherwise.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 15 18:04:15 PST 2005
//
// Modifications:
//   
// ****************************************************************************

bool
avtLODIFileFormat::Identify(NETCDFFileObject *fileObject)
{
    bool     isLODI = false;

    std::string create_code;
    if(fileObject->ReadStringAttribute("create_code", create_code))
    {
        isLODI = create_code == "LODI";
    }

    return isLODI;
}

// ****************************************************************************
// Method: avtLODIFileFormat::CreateInterface
//
// Purpose: 
//   This method creates a MTSD file format interface containing LODI 
//   file format readers.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 15 18:05:07 PST 2005
//
// Modifications:
//    Jeremy Meredith, Thu Jan 28 12:28:07 EST 2010
//    MTSD now accepts grouping multiple files into longer sequences, so
//    its interface has changed to accept both a number of timestep groups
//    and a number of blocks.
//   
// ****************************************************************************

avtFileFormatInterface *
avtLODIFileFormat::CreateInterface(NETCDFFileObject *f,
    const char *const *list, int nList, int nBlock)
{
    int nTimestepGroups = nList / nBlock;
    avtMTSDFileFormat ***ffl = new avtMTSDFileFormat**[nTimestepGroups];
    for (int i = 0 ; i < nTimestepGroups ; i++)
    {
        ffl[i] = new avtMTSDFileFormat*[nBlock];
        for (int j = 0 ; j < nBlock ; j++)
        {
            ffl[i][j] = NULL;
        }
    }

    TRY
    {
        for (int i = 0 ; i < nTimestepGroups ; i++)
        {
            for (int j = 0 ; j < nBlock ; j++)
            {
                ffl[i][j] = new avtLODIFileFormat(list[i*nBlock+j],
                                                  (i==0) ? f : NULL);
            }
        }
    }
    CATCH(VisItException)
    {
        for (int i = 0 ; i < nTimestepGroups ; i++)
        {
            for (int j = 0 ; j < nBlock ; j++)
            {
                if(ffl[i][j] != 0)
                    delete ffl[i][j];
            }
            delete [] ffl[i];
        }
        delete [] ffl;
        RETHROW;
    }
    ENDTRY

    return new avtMTSDFileFormatInterface(ffl, nTimestepGroups, nBlock);
}

// ****************************************************************************
// Method: avtLODIFileFormat::avtLODIFileFormat
//
// Purpose: 
//   Constructor for the avtLODIFileFormat file format.
//
// Arguments:
//   filename : The name of the file to read.
//   f        : The file object to use when reading the netcdf file.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 22 16:09:02 PST 2005
//
// Modifications:
//   
// ****************************************************************************

avtLODIFileFormat::avtLODIFileFormat(const char *filename) :
    avtMTSDFileFormat(&filename, 1), times()
{
    fileObject = new NETCDFFileObject(filename);
    timesRead = false;
}

avtLODIFileFormat::avtLODIFileFormat(const char *filename,
    NETCDFFileObject *f) : avtMTSDFileFormat(&filename, 1), times()
{
    fileObject = f;
    timesRead = false;
}

// ****************************************************************************
// Method: avtLODIFileFormat::~avtLODIFileFormat
//
// Purpose: 
//   Destructor for the avtLODIFileFormat class.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 22 16:09:44 PST 2005
//
// Modifications:
//   
// ****************************************************************************

avtLODIFileFormat::~avtLODIFileFormat()
{
    FreeUpResources();

    delete fileObject;
}

// ****************************************************************************
// Method: avtLODIFileFormat::FreeUpResources
//
// Purpose: 
//   Called when the file format needs to free up resources.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 22 16:41:08 PST 2005
//
// Modifications:
//   
// ****************************************************************************

void
avtLODIFileFormat::FreeUpResources()
{
    debug4 << "avtLODIFileFormat::FreeUpResources" << endl;

    fileObject->Close();
}

// ****************************************************************************
// Method: avtLODIFileFormat::ActivateTimestep
//
// Purpose: 
//   Called to activate the specified time step.
//
// Arguments:
//   ts : The new active time step.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 22 16:41:29 PST 2005
//
// Modifications:
//   
// ****************************************************************************

void
avtLODIFileFormat::ActivateTimestep(int ts)
{
    debug4 << "avtLODIFileFormat::ActivateTimestep: ts=" << ts << endl;
    ReadTimes();
}

// ****************************************************************************
// Method: avtLODIFileFormat::ReadTimes
//
// Purpose: 
//   Reads in the times to be returned by this reader.
//
// Returns:    True if the times were read; False otherwise.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 15 18:07:27 PST 2005
//
// Modifications:
//   
// ****************************************************************************

bool
avtLODIFileFormat::ReadTimes()
{
    const char *mName = "avtLODIFileFormat::ReadTimes: ";
    debug4 << mName << endl;
    if(!timesRead)
    {
        // Set the times
        TypeEnum t = NO_TYPE;
        int ndims = 0, *dims = 0;
        void *values = 0;
        if(fileObject->ReadVariable("elapsed_time", &t, &ndims, &dims, &values))
        {
            if(ndims == 1 && t == DOUBLEARRAY_TYPE)
            {
                debug4 << mName << "times={";
                double *dptr = (double *)values;
                intVector cycles;
                for(int i = 0; i < dims[0]; ++i)
                {
                    debug4 << ", " << *dptr;
                    cycles.push_back(i);
                    times.push_back(*dptr++);
                }
                debug4 << "}" << endl;
                timesRead = true;
            }
            else
            {
                debug4 << mName << "elapsed_time was read but it was the "
                       << "wrong type." << endl;
            }

            delete [] dims;
            free_void_mem(values, t);
        }
        else
        {
            debug4 << mName << "Could not read elapsed_time array!" << endl;
        }
    }

    return timesRead;
}

// ****************************************************************************
// Method: avtLODIFileFormat::GetNTimesteps
//
// Purpose: 
//   Returns the number of time states in this database.
//
// Returns:    The number of time states.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 15 18:08:06 PST 2005
//
// Modifications:
//   
// ****************************************************************************

int
avtLODIFileFormat::GetNTimesteps()
{
    const char *mName = "avtLODIFileFormat::GetNTimesteps: ";
    debug4 << mName << endl;
    ReadTimes();
    debug4 << mName << "returning " << times.size() << endl;
    return times.size();
}

// ****************************************************************************
// Method: avtLODIFileFormat::GetTimes
//
// Purpose: 
//   Returns the times in the file.
//
// Arguments:
//   t : The times to be returned.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 15 18:08:32 PST 2005
//
// Modifications:
//   
// ****************************************************************************

void
avtLODIFileFormat::GetTimes(doubleVector &t)
{
    debug4 << "avtLODIFileFormat::GetTimes" << endl;
    ReadTimes();
    t = times;
}

// ****************************************************************************
// Method: avtLODIFileFormat::PopulateDatabaseMetaData
//
// Purpose: 
//   Returns information about the variables in the file.
//
// Arguments:
//   md : The metadata object to populate with variable names.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 22 16:15:51 PST 2005
//
// Modifications:
//    Jeremy Meredith, Thu Aug 25 12:55:29 PDT 2005
//    Added group origin to mesh metadata constructor.
//
//    Mark C. Miller, Wed Apr 22 13:48:13 PDT 2009
//    Changed interface to DebugStream to obtain current debug level.
// ****************************************************************************

void
avtLODIFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
    const char *mName = "avtLODIFileFormat::PopulateDatabaseMetaData: ";

    debug4 << mName << endl;
    if(DebugStream::Level4())
        fileObject->PrintFileContents(DebugStream::Stream4());

    // Assemble a database title.
    std::string comment(GetType()), titleString, create_version, 
                create_date_time;
    if(fileObject->ReadStringAttribute("title", titleString))
    {
        comment += (std::string(" database: title=") + titleString);

        if(fileObject->ReadStringAttribute("create_version", create_version))
            comment += (std::string(", create_version=") + create_version);

        if(fileObject->ReadStringAttribute("create_date_time", create_date_time))
            comment += (std::string(", create_date_time=") + create_date_time);

        md->SetDatabaseComment(comment);
    }

    TypeEnum t = NO_TYPE;
    int ndims = 0, *dims = 0;
    if(fileObject->InqVariable("concen", &t, &ndims, &dims))
    {
        std::string meshName("mesh");
        avtMeshMetaData *mmd = new avtMeshMetaData(meshName, 
                              1, 1, 1, 0, ndims-1, ndims-1, AVT_RECTILINEAR_MESH);
        fileObject->ReadStringAttribute("cgridx", "units", mmd->xUnits);
        fileObject->ReadStringAttribute("cgridy", "units", mmd->yUnits);
        md->Add(mmd);
        delete [] dims;

        int concen_ndims = 0, *concen_dims = 0;
        if(fileObject->InqVariable("concen", &t, &concen_ndims, &concen_dims))
        {
            avtScalarMetaData *smd = new avtScalarMetaData("concen",
                        meshName, AVT_ZONECENT);
            smd->hasUnits = fileObject->ReadStringAttribute("concen", "units", smd->units);
            md->Add(smd);
            delete [] concen_dims;
        }

        if(ndims-1 == 2)
        {
            int ac_ndims = 0, *ac_dims = 0;
            if(fileObject->InqVariable("area_cell", &t, &ac_ndims, &ac_dims))
            {
                avtScalarMetaData *smd = new avtScalarMetaData("area_cell",
                            meshName, AVT_ZONECENT);
                smd->hasUnits = fileObject->ReadStringAttribute("area_cell", "units", smd->units);
                md->Add(smd);
                delete [] ac_dims;
            }

            int zgij_ndims = 0, *zgij_dims = 0;
            if(fileObject->InqVariable("zgij", &t, &zgij_ndims, &zgij_dims))
            {
                avtScalarMetaData *smd = new avtScalarMetaData("zgij",
                            meshName, AVT_ZONECENT);
                smd->hasUnits = fileObject->ReadStringAttribute("zgij", "units", smd->units);
                md->Add(smd);
                delete [] zgij_dims;
            }
        }
    }
}

// ****************************************************************************
// Method: avtLODIFileFormat::GetMesh
//
// Purpose: 
//   This method returns the mesh for the specified time state.
//
// Arguments:
//   ts  : The time state for which to return the mesh.
//   var : The mesh to fetch.
//
// Returns:    A vtkDataSet or 0.
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 22 17:21:35 PST 2005
//
// Modifications:
//   
// ****************************************************************************

vtkDataSet *
avtLODIFileFormat::GetMesh(int ts, const char *var)
{
    const char *mName = "avtLODIFileFormat::GetMesh: ";
    debug4 << mName << "ts=" << ts
           << ", var=" << var << endl;
    vtkDataSet *retval = 0;

    if(strcmp(var, "mesh") == 0)
    {
        TypeEnum t = NO_TYPE;
        int concen_ndims = 0, *concen_dims = 0;
        if(fileObject->InqVariable("concen", &t, &concen_ndims, &concen_dims))
        {
            delete [] concen_dims;
            if(concen_ndims-1 == 2)
            {
                // Read the X and Y coordinates.
                bool err = false;
                TypeEnum xt = NO_TYPE, yt = NO_TYPE;
                int xndims = 0, yndims = 0, *xdims = 0, *ydims = 0;
                void *xvals = 0, *yvals = 0;
                fileObject->ReadVariable("cgridx", &xt, &xndims, &xdims, &xvals);
                fileObject->ReadVariable("cgridy", &yt, &yndims, &ydims, &yvals);
                if(xvals != 0 && xt == DOUBLEARRAY_TYPE &&
                   yvals != 0 && yt == DOUBLEARRAY_TYPE)
                {
                    //
                    // Populate the coordinates.
                    //
                    int    dims[3];
                    dims[0] = xdims[0];
                    dims[1] = ydims[0];
                    dims[2] = 1;
                    const double *coordinate[3];
                    coordinate[0] = (const double *)xvals;
                    coordinate[1] = (const double *)yvals;
                    coordinate[2] = 0;
                    const char *coordLabels[3] = {"X coords", "Y coords", "Z coords"};
                    vtkDoubleArray *coords[3];
                    for (int i = 0 ; i < 3 ; i++)
                    {
                        // Default number of components for an array is 1.
                        coords[i] = vtkDoubleArray::New();
                        coords[i]->SetNumberOfTuples(dims[i]);

                        if(i < 2)
                        {
                            debug4 << mName << coordLabels[i] << " size=" << dims[i]
                                   << ", values = {";
                            for (int j = 0 ; j < dims[i] ; j++)
                            {
                                coords[i]->SetComponent(j, 0, coordinate[i][j]);
                                debug4 << ", " << coordinate[i][j];
                            }
                            debug4 << "}" << endl;
                        }
                        else
                            coords[i]->SetComponent(0, 0, 0.);
                    }

                    vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New(); 
                    rgrid->SetDimensions(dims);
                    rgrid->SetXCoordinates(coords[0]);
                    coords[0]->Delete();
                    rgrid->SetYCoordinates(coords[1]);
                    coords[1]->Delete();
                    rgrid->SetZCoordinates(coords[2]);
                    coords[2]->Delete();

                    retval = rgrid;
                }
                else
                    err = true;

                // Clean up
                delete [] xdims;
                if(xvals != 0)
                   free_void_mem(xvals, xt);
                delete [] ydims;
                if(yvals != 0)
                   free_void_mem(yvals, yt);

                if(err)
                {
                    if(xvals == 0)
                        debug4 << mName << "error reading cgridx" << endl;
                    if(yvals == 0)
                        debug4 << mName << "error reading cgridy" << endl;
                    if(xt != DOUBLEARRAY_TYPE)
                        debug4 << mName << "cgridx was not the right type" << endl;
                    if(yt != DOUBLEARRAY_TYPE)
                        debug4 << mName << "cgridy was not the right type" << endl;

                    std::string msg("\"The variable ");
                    msg += var;
                    msg += " could not be created. Contact a VisIt developer.\"";
                    EXCEPTION1(InvalidVariableException, msg);
                }
            }
            else
            {
                std::string msg("\"The variable ");
                msg += var;
                msg += " is not 2D. Contact a VisIt developer.\"";
                EXCEPTION1(InvalidVariableException, msg);
            }
        }
        else
        {
            EXCEPTION1(InvalidVariableException, var);
        }
    }
    else
    {
        EXCEPTION1(InvalidVariableException, var);
    }

    return retval;
}

// ****************************************************************************
// Method: avtLODIFileFormat::GetVar
//
// Purpose: 
//   Reads a variable from the file and returns the values in a data array.
//
// Arguments:
//   ts  : The time state for which we want data.
//   var : The name of the variable to read.
//
// Returns:    A data array or 0.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 22 17:30:09 PST 2005
//
// Modifications:
//   
// ****************************************************************************

vtkDataArray *
avtLODIFileFormat::GetVar(int ts, const char *var)
{
    const char *mName = "avtLODIFileFormat::GetVar: ";
    debug4 << mName << "ts=" << ts
           << ", var=" << var << endl;

    vtkDataArray *retval = 0;
    bool variesOverTime = false;
    if(strcmp(var, "concen") == 0)
    {
        variesOverTime = true;
    }
    else if(strcmp(var, "area_cell") == 0 ||
            strcmp(var, "zgij") == 0)
    {
        variesOverTime = false;
    }
    else
    {
        EXCEPTION1(InvalidVariableException, var);
    }

    TypeEnum t = NO_TYPE;
    int ndims = 0, *dims = 0;
    if(fileObject->InqVariable(var, &t, &ndims, &dims))
    {
        // Figure out the size of the chunk that we want to read.
        size_t *starts = new size_t[ndims];
        size_t *counts = new size_t[ndims];
        int nValues = 1;
        int xdimi = 0;
        int ydimi = 1;
        debug4 << mName << "var=" << var << " dims={";
        for(int i = 0; i < ndims; ++i)
        {
            starts[i] = 0;
            counts[i] = dims[i];
            nValues *= dims[i];
            if(i > 0)
                debug4 << ", ";
            debug4 << dims[i];
        }
        debug4 << "}" << endl;

        if(variesOverTime)
        {
            starts[0] = ts;
            counts[0] = 1;
            nValues /= dims[0];
            ++xdimi;
            ++ydimi;
        }

        int varId;
        fileObject->GetVarId(var, &varId);

#if 0
#define READVAR(VTK, T, FUNC) \
        {\
            VTK *arr = VTK::New();\
            arr->SetNumberOfTuples(nValues);\
            int status = FUNC(fileObject->GetFileHandle(),\
                              varId, starts, counts, (T *)arr->GetVoidPointer(0));\
            retval = arr;\
        }
#else
// Transpose the data in x,y so it looks like other related datasets
#define READVAR(VTK, T, FUNC) \
        {\
            T *data = new T[nValues];\
            VTK *arr = VTK::New();\
            int status = FUNC(fileObject->GetFileHandle(),\
                              varId, starts, counts, data);\
            arr->SetNumberOfTuples(nValues);\
            T *ptr = (T *)arr->GetVoidPointer(0);\
            int nx = dims[xdimi];\
            int ny = dims[ydimi];\
            for(int j = 0; j < ny; ++j)\
                for(int i = 0; i < nx; ++i)\
                {\
                    *ptr++ = data[i * ny + j];\
                }\
            delete [] data; \
            retval = arr;\
        }
#endif
        if(t == CHARARRAY_TYPE)
            READVAR(vtkUnsignedCharArray, char, nc_get_vara_text)
        else if(t == UCHARARRAY_TYPE)
            READVAR(vtkUnsignedCharArray, unsigned char, nc_get_vara_uchar)
        else if(t == SHORTARRAY_TYPE)
            READVAR(vtkShortArray, short, nc_get_vara_short)
        else if(t == INTEGERARRAY_TYPE)
            READVAR(vtkIntArray, int, nc_get_vara_int)
        else if(t == LONGARRAY_TYPE)
            READVAR(vtkLongArray, long, nc_get_vara_long)
        else if(t == FLOATARRAY_TYPE)
            READVAR(vtkFloatArray, float, nc_get_vara_float)
        else if(t == DOUBLEARRAY_TYPE)
            READVAR(vtkDoubleArray, double, nc_get_vara_double)

        delete [] dims;
        delete [] starts;
        delete [] counts;
    }
    else
    {
        EXCEPTION1(InvalidVariableException, var);
    }

    return retval;
}