File: file_dlp.c

package info (click to toggle)
gdis 0.90-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 10,364 kB
  • ctags: 9,392
  • sloc: ansic: 71,121; perl: 298; sh: 115; python: 115; makefile: 33; xml: 26
file content (146 lines) | stat: -rw-r--r-- 3,169 bytes parent folder | download | duplicates (4)
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
/*
Copyright (C) 2003 by Sean David Fleming

sean@ivec.org

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 details.

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.

The GNU GPL can also be found at http://www.gnu.org
*/

#include <stdio.h>
#include <string.h>

#include "gdis.h"
#include "coords.h"
#include "model.h"
#include "file.h"
#include "parse.h"
#include "scan.h"
#include "interface.h"

/* main structures */
extern struct sysenv_pak sysenv;
extern struct elem_pak elements[];

/****************/
/* file writing */
/****************/
gint write_dlp(gchar *filename, struct model_pak *model)
{
return(0);
}

/****************/
/* file reading */
/****************/
#define DEBUG_READ_XYZ 0
gint read_dlp(gchar *filename, struct model_pak *model)
{
gint i, tokens;
gchar *line, **buff;
gpointer scan;
struct core_pak *core;

/* checks */
g_return_val_if_fail(model != NULL, 1);
g_return_val_if_fail(filename != NULL, 2);

scan = scan_new(filename);
if (!scan)
  return(3);

/* title line */
line = scan_get_line(scan);

/* config stuff */
line = scan_get_line(scan);

/* cell vectors */
model->construct_pbc = TRUE;
model->periodic = 3;
for (i=0 ; i<3 ; i++)
  {
  line = scan_get_line(scan);
  if (line)
    {
    buff = tokenize(line, &tokens);
    if (tokens > 2)
      {
      model->latmat[3*i] = str_to_float(*(buff));
      model->latmat[3*i+1] = str_to_float(*(buff+1));
      model->latmat[3*i+2] = str_to_float(*(buff+2));
      }
    g_strfreev(buff);
    }
  }

/* atoms & associated data */
model->fractional = FALSE;
while (!scan_complete(scan))
  {
  line = scan_get_line(scan);
  core = NULL;

/* element and id */
  buff = tokenize(line, &tokens);
  if (buff)
    core = core_new(*buff, NULL, model);
  g_strfreev(buff);

/* coordinates */
  line = scan_get_line(scan);
  buff = tokenize(line, &tokens);
  if (core && tokens > 2)
    {
    core->x[0] = str_to_float(*buff);
    core->x[1] = str_to_float(*(buff+1));
    core->x[2] = str_to_float(*(buff+2));
    }
  g_strfreev(buff);

/* velocity */
  line = scan_get_line(scan);
  buff = tokenize(line, &tokens);
  if (core && tokens > 2)
    {
    core->v[0] = str_to_float(*buff);
    core->v[1] = str_to_float(*(buff+1));
    core->v[2] = str_to_float(*(buff+2));
    }
  g_strfreev(buff);

/* TODO - acceleration??? */
  line = scan_get_line(scan);

/* finished reading atom data */
  if (core)
    model->cores = g_slist_prepend(model->cores, core);
  }


/*
strcpy(data->filename, filename);
g_free(data->basename);
data->basename = parse_strip(filename);
*/

model_prep(model);

scan_free(scan);

return(0);
}