[bd84570] | 1 | /* |
---|
| 2 | * Copyright (C) 2015, UChicago Argonne, LLC |
---|
| 3 | * All Rights Reserved |
---|
| 4 | * |
---|
| 5 | * Generic IO (ANL-15-066) |
---|
| 6 | * Hal Finkel, Argonne National Laboratory |
---|
| 7 | * |
---|
| 8 | * OPEN SOURCE LICENSE |
---|
| 9 | * |
---|
| 10 | * Under the terms of Contract No. DE-AC02-06CH11357 with UChicago Argonne, |
---|
| 11 | * LLC, the U.S. Government retains certain rights in this software. |
---|
| 12 | * |
---|
| 13 | * Redistribution and use in source and binary forms, with or without |
---|
| 14 | * modification, are permitted provided that the following conditions are met: |
---|
| 15 | * |
---|
| 16 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
| 17 | * this list of conditions and the following disclaimer. |
---|
| 18 | * |
---|
| 19 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 20 | * notice, this list of conditions and the following disclaimer in the |
---|
| 21 | * documentation and/or other materials provided with the distribution. |
---|
| 22 | * |
---|
| 23 | * 3. Neither the names of UChicago Argonne, LLC or the Department of Energy |
---|
| 24 | * nor the names of its contributors may be used to endorse or promote |
---|
| 25 | * products derived from this software without specific prior written |
---|
| 26 | * permission. |
---|
| 27 | * |
---|
| 28 | * ***************************************************************************** |
---|
| 29 | * |
---|
| 30 | * DISCLAIMER |
---|
| 31 | * THE SOFTWARE IS SUPPLIED “AS IS” WITHOUT WARRANTY OF ANY KIND. NEITHER THE |
---|
| 32 | * UNTED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR |
---|
| 33 | * UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, |
---|
| 34 | * EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE |
---|
| 35 | * ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, DATA, APPARATUS, |
---|
| 36 | * PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE |
---|
| 37 | * PRIVATELY OWNED RIGHTS. |
---|
| 38 | * |
---|
| 39 | * ***************************************************************************** |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | #include <GenericIO.h> |
---|
| 43 | |
---|
| 44 | #include <stdint.h> |
---|
| 45 | #include <sstream> |
---|
| 46 | |
---|
| 47 | template <class T> |
---|
[9796d0a] | 48 | void read_gio(char* file_name, std::string var_name, T*& data, int field_count){ |
---|
[bd84570] | 49 | gio::GenericIO reader(file_name); |
---|
| 50 | reader.openAndReadHeader(gio::GenericIO::MismatchAllowed); |
---|
| 51 | int num_ranks = reader.readNRanks(); |
---|
| 52 | uint64_t max_size = 0; |
---|
| 53 | uint64_t rank_size[num_ranks]; |
---|
| 54 | for(int i =0;i<num_ranks;++i){ |
---|
| 55 | rank_size[i] = reader.readNumElems(i); |
---|
| 56 | if(max_size < rank_size[i]) |
---|
| 57 | max_size = rank_size[i]; |
---|
| 58 | } |
---|
[9796d0a] | 59 | T* rank_data = new T[max_size*field_count+reader.requestedExtraSpace()/sizeof(T)]; |
---|
[bd84570] | 60 | int64_t offset =0; |
---|
[9796d0a] | 61 | reader.addScalarizedVariable(var_name,rank_data,field_count, |
---|
| 62 | gio::GenericIO::VarHasExtraSpace); |
---|
[bd84570] | 63 | for(int i=0;i<num_ranks;++i){ |
---|
| 64 | reader.readData(i,false); |
---|
[9796d0a] | 65 | std::copy(rank_data,rank_data+rank_size[i]*field_count,data+offset); |
---|
| 66 | offset +=rank_size[i]*field_count; |
---|
[bd84570] | 67 | } |
---|
| 68 | delete [] rank_data; |
---|
| 69 | reader.close(); |
---|
| 70 | } |
---|
| 71 | extern "C" int64_t get_elem_num(char* file_name); |
---|
| 72 | |
---|
[9796d0a] | 73 | extern "C" void read_gio_float (char* file_name, char* var_name, float* data, int field_count); |
---|
| 74 | extern "C" void read_gio_double(char* file_name, char* var_name, double* data, int field_count); |
---|
| 75 | extern "C" void read_gio_int32 (char* file_name, char* var_name, int* data, int field_count); |
---|
| 76 | extern "C" void read_gio_int64 (char* file_name, char* var_name, int64_t* data, int field_count); |
---|
[bd84570] | 77 | enum var_type{ |
---|
| 78 | float_type=0, |
---|
| 79 | double_type=1, |
---|
| 80 | int32_type=2, |
---|
| 81 | int64_type=3, |
---|
| 82 | type_not_found=9, |
---|
| 83 | var_not_found=10 |
---|
| 84 | }; |
---|
| 85 | extern "C" var_type get_variable_type(char* file_name,char* var_name); |
---|
[9796d0a] | 86 | extern "C" int get_variable_field_count(char* file_name,char* var_name); |
---|
[bd84570] | 87 | extern "C" void inspect_gio(char* file_name); |
---|