-
Notifications
You must be signed in to change notification settings - Fork 0
/
shmimview.cpp
996 lines (717 loc) · 22.7 KB
/
shmimview.cpp
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
#include "shmimview.h"
#include "ui_shmimview.h"
#include <stdint.h>
#include <unistd.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/mman.h> // mmap, PROT_READ, PROT_WRITE ...
#include <semaphore.h>
#include <fcntl.h> // for open
#include <unistd.h> // for close
#include <ImageStruct.h>
#include <QtGlobal>
#include <QImage>
#include <QTimer>
IMAGE ImageData;
IMAGE ImageDataDark;
float *imdataf = NULL;
unsigned char *imdata = NULL;
uint8_t imtype;
// data values
float dataMaxVal;
float dataMinVal;
int autominmax = 0;
QImage qimage(100, 100, QImage::Format_Grayscale8);
long read_sharedmem_image_toIMAGE(const char *name, IMAGE *image);
static QGraphicsScene * scene;
static int initscene = 0;
static long long refreshcnt = 0;
static int imxsize_view;
static int imysize_view;
static float freq;
static float minVal = 0.0;
static float maxVal = 1.0;
static long refreshintervalms = 1000;
static int brightness_scale_mode = 0;
static int OKdark = 0;
static int rmDarkMode = 0;
static long long imcnt0, imcnt1;
long long imcnt00 = 0;
static long imxsize, imysize, imzsize;
QTimer *timer;
char tmpstring[200];
char input_streamname[200];
float input_framerate;
float input_minval;
float input_maxval;
int imxsize_view_min = 200;
int imysize_view_min = 200;
int imxsize_view_max = 1000;
int imysize_view_max = 1000;
int fileconfinit = 0; // toggles to 1 if parameter file present
// Reads from disk input parameters
// Default configuration file : .shmimview.conf
// File format :
// Line 1: stream name
// Line 2: update frequency
int ReadFileParameters()
{
FILE *fp;
char keyword[200];
char fieldval[200];
fp = fopen(".shmimview.conf", "r");
if(fp==NULL)
{
printf("Warning : no input parameter conf file\n");
fflush(stdout);
}
else
{
printf("Found parameter conf file\n");
fflush(stdout);
fileconfinit = 1;
while(fscanf(fp, "%s %s", keyword, fieldval)==2)
{
printf("keyword = %20s value = %20s\n", keyword, fieldval);
if(!strcmp(keyword, "STREAM_NAME"))
strcpy(input_streamname, fieldval);
if(!strcmp(keyword, "FRAME_RATE"))
input_framerate = atof(fieldval);
if(!strcmp(keyword, "VAL_MIN"))
input_minval = atof(fieldval);
if(!strcmp(keyword, "VAL_MAX"))
input_maxval = atof(fieldval);
}
fclose(fp);
}
return 0;
}
// This function is executed upon startup
shmimview::shmimview(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::shmimview)
{
ui->setupUi(this);
this->setStyleSheet(
"QToolButton#streamON::checked {"
"background-color: red; }"
"QToolButton#rmdarkON::checked {"
"background-color: red; }"
);
ui->brightnessscale->addItem("Linear");
ui->brightnessscale->addItem("Log");
ui->brightnessscale->addItem("Sqrt");
ui->brightnessscale->addItem("Sqr");
ui->brightnessscale->addItem("Pow01");
ui->brightnessscale->addItem("Pow02");
ui->brightnessscale->addItem("Pow04");
ui->brightnessscale->addItem("Pow08");
ui->brightnessscale->addItem("Pow16");
ui->brightnessscale->addItem("Pow32");
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_display_clicked()));
// STARTUP
// Default values
strcpy(input_streamname, "nullim");
ReadFileParameters();
// UPDATE FREQUENCY
sprintf(tmpstring, "%.2f", input_framerate);
ui->updatefreq->setText(tmpstring);
freq = atof(qPrintable(ui->updatefreq->text()));
refreshintervalms = (long) (1000.0/freq);
// STREAM NAME
ui->streamname->setText(input_streamname);
sprintf(tmpstring, "%.3f", input_minval);
ui->minval->setText(tmpstring);
minVal = input_minval;
sprintf(tmpstring, "%.3f", input_maxval);
ui->maxval->setText(tmpstring);
maxVal = input_maxval;
// timer->start(refreshintervalms);
}
shmimview::~shmimview()
{
delete ui;
}
void shmimview::on_brightnessscale_currentIndexChanged()
{
brightness_scale_mode = ui->brightnessscale->currentIndex();
printf("CURRENT SELECTION CHANGED to : %d\n", brightness_scale_mode);
fflush(stdout);
}
void shmimview::on_setfreq_clicked()
{
char messagetext[200];
freq = atof(qPrintable(ui->updatefreq->text()));
sprintf(messagetext, "set update freq to %.2f Hz", freq);
refreshintervalms = (long) (1000.0/freq);
timer->stop();
timer->start(refreshintervalms);
ui->msgbox->append(messagetext);
}
void shmimview::on_setminval_clicked()
{
char messagetext[200];
minVal = atof(qPrintable(ui->minval->text()));
sprintf(messagetext, "set min val to %.2f", minVal);
ui->msgbox->append(messagetext);
}
void shmimview::on_setmaxval_clicked()
{
char messagetext[200];
maxVal = atof(qPrintable(ui->maxval->text()));
sprintf(messagetext, "set max val to %.2f", maxVal);
ui->msgbox->append(messagetext);
}
void shmimview::on_streamON_clicked()
{
if(imdata==NULL)
{
ui->streamON->setChecked(0);
timer->stop();
}
else
{
printf("button streamON clicked\n");
if(ui->streamON->isChecked()==0)
timer->stop();
else
timer->start(refreshintervalms);
}
}
void shmimview::on_rmdarkON_clicked()
{
if(OKdark==0)
{
ui->rmdarkON->setChecked(0);
}
else
{
if(ui->rmdarkON->isChecked()==0)
rmDarkMode = 0;
else
rmDarkMode = 1;
}
}
void shmimview::on_autominmax_clicked()
{
if(imdata==NULL)
{
ui->autominmax->setChecked(0);
autominmax = 0;
}
else
{
if(ui->autominmax->isChecked()==0)
autominmax = 0;
else
autominmax = 1;
}
}
void shmimview::data2bitmap()
{
long ii, jj;
long iii;
float dataMaxVal = 1.0;
float dataMinVal = 0.0;
// convert to float
switch (imtype) {
case (_DATATYPE_UINT8):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.UI8[jj*imxsize+ii];
break;
case (_DATATYPE_INT8):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.SI8[jj*imxsize+ii];
break;
case (_DATATYPE_UINT16):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.UI16[jj*imxsize+ii];
break;
case (_DATATYPE_INT16):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.SI16[jj*imxsize+ii];
break;
case (_DATATYPE_UINT32):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.UI32[jj*imxsize+ii];
break;
case (_DATATYPE_INT32):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.SI32[jj*imxsize+ii];
break;
case (_DATATYPE_UINT64):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.UI64[jj*imxsize+ii];
break;
case (_DATATYPE_INT64):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.SI64[jj*imxsize+ii];
break;
case (_DATATYPE_FLOAT):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.F[jj*imxsize+ii];
break;
case (_DATATYPE_DOUBLE):
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdataf[jj*imxsize+ii] = 1.0*ImageData.array.D[jj*imxsize+ii];
break;
}
if(rmDarkMode==1)
for(iii=0;iii<imxsize*imysize;iii++)
imdataf[iii] -= ImageDataDark.array.F[iii];
dataMinVal = imdataf[0];
dataMaxVal = imdataf[0];
for(iii=0;iii<imxsize*imysize;iii++)
{
if(imdataf[iii]>dataMaxVal)
dataMaxVal = imdataf[iii];
if(imdataf[iii]<dataMinVal)
dataMinVal = imdataf[iii];
}
if(autominmax==1)
{
minVal = dataMinVal;
maxVal = dataMaxVal;
sprintf(tmpstring, "%8g", minVal);
ui->minval->setText(tmpstring);
sprintf(tmpstring, "%8g", maxVal);
ui->maxval->setText(tmpstring);
}
// clip 0.001 -> 1.0
for(iii=0;iii<imxsize*imysize;iii++)
{
imdataf[iii] = (1.0*imdataf[iii]-minVal) / (maxVal-minVal);
if(imdataf[iii]<0.000001)
imdataf[iii] = 0.000001;
if(imdataf[iii]>1.0)
imdataf[iii] = 1.0;
}
switch ( brightness_scale_mode ) {
case ( 1 ) : // log scale
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = (log10(imdataf[iii]+0.00001)+5.0)/5.0;
break;
case ( 2 ) : // sqrt
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = sqrt(imdataf[iii]);
break;
case ( 3 ) : // sqr
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = imdataf[iii]*imdataf[iii];
break;
case ( 4 ) : // pow 01
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = pow(imdataf[iii], 0.1);
break;
case ( 5 ) : // pow 02
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = pow(imdataf[iii], 0.2);
break;
case ( 6 ) : // pow 04
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = pow(imdataf[iii], 0.4);
break;
case ( 7 ) : // pow 08
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = pow(imdataf[iii], 0.8);
break;
case ( 8 ) : // pow 16
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = pow(imdataf[iii], 1.6);
break;
case ( 9 ) : // pow 32
for(iii=0 ; iii<imxsize*imysize ; iii++)
imdataf[iii] = pow(imdataf[iii], 3.2);
break;
}
for(ii=0;ii<imxsize;ii++)
for(jj=0;jj<imysize;jj++)
imdata[jj*imxsize+ii] = (unsigned char) (imdataf[jj*imxsize+ii] * 255.0 );
}
void shmimview::on_display_clicked()
{
QPixmap qpixmap;
char messagetext[200];
imcnt0 = ImageData.md[0].cnt0;
if(imcnt0!=imcnt00)
{
ui->cnt0->setText(QString::number(imcnt0));
imcnt1 = ImageData.md[0].cnt1;
ui->cnt1->setText(QString::number(imcnt1));
data2bitmap();
QImage qimage(imdata, imxsize, imysize, QImage::Format_Grayscale8);
qpixmap = QPixmap::fromImage(qimage);
scene->clear();
scene->addPixmap(qpixmap);
refreshcnt++;
imcnt00 = imcnt0;
sprintf(messagetext, "[%10lld] display updated %d %d", refreshcnt, OKdark, rmDarkMode);
ui->msgbox->append(messagetext);
}
}
void shmimview::on_connect_clicked()
{
char sname[200];
char snamedark[200];
char messagetext[200];
int imnaxis;
sprintf(sname, "%s", qPrintable(ui->streamname->text()));
if( read_sharedmem_image_toIMAGE(sname, &ImageData) == -1)
{
sprintf(messagetext, "ERROR: cannot load stream %s", sname);
ui->msgbox->append(messagetext);
}
else
{
ui->stream->setText(sname);
sprintf(messagetext, "[%10lld] Stream %s loaded (%.2f Hz)", refreshcnt, sname, freq);
ui->msgbox->append(messagetext);
imtype = ImageData.md[0].atype;
switch (imtype) {
case (_DATATYPE_UINT8):
ui->type->setText("UINT8");
break;
case (_DATATYPE_INT8):
ui->type->setText("INT8");
break;
case (_DATATYPE_UINT16):
ui->type->setText("UINT16");
break;
case (_DATATYPE_INT16):
ui->type->setText("INT16");
break;
case (_DATATYPE_UINT32):
ui->type->setText("UINT32");
break;
case (_DATATYPE_INT32):
ui->type->setText("INT32");
break;
case (_DATATYPE_UINT64):
ui->type->setText("UINT64");
break;
case (_DATATYPE_INT64):
ui->type->setText("INT64");
break;
case (_DATATYPE_FLOAT):
ui->type->setText("FLOAT");
break;
case (_DATATYPE_DOUBLE):
ui->type->setText("DOUBLE");
break;
default:
ui->type->setText("ERR");
break;
}
imnaxis = ImageData.md[0].naxis;
ui->naxis->setText(QString::number(imnaxis));
imxsize = ImageData.md[0].size[0];
ui->xsize->setText(QString::number(imxsize));
if(imnaxis>1)
{
imysize = ImageData.md[0].size[1];
ui->ysize->setText(QString::number(imysize));
}
else
ui->ysize->setText("-");
if(imnaxis>2)
{
imzsize = ImageData.md[0].size[2];
ui->zsize->setText(QString::number(imzsize));
}
else
ui->zsize->setText("-");
imcnt0 = ImageData.md[0].cnt0;
ui->cnt0->setText(QString::number(imcnt0));
imcnt1 = ImageData.md[0].cnt1;
ui->cnt1->setText(QString::number(imcnt1));
// SET VIEWBOX SIZE
imxsize_view = imxsize;
if(imxsize_view < imxsize_view_min)
imxsize_view = imxsize_view_min;
if(imxsize_view > imxsize_view_max)
imxsize_view = imxsize_view_max;
imysize_view = imysize;
if(imysize_view < imysize_view_min)
imysize_view = imysize_view_min;
if(imysize_view > imysize_view_max)
imysize_view = imysize_view_max;
ui->viewbox->setFixedHeight(imxsize_view);
ui->viewbox->setFixedWidth(imysize_view);
imdataf = (float*) malloc(sizeof(float)*imxsize*imysize);
imdata = (unsigned char*) malloc(sizeof(char)*imxsize*imysize);
data2bitmap();
QImage qimage(imdata, imxsize, imysize, QImage::Format_Grayscale8);
//QGraphicsScene scene;
if(initscene==0){
scene = new QGraphicsScene();
initscene = 1;
}
scene->addPixmap(QPixmap::fromImage(qimage));
ui->viewbox->setScene(scene);
refreshcnt++;
ui->streamON->setChecked(0);
timer->stop();
// timer->start(refreshintervalms);
}
// load dark if exists
OKdark = 0;
sprintf(snamedark, "%s_dark", qPrintable(ui->streamname->text()));
if( read_sharedmem_image_toIMAGE(snamedark, &ImageDataDark) == -1)
{
sprintf(messagetext, "WARNING: cannot load dark %s", snamedark);
ui->msgbox->append(messagetext);
}
else
{
sprintf(messagetext, "Loaded dark %s", snamedark);
ui->msgbox->append(messagetext);
OKdark = 1;
}
if(OKdark == 1)
if(ImageDataDark.md[0].atype != _DATATYPE_FLOAT )
{
sprintf(messagetext, "ERROR: dark is not float");
ui->msgbox->append(messagetext);
OKdark = 0;
}
}
void shmimview::on_VBbigger_clicked()
{
imxsize_view = (int) (1.2*imxsize_view);
if(imxsize_view > imxsize_view_max)
imxsize_view = imxsize_view_max;
imysize_view = (int) (1.2*imysize_view);
if(imysize_view > imysize_view_max)
imysize_view = imysize_view_max;
ui->viewbox->setFixedHeight(imxsize_view);
ui->viewbox->setFixedWidth(imysize_view);
}
void shmimview::on_VBsmaller_clicked()
{
imxsize_view = (int) (1.0/1.2*imxsize_view);
if(imxsize_view > imxsize_view_max)
imxsize_view = imxsize_view_max;
if(imxsize_view < imxsize_view_min)
imxsize_view = imxsize_view_min;
imysize_view = (int) (1.0/1.2*imysize_view);
if(imysize_view < imysize_view_min)
imysize_view = imysize_view_min;
if(imysize_view > imysize_view_max)
imysize_view = imysize_view_max;
ui->viewbox->setFixedHeight(imxsize_view);
ui->viewbox->setFixedWidth(imysize_view);
resize(minimumSize());
}
void shmimview::wheelEvent(QWheelEvent *event){
ui->viewbox->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
// Scale the view / do the zoom
double scaleFactor = 1.15;
if(event->delta() > 0) {
// Zoom in
ui->viewbox->scale(scaleFactor, scaleFactor);
} else {
// Zooming out
ui->viewbox->scale(1.0 / scaleFactor, 1.0 / scaleFactor);
}
}
long read_sharedmem_image_toIMAGE(const char *name, IMAGE *image)
{
int SM_fd;
struct stat file_stat;
char SM_fname[200];
IMAGE_METADATA *map;
char *mapv;
uint8_t atype;
int kw;
char sname[200];
sem_t *stest;
int sOK;
long snb;
long s;
int rval = -1;
sprintf(SM_fname, "%s/%s.im.shm", SHAREDMEMDIR, name);
SM_fd = open(SM_fname, O_RDWR);
if(SM_fd==-1)
{
image->used = 0;
return(-1);
printf("Cannot import shared memory file %s \n", name);
rval = -1;
}
else
{
rval = 0; // we assume by default success
fstat(SM_fd, &file_stat);
printf("File %s size: %zd\n", SM_fname, file_stat.st_size);
map = (IMAGE_METADATA*) mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0);
if (map == MAP_FAILED) {
close(SM_fd);
perror("Error mmapping the file");
rval = -1;
exit(0);
}
image->memsize = file_stat.st_size;
image->shmfd = SM_fd;
image->md = map;
// image->md[0].sem = 0;
atype = image->md[0].atype;
image->md[0].shared = 1;
printf("image size = %ld %ld\n", (long) image->md[0].size[0], (long) image->md[0].size[1]);
fflush(stdout);
// some verification
if(image->md[0].size[0]*image->md[0].size[1]>10000000000)
{
printf("IMAGE \"%s\" SEEMS BIG... ABORTING\n", name);
rval = -1;
exit(0);
}
if(image->md[0].size[0]<1)
{
printf("IMAGE \"%s\" AXIS SIZE < 1... ABORTING\n", name);
rval = -1;
exit(0);
}
if(image->md[0].size[1]<1)
{
printf("IMAGE \"%s\" AXIS SIZE < 1... ABORTING\n", name);
rval = -1;
exit(0);
}
mapv = (char*) map;
mapv += sizeof(IMAGE_METADATA);
printf("atype = %d\n", (int) atype);
fflush(stdout);
if(atype == _DATATYPE_UINT8)
{
printf("atype = UINT8\n");
image->array.UI8 = (uint8_t*) mapv;
mapv += SIZEOF_DATATYPE_UINT8 * image->md[0].nelement;
}
if(atype == _DATATYPE_INT8)
{
printf("atype = INT8\n");
image->array.SI8 = (int8_t*) mapv;
mapv += SIZEOF_DATATYPE_INT8 * image->md[0].nelement;
}
if(atype == _DATATYPE_UINT16)
{
printf("atype = UINT16\n");
image->array.UI16 = (uint16_t*) mapv;
mapv += SIZEOF_DATATYPE_UINT16 * image->md[0].nelement;
}
if(atype == _DATATYPE_INT16)
{
printf("atype = INT16\n");
image->array.SI16 = (int16_t*) mapv;
mapv += SIZEOF_DATATYPE_INT16 * image->md[0].nelement;
}
if(atype == _DATATYPE_UINT32)
{
printf("atype = UINT32\n");
image->array.UI32 = (uint32_t*) mapv;
mapv += SIZEOF_DATATYPE_UINT32 * image->md[0].nelement;
}
if(atype == _DATATYPE_INT32)
{
printf("atype = INT32\n");
image->array.SI32 = (int32_t*) mapv;
mapv += SIZEOF_DATATYPE_INT32 * image->md[0].nelement;
}
if(atype == _DATATYPE_UINT64)
{
printf("atype = UINT64\n");
image->array.UI64 = (uint64_t*) mapv;
mapv += SIZEOF_DATATYPE_UINT64 * image->md[0].nelement;
}
if(atype == _DATATYPE_INT64)
{
printf("atype = INT64\n");
image->array.SI64 = (int64_t*) mapv;
mapv += SIZEOF_DATATYPE_INT64 * image->md[0].nelement;
}
if(atype == _DATATYPE_FLOAT)
{
printf("atype = FLOAT\n");
image->array.F = (float*) mapv;
mapv += SIZEOF_DATATYPE_FLOAT * image->md[0].nelement;
}
if(atype == _DATATYPE_DOUBLE)
{
printf("atype = DOUBLE\n");
image->array.D = (double*) mapv;
mapv += SIZEOF_DATATYPE_COMPLEX_DOUBLE * image->md[0].nelement;
}
if(atype == _DATATYPE_COMPLEX_FLOAT)
{
printf("atype = COMPLEX_FLOAT\n");
image->array.CF = (complex_float*) mapv;
mapv += SIZEOF_DATATYPE_COMPLEX_FLOAT * image->md[0].nelement;
}
if(atype == _DATATYPE_COMPLEX_DOUBLE)
{
printf("atype = COMPLEX_DOUBLE\n");
image->array.CD = (complex_double*) mapv;
mapv += SIZEOF_DATATYPE_COMPLEX_DOUBLE * image->md[0].nelement;
}
printf("%ld keywords\n", (long) image->md[0].NBkw);
fflush(stdout);
image->kw = (IMAGE_KEYWORD*) (mapv);
for(kw=0; kw<image->md[0].NBkw; kw++)
{
if(image->kw[kw].type == 'L')
printf("%d %s %ld %s\n", kw, image->kw[kw].name, image->kw[kw].value.numl, image->kw[kw].comment);
if(image->kw[kw].type == 'D')
printf("%d %s %lf %s\n", kw, image->kw[kw].name, image->kw[kw].value.numf, image->kw[kw].comment);
if(image->kw[kw].type == 'S')
printf("%d %s %s %s\n", kw, image->kw[kw].name, image->kw[kw].value.valstr, image->kw[kw].comment);
}
mapv += sizeof(IMAGE_KEYWORD)*image->md[0].NBkw;
strcpy(image->name, name);
// looking for semaphores
snb = 0;
sOK = 1;
while(sOK==1)
{
sprintf(sname, "%s_sem%02ld", image->md[0].name, snb);
if((stest = sem_open(sname, 0, 0644, 0))== SEM_FAILED)
sOK = 0;
else
{
sem_close(stest);
snb++;
}
}
printf("%ld semaphores detected %ld\n", snb, (long) image->md[0].sem);
//image->md[0].sem = snb;
image->semptr = (sem_t**) malloc(sizeof(sem_t*) * image->md[0].sem);
for(s=0; s<snb; s++)
{
sprintf(sname, "%s_sem%02ld", image->md[0].name, s);
if ((image->semptr[s] = sem_open(sname, 0, 0644, 0))== SEM_FAILED) {
printf("ERROR: could not open semaphore %s\n", sname);
}
}
sprintf(sname, "%s_semlog", image->md[0].name);
if ((image->semlog = sem_open(sname, 0, 0644, 0))== SEM_FAILED) {
printf("ERROR: could not open semaphore %s\n", sname);
}
}
return(rval);
}