rita.c 3.54 KB
Newer Older
saeed's avatar
saeed committed
1
2
3
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
saeed's avatar
saeed committed
4
#include<stdarg.h>
saeed's avatar
saeed committed
5
#include<X11/Xlib.h>
saeed's avatar
saeed committed
6
#include<time.h>
saeed's avatar
saeed committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<X11/Xutil.h>
#include <X11/Xatom.h>
#include<X11/keysym.h>
#include<X11/cursorfont.h>
#include<pthread.h>
#include"intostr.c"
#include"config.h"
#include"reportype.h"

#define __USE_XOPEN_EXTENDED (1)
#include<unistd.h>

#define ArrayCount(a) (sizeof(a) / sizeof(a[0]))
#define StringArrayCount(a) (ArrayCount(a) -1)

typedef unsigned int  uint32;
typedef unsigned char uint8;

saeed's avatar
saeed committed
25
static uint32 land_color  = landcolor;
saeed's avatar
saeed committed
26
static uint32 ocean_color = oceancolor;
saeed's avatar
saeed committed
27
static uint32 stn_color   = stncolor;
saeed's avatar
saeed committed
28

saeed's avatar
saeed committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma pack(push,1)
struct field {
  short  SSH[NX*NY];
  uint8  image32[NX*NY*4];
  float lat[NY];
  float lon[NX];
};
#pragma pack(pop)

static struct field FLD = {{0},{0},{0.0},{0.0}};
static char cinfo[1024] = {'\0'};

struct station {
  char name[256];
  float lon;
  float lat;
  int   ix;
  int   iy;
  int   radius;
  int   ns;
};

saeed's avatar
saeed committed
51
52
53
54
55
56
struct stn_set{
  struct station **stns;
  int icur;
  int nt;
};

saeed's avatar
saeed committed
57
static struct station *stns;
saeed's avatar
saeed committed
58
static struct stn_set stns_set;
saeed's avatar
saeed committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72

struct odbinfo{
  char *filename;
  char ntotal[256];
  char cycle[256];
  char start_date[256];
  char end_date[256];
  char reportype[256];
  char *desc;
  char *group;
};

static struct odbinfo odbinfo = {NULL,{'\0'},{'\0'},{'\0'},{'\0'},{'\0'},NULL,NULL};

saeed's avatar
saeed committed
73
74
75
76
77
78
79
struct odbinfo_set{
  struct odbinfo **odb_set;
  int icur;
  int nt;
};
static struct odbinfo_set odbinfo_set;

saeed's avatar
saeed committed
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
struct Vis{
  Display *dsp;
  Window win;
  Visual *visual;
  int screen_num;
  XGCValues gr_values;
  XFontStruct *fontinfo;
  GC gc;
  int w;
  int h;
  int depth;
  Cursor font_cursor;
  Colormap cmap;
};

struct dsp_field {
  float  *SSH;
  uint8  *image32;
  int nx;
  int ny;
};

struct Colort{
  float red, green, blue, alpha;
  int ncol;
};

struct xdata {
  Display *dsp;
  int screen_num;
  Window win;
  GC gc;                                  
};

struct symbol{
  float radius;
};

struct obs{
  int *iindex;
  int *jindex;
  int npx;
  int npy;
};

struct mousepose{
  int x;
  int y;
};

struct textprop{
  int direction;
  int ascent;
  int descent;
  XCharStruct overall;
};

struct screen_dim{
  int width;
  int height;
  float symbol_radius;
};

struct Index {
  int i;
  int j;
};

#include"util.c"
#include"renderer.c"
#include"renderer_thread.c"


int main(int argc, char *argv[]){
  
  if (argc == 1){
    printf("\nUsage %s odb_file\n\n",argv[0]);
  }
  
  if (argc == 2){
  
saeed's avatar
saeed committed
161
162
163
    int width  = WIDTH_INIT;
    int height = HEIGHT_INIT;
    int ncolor = 0;
saeed's avatar
saeed committed
164

saeed's avatar
saeed committed
165
166
167
    land_color  = landcolor;
    ocean_color = oceancolor;
    stn_color   = stncolor;
saeed's avatar
saeed committed
168
  
saeed's avatar
saeed committed
169
170
171
    if (usesrgb) land_color  = lineartosrgbi(landcolor);
    if (usesrgb) ocean_color = lineartosrgbi(oceancolor);
    if (usesrgb) stn_color   = lineartosrgbi(stncolor);
saeed's avatar
saeed committed
172
173
  
  
saeed's avatar
saeed committed
174
175
176
177
    struct screen_dim scdim = {0,0,0};
    scdim.width = width;
    scdim.height = height;
    scdim.symbol_radius = SYM_SIZE;
saeed's avatar
saeed committed
178

saeed's avatar
saeed committed
179
    struct Colort *scolor = NULL;
saeed's avatar
saeed committed
180

saeed's avatar
saeed committed
181
    get2dfield_binary("landseamask.bin",&FLD);
saeed's avatar
saeed committed
182

saeed's avatar
saeed committed
183
184
185
    struct Vis visu       = init_x(width,height);
    struct dsp_field dspf = adjusttowindowsize(&visu, &FLD);
    stns  = getstn(argv[1],&odbinfo);
saeed's avatar
saeed committed
186
  
saeed's avatar
saeed committed
187
188
189
    width  = WIDTH_TR1;
    height = HEIGHT_TR1;
    struct Vis visu_1       = init_x(width,height);
saeed's avatar
saeed committed
190
  
saeed's avatar
saeed committed
191
192
193
    map_window(&visu_1);
    map_window(&visu);

saeed's avatar
saeed committed
194
195
    movewindow(&visu,(int)(WIDTH_TR1*1.01),0);

saeed's avatar
saeed committed
196
197
198
199
200
    pthread_t thread_id[NUM_THREADS];
    for (int i=0; i < NUM_THREADS;++i){
      pthread_create(&thread_id[i], NULL, handle_event_thread, (void *)&visu_1);
    }
    handle_event(&visu,&visu_1,&dspf,scolor,ncolor,&scdim);
saeed's avatar
saeed committed
201
202
203
204
205
206
207
208
  }
  
  return 0;
}