|
funkalicious 0.1
|
00001 /* 00002 ** write_ascii_slice.c 00003 ** 00004 ** Made by (Johnny Q. Hacker) 00005 ** Login <solarion@borkborkbork> 00006 ** 00007 Copyright (C) 2010 Joseph Pingenot 00008 00009 This program is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Affero General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Affero General Public License for more details. 00018 00019 You should have received a copy of the GNU Affero General Public License 00020 along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 00022 ** Started on Thu Feb 25 14:19:00 2010 Johnny Q. Hacker 00023 ** Last update Sun May 12 01:17:25 2002 Speed Blue 00024 */ 00025 00026 #include "write_ascii_slice.h" 00027 #include "gcc_hints.h" 00028 00029 #define LIBPOSTPROC_WRITE_ASCII_SLICE_DOMAIN 2378 00030 00031 hotfunc ___const ___always_inline long unsigned int get_assignment_index3(int x, int y, int z, int Nx, int Ny) { 00032 return x + Nx*(y + Ny*(z)); 00033 } 00034 00035 GError* postproc_write_ascii_slice(int Nd, const int* sizes, enum postproc_type t, const void* buffer, enum postproc_coord coord, int value, GFile* base) { 00036 if(Nd != 3) { 00037 return g_error_new(LIBPOSTPROC_WRITE_ASCII_SLICE_DOMAIN, 1, "libpostproc::write_ascii_slice.c::postproc_write_ascii_slice: Dimensions other then 3 not supported."); 00038 } 00039 GError *e = NULL; 00040 GError *err; 00041 GString *s = g_string_new("gridslice_");; 00042 switch(coord) { 00043 case POSTPROC_X: 00044 g_string_append_printf(s, "X=%d.pdata", coord); 00045 break; 00046 case POSTPROC_Y: 00047 g_string_append_printf(s, "Y=%d.pdata", coord); 00048 break; 00049 case POSTPROC_Z: 00050 g_string_append_printf(s, "Z=%d.pdata", coord); 00051 break; 00052 } 00053 GFile* f; 00054 if(base == NULL) { 00055 f = g_file_new_for_path(s->str); 00056 }else{ 00057 f = g_file_resolve_relative_path(base, s->str); 00058 } 00059 GFileIOStream *gfos = g_file_create_readwrite(f, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &e); 00060 if(e != NULL) { 00061 return e; 00062 } 00063 GOutputStream *os = g_io_stream_get_output_stream((GIOStream*)gfos); 00064 GDataOutputStream *dos = g_data_output_stream_new(os); 00065 g_string_printf(s, "#index\tmaterial\n"); 00066 e=NULL; 00067 char *str; 00068 g_data_output_stream_put_string(dos, s->str, NULL, &e); 00069 if(e != NULL) { 00070 err = e; 00071 g_string_free(s, TRUE); 00072 e=NULL; 00073 g_io_stream_close((GIOStream*)gfos, NULL, &e); 00074 if(e != NULL) { 00075 err = g_error_new(LIBPOSTPROC_WRITE_ASCII_SLICE_DOMAIN, 1, "libpostprocess::write_ascii_slice.c::write_ascii_slice: had an error (%s) while writing string (%s), but had another error (%s) while closing the file (%s)!\n", (err)->message, s->str, e->message, str=g_file_get_uri(f)); 00076 g_free(str); 00077 } 00078 return err; 00079 } 00080 00081 return NULL; 00082 }