LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-07-2006, 07:50 AM   #1
WESS126
LQ Newbie
 
Registered: Apr 2004
Posts: 6

Rep: Reputation: 0
What is pgm.h and how do I install?


Hallo everyone,

I am having some trouble compiling C code written for me. I working on cygwin (at work) at the moment but would like to compile the software on a machine running Mandriva 2006 (at home: no i-net access).

I get an error when I try and compile using the following command (cygwin work and at home).

gcc -O4 -o tempspatcorrel tempspatcorrel.c -lm -lpgm -lpbm

The error states that pgm.h: No such file or directory

When I add pgm.h to /usr/local/include I get an error asking for pbm.h
So I put pbm.h in /usr/local/include and get an error asking for pbmplus.h
After that I get new errors regarding conflicting types for srandom and random in stdlib.h and pbm.h.

I know that it would be useful to include the error messages but my efforts to write the error output to a file under cygwin have met with scant success and copying cygwin command line to windows notepad just doesnt work. Apologies.

The source code is below. As I said I did not write the code and I have little or no experience writing and compiling c code.

I would really appreciate some help on this as I need to get the code compiled to run some analysis.

Many thanks in advance for your help and input

Wesley


***************************************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <pgm.h>



// Some basic parameters that won't change often
#define MAXFILES 600
#define MAXSTR 100
#define KERNEL_SIZE 2
// Function declaration for basic Pearson Correlation calc
float correl(float *series1, float *series2, int n);
int main(int argc, char **argv)
{

char tempfilename[MAXSTR], filename[MAXSTR], command[500];
FILE *infiles[MAXFILES], *filelist, *outfile;
int fileno, xsize, ysize, xpos, ypos, xi, yi, zi, img;
gray **sourceimages[MAXFILES], **outimage, maxval;
float cntr_series[MAXFILES], series[MAXFILES], r;

// Check command line parameters

if (argc != 3)

{
printf("Usage: %s filelist outfile\n", argv[0]);
exit(1);
}

// Open the file list file
if (!(filelist = fopen(argv[1], "r")))
{
printf("Error opening filelist: %s\n", argv[1]);
exit(1);
}

else
printf("Opened filelist: %s\n", argv[1]);

outfile = fopen(argv[2], "w");

// Open all the input image files and read in the image data

fileno = 0;

while (!feof(filelist))

{

// Get the file name

fscanf(filelist, "%s\n", filename);

printf("file %d: %s\n", fileno, filename);



// Convert to pgm format

sprintf(tempfilename, "temp%d.pgm", fileno);

sprintf(command, "/usr/X11R6/bin/convert %s %s >& /dev/null", filename, tempfilename);

system(command);



// Open the file and read in the data

if (!(infiles[fileno] = fopen(tempfilename, "r"))) printf("Oops!\n");

sourceimages[fileno] = pgm_readpgm(infiles[fileno], &xsize, &ysize,&maxval);

fileno++;

}



// Allocate space for the new image

outimage = pgm_allocarray(xsize-(KERNEL_SIZE*2), ysize-(KERNEL_SIZE*2));



// Now scan the source images and calc correlations

for (ypos = KERNEL_SIZE; ypos < ysize - KERNEL_SIZE; ypos++)

{

printf("Processing row %d \r", ypos);



for (xpos = KERNEL_SIZE; xpos < xsize - KERNEL_SIZE; xpos++)

{

r = 0;



// Pull out the kernel central time series

for (img = 0; img < fileno; img++)

cntr_series[img] = (float)sourceimages[img][ypos][xpos];



// For each pixel in the kernel

for (xi = xpos-KERNEL_SIZE; xi <= xpos+KERNEL_SIZE; xi++)

for (yi = ypos-KERNEL_SIZE; yi <= ypos+KERNEL_SIZE; yi++)

{

// .. except the central pixel!

if (xi == xpos && yi == ypos) continue;



// Pull out the time series

for (img = 0; img < fileno; img++)

series[img] = (float)sourceimages[img][yi][xi];



// Accumulate the correlation coefficients

r += correl(cntr_series, series, fileno);

}



// Now calculate the average coefficient and write to the new image

r = r/((KERNEL_SIZE*2 + 1)*((KERNEL_SIZE*2)+1) - 1);

outimage[ypos-KERNEL_SIZE][xpos-KERNEL_SIZE] = (int)(r*255);

}

}



// Write out the image file

pgm_writepgm(outfile, outimage, xsize-(KERNEL_SIZE*2), ysize-(KERNEL_SIZE*2), 255, 1);



return 0;

}



// Calculate Pearson correlatoin coefficient

float correl(float *series1, float *series2, int n)

{

float xm=0, ym=0, xx=0, yy=0, xy=0;

int i;

float r;



// Means

for (i = 0; i < n; i++)

{

xm += series1[i];

ym += series2[i];

}

xm = xm/n;

ym = ym/n;



// Sum of normalised squares

for (i = 0; i < n; i++)

{

xx += pow((series1[i]-xm),2);

yy += pow((series2[i]-ym),2);

xy += (series1[i] - xm)*(series2[i] - ym);

}



// We don't want div by zero

if (xx*yy == 0.0)

r = 0;

// The final formula...

else

r = pow(xy,2)/(xx*yy);



// And back we go

return r;

}
 
Old 05-07-2006, 10:16 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
install netpbm-devel.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't compile C pgm in SUSE 9.1 gjo Programming 10 10-25-2004 12:00 PM
starting java pgm at services bgcynthia Red Hat 0 10-06-2004 01:00 AM
Any IT managers in here? Writing COBOL pgm to show @ interview superztnt Programming 0 07-05-2004 06:24 PM
fprintf is not working in rpc server pgm ratheesh Programming 1 01-08-2004 09:33 PM
problems compiling qt-pgm engman Programming 0 05-31-2001 08:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration