InstrumentParameters.java 5.97 KB
package osp;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;

/*
 * Class to read or to configure the instrument parameters. 
 */
public class InstrumentParameters {
	
	public  static double _PXSZ; // detector pixel size projected in the CSU, in mm/px
	public  static double _PLTSC; // GTC plate scale in arcseg/mm
	public static  double _OFFSET_X; // shift in virt. pixs between the CSU and detector
	public static  double _SAFE_PARAMETER; // safe parameter to safety unused slits opening for detector
	public static  double _OFFSET_IPA; // offset Angle
	
	// columns nb for the Emir parameters file
	public static int _nbColFi0=1;
	// lines nb for the Emir parameters file
	public static int _nbLiFi0=5;
	
	// columns nb for the Yv_barras parameters file
	public static int _nbColFi1=3;
	// lines nb for the Yv_barras parameters file
	public static int _nbLiFi1=111;
	// columns nb for the X calibrations values parameters file
	public static int _nbColFi2=111;
	//lines nb for the X calibrations values parameters file
	public static int _nbLiFi2=2056;
	
	private String filter;
	private String grism;
	
	public boolean filterSet;
	public boolean grismSet;
	
	private double tabParams [][];
	private double tabYVirtuals [][];
	private double tabXVirtuals [][];
	private int nbcol=0;
	private int nbli=0;
	
	/**
	 * 
	 * @param projectCompletePath : path for the config files. 
	 */
	public InstrumentParameters(String projectCompletePath)
	{
		// loads instruments parameters 	
		
		String fileName="calibration/EMIR_parameters.dat";
		nbcol=_nbColFi0;
		nbli=_nbLiFi0;
		File fiTelescope= new File(fileName);

		tabParams=loadInstrumentParameters(fiTelescope, nbcol, nbli);
		_PXSZ=tabParams[0][0]; 
		_PLTSC=tabParams[0][1];
		_OFFSET_X=tabParams[0][2];
		_SAFE_PARAMETER=tabParams[0][3];
		_OFFSET_IPA=tabParams[0][4];
//System.out.println("Inst param tab "+ tabParams[0][0]+ " "+ tabParams[0][1]+ " "+tabParams[0][2]+ " "+tabParams[0][3]+ " "+tabParams[0][4]);

		// Load Y bars
		fileName="calibration/EMIR_yv_bars.dat";
		nbcol=_nbColFi1;
		nbli=_nbLiFi1;
		File fiy= new File(fileName);
		tabYVirtuals=loadInstrumentParameters(fiy, nbcol, nbli);
//System.out.println("Inst param tab "+ tabYVirtuals[2][10]+ " "+ tabYVirtuals[0][100]);
		
		// load CSU values 
		fileName="calibration/EMIR_CSUcal.dat";
//System.out.println("Inst param tab file : "+fileName);
		File fix= new File(fileName);
		nbcol=_nbColFi2;
		nbli=_nbLiFi2;
		tabXVirtuals=loadInstrumentParameters(fix, nbcol, nbli);
		
//System.out.println("Inst param tab "+ tabXVirtuals[110][2040]+" "+tabXVirtuals[1][2001]);	
	}
	
	
	
	public double[][] getTabX()
	{
		return tabXVirtuals;
	}
	public double getTabY(int i, int j)
	{
		return tabYVirtuals[i][j];
	}
	
	
	public double [][] loadInstrumentParameters(File catFile, int nbcol, int nbli)
	{
		double tab[][]=new double [nbcol][nbli];
//		boolean paramFile=false;
  
		 try 
	     { 
	         // Prepare to read from the file, using a Scanner object
	         Scanner in = new Scanner(catFile);
	         String line=null;
	    
	         int liNb=0;
	         int colNb=0;
		         
	         // Read each line until end of file is reached
	         while (in.hasNextLine())
	         {
	             // Read an entire line, which contains all the details for 1 account
	              line = in.nextLine();
//	if (paramFile) System.out.println("LoadParam line read "+line);
	             // Make a Scanner object to break up this line into parts
				 Scanner lineBreaker = new Scanner(line);
	             String firstChar = null;
	             String firstField = null;
	             boolean read=true;
	             
	           
	             if (lineBreaker.hasNext()) 
	            {
	            	 firstField=lineBreaker.next();
	            	 firstChar=firstField.substring(0,1);      
	             }
	            
                       
	              if ((!firstChar.isEmpty()) && (!firstChar.equals("#")))
	              {
	             // 1st part is the account number	      	      
	              	  tab[colNb][liNb]=Double.parseDouble(firstField);
	            	  colNb++;

	            	  try 
	            	  {  
	            
	            		  while (lineBreaker.hasNext())
	            		  {
	            			  String field = null;
	            			  field=lineBreaker.next();
	            			   firstChar=field.substring(0,1);
		        	               
	            			  if (firstChar.equals("#"))
	            			  {
	            				  
	            				  read=false;
	            			  }
	            			  
	            			  if (read)
	            			  {   				  
	            			    Double d=Double.parseDouble(field);
	            				  tab[colNb][liNb]=d;
	            			  //tab[colNb][liNb]=lineBreaker.nextDouble();
// System.out.println("Inst Param field  "+tab[colNb][liNb]);  
 								colNb++;
	            			  }
	         
	            		  }
	  
	            		  
	            		//  tab[colNb][liNb]=lineBreaker.nextDouble();	 
	            		  liNb++;
	      
	            		 colNb=0;
	            	  }
	              
	            	  catch (InputMismatchException e)
	            	  {
	            		  System.out.println("File "+ catFile.getName() +" got pbs in loading");
	            	  }
	             
	            	  catch (NoSuchElementException e)
	            	  {
	            		  System.out.println("File "+ catFile.getName() +" not found.2");

	            	  }
	      
	               }
	              
	         lineBreaker.close();     
	                
	       
	         } // End while
	//  bip = bip +" li "+liNb;
	  //System.out.println("IntsrumParam loadInstrum "+bip);
	         in.close();
	   
	     }
	     catch (FileNotFoundException e)
	     {
	    	  System.out.println("File "+ catFile.getAbsoluteFile() +" not found.0");

	     }   // Make an ArrayList to store all the accounts we will make
		
		return tab;
	} // End LoadIntrumentParameters


}