Commit 51a054c7 authored by saeed's avatar saeed

more functionality

parent b233ca52
......@@ -13,5 +13,5 @@
#define useminmax 0
#define usesrgb 1
#define oceancolor 0xffffffff
#define landcolor 0xb1b1b1b1
#define landcolor 0x91919191
#define stncolor 0x00bf0000
......@@ -22,22 +22,23 @@ static void lineartosrgb(float *red, float *green, float *blue){
static uint32 lineartosrgbi(uint32 color){
uint32 result = 0x00000000;
uint8 ured = 0x00;
uint8 ugreen = 0x00;
uint8 ublue = 0x00;
uint8 ualpha = 0x00;
float red = ((uint8)((color & 0x00FF0000) >> 16)) / 255.0;
float green = ((uint8)((color & 0x0000FF00) >> 8)) / 255.0;
float blue = ((uint8)(color & 0x000000FF) ) / 255.0;
float alpha = ((uint8)((color & 0xFF000000) >> 24)) / 255.0;
float red = ((uint8)((color & 0x00FF0000) >> 16)) / 255.0;
float green = ((uint8)((color & 0x0000FF00) >> 8 )) / 255.0;
float blue = ((uint8)((color & 0x000000FF) >> 0 )) / 255.0;
lineartosrgb(&red, &green, &blue);
ured = (uint8 )(red * 255.0);
ugreen = (uint8 )(green * 255.0);
ublue = (uint8 )(blue * 255.0);
ualpha = (uint8 )(alpha * 255.0);
ualpha = (uint8 )(alpha * 255.0);
result = (((uint32)ured << 16) | ((uint32)ugreen << 8) | ((uint32)ublue) | (uint32)ualpha<<24);
......@@ -58,6 +59,7 @@ static XImage *CreateTrueColorImage(Display *display, Visual *visual, int width,
}
static struct Vis init_x(int w, int h){
struct Vis result = {0};
......@@ -73,13 +75,23 @@ static struct Vis init_x(int w, int h){
attributes.override_redirect = 0;
result.win = XCreateWindow(result.dsp,RootWindow(result.dsp,result.screen_num), 0, 0, w, h, 0, result.depth, InputOutput,result.visual ,CWBackPixel | CWBorderPixel | CWOverrideRedirect, &attributes);
XSelectInput(result.dsp, result.win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | PointerMotionMask | FocusChangeMask);
result.fontinfo = XLoadQueryFont(result.dsp,"10x20");
char * fontname = "lucidasanstypewriter-bold-18";
result.fontinfo = XLoadQueryFont (result.dsp, fontname);
if (! result.fontinfo) {
fprintf (stderr, "unable to load font %s: using fixed\n", fontname);
result.fontinfo = XLoadQueryFont(result.dsp,"10x20");
if (! result.fontinfo){
result.fontinfo = XLoadQueryFont (result.dsp, "fixed");
}
}
result.gr_values.font = result.fontinfo->fid;
result.gr_values.function = GXcopy;
result.gr_values.plane_mask = AllPlanes;
result.gr_values.foreground = WhitePixel(result.dsp,result.screen_num);
result.gr_values.background = WhitePixel(result.dsp,result.screen_num);
result.gc=XCreateGC(result.dsp,result.win,GCFont | GCFunction | GCPlaneMask | GCForeground | GCBackground,&result.gr_values);
//XSetFont (result.dsp, result.gc, result.fontinfo->fid);
result.cmap = DefaultColormap(result.dsp, result.screen_num);
XStoreName( result.dsp, result.win, "ODBVIS" ) ;
XSetIconName( result.dsp, result.win, "ODBVIS" ) ;
......@@ -510,6 +522,7 @@ static void handle_event(struct Vis *vis,struct Vis *vis1, struct dsp_field *dsp
if (XPending(vis->dsp)){
if (e.type == Expose){
drawonscreen_expose(vis,dspf,scolor,ncolor,&obsp,scdim);
odbinfo_onotherwindow(vis1, &odbinfo);
}
done = 0;
}
......
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<stdarg.h>
#include<X11/Xlib.h>
#include<time.h>
#include<X11/Xutil.h>
#include <X11/Xatom.h>
#include<X11/keysym.h>
#include<X11/cursorfont.h>
#include<pthread.h>
#include<stdarg.h>
#include<time.h>
#include"intostr.c"
#include"config.h"
#include"reportype.h"
......@@ -22,9 +22,9 @@
typedef unsigned int uint32;
typedef unsigned char uint8;
static uint32 land_color = landcolor;
static uint32 land_color = landcolor;
static uint32 ocean_color = oceancolor;
static uint32 stn_color = stncolor;
static uint32 stn_color = stncolor;
#pragma pack(push,1)
struct field {
......@@ -144,50 +144,44 @@ int main(int argc, char *argv[]){
if (argc == 2){
int width = WIDTH_INIT;
int height = HEIGHT_INIT;
int ncolor = 0;
int width = WIDTH_INIT;
int height = HEIGHT_INIT;
int ncolor = 0;
land_color = landcolor;
ocean_color = oceancolor;
stn_color = stncolor;
land_color = landcolor;
ocean_color = oceancolor;
stn_color = stncolor;
if (usesrgb) land_color = lineartosrgbi(landcolor);
if (usesrgb) ocean_color = lineartosrgbi(oceancolor);
if (usesrgb) stn_color = lineartosrgbi(stncolor);
if (usesrgb) land_color = lineartosrgbi(landcolor);
if (usesrgb) ocean_color = lineartosrgbi(oceancolor);
if (usesrgb) stn_color = lineartosrgbi(stncolor);
struct screen_dim scdim = {0,0,0};
scdim.width = width;
scdim.height = height;
scdim.symbol_radius = SYM_SIZE;
struct screen_dim scdim = {0,0,0};
scdim.width = width;
scdim.height = height;
scdim.symbol_radius = SYM_SIZE;
struct Colort *scolor = NULL;
struct Colort *scolor = NULL;
get2dfield_binary("bathy_precise_etopo2.bin",&FLD);
get2dfield_binary("bathy_precise_etopo2.bin",&FLD);
struct Vis visu = init_x(width,height);
struct dsp_field dspf = adjusttowindowsize(&visu, &FLD);
stns = getstn(argv[1],&odbinfo);
struct Vis visu = init_x(width,height);
struct dsp_field dspf = adjusttowindowsize(&visu, &FLD);
stns = getstn(argv[1],&odbinfo);
width = WIDTH_TR1;
height = HEIGHT_TR1;
struct Vis visu_1 = init_x(width,height);
width = WIDTH_TR1;
height = HEIGHT_TR1;
struct Vis visu_1 = init_x(width,height);
map_window(&visu_1);
map_window(&visu);
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);
/*
for (int i=0; i < NUM_THREADS;++i){
pthread_join(thread_id[i], NULL);
}
*/
printf("After Thread\n");
map_window(&visu_1);
map_window(&visu);
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);
}
return 0;
......
......@@ -20,11 +20,82 @@ static int Isdigit(char C){
}
static int getLen(char *str){
int result = 0;
if (str){
while(*str != '\0'){
result++;
str++;
}
}
return result;
}
static int find(char *reg, char *str, int *first, int *last){
int result = -1;
int lnr = getLen(reg);
int lns = getLen(str);
if ( lnr == 0 || lns == 0) return result;
if (lnr > lns) return result;
int i = 0;
int ncount = 0;
int k = 0;
int ip = 0;
for (int j=0; j < lns; ++j){
i = 0;
if (str[j] == reg[i]){
*first = j;
k = j+1;
ip = i + 1;
ncount = 1;
while(str[k] == reg[ip]){
++k;
++ip;
++ncount;
}
if (ncount == lnr){
result = j;
*last = (k-1);
break;
}
else{
}
}
}
return result;
}
static void getreportype(char *filename,char *reportype){
char *era = "odb_era5_";
char *precise = "odb_precise_";
char *beg = NULL;
char *end = NULL;
char *str = filename;
int first = -1, last = -1;
find(era, filename, &first, &last);
printf("first %d last %d\n",first, last);
if (first == -1 || last == -1){
first = -1;
last = -1;
find(precise, filename, &first, &last);
if ( first == -1 || last == -1){
return ;
}
else{
str = str + last + 1;
}
}
else{
str = str + last + 1;
}
printf("str %c \n",*str);
while (*str != '\0'){
beg = NULL;
if (Isdigit(*str)){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment