?? gsegyfile.c
字號(hào):
/* * GSEGYLIB - Library for accessing files in SEG-Y format * * Copyright (C) 2005-2006 Vladimir Bashkardin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more av. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Author: Vladimir Bashkardin <vovizmus@users.sourceforge.net> */#include "gsegyfile.h"#include "gsegyfileaccessor.h"#include "gsegyseismicaccessor.h"#include "gsegyfile_marshal.h"G_DEFINE_TYPE (GSEGYFile, g_segy_file, G_TYPE_OBJECT)#define G_SEGY_FILE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), G_SEGY_TYPE_FILE, GSEGYFilePrivate))typedef struct _GSEGYFilePrivate GSEGYFilePrivate;struct _GSEGYFilePrivate { const gchar *filename; GIOChannel *io_channel; GSEGYFileError file_error; GSEGYFileAccessor *file_accessor;};static gboolean g_segy_file_scan_fraction_signal (GSEGYFile *self, gfloat fraction, GSEGYFileError *file_error) { gboolean return_value; g_signal_emit (self, G_SEGY_GET_FILE_CLASS (self)->scan_fraction_id, 0, fraction, file_error, &return_value); return return_value;}static void g_segy_file_scan_accessor_fraction_handler (GSEGYFileAccessor *accessor, gfloat fraction, GSEGYFileError *file_error, gpointer *data) { g_segy_file_scan_fraction_signal ((GSEGYFile*)data, fraction, file_error);}gboolean g_segy_file_set_format (GSEGYFile *self, GSEGYFormatWizard *format_wizard, GSEGYFileError *file_error) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (self); if (file_error) file_error->id = G_SEGY_FILE_NO_ERROR; else file_error = &private->file_error; if (private->file_accessor) { if (file_error) file_error->id = G_SEGY_FILE_FORMAT_ALREADY_SET; return FALSE; } private->file_accessor = g_segy_file_accessor_new (private->io_channel, format_wizard); if (private->file_accessor) { g_signal_connect (G_OBJECT (private->file_accessor), "scan_fraction", (GCallback)g_segy_file_scan_accessor_fraction_handler, (gpointer)self); return g_segy_file_accessor_scan_file (private->file_accessor, file_error); } else return FALSE;}GSEGYFile* g_segy_file_new (const gchar *filename) { return G_SEGY_FILE (g_object_new (G_SEGY_TYPE_FILE, "file_name", filename, NULL));}GSEGYFileError* g_segy_file_get_error (GSEGYFile *self) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (self); return &private->file_error;}static gboolean g_segy_file_setup (GSEGYFile *self, const gchar *filename, GSEGYFileError *file_error) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (self); if (file_error) { file_error->gerror = NULL; file_error->id = G_SEGY_FILE_NO_ERROR; } if (FALSE == g_file_test (filename, G_FILE_TEST_EXISTS)) { if (file_error) file_error->id = G_SEGY_FILE_DOES_NOT_EXIST; return FALSE; } if (FALSE == g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { if (file_error) file_error->id = G_SEGY_FILE_NON_REGULAR; return FALSE; }#ifdef DEBUG g_print ("Filename: %s\n", filename);#endif if (file_error) private->io_channel = g_io_channel_new_file (filename, "r", &file_error->gerror); else private->io_channel = g_io_channel_new_file (filename, "r", NULL); if (NULL == private->io_channel || (file_error && file_error->gerror)) { if (file_error) file_error->id = G_SEGY_FILE_OPEN_ERROR; return FALSE; } return TRUE;}GSEGYFileAccessor* g_segy_file_get_file_accessor (GSEGYFile *self) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (self); return private->file_accessor;}GSEGYSeismicAccessor* g_segy_file_get_seismic_accessor (GSEGYFile *self) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (self); return g_segy_seismic_accessor_new (private->file_accessor);}static void g_segy_file_init (GSEGYFile *self) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (self); private->filename = NULL; private->io_channel = NULL; private->file_accessor = NULL; private->file_error.id = G_SEGY_FILE_NO_ERROR; private->file_error.gerror = NULL;#ifdef DEBUG g_print ("<GSEGYFile is inited>\n");#endif}static void g_segy_file_finalize (GObject *object) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (G_SEGY_FILE (object)); if (private->filename) g_free ((gchar*)private->filename); if (private->io_channel) g_io_channel_shutdown (private->io_channel, FALSE, NULL); if (private->file_accessor) g_object_unref (G_OBJECT (private->file_accessor)); if (private->file_error.gerror) g_error_free (private->file_error.gerror);#ifdef DEBUG g_print ("<GSEGYFile is finalized>\n");#endif if (G_OBJECT_CLASS (g_segy_file_parent_class)->finalize) G_OBJECT_CLASS (g_segy_file_parent_class)->finalize (object);}enum { PROP_0, PROP_FILE_NAME, PROP_FILE_ERROR, PROP_IO_CHANNEL, PROP_FILE_ACCESSOR};static void g_segy_file_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (G_SEGY_FILE (object)); switch (prop_id) { case PROP_FILE_NAME: { const gchar *filename = g_value_get_string (value); g_segy_file_setup (G_SEGY_FILE (object), filename, &private->file_error); g_object_notify (object, "file_name"); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; }}static void g_segy_file_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GSEGYFilePrivate *private = G_SEGY_FILE_GET_PRIVATE (G_SEGY_FILE (object)); switch (prop_id) { case PROP_FILE_ERROR: g_value_set_pointer (value, &private->file_error); break; case PROP_IO_CHANNEL: g_value_set_pointer (value, private->io_channel); break; case PROP_FILE_ACCESSOR: g_value_set_object (value, private->file_accessor); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; }}static void g_segy_file_class_init (GSEGYFileClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (GSEGYFilePrivate)); gobject_class->finalize = (GObjectFinalizeFunc) g_segy_file_finalize; gobject_class->set_property = g_segy_file_set_property; gobject_class->get_property = g_segy_file_get_property; klass->scan_fraction = NULL; klass->scan_fraction_id = g_signal_new ("scan_fraction", G_TYPE_FROM_CLASS ((gpointer)G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GSEGYFileClass, scan_fraction), NULL, NULL, g_segy_marshal_BOOLEAN__FLOAT_BOXED, G_TYPE_BOOLEAN, 2, G_TYPE_FLOAT, G_TYPE_POINTER); g_object_class_install_property (gobject_class, PROP_FILE_NAME, g_param_spec_string ("file_name", "FileName", "Name of the opened seismic file", "NULL", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_FILE_ERROR, g_param_spec_pointer ("file_error", "FileError", "Structure pointing out a file problem (if any)", G_PARAM_READABLE)); g_object_class_install_property (gobject_class, PROP_IO_CHANNEL, g_param_spec_pointer ("io_channel", "IOChannel", "System object describing opened files", G_PARAM_READABLE)); g_object_class_install_property (gobject_class, PROP_FILE_ACCESSOR, g_param_spec_object ("file_accessor", "FileAccessor", "Object responsible for an opened seismic file access", G_SEGY_TYPE_FILE_ACCESSOR, G_PARAM_READABLE));#ifdef DEBUG g_print ("<GSEGYFile class is inited>\n");#endif}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -